@dxos/client-services 0.1.56-main.e47dfd1 → 0.1.56-main.e79d64a

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 (95) hide show
  1. package/dist/lib/browser/{chunk-CSJSC47N.mjs → chunk-T32PP5QD.mjs} +1284 -625
  2. package/dist/lib/browser/chunk-T32PP5QD.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +70 -54
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +42 -48
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +1439 -767
  9. package/dist/lib/node/index.cjs.map +4 -4
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +1590 -936
  12. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -1
  14. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +7 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/identity/identity.d.ts +3 -2
  18. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  21. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  23. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  24. package/dist/types/src/packlets/logging/logging-service.d.ts +6 -2
  25. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  26. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/diagnostics.d.ts +46 -0
  28. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -0
  29. package/dist/types/src/packlets/services/index.d.ts +1 -0
  30. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  31. package/dist/types/src/packlets/services/platform.d.ts +16 -0
  32. package/dist/types/src/packlets/services/platform.d.ts.map +1 -0
  33. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  34. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  35. package/dist/types/src/packlets/services/service-host.d.ts +7 -3
  36. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  37. package/dist/types/src/packlets/services/util.d.ts +6 -0
  38. package/dist/types/src/packlets/services/util.d.ts.map +1 -0
  39. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  40. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  41. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  42. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  43. package/dist/types/src/packlets/system/system-service.d.ts +12 -2
  44. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  45. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  46. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  47. package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
  48. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  49. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  50. package/dist/types/src/version.d.ts +2 -0
  51. package/dist/types/src/version.d.ts.map +1 -0
  52. package/package.json +34 -33
  53. package/src/packlets/devices/devices-service.test.ts +2 -1
  54. package/src/packlets/identity/authenticator.test.ts +2 -2
  55. package/src/packlets/identity/identity-manager.test.ts +15 -3
  56. package/src/packlets/identity/identity-manager.ts +28 -8
  57. package/src/packlets/identity/identity-service.test.ts +17 -2
  58. package/src/packlets/identity/identity-service.ts +24 -16
  59. package/src/packlets/identity/identity.test.ts +7 -6
  60. package/src/packlets/identity/identity.ts +9 -5
  61. package/src/packlets/invitations/device-invitation-protocol.test.ts +2 -1
  62. package/src/packlets/invitations/device-invitation-protocol.ts +1 -2
  63. package/src/packlets/invitations/invitation-extension.ts +1 -2
  64. package/src/packlets/invitations/invitations-handler.ts +3 -2
  65. package/src/packlets/invitations/invitations-service.ts +1 -2
  66. package/src/packlets/invitations/space-invitation-protocol.ts +1 -2
  67. package/src/packlets/locks/node.ts +1 -1
  68. package/src/packlets/logging/logging-service.ts +17 -9
  69. package/src/packlets/network/network-service.test.ts +2 -1
  70. package/src/packlets/services/client-rpc-server.ts +4 -4
  71. package/src/packlets/services/diagnostics.ts +212 -0
  72. package/src/packlets/services/index.ts +1 -0
  73. package/src/packlets/services/platform.ts +48 -0
  74. package/src/packlets/services/service-context.test.ts +59 -0
  75. package/src/packlets/services/service-context.ts +21 -15
  76. package/src/packlets/services/service-host.test.ts +12 -11
  77. package/src/packlets/services/service-host.ts +39 -20
  78. package/src/packlets/services/service-registry.test.ts +3 -1
  79. package/src/packlets/services/util.ts +33 -0
  80. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  81. package/src/packlets/spaces/data-space-manager.ts +7 -4
  82. package/src/packlets/spaces/data-space.ts +17 -5
  83. package/src/packlets/spaces/notarization-plugin.ts +1 -2
  84. package/src/packlets/spaces/spaces-service.test.ts +2 -1
  85. package/src/packlets/spaces/spaces-service.ts +19 -13
  86. package/src/packlets/system/system-service.test.ts +1 -0
  87. package/src/packlets/system/system-service.ts +34 -2
  88. package/src/packlets/testing/invitation-utils.ts +1 -2
  89. package/src/packlets/testing/test-builder.ts +1 -1
  90. package/src/packlets/vault/iframe-host-runtime.ts +2 -1
  91. package/src/packlets/vault/shell-runtime.ts +1 -2
  92. package/src/packlets/vault/worker-runtime.ts +3 -2
  93. package/src/packlets/vault/worker-session.ts +7 -3
  94. package/src/version.ts +1 -0
  95. package/dist/lib/browser/chunk-CSJSC47N.mjs.map +0 -7
@@ -12,7 +12,7 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
12
12
  const feedMap = new ComplexMap(PublicKey.hash);
13
13
  const update = () => {
14
14
  const { feeds } = feedStore;
15
- feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
15
+ feeds.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
16
16
  if (!feedMap.has(feed.key)) {
17
17
  feedMap.set(feed.key, feed);
18
18
  feed.on("close", update);
@@ -20,15 +20,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
20
20
  }
21
21
  });
22
22
  next({
23
- feeds: Array.from(feedMap.values()).map((feed) => {
24
- var _a, _b;
25
- return {
26
- feedKey: feed.key,
27
- length: feed.properties.length,
28
- bytes: feed.core.byteLength,
29
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
30
- };
31
- })
23
+ feeds: Array.from(feedMap.values()).map((feed) => ({
24
+ feedKey: feed.key,
25
+ length: feed.properties.length,
26
+ bytes: feed.core.byteLength,
27
+ downloaded: feed.core.bitfield?.data.toBuffer() ?? new Uint8Array()
28
+ }))
32
29
  });
33
30
  };
34
31
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -104,13 +101,13 @@ var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
104
101
  recipient: message.recipient.asUint8Array(),
105
102
  payload: message.payload
106
103
  },
107
- receivedAt: new Date()
104
+ receivedAt: /* @__PURE__ */ new Date()
108
105
  });
109
106
  });
110
107
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
111
108
  next({
112
109
  swarmEvent: swarmEvent.swarmEvent,
113
- receivedAt: new Date()
110
+ receivedAt: /* @__PURE__ */ new Date()
114
111
  });
115
112
  });
116
113
  return () => {
@@ -121,13 +118,10 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
121
118
  const update = () => {
122
119
  try {
123
120
  const topics = networkManager.topics;
124
- const labeledTopics = topics.map((topic) => {
125
- var _a, _b;
126
- return {
127
- topic,
128
- label: (_b = (_a = networkManager.getSwarm(topic)) == null ? void 0 : _a.label) != null ? _b : topic.toHex()
129
- };
130
- });
121
+ const labeledTopics = topics.map((topic) => ({
122
+ topic,
123
+ label: networkManager.getSwarm(topic)?.label ?? topic.toHex()
124
+ }));
131
125
  next({
132
126
  topics: labeledTopics
133
127
  });
@@ -139,17 +133,15 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
139
133
  update();
140
134
  });
141
135
  var subscribeToSwarmInfo = ({ networkManager }) => new Stream2(({ next }) => {
142
- var _a;
143
136
  const update = () => {
144
- var _a2;
145
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
137
+ const info = networkManager.connectionLog?.swarms;
146
138
  if (info) {
147
139
  next({
148
140
  data: info
149
141
  });
150
142
  }
151
143
  };
152
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
144
+ networkManager.connectionLog?.update.on(update);
153
145
  update();
154
146
  });
155
147
  var getNetworkPeers = ({ networkManager }, request) => {
@@ -158,7 +150,7 @@ var getNetworkPeers = ({ networkManager }, request) => {
158
150
  }
159
151
  const map = networkManager.getSwarmMap(PublicKey2.from(request.topic));
160
152
  return {
161
- peers: map == null ? void 0 : map.peers.map((peer) => ({
153
+ peers: map?.peers.map((peer) => ({
162
154
  ...peer,
163
155
  connections: peer.connections.map((connection) => connection.asUint8Array())
164
156
  }))
@@ -174,14 +166,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
174
166
  const spaces = [
175
167
  ...context.spaceManager.spaces.values()
176
168
  ];
177
- const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
169
+ const filteredSpaces = spaces.filter((space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
178
170
  next({
179
171
  spaces: filteredSpaces.map((space) => {
180
172
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
181
173
  return {
182
174
  key: space.key,
183
175
  isOpen: space.isOpen,
184
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
176
+ timeframe: spaceMetadata?.dataTimeframe,
185
177
  genesisFeed: space.genesisFeedKey,
186
178
  controlFeed: space.controlFeedKey,
187
179
  dataFeed: space.dataFeedKey
@@ -195,7 +187,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
195
187
  await update();
196
188
  });
197
189
  return () => {
198
- unsubscribe == null ? void 0 : unsubscribe();
190
+ unsubscribe?.();
199
191
  clearTimeout(timeout);
200
192
  };
201
193
  });
@@ -254,16 +246,15 @@ var DevtoolsServiceImpl = class {
254
246
  };
255
247
  }
256
248
  async getStorageInfo() {
257
- var _a, _b, _c, _d, _e;
258
- const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
249
+ const storageUsage = await this.params.context.storage.getDiskInfo?.() ?? {
259
250
  used: 0
260
251
  };
261
252
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
262
253
  return {
263
254
  type: this.params.context.storage.type,
264
255
  storageUsage: storageUsage.used,
265
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
266
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
256
+ originUsage: navigatorInfo?.usage ?? 0,
257
+ usageQuota: navigatorInfo?.quota ?? 0
267
258
  };
268
259
  }
269
260
  async getBlobs() {
@@ -449,7 +440,7 @@ var TrustedKeySetAuthVerifier = class {
449
440
  return await trigger.wait({
450
441
  timeout: this._params.authTimeout
451
442
  });
452
- } catch (e) {
443
+ } catch {
453
444
  return false;
454
445
  } finally {
455
446
  clear();
@@ -463,16 +454,27 @@ var TrustedKeySetAuthVerifier = class {
463
454
  };
464
455
 
465
456
  // packages/sdk/client-services/src/packlets/identity/identity.ts
466
- import invariant from "tiny-invariant";
467
457
  import { Event } from "@dxos/async";
468
458
  import { AUTH_TIMEOUT, LOAD_CONTROL_FEEDS_TIMEOUT } from "@dxos/client-protocol";
469
459
  import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSignerWithChain, ProfileStateMachine } from "@dxos/credentials";
470
460
  import { failUndefined } from "@dxos/debug";
471
461
  import { writeMessages } from "@dxos/feed-store";
462
+ import { invariant } from "@dxos/invariant";
472
463
  import { log as log2 } from "@dxos/log";
473
464
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
465
+ import { trace } from "@dxos/tracing";
466
+ function _ts_decorate(decorators, target, key, desc) {
467
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
468
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
469
+ r = Reflect.decorate(decorators, target, key, desc);
470
+ else
471
+ for (var i = decorators.length - 1; i >= 0; i--)
472
+ if (d = decorators[i])
473
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
474
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
475
+ }
474
476
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
475
- var Identity = class {
477
+ var Identity = class Identity2 {
476
478
  constructor({ space, signer, identityKey, deviceKey }) {
477
479
  this.stateUpdate = new Event();
478
480
  this.space = space;
@@ -498,12 +500,12 @@ var Identity = class {
498
500
  get authorizedDeviceKeys() {
499
501
  return this._deviceStateMachine.authorizedDeviceKeys;
500
502
  }
501
- async open() {
503
+ async open(ctx) {
502
504
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
503
505
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
504
- await this.space.open();
506
+ await this.space.open(ctx);
505
507
  }
506
- async close() {
508
+ async close(ctx) {
507
509
  await this.authVerifier.close();
508
510
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
509
511
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
@@ -534,11 +536,10 @@ var Identity = class {
534
536
  return this._deviceStateMachine.deviceCredentialChain;
535
537
  }
536
538
  getAdmissionCredentials() {
537
- var _a, _b;
538
539
  return {
539
540
  deviceKey: this.deviceKey,
540
- controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : failUndefined(),
541
- dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : failUndefined()
541
+ controlFeedKey: this.space.controlFeedKey ?? failUndefined(),
542
+ dataFeedKey: this.space.dataFeedKey ?? failUndefined()
542
543
  };
543
544
  }
544
545
  /**
@@ -546,7 +547,15 @@ var Identity = class {
546
547
  * Requires identity to be ready.
547
548
  */
548
549
  getIdentityCredentialSigner() {
549
- invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.");
550
+ invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
551
+ F: __dxlog_file2,
552
+ L: 139,
553
+ S: this,
554
+ A: [
555
+ "this._deviceStateMachine.deviceCredentialChain",
556
+ "'Device credential chain is not ready.'"
557
+ ]
558
+ });
550
559
  return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
551
560
  }
552
561
  /**
@@ -564,7 +573,7 @@ var Identity = class {
564
573
  dataFeedKey
565
574
  }, {
566
575
  F: __dxlog_file2,
567
- L: 151,
576
+ L: 155,
568
577
  S: this,
569
578
  C: (f, a) => f(...a)
570
579
  });
@@ -605,18 +614,40 @@ var Identity = class {
605
614
  })));
606
615
  }
607
616
  };
617
+ _ts_decorate([
618
+ trace.span()
619
+ ], Identity.prototype, "open", null);
620
+ _ts_decorate([
621
+ trace.span()
622
+ ], Identity.prototype, "close", null);
623
+ Identity = _ts_decorate([
624
+ trace.resource()
625
+ ], Identity);
608
626
 
609
627
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
610
- import invariant2 from "tiny-invariant";
611
628
  import { Event as Event2 } from "@dxos/async";
629
+ import { Context as Context3 } from "@dxos/context";
612
630
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
631
+ import { invariant as invariant2 } from "@dxos/invariant";
613
632
  import { PublicKey as PublicKey3 } from "@dxos/keys";
614
633
  import { log as log3 } from "@dxos/log";
615
- import { trace } from "@dxos/protocols";
634
+ import { trace as trace2 } from "@dxos/protocols";
616
635
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
636
+ import { Timeframe } from "@dxos/timeframe";
637
+ import { trace as Trace } from "@dxos/tracing";
617
638
  import { deferFunction } from "@dxos/util";
639
+ function _ts_decorate2(decorators, target, key, desc) {
640
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
641
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
642
+ r = Reflect.decorate(decorators, target, key, desc);
643
+ else
644
+ for (var i = decorators.length - 1; i >= 0; i--)
645
+ if (d = decorators[i])
646
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
647
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
648
+ }
618
649
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
619
- var IdentityManager = class {
650
+ var IdentityManager = class IdentityManager2 {
620
651
  // TODO(burdon): IdentityManagerParams.
621
652
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
622
653
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -629,14 +660,13 @@ var IdentityManager = class {
629
660
  get identity() {
630
661
  return this._identity;
631
662
  }
632
- async open() {
633
- var _a;
663
+ async open(ctx) {
634
664
  const traceId = PublicKey3.random().toHex();
635
- log3.trace("dxos.halo.identity-manager.open", trace.begin({
665
+ log3.trace("dxos.halo.identity-manager.open", trace2.begin({
636
666
  id: traceId
637
667
  }), {
638
668
  F: __dxlog_file3,
639
- L: 70,
669
+ L: 73,
640
670
  S: this,
641
671
  C: (f, a) => f(...a)
642
672
  });
@@ -646,44 +676,50 @@ var IdentityManager = class {
646
676
  identityRecord
647
677
  }, {
648
678
  F: __dxlog_file3,
649
- L: 74,
679
+ L: 77,
650
680
  S: this,
651
681
  C: (f, a) => f(...a)
652
682
  });
653
683
  if (identityRecord) {
654
684
  this._identity = await this._constructIdentity(identityRecord);
655
- await this._identity.open();
685
+ await this._identity.open(ctx);
656
686
  await this._identity.ready();
657
687
  log3.trace("dxos.halo.identity", {
658
688
  identityKey: identityRecord.identityKey,
659
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
689
+ displayName: this._identity.profileDocument?.displayName
660
690
  }, {
661
691
  F: __dxlog_file3,
662
- L: 79,
692
+ L: 82,
663
693
  S: this,
664
694
  C: (f, a) => f(...a)
665
695
  });
666
696
  this.stateUpdate.emit();
667
697
  }
668
- log3.trace("dxos.halo.identity-manager.open", trace.end({
698
+ log3.trace("dxos.halo.identity-manager.open", trace2.end({
669
699
  id: traceId
670
700
  }), {
671
701
  F: __dxlog_file3,
672
- L: 85,
702
+ L: 88,
673
703
  S: this,
674
704
  C: (f, a) => f(...a)
675
705
  });
676
706
  }
677
707
  async close() {
678
- var _a;
679
- await ((_a = this._identity) == null ? void 0 : _a.close());
708
+ await this._identity?.close(new Context3());
680
709
  }
681
710
  async createIdentity({ displayName } = {}) {
682
- var _a;
683
- invariant2(!this._identity, "Identity already exists.");
711
+ invariant2(!this._identity, "Identity already exists.", {
712
+ F: __dxlog_file3,
713
+ L: 96,
714
+ S: this,
715
+ A: [
716
+ "!this._identity",
717
+ "'Identity already exists.'"
718
+ ]
719
+ });
684
720
  log3("creating identity...", void 0, {
685
721
  F: __dxlog_file3,
686
- L: 94,
722
+ L: 97,
687
723
  S: this,
688
724
  C: (f, a) => f(...a)
689
725
  });
@@ -699,11 +735,27 @@ var IdentityManager = class {
699
735
  }
700
736
  };
701
737
  const identity = await this._constructIdentity(identityRecord);
702
- await identity.open();
738
+ await identity.open(new Context3());
703
739
  {
704
740
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
705
- invariant2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.");
706
- invariant2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.");
741
+ invariant2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
742
+ F: __dxlog_file3,
743
+ L: 116,
744
+ S: this,
745
+ A: [
746
+ "identityRecord.haloSpace.genesisFeedKey",
747
+ "'Genesis feed key is required.'"
748
+ ]
749
+ });
750
+ invariant2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
751
+ F: __dxlog_file3,
752
+ L: 117,
753
+ S: this,
754
+ A: [
755
+ "identityRecord.haloSpace.dataFeedKey",
756
+ "'Data feed key is required.'"
757
+ ]
758
+ });
707
759
  const credentials = [
708
760
  // Space genesis.
709
761
  ...await generator.createSpaceGenesis(identityRecord.haloSpace.key, identityRecord.haloSpace.genesisFeedKey),
@@ -729,10 +781,10 @@ var IdentityManager = class {
729
781
  await this._identity.ready();
730
782
  log3.trace("dxos.halo.identity", {
731
783
  identityKey: identityRecord.identityKey,
732
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
784
+ displayName: this._identity.profileDocument?.displayName
733
785
  }, {
734
786
  F: __dxlog_file3,
735
- L: 149,
787
+ L: 152,
736
788
  S: this,
737
789
  C: (f, a) => f(...a)
738
790
  });
@@ -742,7 +794,7 @@ var IdentityManager = class {
742
794
  deviceKey: identity.deviceKey
743
795
  }, {
744
796
  F: __dxlog_file3,
745
- L: 155,
797
+ L: 158,
746
798
  S: this,
747
799
  C: (f, a) => f(...a)
748
800
  });
@@ -752,16 +804,23 @@ var IdentityManager = class {
752
804
  * Accept an existing identity. Expects it's device key to be authorized (now or later).
753
805
  */
754
806
  async acceptIdentity(params) {
755
- var _a;
756
807
  log3("accepting identity", {
757
808
  params
758
809
  }, {
759
810
  F: __dxlog_file3,
760
- L: 163,
811
+ L: 166,
761
812
  S: this,
762
813
  C: (f, a) => f(...a)
763
814
  });
764
- invariant2(!this._identity, "Identity already exists.");
815
+ invariant2(!this._identity, "Identity already exists.", {
816
+ F: __dxlog_file3,
817
+ L: 167,
818
+ S: this,
819
+ A: [
820
+ "!this._identity",
821
+ "'Identity already exists.'"
822
+ ]
823
+ });
765
824
  const identityRecord = {
766
825
  identityKey: params.identityKey,
767
826
  deviceKey: params.deviceKey,
@@ -774,16 +833,16 @@ var IdentityManager = class {
774
833
  }
775
834
  };
776
835
  const identity = await this._constructIdentity(identityRecord);
777
- await identity.open();
836
+ await identity.open(new Context3());
778
837
  this._identity = identity;
779
838
  await this._metadataStore.setIdentityRecord(identityRecord);
780
839
  await this._identity.ready();
781
840
  log3.trace("dxos.halo.identity", {
782
841
  identityKey: identityRecord.identityKey,
783
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
842
+ displayName: this._identity.profileDocument?.displayName
784
843
  }, {
785
844
  F: __dxlog_file3,
786
- L: 183,
845
+ L: 186,
787
846
  S: this,
788
847
  C: (f, a) => f(...a)
789
848
  });
@@ -793,27 +852,83 @@ var IdentityManager = class {
793
852
  deviceKey: identity.deviceKey
794
853
  }, {
795
854
  F: __dxlog_file3,
796
- L: 189,
855
+ L: 192,
797
856
  S: this,
798
857
  C: (f, a) => f(...a)
799
858
  });
800
859
  return identity;
801
860
  }
861
+ /**
862
+ * Update the profile document of an existing identity.
863
+ */
864
+ async updateProfile(profile) {
865
+ invariant2(this._identity, "Identity not initialized.", {
866
+ F: __dxlog_file3,
867
+ L: 200,
868
+ S: this,
869
+ A: [
870
+ "this._identity",
871
+ "'Identity not initialized.'"
872
+ ]
873
+ });
874
+ const credential = await this._identity.getIdentityCredentialSigner().createCredential({
875
+ subject: this._identity.identityKey,
876
+ assertion: {
877
+ "@type": "dxos.halo.credentials.IdentityProfile",
878
+ profile
879
+ }
880
+ });
881
+ const receipt = await this._identity.controlPipeline.writer.write({
882
+ credential: {
883
+ credential
884
+ }
885
+ });
886
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe([
887
+ [
888
+ receipt.feedKey,
889
+ receipt.seq
890
+ ]
891
+ ]));
892
+ }
802
893
  async _constructIdentity(identityRecord) {
803
- invariant2(!this._identity);
894
+ invariant2(!this._identity, void 0, {
895
+ F: __dxlog_file3,
896
+ L: 214,
897
+ S: this,
898
+ A: [
899
+ "!this._identity",
900
+ ""
901
+ ]
902
+ });
804
903
  log3("constructing identity", {
805
904
  identityRecord
806
905
  }, {
807
906
  F: __dxlog_file3,
808
- L: 195,
907
+ L: 215,
809
908
  S: this,
810
909
  C: (f, a) => f(...a)
811
910
  });
812
- invariant2(identityRecord.haloSpace.controlFeedKey);
911
+ invariant2(identityRecord.haloSpace.controlFeedKey, void 0, {
912
+ F: __dxlog_file3,
913
+ L: 218,
914
+ S: this,
915
+ A: [
916
+ "identityRecord.haloSpace.controlFeedKey",
917
+ ""
918
+ ]
919
+ });
813
920
  const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
814
921
  writable: true
815
922
  });
816
- invariant2(identityRecord.haloSpace.dataFeedKey);
923
+ invariant2(identityRecord.haloSpace.dataFeedKey, void 0, {
924
+ F: __dxlog_file3,
925
+ L: 222,
926
+ S: this,
927
+ A: [
928
+ "identityRecord.haloSpace.dataFeedKey",
929
+ ""
930
+ ]
931
+ });
817
932
  const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.dataFeedKey, {
818
933
  writable: true,
819
934
  sparse: true
@@ -839,7 +954,7 @@ var IdentityManager = class {
839
954
  identityKey: identityRecord.identityKey
840
955
  }, {
841
956
  F: __dxlog_file3,
842
- L: 226,
957
+ L: 246,
843
958
  S: this,
844
959
  C: (f, a) => f(...a)
845
960
  });
@@ -860,7 +975,7 @@ var IdentityManager = class {
860
975
  onAuthFailure: () => {
861
976
  log3.warn("auth failure", void 0, {
862
977
  F: __dxlog_file3,
863
- L: 245,
978
+ L: 265,
864
979
  S: this,
865
980
  C: (f, a) => f(...a)
866
981
  });
@@ -869,19 +984,27 @@ var IdentityManager = class {
869
984
  });
870
985
  }
871
986
  };
987
+ _ts_decorate2([
988
+ Trace.span()
989
+ ], IdentityManager.prototype, "open", null);
990
+ IdentityManager = _ts_decorate2([
991
+ Trace.resource()
992
+ ], IdentityManager);
872
993
 
873
994
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
874
- import invariant3 from "tiny-invariant";
875
995
  import { Stream as Stream7 } from "@dxos/codec-protobuf";
876
996
  import { signPresentation } from "@dxos/credentials";
877
997
  import { todo } from "@dxos/debug";
998
+ import { invariant as invariant3 } from "@dxos/invariant";
999
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
878
1000
  var IdentityServiceImpl = class {
879
- // TODO(wittjosiah): Remove dependency on service context.
880
- constructor(_serviceContext) {
881
- this._serviceContext = _serviceContext;
1001
+ constructor(_createIdentity, _identityManager, _keyring) {
1002
+ this._createIdentity = _createIdentity;
1003
+ this._identityManager = _identityManager;
1004
+ this._keyring = _keyring;
882
1005
  }
883
1006
  async createIdentity(request) {
884
- await this._serviceContext.createIdentity(request);
1007
+ await this._createIdentity(request);
885
1008
  return this._getIdentity();
886
1009
  }
887
1010
  async recoverIdentity(request) {
@@ -893,34 +1016,56 @@ var IdentityServiceImpl = class {
893
1016
  identity: this._getIdentity()
894
1017
  });
895
1018
  emitNext();
896
- return this._serviceContext.identityManager.stateUpdate.on(emitNext);
1019
+ return this._identityManager.stateUpdate.on(emitNext);
897
1020
  });
898
1021
  }
899
1022
  _getIdentity() {
900
- if (!this._serviceContext.identityManager.identity) {
1023
+ if (!this._identityManager.identity) {
901
1024
  return void 0;
902
1025
  }
903
1026
  return {
904
- identityKey: this._serviceContext.identityManager.identity.identityKey,
905
- spaceKey: this._serviceContext.identityManager.identity.space.key,
906
- profile: this._serviceContext.identityManager.identity.profileDocument
1027
+ identityKey: this._identityManager.identity.identityKey,
1028
+ spaceKey: this._identityManager.identity.space.key,
1029
+ profile: this._identityManager.identity.profileDocument
907
1030
  };
908
1031
  }
1032
+ async updateProfile(profile) {
1033
+ invariant3(this._identityManager.identity, "Identity not initialized.", {
1034
+ F: __dxlog_file4,
1035
+ L: 59,
1036
+ S: this,
1037
+ A: [
1038
+ "this._identityManager.identity",
1039
+ "'Identity not initialized.'"
1040
+ ]
1041
+ });
1042
+ await this._identityManager.updateProfile(profile);
1043
+ return this._getIdentity();
1044
+ }
909
1045
  async signPresentation({ presentation, nonce }) {
910
- invariant3(this._serviceContext.identityManager.identity, "Identity not initialized.");
1046
+ invariant3(this._identityManager.identity, "Identity not initialized.", {
1047
+ F: __dxlog_file4,
1048
+ L: 65,
1049
+ S: this,
1050
+ A: [
1051
+ "this._identityManager.identity",
1052
+ "'Identity not initialized.'"
1053
+ ]
1054
+ });
911
1055
  return await signPresentation({
912
1056
  presentation,
913
- signer: this._serviceContext.keyring,
914
- signerKey: this._serviceContext.identityManager.identity.deviceKey,
915
- chain: this._serviceContext.identityManager.identity.deviceCredentialChain,
1057
+ signer: this._keyring,
1058
+ signerKey: this._identityManager.identity.deviceKey,
1059
+ chain: this._identityManager.identity.deviceCredentialChain,
916
1060
  nonce
917
1061
  });
918
1062
  }
919
1063
  };
920
1064
 
921
1065
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
922
- import invariant4 from "tiny-invariant";
1066
+ import { invariant as invariant4 } from "@dxos/invariant";
923
1067
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
1068
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
924
1069
  var DeviceInvitationProtocol = class {
925
1070
  constructor(_keyring, _getIdentity, _acceptIdentity) {
926
1071
  this._keyring = _keyring;
@@ -936,7 +1081,15 @@ var DeviceInvitationProtocol = class {
936
1081
  };
937
1082
  }
938
1083
  async admit(request) {
939
- invariant4(request.device);
1084
+ invariant4(request.device, void 0, {
1085
+ F: __dxlog_file5,
1086
+ L: 31,
1087
+ S: this,
1088
+ A: [
1089
+ "request.device",
1090
+ ""
1091
+ ]
1092
+ });
940
1093
  const identity = this._getIdentity();
941
1094
  await identity.admitDevice(request.device);
942
1095
  return {
@@ -964,9 +1117,25 @@ var DeviceInvitationProtocol = class {
964
1117
  };
965
1118
  }
966
1119
  async accept(response, request) {
967
- invariant4(response.device);
1120
+ invariant4(response.device, void 0, {
1121
+ F: __dxlog_file5,
1122
+ L: 64,
1123
+ S: this,
1124
+ A: [
1125
+ "response.device",
1126
+ ""
1127
+ ]
1128
+ });
968
1129
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
969
- invariant4(request.device);
1130
+ invariant4(request.device, void 0, {
1131
+ F: __dxlog_file5,
1132
+ L: 67,
1133
+ S: this,
1134
+ A: [
1135
+ "request.device",
1136
+ ""
1137
+ ]
1138
+ });
970
1139
  const { deviceKey, controlFeedKey, dataFeedKey } = request.device;
971
1140
  await this._acceptIdentity({
972
1141
  identityKey,
@@ -984,31 +1153,31 @@ var DeviceInvitationProtocol = class {
984
1153
  };
985
1154
 
986
1155
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
987
- import invariant6 from "tiny-invariant";
988
1156
  import { PushStream, scheduleTask as scheduleTask2, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
989
1157
  import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT } from "@dxos/client-protocol";
990
- import { Context as Context4 } from "@dxos/context";
1158
+ import { Context as Context5 } from "@dxos/context";
991
1159
  import { generatePasscode } from "@dxos/credentials";
992
1160
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2 } from "@dxos/errors";
1161
+ import { invariant as invariant6 } from "@dxos/invariant";
993
1162
  import { PublicKey as PublicKey5 } from "@dxos/keys";
994
1163
  import { log as log5 } from "@dxos/log";
995
1164
  import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
996
- import { trace as trace3 } from "@dxos/protocols";
1165
+ import { trace as trace4 } from "@dxos/protocols";
997
1166
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
998
1167
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
999
1168
 
1000
1169
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1001
- import invariant5 from "tiny-invariant";
1002
1170
  import { Trigger as Trigger2 } from "@dxos/async";
1003
- import { cancelWithContext, Context as Context3 } from "@dxos/context";
1171
+ import { cancelWithContext, Context as Context4 } from "@dxos/context";
1004
1172
  import { InvalidInvitationExtensionRoleError } from "@dxos/errors";
1173
+ import { invariant as invariant5 } from "@dxos/invariant";
1005
1174
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1006
1175
  import { log as log4 } from "@dxos/log";
1007
- import { schema as schema2, trace as trace2 } from "@dxos/protocols";
1176
+ import { schema as schema2, trace as trace3 } from "@dxos/protocols";
1008
1177
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1009
1178
  import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1010
1179
  import { RpcExtension } from "@dxos/teleport";
1011
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
1180
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
1012
1181
  var OPTIONS_TIMEOUT = 1e4;
1013
1182
  var MAX_OTP_ATTEMPTS = 3;
1014
1183
  var InvitationHostExtension = class extends RpcExtension {
@@ -1022,7 +1191,7 @@ var InvitationHostExtension = class extends RpcExtension {
1022
1191
  }
1023
1192
  });
1024
1193
  this._callbacks = _callbacks;
1025
- this._ctx = new Context3();
1194
+ this._ctx = new Context4();
1026
1195
  this._remoteOptionsTrigger = new Trigger2();
1027
1196
  this.invitation = void 0;
1028
1197
  this.guestProfile = void 0;
@@ -1036,18 +1205,26 @@ var InvitationHostExtension = class extends RpcExtension {
1036
1205
  // Perhaps in the future we will have more complex logic here.
1037
1206
  InvitationHostService: {
1038
1207
  options: async (options) => {
1039
- invariant5(!this._remoteOptions, "Remote options already set.");
1208
+ invariant5(!this._remoteOptions, "Remote options already set.", {
1209
+ F: __dxlog_file6,
1210
+ L: 88,
1211
+ S: this,
1212
+ A: [
1213
+ "!this._remoteOptions",
1214
+ "'Remote options already set.'"
1215
+ ]
1216
+ });
1040
1217
  this._remoteOptions = options;
1041
1218
  this._remoteOptionsTrigger.wake();
1042
1219
  },
1043
1220
  introduce: async (request) => {
1044
1221
  const { profile, invitationId } = request;
1045
1222
  const traceId = PublicKey4.random().toHex();
1046
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
1223
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.begin({
1047
1224
  id: traceId
1048
1225
  }), {
1049
- F: __dxlog_file4,
1050
- L: 98,
1226
+ F: __dxlog_file6,
1227
+ L: 97,
1051
1228
  S: this,
1052
1229
  C: (f, a) => f(...a)
1053
1230
  });
@@ -1056,8 +1233,8 @@ var InvitationHostExtension = class extends RpcExtension {
1056
1233
  log4.warn("invitation not found", {
1057
1234
  invitationId
1058
1235
  }, {
1059
- F: __dxlog_file4,
1060
- L: 102,
1236
+ F: __dxlog_file6,
1237
+ L: 101,
1061
1238
  S: this,
1062
1239
  C: (f, a) => f(...a)
1063
1240
  });
@@ -1070,8 +1247,8 @@ var InvitationHostExtension = class extends RpcExtension {
1070
1247
  log4("guest introduced itself", {
1071
1248
  guestProfile: profile
1072
1249
  }, {
1073
- F: __dxlog_file4,
1074
- L: 111,
1250
+ F: __dxlog_file6,
1251
+ L: 110,
1075
1252
  S: this,
1076
1253
  C: (f, a) => f(...a)
1077
1254
  });
@@ -1080,11 +1257,11 @@ var InvitationHostExtension = class extends RpcExtension {
1080
1257
  ...this.invitation,
1081
1258
  state: Invitation2.State.READY_FOR_AUTHENTICATION
1082
1259
  });
1083
- log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
1260
+ log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
1084
1261
  id: traceId
1085
1262
  }), {
1086
- F: __dxlog_file4,
1087
- L: 118,
1263
+ F: __dxlog_file6,
1264
+ L: 117,
1088
1265
  S: this,
1089
1266
  C: (f, a) => f(...a)
1090
1267
  });
@@ -1095,29 +1272,37 @@ var InvitationHostExtension = class extends RpcExtension {
1095
1272
  },
1096
1273
  authenticate: async ({ authCode: code }) => {
1097
1274
  const traceId = PublicKey4.random().toHex();
1098
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
1275
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
1099
1276
  id: traceId
1100
1277
  }), {
1101
- F: __dxlog_file4,
1102
- L: 127,
1278
+ F: __dxlog_file6,
1279
+ L: 126,
1103
1280
  S: this,
1104
1281
  C: (f, a) => f(...a)
1105
1282
  });
1106
1283
  log4("received authentication request", {
1107
1284
  authCode: code
1108
1285
  }, {
1109
- F: __dxlog_file4,
1110
- L: 128,
1286
+ F: __dxlog_file6,
1287
+ L: 127,
1111
1288
  S: this,
1112
1289
  C: (f, a) => f(...a)
1113
1290
  });
1114
1291
  let status = AuthenticationResponse.Status.OK;
1115
- invariant5(this.invitation, "Invitation is not set.");
1292
+ invariant5(this.invitation, "Invitation is not set.", {
1293
+ F: __dxlog_file6,
1294
+ L: 130,
1295
+ S: this,
1296
+ A: [
1297
+ "this.invitation",
1298
+ "'Invitation is not set.'"
1299
+ ]
1300
+ });
1116
1301
  switch (this.invitation.authMethod) {
1117
1302
  case Invitation2.AuthMethod.NONE: {
1118
1303
  log4("authentication not required", void 0, {
1119
- F: __dxlog_file4,
1120
- L: 134,
1304
+ F: __dxlog_file6,
1305
+ L: 133,
1121
1306
  S: this,
1122
1307
  C: (f, a) => f(...a)
1123
1308
  });
@@ -1141,8 +1326,8 @@ var InvitationHostExtension = class extends RpcExtension {
1141
1326
  log4.error("invalid authentication method", {
1142
1327
  authMethod: this.invitation.authMethod
1143
1328
  }, {
1144
- F: __dxlog_file4,
1145
- L: 152,
1329
+ F: __dxlog_file6,
1330
+ L: 151,
1146
1331
  S: this,
1147
1332
  C: (f, a) => f(...a)
1148
1333
  });
@@ -1150,14 +1335,14 @@ var InvitationHostExtension = class extends RpcExtension {
1150
1335
  break;
1151
1336
  }
1152
1337
  }
1153
- log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.end({
1338
+ log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.end({
1154
1339
  id: traceId,
1155
1340
  data: {
1156
1341
  status
1157
1342
  }
1158
1343
  }), {
1159
- F: __dxlog_file4,
1160
- L: 158,
1344
+ F: __dxlog_file6,
1345
+ L: 157,
1161
1346
  S: this,
1162
1347
  C: (f, a) => f(...a)
1163
1348
  });
@@ -1167,25 +1352,33 @@ var InvitationHostExtension = class extends RpcExtension {
1167
1352
  },
1168
1353
  admit: async (request) => {
1169
1354
  const traceId = PublicKey4.random().toHex();
1170
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
1355
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.begin({
1171
1356
  id: traceId
1172
1357
  }), {
1173
- F: __dxlog_file4,
1174
- L: 164,
1358
+ F: __dxlog_file6,
1359
+ L: 163,
1175
1360
  S: this,
1176
1361
  C: (f, a) => f(...a)
1177
1362
  });
1178
1363
  try {
1179
- invariant5(this.invitation, "Invitation is not set.");
1364
+ invariant5(this.invitation, "Invitation is not set.", {
1365
+ F: __dxlog_file6,
1366
+ L: 166,
1367
+ S: this,
1368
+ A: [
1369
+ "this.invitation",
1370
+ "'Invitation is not set.'"
1371
+ ]
1372
+ });
1180
1373
  if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
1181
1374
  throw new Error("Not authenticated");
1182
1375
  }
1183
1376
  const response = await this._callbacks.admit(request);
1184
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
1377
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace3.end({
1185
1378
  id: traceId
1186
1379
  }), {
1187
- F: __dxlog_file4,
1188
- L: 175,
1380
+ F: __dxlog_file6,
1381
+ L: 174,
1189
1382
  S: this,
1190
1383
  C: (f, a) => f(...a)
1191
1384
  });
@@ -1199,7 +1392,6 @@ var InvitationHostExtension = class extends RpcExtension {
1199
1392
  };
1200
1393
  }
1201
1394
  async onOpen(context) {
1202
- var _a;
1203
1395
  await super.onOpen(context);
1204
1396
  try {
1205
1397
  await this.rpc.InvitationHostService.options({
@@ -1208,7 +1400,7 @@ var InvitationHostExtension = class extends RpcExtension {
1208
1400
  await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
1209
1401
  timeout: OPTIONS_TIMEOUT
1210
1402
  }));
1211
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.GUEST) {
1403
+ if (this._remoteOptions?.role !== Options.Role.GUEST) {
1212
1404
  throw new InvalidInvitationExtensionRoleError(void 0, {
1213
1405
  expected: Options.Role.GUEST,
1214
1406
  remoteOptions: this._remoteOptions
@@ -1234,14 +1426,22 @@ var InvitationGuestExtension = class extends RpcExtension {
1234
1426
  }
1235
1427
  });
1236
1428
  this._callbacks = _callbacks;
1237
- this._ctx = new Context3();
1429
+ this._ctx = new Context4();
1238
1430
  this._remoteOptionsTrigger = new Trigger2();
1239
1431
  }
1240
1432
  async getHandlers() {
1241
1433
  return {
1242
1434
  InvitationHostService: {
1243
1435
  options: async (options) => {
1244
- invariant5(!this._remoteOptions, "Remote options already set.");
1436
+ invariant5(!this._remoteOptions, "Remote options already set.", {
1437
+ F: __dxlog_file6,
1438
+ L: 241,
1439
+ S: this,
1440
+ A: [
1441
+ "!this._remoteOptions",
1442
+ "'Remote options already set.'"
1443
+ ]
1444
+ });
1245
1445
  this._remoteOptions = options;
1246
1446
  this._remoteOptionsTrigger.wake();
1247
1447
  },
@@ -1258,12 +1458,11 @@ var InvitationGuestExtension = class extends RpcExtension {
1258
1458
  };
1259
1459
  }
1260
1460
  async onOpen(context) {
1261
- var _a;
1262
1461
  await super.onOpen(context);
1263
1462
  try {
1264
1463
  log4("begin options", void 0, {
1265
- F: __dxlog_file4,
1266
- L: 263,
1464
+ F: __dxlog_file6,
1465
+ L: 262,
1267
1466
  S: this,
1268
1467
  C: (f, a) => f(...a)
1269
1468
  });
@@ -1274,12 +1473,12 @@ var InvitationGuestExtension = class extends RpcExtension {
1274
1473
  timeout: OPTIONS_TIMEOUT
1275
1474
  }));
1276
1475
  log4("end options", void 0, {
1277
- F: __dxlog_file4,
1278
- L: 266,
1476
+ F: __dxlog_file6,
1477
+ L: 265,
1279
1478
  S: this,
1280
1479
  C: (f, a) => f(...a)
1281
1480
  });
1282
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.HOST) {
1481
+ if (this._remoteOptions?.role !== Options.Role.HOST) {
1283
1482
  throw new InvalidInvitationExtensionRoleError(void 0, {
1284
1483
  expected: Options.Role.HOST,
1285
1484
  remoteOptions: this._remoteOptions
@@ -1288,8 +1487,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1288
1487
  this._callbacks.onOpen(this._ctx);
1289
1488
  } catch (err) {
1290
1489
  log4("openError", err, {
1291
- F: __dxlog_file4,
1292
- L: 276,
1490
+ F: __dxlog_file6,
1491
+ L: 275,
1293
1492
  S: this,
1294
1493
  C: (f, a) => f(...a)
1295
1494
  });
@@ -1298,8 +1497,8 @@ var InvitationGuestExtension = class extends RpcExtension {
1298
1497
  }
1299
1498
  async onClose() {
1300
1499
  log4("onClose", void 0, {
1301
- F: __dxlog_file4,
1302
- L: 282,
1500
+ F: __dxlog_file6,
1501
+ L: 281,
1303
1502
  S: this,
1304
1503
  C: (f, a) => f(...a)
1305
1504
  });
@@ -1309,7 +1508,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1309
1508
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
1310
1509
 
1311
1510
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1312
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
1511
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
1313
1512
  var InvitationsHandler = class {
1314
1513
  /**
1315
1514
  * @internal
@@ -1318,10 +1517,17 @@ var InvitationsHandler = class {
1318
1517
  this._networkManager = _networkManager;
1319
1518
  }
1320
1519
  createInvitation(protocol, options) {
1321
- var _a;
1322
- const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options != null ? options : {};
1323
- const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
1324
- invariant6(protocol);
1520
+ const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options ?? {};
1521
+ const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1522
+ invariant6(protocol, void 0, {
1523
+ F: __dxlog_file7,
1524
+ L: 76,
1525
+ S: this,
1526
+ A: [
1527
+ "protocol",
1528
+ ""
1529
+ ]
1530
+ });
1325
1531
  const invitation = {
1326
1532
  invitationId,
1327
1533
  type,
@@ -1333,7 +1539,7 @@ var InvitationsHandler = class {
1333
1539
  ...protocol.getInvitationContext()
1334
1540
  };
1335
1541
  const stream = new PushStream();
1336
- const ctx = new Context4({
1542
+ const ctx = new Context5({
1337
1543
  onError: (err) => {
1338
1544
  void ctx.dispose();
1339
1545
  stream.error(err);
@@ -1343,8 +1549,8 @@ var InvitationsHandler = class {
1343
1549
  log5("complete", {
1344
1550
  ...protocol.toJSON()
1345
1551
  }, {
1346
- F: __dxlog_file5,
1347
- L: 99,
1552
+ F: __dxlog_file7,
1553
+ L: 98,
1348
1554
  S: this,
1349
1555
  C: (f, a) => f(...a)
1350
1556
  });
@@ -1365,10 +1571,17 @@ var InvitationsHandler = class {
1365
1571
  return invitation;
1366
1572
  },
1367
1573
  admit: async (admissionRequest) => {
1368
- var _a2, _b, _c;
1369
1574
  try {
1370
- const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1371
- invariant6(deviceKey);
1575
+ const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1576
+ invariant6(deviceKey, void 0, {
1577
+ F: __dxlog_file7,
1578
+ L: 119,
1579
+ S: this,
1580
+ A: [
1581
+ "deviceKey",
1582
+ ""
1583
+ ]
1584
+ });
1372
1585
  const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1373
1586
  extension.completedTrigger.wake(deviceKey);
1374
1587
  return admissionResponse;
@@ -1381,19 +1594,19 @@ var InvitationsHandler = class {
1381
1594
  scheduleTask2(ctx, async () => {
1382
1595
  const traceId = PublicKey5.random().toHex();
1383
1596
  try {
1384
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.begin({
1597
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.begin({
1385
1598
  id: traceId
1386
1599
  }), {
1387
- F: __dxlog_file5,
1388
- L: 138,
1600
+ F: __dxlog_file7,
1601
+ L: 137,
1389
1602
  S: this,
1390
1603
  C: (f, a) => f(...a)
1391
1604
  });
1392
1605
  log5("connected", {
1393
1606
  ...protocol.toJSON()
1394
1607
  }, {
1395
- F: __dxlog_file5,
1396
- L: 139,
1608
+ F: __dxlog_file7,
1609
+ L: 138,
1397
1610
  S: this,
1398
1611
  C: (f, a) => f(...a)
1399
1612
  });
@@ -1408,8 +1621,8 @@ var InvitationsHandler = class {
1408
1621
  guest: deviceKey,
1409
1622
  ...protocol.toJSON()
1410
1623
  }, {
1411
- F: __dxlog_file5,
1412
- L: 142,
1624
+ F: __dxlog_file7,
1625
+ L: 141,
1413
1626
  S: this,
1414
1627
  C: (f, a) => f(...a)
1415
1628
  });
@@ -1417,11 +1630,11 @@ var InvitationsHandler = class {
1417
1630
  ...invitation,
1418
1631
  state: Invitation3.State.SUCCESS
1419
1632
  });
1420
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.end({
1633
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
1421
1634
  id: traceId
1422
1635
  }), {
1423
- F: __dxlog_file5,
1424
- L: 144,
1636
+ F: __dxlog_file7,
1637
+ L: 143,
1425
1638
  S: this,
1426
1639
  C: (f, a) => f(...a)
1427
1640
  });
@@ -1430,8 +1643,8 @@ var InvitationsHandler = class {
1430
1643
  log5("timeout", {
1431
1644
  ...protocol.toJSON()
1432
1645
  }, {
1433
- F: __dxlog_file5,
1434
- L: 147,
1646
+ F: __dxlog_file7,
1647
+ L: 146,
1435
1648
  S: this,
1436
1649
  C: (f, a) => f(...a)
1437
1650
  });
@@ -1441,19 +1654,19 @@ var InvitationsHandler = class {
1441
1654
  });
1442
1655
  } else {
1443
1656
  log5.error("failed", err, {
1444
- F: __dxlog_file5,
1445
- L: 150,
1657
+ F: __dxlog_file7,
1658
+ L: 149,
1446
1659
  S: this,
1447
1660
  C: (f, a) => f(...a)
1448
1661
  });
1449
1662
  stream.error(err);
1450
1663
  }
1451
- log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.error({
1664
+ log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.error({
1452
1665
  id: traceId,
1453
1666
  error: err
1454
1667
  }), {
1455
- F: __dxlog_file5,
1456
- L: 153,
1668
+ F: __dxlog_file7,
1669
+ L: 152,
1457
1670
  S: this,
1458
1671
  C: (f, a) => f(...a)
1459
1672
  });
@@ -1473,8 +1686,8 @@ var InvitationsHandler = class {
1473
1686
  log5("timeout", {
1474
1687
  ...protocol.toJSON()
1475
1688
  }, {
1476
- F: __dxlog_file5,
1477
- L: 168,
1689
+ F: __dxlog_file7,
1690
+ L: 167,
1478
1691
  S: this,
1479
1692
  C: (f, a) => f(...a)
1480
1693
  });
@@ -1484,8 +1697,8 @@ var InvitationsHandler = class {
1484
1697
  });
1485
1698
  } else {
1486
1699
  log5.error("failed", err, {
1487
- F: __dxlog_file5,
1488
- L: 171,
1700
+ F: __dxlog_file7,
1701
+ L: 170,
1489
1702
  S: this,
1490
1703
  C: (f, a) => f(...a)
1491
1704
  });
@@ -1504,7 +1717,8 @@ var InvitationsHandler = class {
1504
1717
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1505
1718
  teleport.addExtension("dxos.halo.invitations", createExtension());
1506
1719
  }),
1507
- topology: new StarTopology(topic)
1720
+ topology: new StarTopology(topic),
1721
+ label: "invitation host"
1508
1722
  });
1509
1723
  ctx.onDispose(() => swarmConnection.close());
1510
1724
  stream.next({
@@ -1527,26 +1741,42 @@ var InvitationsHandler = class {
1527
1741
  }
1528
1742
  acceptInvitation(protocol, invitation) {
1529
1743
  const { timeout = INVITATION_TIMEOUT } = invitation;
1530
- invariant6(protocol);
1744
+ invariant6(protocol, void 0, {
1745
+ F: __dxlog_file7,
1746
+ L: 211,
1747
+ S: this,
1748
+ A: [
1749
+ "protocol",
1750
+ ""
1751
+ ]
1752
+ });
1531
1753
  const authenticated = new Trigger3();
1532
1754
  let admitted = false;
1533
1755
  let currentState;
1534
1756
  const stream = new PushStream();
1535
1757
  const setState = (newData) => {
1536
- invariant6(newData.state !== void 0);
1758
+ invariant6(newData.state !== void 0, void 0, {
1759
+ F: __dxlog_file7,
1760
+ L: 222,
1761
+ S: this,
1762
+ A: [
1763
+ "newData.state !== undefined",
1764
+ ""
1765
+ ]
1766
+ });
1537
1767
  currentState = newData.state;
1538
1768
  stream.next({
1539
1769
  ...invitation,
1540
1770
  ...newData
1541
1771
  });
1542
1772
  };
1543
- const ctx = new Context4({
1773
+ const ctx = new Context5({
1544
1774
  onError: (err) => {
1545
1775
  if (err instanceof TimeoutError) {
1546
1776
  log5("timeout", {
1547
1777
  ...protocol.toJSON()
1548
1778
  }, {
1549
- F: __dxlog_file5,
1779
+ F: __dxlog_file7,
1550
1780
  L: 230,
1551
1781
  S: this,
1552
1782
  C: (f, a) => f(...a)
@@ -1556,7 +1786,7 @@ var InvitationsHandler = class {
1556
1786
  });
1557
1787
  } else {
1558
1788
  log5.warn("auth failed", err, {
1559
- F: __dxlog_file5,
1789
+ F: __dxlog_file7,
1560
1790
  L: 233,
1561
1791
  S: this,
1562
1792
  C: (f, a) => f(...a)
@@ -1570,7 +1800,7 @@ var InvitationsHandler = class {
1570
1800
  log5("complete", {
1571
1801
  ...protocol.toJSON()
1572
1802
  }, {
1573
- F: __dxlog_file5,
1803
+ F: __dxlog_file7,
1574
1804
  L: 241,
1575
1805
  S: this,
1576
1806
  C: (f, a) => f(...a)
@@ -1585,7 +1815,7 @@ var InvitationsHandler = class {
1585
1815
  log5("extension disposed", {
1586
1816
  currentState
1587
1817
  }, {
1588
- F: __dxlog_file5,
1818
+ F: __dxlog_file7,
1589
1819
  L: 251,
1590
1820
  S: this,
1591
1821
  C: (f, a) => f(...a)
@@ -1597,10 +1827,10 @@ var InvitationsHandler = class {
1597
1827
  scheduleTask2(ctx, async () => {
1598
1828
  const traceId = PublicKey5.random().toHex();
1599
1829
  try {
1600
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.begin({
1830
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.begin({
1601
1831
  id: traceId
1602
1832
  }), {
1603
- F: __dxlog_file5,
1833
+ F: __dxlog_file7,
1604
1834
  L: 260,
1605
1835
  S: this,
1606
1836
  C: (f, a) => f(...a)
@@ -1612,7 +1842,7 @@ var InvitationsHandler = class {
1612
1842
  log5("connected", {
1613
1843
  ...protocol.toJSON()
1614
1844
  }, {
1615
- F: __dxlog_file5,
1845
+ F: __dxlog_file7,
1616
1846
  L: 268,
1617
1847
  S: this,
1618
1848
  C: (f, a) => f(...a)
@@ -1623,7 +1853,7 @@ var InvitationsHandler = class {
1623
1853
  log5("introduce", {
1624
1854
  ...protocol.toJSON()
1625
1855
  }, {
1626
- F: __dxlog_file5,
1856
+ F: __dxlog_file7,
1627
1857
  L: 272,
1628
1858
  S: this,
1629
1859
  C: (f, a) => f(...a)
@@ -1633,7 +1863,7 @@ var InvitationsHandler = class {
1633
1863
  ...protocol.toJSON(),
1634
1864
  response: introductionResponse
1635
1865
  }, {
1636
- F: __dxlog_file5,
1866
+ F: __dxlog_file7,
1637
1867
  L: 276,
1638
1868
  S: this,
1639
1869
  C: (f, a) => f(...a)
@@ -1645,7 +1875,7 @@ var InvitationsHandler = class {
1645
1875
  if (isAuthenticationRequired(invitation)) {
1646
1876
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1647
1877
  log5("guest waiting for authentication code...", void 0, {
1648
- F: __dxlog_file5,
1878
+ F: __dxlog_file7,
1649
1879
  L: 285,
1650
1880
  S: this,
1651
1881
  C: (f, a) => f(...a)
@@ -1657,7 +1887,7 @@ var InvitationsHandler = class {
1657
1887
  timeout
1658
1888
  });
1659
1889
  log5("sending authentication request", void 0, {
1660
- F: __dxlog_file5,
1890
+ F: __dxlog_file7,
1661
1891
  L: 289,
1662
1892
  S: this,
1663
1893
  C: (f, a) => f(...a)
@@ -1678,7 +1908,7 @@ var InvitationsHandler = class {
1678
1908
  log5("retrying invalid code", {
1679
1909
  attempt
1680
1910
  }, {
1681
- F: __dxlog_file5,
1911
+ F: __dxlog_file7,
1682
1912
  L: 300,
1683
1913
  S: this,
1684
1914
  C: (f, a) => f(...a)
@@ -1695,7 +1925,7 @@ var InvitationsHandler = class {
1695
1925
  log5("request admission", {
1696
1926
  ...protocol.toJSON()
1697
1927
  }, {
1698
- F: __dxlog_file5,
1928
+ F: __dxlog_file7,
1699
1929
  L: 311,
1700
1930
  S: this,
1701
1931
  C: (f, a) => f(...a)
@@ -1707,7 +1937,7 @@ var InvitationsHandler = class {
1707
1937
  log5("admitted by host", {
1708
1938
  ...protocol.toJSON()
1709
1939
  }, {
1710
- F: __dxlog_file5,
1940
+ F: __dxlog_file7,
1711
1941
  L: 322,
1712
1942
  S: this,
1713
1943
  C: (f, a) => f(...a)
@@ -1716,10 +1946,10 @@ var InvitationsHandler = class {
1716
1946
  ...result,
1717
1947
  state: Invitation3.State.SUCCESS
1718
1948
  });
1719
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.end({
1949
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.end({
1720
1950
  id: traceId
1721
1951
  }), {
1722
- F: __dxlog_file5,
1952
+ F: __dxlog_file7,
1723
1953
  L: 324,
1724
1954
  S: this,
1725
1955
  C: (f, a) => f(...a)
@@ -1729,7 +1959,7 @@ var InvitationsHandler = class {
1729
1959
  log5("timeout", {
1730
1960
  ...protocol.toJSON()
1731
1961
  }, {
1732
- F: __dxlog_file5,
1962
+ F: __dxlog_file7,
1733
1963
  L: 327,
1734
1964
  S: this,
1735
1965
  C: (f, a) => f(...a)
@@ -1739,18 +1969,18 @@ var InvitationsHandler = class {
1739
1969
  });
1740
1970
  } else {
1741
1971
  log5("auth failed", err, {
1742
- F: __dxlog_file5,
1972
+ F: __dxlog_file7,
1743
1973
  L: 330,
1744
1974
  S: this,
1745
1975
  C: (f, a) => f(...a)
1746
1976
  });
1747
1977
  stream.error(err);
1748
1978
  }
1749
- log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.error({
1979
+ log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.error({
1750
1980
  id: traceId,
1751
1981
  error: err
1752
1982
  }), {
1753
- F: __dxlog_file5,
1983
+ F: __dxlog_file7,
1754
1984
  L: 333,
1755
1985
  S: this,
1756
1986
  C: (f, a) => f(...a)
@@ -1768,7 +1998,7 @@ var InvitationsHandler = class {
1768
1998
  log5("timeout", {
1769
1999
  ...protocol.toJSON()
1770
2000
  }, {
1771
- F: __dxlog_file5,
2001
+ F: __dxlog_file7,
1772
2002
  L: 344,
1773
2003
  S: this,
1774
2004
  C: (f, a) => f(...a)
@@ -1778,7 +2008,7 @@ var InvitationsHandler = class {
1778
2008
  });
1779
2009
  } else {
1780
2010
  log5("auth failed", err, {
1781
- F: __dxlog_file5,
2011
+ F: __dxlog_file7,
1782
2012
  L: 347,
1783
2013
  S: this,
1784
2014
  C: (f, a) => f(...a)
@@ -1790,7 +2020,15 @@ var InvitationsHandler = class {
1790
2020
  return extension;
1791
2021
  };
1792
2022
  scheduleTask2(ctx, async () => {
1793
- invariant6(invitation.swarmKey);
2023
+ invariant6(invitation.swarmKey, void 0, {
2024
+ F: __dxlog_file7,
2025
+ L: 357,
2026
+ S: this,
2027
+ A: [
2028
+ "invitation.swarmKey",
2029
+ ""
2030
+ ]
2031
+ });
1794
2032
  const topic = invitation.swarmKey;
1795
2033
  const swarmConnection = await this._networkManager.joinSwarm({
1796
2034
  topic,
@@ -1798,7 +2036,8 @@ var InvitationsHandler = class {
1798
2036
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1799
2037
  teleport.addExtension("dxos.halo.invitations", createExtension());
1800
2038
  }),
1801
- topology: new StarTopology(topic)
2039
+ topology: new StarTopology(topic),
2040
+ label: "invitation guest"
1802
2041
  });
1803
2042
  ctx.onDispose(() => swarmConnection.close());
1804
2043
  setState({
@@ -1823,12 +2062,12 @@ var InvitationsHandler = class {
1823
2062
  };
1824
2063
 
1825
2064
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1826
- import invariant7 from "tiny-invariant";
1827
2065
  import { Event as Event3 } from "@dxos/async";
1828
2066
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
2067
+ import { invariant as invariant7 } from "@dxos/invariant";
1829
2068
  import { log as log6 } from "@dxos/log";
1830
2069
  import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
1831
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2070
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
1832
2071
  var InvitationsServiceImpl = class {
1833
2072
  constructor(_invitationsHandler, _getHandler) {
1834
2073
  this._invitationsHandler = _invitationsHandler;
@@ -1890,19 +2129,27 @@ var InvitationsServiceImpl = class {
1890
2129
  }
1891
2130
  async authenticate({ invitationId, authCode }) {
1892
2131
  log6("authenticating...", void 0, {
1893
- F: __dxlog_file6,
1894
- L: 103,
2132
+ F: __dxlog_file8,
2133
+ L: 102,
1895
2134
  S: this,
1896
2135
  C: (f, a) => f(...a)
1897
2136
  });
1898
- invariant7(invitationId);
2137
+ invariant7(invitationId, void 0, {
2138
+ F: __dxlog_file8,
2139
+ L: 103,
2140
+ S: this,
2141
+ A: [
2142
+ "invitationId",
2143
+ ""
2144
+ ]
2145
+ });
1899
2146
  const observable = this._acceptInvitations.get(invitationId);
1900
2147
  if (!observable) {
1901
2148
  log6.warn("invalid invitation", {
1902
2149
  invitationId
1903
2150
  }, {
1904
- F: __dxlog_file6,
1905
- L: 107,
2151
+ F: __dxlog_file8,
2152
+ L: 106,
1906
2153
  S: this,
1907
2154
  C: (f, a) => f(...a)
1908
2155
  });
@@ -1912,12 +2159,20 @@ var InvitationsServiceImpl = class {
1912
2159
  }
1913
2160
  async cancelInvitation({ invitationId }) {
1914
2161
  log6("deleting...", void 0, {
1915
- F: __dxlog_file6,
1916
- L: 114,
2162
+ F: __dxlog_file8,
2163
+ L: 113,
1917
2164
  S: this,
1918
2165
  C: (f, a) => f(...a)
1919
2166
  });
1920
- invariant7(invitationId);
2167
+ invariant7(invitationId, void 0, {
2168
+ F: __dxlog_file8,
2169
+ L: 114,
2170
+ S: this,
2171
+ A: [
2172
+ "invitationId",
2173
+ ""
2174
+ ]
2175
+ });
1921
2176
  const created = this._createInvitations.get(invitationId);
1922
2177
  const accepted = this._acceptInvitations.get(invitationId);
1923
2178
  if (created) {
@@ -1932,8 +2187,8 @@ var InvitationsServiceImpl = class {
1932
2187
  log6.warn("invalid invitation", {
1933
2188
  invitationId
1934
2189
  }, {
1935
- F: __dxlog_file6,
1936
- L: 127,
2190
+ F: __dxlog_file8,
2191
+ L: 126,
1937
2192
  S: this,
1938
2193
  C: (f, a) => f(...a)
1939
2194
  });
@@ -1992,12 +2247,12 @@ var InvitationsServiceImpl = class {
1992
2247
  };
1993
2248
 
1994
2249
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
1995
- import invariant8 from "tiny-invariant";
1996
2250
  import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
1997
2251
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2252
+ import { invariant as invariant8 } from "@dxos/invariant";
1998
2253
  import { log as log7 } from "@dxos/log";
1999
2254
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
2000
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2255
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2001
2256
  var SpaceInvitationProtocol = class {
2002
2257
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2003
2258
  this._spaceManager = _spaceManager;
@@ -2018,31 +2273,70 @@ var SpaceInvitationProtocol = class {
2018
2273
  };
2019
2274
  }
2020
2275
  async admit(request, guestProfile) {
2021
- var _a;
2022
- invariant8(this._spaceKey);
2276
+ invariant8(this._spaceKey, void 0, {
2277
+ F: __dxlog_file9,
2278
+ L: 42,
2279
+ S: this,
2280
+ A: [
2281
+ "this._spaceKey",
2282
+ ""
2283
+ ]
2284
+ });
2023
2285
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2024
- invariant8(space);
2025
- invariant8(request.space);
2286
+ invariant8(space, void 0, {
2287
+ F: __dxlog_file9,
2288
+ L: 44,
2289
+ S: this,
2290
+ A: [
2291
+ "space",
2292
+ ""
2293
+ ]
2294
+ });
2295
+ invariant8(request.space, void 0, {
2296
+ F: __dxlog_file9,
2297
+ L: 46,
2298
+ S: this,
2299
+ A: [
2300
+ "request.space",
2301
+ ""
2302
+ ]
2303
+ });
2026
2304
  const { identityKey, deviceKey } = request.space;
2027
2305
  log7("writing guest credentials", {
2028
2306
  host: this._signingContext.deviceKey,
2029
2307
  guest: deviceKey
2030
2308
  }, {
2031
- F: __dxlog_file7,
2032
- L: 50,
2309
+ F: __dxlog_file9,
2310
+ L: 49,
2033
2311
  S: this,
2034
2312
  C: (f, a) => f(...a)
2035
2313
  });
2036
2314
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2037
- invariant8(credentials[0].credential);
2315
+ invariant8(credentials[0].credential, void 0, {
2316
+ F: __dxlog_file9,
2317
+ L: 60,
2318
+ S: this,
2319
+ A: [
2320
+ "credentials[0].credential",
2321
+ ""
2322
+ ]
2323
+ });
2038
2324
  const spaceMemberCredential = credentials[0].credential.credential;
2039
- invariant8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2325
+ invariant8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2326
+ F: __dxlog_file9,
2327
+ L: 62,
2328
+ S: this,
2329
+ A: [
2330
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
2331
+ ""
2332
+ ]
2333
+ });
2040
2334
  await writeMessages2(space.inner.controlPipeline.writer, credentials);
2041
2335
  return {
2042
2336
  space: {
2043
2337
  credential: spaceMemberCredential,
2044
2338
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2045
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2339
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2046
2340
  }
2047
2341
  };
2048
2342
  }
@@ -2064,11 +2358,35 @@ var SpaceInvitationProtocol = class {
2064
2358
  };
2065
2359
  }
2066
2360
  async accept(response) {
2067
- invariant8(response.space);
2361
+ invariant8(response.space, void 0, {
2362
+ F: __dxlog_file9,
2363
+ L: 97,
2364
+ S: this,
2365
+ A: [
2366
+ "response.space",
2367
+ ""
2368
+ ]
2369
+ });
2068
2370
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2069
2371
  const assertion = getCredentialAssertion(credential);
2070
- invariant8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2071
- invariant8(credential.subject.id.equals(this._signingContext.identityKey));
2372
+ invariant8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2373
+ F: __dxlog_file9,
2374
+ L: 100,
2375
+ S: this,
2376
+ A: [
2377
+ "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
2378
+ "'Invalid credential'"
2379
+ ]
2380
+ });
2381
+ invariant8(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2382
+ F: __dxlog_file9,
2383
+ L: 101,
2384
+ S: this,
2385
+ A: [
2386
+ "credential.subject.id.equals(this._signingContext.identityKey)",
2387
+ ""
2388
+ ]
2389
+ });
2072
2390
  await this._spaceManager.acceptSpace({
2073
2391
  spaceKey: assertion.spaceKey,
2074
2392
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2122,9 +2440,8 @@ var ClientRpcServer = class {
2122
2440
  await this._rpcPeer.close();
2123
2441
  }
2124
2442
  _getServiceHandler(serviceName) {
2125
- var _a;
2126
2443
  if (!this._handlerCache.has(serviceName)) {
2127
- const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : raise(new Error(`Service not available: ${serviceName}`));
2444
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
2128
2445
  const service = this._serviceRegistry.services[key];
2129
2446
  if (!service) {
2130
2447
  throw new Error(`Service not available: ${serviceName}`);
@@ -2135,37 +2452,196 @@ var ClientRpcServer = class {
2135
2452
  }
2136
2453
  };
2137
2454
 
2455
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2456
+ import { getFirstStreamValue } from "@dxos/codec-protobuf";
2457
+ import { credentialTypeFilter } from "@dxos/credentials";
2458
+ import { DocumentModel } from "@dxos/document-model";
2459
+ import { TYPE_PROPERTIES } from "@dxos/echo-db";
2460
+ import { invariant as invariant9 } from "@dxos/invariant";
2461
+ import { log as log8 } from "@dxos/log";
2462
+ import { STORAGE_VERSION } from "@dxos/protocols";
2463
+ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2464
+
2465
+ // packages/sdk/client-services/src/version.ts
2466
+ var DXOS_VERSION = "0.1.56-main.e79d64a";
2467
+
2468
+ // packages/sdk/client-services/src/packlets/services/platform.ts
2469
+ var getPlatform = () => {
2470
+ if (process.browser) {
2471
+ if (typeof window !== "undefined") {
2472
+ const { userAgent } = window.navigator;
2473
+ return {
2474
+ type: "browser",
2475
+ userAgent,
2476
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2477
+ };
2478
+ } else {
2479
+ return {
2480
+ type: "shared-worker",
2481
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2482
+ };
2483
+ }
2484
+ } else {
2485
+ const { platform, version, arch } = process;
2486
+ return {
2487
+ type: "node",
2488
+ platform: `${platform} ${version} ${arch}`,
2489
+ runtime: process.version,
2490
+ uptime: Math.floor(process.uptime()),
2491
+ memory: process.memoryUsage()
2492
+ };
2493
+ }
2494
+ };
2495
+
2496
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2497
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2498
+ var DEFAULT_TIMEOUT = 1e3;
2499
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
2500
+ const diagnostics = {
2501
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2502
+ platform: getPlatform(),
2503
+ client: {
2504
+ version: DXOS_VERSION,
2505
+ storage: {
2506
+ version: STORAGE_VERSION
2507
+ }
2508
+ }
2509
+ };
2510
+ {
2511
+ invariant9(clientServices.LoggingService, "SystemService is not available.", {
2512
+ F: __dxlog_file10,
2513
+ L: 88,
2514
+ S: void 0,
2515
+ A: [
2516
+ "clientServices.LoggingService",
2517
+ "'SystemService is not available.'"
2518
+ ]
2519
+ });
2520
+ diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
2521
+ timeout: DEFAULT_TIMEOUT
2522
+ }).catch(() => void 0);
2523
+ }
2524
+ const identity = serviceContext.identityManager.identity;
2525
+ if (identity) {
2526
+ diagnostics.identity = {
2527
+ identityKey: identity.identityKey,
2528
+ spaceKey: identity.space.key,
2529
+ profile: identity.profileDocument
2530
+ };
2531
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2532
+ timeout: DEFAULT_TIMEOUT
2533
+ }).catch(() => void 0) ?? {};
2534
+ diagnostics.devices = devices;
2535
+ if (serviceContext.dataSpaceManager) {
2536
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2537
+ }
2538
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2539
+ timeout: DEFAULT_TIMEOUT
2540
+ }).catch(() => void 0) ?? {};
2541
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2542
+ feedKey,
2543
+ bytes,
2544
+ length
2545
+ }));
2546
+ }
2547
+ diagnostics.config = config.values;
2548
+ return diagnostics;
2549
+ };
2550
+ var getProperties = (space) => {
2551
+ let properties = {};
2552
+ try {
2553
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === DocumentModel.meta.type && item.state?.type === TYPE_PROPERTIES);
2554
+ const state = propertiesItem?.state;
2555
+ properties = state?.data;
2556
+ } catch (err) {
2557
+ log8.warn(err.message, void 0, {
2558
+ F: __dxlog_file10,
2559
+ L: 145,
2560
+ S: void 0,
2561
+ C: (f, a) => f(...a)
2562
+ });
2563
+ }
2564
+ return properties;
2565
+ };
2566
+ var getSpaceStats = async (space) => {
2567
+ const stats = {
2568
+ key: space.key,
2569
+ metrics: space.metrics,
2570
+ epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
2571
+ ...credential.subject.assertion,
2572
+ id: credential.id
2573
+ })),
2574
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2575
+ identity: {
2576
+ identityKey: member.key,
2577
+ profile: {
2578
+ displayName: member.assertion.profile?.displayName
2579
+ }
2580
+ },
2581
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2582
+ })),
2583
+ pipeline: {
2584
+ // TODO(burdon): Pick properties from credentials if needed.
2585
+ // currentEpoch: space.dataPipeline.currentEpoch,
2586
+ // appliedEpoch: space.dataPipeline.appliedEpoch,
2587
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2588
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2589
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2590
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2591
+ // TODO(burdon): Empty?
2592
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
2593
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
2594
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
2595
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
2596
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
2597
+ }
2598
+ };
2599
+ if (space.dataPipeline.itemManager) {
2600
+ Object.assign(stats, {
2601
+ properties: getProperties(space),
2602
+ db: {
2603
+ objects: space.dataPipeline.itemManager.entities.size
2604
+ }
2605
+ });
2606
+ }
2607
+ if (stats.metrics) {
2608
+ const { open, ready } = stats.metrics;
2609
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2610
+ }
2611
+ return stats;
2612
+ };
2613
+
2138
2614
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2139
2615
  import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2140
2616
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2141
- import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2617
+ import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2142
2618
  import { timed } from "@dxos/debug";
2143
2619
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2144
2620
  import { CancelledError, SystemError } from "@dxos/errors";
2145
2621
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2146
- import { log as log9 } from "@dxos/log";
2622
+ import { log as log10 } from "@dxos/log";
2147
2623
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2148
2624
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2149
- import { Timeframe } from "@dxos/timeframe";
2625
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2150
2626
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2151
2627
 
2152
2628
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2153
- import invariant9 from "tiny-invariant";
2154
2629
  import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2155
- import { Context as Context5, rejectOnDispose } from "@dxos/context";
2630
+ import { Context as Context6, rejectOnDispose } from "@dxos/context";
2631
+ import { invariant as invariant10 } from "@dxos/invariant";
2156
2632
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2157
- import { log as log8 } from "@dxos/log";
2633
+ import { log as log9 } from "@dxos/log";
2158
2634
  import { schema as schema3 } from "@dxos/protocols";
2159
2635
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2160
2636
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2161
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2637
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2162
2638
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2163
2639
  var DEFAULT_SUCCESS_DELAY = 1e3;
2164
2640
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2165
2641
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2166
2642
  var NotarizationPlugin = class {
2167
2643
  constructor() {
2168
- this._ctx = new Context5();
2644
+ this._ctx = new Context6();
2169
2645
  this._extensionOpened = new Event4();
2170
2646
  this._extensions = /* @__PURE__ */ new Set();
2171
2647
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
@@ -2183,23 +2659,31 @@ var NotarizationPlugin = class {
2183
2659
  * Request credentials to be notarized.
2184
2660
  */
2185
2661
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2186
- log8("notarize", {
2662
+ log9("notarize", {
2187
2663
  credentials
2188
2664
  }, {
2189
- F: __dxlog_file8,
2190
- L: 91,
2665
+ F: __dxlog_file11,
2666
+ L: 90,
2191
2667
  S: this,
2192
2668
  C: (f, a) => f(...a)
2193
2669
  });
2194
- invariant9(credentials.every((credential) => credential.id), "Credentials must have an id");
2670
+ invariant10(credentials.every((credential) => credential.id), "Credentials must have an id", {
2671
+ F: __dxlog_file11,
2672
+ L: 91,
2673
+ S: this,
2674
+ A: [
2675
+ "credentials.every((credential) => credential.id)",
2676
+ "'Credentials must have an id'"
2677
+ ]
2678
+ });
2195
2679
  const errors = new Trigger4();
2196
2680
  const ctx = this._ctx.derive({
2197
2681
  onError: (err) => {
2198
- log8.warn("Notarization error", {
2682
+ log9.warn("Notarization error", {
2199
2683
  err
2200
2684
  }, {
2201
- F: __dxlog_file8,
2202
- L: 100,
2685
+ F: __dxlog_file11,
2686
+ L: 99,
2203
2687
  S: this,
2204
2688
  C: (f, a) => f(...a)
2205
2689
  });
@@ -2207,15 +2691,15 @@ var NotarizationPlugin = class {
2207
2691
  errors.throw(err);
2208
2692
  }
2209
2693
  });
2210
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2694
+ opCtx?.onDispose(() => ctx.dispose());
2211
2695
  if (timeout !== 0) {
2212
2696
  scheduleTask3(ctx, () => {
2213
- log8.warn("Notarization timeout", {
2697
+ log9.warn("Notarization timeout", {
2214
2698
  timeout,
2215
2699
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2216
2700
  }, {
2217
- F: __dxlog_file8,
2218
- L: 112,
2701
+ F: __dxlog_file11,
2702
+ L: 111,
2219
2703
  S: this,
2220
2704
  C: (f, a) => f(...a)
2221
2705
  });
@@ -2234,11 +2718,11 @@ var NotarizationPlugin = class {
2234
2718
  ...this._extensions
2235
2719
  ].find((peer2) => !peersTried.has(peer2));
2236
2720
  if (!peer) {
2237
- log8.warn("Exhausted all peers to notarize with", {
2721
+ log9.warn("Exhausted all peers to notarize with", {
2238
2722
  retryIn: retryTimeout
2239
2723
  }, {
2240
- F: __dxlog_file8,
2241
- L: 137,
2724
+ F: __dxlog_file11,
2725
+ L: 136,
2242
2726
  S: this,
2243
2727
  C: (f, a) => f(...a)
2244
2728
  });
@@ -2247,30 +2731,30 @@ var NotarizationPlugin = class {
2247
2731
  return;
2248
2732
  }
2249
2733
  peersTried.add(peer);
2250
- log8("try notarizing", {
2734
+ log9("try notarizing", {
2251
2735
  peer: peer.localPeerId,
2252
2736
  credentialId: credentials.map((credential) => credential.id)
2253
2737
  }, {
2254
- F: __dxlog_file8,
2255
- L: 144,
2738
+ F: __dxlog_file11,
2739
+ L: 143,
2256
2740
  S: this,
2257
2741
  C: (f, a) => f(...a)
2258
2742
  });
2259
2743
  await peer.rpc.NotarizationService.notarize({
2260
2744
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2261
2745
  });
2262
- log8("success", void 0, {
2263
- F: __dxlog_file8,
2264
- L: 148,
2746
+ log9("success", void 0, {
2747
+ F: __dxlog_file11,
2748
+ L: 147,
2265
2749
  S: this,
2266
2750
  C: (f, a) => f(...a)
2267
2751
  });
2268
2752
  await sleep(successDelay);
2269
2753
  } catch (err) {
2270
2754
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2271
- log8.warn("error notarizing (recoverable)", err, {
2272
- F: __dxlog_file8,
2273
- L: 152,
2755
+ log9.warn("error notarizing (recoverable)", err, {
2756
+ F: __dxlog_file11,
2757
+ L: 151,
2274
2758
  S: this,
2275
2759
  C: (f, a) => f(...a)
2276
2760
  });
@@ -2286,9 +2770,9 @@ var NotarizationPlugin = class {
2286
2770
  allNotarized,
2287
2771
  errors.wait()
2288
2772
  ]);
2289
- log8("done", void 0, {
2290
- F: __dxlog_file8,
2291
- L: 163,
2773
+ log9("done", void 0, {
2774
+ F: __dxlog_file11,
2775
+ L: 162,
2292
2776
  S: this,
2293
2777
  C: (f, a) => f(...a)
2294
2778
  });
@@ -2300,16 +2784,23 @@ var NotarizationPlugin = class {
2300
2784
  * Called with credentials arriving from the control pipeline.
2301
2785
  */
2302
2786
  async processCredential(credential) {
2303
- var _a;
2304
2787
  if (!credential.id) {
2305
2788
  return;
2306
2789
  }
2307
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2790
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2308
2791
  this._processedCredentials.add(credential.id);
2309
2792
  this._processCredentialsTriggers.delete(credential.id);
2310
2793
  }
2311
2794
  setWriter(writer) {
2312
- invariant9(!this._writer, "Writer already set.");
2795
+ invariant10(!this._writer, "Writer already set.", {
2796
+ F: __dxlog_file11,
2797
+ L: 181,
2798
+ S: this,
2799
+ A: [
2800
+ "!this._writer",
2801
+ "'Writer already set.'"
2802
+ ]
2803
+ });
2313
2804
  this._writer = writer;
2314
2805
  }
2315
2806
  async _waitUntilProcessed(id) {
@@ -2322,12 +2813,19 @@ var NotarizationPlugin = class {
2322
2813
  * Requests from other peers to notarize credentials.
2323
2814
  */
2324
2815
  async _onNotarize(request) {
2325
- var _a;
2326
2816
  if (!this._writer) {
2327
2817
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2328
2818
  }
2329
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2330
- invariant9(credential.id, "Credential must have an id");
2819
+ for (const credential of request.credentials ?? []) {
2820
+ invariant10(credential.id, "Credential must have an id", {
2821
+ F: __dxlog_file11,
2822
+ L: 200,
2823
+ S: this,
2824
+ A: [
2825
+ "credential.id",
2826
+ "'Credential must have an id'"
2827
+ ]
2828
+ });
2331
2829
  if (this._processedCredentials.has(credential.id)) {
2332
2830
  continue;
2333
2831
  }
@@ -2337,11 +2835,11 @@ var NotarizationPlugin = class {
2337
2835
  createExtension() {
2338
2836
  const extension = new NotarizationTeleportExtension({
2339
2837
  onOpen: async () => {
2340
- log8("extension opened", {
2838
+ log9("extension opened", {
2341
2839
  peer: extension.localPeerId
2342
2840
  }, {
2343
- F: __dxlog_file8,
2344
- L: 212,
2841
+ F: __dxlog_file11,
2842
+ L: 211,
2345
2843
  S: this,
2346
2844
  C: (f, a) => f(...a)
2347
2845
  });
@@ -2349,11 +2847,11 @@ var NotarizationPlugin = class {
2349
2847
  this._extensionOpened.emit();
2350
2848
  },
2351
2849
  onClose: async () => {
2352
- log8("extension closed", {
2850
+ log9("extension closed", {
2353
2851
  peer: extension.localPeerId
2354
2852
  }, {
2355
- F: __dxlog_file8,
2356
- L: 217,
2853
+ F: __dxlog_file11,
2854
+ L: 216,
2357
2855
  S: this,
2358
2856
  C: (f, a) => f(...a)
2359
2857
  });
@@ -2396,7 +2894,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2396
2894
  };
2397
2895
 
2398
2896
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2399
- function _ts_decorate(decorators, target, key, desc) {
2897
+ function _ts_decorate3(decorators, target, key, desc) {
2400
2898
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2401
2899
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2402
2900
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2406,10 +2904,11 @@ function _ts_decorate(decorators, target, key, desc) {
2406
2904
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2407
2905
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2408
2906
  }
2409
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2907
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2908
+ var ENABLE_FEED_PURGE = false;
2410
2909
  var DataSpace = class DataSpace2 {
2411
2910
  constructor(params) {
2412
- this._ctx = new Context6();
2911
+ this._ctx = new Context7();
2413
2912
  this._notarizationPlugin = new NotarizationPlugin();
2414
2913
  this._state = SpaceState.CLOSED;
2415
2914
  /**
@@ -2418,7 +2917,6 @@ var DataSpace = class DataSpace2 {
2418
2917
  this.error = void 0;
2419
2918
  this.stateUpdate = new Event5();
2420
2919
  this.metrics = {};
2421
- var _a;
2422
2920
  this._inner = params.inner;
2423
2921
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2424
2922
  this._gossip = params.gossip;
@@ -2427,7 +2925,7 @@ var DataSpace = class DataSpace2 {
2427
2925
  this._feedStore = params.feedStore;
2428
2926
  this._metadataStore = params.metadataStore;
2429
2927
  this._signingContext = params.signingContext;
2430
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2928
+ this._callbacks = params.callbacks ?? {};
2431
2929
  this.authVerifier = new TrustedKeySetAuthVerifier({
2432
2930
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2433
2931
  update: this._inner.stateUpdate,
@@ -2467,21 +2965,20 @@ var DataSpace = class DataSpace2 {
2467
2965
  async _open() {
2468
2966
  await this._notarizationPlugin.open();
2469
2967
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2470
- await this._inner.open();
2968
+ await this._inner.open(new Context7());
2471
2969
  this._state = SpaceState.CONTROL_ONLY;
2472
2970
  this.stateUpdate.emit();
2473
2971
  this.metrics = {};
2474
- this.metrics.open = new Date();
2972
+ this.metrics.open = /* @__PURE__ */ new Date();
2475
2973
  }
2476
2974
  async close() {
2477
2975
  await this._close();
2478
2976
  }
2479
2977
  async _close() {
2480
- var _a, _b;
2481
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2978
+ await this._callbacks.beforeClose?.();
2482
2979
  this._state = SpaceState.CLOSED;
2483
2980
  await this._ctx.dispose();
2484
- this._ctx = new Context6();
2981
+ this._ctx = new Context7();
2485
2982
  await this.authVerifier.close();
2486
2983
  await this._inner.close();
2487
2984
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
@@ -2500,21 +2997,21 @@ var DataSpace = class DataSpace2 {
2500
2997
  initializeDataPipelineAsync() {
2501
2998
  scheduleTask4(this._ctx, async () => {
2502
2999
  try {
2503
- this.metrics.pipelineInitBegin = new Date();
3000
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2504
3001
  await this.initializeDataPipeline();
2505
3002
  } catch (err) {
2506
3003
  if (err instanceof CancelledError) {
2507
- log9("data pipeline initialization cancelled", err, {
2508
- F: __dxlog_file9,
2509
- L: 193,
3004
+ log10("data pipeline initialization cancelled", err, {
3005
+ F: __dxlog_file12,
3006
+ L: 199,
2510
3007
  S: this,
2511
3008
  C: (f, a) => f(...a)
2512
3009
  });
2513
3010
  return;
2514
3011
  }
2515
- log9.error("Error initializing data pipeline", err, {
2516
- F: __dxlog_file9,
2517
- L: 197,
3012
+ log10.error("Error initializing data pipeline", err, {
3013
+ F: __dxlog_file12,
3014
+ L: 203,
2518
3015
  S: this,
2519
3016
  C: (f, a) => f(...a)
2520
3017
  });
@@ -2522,12 +3019,11 @@ var DataSpace = class DataSpace2 {
2522
3019
  this.error = err;
2523
3020
  this.stateUpdate.emit();
2524
3021
  } finally {
2525
- this.metrics.ready = new Date();
3022
+ this.metrics.ready = /* @__PURE__ */ new Date();
2526
3023
  }
2527
3024
  });
2528
3025
  }
2529
3026
  async initializeDataPipeline() {
2530
- var _a, _b, _c, _d;
2531
3027
  if (this._state !== SpaceState.CONTROL_ONLY) {
2532
3028
  throw new SystemError("Invalid operation");
2533
3029
  }
@@ -2536,11 +3032,11 @@ var DataSpace = class DataSpace2 {
2536
3032
  ctx: this._ctx,
2537
3033
  breakOnStall: false
2538
3034
  });
2539
- this.metrics.controlPipelineReady = new Date();
3035
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
2540
3036
  await this._createWritableFeeds();
2541
- log9("writable feeds created", void 0, {
2542
- F: __dxlog_file9,
2543
- L: 221,
3037
+ log10("writable feeds created", void 0, {
3038
+ F: __dxlog_file12,
3039
+ L: 227,
2544
3040
  S: this,
2545
3041
  C: (f, a) => f(...a)
2546
3042
  });
@@ -2553,11 +3049,11 @@ var DataSpace = class DataSpace2 {
2553
3049
  }), this._inner.controlPipeline.writer));
2554
3050
  }
2555
3051
  await this._inner.initializeDataPipeline();
2556
- this.metrics.dataPipelineOpen = new Date();
3052
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
2557
3053
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2558
- log9("waiting for data pipeline to reach target timeframe", void 0, {
2559
- F: __dxlog_file9,
2560
- L: 242,
3054
+ log10("waiting for data pipeline to reach target timeframe", void 0, {
3055
+ F: __dxlog_file12,
3056
+ L: 248,
2561
3057
  S: this,
2562
3058
  C: (f, a) => f(...a)
2563
3059
  });
@@ -2565,17 +3061,17 @@ var DataSpace = class DataSpace2 {
2565
3061
  ctx: this._ctx,
2566
3062
  breakOnStall: false
2567
3063
  });
2568
- this.metrics.dataPipelineReady = new Date();
2569
- log9("data pipeline ready", void 0, {
2570
- F: __dxlog_file9,
2571
- L: 251,
3064
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3065
+ log10("data pipeline ready", void 0, {
3066
+ F: __dxlog_file12,
3067
+ L: 257,
2572
3068
  S: this,
2573
3069
  C: (f, a) => f(...a)
2574
3070
  });
2575
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3071
+ await this._callbacks.beforeReady?.();
2576
3072
  this._state = SpaceState.READY;
2577
3073
  this.stateUpdate.emit();
2578
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3074
+ await this._callbacks.afterReady?.();
2579
3075
  }
2580
3076
  async _createWritableFeeds() {
2581
3077
  const credentials = [];
@@ -2622,7 +3118,6 @@ var DataSpace = class DataSpace2 {
2622
3118
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2623
3119
  }
2624
3120
  async createEpoch() {
2625
- var _a, _b;
2626
3121
  const epoch = await this.dataPipeline.createEpoch();
2627
3122
  const receipt = await this.inner.controlPipeline.writer.write({
2628
3123
  credential: {
@@ -2635,16 +3130,19 @@ var DataSpace = class DataSpace2 {
2635
3130
  })
2636
3131
  }
2637
3132
  });
2638
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
3133
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
2639
3134
  [
2640
3135
  receipt.feedKey,
2641
3136
  receipt.seq
2642
3137
  ]
2643
3138
  ]));
2644
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2645
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2646
- if (indexBeforeEpoch) {
2647
- await feed.clear(0, indexBeforeEpoch + 1);
3139
+ if (ENABLE_FEED_PURGE) {
3140
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
3141
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3142
+ if (indexBeforeEpoch === void 0) {
3143
+ continue;
3144
+ }
3145
+ await feed.safeClear(0, indexBeforeEpoch + 1);
2648
3146
  }
2649
3147
  }
2650
3148
  }
@@ -2666,33 +3164,33 @@ var DataSpace = class DataSpace2 {
2666
3164
  this.stateUpdate.emit();
2667
3165
  }
2668
3166
  };
2669
- _ts_decorate([
3167
+ _ts_decorate3([
2670
3168
  synchronized
2671
3169
  ], DataSpace.prototype, "open", null);
2672
- _ts_decorate([
3170
+ _ts_decorate3([
2673
3171
  synchronized
2674
3172
  ], DataSpace.prototype, "close", null);
2675
- _ts_decorate([
3173
+ _ts_decorate3([
2676
3174
  timed(1e4)
2677
3175
  ], DataSpace.prototype, "_createWritableFeeds", null);
2678
- _ts_decorate([
3176
+ _ts_decorate3([
2679
3177
  synchronized
2680
3178
  ], DataSpace.prototype, "activate", null);
2681
- _ts_decorate([
3179
+ _ts_decorate3([
2682
3180
  synchronized
2683
3181
  ], DataSpace.prototype, "deactivate", null);
2684
- DataSpace = _ts_decorate([
3182
+ DataSpace = _ts_decorate3([
2685
3183
  trackLeaks("open", "close")
2686
3184
  ], DataSpace);
2687
3185
 
2688
3186
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2689
- import invariant10 from "tiny-invariant";
2690
3187
  import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
2691
- import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
3188
+ import { cancelWithContext as cancelWithContext3, Context as Context8 } from "@dxos/context";
2692
3189
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3190
+ import { invariant as invariant11 } from "@dxos/invariant";
2693
3191
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2694
- import { log as log10 } from "@dxos/log";
2695
- import { trace as trace4 } from "@dxos/protocols";
3192
+ import { log as log11 } from "@dxos/log";
3193
+ import { trace as trace5 } from "@dxos/protocols";
2696
3194
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2697
3195
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2698
3196
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
@@ -2700,10 +3198,9 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
2700
3198
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
2701
3199
  import { createCredential } from "@dxos/credentials";
2702
3200
  import { failUndefined as failUndefined2 } from "@dxos/debug";
2703
- import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2704
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3201
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3202
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
2705
3203
  var spaceGenesis = async (keyring, signingContext, space) => {
2706
- var _a, _b, _c, _d;
2707
3204
  const credentials = [
2708
3205
  await createCredential({
2709
3206
  signer: keyring,
@@ -2721,13 +3218,13 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2721
3218
  assertion: {
2722
3219
  "@type": "dxos.halo.credentials.SpaceMember",
2723
3220
  spaceKey: space.key,
2724
- role: SpaceMember.Role.ADMIN,
3221
+ role: SpaceMember2.Role.ADMIN,
2725
3222
  profile: signingContext.profile,
2726
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3223
+ genesisFeedKey: space.controlFeedKey ?? failUndefined2()
2727
3224
  }
2728
3225
  }),
2729
3226
  await signingContext.credentialSigner.createCredential({
2730
- subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
3227
+ subject: space.controlFeedKey ?? failUndefined2(),
2731
3228
  assertion: {
2732
3229
  "@type": "dxos.halo.credentials.AdmittedFeed",
2733
3230
  spaceKey: space.key,
@@ -2737,7 +3234,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2737
3234
  }
2738
3235
  }),
2739
3236
  await signingContext.credentialSigner.createCredential({
2740
- subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
3237
+ subject: space.dataFeedKey ?? failUndefined2(),
2741
3238
  assertion: {
2742
3239
  "@type": "dxos.halo.credentials.AdmittedFeed",
2743
3240
  spaceKey: space.key,
@@ -2747,12 +3244,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2747
3244
  }
2748
3245
  }),
2749
3246
  await signingContext.credentialSigner.createCredential({
2750
- subject: (_d = space.key) != null ? _d : failUndefined2(),
3247
+ subject: space.key ?? failUndefined2(),
2751
3248
  assertion: {
2752
3249
  "@type": "dxos.halo.credentials.Epoch",
2753
3250
  number: 0,
2754
3251
  previousId: void 0,
2755
- timeframe: new Timeframe2(),
3252
+ timeframe: new Timeframe3(),
2756
3253
  snapshotCid: void 0
2757
3254
  }
2758
3255
  })
@@ -2768,7 +3265,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2768
3265
  };
2769
3266
 
2770
3267
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2771
- function _ts_decorate2(decorators, target, key, desc) {
3268
+ function _ts_decorate4(decorators, target, key, desc) {
2772
3269
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2773
3270
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2774
3271
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2778,7 +3275,7 @@ function _ts_decorate2(decorators, target, key, desc) {
2778
3275
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2779
3276
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2780
3277
  }
2781
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3278
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
2782
3279
  var DataSpaceManager = class DataSpaceManager2 {
2783
3280
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore) {
2784
3281
  this._spaceManager = _spaceManager;
@@ -2787,7 +3284,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2787
3284
  this._keyring = _keyring;
2788
3285
  this._signingContext = _signingContext;
2789
3286
  this._feedStore = _feedStore;
2790
- this._ctx = new Context7();
3287
+ this._ctx = new Context8();
2791
3288
  this.updated = new Event6();
2792
3289
  this._spaces = new ComplexMap3(PublicKey8.hash);
2793
3290
  this._isOpen = false;
@@ -2798,36 +3295,36 @@ var DataSpaceManager = class DataSpaceManager2 {
2798
3295
  return this._spaces;
2799
3296
  }
2800
3297
  async open() {
2801
- log10("open", void 0, {
2802
- F: __dxlog_file10,
2803
- L: 80,
3298
+ log11("open", void 0, {
3299
+ F: __dxlog_file13,
3300
+ L: 79,
2804
3301
  S: this,
2805
3302
  C: (f, a) => f(...a)
2806
3303
  });
2807
- log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
3304
+ log11.trace("dxos.echo.data-space-manager.open", trace5.begin({
2808
3305
  id: this._instanceId
2809
3306
  }), {
2810
- F: __dxlog_file10,
2811
- L: 81,
3307
+ F: __dxlog_file13,
3308
+ L: 80,
2812
3309
  S: this,
2813
3310
  C: (f, a) => f(...a)
2814
3311
  });
2815
3312
  await this._metadataStore.load();
2816
- log10("metadata loaded", {
3313
+ log11("metadata loaded", {
2817
3314
  spaces: this._metadataStore.spaces.length
2818
3315
  }, {
2819
- F: __dxlog_file10,
2820
- L: 83,
3316
+ F: __dxlog_file13,
3317
+ L: 82,
2821
3318
  S: this,
2822
3319
  C: (f, a) => f(...a)
2823
3320
  });
2824
3321
  for (const spaceMetadata of this._metadataStore.spaces) {
2825
3322
  try {
2826
- log10("load space", {
3323
+ log11("load space", {
2827
3324
  spaceMetadata
2828
3325
  }, {
2829
- F: __dxlog_file10,
2830
- L: 87,
3326
+ F: __dxlog_file13,
3327
+ L: 86,
2831
3328
  S: this,
2832
3329
  C: (f, a) => f(...a)
2833
3330
  });
@@ -2836,12 +3333,12 @@ var DataSpaceManager = class DataSpaceManager2 {
2836
3333
  space.initializeDataPipelineAsync();
2837
3334
  }
2838
3335
  } catch (err) {
2839
- log10.error("Error loading space", {
3336
+ log11.error("Error loading space", {
2840
3337
  spaceMetadata,
2841
3338
  err
2842
3339
  }, {
2843
- F: __dxlog_file10,
2844
- L: 93,
3340
+ F: __dxlog_file13,
3341
+ L: 92,
2845
3342
  S: this,
2846
3343
  C: (f, a) => f(...a)
2847
3344
  });
@@ -2849,19 +3346,19 @@ var DataSpaceManager = class DataSpaceManager2 {
2849
3346
  }
2850
3347
  this._isOpen = true;
2851
3348
  this.updated.emit();
2852
- log10.trace("dxos.echo.data-space-manager.open", trace4.end({
3349
+ log11.trace("dxos.echo.data-space-manager.open", trace5.end({
2853
3350
  id: this._instanceId
2854
3351
  }), {
2855
- F: __dxlog_file10,
2856
- L: 99,
3352
+ F: __dxlog_file13,
3353
+ L: 98,
2857
3354
  S: this,
2858
3355
  C: (f, a) => f(...a)
2859
3356
  });
2860
3357
  }
2861
3358
  async close() {
2862
- log10("close", void 0, {
2863
- F: __dxlog_file10,
2864
- L: 104,
3359
+ log11("close", void 0, {
3360
+ F: __dxlog_file13,
3361
+ L: 103,
2865
3362
  S: this,
2866
3363
  C: (f, a) => f(...a)
2867
3364
  });
@@ -2875,7 +3372,15 @@ var DataSpaceManager = class DataSpaceManager2 {
2875
3372
  * Creates a new space writing the genesis credentials to the control feed.
2876
3373
  */
2877
3374
  async createSpace() {
2878
- invariant10(this._isOpen, "Not open.");
3375
+ invariant11(this._isOpen, "Not open.", {
3376
+ F: __dxlog_file13,
3377
+ L: 116,
3378
+ S: this,
3379
+ A: [
3380
+ "this._isOpen",
3381
+ "'Not open.'"
3382
+ ]
3383
+ });
2879
3384
  const spaceKey = await this._keyring.createKey();
2880
3385
  const controlFeedKey = await this._keyring.createKey();
2881
3386
  const dataFeedKey = await this._keyring.createKey();
@@ -2886,11 +3391,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2886
3391
  dataFeedKey,
2887
3392
  state: SpaceState2.ACTIVE
2888
3393
  };
2889
- log10("creating space...", {
3394
+ log11("creating space...", {
2890
3395
  spaceKey
2891
3396
  }, {
2892
- F: __dxlog_file10,
2893
- L: 129,
3397
+ F: __dxlog_file13,
3398
+ L: 128,
2894
3399
  S: this,
2895
3400
  C: (f, a) => f(...a)
2896
3401
  });
@@ -2898,7 +3403,15 @@ var DataSpaceManager = class DataSpaceManager2 {
2898
3403
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
2899
3404
  await this._metadataStore.addSpace(metadata);
2900
3405
  const memberCredential = credentials[1];
2901
- invariant10(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
3406
+ invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3407
+ F: __dxlog_file13,
3408
+ L: 135,
3409
+ S: this,
3410
+ A: [
3411
+ "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
3412
+ ""
3413
+ ]
3414
+ });
2902
3415
  await this._signingContext.recordCredential(memberCredential);
2903
3416
  await space.initializeDataPipeline();
2904
3417
  this.updated.emit();
@@ -2906,16 +3419,32 @@ var DataSpaceManager = class DataSpaceManager2 {
2906
3419
  }
2907
3420
  // TODO(burdon): Rename join space.
2908
3421
  async acceptSpace(opts) {
2909
- log10("accept space", {
3422
+ log11("accept space", {
2910
3423
  opts
2911
3424
  }, {
2912
- F: __dxlog_file10,
2913
- L: 148,
3425
+ F: __dxlog_file13,
3426
+ L: 147,
2914
3427
  S: this,
2915
3428
  C: (f, a) => f(...a)
2916
3429
  });
2917
- invariant10(this._isOpen, "Not open.");
2918
- invariant10(!this._spaces.has(opts.spaceKey), "Space already exists.");
3430
+ invariant11(this._isOpen, "Not open.", {
3431
+ F: __dxlog_file13,
3432
+ L: 148,
3433
+ S: this,
3434
+ A: [
3435
+ "this._isOpen",
3436
+ "'Not open.'"
3437
+ ]
3438
+ });
3439
+ invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3440
+ F: __dxlog_file13,
3441
+ L: 149,
3442
+ S: this,
3443
+ A: [
3444
+ "!this._spaces.has(opts.spaceKey)",
3445
+ "'Space already exists.'"
3446
+ ]
3447
+ });
2919
3448
  const metadata = {
2920
3449
  key: opts.spaceKey,
2921
3450
  genesisFeedKey: opts.genesisFeedKey,
@@ -2940,11 +3469,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2940
3469
  }));
2941
3470
  }
2942
3471
  async _constructSpace(metadata) {
2943
- log10("construct space", {
3472
+ log11("construct space", {
2944
3473
  metadata
2945
3474
  }, {
2946
- F: __dxlog_file10,
2947
- L: 183,
3475
+ F: __dxlog_file13,
3476
+ L: 182,
2948
3477
  S: this,
2949
3478
  C: (f, a) => f(...a)
2950
3479
  });
@@ -2952,7 +3481,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2952
3481
  localPeerId: this._signingContext.deviceKey
2953
3482
  });
2954
3483
  const presence = new Presence({
2955
- announceInterval: 500,
3484
+ announceInterval: 1e3,
2956
3485
  offlineTimeout: 5e3,
2957
3486
  identityKey: this._signingContext.identityKey,
2958
3487
  gossip
@@ -2978,9 +3507,9 @@ var DataSpaceManager = class DataSpaceManager2 {
2978
3507
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2979
3508
  },
2980
3509
  onAuthFailure: () => {
2981
- log10.warn("auth failure", void 0, {
2982
- F: __dxlog_file10,
2983
- L: 214,
3510
+ log11.warn("auth failure", void 0, {
3511
+ F: __dxlog_file13,
3512
+ L: 217,
2984
3513
  S: this,
2985
3514
  C: (f, a) => f(...a)
2986
3515
  });
@@ -3000,23 +3529,23 @@ var DataSpaceManager = class DataSpaceManager2 {
3000
3529
  signingContext: this._signingContext,
3001
3530
  callbacks: {
3002
3531
  beforeReady: async () => {
3003
- log10("before space ready", {
3532
+ log11("before space ready", {
3004
3533
  space: space.key
3005
3534
  }, {
3006
- F: __dxlog_file10,
3007
- L: 232,
3535
+ F: __dxlog_file13,
3536
+ L: 235,
3008
3537
  S: this,
3009
3538
  C: (f, a) => f(...a)
3010
3539
  });
3011
3540
  await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3012
3541
  },
3013
3542
  afterReady: async () => {
3014
- log10("after space ready", {
3543
+ log11("after space ready", {
3015
3544
  space: space.key,
3016
3545
  open: this._isOpen
3017
3546
  }, {
3018
- F: __dxlog_file10,
3019
- L: 239,
3547
+ F: __dxlog_file13,
3548
+ L: 242,
3020
3549
  S: this,
3021
3550
  C: (f, a) => f(...a)
3022
3551
  });
@@ -3025,11 +3554,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3025
3554
  }
3026
3555
  },
3027
3556
  beforeClose: async () => {
3028
- log10("before space close", {
3557
+ log11("before space close", {
3029
3558
  space: space.key
3030
3559
  }, {
3031
- F: __dxlog_file10,
3032
- L: 245,
3560
+ F: __dxlog_file13,
3561
+ L: 248,
3033
3562
  S: this,
3034
3563
  C: (f, a) => f(...a)
3035
3564
  });
@@ -3051,19 +3580,19 @@ var DataSpaceManager = class DataSpaceManager2 {
3051
3580
  return dataSpace;
3052
3581
  }
3053
3582
  };
3054
- _ts_decorate2([
3583
+ _ts_decorate4([
3055
3584
  synchronized2
3056
3585
  ], DataSpaceManager.prototype, "open", null);
3057
- _ts_decorate2([
3586
+ _ts_decorate4([
3058
3587
  synchronized2
3059
3588
  ], DataSpaceManager.prototype, "close", null);
3060
- _ts_decorate2([
3589
+ _ts_decorate4([
3061
3590
  synchronized2
3062
3591
  ], DataSpaceManager.prototype, "createSpace", null);
3063
- _ts_decorate2([
3592
+ _ts_decorate4([
3064
3593
  synchronized2
3065
3594
  ], DataSpaceManager.prototype, "acceptSpace", null);
3066
- DataSpaceManager = _ts_decorate2([
3595
+ DataSpaceManager = _ts_decorate4([
3067
3596
  trackLeaks2("open", "close")
3068
3597
  ], DataSpaceManager);
3069
3598
 
@@ -3073,11 +3602,11 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
3073
3602
  import { raise as raise2 } from "@dxos/debug";
3074
3603
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3075
3604
  import { ApiError } from "@dxos/errors";
3076
- import { log as log11 } from "@dxos/log";
3605
+ import { log as log12 } from "@dxos/log";
3077
3606
  import { encodeError } from "@dxos/protocols";
3078
- import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3607
+ import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3079
3608
  import { humanize } from "@dxos/util";
3080
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3609
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3081
3610
  var SpacesServiceImpl = class {
3082
3611
  constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
3083
3612
  this._identityManager = _identityManager;
@@ -3094,9 +3623,8 @@ var SpacesServiceImpl = class {
3094
3623
  return this._serializeSpace(space);
3095
3624
  }
3096
3625
  async updateSpace({ spaceKey, state }) {
3097
- var _a;
3098
3626
  const dataSpaceManager = await this._getDataSpaceManager();
3099
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3627
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3100
3628
  if (state) {
3101
3629
  switch (state) {
3102
3630
  case SpaceState3.ACTIVE:
@@ -3115,10 +3643,10 @@ var SpacesServiceImpl = class {
3115
3643
  const scheduler = new UpdateScheduler(ctx, async () => {
3116
3644
  const dataSpaceManager = await this._getDataSpaceManager();
3117
3645
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
3118
- log11("update", {
3646
+ log12("update", {
3119
3647
  spaces
3120
3648
  }, {
3121
- F: __dxlog_file11,
3649
+ F: __dxlog_file14,
3122
3650
  L: 78,
3123
3651
  S: this,
3124
3652
  C: (f, a) => f(...a)
@@ -3127,7 +3655,7 @@ var SpacesServiceImpl = class {
3127
3655
  spaces
3128
3656
  });
3129
3657
  }, {
3130
- maxFrequency: 2
3658
+ maxFrequency: false ? void 0 : 2
3131
3659
  });
3132
3660
  scheduleTask5(ctx, async () => {
3133
3661
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -3160,17 +3688,15 @@ var SpacesServiceImpl = class {
3160
3688
  });
3161
3689
  }
3162
3690
  async postMessage({ spaceKey, channel, message }) {
3163
- var _a;
3164
3691
  const dataSpaceManager = await this._getDataSpaceManager();
3165
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3692
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3166
3693
  await space.postMessage(getChannelId(channel), message);
3167
3694
  }
3168
3695
  subscribeMessages({ spaceKey, channel }) {
3169
3696
  return new Stream10(({ ctx, next }) => {
3170
3697
  scheduleTask5(ctx, async () => {
3171
- var _a;
3172
3698
  const dataSpaceManager = await this._getDataSpaceManager();
3173
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3699
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3174
3700
  const handle = space.listen(getChannelId(channel), (message) => {
3175
3701
  next(message);
3176
3702
  });
@@ -3180,8 +3706,7 @@ var SpacesServiceImpl = class {
3180
3706
  }
3181
3707
  queryCredentials({ spaceKey }) {
3182
3708
  return new Stream10(({ ctx, next }) => {
3183
- var _a;
3184
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3709
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3185
3710
  const processor = {
3186
3711
  processCredential: async (credential) => {
3187
3712
  next(credential);
@@ -3192,9 +3717,8 @@ var SpacesServiceImpl = class {
3192
3717
  });
3193
3718
  }
3194
3719
  async writeCredentials({ spaceKey, credentials }) {
3195
- var _a;
3196
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3197
- for (const credential of credentials != null ? credentials : []) {
3720
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3721
+ for (const credential of credentials ?? []) {
3198
3722
  await space.controlPipeline.writer.write({
3199
3723
  credential: {
3200
3724
  credential
@@ -3203,13 +3727,11 @@ var SpacesServiceImpl = class {
3203
3727
  }
3204
3728
  }
3205
3729
  async createEpoch({ spaceKey }) {
3206
- var _a;
3207
3730
  const dataSpaceManager = await this._getDataSpaceManager();
3208
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3731
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3209
3732
  await space.createEpoch();
3210
3733
  }
3211
3734
  _serializeSpace(space) {
3212
- var _a, _b, _c, _d, _e, _f, _g;
3213
3735
  return {
3214
3736
  spaceKey: space.key,
3215
3737
  state: space.state,
@@ -3221,25 +3743,30 @@ var SpacesServiceImpl = class {
3221
3743
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3222
3744
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3223
3745
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3224
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3225
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3226
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3227
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3228
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3746
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
3747
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
3748
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
3749
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
3750
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
3229
3751
  },
3230
3752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3231
- var _a2, _b2, _c2;
3753
+ const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3754
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3755
+ if (isMe) {
3756
+ peers.push(space.presence.getLocalState());
3757
+ }
3232
3758
  return {
3233
3759
  identity: {
3234
3760
  identityKey: member.key,
3235
3761
  profile: {
3236
- displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : humanize(member.key)
3762
+ displayName: member.assertion.profile?.displayName ?? humanize(member.key)
3237
3763
  }
3238
3764
  },
3239
- presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE
3765
+ presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3766
+ peerStates: peers
3240
3767
  };
3241
3768
  }),
3242
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3769
+ creator: space.inner.spaceState.creator?.key,
3243
3770
  cache: space.cache,
3244
3771
  metrics: space.metrics
3245
3772
  };
@@ -3248,20 +3775,33 @@ var SpacesServiceImpl = class {
3248
3775
  var getChannelId = (channel) => `user-channel/${channel}`;
3249
3776
 
3250
3777
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3251
- import invariant11 from "tiny-invariant";
3252
3778
  import { Trigger as Trigger5 } from "@dxos/async";
3779
+ import { Context as Context9 } from "@dxos/context";
3253
3780
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3254
3781
  import { failUndefined as failUndefined3 } from "@dxos/debug";
3255
3782
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3256
3783
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3784
+ import { invariant as invariant12 } from "@dxos/invariant";
3257
3785
  import { Keyring } from "@dxos/keyring";
3258
3786
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3259
- import { log as log12 } from "@dxos/log";
3260
- import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3787
+ import { log as log13 } from "@dxos/log";
3788
+ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/protocols";
3261
3789
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3262
3790
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3263
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3264
- var ServiceContext = class {
3791
+ import { trace as Trace2 } from "@dxos/tracing";
3792
+ import { safeInstanceof } from "@dxos/util";
3793
+ function _ts_decorate5(decorators, target, key, desc) {
3794
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3795
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3796
+ r = Reflect.decorate(decorators, target, key, desc);
3797
+ else
3798
+ for (var i = decorators.length - 1; i >= 0; i--)
3799
+ if (d = decorators[i])
3800
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3801
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3802
+ }
3803
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3804
+ var ServiceContext = class ServiceContext2 {
3265
3805
  // prettier-ignore
3266
3806
  constructor(storage, networkManager, signalManager, modelFactory) {
3267
3807
  this.storage = storage;
@@ -3281,7 +3821,8 @@ var ServiceContext = class {
3281
3821
  root: storage.createDirectory("feeds"),
3282
3822
  signer: this.keyring,
3283
3823
  hypercore: {
3284
- valueEncoding
3824
+ valueEncoding,
3825
+ stats: true
3285
3826
  }
3286
3827
  })
3287
3828
  });
@@ -3295,105 +3836,108 @@ var ServiceContext = class {
3295
3836
  });
3296
3837
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3297
3838
  this.invitations = new InvitationsHandler(this.networkManager);
3298
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3299
- var _a;
3300
- return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3301
- }, this._acceptIdentity.bind(this)));
3839
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined3(), this._acceptIdentity.bind(this)));
3302
3840
  }
3303
- async open() {
3304
- log12.trace("dxos.sdk.service-context.open", trace5.begin({
3305
- id: this._instanceId
3306
- }), {
3307
- F: __dxlog_file12,
3308
- L: 126,
3841
+ async open(ctx) {
3842
+ await this._checkStorageVersion();
3843
+ log13("opening...", void 0, {
3844
+ F: __dxlog_file15,
3845
+ L: 135,
3309
3846
  S: this,
3310
3847
  C: (f, a) => f(...a)
3311
3848
  });
3312
- await this._checkStorageVersion();
3313
- log12("opening...", void 0, {
3314
- F: __dxlog_file12,
3315
- L: 130,
3849
+ log13.trace("dxos.sdk.service-context.open", trace6.begin({
3850
+ id: this._instanceId
3851
+ }), {
3852
+ F: __dxlog_file15,
3853
+ L: 136,
3316
3854
  S: this,
3317
3855
  C: (f, a) => f(...a)
3318
3856
  });
3319
3857
  await this.signalManager.open();
3320
3858
  await this.networkManager.open();
3321
3859
  await this.spaceManager.open();
3322
- await this.identityManager.open();
3860
+ await this.identityManager.open(ctx);
3323
3861
  if (this.identityManager.identity) {
3324
- await this._initialize();
3862
+ await this._initialize(ctx);
3325
3863
  }
3326
- log12("opened", void 0, {
3327
- F: __dxlog_file12,
3328
- L: 138,
3864
+ log13.trace("dxos.sdk.service-context.open", trace6.end({
3865
+ id: this._instanceId
3866
+ }), {
3867
+ F: __dxlog_file15,
3868
+ L: 144,
3329
3869
  S: this,
3330
3870
  C: (f, a) => f(...a)
3331
3871
  });
3332
- log12.trace("dxos.sdk.service-context.open", trace5.end({
3333
- id: this._instanceId
3334
- }), {
3335
- F: __dxlog_file12,
3336
- L: 139,
3872
+ log13("opened", void 0, {
3873
+ F: __dxlog_file15,
3874
+ L: 145,
3337
3875
  S: this,
3338
3876
  C: (f, a) => f(...a)
3339
3877
  });
3340
3878
  }
3341
3879
  async close() {
3342
- var _a;
3343
- log12("closing...", void 0, {
3344
- F: __dxlog_file12,
3345
- L: 143,
3880
+ log13("closing...", void 0, {
3881
+ F: __dxlog_file15,
3882
+ L: 149,
3346
3883
  S: this,
3347
3884
  C: (f, a) => f(...a)
3348
3885
  });
3349
3886
  if (this._deviceSpaceSync && this.identityManager.identity) {
3350
3887
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3351
3888
  }
3352
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3889
+ await this.dataSpaceManager?.close();
3353
3890
  await this.identityManager.close();
3354
3891
  await this.spaceManager.close();
3355
3892
  await this.feedStore.close();
3356
3893
  await this.networkManager.close();
3357
3894
  await this.signalManager.close();
3358
3895
  this.dataServiceSubscriptions.clear();
3359
- log12("closed", void 0, {
3360
- F: __dxlog_file12,
3361
- L: 154,
3896
+ log13("closed", void 0, {
3897
+ F: __dxlog_file15,
3898
+ L: 160,
3362
3899
  S: this,
3363
3900
  C: (f, a) => f(...a)
3364
3901
  });
3365
3902
  }
3366
3903
  async createIdentity(params = {}) {
3367
3904
  const identity = await this.identityManager.createIdentity(params);
3368
- await this._initialize();
3905
+ await this._initialize(new Context9());
3369
3906
  return identity;
3370
3907
  }
3371
3908
  getInvitationHandler(invitation) {
3372
3909
  const factory = this._handlerFactories.get(invitation.kind);
3373
- invariant11(factory, `Unknown invitation kind: ${invitation.kind}`);
3910
+ invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3911
+ F: __dxlog_file15,
3912
+ L: 171,
3913
+ S: this,
3914
+ A: [
3915
+ "factory",
3916
+ "`Unknown invitation kind: ${invitation.kind}`"
3917
+ ]
3918
+ });
3374
3919
  return factory(invitation);
3375
3920
  }
3376
3921
  async _acceptIdentity(params) {
3377
3922
  const identity = await this.identityManager.acceptIdentity(params);
3378
- await this._initialize();
3923
+ await this._initialize(new Context9());
3379
3924
  return identity;
3380
3925
  }
3381
3926
  async _checkStorageVersion() {
3382
3927
  await this.metadataStore.load();
3383
- if (this.metadataStore.version !== STORAGE_VERSION) {
3384
- throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${STORAGE_VERSION}`);
3928
+ if (this.metadataStore.version !== STORAGE_VERSION2) {
3929
+ throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${STORAGE_VERSION2}`);
3385
3930
  }
3386
3931
  }
3387
3932
  // Called when identity is created.
3388
- async _initialize() {
3389
- var _a;
3390
- log12("initializing spaces...", void 0, {
3391
- F: __dxlog_file12,
3392
- L: 187,
3933
+ async _initialize(ctx) {
3934
+ log13("initializing spaces...", void 0, {
3935
+ F: __dxlog_file15,
3936
+ L: 192,
3393
3937
  S: this,
3394
3938
  C: (f, a) => f(...a)
3395
3939
  });
3396
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3940
+ const identity = this.identityManager.identity ?? failUndefined3();
3397
3941
  const signingContext = {
3398
3942
  credentialSigner: identity.getIdentityCredentialSigner(),
3399
3943
  identityKey: identity.identityKey,
@@ -3410,7 +3954,15 @@ var ServiceContext = class {
3410
3954
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
3411
3955
  await this.dataSpaceManager.open();
3412
3956
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3413
- invariant11(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3957
+ invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3958
+ F: __dxlog_file15,
3959
+ L: 215,
3960
+ S: this,
3961
+ A: [
3962
+ "this.dataSpaceManager",
3963
+ "'dataSpaceManager not initialized yet'"
3964
+ ]
3965
+ });
3414
3966
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3415
3967
  });
3416
3968
  this.initialized.wake();
@@ -3424,33 +3976,33 @@ var ServiceContext = class {
3424
3976
  return;
3425
3977
  }
3426
3978
  if (!this.dataSpaceManager) {
3427
- log12("dataSpaceManager not initialized yet, ignoring space admission", {
3979
+ log13("dataSpaceManager not initialized yet, ignoring space admission", {
3428
3980
  details: assertion
3429
3981
  }, {
3430
- F: __dxlog_file12,
3431
- L: 226,
3982
+ F: __dxlog_file15,
3983
+ L: 231,
3432
3984
  S: this,
3433
3985
  C: (f, a) => f(...a)
3434
3986
  });
3435
3987
  return;
3436
3988
  }
3437
3989
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3438
- log12("space already exists, ignoring space admission", {
3990
+ log13("space already exists, ignoring space admission", {
3439
3991
  details: assertion
3440
3992
  }, {
3441
- F: __dxlog_file12,
3442
- L: 230,
3993
+ F: __dxlog_file15,
3994
+ L: 235,
3443
3995
  S: this,
3444
3996
  C: (f, a) => f(...a)
3445
3997
  });
3446
3998
  return;
3447
3999
  }
3448
4000
  try {
3449
- log12("accepting space recorded in halo", {
4001
+ log13("accepting space recorded in halo", {
3450
4002
  details: assertion
3451
4003
  }, {
3452
- F: __dxlog_file12,
3453
- L: 235,
4004
+ F: __dxlog_file15,
4005
+ L: 240,
3454
4006
  S: this,
3455
4007
  C: (f, a) => f(...a)
3456
4008
  });
@@ -3459,9 +4011,9 @@ var ServiceContext = class {
3459
4011
  genesisFeedKey: assertion.genesisFeedKey
3460
4012
  });
3461
4013
  } catch (err) {
3462
- log12.catch(err, void 0, {
3463
- F: __dxlog_file12,
3464
- L: 241,
4014
+ log13.catch(err, void 0, {
4015
+ F: __dxlog_file15,
4016
+ L: 246,
3465
4017
  S: this,
3466
4018
  C: (f, a) => f(...a)
3467
4019
  });
@@ -3471,12 +4023,22 @@ var ServiceContext = class {
3471
4023
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3472
4024
  }
3473
4025
  };
4026
+ _ts_decorate5([
4027
+ Trace2.span()
4028
+ ], ServiceContext.prototype, "open", null);
4029
+ _ts_decorate5([
4030
+ Trace2.span()
4031
+ ], ServiceContext.prototype, "_initialize", null);
4032
+ ServiceContext = _ts_decorate5([
4033
+ safeInstanceof("dxos.client-services.ServiceContext"),
4034
+ Trace2.resource()
4035
+ ], ServiceContext);
3474
4036
 
3475
4037
  // packages/sdk/client-services/src/packlets/locks/browser.ts
3476
4038
  import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3477
4039
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3478
- import { log as log13, logInfo } from "@dxos/log";
3479
- function _ts_decorate3(decorators, target, key, desc) {
4040
+ import { log as log14, logInfo } from "@dxos/log";
4041
+ function _ts_decorate6(decorators, target, key, desc) {
3480
4042
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3481
4043
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3482
4044
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3486,7 +4048,7 @@ function _ts_decorate3(decorators, target, key, desc) {
3486
4048
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3487
4049
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3488
4050
  }
3489
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
4051
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
3490
4052
  var Message;
3491
4053
  (function(Message2) {
3492
4054
  Message2["ACQUIRING"] = "acquiring";
@@ -3508,29 +4070,29 @@ var Lock = class {
3508
4070
  message: Message.ACQUIRING
3509
4071
  });
3510
4072
  try {
3511
- log13("aquiring lock...", void 0, {
3512
- F: __dxlog_file13,
4073
+ log14("aquiring lock...", void 0, {
4074
+ F: __dxlog_file16,
3513
4075
  L: 42,
3514
4076
  S: this,
3515
4077
  C: (f, a) => f(...a)
3516
4078
  });
3517
4079
  await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
3518
- log13("acquired lock", void 0, {
3519
- F: __dxlog_file13,
4080
+ log14("acquired lock", void 0, {
4081
+ F: __dxlog_file16,
3520
4082
  L: 44,
3521
4083
  S: this,
3522
4084
  C: (f, a) => f(...a)
3523
4085
  });
3524
- } catch (e) {
3525
- log13("stealing lock...", void 0, {
3526
- F: __dxlog_file13,
4086
+ } catch {
4087
+ log14("stealing lock...", void 0, {
4088
+ F: __dxlog_file16,
3527
4089
  L: 46,
3528
4090
  S: this,
3529
4091
  C: (f, a) => f(...a)
3530
4092
  });
3531
4093
  await this._requestLock(true);
3532
- log13("stolen lock", void 0, {
3533
- F: __dxlog_file13,
4094
+ log14("stolen lock", void 0, {
4095
+ F: __dxlog_file16,
3534
4096
  L: 48,
3535
4097
  S: this,
3536
4098
  C: (f, a) => f(...a)
@@ -3546,10 +4108,10 @@ var Lock = class {
3546
4108
  }
3547
4109
  }
3548
4110
  async _requestLock(steal = false) {
3549
- log13("requesting lock...", {
4111
+ log14("requesting lock...", {
3550
4112
  steal
3551
4113
  }, {
3552
- F: __dxlog_file13,
4114
+ F: __dxlog_file16,
3553
4115
  L: 63,
3554
4116
  S: this,
3555
4117
  C: (f, a) => f(...a)
@@ -3558,40 +4120,38 @@ var Lock = class {
3558
4120
  void navigator.locks.request(this._lockKey, {
3559
4121
  steal
3560
4122
  }, async () => {
3561
- var _a, _b;
3562
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4123
+ await this._onAcquire?.();
3563
4124
  acquired.wake();
3564
4125
  this._releaseTrigger = new Trigger6();
3565
4126
  await this._releaseTrigger.wait();
3566
- log13("releasing lock...", void 0, {
3567
- F: __dxlog_file13,
4127
+ log14("releasing lock...", void 0, {
4128
+ F: __dxlog_file16,
3568
4129
  L: 72,
3569
4130
  S: this,
3570
4131
  C: (f, a) => f(...a)
3571
4132
  });
3572
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3573
- log13("released lock", void 0, {
3574
- F: __dxlog_file13,
4133
+ await this._onRelease?.();
4134
+ log14("released lock", void 0, {
4135
+ F: __dxlog_file16,
3575
4136
  L: 74,
3576
4137
  S: this,
3577
4138
  C: (f, a) => f(...a)
3578
4139
  });
3579
4140
  }).catch(async () => {
3580
- var _a;
3581
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4141
+ await this._onRelease?.();
3582
4142
  });
3583
4143
  await acquired.wait();
3584
- log13("recieved lock", {
4144
+ log14("recieved lock", {
3585
4145
  steal
3586
4146
  }, {
3587
- F: __dxlog_file13,
4147
+ F: __dxlog_file16,
3588
4148
  L: 81,
3589
4149
  S: this,
3590
4150
  C: (f, a) => f(...a)
3591
4151
  });
3592
4152
  }
3593
4153
  };
3594
- _ts_decorate3([
4154
+ _ts_decorate6([
3595
4155
  logInfo
3596
4156
  ], Lock.prototype, "lockKey", null);
3597
4157
  var isLocked = (lockPath) => {
@@ -3606,7 +4166,7 @@ import { createStorage, StorageType } from "@dxos/random-access-storage";
3606
4166
  import { isNode } from "@dxos/util";
3607
4167
  var StorageDriver = Runtime.Client.Storage.StorageDriver;
3608
4168
  var createStorageObjects = (config) => {
3609
- const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
4169
+ const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
3610
4170
  if (persistent && storageType === StorageDriver.RAM) {
3611
4171
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
3612
4172
  }
@@ -3672,19 +4232,21 @@ var ServiceRegistry = class {
3672
4232
  };
3673
4233
 
3674
4234
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3675
- import invariant12 from "tiny-invariant";
3676
4235
  import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
3677
4236
  import { clientServiceBundle } from "@dxos/client-protocol";
3678
- import { DocumentModel } from "@dxos/document-model";
4237
+ import { Context as Context10 } from "@dxos/context";
4238
+ import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
3679
4239
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4240
+ import { invariant as invariant13 } from "@dxos/invariant";
3680
4241
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3681
- import { log as log15 } from "@dxos/log";
4242
+ import { log as log16 } from "@dxos/log";
3682
4243
  import { WebsocketSignalManager } from "@dxos/messaging";
3683
4244
  import { ModelFactory } from "@dxos/model-factory";
3684
4245
  import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
3685
- import { trace as trace6 } from "@dxos/protocols";
4246
+ import { trace as trace7 } from "@dxos/protocols";
3686
4247
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
3687
4248
  import { TextModel } from "@dxos/text-model";
4249
+ import { TRACE_PROCESSOR, trace as Trace3 } from "@dxos/tracing";
3688
4250
 
3689
4251
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
3690
4252
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
@@ -3700,21 +4262,17 @@ var DevicesServiceImpl = class {
3700
4262
  queryDevices() {
3701
4263
  return new Stream11(({ next }) => {
3702
4264
  const update = () => {
3703
- var _a;
3704
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4265
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
3705
4266
  if (!deviceKeys) {
3706
4267
  next({
3707
4268
  devices: []
3708
4269
  });
3709
4270
  } else {
3710
4271
  next({
3711
- devices: Array.from(deviceKeys.values()).map((key) => {
3712
- var _a2;
3713
- return {
3714
- deviceKey: key,
3715
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
3716
- };
3717
- })
4272
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4273
+ deviceKey: key,
4274
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4275
+ }))
3718
4276
  });
3719
4277
  }
3720
4278
  };
@@ -3736,22 +4294,23 @@ var DevicesServiceImpl = class {
3736
4294
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
3737
4295
  import { Event as Event7 } from "@dxos/async";
3738
4296
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
3739
- import { getContextFromEntry, log as log14 } from "@dxos/log";
4297
+ import { getContextFromEntry, log as log15 } from "@dxos/log";
3740
4298
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
3741
4299
  import { jsonify, numericalValues, tracer } from "@dxos/util";
3742
4300
  var LoggingServiceImpl = class {
3743
4301
  constructor() {
3744
4302
  this._logs = new Event7();
4303
+ this._started = /* @__PURE__ */ new Date();
3745
4304
  this._logProcessor = (_config, entry2) => {
3746
4305
  this._logs.emit(entry2);
3747
4306
  };
3748
4307
  }
3749
4308
  async open() {
3750
- log14.runtimeConfig.processors.push(this._logProcessor);
4309
+ log15.runtimeConfig.processors.push(this._logProcessor);
3751
4310
  }
3752
4311
  async close() {
3753
- const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
3754
- log14.runtimeConfig.processors.splice(index, 1);
4312
+ const index = log15.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
4313
+ log15.runtimeConfig.processors.splice(index, 1);
3755
4314
  }
3756
4315
  async controlMetrics({ reset, record }) {
3757
4316
  if (reset) {
@@ -3766,28 +4325,33 @@ var LoggingServiceImpl = class {
3766
4325
  recording: tracer.recording
3767
4326
  };
3768
4327
  }
3769
- queryMetrics({ interval }) {
3770
- const createNumericalValues = (key) => {
3771
- var _a;
3772
- const consume = (_a = tracer.get(key)) != null ? _a : [];
4328
+ /**
4329
+ * @deprecated (Move to diagnostics).
4330
+ */
4331
+ queryMetrics({ interval = 5e3 }) {
4332
+ const getNumericalValues = (key) => {
4333
+ const events = tracer.get(key) ?? [];
3773
4334
  return {
3774
4335
  key,
3775
- stats: numericalValues(consume, "duration")
4336
+ stats: numericalValues(events, "duration")
3776
4337
  };
3777
4338
  };
3778
4339
  return new Stream12(({ next }) => {
3779
4340
  const update = () => {
3780
4341
  const metrics = {
3781
- timestamp: new Date(),
4342
+ timestamp: /* @__PURE__ */ new Date(),
3782
4343
  values: [
3783
- createNumericalValues("dxos.echo.pipeline.control"),
3784
- createNumericalValues("dxos.echo.pipeline.data")
3785
- ]
4344
+ getNumericalValues("dxos.echo.pipeline.control"),
4345
+ getNumericalValues("dxos.echo.pipeline.data")
4346
+ ].filter(Boolean)
3786
4347
  };
3787
- next(metrics);
4348
+ next({
4349
+ timestamp: /* @__PURE__ */ new Date(),
4350
+ metrics
4351
+ });
3788
4352
  };
3789
4353
  update();
3790
- const i = setInterval(update, interval);
4354
+ const i = setInterval(update, Math.max(interval, 1e3));
3791
4355
  return () => {
3792
4356
  clearInterval(i);
3793
4357
  };
@@ -3796,11 +4360,10 @@ var LoggingServiceImpl = class {
3796
4360
  queryLogs(request) {
3797
4361
  return new Stream12(({ ctx, next }) => {
3798
4362
  const handler = (entry2) => {
3799
- var _a, _b, _c, _d, _e;
3800
4363
  if (LOG_PROCESSING > 0) {
3801
4364
  return;
3802
4365
  }
3803
- if (((_a = entry2.meta) == null ? void 0 : _a.F.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4366
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3804
4367
  return;
3805
4368
  }
3806
4369
  if (!shouldLog(entry2, request)) {
@@ -3809,11 +4372,11 @@ var LoggingServiceImpl = class {
3809
4372
  const record = {
3810
4373
  ...entry2,
3811
4374
  context: jsonify(getContextFromEntry(entry2)),
3812
- timestamp: new Date(),
4375
+ timestamp: /* @__PURE__ */ new Date(),
3813
4376
  meta: {
3814
4377
  // TODO(dmaretskyi): Fix proto.
3815
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
3816
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4378
+ file: entry2.meta?.F ?? "",
4379
+ line: entry2.meta?.L ?? 0
3817
4380
  }
3818
4381
  };
3819
4382
  try {
@@ -3836,15 +4399,11 @@ var matchFilter = (filter, level, path, options) => {
3836
4399
  }
3837
4400
  };
3838
4401
  var shouldLog = (entry2, request) => {
3839
- var _a;
3840
- const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
4402
+ const options = request.options ?? QueryLogsRequest.MatchingOptions.INCLUSIVE;
3841
4403
  if (request.filters === void 0) {
3842
4404
  return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
3843
4405
  } else {
3844
- return request.filters.some((filter) => {
3845
- var _a2, _b;
3846
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
3847
- });
4406
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
3848
4407
  }
3849
4408
  };
3850
4409
  var LOG_PROCESSING = 0;
@@ -3883,17 +4442,32 @@ var NetworkServiceImpl = class {
3883
4442
 
3884
4443
  // packages/sdk/client-services/src/packlets/system/system-service.ts
3885
4444
  import { Stream as Stream14 } from "@dxos/codec-protobuf";
4445
+ import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
4446
+ import { jsonKeyReplacer } from "@dxos/util";
3886
4447
  var SystemServiceImpl = class {
3887
- constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
4448
+ constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
3888
4449
  this._config = config;
3889
4450
  this._statusUpdate = statusUpdate;
3890
4451
  this._getCurrentStatus = getCurrentStatus;
4452
+ this._getDiagnostics = getDiagnostics;
3891
4453
  this._onUpdateStatus = onUpdateStatus;
3892
4454
  this._onReset = onReset;
3893
4455
  }
3894
4456
  async getConfig() {
3895
- var _a, _b;
3896
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4457
+ return this._config?.values ?? {};
4458
+ }
4459
+ /**
4460
+ * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
4461
+ */
4462
+ async getDiagnostics({ keys } = {}) {
4463
+ const diagnostics = await this._getDiagnostics();
4464
+ return {
4465
+ timestamp: /* @__PURE__ */ new Date(),
4466
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4467
+ truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4468
+ humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4469
+ })))
4470
+ };
3897
4471
  }
3898
4472
  async updateStatus({ status }) {
3899
4473
  await this._onUpdateStatus(status);
@@ -3921,7 +4495,7 @@ var SystemServiceImpl = class {
3921
4495
  };
3922
4496
 
3923
4497
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3924
- function _ts_decorate4(decorators, target, key, desc) {
4498
+ function _ts_decorate7(decorators, target, key, desc) {
3925
4499
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3926
4500
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3927
4501
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3931,23 +4505,22 @@ function _ts_decorate4(decorators, target, key, desc) {
3931
4505
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3932
4506
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3933
4507
  }
3934
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
4508
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
3935
4509
  var createDefaultModelFactory = () => {
3936
- return new ModelFactory().registerModel(DocumentModel).registerModel(TextModel);
4510
+ return new ModelFactory().registerModel(DocumentModel2).registerModel(TextModel);
3937
4511
  };
3938
- var ClientServicesHost = class {
4512
+ var ClientServicesHost = class ClientServicesHost2 {
3939
4513
  constructor({
3940
4514
  config,
3941
4515
  modelFactory = createDefaultModelFactory(),
3942
- // TODO(burdon): Create ApolloLink abstraction (see Client).
3943
4516
  transportFactory,
3944
4517
  signalManager,
3945
- connectionLog,
3946
4518
  storage,
3947
4519
  // TODO(wittjosiah): Turn this on by default.
3948
4520
  lockKey,
3949
4521
  callbacks
3950
4522
  } = {}) {
4523
+ this._tracingService = TRACE_PROCESSOR.createTraceSender();
3951
4524
  this._statusUpdate = new Event8();
3952
4525
  this._opening = false;
3953
4526
  this._open = false;
@@ -3966,7 +4539,7 @@ var ClientServicesHost = class {
3966
4539
  lockKey,
3967
4540
  onAcquire: () => {
3968
4541
  if (!this._opening) {
3969
- void this.open();
4542
+ void this.open(new Context10());
3970
4543
  }
3971
4544
  },
3972
4545
  onRelease: () => this.close()
@@ -3976,12 +4549,14 @@ var ClientServicesHost = class {
3976
4549
  config: this._config,
3977
4550
  statusUpdate: this._statusUpdate,
3978
4551
  getCurrentStatus: () => this.isOpen ? SystemStatus.ACTIVE : SystemStatus.INACTIVE,
4552
+ getDiagnostics: () => {
4553
+ return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4554
+ },
3979
4555
  onUpdateStatus: async (status) => {
3980
- var _a, _b;
3981
4556
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
3982
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4557
+ await this._resourceLock?.acquire();
3983
4558
  } else if (this.isOpen && status === SystemStatus.INACTIVE) {
3984
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4559
+ await this._resourceLock?.release();
3985
4560
  }
3986
4561
  },
3987
4562
  onReset: async () => {
@@ -3990,12 +4565,19 @@ var ClientServicesHost = class {
3990
4565
  });
3991
4566
  this._loggingService = new LoggingServiceImpl();
3992
4567
  this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
3993
- SystemService: this._systemService
4568
+ SystemService: this._systemService,
4569
+ TracingService: this._tracingService
3994
4570
  });
3995
4571
  }
3996
4572
  get isOpen() {
3997
4573
  return this._open;
3998
4574
  }
4575
+ get config() {
4576
+ return this._config;
4577
+ }
4578
+ get context() {
4579
+ return this._serviceContext;
4580
+ }
3999
4581
  get serviceRegistry() {
4000
4582
  return this._serviceRegistry;
4001
4583
  }
@@ -4011,59 +4593,125 @@ var ClientServicesHost = class {
4011
4593
  * Can only be called once.
4012
4594
  */
4013
4595
  initialize({ config, ...options }) {
4014
- var _a, _b, _c;
4015
- invariant12(!this._open, "service host is open");
4596
+ invariant13(!this._open, "service host is open", {
4597
+ F: __dxlog_file17,
4598
+ L: 181,
4599
+ S: this,
4600
+ A: [
4601
+ "!this._open",
4602
+ "'service host is open'"
4603
+ ]
4604
+ });
4605
+ log16("initializing...", void 0, {
4606
+ F: __dxlog_file17,
4607
+ L: 182,
4608
+ S: this,
4609
+ C: (f, a) => f(...a)
4610
+ });
4016
4611
  if (config) {
4017
- invariant12(!this._config, "config already set");
4612
+ invariant13(!this._config, "config already set", {
4613
+ F: __dxlog_file17,
4614
+ L: 185,
4615
+ S: this,
4616
+ A: [
4617
+ "!this._config",
4618
+ "'config already set'"
4619
+ ]
4620
+ });
4018
4621
  this._config = config;
4019
4622
  if (!this._storage) {
4020
4623
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
4021
4624
  }
4022
4625
  }
4023
4626
  const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4024
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4025
- }), signalManager = new WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4627
+ iceServers: this._config?.get("runtime.services.ice")
4628
+ }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4026
4629
  this._signalManager = signalManager;
4027
- invariant12(!this._networkManager, "network manager already set");
4630
+ invariant13(!this._networkManager, "network manager already set", {
4631
+ F: __dxlog_file17,
4632
+ L: 201,
4633
+ S: this,
4634
+ A: [
4635
+ "!this._networkManager",
4636
+ "'network manager already set'"
4637
+ ]
4638
+ });
4028
4639
  this._networkManager = new NetworkManager({
4029
4640
  log: connectionLog,
4030
4641
  transportFactory,
4031
4642
  signalManager
4032
4643
  });
4644
+ log16("initialized", void 0, {
4645
+ F: __dxlog_file17,
4646
+ L: 208,
4647
+ S: this,
4648
+ C: (f, a) => f(...a)
4649
+ });
4033
4650
  }
4034
- async open() {
4035
- var _a, _b, _c;
4651
+ async open(ctx) {
4036
4652
  if (this._open) {
4037
4653
  return;
4038
4654
  }
4039
4655
  const traceId = PublicKey10.random().toHex();
4040
- log15.trace("dxos.sdk.client-services-host.open", trace6.begin({
4656
+ log16.trace("dxos.client-services.host.open", trace7.begin({
4041
4657
  id: traceId
4042
4658
  }), {
4043
- F: __dxlog_file14,
4044
- L: 203,
4659
+ F: __dxlog_file17,
4660
+ L: 219,
4045
4661
  S: this,
4046
4662
  C: (f, a) => f(...a)
4047
4663
  });
4048
- invariant12(this._config, "config not set");
4049
- invariant12(this._storage, "storage not set");
4050
- invariant12(this._signalManager, "signal manager not set");
4051
- invariant12(this._networkManager, "network manager not set");
4664
+ invariant13(this._config, "config not set", {
4665
+ F: __dxlog_file17,
4666
+ L: 221,
4667
+ S: this,
4668
+ A: [
4669
+ "this._config",
4670
+ "'config not set'"
4671
+ ]
4672
+ });
4673
+ invariant13(this._storage, "storage not set", {
4674
+ F: __dxlog_file17,
4675
+ L: 222,
4676
+ S: this,
4677
+ A: [
4678
+ "this._storage",
4679
+ "'storage not set'"
4680
+ ]
4681
+ });
4682
+ invariant13(this._signalManager, "signal manager not set", {
4683
+ F: __dxlog_file17,
4684
+ L: 223,
4685
+ S: this,
4686
+ A: [
4687
+ "this._signalManager",
4688
+ "'signal manager not set'"
4689
+ ]
4690
+ });
4691
+ invariant13(this._networkManager, "network manager not set", {
4692
+ F: __dxlog_file17,
4693
+ L: 224,
4694
+ S: this,
4695
+ A: [
4696
+ "this._networkManager",
4697
+ "'network manager not set'"
4698
+ ]
4699
+ });
4052
4700
  this._opening = true;
4053
- log15("opening...", {
4054
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4701
+ log16("opening...", {
4702
+ lockKey: this._resourceLock?.lockKey
4055
4703
  }, {
4056
- F: __dxlog_file14,
4057
- L: 211,
4704
+ F: __dxlog_file17,
4705
+ L: 227,
4058
4706
  S: this,
4059
4707
  C: (f, a) => f(...a)
4060
4708
  });
4061
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4709
+ await this._resourceLock?.acquire();
4062
4710
  await this._loggingService.open();
4063
4711
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4064
4712
  this._serviceRegistry.setServices({
4065
4713
  SystemService: this._systemService,
4066
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4714
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4067
4715
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4068
4716
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4069
4717
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4073,6 +4721,7 @@ var ClientServicesHost = class {
4073
4721
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4074
4722
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4075
4723
  LoggingService: this._loggingService,
4724
+ TracingService: this._tracingService,
4076
4725
  // TODO(burdon): Move to new protobuf definitions.
4077
4726
  DevtoolsHost: new DevtoolsServiceImpl({
4078
4727
  events: new DevtoolsHostEvents(),
@@ -4080,39 +4729,38 @@ var ClientServicesHost = class {
4080
4729
  context: this._serviceContext
4081
4730
  })
4082
4731
  });
4083
- await this._serviceContext.open();
4732
+ await this._serviceContext.open(ctx);
4084
4733
  this._opening = false;
4085
4734
  this._open = true;
4086
4735
  this._statusUpdate.emit();
4087
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4088
- log15("opened", {
4736
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4737
+ log16("opened", {
4089
4738
  deviceKey
4090
4739
  }, {
4091
- F: __dxlog_file14,
4092
- L: 266,
4740
+ F: __dxlog_file17,
4741
+ L: 284,
4093
4742
  S: this,
4094
4743
  C: (f, a) => f(...a)
4095
4744
  });
4096
- log15.trace("dxos.sdk.client-services-host.open", trace6.end({
4745
+ log16.trace("dxos.client-services.host.open", trace7.end({
4097
4746
  id: traceId
4098
4747
  }), {
4099
- F: __dxlog_file14,
4100
- L: 267,
4748
+ F: __dxlog_file17,
4749
+ L: 285,
4101
4750
  S: this,
4102
4751
  C: (f, a) => f(...a)
4103
4752
  });
4104
4753
  }
4105
4754
  async close() {
4106
- var _a;
4107
4755
  if (!this._open) {
4108
4756
  return;
4109
4757
  }
4110
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4111
- log15("closing...", {
4758
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4759
+ log16("closing...", {
4112
4760
  deviceKey
4113
4761
  }, {
4114
- F: __dxlog_file14,
4115
- L: 277,
4762
+ F: __dxlog_file17,
4763
+ L: 296,
4116
4764
  S: this,
4117
4765
  C: (f, a) => f(...a)
4118
4766
  });
@@ -4123,57 +4771,67 @@ var ClientServicesHost = class {
4123
4771
  await this._serviceContext.close();
4124
4772
  this._open = false;
4125
4773
  this._statusUpdate.emit();
4126
- log15("closed", {
4774
+ log16("closed", {
4127
4775
  deviceKey
4128
4776
  }, {
4129
- F: __dxlog_file14,
4130
- L: 283,
4777
+ F: __dxlog_file17,
4778
+ L: 302,
4131
4779
  S: this,
4132
4780
  C: (f, a) => f(...a)
4133
4781
  });
4134
4782
  }
4135
4783
  async reset() {
4136
- var _a, _b, _c;
4137
4784
  const traceId = PublicKey10.random().toHex();
4138
- log15.trace("dxos.sdk.client-services-host.reset", trace6.begin({
4785
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4139
4786
  id: traceId
4140
4787
  }), {
4141
- F: __dxlog_file14,
4142
- L: 288,
4788
+ F: __dxlog_file17,
4789
+ L: 307,
4143
4790
  S: this,
4144
4791
  C: (f, a) => f(...a)
4145
4792
  });
4146
- log15("resetting...", void 0, {
4147
- F: __dxlog_file14,
4148
- L: 290,
4793
+ log16("resetting...", void 0, {
4794
+ F: __dxlog_file17,
4795
+ L: 309,
4149
4796
  S: this,
4150
4797
  C: (f, a) => f(...a)
4151
4798
  });
4152
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4799
+ await this._serviceContext?.close();
4153
4800
  await this._storage.reset();
4154
- log15("reset", void 0, {
4155
- F: __dxlog_file14,
4156
- L: 293,
4801
+ log16("reset", void 0, {
4802
+ F: __dxlog_file17,
4803
+ L: 312,
4157
4804
  S: this,
4158
4805
  C: (f, a) => f(...a)
4159
4806
  });
4160
- log15.trace("dxos.sdk.client-services-host.reset", trace6.end({
4807
+ log16.trace("dxos.sdk.client-services-host.reset", trace7.end({
4161
4808
  id: traceId
4162
4809
  }), {
4163
- F: __dxlog_file14,
4164
- L: 294,
4810
+ F: __dxlog_file17,
4811
+ L: 313,
4165
4812
  S: this,
4166
4813
  C: (f, a) => f(...a)
4167
4814
  });
4168
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4815
+ await this._callbacks?.onReset?.();
4169
4816
  }
4170
4817
  };
4171
- _ts_decorate4([
4172
- synchronized3
4818
+ _ts_decorate7([
4819
+ Trace3.info()
4820
+ ], ClientServicesHost.prototype, "_opening", void 0);
4821
+ _ts_decorate7([
4822
+ Trace3.info()
4823
+ ], ClientServicesHost.prototype, "_open", void 0);
4824
+ _ts_decorate7([
4825
+ synchronized3,
4826
+ Trace3.span()
4173
4827
  ], ClientServicesHost.prototype, "open", null);
4174
- _ts_decorate4([
4175
- synchronized3
4828
+ _ts_decorate7([
4829
+ synchronized3,
4830
+ Trace3.span()
4176
4831
  ], ClientServicesHost.prototype, "close", null);
4832
+ ClientServicesHost = _ts_decorate7([
4833
+ Trace3.resource()
4834
+ ], ClientServicesHost);
4177
4835
 
4178
4836
  export {
4179
4837
  subscribeToFeeds,
@@ -4196,6 +4854,7 @@ export {
4196
4854
  InvitationsServiceImpl,
4197
4855
  SpaceInvitationProtocol,
4198
4856
  ClientRpcServer,
4857
+ createDiagnostics,
4199
4858
  DataSpace,
4200
4859
  DataSpaceManager,
4201
4860
  SpacesServiceImpl,
@@ -4207,4 +4866,4 @@ export {
4207
4866
  createDefaultModelFactory,
4208
4867
  ClientServicesHost
4209
4868
  };
4210
- //# sourceMappingURL=chunk-CSJSC47N.mjs.map
4869
+ //# sourceMappingURL=chunk-T32PP5QD.mjs.map