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

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 (94) hide show
  1. package/dist/lib/browser/{chunk-CSJSC47N.mjs → chunk-UBWFDTK6.mjs} +1295 -640
  2. package/dist/lib/browser/chunk-UBWFDTK6.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +69 -53
  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 +1450 -782
  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 +1602 -952
  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 +1 -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 +211 -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 +17 -11
  76. package/src/packlets/services/service-host.test.ts +11 -10
  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.ts +2 -3
  81. package/src/packlets/spaces/data-space.ts +17 -5
  82. package/src/packlets/spaces/notarization-plugin.ts +1 -2
  83. package/src/packlets/spaces/spaces-service.test.ts +2 -1
  84. package/src/packlets/spaces/spaces-service.ts +18 -12
  85. package/src/packlets/system/system-service.test.ts +1 -0
  86. package/src/packlets/system/system-service.ts +34 -2
  87. package/src/packlets/testing/invitation-utils.ts +1 -2
  88. package/src/packlets/testing/test-builder.ts +1 -1
  89. package/src/packlets/vault/iframe-host-runtime.ts +2 -1
  90. package/src/packlets/vault/shell-runtime.ts +1 -2
  91. package/src/packlets/vault/worker-runtime.ts +2 -1
  92. package/src/packlets/vault/worker-session.ts +7 -3
  93. package/src/version.ts +1 -0
  94. package/dist/lib/browser/chunk-CSJSC47N.mjs.map +0 -7
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // packages/sdk/client-services/src/index.ts
@@ -55,6 +45,7 @@ __export(src_exports, {
55
45
  WorkerSession: () => WorkerSession,
56
46
  createAuthProvider: () => createAuthProvider,
57
47
  createDefaultModelFactory: () => createDefaultModelFactory,
48
+ createDiagnostics: () => createDiagnostics,
58
49
  createStorageObjects: () => createStorageObjects,
59
50
  getNetworkPeers: () => getNetworkPeers,
60
51
  isLocked: () => isLocked,
@@ -84,7 +75,7 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
84
75
  const feedMap = new import_util.ComplexMap(import_keys.PublicKey.hash);
85
76
  const update = () => {
86
77
  const { feeds } = feedStore;
87
- feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
78
+ feeds.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
88
79
  if (!feedMap.has(feed.key)) {
89
80
  feedMap.set(feed.key, feed);
90
81
  feed.on("close", update);
@@ -92,15 +83,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
92
83
  }
93
84
  });
94
85
  next({
95
- feeds: Array.from(feedMap.values()).map((feed) => {
96
- var _a, _b;
97
- return {
98
- feedKey: feed.key,
99
- length: feed.properties.length,
100
- bytes: feed.core.byteLength,
101
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
102
- };
103
- })
86
+ feeds: Array.from(feedMap.values()).map((feed) => ({
87
+ feedKey: feed.key,
88
+ length: feed.properties.length,
89
+ bytes: feed.core.byteLength,
90
+ downloaded: feed.core.bitfield?.data.toBuffer() ?? new Uint8Array()
91
+ }))
104
92
  });
105
93
  };
106
94
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -200,13 +188,13 @@ var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf4.Stream
200
188
  recipient: message.recipient.asUint8Array(),
201
189
  payload: message.payload
202
190
  },
203
- receivedAt: new Date()
191
+ receivedAt: /* @__PURE__ */ new Date()
204
192
  });
205
193
  });
206
194
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
207
195
  next({
208
196
  swarmEvent: swarmEvent.swarmEvent,
209
- receivedAt: new Date()
197
+ receivedAt: /* @__PURE__ */ new Date()
210
198
  });
211
199
  });
212
200
  return () => {
@@ -217,13 +205,10 @@ var subscribeToNetworkTopics = ({ networkManager }) => new import_codec_protobuf
217
205
  const update = () => {
218
206
  try {
219
207
  const topics = networkManager.topics;
220
- const labeledTopics = topics.map((topic) => {
221
- var _a, _b;
222
- return {
223
- topic,
224
- label: (_b = (_a = networkManager.getSwarm(topic)) == null ? void 0 : _a.label) != null ? _b : topic.toHex()
225
- };
226
- });
208
+ const labeledTopics = topics.map((topic) => ({
209
+ topic,
210
+ label: networkManager.getSwarm(topic)?.label ?? topic.toHex()
211
+ }));
227
212
  next({
228
213
  topics: labeledTopics
229
214
  });
@@ -235,17 +220,15 @@ var subscribeToNetworkTopics = ({ networkManager }) => new import_codec_protobuf
235
220
  update();
236
221
  });
237
222
  var subscribeToSwarmInfo = ({ networkManager }) => new import_codec_protobuf4.Stream(({ next }) => {
238
- var _a;
239
223
  const update = () => {
240
- var _a2;
241
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
224
+ const info = networkManager.connectionLog?.swarms;
242
225
  if (info) {
243
226
  next({
244
227
  data: info
245
228
  });
246
229
  }
247
230
  };
248
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
231
+ networkManager.connectionLog?.update.on(update);
249
232
  update();
250
233
  });
251
234
  var getNetworkPeers = ({ networkManager }, request) => {
@@ -254,7 +237,7 @@ var getNetworkPeers = ({ networkManager }, request) => {
254
237
  }
255
238
  const map = networkManager.getSwarmMap(import_keys2.PublicKey.from(request.topic));
256
239
  return {
257
- peers: map == null ? void 0 : map.peers.map((peer) => ({
240
+ peers: map?.peers.map((peer) => ({
258
241
  ...peer,
259
242
  connections: peer.connections.map((connection) => connection.asUint8Array())
260
243
  }))
@@ -270,14 +253,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
270
253
  const spaces = [
271
254
  ...context.spaceManager.spaces.values()
272
255
  ];
273
- const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
256
+ const filteredSpaces = spaces.filter((space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
274
257
  next({
275
258
  spaces: filteredSpaces.map((space) => {
276
259
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
277
260
  return {
278
261
  key: space.key,
279
262
  isOpen: space.isOpen,
280
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
263
+ timeframe: spaceMetadata?.dataTimeframe,
281
264
  genesisFeed: space.genesisFeedKey,
282
265
  controlFeed: space.controlFeedKey,
283
266
  dataFeed: space.dataFeedKey
@@ -291,7 +274,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
291
274
  await update();
292
275
  });
293
276
  return () => {
294
- unsubscribe == null ? void 0 : unsubscribe();
277
+ unsubscribe?.();
295
278
  clearTimeout(timeout);
296
279
  };
297
280
  });
@@ -322,16 +305,15 @@ var DevtoolsServiceImpl = class {
322
305
  };
323
306
  }
324
307
  async getStorageInfo() {
325
- var _a, _b, _c, _d, _e;
326
- const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
308
+ const storageUsage = await this.params.context.storage.getDiskInfo?.() ?? {
327
309
  used: 0
328
310
  };
329
311
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
330
312
  return {
331
313
  type: this.params.context.storage.type,
332
314
  storageUsage: storageUsage.used,
333
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
334
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
315
+ originUsage: navigatorInfo?.usage ?? 0,
316
+ usageQuota: navigatorInfo?.quota ?? 0
335
317
  };
336
318
  }
337
319
  async getBlobs() {
@@ -517,7 +499,7 @@ var TrustedKeySetAuthVerifier = class {
517
499
  return await trigger.wait({
518
500
  timeout: this._params.authTimeout
519
501
  });
520
- } catch (e) {
502
+ } catch {
521
503
  return false;
522
504
  } finally {
523
505
  clear();
@@ -531,16 +513,27 @@ var TrustedKeySetAuthVerifier = class {
531
513
  };
532
514
 
533
515
  // packages/sdk/client-services/src/packlets/identity/identity.ts
534
- var import_tiny_invariant = __toESM(require("tiny-invariant"));
535
516
  var import_async5 = require("@dxos/async");
536
517
  var import_client_protocol = require("@dxos/client-protocol");
537
518
  var import_credentials2 = require("@dxos/credentials");
538
519
  var import_debug = require("@dxos/debug");
539
520
  var import_feed_store2 = require("@dxos/feed-store");
521
+ var import_invariant = require("@dxos/invariant");
540
522
  var import_log2 = require("@dxos/log");
541
523
  var import_credentials3 = require("@dxos/protocols/proto/dxos/halo/credentials");
524
+ var import_tracing = require("@dxos/tracing");
525
+ function _ts_decorate(decorators, target, key, desc) {
526
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
527
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
528
+ r = Reflect.decorate(decorators, target, key, desc);
529
+ else
530
+ for (var i = decorators.length - 1; i >= 0; i--)
531
+ if (d = decorators[i])
532
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
533
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
534
+ }
542
535
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
543
- var Identity = class {
536
+ var Identity = class Identity2 {
544
537
  constructor({ space, signer, identityKey, deviceKey }) {
545
538
  this.stateUpdate = new import_async5.Event();
546
539
  this.space = space;
@@ -566,12 +559,12 @@ var Identity = class {
566
559
  get authorizedDeviceKeys() {
567
560
  return this._deviceStateMachine.authorizedDeviceKeys;
568
561
  }
569
- async open() {
562
+ async open(ctx) {
570
563
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
571
564
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
572
- await this.space.open();
565
+ await this.space.open(ctx);
573
566
  }
574
- async close() {
567
+ async close(ctx) {
575
568
  await this.authVerifier.close();
576
569
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
577
570
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
@@ -602,11 +595,10 @@ var Identity = class {
602
595
  return this._deviceStateMachine.deviceCredentialChain;
603
596
  }
604
597
  getAdmissionCredentials() {
605
- var _a, _b;
606
598
  return {
607
599
  deviceKey: this.deviceKey,
608
- controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : (0, import_debug.failUndefined)(),
609
- dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : (0, import_debug.failUndefined)()
600
+ controlFeedKey: this.space.controlFeedKey ?? (0, import_debug.failUndefined)(),
601
+ dataFeedKey: this.space.dataFeedKey ?? (0, import_debug.failUndefined)()
610
602
  };
611
603
  }
612
604
  /**
@@ -614,7 +606,15 @@ var Identity = class {
614
606
  * Requires identity to be ready.
615
607
  */
616
608
  getIdentityCredentialSigner() {
617
- (0, import_tiny_invariant.default)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.");
609
+ (0, import_invariant.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
610
+ F: __dxlog_file2,
611
+ L: 139,
612
+ S: this,
613
+ A: [
614
+ "this._deviceStateMachine.deviceCredentialChain",
615
+ "'Device credential chain is not ready.'"
616
+ ]
617
+ });
618
618
  return (0, import_credentials2.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
619
619
  }
620
620
  /**
@@ -632,7 +632,7 @@ var Identity = class {
632
632
  dataFeedKey
633
633
  }, {
634
634
  F: __dxlog_file2,
635
- L: 151,
635
+ L: 155,
636
636
  S: this,
637
637
  C: (f, a) => f(...a)
638
638
  });
@@ -673,18 +673,40 @@ var Identity = class {
673
673
  })));
674
674
  }
675
675
  };
676
+ _ts_decorate([
677
+ import_tracing.trace.span()
678
+ ], Identity.prototype, "open", null);
679
+ _ts_decorate([
680
+ import_tracing.trace.span()
681
+ ], Identity.prototype, "close", null);
682
+ Identity = _ts_decorate([
683
+ import_tracing.trace.resource()
684
+ ], Identity);
676
685
 
677
686
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
678
- var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
679
687
  var import_async6 = require("@dxos/async");
688
+ var import_context3 = require("@dxos/context");
680
689
  var import_credentials4 = require("@dxos/credentials");
690
+ var import_invariant2 = require("@dxos/invariant");
681
691
  var import_keys4 = require("@dxos/keys");
682
692
  var import_log3 = require("@dxos/log");
683
693
  var import_protocols2 = require("@dxos/protocols");
684
694
  var import_credentials5 = require("@dxos/protocols/proto/dxos/halo/credentials");
695
+ var import_timeframe = require("@dxos/timeframe");
696
+ var import_tracing2 = require("@dxos/tracing");
685
697
  var import_util2 = require("@dxos/util");
698
+ function _ts_decorate2(decorators, target, key, desc) {
699
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
700
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
701
+ r = Reflect.decorate(decorators, target, key, desc);
702
+ else
703
+ for (var i = decorators.length - 1; i >= 0; i--)
704
+ if (d = decorators[i])
705
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
706
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
707
+ }
686
708
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
687
- var IdentityManager = class {
709
+ var IdentityManager = class IdentityManager2 {
688
710
  // TODO(burdon): IdentityManagerParams.
689
711
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
690
712
  constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
@@ -697,14 +719,13 @@ var IdentityManager = class {
697
719
  get identity() {
698
720
  return this._identity;
699
721
  }
700
- async open() {
701
- var _a;
722
+ async open(ctx) {
702
723
  const traceId = import_keys4.PublicKey.random().toHex();
703
724
  import_log3.log.trace("dxos.halo.identity-manager.open", import_protocols2.trace.begin({
704
725
  id: traceId
705
726
  }), {
706
727
  F: __dxlog_file3,
707
- L: 70,
728
+ L: 73,
708
729
  S: this,
709
730
  C: (f, a) => f(...a)
710
731
  });
@@ -714,20 +735,20 @@ var IdentityManager = class {
714
735
  identityRecord
715
736
  }, {
716
737
  F: __dxlog_file3,
717
- L: 74,
738
+ L: 77,
718
739
  S: this,
719
740
  C: (f, a) => f(...a)
720
741
  });
721
742
  if (identityRecord) {
722
743
  this._identity = await this._constructIdentity(identityRecord);
723
- await this._identity.open();
744
+ await this._identity.open(ctx);
724
745
  await this._identity.ready();
725
746
  import_log3.log.trace("dxos.halo.identity", {
726
747
  identityKey: identityRecord.identityKey,
727
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
748
+ displayName: this._identity.profileDocument?.displayName
728
749
  }, {
729
750
  F: __dxlog_file3,
730
- L: 79,
751
+ L: 82,
731
752
  S: this,
732
753
  C: (f, a) => f(...a)
733
754
  });
@@ -737,21 +758,27 @@ var IdentityManager = class {
737
758
  id: traceId
738
759
  }), {
739
760
  F: __dxlog_file3,
740
- L: 85,
761
+ L: 88,
741
762
  S: this,
742
763
  C: (f, a) => f(...a)
743
764
  });
744
765
  }
745
766
  async close() {
746
- var _a;
747
- await ((_a = this._identity) == null ? void 0 : _a.close());
767
+ await this._identity?.close(new import_context3.Context());
748
768
  }
749
769
  async createIdentity({ displayName } = {}) {
750
- var _a;
751
- (0, import_tiny_invariant2.default)(!this._identity, "Identity already exists.");
770
+ (0, import_invariant2.invariant)(!this._identity, "Identity already exists.", {
771
+ F: __dxlog_file3,
772
+ L: 96,
773
+ S: this,
774
+ A: [
775
+ "!this._identity",
776
+ "'Identity already exists.'"
777
+ ]
778
+ });
752
779
  (0, import_log3.log)("creating identity...", void 0, {
753
780
  F: __dxlog_file3,
754
- L: 94,
781
+ L: 97,
755
782
  S: this,
756
783
  C: (f, a) => f(...a)
757
784
  });
@@ -767,11 +794,27 @@ var IdentityManager = class {
767
794
  }
768
795
  };
769
796
  const identity = await this._constructIdentity(identityRecord);
770
- await identity.open();
797
+ await identity.open(new import_context3.Context());
771
798
  {
772
799
  const generator = new import_credentials4.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
773
- (0, import_tiny_invariant2.default)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.");
774
- (0, import_tiny_invariant2.default)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.");
800
+ (0, import_invariant2.invariant)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
801
+ F: __dxlog_file3,
802
+ L: 116,
803
+ S: this,
804
+ A: [
805
+ "identityRecord.haloSpace.genesisFeedKey",
806
+ "'Genesis feed key is required.'"
807
+ ]
808
+ });
809
+ (0, import_invariant2.invariant)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
810
+ F: __dxlog_file3,
811
+ L: 117,
812
+ S: this,
813
+ A: [
814
+ "identityRecord.haloSpace.dataFeedKey",
815
+ "'Data feed key is required.'"
816
+ ]
817
+ });
775
818
  const credentials = [
776
819
  // Space genesis.
777
820
  ...await generator.createSpaceGenesis(identityRecord.haloSpace.key, identityRecord.haloSpace.genesisFeedKey),
@@ -797,10 +840,10 @@ var IdentityManager = class {
797
840
  await this._identity.ready();
798
841
  import_log3.log.trace("dxos.halo.identity", {
799
842
  identityKey: identityRecord.identityKey,
800
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
843
+ displayName: this._identity.profileDocument?.displayName
801
844
  }, {
802
845
  F: __dxlog_file3,
803
- L: 149,
846
+ L: 152,
804
847
  S: this,
805
848
  C: (f, a) => f(...a)
806
849
  });
@@ -810,7 +853,7 @@ var IdentityManager = class {
810
853
  deviceKey: identity.deviceKey
811
854
  }, {
812
855
  F: __dxlog_file3,
813
- L: 155,
856
+ L: 158,
814
857
  S: this,
815
858
  C: (f, a) => f(...a)
816
859
  });
@@ -820,16 +863,23 @@ var IdentityManager = class {
820
863
  * Accept an existing identity. Expects it's device key to be authorized (now or later).
821
864
  */
822
865
  async acceptIdentity(params) {
823
- var _a;
824
866
  (0, import_log3.log)("accepting identity", {
825
867
  params
826
868
  }, {
827
869
  F: __dxlog_file3,
828
- L: 163,
870
+ L: 166,
829
871
  S: this,
830
872
  C: (f, a) => f(...a)
831
873
  });
832
- (0, import_tiny_invariant2.default)(!this._identity, "Identity already exists.");
874
+ (0, import_invariant2.invariant)(!this._identity, "Identity already exists.", {
875
+ F: __dxlog_file3,
876
+ L: 167,
877
+ S: this,
878
+ A: [
879
+ "!this._identity",
880
+ "'Identity already exists.'"
881
+ ]
882
+ });
833
883
  const identityRecord = {
834
884
  identityKey: params.identityKey,
835
885
  deviceKey: params.deviceKey,
@@ -842,16 +892,16 @@ var IdentityManager = class {
842
892
  }
843
893
  };
844
894
  const identity = await this._constructIdentity(identityRecord);
845
- await identity.open();
895
+ await identity.open(new import_context3.Context());
846
896
  this._identity = identity;
847
897
  await this._metadataStore.setIdentityRecord(identityRecord);
848
898
  await this._identity.ready();
849
899
  import_log3.log.trace("dxos.halo.identity", {
850
900
  identityKey: identityRecord.identityKey,
851
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
901
+ displayName: this._identity.profileDocument?.displayName
852
902
  }, {
853
903
  F: __dxlog_file3,
854
- L: 183,
904
+ L: 186,
855
905
  S: this,
856
906
  C: (f, a) => f(...a)
857
907
  });
@@ -861,27 +911,83 @@ var IdentityManager = class {
861
911
  deviceKey: identity.deviceKey
862
912
  }, {
863
913
  F: __dxlog_file3,
864
- L: 189,
914
+ L: 192,
865
915
  S: this,
866
916
  C: (f, a) => f(...a)
867
917
  });
868
918
  return identity;
869
919
  }
920
+ /**
921
+ * Update the profile document of an existing identity.
922
+ */
923
+ async updateProfile(profile) {
924
+ (0, import_invariant2.invariant)(this._identity, "Identity not initialized.", {
925
+ F: __dxlog_file3,
926
+ L: 200,
927
+ S: this,
928
+ A: [
929
+ "this._identity",
930
+ "'Identity not initialized.'"
931
+ ]
932
+ });
933
+ const credential = await this._identity.getIdentityCredentialSigner().createCredential({
934
+ subject: this._identity.identityKey,
935
+ assertion: {
936
+ "@type": "dxos.halo.credentials.IdentityProfile",
937
+ profile
938
+ }
939
+ });
940
+ const receipt = await this._identity.controlPipeline.writer.write({
941
+ credential: {
942
+ credential
943
+ }
944
+ });
945
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
946
+ [
947
+ receipt.feedKey,
948
+ receipt.seq
949
+ ]
950
+ ]));
951
+ }
870
952
  async _constructIdentity(identityRecord) {
871
- (0, import_tiny_invariant2.default)(!this._identity);
953
+ (0, import_invariant2.invariant)(!this._identity, void 0, {
954
+ F: __dxlog_file3,
955
+ L: 214,
956
+ S: this,
957
+ A: [
958
+ "!this._identity",
959
+ ""
960
+ ]
961
+ });
872
962
  (0, import_log3.log)("constructing identity", {
873
963
  identityRecord
874
964
  }, {
875
965
  F: __dxlog_file3,
876
- L: 195,
966
+ L: 215,
877
967
  S: this,
878
968
  C: (f, a) => f(...a)
879
969
  });
880
- (0, import_tiny_invariant2.default)(identityRecord.haloSpace.controlFeedKey);
970
+ (0, import_invariant2.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
971
+ F: __dxlog_file3,
972
+ L: 218,
973
+ S: this,
974
+ A: [
975
+ "identityRecord.haloSpace.controlFeedKey",
976
+ ""
977
+ ]
978
+ });
881
979
  const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
882
980
  writable: true
883
981
  });
884
- (0, import_tiny_invariant2.default)(identityRecord.haloSpace.dataFeedKey);
982
+ (0, import_invariant2.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
983
+ F: __dxlog_file3,
984
+ L: 222,
985
+ S: this,
986
+ A: [
987
+ "identityRecord.haloSpace.dataFeedKey",
988
+ ""
989
+ ]
990
+ });
885
991
  const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.dataFeedKey, {
886
992
  writable: true,
887
993
  sparse: true
@@ -907,7 +1013,7 @@ var IdentityManager = class {
907
1013
  identityKey: identityRecord.identityKey
908
1014
  }, {
909
1015
  F: __dxlog_file3,
910
- L: 226,
1016
+ L: 246,
911
1017
  S: this,
912
1018
  C: (f, a) => f(...a)
913
1019
  });
@@ -928,7 +1034,7 @@ var IdentityManager = class {
928
1034
  onAuthFailure: () => {
929
1035
  import_log3.log.warn("auth failure", void 0, {
930
1036
  F: __dxlog_file3,
931
- L: 245,
1037
+ L: 265,
932
1038
  S: this,
933
1039
  C: (f, a) => f(...a)
934
1040
  });
@@ -937,19 +1043,27 @@ var IdentityManager = class {
937
1043
  });
938
1044
  }
939
1045
  };
1046
+ _ts_decorate2([
1047
+ import_tracing2.trace.span()
1048
+ ], IdentityManager.prototype, "open", null);
1049
+ IdentityManager = _ts_decorate2([
1050
+ import_tracing2.trace.resource()
1051
+ ], IdentityManager);
940
1052
 
941
1053
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
942
- var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
943
1054
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
944
1055
  var import_credentials6 = require("@dxos/credentials");
945
1056
  var import_debug2 = require("@dxos/debug");
1057
+ var import_invariant3 = require("@dxos/invariant");
1058
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
946
1059
  var IdentityServiceImpl = class {
947
- // TODO(wittjosiah): Remove dependency on service context.
948
- constructor(_serviceContext) {
949
- this._serviceContext = _serviceContext;
1060
+ constructor(_createIdentity, _identityManager, _keyring) {
1061
+ this._createIdentity = _createIdentity;
1062
+ this._identityManager = _identityManager;
1063
+ this._keyring = _keyring;
950
1064
  }
951
1065
  async createIdentity(request) {
952
- await this._serviceContext.createIdentity(request);
1066
+ await this._createIdentity(request);
953
1067
  return this._getIdentity();
954
1068
  }
955
1069
  async recoverIdentity(request) {
@@ -961,34 +1075,56 @@ var IdentityServiceImpl = class {
961
1075
  identity: this._getIdentity()
962
1076
  });
963
1077
  emitNext();
964
- return this._serviceContext.identityManager.stateUpdate.on(emitNext);
1078
+ return this._identityManager.stateUpdate.on(emitNext);
965
1079
  });
966
1080
  }
967
1081
  _getIdentity() {
968
- if (!this._serviceContext.identityManager.identity) {
1082
+ if (!this._identityManager.identity) {
969
1083
  return void 0;
970
1084
  }
971
1085
  return {
972
- identityKey: this._serviceContext.identityManager.identity.identityKey,
973
- spaceKey: this._serviceContext.identityManager.identity.space.key,
974
- profile: this._serviceContext.identityManager.identity.profileDocument
1086
+ identityKey: this._identityManager.identity.identityKey,
1087
+ spaceKey: this._identityManager.identity.space.key,
1088
+ profile: this._identityManager.identity.profileDocument
975
1089
  };
976
1090
  }
1091
+ async updateProfile(profile) {
1092
+ (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1093
+ F: __dxlog_file4,
1094
+ L: 59,
1095
+ S: this,
1096
+ A: [
1097
+ "this._identityManager.identity",
1098
+ "'Identity not initialized.'"
1099
+ ]
1100
+ });
1101
+ await this._identityManager.updateProfile(profile);
1102
+ return this._getIdentity();
1103
+ }
977
1104
  async signPresentation({ presentation, nonce }) {
978
- (0, import_tiny_invariant3.default)(this._serviceContext.identityManager.identity, "Identity not initialized.");
1105
+ (0, import_invariant3.invariant)(this._identityManager.identity, "Identity not initialized.", {
1106
+ F: __dxlog_file4,
1107
+ L: 65,
1108
+ S: this,
1109
+ A: [
1110
+ "this._identityManager.identity",
1111
+ "'Identity not initialized.'"
1112
+ ]
1113
+ });
979
1114
  return await (0, import_credentials6.signPresentation)({
980
1115
  presentation,
981
- signer: this._serviceContext.keyring,
982
- signerKey: this._serviceContext.identityManager.identity.deviceKey,
983
- chain: this._serviceContext.identityManager.identity.deviceCredentialChain,
1116
+ signer: this._keyring,
1117
+ signerKey: this._identityManager.identity.deviceKey,
1118
+ chain: this._identityManager.identity.deviceCredentialChain,
984
1119
  nonce
985
1120
  });
986
1121
  }
987
1122
  };
988
1123
 
989
1124
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
990
- var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
1125
+ var import_invariant4 = require("@dxos/invariant");
991
1126
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
1127
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
992
1128
  var DeviceInvitationProtocol = class {
993
1129
  constructor(_keyring, _getIdentity, _acceptIdentity) {
994
1130
  this._keyring = _keyring;
@@ -1004,7 +1140,15 @@ var DeviceInvitationProtocol = class {
1004
1140
  };
1005
1141
  }
1006
1142
  async admit(request) {
1007
- (0, import_tiny_invariant4.default)(request.device);
1143
+ (0, import_invariant4.invariant)(request.device, void 0, {
1144
+ F: __dxlog_file5,
1145
+ L: 31,
1146
+ S: this,
1147
+ A: [
1148
+ "request.device",
1149
+ ""
1150
+ ]
1151
+ });
1008
1152
  const identity = this._getIdentity();
1009
1153
  await identity.admitDevice(request.device);
1010
1154
  return {
@@ -1032,9 +1176,25 @@ var DeviceInvitationProtocol = class {
1032
1176
  };
1033
1177
  }
1034
1178
  async accept(response, request) {
1035
- (0, import_tiny_invariant4.default)(response.device);
1179
+ (0, import_invariant4.invariant)(response.device, void 0, {
1180
+ F: __dxlog_file5,
1181
+ L: 64,
1182
+ S: this,
1183
+ A: [
1184
+ "response.device",
1185
+ ""
1186
+ ]
1187
+ });
1036
1188
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1037
- (0, import_tiny_invariant4.default)(request.device);
1189
+ (0, import_invariant4.invariant)(request.device, void 0, {
1190
+ F: __dxlog_file5,
1191
+ L: 67,
1192
+ S: this,
1193
+ A: [
1194
+ "request.device",
1195
+ ""
1196
+ ]
1197
+ });
1038
1198
  const { deviceKey, controlFeedKey, dataFeedKey } = request.device;
1039
1199
  await this._acceptIdentity({
1040
1200
  identityKey,
@@ -1052,12 +1212,12 @@ var DeviceInvitationProtocol = class {
1052
1212
  };
1053
1213
 
1054
1214
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1055
- var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
1056
1215
  var import_async8 = require("@dxos/async");
1057
1216
  var import_client_protocol2 = require("@dxos/client-protocol");
1058
- var import_context4 = require("@dxos/context");
1217
+ var import_context5 = require("@dxos/context");
1059
1218
  var import_credentials7 = require("@dxos/credentials");
1060
1219
  var import_errors2 = require("@dxos/errors");
1220
+ var import_invariant6 = require("@dxos/invariant");
1061
1221
  var import_keys6 = require("@dxos/keys");
1062
1222
  var import_log5 = require("@dxos/log");
1063
1223
  var import_network_manager = require("@dxos/network-manager");
@@ -1066,17 +1226,17 @@ var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1066
1226
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
1067
1227
 
1068
1228
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1069
- var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
1070
1229
  var import_async7 = require("@dxos/async");
1071
- var import_context3 = require("@dxos/context");
1230
+ var import_context4 = require("@dxos/context");
1072
1231
  var import_errors = require("@dxos/errors");
1232
+ var import_invariant5 = require("@dxos/invariant");
1073
1233
  var import_keys5 = require("@dxos/keys");
1074
1234
  var import_log4 = require("@dxos/log");
1075
1235
  var import_protocols3 = require("@dxos/protocols");
1076
1236
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
1077
1237
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
1078
1238
  var import_teleport = require("@dxos/teleport");
1079
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
1239
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
1080
1240
  var OPTIONS_TIMEOUT = 1e4;
1081
1241
  var MAX_OTP_ATTEMPTS = 3;
1082
1242
  var InvitationHostExtension = class extends import_teleport.RpcExtension {
@@ -1090,7 +1250,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1090
1250
  }
1091
1251
  });
1092
1252
  this._callbacks = _callbacks;
1093
- this._ctx = new import_context3.Context();
1253
+ this._ctx = new import_context4.Context();
1094
1254
  this._remoteOptionsTrigger = new import_async7.Trigger();
1095
1255
  this.invitation = void 0;
1096
1256
  this.guestProfile = void 0;
@@ -1104,7 +1264,15 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1104
1264
  // Perhaps in the future we will have more complex logic here.
1105
1265
  InvitationHostService: {
1106
1266
  options: async (options) => {
1107
- (0, import_tiny_invariant5.default)(!this._remoteOptions, "Remote options already set.");
1267
+ (0, import_invariant5.invariant)(!this._remoteOptions, "Remote options already set.", {
1268
+ F: __dxlog_file6,
1269
+ L: 88,
1270
+ S: this,
1271
+ A: [
1272
+ "!this._remoteOptions",
1273
+ "'Remote options already set.'"
1274
+ ]
1275
+ });
1108
1276
  this._remoteOptions = options;
1109
1277
  this._remoteOptionsTrigger.wake();
1110
1278
  },
@@ -1114,8 +1282,8 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1114
1282
  import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
1115
1283
  id: traceId
1116
1284
  }), {
1117
- F: __dxlog_file4,
1118
- L: 98,
1285
+ F: __dxlog_file6,
1286
+ L: 97,
1119
1287
  S: this,
1120
1288
  C: (f, a) => f(...a)
1121
1289
  });
@@ -1124,8 +1292,8 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1124
1292
  import_log4.log.warn("invitation not found", {
1125
1293
  invitationId
1126
1294
  }, {
1127
- F: __dxlog_file4,
1128
- L: 102,
1295
+ F: __dxlog_file6,
1296
+ L: 101,
1129
1297
  S: this,
1130
1298
  C: (f, a) => f(...a)
1131
1299
  });
@@ -1138,8 +1306,8 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1138
1306
  (0, import_log4.log)("guest introduced itself", {
1139
1307
  guestProfile: profile
1140
1308
  }, {
1141
- F: __dxlog_file4,
1142
- L: 111,
1309
+ F: __dxlog_file6,
1310
+ L: 110,
1143
1311
  S: this,
1144
1312
  C: (f, a) => f(...a)
1145
1313
  });
@@ -1151,8 +1319,8 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1151
1319
  import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
1152
1320
  id: traceId
1153
1321
  }), {
1154
- F: __dxlog_file4,
1155
- L: 118,
1322
+ F: __dxlog_file6,
1323
+ L: 117,
1156
1324
  S: this,
1157
1325
  C: (f, a) => f(...a)
1158
1326
  });
@@ -1166,26 +1334,34 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1166
1334
  import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
1167
1335
  id: traceId
1168
1336
  }), {
1169
- F: __dxlog_file4,
1170
- L: 127,
1337
+ F: __dxlog_file6,
1338
+ L: 126,
1171
1339
  S: this,
1172
1340
  C: (f, a) => f(...a)
1173
1341
  });
1174
1342
  (0, import_log4.log)("received authentication request", {
1175
1343
  authCode: code
1176
1344
  }, {
1177
- F: __dxlog_file4,
1178
- L: 128,
1345
+ F: __dxlog_file6,
1346
+ L: 127,
1179
1347
  S: this,
1180
1348
  C: (f, a) => f(...a)
1181
1349
  });
1182
1350
  let status = import_invitations.AuthenticationResponse.Status.OK;
1183
- (0, import_tiny_invariant5.default)(this.invitation, "Invitation is not set.");
1351
+ (0, import_invariant5.invariant)(this.invitation, "Invitation is not set.", {
1352
+ F: __dxlog_file6,
1353
+ L: 130,
1354
+ S: this,
1355
+ A: [
1356
+ "this.invitation",
1357
+ "'Invitation is not set.'"
1358
+ ]
1359
+ });
1184
1360
  switch (this.invitation.authMethod) {
1185
1361
  case import_services2.Invitation.AuthMethod.NONE: {
1186
1362
  (0, import_log4.log)("authentication not required", void 0, {
1187
- F: __dxlog_file4,
1188
- L: 134,
1363
+ F: __dxlog_file6,
1364
+ L: 133,
1189
1365
  S: this,
1190
1366
  C: (f, a) => f(...a)
1191
1367
  });
@@ -1209,8 +1385,8 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1209
1385
  import_log4.log.error("invalid authentication method", {
1210
1386
  authMethod: this.invitation.authMethod
1211
1387
  }, {
1212
- F: __dxlog_file4,
1213
- L: 152,
1388
+ F: __dxlog_file6,
1389
+ L: 151,
1214
1390
  S: this,
1215
1391
  C: (f, a) => f(...a)
1216
1392
  });
@@ -1224,8 +1400,8 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1224
1400
  status
1225
1401
  }
1226
1402
  }), {
1227
- F: __dxlog_file4,
1228
- L: 158,
1403
+ F: __dxlog_file6,
1404
+ L: 157,
1229
1405
  S: this,
1230
1406
  C: (f, a) => f(...a)
1231
1407
  });
@@ -1238,13 +1414,21 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1238
1414
  import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
1239
1415
  id: traceId
1240
1416
  }), {
1241
- F: __dxlog_file4,
1242
- L: 164,
1417
+ F: __dxlog_file6,
1418
+ L: 163,
1243
1419
  S: this,
1244
1420
  C: (f, a) => f(...a)
1245
1421
  });
1246
1422
  try {
1247
- (0, import_tiny_invariant5.default)(this.invitation, "Invitation is not set.");
1423
+ (0, import_invariant5.invariant)(this.invitation, "Invitation is not set.", {
1424
+ F: __dxlog_file6,
1425
+ L: 166,
1426
+ S: this,
1427
+ A: [
1428
+ "this.invitation",
1429
+ "'Invitation is not set.'"
1430
+ ]
1431
+ });
1248
1432
  if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
1249
1433
  throw new Error("Not authenticated");
1250
1434
  }
@@ -1252,8 +1436,8 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1252
1436
  import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.end({
1253
1437
  id: traceId
1254
1438
  }), {
1255
- F: __dxlog_file4,
1256
- L: 175,
1439
+ F: __dxlog_file6,
1440
+ L: 174,
1257
1441
  S: this,
1258
1442
  C: (f, a) => f(...a)
1259
1443
  });
@@ -1267,16 +1451,15 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1267
1451
  };
1268
1452
  }
1269
1453
  async onOpen(context) {
1270
- var _a;
1271
1454
  await super.onOpen(context);
1272
1455
  try {
1273
1456
  await this.rpc.InvitationHostService.options({
1274
1457
  role: import_invitations.Options.Role.HOST
1275
1458
  });
1276
- await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1459
+ await (0, import_context4.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1277
1460
  timeout: OPTIONS_TIMEOUT
1278
1461
  }));
1279
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.GUEST) {
1462
+ if (this._remoteOptions?.role !== import_invitations.Options.Role.GUEST) {
1280
1463
  throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1281
1464
  expected: import_invitations.Options.Role.GUEST,
1282
1465
  remoteOptions: this._remoteOptions
@@ -1302,14 +1485,22 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1302
1485
  }
1303
1486
  });
1304
1487
  this._callbacks = _callbacks;
1305
- this._ctx = new import_context3.Context();
1488
+ this._ctx = new import_context4.Context();
1306
1489
  this._remoteOptionsTrigger = new import_async7.Trigger();
1307
1490
  }
1308
1491
  async getHandlers() {
1309
1492
  return {
1310
1493
  InvitationHostService: {
1311
1494
  options: async (options) => {
1312
- (0, import_tiny_invariant5.default)(!this._remoteOptions, "Remote options already set.");
1495
+ (0, import_invariant5.invariant)(!this._remoteOptions, "Remote options already set.", {
1496
+ F: __dxlog_file6,
1497
+ L: 241,
1498
+ S: this,
1499
+ A: [
1500
+ "!this._remoteOptions",
1501
+ "'Remote options already set.'"
1502
+ ]
1503
+ });
1313
1504
  this._remoteOptions = options;
1314
1505
  this._remoteOptionsTrigger.wake();
1315
1506
  },
@@ -1326,28 +1517,27 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1326
1517
  };
1327
1518
  }
1328
1519
  async onOpen(context) {
1329
- var _a;
1330
1520
  await super.onOpen(context);
1331
1521
  try {
1332
1522
  (0, import_log4.log)("begin options", void 0, {
1333
- F: __dxlog_file4,
1334
- L: 263,
1523
+ F: __dxlog_file6,
1524
+ L: 262,
1335
1525
  S: this,
1336
1526
  C: (f, a) => f(...a)
1337
1527
  });
1338
- await (0, import_context3.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1528
+ await (0, import_context4.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1339
1529
  role: import_invitations.Options.Role.GUEST
1340
1530
  }));
1341
- await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1531
+ await (0, import_context4.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1342
1532
  timeout: OPTIONS_TIMEOUT
1343
1533
  }));
1344
1534
  (0, import_log4.log)("end options", void 0, {
1345
- F: __dxlog_file4,
1346
- L: 266,
1535
+ F: __dxlog_file6,
1536
+ L: 265,
1347
1537
  S: this,
1348
1538
  C: (f, a) => f(...a)
1349
1539
  });
1350
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.HOST) {
1540
+ if (this._remoteOptions?.role !== import_invitations.Options.Role.HOST) {
1351
1541
  throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1352
1542
  expected: import_invitations.Options.Role.HOST,
1353
1543
  remoteOptions: this._remoteOptions
@@ -1356,8 +1546,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1356
1546
  this._callbacks.onOpen(this._ctx);
1357
1547
  } catch (err) {
1358
1548
  (0, import_log4.log)("openError", err, {
1359
- F: __dxlog_file4,
1360
- L: 276,
1549
+ F: __dxlog_file6,
1550
+ L: 275,
1361
1551
  S: this,
1362
1552
  C: (f, a) => f(...a)
1363
1553
  });
@@ -1366,8 +1556,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1366
1556
  }
1367
1557
  async onClose() {
1368
1558
  (0, import_log4.log)("onClose", void 0, {
1369
- F: __dxlog_file4,
1370
- L: 282,
1559
+ F: __dxlog_file6,
1560
+ L: 281,
1371
1561
  S: this,
1372
1562
  C: (f, a) => f(...a)
1373
1563
  });
@@ -1377,7 +1567,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1377
1567
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services2.Invitation.AuthMethod.NONE;
1378
1568
 
1379
1569
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1380
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
1570
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
1381
1571
  var InvitationsHandler = class {
1382
1572
  /**
1383
1573
  * @internal
@@ -1386,10 +1576,17 @@ var InvitationsHandler = class {
1386
1576
  this._networkManager = _networkManager;
1387
1577
  }
1388
1578
  createInvitation(protocol, options) {
1389
- var _a;
1390
- const { invitationId = import_keys6.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys6.PublicKey.random() } = options != null ? options : {};
1391
- const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0;
1392
- (0, import_tiny_invariant6.default)(protocol);
1579
+ const { invitationId = import_keys6.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys6.PublicKey.random() } = options ?? {};
1580
+ const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1581
+ (0, import_invariant6.invariant)(protocol, void 0, {
1582
+ F: __dxlog_file7,
1583
+ L: 76,
1584
+ S: this,
1585
+ A: [
1586
+ "protocol",
1587
+ ""
1588
+ ]
1589
+ });
1393
1590
  const invitation = {
1394
1591
  invitationId,
1395
1592
  type,
@@ -1401,7 +1598,7 @@ var InvitationsHandler = class {
1401
1598
  ...protocol.getInvitationContext()
1402
1599
  };
1403
1600
  const stream = new import_async8.PushStream();
1404
- const ctx = new import_context4.Context({
1601
+ const ctx = new import_context5.Context({
1405
1602
  onError: (err) => {
1406
1603
  void ctx.dispose();
1407
1604
  stream.error(err);
@@ -1411,8 +1608,8 @@ var InvitationsHandler = class {
1411
1608
  (0, import_log5.log)("complete", {
1412
1609
  ...protocol.toJSON()
1413
1610
  }, {
1414
- F: __dxlog_file5,
1415
- L: 99,
1611
+ F: __dxlog_file7,
1612
+ L: 98,
1416
1613
  S: this,
1417
1614
  C: (f, a) => f(...a)
1418
1615
  });
@@ -1433,10 +1630,17 @@ var InvitationsHandler = class {
1433
1630
  return invitation;
1434
1631
  },
1435
1632
  admit: async (admissionRequest) => {
1436
- var _a2, _b, _c;
1437
1633
  try {
1438
- const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1439
- (0, import_tiny_invariant6.default)(deviceKey);
1634
+ const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1635
+ (0, import_invariant6.invariant)(deviceKey, void 0, {
1636
+ F: __dxlog_file7,
1637
+ L: 119,
1638
+ S: this,
1639
+ A: [
1640
+ "deviceKey",
1641
+ ""
1642
+ ]
1643
+ });
1440
1644
  const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1441
1645
  extension.completedTrigger.wake(deviceKey);
1442
1646
  return admissionResponse;
@@ -1452,16 +1656,16 @@ var InvitationsHandler = class {
1452
1656
  import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1453
1657
  id: traceId
1454
1658
  }), {
1455
- F: __dxlog_file5,
1456
- L: 138,
1659
+ F: __dxlog_file7,
1660
+ L: 137,
1457
1661
  S: this,
1458
1662
  C: (f, a) => f(...a)
1459
1663
  });
1460
1664
  (0, import_log5.log)("connected", {
1461
1665
  ...protocol.toJSON()
1462
1666
  }, {
1463
- F: __dxlog_file5,
1464
- L: 139,
1667
+ F: __dxlog_file7,
1668
+ L: 138,
1465
1669
  S: this,
1466
1670
  C: (f, a) => f(...a)
1467
1671
  });
@@ -1476,8 +1680,8 @@ var InvitationsHandler = class {
1476
1680
  guest: deviceKey,
1477
1681
  ...protocol.toJSON()
1478
1682
  }, {
1479
- F: __dxlog_file5,
1480
- L: 142,
1683
+ F: __dxlog_file7,
1684
+ L: 141,
1481
1685
  S: this,
1482
1686
  C: (f, a) => f(...a)
1483
1687
  });
@@ -1488,8 +1692,8 @@ var InvitationsHandler = class {
1488
1692
  import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1489
1693
  id: traceId
1490
1694
  }), {
1491
- F: __dxlog_file5,
1492
- L: 144,
1695
+ F: __dxlog_file7,
1696
+ L: 143,
1493
1697
  S: this,
1494
1698
  C: (f, a) => f(...a)
1495
1699
  });
@@ -1498,8 +1702,8 @@ var InvitationsHandler = class {
1498
1702
  (0, import_log5.log)("timeout", {
1499
1703
  ...protocol.toJSON()
1500
1704
  }, {
1501
- F: __dxlog_file5,
1502
- L: 147,
1705
+ F: __dxlog_file7,
1706
+ L: 146,
1503
1707
  S: this,
1504
1708
  C: (f, a) => f(...a)
1505
1709
  });
@@ -1509,8 +1713,8 @@ var InvitationsHandler = class {
1509
1713
  });
1510
1714
  } else {
1511
1715
  import_log5.log.error("failed", err, {
1512
- F: __dxlog_file5,
1513
- L: 150,
1716
+ F: __dxlog_file7,
1717
+ L: 149,
1514
1718
  S: this,
1515
1719
  C: (f, a) => f(...a)
1516
1720
  });
@@ -1520,8 +1724,8 @@ var InvitationsHandler = class {
1520
1724
  id: traceId,
1521
1725
  error: err
1522
1726
  }), {
1523
- F: __dxlog_file5,
1524
- L: 153,
1727
+ F: __dxlog_file7,
1728
+ L: 152,
1525
1729
  S: this,
1526
1730
  C: (f, a) => f(...a)
1527
1731
  });
@@ -1541,8 +1745,8 @@ var InvitationsHandler = class {
1541
1745
  (0, import_log5.log)("timeout", {
1542
1746
  ...protocol.toJSON()
1543
1747
  }, {
1544
- F: __dxlog_file5,
1545
- L: 168,
1748
+ F: __dxlog_file7,
1749
+ L: 167,
1546
1750
  S: this,
1547
1751
  C: (f, a) => f(...a)
1548
1752
  });
@@ -1552,8 +1756,8 @@ var InvitationsHandler = class {
1552
1756
  });
1553
1757
  } else {
1554
1758
  import_log5.log.error("failed", err, {
1555
- F: __dxlog_file5,
1556
- L: 171,
1759
+ F: __dxlog_file7,
1760
+ L: 170,
1557
1761
  S: this,
1558
1762
  C: (f, a) => f(...a)
1559
1763
  });
@@ -1595,27 +1799,43 @@ var InvitationsHandler = class {
1595
1799
  }
1596
1800
  acceptInvitation(protocol, invitation) {
1597
1801
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
1598
- (0, import_tiny_invariant6.default)(protocol);
1802
+ (0, import_invariant6.invariant)(protocol, void 0, {
1803
+ F: __dxlog_file7,
1804
+ L: 210,
1805
+ S: this,
1806
+ A: [
1807
+ "protocol",
1808
+ ""
1809
+ ]
1810
+ });
1599
1811
  const authenticated = new import_async8.Trigger();
1600
1812
  let admitted = false;
1601
1813
  let currentState;
1602
1814
  const stream = new import_async8.PushStream();
1603
1815
  const setState = (newData) => {
1604
- (0, import_tiny_invariant6.default)(newData.state !== void 0);
1816
+ (0, import_invariant6.invariant)(newData.state !== void 0, void 0, {
1817
+ F: __dxlog_file7,
1818
+ L: 221,
1819
+ S: this,
1820
+ A: [
1821
+ "newData.state !== undefined",
1822
+ ""
1823
+ ]
1824
+ });
1605
1825
  currentState = newData.state;
1606
1826
  stream.next({
1607
1827
  ...invitation,
1608
1828
  ...newData
1609
1829
  });
1610
1830
  };
1611
- const ctx = new import_context4.Context({
1831
+ const ctx = new import_context5.Context({
1612
1832
  onError: (err) => {
1613
1833
  if (err instanceof import_async8.TimeoutError) {
1614
1834
  (0, import_log5.log)("timeout", {
1615
1835
  ...protocol.toJSON()
1616
1836
  }, {
1617
- F: __dxlog_file5,
1618
- L: 230,
1837
+ F: __dxlog_file7,
1838
+ L: 229,
1619
1839
  S: this,
1620
1840
  C: (f, a) => f(...a)
1621
1841
  });
@@ -1624,8 +1844,8 @@ var InvitationsHandler = class {
1624
1844
  });
1625
1845
  } else {
1626
1846
  import_log5.log.warn("auth failed", err, {
1627
- F: __dxlog_file5,
1628
- L: 233,
1847
+ F: __dxlog_file7,
1848
+ L: 232,
1629
1849
  S: this,
1630
1850
  C: (f, a) => f(...a)
1631
1851
  });
@@ -1638,8 +1858,8 @@ var InvitationsHandler = class {
1638
1858
  (0, import_log5.log)("complete", {
1639
1859
  ...protocol.toJSON()
1640
1860
  }, {
1641
- F: __dxlog_file5,
1642
- L: 241,
1861
+ F: __dxlog_file7,
1862
+ L: 240,
1643
1863
  S: this,
1644
1864
  C: (f, a) => f(...a)
1645
1865
  });
@@ -1653,8 +1873,8 @@ var InvitationsHandler = class {
1653
1873
  (0, import_log5.log)("extension disposed", {
1654
1874
  currentState
1655
1875
  }, {
1656
- F: __dxlog_file5,
1657
- L: 251,
1876
+ F: __dxlog_file7,
1877
+ L: 250,
1658
1878
  S: this,
1659
1879
  C: (f, a) => f(...a)
1660
1880
  });
@@ -1668,8 +1888,8 @@ var InvitationsHandler = class {
1668
1888
  import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
1669
1889
  id: traceId
1670
1890
  }), {
1671
- F: __dxlog_file5,
1672
- L: 260,
1891
+ F: __dxlog_file7,
1892
+ L: 259,
1673
1893
  S: this,
1674
1894
  C: (f, a) => f(...a)
1675
1895
  });
@@ -1680,8 +1900,8 @@ var InvitationsHandler = class {
1680
1900
  (0, import_log5.log)("connected", {
1681
1901
  ...protocol.toJSON()
1682
1902
  }, {
1683
- F: __dxlog_file5,
1684
- L: 268,
1903
+ F: __dxlog_file7,
1904
+ L: 267,
1685
1905
  S: this,
1686
1906
  C: (f, a) => f(...a)
1687
1907
  });
@@ -1691,8 +1911,8 @@ var InvitationsHandler = class {
1691
1911
  (0, import_log5.log)("introduce", {
1692
1912
  ...protocol.toJSON()
1693
1913
  }, {
1694
- F: __dxlog_file5,
1695
- L: 272,
1914
+ F: __dxlog_file7,
1915
+ L: 271,
1696
1916
  S: this,
1697
1917
  C: (f, a) => f(...a)
1698
1918
  });
@@ -1701,8 +1921,8 @@ var InvitationsHandler = class {
1701
1921
  ...protocol.toJSON(),
1702
1922
  response: introductionResponse
1703
1923
  }, {
1704
- F: __dxlog_file5,
1705
- L: 276,
1924
+ F: __dxlog_file7,
1925
+ L: 275,
1706
1926
  S: this,
1707
1927
  C: (f, a) => f(...a)
1708
1928
  });
@@ -1713,8 +1933,8 @@ var InvitationsHandler = class {
1713
1933
  if (isAuthenticationRequired(invitation)) {
1714
1934
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1715
1935
  (0, import_log5.log)("guest waiting for authentication code...", void 0, {
1716
- F: __dxlog_file5,
1717
- L: 285,
1936
+ F: __dxlog_file7,
1937
+ L: 284,
1718
1938
  S: this,
1719
1939
  C: (f, a) => f(...a)
1720
1940
  });
@@ -1725,8 +1945,8 @@ var InvitationsHandler = class {
1725
1945
  timeout
1726
1946
  });
1727
1947
  (0, import_log5.log)("sending authentication request", void 0, {
1728
- F: __dxlog_file5,
1729
- L: 289,
1948
+ F: __dxlog_file7,
1949
+ L: 288,
1730
1950
  S: this,
1731
1951
  C: (f, a) => f(...a)
1732
1952
  });
@@ -1746,8 +1966,8 @@ var InvitationsHandler = class {
1746
1966
  (0, import_log5.log)("retrying invalid code", {
1747
1967
  attempt
1748
1968
  }, {
1749
- F: __dxlog_file5,
1750
- L: 300,
1969
+ F: __dxlog_file7,
1970
+ L: 299,
1751
1971
  S: this,
1752
1972
  C: (f, a) => f(...a)
1753
1973
  });
@@ -1763,8 +1983,8 @@ var InvitationsHandler = class {
1763
1983
  (0, import_log5.log)("request admission", {
1764
1984
  ...protocol.toJSON()
1765
1985
  }, {
1766
- F: __dxlog_file5,
1767
- L: 311,
1986
+ F: __dxlog_file7,
1987
+ L: 310,
1768
1988
  S: this,
1769
1989
  C: (f, a) => f(...a)
1770
1990
  });
@@ -1775,8 +1995,8 @@ var InvitationsHandler = class {
1775
1995
  (0, import_log5.log)("admitted by host", {
1776
1996
  ...protocol.toJSON()
1777
1997
  }, {
1778
- F: __dxlog_file5,
1779
- L: 322,
1998
+ F: __dxlog_file7,
1999
+ L: 321,
1780
2000
  S: this,
1781
2001
  C: (f, a) => f(...a)
1782
2002
  });
@@ -1787,8 +2007,8 @@ var InvitationsHandler = class {
1787
2007
  import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
1788
2008
  id: traceId
1789
2009
  }), {
1790
- F: __dxlog_file5,
1791
- L: 324,
2010
+ F: __dxlog_file7,
2011
+ L: 323,
1792
2012
  S: this,
1793
2013
  C: (f, a) => f(...a)
1794
2014
  });
@@ -1797,8 +2017,8 @@ var InvitationsHandler = class {
1797
2017
  (0, import_log5.log)("timeout", {
1798
2018
  ...protocol.toJSON()
1799
2019
  }, {
1800
- F: __dxlog_file5,
1801
- L: 327,
2020
+ F: __dxlog_file7,
2021
+ L: 326,
1802
2022
  S: this,
1803
2023
  C: (f, a) => f(...a)
1804
2024
  });
@@ -1807,8 +2027,8 @@ var InvitationsHandler = class {
1807
2027
  });
1808
2028
  } else {
1809
2029
  (0, import_log5.log)("auth failed", err, {
1810
- F: __dxlog_file5,
1811
- L: 330,
2030
+ F: __dxlog_file7,
2031
+ L: 329,
1812
2032
  S: this,
1813
2033
  C: (f, a) => f(...a)
1814
2034
  });
@@ -1818,8 +2038,8 @@ var InvitationsHandler = class {
1818
2038
  id: traceId,
1819
2039
  error: err
1820
2040
  }), {
1821
- F: __dxlog_file5,
1822
- L: 333,
2041
+ F: __dxlog_file7,
2042
+ L: 332,
1823
2043
  S: this,
1824
2044
  C: (f, a) => f(...a)
1825
2045
  });
@@ -1836,8 +2056,8 @@ var InvitationsHandler = class {
1836
2056
  (0, import_log5.log)("timeout", {
1837
2057
  ...protocol.toJSON()
1838
2058
  }, {
1839
- F: __dxlog_file5,
1840
- L: 344,
2059
+ F: __dxlog_file7,
2060
+ L: 343,
1841
2061
  S: this,
1842
2062
  C: (f, a) => f(...a)
1843
2063
  });
@@ -1846,8 +2066,8 @@ var InvitationsHandler = class {
1846
2066
  });
1847
2067
  } else {
1848
2068
  (0, import_log5.log)("auth failed", err, {
1849
- F: __dxlog_file5,
1850
- L: 347,
2069
+ F: __dxlog_file7,
2070
+ L: 346,
1851
2071
  S: this,
1852
2072
  C: (f, a) => f(...a)
1853
2073
  });
@@ -1858,7 +2078,15 @@ var InvitationsHandler = class {
1858
2078
  return extension;
1859
2079
  };
1860
2080
  (0, import_async8.scheduleTask)(ctx, async () => {
1861
- (0, import_tiny_invariant6.default)(invitation.swarmKey);
2081
+ (0, import_invariant6.invariant)(invitation.swarmKey, void 0, {
2082
+ F: __dxlog_file7,
2083
+ L: 356,
2084
+ S: this,
2085
+ A: [
2086
+ "invitation.swarmKey",
2087
+ ""
2088
+ ]
2089
+ });
1862
2090
  const topic = invitation.swarmKey;
1863
2091
  const swarmConnection = await this._networkManager.joinSwarm({
1864
2092
  topic,
@@ -1891,12 +2119,12 @@ var InvitationsHandler = class {
1891
2119
  };
1892
2120
 
1893
2121
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1894
- var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
1895
2122
  var import_async9 = require("@dxos/async");
1896
2123
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
2124
+ var import_invariant7 = require("@dxos/invariant");
1897
2125
  var import_log6 = require("@dxos/log");
1898
2126
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
1899
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2127
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
1900
2128
  var InvitationsServiceImpl = class {
1901
2129
  constructor(_invitationsHandler, _getHandler) {
1902
2130
  this._invitationsHandler = _invitationsHandler;
@@ -1958,19 +2186,27 @@ var InvitationsServiceImpl = class {
1958
2186
  }
1959
2187
  async authenticate({ invitationId, authCode }) {
1960
2188
  (0, import_log6.log)("authenticating...", void 0, {
1961
- F: __dxlog_file6,
1962
- L: 103,
2189
+ F: __dxlog_file8,
2190
+ L: 102,
1963
2191
  S: this,
1964
2192
  C: (f, a) => f(...a)
1965
2193
  });
1966
- (0, import_tiny_invariant7.default)(invitationId);
2194
+ (0, import_invariant7.invariant)(invitationId, void 0, {
2195
+ F: __dxlog_file8,
2196
+ L: 103,
2197
+ S: this,
2198
+ A: [
2199
+ "invitationId",
2200
+ ""
2201
+ ]
2202
+ });
1967
2203
  const observable = this._acceptInvitations.get(invitationId);
1968
2204
  if (!observable) {
1969
2205
  import_log6.log.warn("invalid invitation", {
1970
2206
  invitationId
1971
2207
  }, {
1972
- F: __dxlog_file6,
1973
- L: 107,
2208
+ F: __dxlog_file8,
2209
+ L: 106,
1974
2210
  S: this,
1975
2211
  C: (f, a) => f(...a)
1976
2212
  });
@@ -1980,12 +2216,20 @@ var InvitationsServiceImpl = class {
1980
2216
  }
1981
2217
  async cancelInvitation({ invitationId }) {
1982
2218
  (0, import_log6.log)("deleting...", void 0, {
1983
- F: __dxlog_file6,
1984
- L: 114,
2219
+ F: __dxlog_file8,
2220
+ L: 113,
1985
2221
  S: this,
1986
2222
  C: (f, a) => f(...a)
1987
2223
  });
1988
- (0, import_tiny_invariant7.default)(invitationId);
2224
+ (0, import_invariant7.invariant)(invitationId, void 0, {
2225
+ F: __dxlog_file8,
2226
+ L: 114,
2227
+ S: this,
2228
+ A: [
2229
+ "invitationId",
2230
+ ""
2231
+ ]
2232
+ });
1989
2233
  const created = this._createInvitations.get(invitationId);
1990
2234
  const accepted = this._acceptInvitations.get(invitationId);
1991
2235
  if (created) {
@@ -2000,8 +2244,8 @@ var InvitationsServiceImpl = class {
2000
2244
  import_log6.log.warn("invalid invitation", {
2001
2245
  invitationId
2002
2246
  }, {
2003
- F: __dxlog_file6,
2004
- L: 127,
2247
+ F: __dxlog_file8,
2248
+ L: 126,
2005
2249
  S: this,
2006
2250
  C: (f, a) => f(...a)
2007
2251
  });
@@ -2060,12 +2304,12 @@ var InvitationsServiceImpl = class {
2060
2304
  };
2061
2305
 
2062
2306
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2063
- var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
2064
2307
  var import_credentials8 = require("@dxos/credentials");
2065
2308
  var import_feed_store3 = require("@dxos/feed-store");
2309
+ var import_invariant8 = require("@dxos/invariant");
2066
2310
  var import_log7 = require("@dxos/log");
2067
2311
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
2068
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2312
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2069
2313
  var SpaceInvitationProtocol = class {
2070
2314
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2071
2315
  this._spaceManager = _spaceManager;
@@ -2086,31 +2330,70 @@ var SpaceInvitationProtocol = class {
2086
2330
  };
2087
2331
  }
2088
2332
  async admit(request, guestProfile) {
2089
- var _a;
2090
- (0, import_tiny_invariant8.default)(this._spaceKey);
2333
+ (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2334
+ F: __dxlog_file9,
2335
+ L: 42,
2336
+ S: this,
2337
+ A: [
2338
+ "this._spaceKey",
2339
+ ""
2340
+ ]
2341
+ });
2091
2342
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2092
- (0, import_tiny_invariant8.default)(space);
2093
- (0, import_tiny_invariant8.default)(request.space);
2343
+ (0, import_invariant8.invariant)(space, void 0, {
2344
+ F: __dxlog_file9,
2345
+ L: 44,
2346
+ S: this,
2347
+ A: [
2348
+ "space",
2349
+ ""
2350
+ ]
2351
+ });
2352
+ (0, import_invariant8.invariant)(request.space, void 0, {
2353
+ F: __dxlog_file9,
2354
+ L: 46,
2355
+ S: this,
2356
+ A: [
2357
+ "request.space",
2358
+ ""
2359
+ ]
2360
+ });
2094
2361
  const { identityKey, deviceKey } = request.space;
2095
2362
  (0, import_log7.log)("writing guest credentials", {
2096
2363
  host: this._signingContext.deviceKey,
2097
2364
  guest: deviceKey
2098
2365
  }, {
2099
- F: __dxlog_file7,
2100
- L: 50,
2366
+ F: __dxlog_file9,
2367
+ L: 49,
2101
2368
  S: this,
2102
2369
  C: (f, a) => f(...a)
2103
2370
  });
2104
2371
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2105
- (0, import_tiny_invariant8.default)(credentials[0].credential);
2372
+ (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2373
+ F: __dxlog_file9,
2374
+ L: 60,
2375
+ S: this,
2376
+ A: [
2377
+ "credentials[0].credential",
2378
+ ""
2379
+ ]
2380
+ });
2106
2381
  const spaceMemberCredential = credentials[0].credential.credential;
2107
- (0, import_tiny_invariant8.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2382
+ (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2383
+ F: __dxlog_file9,
2384
+ L: 62,
2385
+ S: this,
2386
+ A: [
2387
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
2388
+ ""
2389
+ ]
2390
+ });
2108
2391
  await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
2109
2392
  return {
2110
2393
  space: {
2111
2394
  credential: spaceMemberCredential,
2112
2395
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2113
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2396
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2114
2397
  }
2115
2398
  };
2116
2399
  }
@@ -2132,11 +2415,35 @@ var SpaceInvitationProtocol = class {
2132
2415
  };
2133
2416
  }
2134
2417
  async accept(response) {
2135
- (0, import_tiny_invariant8.default)(response.space);
2418
+ (0, import_invariant8.invariant)(response.space, void 0, {
2419
+ F: __dxlog_file9,
2420
+ L: 97,
2421
+ S: this,
2422
+ A: [
2423
+ "response.space",
2424
+ ""
2425
+ ]
2426
+ });
2136
2427
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2137
2428
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2138
- (0, import_tiny_invariant8.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2139
- (0, import_tiny_invariant8.default)(credential.subject.id.equals(this._signingContext.identityKey));
2429
+ (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2430
+ F: __dxlog_file9,
2431
+ L: 100,
2432
+ S: this,
2433
+ A: [
2434
+ "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
2435
+ "'Invalid credential'"
2436
+ ]
2437
+ });
2438
+ (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2439
+ F: __dxlog_file9,
2440
+ L: 101,
2441
+ S: this,
2442
+ A: [
2443
+ "credential.subject.id.equals(this._signingContext.identityKey)",
2444
+ ""
2445
+ ]
2446
+ });
2140
2447
  await this._spaceManager.acceptSpace({
2141
2448
  spaceKey: assertion.spaceKey,
2142
2449
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2190,9 +2497,8 @@ var ClientRpcServer = class {
2190
2497
  await this._rpcPeer.close();
2191
2498
  }
2192
2499
  _getServiceHandler(serviceName) {
2193
- var _a;
2194
2500
  if (!this._handlerCache.has(serviceName)) {
2195
- const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : (0, import_debug3.raise)(new Error(`Service not available: ${serviceName}`));
2501
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? (0, import_debug3.raise)(new Error(`Service not available: ${serviceName}`));
2196
2502
  const service = this._serviceRegistry.services[key];
2197
2503
  if (!service) {
2198
2504
  throw new Error(`Service not available: ${serviceName}`);
@@ -2203,63 +2509,224 @@ var ClientRpcServer = class {
2203
2509
  }
2204
2510
  };
2205
2511
 
2512
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2513
+ var import_codec_protobuf10 = require("@dxos/codec-protobuf");
2514
+ var import_credentials9 = require("@dxos/credentials");
2515
+ var import_document_model = require("@dxos/document-model");
2516
+ var import_invariant9 = require("@dxos/invariant");
2517
+ var import_log8 = require("@dxos/log");
2518
+ var import_protocols5 = require("@dxos/protocols");
2519
+ var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
2520
+
2521
+ // packages/sdk/client-services/src/version.ts
2522
+ var DXOS_VERSION = "0.1.56-main.ed2f871";
2523
+
2524
+ // packages/sdk/client-services/src/packlets/services/platform.ts
2525
+ var getPlatform = () => {
2526
+ if (process.browser) {
2527
+ if (typeof window !== "undefined") {
2528
+ const { userAgent } = window.navigator;
2529
+ return {
2530
+ type: "browser",
2531
+ userAgent,
2532
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2533
+ };
2534
+ } else {
2535
+ return {
2536
+ type: "shared-worker",
2537
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2538
+ };
2539
+ }
2540
+ } else {
2541
+ const { platform, version, arch } = process;
2542
+ return {
2543
+ type: "node",
2544
+ platform: `${platform} ${version} ${arch}`,
2545
+ runtime: process.version,
2546
+ uptime: Math.floor(process.uptime()),
2547
+ memory: process.memoryUsage()
2548
+ };
2549
+ }
2550
+ };
2551
+
2552
+ // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2553
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2554
+ var DEFAULT_TIMEOUT = 1e3;
2555
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
2556
+ const diagnostics = {
2557
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2558
+ platform: getPlatform(),
2559
+ client: {
2560
+ version: DXOS_VERSION,
2561
+ storage: {
2562
+ version: import_protocols5.STORAGE_VERSION
2563
+ }
2564
+ }
2565
+ };
2566
+ {
2567
+ (0, import_invariant9.invariant)(clientServices.LoggingService, "SystemService is not available.", {
2568
+ F: __dxlog_file10,
2569
+ L: 87,
2570
+ S: void 0,
2571
+ A: [
2572
+ "clientServices.LoggingService",
2573
+ "'SystemService is not available.'"
2574
+ ]
2575
+ });
2576
+ diagnostics.metrics = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
2577
+ timeout: DEFAULT_TIMEOUT
2578
+ }).catch(() => void 0);
2579
+ }
2580
+ const identity = serviceContext.identityManager.identity;
2581
+ if (identity) {
2582
+ diagnostics.identity = {
2583
+ identityKey: identity.identityKey,
2584
+ spaceKey: identity.space.key,
2585
+ profile: identity.profileDocument
2586
+ };
2587
+ const { devices } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
2588
+ timeout: DEFAULT_TIMEOUT
2589
+ }).catch(() => void 0) ?? {};
2590
+ diagnostics.devices = devices;
2591
+ if (serviceContext.dataSpaceManager) {
2592
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2593
+ }
2594
+ const { feeds = [] } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2595
+ timeout: DEFAULT_TIMEOUT
2596
+ }).catch(() => void 0) ?? {};
2597
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2598
+ feedKey,
2599
+ bytes,
2600
+ length
2601
+ }));
2602
+ }
2603
+ diagnostics.config = config.values;
2604
+ return diagnostics;
2605
+ };
2606
+ var getProperties = (space) => {
2607
+ let properties = {};
2608
+ try {
2609
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === import_document_model.DocumentModel.meta.type && item.state?.type === "dxos.sdk.client.Properties");
2610
+ const state = propertiesItem?.state;
2611
+ properties = state?.data;
2612
+ } catch (err) {
2613
+ import_log8.log.warn(err.message, void 0, {
2614
+ F: __dxlog_file10,
2615
+ L: 144,
2616
+ S: void 0,
2617
+ C: (f, a) => f(...a)
2618
+ });
2619
+ }
2620
+ return properties;
2621
+ };
2622
+ var getSpaceStats = async (space) => {
2623
+ const stats = {
2624
+ key: space.key,
2625
+ metrics: space.metrics,
2626
+ epochs: space.inner.spaceState.credentials.filter((0, import_credentials9.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
2627
+ ...credential.subject.assertion,
2628
+ id: credential.id
2629
+ })),
2630
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2631
+ identity: {
2632
+ identityKey: member.key,
2633
+ profile: {
2634
+ displayName: member.assertion.profile?.displayName
2635
+ }
2636
+ },
2637
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services6.SpaceMember.PresenceState.ONLINE : import_services6.SpaceMember.PresenceState.OFFLINE
2638
+ })),
2639
+ pipeline: {
2640
+ // TODO(burdon): Pick properties from credentials if needed.
2641
+ // currentEpoch: space.dataPipeline.currentEpoch,
2642
+ // appliedEpoch: space.dataPipeline.appliedEpoch,
2643
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2644
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2645
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2646
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2647
+ // TODO(burdon): Empty?
2648
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
2649
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
2650
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
2651
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
2652
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
2653
+ }
2654
+ };
2655
+ if (space.dataPipeline.itemManager) {
2656
+ Object.assign(stats, {
2657
+ properties: getProperties(space),
2658
+ db: {
2659
+ objects: space.dataPipeline.itemManager.entities.size
2660
+ }
2661
+ });
2662
+ }
2663
+ if (stats.metrics) {
2664
+ const { open, ready } = stats.metrics;
2665
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
2666
+ }
2667
+ return stats;
2668
+ };
2669
+
2206
2670
  // packages/sdk/client-services/src/packlets/services/service-context.ts
2207
- var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
2208
2671
  var import_async14 = require("@dxos/async");
2209
- var import_credentials13 = require("@dxos/credentials");
2672
+ var import_context9 = require("@dxos/context");
2673
+ var import_credentials14 = require("@dxos/credentials");
2210
2674
  var import_debug7 = require("@dxos/debug");
2211
2675
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
2212
2676
  var import_feed_store4 = require("@dxos/feed-store");
2677
+ var import_invariant12 = require("@dxos/invariant");
2213
2678
  var import_keyring = require("@dxos/keyring");
2214
2679
  var import_keys10 = require("@dxos/keys");
2215
- var import_log12 = require("@dxos/log");
2216
- var import_protocols8 = require("@dxos/protocols");
2217
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
2680
+ var import_log13 = require("@dxos/log");
2681
+ var import_protocols9 = require("@dxos/protocols");
2682
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
2218
2683
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
2684
+ var import_tracing3 = require("@dxos/tracing");
2685
+ var import_util7 = require("@dxos/util");
2219
2686
 
2220
2687
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2221
- var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
2222
2688
  var import_async12 = require("@dxos/async");
2223
- var import_context7 = require("@dxos/context");
2224
- var import_credentials12 = require("@dxos/credentials");
2689
+ var import_context8 = require("@dxos/context");
2690
+ var import_credentials13 = require("@dxos/credentials");
2691
+ var import_invariant11 = require("@dxos/invariant");
2225
2692
  var import_keys9 = require("@dxos/keys");
2226
- var import_log10 = require("@dxos/log");
2227
- var import_protocols6 = require("@dxos/protocols");
2228
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2693
+ var import_log11 = require("@dxos/log");
2694
+ var import_protocols7 = require("@dxos/protocols");
2695
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
2229
2696
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
2230
2697
  var import_util5 = require("@dxos/util");
2231
2698
 
2232
2699
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2233
2700
  var import_async11 = require("@dxos/async");
2234
2701
  var import_client_protocol3 = require("@dxos/client-protocol");
2235
- var import_context6 = require("@dxos/context");
2702
+ var import_context7 = require("@dxos/context");
2236
2703
  var import_debug4 = require("@dxos/debug");
2237
2704
  var import_echo_pipeline = require("@dxos/echo-pipeline");
2238
2705
  var import_errors3 = require("@dxos/errors");
2239
2706
  var import_keys8 = require("@dxos/keys");
2240
- var import_log9 = require("@dxos/log");
2241
- var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
2242
- var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
2243
- var import_timeframe = require("@dxos/timeframe");
2707
+ var import_log10 = require("@dxos/log");
2708
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2709
+ var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
2710
+ var import_timeframe2 = require("@dxos/timeframe");
2244
2711
  var import_util4 = require("@dxos/util");
2245
2712
 
2246
2713
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2247
- var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
2248
2714
  var import_async10 = require("@dxos/async");
2249
- var import_context5 = require("@dxos/context");
2715
+ var import_context6 = require("@dxos/context");
2716
+ var import_invariant10 = require("@dxos/invariant");
2250
2717
  var import_keys7 = require("@dxos/keys");
2251
- var import_log8 = require("@dxos/log");
2252
- var import_protocols5 = require("@dxos/protocols");
2718
+ var import_log9 = require("@dxos/log");
2719
+ var import_protocols6 = require("@dxos/protocols");
2253
2720
  var import_teleport2 = require("@dxos/teleport");
2254
2721
  var import_util3 = require("@dxos/util");
2255
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2722
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
2256
2723
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2257
2724
  var DEFAULT_SUCCESS_DELAY = 1e3;
2258
2725
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2259
2726
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2260
2727
  var NotarizationPlugin = class {
2261
2728
  constructor() {
2262
- this._ctx = new import_context5.Context();
2729
+ this._ctx = new import_context6.Context();
2263
2730
  this._extensionOpened = new import_async10.Event();
2264
2731
  this._extensions = /* @__PURE__ */ new Set();
2265
2732
  this._processedCredentials = new import_util3.ComplexSet(import_keys7.PublicKey.hash);
@@ -2277,23 +2744,31 @@ var NotarizationPlugin = class {
2277
2744
  * Request credentials to be notarized.
2278
2745
  */
2279
2746
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2280
- (0, import_log8.log)("notarize", {
2747
+ (0, import_log9.log)("notarize", {
2281
2748
  credentials
2282
2749
  }, {
2283
- F: __dxlog_file8,
2284
- L: 91,
2750
+ F: __dxlog_file11,
2751
+ L: 90,
2285
2752
  S: this,
2286
2753
  C: (f, a) => f(...a)
2287
2754
  });
2288
- (0, import_tiny_invariant9.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2755
+ (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2756
+ F: __dxlog_file11,
2757
+ L: 91,
2758
+ S: this,
2759
+ A: [
2760
+ "credentials.every((credential) => credential.id)",
2761
+ "'Credentials must have an id'"
2762
+ ]
2763
+ });
2289
2764
  const errors = new import_async10.Trigger();
2290
2765
  const ctx = this._ctx.derive({
2291
2766
  onError: (err) => {
2292
- import_log8.log.warn("Notarization error", {
2767
+ import_log9.log.warn("Notarization error", {
2293
2768
  err
2294
2769
  }, {
2295
- F: __dxlog_file8,
2296
- L: 100,
2770
+ F: __dxlog_file11,
2771
+ L: 99,
2297
2772
  S: this,
2298
2773
  C: (f, a) => f(...a)
2299
2774
  });
@@ -2301,15 +2776,15 @@ var NotarizationPlugin = class {
2301
2776
  errors.throw(err);
2302
2777
  }
2303
2778
  });
2304
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2779
+ opCtx?.onDispose(() => ctx.dispose());
2305
2780
  if (timeout !== 0) {
2306
2781
  (0, import_async10.scheduleTask)(ctx, () => {
2307
- import_log8.log.warn("Notarization timeout", {
2782
+ import_log9.log.warn("Notarization timeout", {
2308
2783
  timeout,
2309
2784
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2310
2785
  }, {
2311
- F: __dxlog_file8,
2312
- L: 112,
2786
+ F: __dxlog_file11,
2787
+ L: 111,
2313
2788
  S: this,
2314
2789
  C: (f, a) => f(...a)
2315
2790
  });
@@ -2328,11 +2803,11 @@ var NotarizationPlugin = class {
2328
2803
  ...this._extensions
2329
2804
  ].find((peer2) => !peersTried.has(peer2));
2330
2805
  if (!peer) {
2331
- import_log8.log.warn("Exhausted all peers to notarize with", {
2806
+ import_log9.log.warn("Exhausted all peers to notarize with", {
2332
2807
  retryIn: retryTimeout
2333
2808
  }, {
2334
- F: __dxlog_file8,
2335
- L: 137,
2809
+ F: __dxlog_file11,
2810
+ L: 136,
2336
2811
  S: this,
2337
2812
  C: (f, a) => f(...a)
2338
2813
  });
@@ -2341,30 +2816,30 @@ var NotarizationPlugin = class {
2341
2816
  return;
2342
2817
  }
2343
2818
  peersTried.add(peer);
2344
- (0, import_log8.log)("try notarizing", {
2819
+ (0, import_log9.log)("try notarizing", {
2345
2820
  peer: peer.localPeerId,
2346
2821
  credentialId: credentials.map((credential) => credential.id)
2347
2822
  }, {
2348
- F: __dxlog_file8,
2349
- L: 144,
2823
+ F: __dxlog_file11,
2824
+ L: 143,
2350
2825
  S: this,
2351
2826
  C: (f, a) => f(...a)
2352
2827
  });
2353
2828
  await peer.rpc.NotarizationService.notarize({
2354
2829
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2355
2830
  });
2356
- (0, import_log8.log)("success", void 0, {
2357
- F: __dxlog_file8,
2358
- L: 148,
2831
+ (0, import_log9.log)("success", void 0, {
2832
+ F: __dxlog_file11,
2833
+ L: 147,
2359
2834
  S: this,
2360
2835
  C: (f, a) => f(...a)
2361
2836
  });
2362
2837
  await (0, import_async10.sleep)(successDelay);
2363
2838
  } catch (err) {
2364
2839
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2365
- import_log8.log.warn("error notarizing (recoverable)", err, {
2366
- F: __dxlog_file8,
2367
- L: 152,
2840
+ import_log9.log.warn("error notarizing (recoverable)", err, {
2841
+ F: __dxlog_file11,
2842
+ L: 151,
2368
2843
  S: this,
2369
2844
  C: (f, a) => f(...a)
2370
2845
  });
@@ -2376,13 +2851,13 @@ var NotarizationPlugin = class {
2376
2851
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
2377
2852
  try {
2378
2853
  await Promise.race([
2379
- (0, import_context5.rejectOnDispose)(ctx),
2854
+ (0, import_context6.rejectOnDispose)(ctx),
2380
2855
  allNotarized,
2381
2856
  errors.wait()
2382
2857
  ]);
2383
- (0, import_log8.log)("done", void 0, {
2384
- F: __dxlog_file8,
2385
- L: 163,
2858
+ (0, import_log9.log)("done", void 0, {
2859
+ F: __dxlog_file11,
2860
+ L: 162,
2386
2861
  S: this,
2387
2862
  C: (f, a) => f(...a)
2388
2863
  });
@@ -2394,16 +2869,23 @@ var NotarizationPlugin = class {
2394
2869
  * Called with credentials arriving from the control pipeline.
2395
2870
  */
2396
2871
  async processCredential(credential) {
2397
- var _a;
2398
2872
  if (!credential.id) {
2399
2873
  return;
2400
2874
  }
2401
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2875
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2402
2876
  this._processedCredentials.add(credential.id);
2403
2877
  this._processCredentialsTriggers.delete(credential.id);
2404
2878
  }
2405
2879
  setWriter(writer) {
2406
- (0, import_tiny_invariant9.default)(!this._writer, "Writer already set.");
2880
+ (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
2881
+ F: __dxlog_file11,
2882
+ L: 181,
2883
+ S: this,
2884
+ A: [
2885
+ "!this._writer",
2886
+ "'Writer already set.'"
2887
+ ]
2888
+ });
2407
2889
  this._writer = writer;
2408
2890
  }
2409
2891
  async _waitUntilProcessed(id) {
@@ -2416,12 +2898,19 @@ var NotarizationPlugin = class {
2416
2898
  * Requests from other peers to notarize credentials.
2417
2899
  */
2418
2900
  async _onNotarize(request) {
2419
- var _a;
2420
2901
  if (!this._writer) {
2421
2902
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2422
2903
  }
2423
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2424
- (0, import_tiny_invariant9.default)(credential.id, "Credential must have an id");
2904
+ for (const credential of request.credentials ?? []) {
2905
+ (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
2906
+ F: __dxlog_file11,
2907
+ L: 200,
2908
+ S: this,
2909
+ A: [
2910
+ "credential.id",
2911
+ "'Credential must have an id'"
2912
+ ]
2913
+ });
2425
2914
  if (this._processedCredentials.has(credential.id)) {
2426
2915
  continue;
2427
2916
  }
@@ -2431,11 +2920,11 @@ var NotarizationPlugin = class {
2431
2920
  createExtension() {
2432
2921
  const extension = new NotarizationTeleportExtension({
2433
2922
  onOpen: async () => {
2434
- (0, import_log8.log)("extension opened", {
2923
+ (0, import_log9.log)("extension opened", {
2435
2924
  peer: extension.localPeerId
2436
2925
  }, {
2437
- F: __dxlog_file8,
2438
- L: 212,
2926
+ F: __dxlog_file11,
2927
+ L: 211,
2439
2928
  S: this,
2440
2929
  C: (f, a) => f(...a)
2441
2930
  });
@@ -2443,11 +2932,11 @@ var NotarizationPlugin = class {
2443
2932
  this._extensionOpened.emit();
2444
2933
  },
2445
2934
  onClose: async () => {
2446
- (0, import_log8.log)("extension closed", {
2935
+ (0, import_log9.log)("extension closed", {
2447
2936
  peer: extension.localPeerId
2448
2937
  }, {
2449
- F: __dxlog_file8,
2450
- L: 217,
2938
+ F: __dxlog_file11,
2939
+ L: 216,
2451
2940
  S: this,
2452
2941
  C: (f, a) => f(...a)
2453
2942
  });
@@ -2462,10 +2951,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
2462
2951
  constructor(_params) {
2463
2952
  super({
2464
2953
  requested: {
2465
- NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2954
+ NotarizationService: import_protocols6.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2466
2955
  },
2467
2956
  exposed: {
2468
- NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2957
+ NotarizationService: import_protocols6.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2469
2958
  }
2470
2959
  });
2471
2960
  this._params = _params;
@@ -2490,7 +2979,7 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
2490
2979
  };
2491
2980
 
2492
2981
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2493
- function _ts_decorate(decorators, target, key, desc) {
2982
+ function _ts_decorate3(decorators, target, key, desc) {
2494
2983
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2495
2984
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2496
2985
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2500,19 +2989,19 @@ function _ts_decorate(decorators, target, key, desc) {
2500
2989
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2501
2990
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2502
2991
  }
2503
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2992
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2993
+ var ENABLE_FEED_PURGE = false;
2504
2994
  var DataSpace = class DataSpace2 {
2505
2995
  constructor(params) {
2506
- this._ctx = new import_context6.Context();
2996
+ this._ctx = new import_context7.Context();
2507
2997
  this._notarizationPlugin = new NotarizationPlugin();
2508
- this._state = import_services6.SpaceState.CLOSED;
2998
+ this._state = import_services7.SpaceState.CLOSED;
2509
2999
  /**
2510
3000
  * Error for _state === SpaceState.ERROR.
2511
3001
  */
2512
3002
  this.error = void 0;
2513
3003
  this.stateUpdate = new import_async11.Event();
2514
3004
  this.metrics = {};
2515
- var _a;
2516
3005
  this._inner = params.inner;
2517
3006
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2518
3007
  this._gossip = params.gossip;
@@ -2521,7 +3010,7 @@ var DataSpace = class DataSpace2 {
2521
3010
  this._feedStore = params.feedStore;
2522
3011
  this._metadataStore = params.metadataStore;
2523
3012
  this._signingContext = params.signingContext;
2524
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
3013
+ this._callbacks = params.callbacks ?? {};
2525
3014
  this.authVerifier = new TrustedKeySetAuthVerifier({
2526
3015
  trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2527
3016
  update: this._inner.stateUpdate,
@@ -2561,21 +3050,20 @@ var DataSpace = class DataSpace2 {
2561
3050
  async _open() {
2562
3051
  await this._notarizationPlugin.open();
2563
3052
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2564
- await this._inner.open();
2565
- this._state = import_services6.SpaceState.CONTROL_ONLY;
3053
+ await this._inner.open(new import_context7.Context());
3054
+ this._state = import_services7.SpaceState.CONTROL_ONLY;
2566
3055
  this.stateUpdate.emit();
2567
3056
  this.metrics = {};
2568
- this.metrics.open = new Date();
3057
+ this.metrics.open = /* @__PURE__ */ new Date();
2569
3058
  }
2570
3059
  async close() {
2571
3060
  await this._close();
2572
3061
  }
2573
3062
  async _close() {
2574
- var _a, _b;
2575
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2576
- this._state = import_services6.SpaceState.CLOSED;
3063
+ await this._callbacks.beforeClose?.();
3064
+ this._state = import_services7.SpaceState.CLOSED;
2577
3065
  await this._ctx.dispose();
2578
- this._ctx = new import_context6.Context();
3066
+ this._ctx = new import_context7.Context();
2579
3067
  await this.authVerifier.close();
2580
3068
  await this._inner.close();
2581
3069
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
@@ -2594,47 +3082,46 @@ var DataSpace = class DataSpace2 {
2594
3082
  initializeDataPipelineAsync() {
2595
3083
  (0, import_async11.scheduleTask)(this._ctx, async () => {
2596
3084
  try {
2597
- this.metrics.pipelineInitBegin = new Date();
3085
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2598
3086
  await this.initializeDataPipeline();
2599
3087
  } catch (err) {
2600
3088
  if (err instanceof import_errors3.CancelledError) {
2601
- (0, import_log9.log)("data pipeline initialization cancelled", err, {
2602
- F: __dxlog_file9,
2603
- L: 193,
3089
+ (0, import_log10.log)("data pipeline initialization cancelled", err, {
3090
+ F: __dxlog_file12,
3091
+ L: 199,
2604
3092
  S: this,
2605
3093
  C: (f, a) => f(...a)
2606
3094
  });
2607
3095
  return;
2608
3096
  }
2609
- import_log9.log.error("Error initializing data pipeline", err, {
2610
- F: __dxlog_file9,
2611
- L: 197,
3097
+ import_log10.log.error("Error initializing data pipeline", err, {
3098
+ F: __dxlog_file12,
3099
+ L: 203,
2612
3100
  S: this,
2613
3101
  C: (f, a) => f(...a)
2614
3102
  });
2615
- this._state = import_services6.SpaceState.ERROR;
3103
+ this._state = import_services7.SpaceState.ERROR;
2616
3104
  this.error = err;
2617
3105
  this.stateUpdate.emit();
2618
3106
  } finally {
2619
- this.metrics.ready = new Date();
3107
+ this.metrics.ready = /* @__PURE__ */ new Date();
2620
3108
  }
2621
3109
  });
2622
3110
  }
2623
3111
  async initializeDataPipeline() {
2624
- var _a, _b, _c, _d;
2625
- if (this._state !== import_services6.SpaceState.CONTROL_ONLY) {
3112
+ if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
2626
3113
  throw new import_errors3.SystemError("Invalid operation");
2627
3114
  }
2628
- this._state = import_services6.SpaceState.INITIALIZING;
3115
+ this._state = import_services7.SpaceState.INITIALIZING;
2629
3116
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
2630
3117
  ctx: this._ctx,
2631
3118
  breakOnStall: false
2632
3119
  });
2633
- this.metrics.controlPipelineReady = new Date();
3120
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
2634
3121
  await this._createWritableFeeds();
2635
- (0, import_log9.log)("writable feeds created", void 0, {
2636
- F: __dxlog_file9,
2637
- L: 221,
3122
+ (0, import_log10.log)("writable feeds created", void 0, {
3123
+ F: __dxlog_file12,
3124
+ L: 227,
2638
3125
  S: this,
2639
3126
  C: (f, a) => f(...a)
2640
3127
  });
@@ -2647,11 +3134,11 @@ var DataSpace = class DataSpace2 {
2647
3134
  }), this._inner.controlPipeline.writer));
2648
3135
  }
2649
3136
  await this._inner.initializeDataPipeline();
2650
- this.metrics.dataPipelineOpen = new Date();
2651
- await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2652
- (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
2653
- F: __dxlog_file9,
2654
- L: 242,
3137
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3138
+ await (0, import_context7.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3139
+ (0, import_log10.log)("waiting for data pipeline to reach target timeframe", void 0, {
3140
+ F: __dxlog_file12,
3141
+ L: 248,
2655
3142
  S: this,
2656
3143
  C: (f, a) => f(...a)
2657
3144
  });
@@ -2659,17 +3146,17 @@ var DataSpace = class DataSpace2 {
2659
3146
  ctx: this._ctx,
2660
3147
  breakOnStall: false
2661
3148
  });
2662
- this.metrics.dataPipelineReady = new Date();
2663
- (0, import_log9.log)("data pipeline ready", void 0, {
2664
- F: __dxlog_file9,
2665
- L: 251,
3149
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3150
+ (0, import_log10.log)("data pipeline ready", void 0, {
3151
+ F: __dxlog_file12,
3152
+ L: 257,
2666
3153
  S: this,
2667
3154
  C: (f, a) => f(...a)
2668
3155
  });
2669
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
2670
- this._state = import_services6.SpaceState.READY;
3156
+ await this._callbacks.beforeReady?.();
3157
+ this._state = import_services7.SpaceState.READY;
2671
3158
  this.stateUpdate.emit();
2672
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3159
+ await this._callbacks.afterReady?.();
2673
3160
  }
2674
3161
  async _createWritableFeeds() {
2675
3162
  const credentials = [];
@@ -2685,7 +3172,7 @@ var DataSpace = class DataSpace2 {
2685
3172
  spaceKey: this.key,
2686
3173
  deviceKey: this._signingContext.deviceKey,
2687
3174
  identityKey: this._signingContext.identityKey,
2688
- designation: import_credentials9.AdmittedFeed.Designation.CONTROL
3175
+ designation: import_credentials10.AdmittedFeed.Designation.CONTROL
2689
3176
  }
2690
3177
  }));
2691
3178
  }
@@ -2702,7 +3189,7 @@ var DataSpace = class DataSpace2 {
2702
3189
  spaceKey: this.key,
2703
3190
  deviceKey: this._signingContext.deviceKey,
2704
3191
  identityKey: this._signingContext.identityKey,
2705
- designation: import_credentials9.AdmittedFeed.Designation.DATA
3192
+ designation: import_credentials10.AdmittedFeed.Designation.DATA
2706
3193
  }
2707
3194
  }));
2708
3195
  }
@@ -2716,7 +3203,6 @@ var DataSpace = class DataSpace2 {
2716
3203
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2717
3204
  }
2718
3205
  async createEpoch() {
2719
- var _a, _b;
2720
3206
  const epoch = await this.dataPipeline.createEpoch();
2721
3207
  const receipt = await this.inner.controlPipeline.writer.write({
2722
3208
  credential: {
@@ -2729,65 +3215,67 @@ var DataSpace = class DataSpace2 {
2729
3215
  })
2730
3216
  }
2731
3217
  });
2732
- await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
3218
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe2.Timeframe([
2733
3219
  [
2734
3220
  receipt.feedKey,
2735
3221
  receipt.seq
2736
3222
  ]
2737
3223
  ]));
2738
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2739
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2740
- if (indexBeforeEpoch) {
2741
- await feed.clear(0, indexBeforeEpoch + 1);
3224
+ if (ENABLE_FEED_PURGE) {
3225
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
3226
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3227
+ if (indexBeforeEpoch === void 0) {
3228
+ continue;
3229
+ }
3230
+ await feed.safeClear(0, indexBeforeEpoch + 1);
2742
3231
  }
2743
3232
  }
2744
3233
  }
2745
3234
  async activate() {
2746
- if (this._state !== import_services6.SpaceState.INACTIVE) {
3235
+ if (this._state !== import_services7.SpaceState.INACTIVE) {
2747
3236
  return;
2748
3237
  }
2749
- await this._metadataStore.setSpaceState(this.key, import_services6.SpaceState.ACTIVE);
3238
+ await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
2750
3239
  await this._open();
2751
3240
  this.initializeDataPipelineAsync();
2752
3241
  }
2753
3242
  async deactivate() {
2754
- if (this._state === import_services6.SpaceState.INACTIVE) {
3243
+ if (this._state === import_services7.SpaceState.INACTIVE) {
2755
3244
  return;
2756
3245
  }
2757
- await this._metadataStore.setSpaceState(this.key, import_services6.SpaceState.INACTIVE);
3246
+ await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
2758
3247
  await this._close();
2759
- this._state = import_services6.SpaceState.INACTIVE;
3248
+ this._state = import_services7.SpaceState.INACTIVE;
2760
3249
  this.stateUpdate.emit();
2761
3250
  }
2762
3251
  };
2763
- _ts_decorate([
3252
+ _ts_decorate3([
2764
3253
  import_async11.synchronized
2765
3254
  ], DataSpace.prototype, "open", null);
2766
- _ts_decorate([
3255
+ _ts_decorate3([
2767
3256
  import_async11.synchronized
2768
3257
  ], DataSpace.prototype, "close", null);
2769
- _ts_decorate([
3258
+ _ts_decorate3([
2770
3259
  (0, import_debug4.timed)(1e4)
2771
3260
  ], DataSpace.prototype, "_createWritableFeeds", null);
2772
- _ts_decorate([
3261
+ _ts_decorate3([
2773
3262
  import_async11.synchronized
2774
3263
  ], DataSpace.prototype, "activate", null);
2775
- _ts_decorate([
3264
+ _ts_decorate3([
2776
3265
  import_async11.synchronized
2777
3266
  ], DataSpace.prototype, "deactivate", null);
2778
- DataSpace = _ts_decorate([
3267
+ DataSpace = _ts_decorate3([
2779
3268
  (0, import_async11.trackLeaks)("open", "close")
2780
3269
  ], DataSpace);
2781
3270
 
2782
3271
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
2783
- var import_credentials10 = require("@dxos/credentials");
3272
+ var import_credentials11 = require("@dxos/credentials");
2784
3273
  var import_debug5 = require("@dxos/debug");
2785
- var import_credentials11 = require("@dxos/protocols/proto/dxos/halo/credentials");
2786
- var import_timeframe2 = require("@dxos/timeframe");
3274
+ var import_credentials12 = require("@dxos/protocols/proto/dxos/halo/credentials");
3275
+ var import_timeframe3 = require("@dxos/timeframe");
2787
3276
  var spaceGenesis = async (keyring, signingContext, space) => {
2788
- var _a, _b, _c, _d;
2789
3277
  const credentials = [
2790
- await (0, import_credentials10.createCredential)({
3278
+ await (0, import_credentials11.createCredential)({
2791
3279
  signer: keyring,
2792
3280
  issuer: space.key,
2793
3281
  subject: space.key,
@@ -2796,45 +3284,45 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2796
3284
  spaceKey: space.key
2797
3285
  }
2798
3286
  }),
2799
- await (0, import_credentials10.createCredential)({
3287
+ await (0, import_credentials11.createCredential)({
2800
3288
  signer: keyring,
2801
3289
  issuer: space.key,
2802
3290
  subject: signingContext.identityKey,
2803
3291
  assertion: {
2804
3292
  "@type": "dxos.halo.credentials.SpaceMember",
2805
3293
  spaceKey: space.key,
2806
- role: import_credentials11.SpaceMember.Role.ADMIN,
3294
+ role: import_credentials12.SpaceMember.Role.ADMIN,
2807
3295
  profile: signingContext.profile,
2808
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : (0, import_debug5.failUndefined)()
3296
+ genesisFeedKey: space.controlFeedKey ?? (0, import_debug5.failUndefined)()
2809
3297
  }
2810
3298
  }),
2811
3299
  await signingContext.credentialSigner.createCredential({
2812
- subject: (_b = space.controlFeedKey) != null ? _b : (0, import_debug5.failUndefined)(),
3300
+ subject: space.controlFeedKey ?? (0, import_debug5.failUndefined)(),
2813
3301
  assertion: {
2814
3302
  "@type": "dxos.halo.credentials.AdmittedFeed",
2815
3303
  spaceKey: space.key,
2816
3304
  identityKey: signingContext.identityKey,
2817
3305
  deviceKey: signingContext.deviceKey,
2818
- designation: import_credentials11.AdmittedFeed.Designation.CONTROL
3306
+ designation: import_credentials12.AdmittedFeed.Designation.CONTROL
2819
3307
  }
2820
3308
  }),
2821
3309
  await signingContext.credentialSigner.createCredential({
2822
- subject: (_c = space.dataFeedKey) != null ? _c : (0, import_debug5.failUndefined)(),
3310
+ subject: space.dataFeedKey ?? (0, import_debug5.failUndefined)(),
2823
3311
  assertion: {
2824
3312
  "@type": "dxos.halo.credentials.AdmittedFeed",
2825
3313
  spaceKey: space.key,
2826
3314
  identityKey: signingContext.identityKey,
2827
3315
  deviceKey: signingContext.deviceKey,
2828
- designation: import_credentials11.AdmittedFeed.Designation.DATA
3316
+ designation: import_credentials12.AdmittedFeed.Designation.DATA
2829
3317
  }
2830
3318
  }),
2831
3319
  await signingContext.credentialSigner.createCredential({
2832
- subject: (_d = space.key) != null ? _d : (0, import_debug5.failUndefined)(),
3320
+ subject: space.key ?? (0, import_debug5.failUndefined)(),
2833
3321
  assertion: {
2834
3322
  "@type": "dxos.halo.credentials.Epoch",
2835
3323
  number: 0,
2836
3324
  previousId: void 0,
2837
- timeframe: new import_timeframe2.Timeframe(),
3325
+ timeframe: new import_timeframe3.Timeframe(),
2838
3326
  snapshotCid: void 0
2839
3327
  }
2840
3328
  })
@@ -2850,7 +3338,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2850
3338
  };
2851
3339
 
2852
3340
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2853
- function _ts_decorate2(decorators, target, key, desc) {
3341
+ function _ts_decorate4(decorators, target, key, desc) {
2854
3342
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2855
3343
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2856
3344
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2860,7 +3348,7 @@ function _ts_decorate2(decorators, target, key, desc) {
2860
3348
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2861
3349
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2862
3350
  }
2863
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3351
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
2864
3352
  var DataSpaceManager = class DataSpaceManager2 {
2865
3353
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore) {
2866
3354
  this._spaceManager = _spaceManager;
@@ -2869,7 +3357,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2869
3357
  this._keyring = _keyring;
2870
3358
  this._signingContext = _signingContext;
2871
3359
  this._feedStore = _feedStore;
2872
- this._ctx = new import_context7.Context();
3360
+ this._ctx = new import_context8.Context();
2873
3361
  this.updated = new import_async12.Event();
2874
3362
  this._spaces = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
2875
3363
  this._isOpen = false;
@@ -2880,50 +3368,50 @@ var DataSpaceManager = class DataSpaceManager2 {
2880
3368
  return this._spaces;
2881
3369
  }
2882
3370
  async open() {
2883
- (0, import_log10.log)("open", void 0, {
2884
- F: __dxlog_file10,
2885
- L: 80,
3371
+ (0, import_log11.log)("open", void 0, {
3372
+ F: __dxlog_file13,
3373
+ L: 79,
2886
3374
  S: this,
2887
3375
  C: (f, a) => f(...a)
2888
3376
  });
2889
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.begin({
3377
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols7.trace.begin({
2890
3378
  id: this._instanceId
2891
3379
  }), {
2892
- F: __dxlog_file10,
2893
- L: 81,
3380
+ F: __dxlog_file13,
3381
+ L: 80,
2894
3382
  S: this,
2895
3383
  C: (f, a) => f(...a)
2896
3384
  });
2897
3385
  await this._metadataStore.load();
2898
- (0, import_log10.log)("metadata loaded", {
3386
+ (0, import_log11.log)("metadata loaded", {
2899
3387
  spaces: this._metadataStore.spaces.length
2900
3388
  }, {
2901
- F: __dxlog_file10,
2902
- L: 83,
3389
+ F: __dxlog_file13,
3390
+ L: 82,
2903
3391
  S: this,
2904
3392
  C: (f, a) => f(...a)
2905
3393
  });
2906
3394
  for (const spaceMetadata of this._metadataStore.spaces) {
2907
3395
  try {
2908
- (0, import_log10.log)("load space", {
3396
+ (0, import_log11.log)("load space", {
2909
3397
  spaceMetadata
2910
3398
  }, {
2911
- F: __dxlog_file10,
2912
- L: 87,
3399
+ F: __dxlog_file13,
3400
+ L: 86,
2913
3401
  S: this,
2914
3402
  C: (f, a) => f(...a)
2915
3403
  });
2916
3404
  const space = await this._constructSpace(spaceMetadata);
2917
- if (spaceMetadata.state !== import_services7.SpaceState.INACTIVE) {
3405
+ if (spaceMetadata.state !== import_services8.SpaceState.INACTIVE) {
2918
3406
  space.initializeDataPipelineAsync();
2919
3407
  }
2920
3408
  } catch (err) {
2921
- import_log10.log.error("Error loading space", {
3409
+ import_log11.log.error("Error loading space", {
2922
3410
  spaceMetadata,
2923
3411
  err
2924
3412
  }, {
2925
- F: __dxlog_file10,
2926
- L: 93,
3413
+ F: __dxlog_file13,
3414
+ L: 92,
2927
3415
  S: this,
2928
3416
  C: (f, a) => f(...a)
2929
3417
  });
@@ -2931,19 +3419,19 @@ var DataSpaceManager = class DataSpaceManager2 {
2931
3419
  }
2932
3420
  this._isOpen = true;
2933
3421
  this.updated.emit();
2934
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.end({
3422
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols7.trace.end({
2935
3423
  id: this._instanceId
2936
3424
  }), {
2937
- F: __dxlog_file10,
2938
- L: 99,
3425
+ F: __dxlog_file13,
3426
+ L: 98,
2939
3427
  S: this,
2940
3428
  C: (f, a) => f(...a)
2941
3429
  });
2942
3430
  }
2943
3431
  async close() {
2944
- (0, import_log10.log)("close", void 0, {
2945
- F: __dxlog_file10,
2946
- L: 104,
3432
+ (0, import_log11.log)("close", void 0, {
3433
+ F: __dxlog_file13,
3434
+ L: 103,
2947
3435
  S: this,
2948
3436
  C: (f, a) => f(...a)
2949
3437
  });
@@ -2957,7 +3445,15 @@ var DataSpaceManager = class DataSpaceManager2 {
2957
3445
  * Creates a new space writing the genesis credentials to the control feed.
2958
3446
  */
2959
3447
  async createSpace() {
2960
- (0, import_tiny_invariant10.default)(this._isOpen, "Not open.");
3448
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3449
+ F: __dxlog_file13,
3450
+ L: 116,
3451
+ S: this,
3452
+ A: [
3453
+ "this._isOpen",
3454
+ "'Not open.'"
3455
+ ]
3456
+ });
2961
3457
  const spaceKey = await this._keyring.createKey();
2962
3458
  const controlFeedKey = await this._keyring.createKey();
2963
3459
  const dataFeedKey = await this._keyring.createKey();
@@ -2966,13 +3462,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2966
3462
  genesisFeedKey: controlFeedKey,
2967
3463
  controlFeedKey,
2968
3464
  dataFeedKey,
2969
- state: import_services7.SpaceState.ACTIVE
3465
+ state: import_services8.SpaceState.ACTIVE
2970
3466
  };
2971
- (0, import_log10.log)("creating space...", {
3467
+ (0, import_log11.log)("creating space...", {
2972
3468
  spaceKey
2973
3469
  }, {
2974
- F: __dxlog_file10,
2975
- L: 129,
3470
+ F: __dxlog_file13,
3471
+ L: 128,
2976
3472
  S: this,
2977
3473
  C: (f, a) => f(...a)
2978
3474
  });
@@ -2980,7 +3476,15 @@ var DataSpaceManager = class DataSpaceManager2 {
2980
3476
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
2981
3477
  await this._metadataStore.addSpace(metadata);
2982
3478
  const memberCredential = credentials[1];
2983
- (0, import_tiny_invariant10.default)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
3479
+ (0, import_invariant11.invariant)((0, import_credentials13.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3480
+ F: __dxlog_file13,
3481
+ L: 135,
3482
+ S: this,
3483
+ A: [
3484
+ "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
3485
+ ""
3486
+ ]
3487
+ });
2984
3488
  await this._signingContext.recordCredential(memberCredential);
2985
3489
  await space.initializeDataPipeline();
2986
3490
  this.updated.emit();
@@ -2988,16 +3492,32 @@ var DataSpaceManager = class DataSpaceManager2 {
2988
3492
  }
2989
3493
  // TODO(burdon): Rename join space.
2990
3494
  async acceptSpace(opts) {
2991
- (0, import_log10.log)("accept space", {
3495
+ (0, import_log11.log)("accept space", {
2992
3496
  opts
2993
3497
  }, {
2994
- F: __dxlog_file10,
2995
- L: 148,
3498
+ F: __dxlog_file13,
3499
+ L: 147,
2996
3500
  S: this,
2997
3501
  C: (f, a) => f(...a)
2998
3502
  });
2999
- (0, import_tiny_invariant10.default)(this._isOpen, "Not open.");
3000
- (0, import_tiny_invariant10.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
3503
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3504
+ F: __dxlog_file13,
3505
+ L: 148,
3506
+ S: this,
3507
+ A: [
3508
+ "this._isOpen",
3509
+ "'Not open.'"
3510
+ ]
3511
+ });
3512
+ (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3513
+ F: __dxlog_file13,
3514
+ L: 149,
3515
+ S: this,
3516
+ A: [
3517
+ "!this._spaces.has(opts.spaceKey)",
3518
+ "'Space already exists.'"
3519
+ ]
3520
+ });
3001
3521
  const metadata = {
3002
3522
  key: opts.spaceKey,
3003
3523
  genesisFeedKey: opts.genesisFeedKey,
@@ -3016,17 +3536,17 @@ var DataSpaceManager = class DataSpaceManager2 {
3016
3536
  * TODO(dmaretskyi): Consider removing.
3017
3537
  */
3018
3538
  async waitUntilSpaceReady(spaceKey) {
3019
- await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3539
+ await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3020
3540
  const space = this._spaces.get(spaceKey);
3021
- return !!space && space.state === import_services7.SpaceState.READY;
3541
+ return !!space && space.state === import_services8.SpaceState.READY;
3022
3542
  }));
3023
3543
  }
3024
3544
  async _constructSpace(metadata) {
3025
- (0, import_log10.log)("construct space", {
3545
+ (0, import_log11.log)("construct space", {
3026
3546
  metadata
3027
3547
  }, {
3028
- F: __dxlog_file10,
3029
- L: 183,
3548
+ F: __dxlog_file13,
3549
+ L: 182,
3030
3550
  S: this,
3031
3551
  C: (f, a) => f(...a)
3032
3552
  });
@@ -3034,7 +3554,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3034
3554
  localPeerId: this._signingContext.deviceKey
3035
3555
  });
3036
3556
  const presence = new import_teleport_extension_gossip.Presence({
3037
- announceInterval: 500,
3557
+ announceInterval: 1e3,
3038
3558
  offlineTimeout: 5e3,
3039
3559
  identityKey: this._signingContext.identityKey,
3040
3560
  gossip
@@ -3060,9 +3580,9 @@ var DataSpaceManager = class DataSpaceManager2 {
3060
3580
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3061
3581
  },
3062
3582
  onAuthFailure: () => {
3063
- import_log10.log.warn("auth failure", void 0, {
3064
- F: __dxlog_file10,
3065
- L: 214,
3583
+ import_log11.log.warn("auth failure", void 0, {
3584
+ F: __dxlog_file13,
3585
+ L: 213,
3066
3586
  S: this,
3067
3587
  C: (f, a) => f(...a)
3068
3588
  });
@@ -3073,7 +3593,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3073
3593
  dataFeed && space.setDataFeed(dataFeed);
3074
3594
  const dataSpace = new DataSpace({
3075
3595
  inner: space,
3076
- initialState: metadata.state === import_services7.SpaceState.INACTIVE ? import_services7.SpaceState.INACTIVE : import_services7.SpaceState.CLOSED,
3596
+ initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
3077
3597
  metadataStore: this._metadataStore,
3078
3598
  gossip,
3079
3599
  presence,
@@ -3082,23 +3602,23 @@ var DataSpaceManager = class DataSpaceManager2 {
3082
3602
  signingContext: this._signingContext,
3083
3603
  callbacks: {
3084
3604
  beforeReady: async () => {
3085
- (0, import_log10.log)("before space ready", {
3605
+ (0, import_log11.log)("before space ready", {
3086
3606
  space: space.key
3087
3607
  }, {
3088
- F: __dxlog_file10,
3089
- L: 232,
3608
+ F: __dxlog_file13,
3609
+ L: 231,
3090
3610
  S: this,
3091
3611
  C: (f, a) => f(...a)
3092
3612
  });
3093
3613
  await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3094
3614
  },
3095
3615
  afterReady: async () => {
3096
- (0, import_log10.log)("after space ready", {
3616
+ (0, import_log11.log)("after space ready", {
3097
3617
  space: space.key,
3098
3618
  open: this._isOpen
3099
3619
  }, {
3100
- F: __dxlog_file10,
3101
- L: 239,
3620
+ F: __dxlog_file13,
3621
+ L: 238,
3102
3622
  S: this,
3103
3623
  C: (f, a) => f(...a)
3104
3624
  });
@@ -3107,11 +3627,11 @@ var DataSpaceManager = class DataSpaceManager2 {
3107
3627
  }
3108
3628
  },
3109
3629
  beforeClose: async () => {
3110
- (0, import_log10.log)("before space close", {
3630
+ (0, import_log11.log)("before space close", {
3111
3631
  space: space.key
3112
3632
  }, {
3113
- F: __dxlog_file10,
3114
- L: 245,
3633
+ F: __dxlog_file13,
3634
+ L: 244,
3115
3635
  S: this,
3116
3636
  C: (f, a) => f(...a)
3117
3637
  });
@@ -3120,7 +3640,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3120
3640
  },
3121
3641
  cache: metadata.cache
3122
3642
  });
3123
- if (metadata.state !== import_services7.SpaceState.INACTIVE) {
3643
+ if (metadata.state !== import_services8.SpaceState.INACTIVE) {
3124
3644
  await dataSpace.open();
3125
3645
  }
3126
3646
  if (metadata.controlTimeframe) {
@@ -3133,33 +3653,33 @@ var DataSpaceManager = class DataSpaceManager2 {
3133
3653
  return dataSpace;
3134
3654
  }
3135
3655
  };
3136
- _ts_decorate2([
3656
+ _ts_decorate4([
3137
3657
  import_async12.synchronized
3138
3658
  ], DataSpaceManager.prototype, "open", null);
3139
- _ts_decorate2([
3659
+ _ts_decorate4([
3140
3660
  import_async12.synchronized
3141
3661
  ], DataSpaceManager.prototype, "close", null);
3142
- _ts_decorate2([
3662
+ _ts_decorate4([
3143
3663
  import_async12.synchronized
3144
3664
  ], DataSpaceManager.prototype, "createSpace", null);
3145
- _ts_decorate2([
3665
+ _ts_decorate4([
3146
3666
  import_async12.synchronized
3147
3667
  ], DataSpaceManager.prototype, "acceptSpace", null);
3148
- DataSpaceManager = _ts_decorate2([
3668
+ DataSpaceManager = _ts_decorate4([
3149
3669
  (0, import_async12.trackLeaks)("open", "close")
3150
3670
  ], DataSpaceManager);
3151
3671
 
3152
3672
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
3153
3673
  var import_async13 = require("@dxos/async");
3154
- var import_codec_protobuf10 = require("@dxos/codec-protobuf");
3674
+ var import_codec_protobuf11 = require("@dxos/codec-protobuf");
3155
3675
  var import_debug6 = require("@dxos/debug");
3156
3676
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
3157
3677
  var import_errors4 = require("@dxos/errors");
3158
- var import_log11 = require("@dxos/log");
3159
- var import_protocols7 = require("@dxos/protocols");
3160
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
3678
+ var import_log12 = require("@dxos/log");
3679
+ var import_protocols8 = require("@dxos/protocols");
3680
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
3161
3681
  var import_util6 = require("@dxos/util");
3162
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3682
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
3163
3683
  var SpacesServiceImpl = class {
3164
3684
  constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
3165
3685
  this._identityManager = _identityManager;
@@ -3176,15 +3696,14 @@ var SpacesServiceImpl = class {
3176
3696
  return this._serializeSpace(space);
3177
3697
  }
3178
3698
  async updateSpace({ spaceKey, state }) {
3179
- var _a;
3180
3699
  const dataSpaceManager = await this._getDataSpaceManager();
3181
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3700
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3182
3701
  if (state) {
3183
3702
  switch (state) {
3184
- case import_services8.SpaceState.ACTIVE:
3703
+ case import_services9.SpaceState.ACTIVE:
3185
3704
  await space.activate();
3186
3705
  break;
3187
- case import_services8.SpaceState.INACTIVE:
3706
+ case import_services9.SpaceState.INACTIVE:
3188
3707
  await space.deactivate();
3189
3708
  break;
3190
3709
  default:
@@ -3193,14 +3712,14 @@ var SpacesServiceImpl = class {
3193
3712
  }
3194
3713
  }
3195
3714
  querySpaces() {
3196
- return new import_codec_protobuf10.Stream(({ next, ctx }) => {
3715
+ return new import_codec_protobuf11.Stream(({ next, ctx }) => {
3197
3716
  const scheduler = new import_async13.UpdateScheduler(ctx, async () => {
3198
3717
  const dataSpaceManager = await this._getDataSpaceManager();
3199
3718
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
3200
- (0, import_log11.log)("update", {
3719
+ (0, import_log12.log)("update", {
3201
3720
  spaces
3202
3721
  }, {
3203
- F: __dxlog_file11,
3722
+ F: __dxlog_file14,
3204
3723
  L: 78,
3205
3724
  S: this,
3206
3725
  C: (f, a) => f(...a)
@@ -3242,17 +3761,15 @@ var SpacesServiceImpl = class {
3242
3761
  });
3243
3762
  }
3244
3763
  async postMessage({ spaceKey, channel, message }) {
3245
- var _a;
3246
3764
  const dataSpaceManager = await this._getDataSpaceManager();
3247
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3765
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3248
3766
  await space.postMessage(getChannelId(channel), message);
3249
3767
  }
3250
3768
  subscribeMessages({ spaceKey, channel }) {
3251
- return new import_codec_protobuf10.Stream(({ ctx, next }) => {
3769
+ return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3252
3770
  (0, import_async13.scheduleTask)(ctx, async () => {
3253
- var _a;
3254
3771
  const dataSpaceManager = await this._getDataSpaceManager();
3255
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3772
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3256
3773
  const handle = space.listen(getChannelId(channel), (message) => {
3257
3774
  next(message);
3258
3775
  });
@@ -3261,9 +3778,8 @@ var SpacesServiceImpl = class {
3261
3778
  });
3262
3779
  }
3263
3780
  queryCredentials({ spaceKey }) {
3264
- return new import_codec_protobuf10.Stream(({ ctx, next }) => {
3265
- var _a;
3266
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3781
+ return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3782
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3267
3783
  const processor = {
3268
3784
  processCredential: async (credential) => {
3269
3785
  next(credential);
@@ -3274,9 +3790,8 @@ var SpacesServiceImpl = class {
3274
3790
  });
3275
3791
  }
3276
3792
  async writeCredentials({ spaceKey, credentials }) {
3277
- var _a;
3278
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3279
- for (const credential of credentials != null ? credentials : []) {
3793
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3794
+ for (const credential of credentials ?? []) {
3280
3795
  await space.controlPipeline.writer.write({
3281
3796
  credential: {
3282
3797
  credential
@@ -3285,17 +3800,15 @@ var SpacesServiceImpl = class {
3285
3800
  }
3286
3801
  }
3287
3802
  async createEpoch({ spaceKey }) {
3288
- var _a;
3289
3803
  const dataSpaceManager = await this._getDataSpaceManager();
3290
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3804
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3291
3805
  await space.createEpoch();
3292
3806
  }
3293
3807
  _serializeSpace(space) {
3294
- var _a, _b, _c, _d, _e, _f, _g;
3295
3808
  return {
3296
3809
  spaceKey: space.key,
3297
3810
  state: space.state,
3298
- error: space.error ? (0, import_protocols7.encodeError)(space.error) : void 0,
3811
+ error: space.error ? (0, import_protocols8.encodeError)(space.error) : void 0,
3299
3812
  pipeline: {
3300
3813
  currentEpoch: space.dataPipeline.currentEpoch,
3301
3814
  appliedEpoch: space.dataPipeline.appliedEpoch,
@@ -3303,25 +3816,30 @@ var SpacesServiceImpl = class {
3303
3816
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3304
3817
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3305
3818
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3306
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3307
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3308
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3309
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3310
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3819
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
3820
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
3821
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
3822
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
3823
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
3311
3824
  },
3312
3825
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3313
- var _a2, _b2, _c2;
3826
+ const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3827
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3828
+ if (isMe) {
3829
+ peers.push(space.presence.getLocalState());
3830
+ }
3314
3831
  return {
3315
3832
  identity: {
3316
3833
  identityKey: member.key,
3317
3834
  profile: {
3318
- displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : (0, import_util6.humanize)(member.key)
3835
+ displayName: member.assertion.profile?.displayName ?? (0, import_util6.humanize)(member.key)
3319
3836
  }
3320
3837
  },
3321
- presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services8.SpaceMember.PresenceState.ONLINE : import_services8.SpaceMember.PresenceState.OFFLINE
3838
+ presence: isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
3839
+ peerStates: peers
3322
3840
  };
3323
3841
  }),
3324
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3842
+ creator: space.inner.spaceState.creator?.key,
3325
3843
  cache: space.cache,
3326
3844
  metrics: space.metrics
3327
3845
  };
@@ -3330,8 +3848,18 @@ var SpacesServiceImpl = class {
3330
3848
  var getChannelId = (channel) => `user-channel/${channel}`;
3331
3849
 
3332
3850
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3333
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3334
- var ServiceContext = class {
3851
+ function _ts_decorate5(decorators, target, key, desc) {
3852
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3853
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3854
+ r = Reflect.decorate(decorators, target, key, desc);
3855
+ else
3856
+ for (var i = decorators.length - 1; i >= 0; i--)
3857
+ if (d = decorators[i])
3858
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3859
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3860
+ }
3861
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
3862
+ var ServiceContext = class ServiceContext2 {
3335
3863
  // prettier-ignore
3336
3864
  constructor(storage, networkManager, signalManager, modelFactory) {
3337
3865
  this.storage = storage;
@@ -3365,105 +3893,108 @@ var ServiceContext = class {
3365
3893
  });
3366
3894
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3367
3895
  this.invitations = new InvitationsHandler(this.networkManager);
3368
- this._handlerFactories.set(import_services9.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3369
- var _a;
3370
- return (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3371
- }, this._acceptIdentity.bind(this)));
3896
+ this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
3372
3897
  }
3373
- async open() {
3374
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.begin({
3375
- id: this._instanceId
3376
- }), {
3377
- F: __dxlog_file12,
3378
- L: 126,
3898
+ async open(ctx) {
3899
+ await this._checkStorageVersion();
3900
+ (0, import_log13.log)("opening...", void 0, {
3901
+ F: __dxlog_file15,
3902
+ L: 134,
3379
3903
  S: this,
3380
3904
  C: (f, a) => f(...a)
3381
3905
  });
3382
- await this._checkStorageVersion();
3383
- (0, import_log12.log)("opening...", void 0, {
3384
- F: __dxlog_file12,
3385
- L: 130,
3906
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols9.trace.begin({
3907
+ id: this._instanceId
3908
+ }), {
3909
+ F: __dxlog_file15,
3910
+ L: 135,
3386
3911
  S: this,
3387
3912
  C: (f, a) => f(...a)
3388
3913
  });
3389
3914
  await this.signalManager.open();
3390
3915
  await this.networkManager.open();
3391
3916
  await this.spaceManager.open();
3392
- await this.identityManager.open();
3917
+ await this.identityManager.open(ctx);
3393
3918
  if (this.identityManager.identity) {
3394
- await this._initialize();
3919
+ await this._initialize(ctx);
3395
3920
  }
3396
- (0, import_log12.log)("opened", void 0, {
3397
- F: __dxlog_file12,
3398
- L: 138,
3921
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols9.trace.end({
3922
+ id: this._instanceId
3923
+ }), {
3924
+ F: __dxlog_file15,
3925
+ L: 143,
3399
3926
  S: this,
3400
3927
  C: (f, a) => f(...a)
3401
3928
  });
3402
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.end({
3403
- id: this._instanceId
3404
- }), {
3405
- F: __dxlog_file12,
3406
- L: 139,
3929
+ (0, import_log13.log)("opened", void 0, {
3930
+ F: __dxlog_file15,
3931
+ L: 144,
3407
3932
  S: this,
3408
3933
  C: (f, a) => f(...a)
3409
3934
  });
3410
3935
  }
3411
3936
  async close() {
3412
- var _a;
3413
- (0, import_log12.log)("closing...", void 0, {
3414
- F: __dxlog_file12,
3415
- L: 143,
3937
+ (0, import_log13.log)("closing...", void 0, {
3938
+ F: __dxlog_file15,
3939
+ L: 148,
3416
3940
  S: this,
3417
3941
  C: (f, a) => f(...a)
3418
3942
  });
3419
3943
  if (this._deviceSpaceSync && this.identityManager.identity) {
3420
3944
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3421
3945
  }
3422
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3946
+ await this.dataSpaceManager?.close();
3423
3947
  await this.identityManager.close();
3424
3948
  await this.spaceManager.close();
3425
3949
  await this.feedStore.close();
3426
3950
  await this.networkManager.close();
3427
3951
  await this.signalManager.close();
3428
3952
  this.dataServiceSubscriptions.clear();
3429
- (0, import_log12.log)("closed", void 0, {
3430
- F: __dxlog_file12,
3431
- L: 154,
3953
+ (0, import_log13.log)("closed", void 0, {
3954
+ F: __dxlog_file15,
3955
+ L: 159,
3432
3956
  S: this,
3433
3957
  C: (f, a) => f(...a)
3434
3958
  });
3435
3959
  }
3436
3960
  async createIdentity(params = {}) {
3437
3961
  const identity = await this.identityManager.createIdentity(params);
3438
- await this._initialize();
3962
+ await this._initialize(new import_context9.Context());
3439
3963
  return identity;
3440
3964
  }
3441
3965
  getInvitationHandler(invitation) {
3442
3966
  const factory = this._handlerFactories.get(invitation.kind);
3443
- (0, import_tiny_invariant11.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
3967
+ (0, import_invariant12.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
3968
+ F: __dxlog_file15,
3969
+ L: 171,
3970
+ S: this,
3971
+ A: [
3972
+ "factory",
3973
+ "`Unknown invitation kind: ${invitation.kind}`"
3974
+ ]
3975
+ });
3444
3976
  return factory(invitation);
3445
3977
  }
3446
3978
  async _acceptIdentity(params) {
3447
3979
  const identity = await this.identityManager.acceptIdentity(params);
3448
- await this._initialize();
3980
+ await this._initialize(new import_context9.Context());
3449
3981
  return identity;
3450
3982
  }
3451
3983
  async _checkStorageVersion() {
3452
3984
  await this.metadataStore.load();
3453
- if (this.metadataStore.version !== import_protocols8.STORAGE_VERSION) {
3454
- throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${import_protocols8.STORAGE_VERSION}`);
3985
+ if (this.metadataStore.version !== import_protocols9.STORAGE_VERSION) {
3986
+ throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${import_protocols9.STORAGE_VERSION}`);
3455
3987
  }
3456
3988
  }
3457
3989
  // Called when identity is created.
3458
- async _initialize() {
3459
- var _a;
3460
- (0, import_log12.log)("initializing spaces...", void 0, {
3461
- F: __dxlog_file12,
3462
- L: 187,
3990
+ async _initialize(ctx) {
3991
+ (0, import_log13.log)("initializing spaces...", void 0, {
3992
+ F: __dxlog_file15,
3993
+ L: 193,
3463
3994
  S: this,
3464
3995
  C: (f, a) => f(...a)
3465
3996
  });
3466
- const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3997
+ const identity = this.identityManager.identity ?? (0, import_debug7.failUndefined)();
3467
3998
  const signingContext = {
3468
3999
  credentialSigner: identity.getIdentityCredentialSigner(),
3469
4000
  identityKey: identity.identityKey,
@@ -3479,14 +4010,22 @@ var ServiceContext = class {
3479
4010
  };
3480
4011
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
3481
4012
  await this.dataSpaceManager.open();
3482
- this._handlerFactories.set(import_services9.Invitation.Kind.SPACE, (invitation) => {
3483
- (0, import_tiny_invariant11.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
4013
+ this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4014
+ (0, import_invariant12.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4015
+ F: __dxlog_file15,
4016
+ L: 216,
4017
+ S: this,
4018
+ A: [
4019
+ "this.dataSpaceManager",
4020
+ "'dataSpaceManager not initialized yet'"
4021
+ ]
4022
+ });
3484
4023
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3485
4024
  });
3486
4025
  this.initialized.wake();
3487
4026
  this._deviceSpaceSync = {
3488
4027
  processCredential: async (credential) => {
3489
- const assertion = (0, import_credentials13.getCredentialAssertion)(credential);
4028
+ const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
3490
4029
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
3491
4030
  return;
3492
4031
  }
@@ -3494,33 +4033,33 @@ var ServiceContext = class {
3494
4033
  return;
3495
4034
  }
3496
4035
  if (!this.dataSpaceManager) {
3497
- (0, import_log12.log)("dataSpaceManager not initialized yet, ignoring space admission", {
4036
+ (0, import_log13.log)("dataSpaceManager not initialized yet, ignoring space admission", {
3498
4037
  details: assertion
3499
4038
  }, {
3500
- F: __dxlog_file12,
3501
- L: 226,
4039
+ F: __dxlog_file15,
4040
+ L: 232,
3502
4041
  S: this,
3503
4042
  C: (f, a) => f(...a)
3504
4043
  });
3505
4044
  return;
3506
4045
  }
3507
4046
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3508
- (0, import_log12.log)("space already exists, ignoring space admission", {
4047
+ (0, import_log13.log)("space already exists, ignoring space admission", {
3509
4048
  details: assertion
3510
4049
  }, {
3511
- F: __dxlog_file12,
3512
- L: 230,
4050
+ F: __dxlog_file15,
4051
+ L: 236,
3513
4052
  S: this,
3514
4053
  C: (f, a) => f(...a)
3515
4054
  });
3516
4055
  return;
3517
4056
  }
3518
4057
  try {
3519
- (0, import_log12.log)("accepting space recorded in halo", {
4058
+ (0, import_log13.log)("accepting space recorded in halo", {
3520
4059
  details: assertion
3521
4060
  }, {
3522
- F: __dxlog_file12,
3523
- L: 235,
4061
+ F: __dxlog_file15,
4062
+ L: 241,
3524
4063
  S: this,
3525
4064
  C: (f, a) => f(...a)
3526
4065
  });
@@ -3529,9 +4068,9 @@ var ServiceContext = class {
3529
4068
  genesisFeedKey: assertion.genesisFeedKey
3530
4069
  });
3531
4070
  } catch (err) {
3532
- import_log12.log.catch(err, void 0, {
3533
- F: __dxlog_file12,
3534
- L: 241,
4071
+ import_log13.log.catch(err, void 0, {
4072
+ F: __dxlog_file15,
4073
+ L: 247,
3535
4074
  S: this,
3536
4075
  C: (f, a) => f(...a)
3537
4076
  });
@@ -3541,26 +4080,38 @@ var ServiceContext = class {
3541
4080
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3542
4081
  }
3543
4082
  };
4083
+ _ts_decorate5([
4084
+ import_tracing3.trace.span()
4085
+ ], ServiceContext.prototype, "open", null);
4086
+ _ts_decorate5([
4087
+ import_tracing3.trace.span()
4088
+ ], ServiceContext.prototype, "_initialize", null);
4089
+ ServiceContext = _ts_decorate5([
4090
+ (0, import_util7.safeInstanceof)("dxos.client-services.ServiceContext"),
4091
+ import_tracing3.trace.resource()
4092
+ ], ServiceContext);
3544
4093
 
3545
4094
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3546
- var import_tiny_invariant13 = __toESM(require("tiny-invariant"));
3547
4095
  var import_async17 = require("@dxos/async");
3548
4096
  var import_client_protocol5 = require("@dxos/client-protocol");
3549
- var import_document_model = require("@dxos/document-model");
4097
+ var import_context10 = require("@dxos/context");
4098
+ var import_document_model2 = require("@dxos/document-model");
3550
4099
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
4100
+ var import_invariant14 = require("@dxos/invariant");
3551
4101
  var import_keys11 = require("@dxos/keys");
3552
- var import_log15 = require("@dxos/log");
4102
+ var import_log16 = require("@dxos/log");
3553
4103
  var import_messaging = require("@dxos/messaging");
3554
4104
  var import_model_factory = require("@dxos/model-factory");
3555
4105
  var import_network_manager2 = require("@dxos/network-manager");
3556
- var import_protocols9 = require("@dxos/protocols");
3557
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
4106
+ var import_protocols10 = require("@dxos/protocols");
4107
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
3558
4108
  var import_text_model = require("@dxos/text-model");
4109
+ var import_tracing4 = require("@dxos/tracing");
3559
4110
 
3560
4111
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
3561
4112
  var import_async15 = require("@dxos/async");
3562
- var import_codec_protobuf11 = require("@dxos/codec-protobuf");
3563
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
4113
+ var import_codec_protobuf12 = require("@dxos/codec-protobuf");
4114
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
3564
4115
  var DevicesServiceImpl = class {
3565
4116
  constructor(_identityManager) {
3566
4117
  this._identityManager = _identityManager;
@@ -3569,23 +4120,19 @@ var DevicesServiceImpl = class {
3569
4120
  throw new Error("Method not implemented.");
3570
4121
  }
3571
4122
  queryDevices() {
3572
- return new import_codec_protobuf11.Stream(({ next }) => {
4123
+ return new import_codec_protobuf12.Stream(({ next }) => {
3573
4124
  const update = () => {
3574
- var _a;
3575
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4125
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
3576
4126
  if (!deviceKeys) {
3577
4127
  next({
3578
4128
  devices: []
3579
4129
  });
3580
4130
  } else {
3581
4131
  next({
3582
- devices: Array.from(deviceKeys.values()).map((key) => {
3583
- var _a2;
3584
- return {
3585
- deviceKey: key,
3586
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services10.DeviceKind.CURRENT : import_services10.DeviceKind.TRUSTED
3587
- };
3588
- })
4132
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4133
+ deviceKey: key,
4134
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services11.DeviceKind.CURRENT : import_services11.DeviceKind.TRUSTED
4135
+ }))
3589
4136
  });
3590
4137
  }
3591
4138
  };
@@ -3605,10 +4152,10 @@ var DevicesServiceImpl = class {
3605
4152
  };
3606
4153
 
3607
4154
  // packages/sdk/client-services/src/packlets/locks/node.ts
3608
- var import_tiny_invariant12 = __toESM(require("tiny-invariant"));
4155
+ var import_invariant13 = require("@dxos/invariant");
3609
4156
  var import_lock_file = require("@dxos/lock-file");
3610
- var import_log13 = require("@dxos/log");
3611
- function _ts_decorate3(decorators, target, key, desc) {
4157
+ var import_log14 = require("@dxos/log");
4158
+ function _ts_decorate6(decorators, target, key, desc) {
3612
4159
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3613
4160
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3614
4161
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3618,7 +4165,7 @@ function _ts_decorate3(decorators, target, key, desc) {
3618
4165
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3619
4166
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3620
4167
  }
3621
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
4168
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
3622
4169
  var Lock = class {
3623
4170
  constructor({ lockKey: lockPath, onAcquire, onRelease }) {
3624
4171
  this._lockPath = lockPath;
@@ -3629,102 +4176,113 @@ var Lock = class {
3629
4176
  return this._lockPath;
3630
4177
  }
3631
4178
  async acquire() {
3632
- var _a;
3633
- (0, import_log13.log)("acquiring lock...", void 0, {
3634
- F: __dxlog_file13,
4179
+ (0, import_log14.log)("acquiring lock...", void 0, {
4180
+ F: __dxlog_file16,
3635
4181
  L: 32,
3636
4182
  S: this,
3637
4183
  C: (f, a) => f(...a)
3638
4184
  });
3639
4185
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
3640
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3641
- (0, import_log13.log)("acquired lock", void 0, {
3642
- F: __dxlog_file13,
4186
+ await this._onAcquire?.();
4187
+ (0, import_log14.log)("acquired lock", void 0, {
4188
+ F: __dxlog_file16,
3643
4189
  L: 37,
3644
4190
  S: this,
3645
4191
  C: (f, a) => f(...a)
3646
4192
  });
3647
4193
  }
3648
4194
  async release() {
3649
- var _a;
3650
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3651
- (0, import_tiny_invariant12.default)(this._fileHandle, "Lock is not acquired");
4195
+ await this._onRelease?.();
4196
+ (0, import_invariant13.invariant)(this._fileHandle, "Lock is not acquired", {
4197
+ F: __dxlog_file16,
4198
+ L: 42,
4199
+ S: this,
4200
+ A: [
4201
+ "this._fileHandle",
4202
+ "'Lock is not acquired'"
4203
+ ]
4204
+ });
3652
4205
  await import_lock_file.LockFile.release(this._fileHandle);
3653
4206
  }
3654
4207
  };
3655
- _ts_decorate3([
3656
- import_log13.logInfo
4208
+ _ts_decorate6([
4209
+ import_log14.logInfo
3657
4210
  ], Lock.prototype, "lockKey", null);
3658
4211
  var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
3659
4212
 
3660
4213
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
3661
4214
  var import_async16 = require("@dxos/async");
3662
- var import_codec_protobuf12 = require("@dxos/codec-protobuf");
3663
- var import_log14 = require("@dxos/log");
3664
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
3665
- var import_util7 = require("@dxos/util");
4215
+ var import_codec_protobuf13 = require("@dxos/codec-protobuf");
4216
+ var import_log15 = require("@dxos/log");
4217
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
4218
+ var import_util8 = require("@dxos/util");
3666
4219
  var LoggingServiceImpl = class {
3667
4220
  constructor() {
3668
4221
  this._logs = new import_async16.Event();
4222
+ this._started = /* @__PURE__ */ new Date();
3669
4223
  this._logProcessor = (_config, entry2) => {
3670
4224
  this._logs.emit(entry2);
3671
4225
  };
3672
4226
  }
3673
4227
  async open() {
3674
- import_log14.log.runtimeConfig.processors.push(this._logProcessor);
4228
+ import_log15.log.runtimeConfig.processors.push(this._logProcessor);
3675
4229
  }
3676
4230
  async close() {
3677
- const index = import_log14.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
3678
- import_log14.log.runtimeConfig.processors.splice(index, 1);
4231
+ const index = import_log15.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
4232
+ import_log15.log.runtimeConfig.processors.splice(index, 1);
3679
4233
  }
3680
4234
  async controlMetrics({ reset, record }) {
3681
4235
  if (reset) {
3682
- import_util7.tracer.clear();
4236
+ import_util8.tracer.clear();
3683
4237
  }
3684
4238
  if (record === true) {
3685
- import_util7.tracer.start();
4239
+ import_util8.tracer.start();
3686
4240
  } else if (record === false) {
3687
- import_util7.tracer.stop();
4241
+ import_util8.tracer.stop();
3688
4242
  }
3689
4243
  return {
3690
- recording: import_util7.tracer.recording
4244
+ recording: import_util8.tracer.recording
3691
4245
  };
3692
4246
  }
3693
- queryMetrics({ interval }) {
3694
- const createNumericalValues = (key) => {
3695
- var _a;
3696
- const consume = (_a = import_util7.tracer.get(key)) != null ? _a : [];
4247
+ /**
4248
+ * @deprecated (Move to diagnostics).
4249
+ */
4250
+ queryMetrics({ interval = 5e3 }) {
4251
+ const getNumericalValues = (key) => {
4252
+ const events = import_util8.tracer.get(key) ?? [];
3697
4253
  return {
3698
4254
  key,
3699
- stats: (0, import_util7.numericalValues)(consume, "duration")
4255
+ stats: (0, import_util8.numericalValues)(events, "duration")
3700
4256
  };
3701
4257
  };
3702
- return new import_codec_protobuf12.Stream(({ next }) => {
4258
+ return new import_codec_protobuf13.Stream(({ next }) => {
3703
4259
  const update = () => {
3704
4260
  const metrics = {
3705
- timestamp: new Date(),
4261
+ timestamp: /* @__PURE__ */ new Date(),
3706
4262
  values: [
3707
- createNumericalValues("dxos.echo.pipeline.control"),
3708
- createNumericalValues("dxos.echo.pipeline.data")
3709
- ]
4263
+ getNumericalValues("dxos.echo.pipeline.control"),
4264
+ getNumericalValues("dxos.echo.pipeline.data")
4265
+ ].filter(Boolean)
3710
4266
  };
3711
- next(metrics);
4267
+ next({
4268
+ timestamp: /* @__PURE__ */ new Date(),
4269
+ metrics
4270
+ });
3712
4271
  };
3713
4272
  update();
3714
- const i = setInterval(update, interval);
4273
+ const i = setInterval(update, Math.max(interval, 1e3));
3715
4274
  return () => {
3716
4275
  clearInterval(i);
3717
4276
  };
3718
4277
  });
3719
4278
  }
3720
4279
  queryLogs(request) {
3721
- return new import_codec_protobuf12.Stream(({ ctx, next }) => {
4280
+ return new import_codec_protobuf13.Stream(({ ctx, next }) => {
3722
4281
  const handler = (entry2) => {
3723
- var _a, _b, _c, _d, _e;
3724
4282
  if (LOG_PROCESSING > 0) {
3725
4283
  return;
3726
4284
  }
3727
- 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"))) {
4285
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3728
4286
  return;
3729
4287
  }
3730
4288
  if (!shouldLog(entry2, request)) {
@@ -3732,12 +4290,12 @@ var LoggingServiceImpl = class {
3732
4290
  }
3733
4291
  const record = {
3734
4292
  ...entry2,
3735
- context: (0, import_util7.jsonify)((0, import_log14.getContextFromEntry)(entry2)),
3736
- timestamp: new Date(),
4293
+ context: (0, import_util8.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
4294
+ timestamp: /* @__PURE__ */ new Date(),
3737
4295
  meta: {
3738
4296
  // TODO(dmaretskyi): Fix proto.
3739
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
3740
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4297
+ file: entry2.meta?.F ?? "",
4298
+ line: entry2.meta?.L ?? 0
3741
4299
  }
3742
4300
  };
3743
4301
  try {
@@ -3753,35 +4311,31 @@ var LoggingServiceImpl = class {
3753
4311
  };
3754
4312
  var matchFilter = (filter, level, path, options) => {
3755
4313
  switch (options) {
3756
- case import_services11.QueryLogsRequest.MatchingOptions.INCLUSIVE:
4314
+ case import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE:
3757
4315
  return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
3758
- case import_services11.QueryLogsRequest.MatchingOptions.EXPLICIT:
4316
+ case import_services12.QueryLogsRequest.MatchingOptions.EXPLICIT:
3759
4317
  return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
3760
4318
  }
3761
4319
  };
3762
4320
  var shouldLog = (entry2, request) => {
3763
- var _a;
3764
- const options = (_a = request.options) != null ? _a : import_services11.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4321
+ const options = request.options ?? import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
3765
4322
  if (request.filters === void 0) {
3766
- return options === import_services11.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4323
+ return options === import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
3767
4324
  } else {
3768
- return request.filters.some((filter) => {
3769
- var _a2, _b;
3770
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
3771
- });
4325
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
3772
4326
  }
3773
4327
  };
3774
4328
  var LOG_PROCESSING = 0;
3775
4329
 
3776
4330
  // packages/sdk/client-services/src/packlets/network/network-service.ts
3777
- var import_codec_protobuf13 = require("@dxos/codec-protobuf");
4331
+ var import_codec_protobuf14 = require("@dxos/codec-protobuf");
3778
4332
  var NetworkServiceImpl = class {
3779
4333
  constructor(networkManager, signalManager) {
3780
4334
  this.networkManager = networkManager;
3781
4335
  this.signalManager = signalManager;
3782
4336
  }
3783
4337
  queryStatus() {
3784
- return new import_codec_protobuf13.Stream(({ next }) => {
4338
+ return new import_codec_protobuf14.Stream(({ next }) => {
3785
4339
  const update = () => {
3786
4340
  next({
3787
4341
  swarm: this.networkManager.connectionState,
@@ -3810,10 +4364,10 @@ var import_client_protocol4 = require("@dxos/client-protocol");
3810
4364
  var import_errors5 = require("@dxos/errors");
3811
4365
  var import_config = require("@dxos/protocols/proto/dxos/config");
3812
4366
  var import_random_access_storage = require("@dxos/random-access-storage");
3813
- var import_util8 = require("@dxos/util");
4367
+ var import_util9 = require("@dxos/util");
3814
4368
  var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
3815
4369
  var createStorageObjects = (config) => {
3816
- const { path = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
4370
+ const { path = (0, import_util9.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
3817
4371
  if (persistent && storageType === StorageDriver.RAM) {
3818
4372
  throw new import_errors5.InvalidConfigError("RAM storage cannot be used in persistent mode.");
3819
4373
  }
@@ -3855,25 +4409,40 @@ var toStorageType = (type) => {
3855
4409
  };
3856
4410
 
3857
4411
  // packages/sdk/client-services/src/packlets/system/system-service.ts
3858
- var import_codec_protobuf14 = require("@dxos/codec-protobuf");
4412
+ var import_codec_protobuf15 = require("@dxos/codec-protobuf");
4413
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
4414
+ var import_util10 = require("@dxos/util");
3859
4415
  var SystemServiceImpl = class {
3860
- constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
4416
+ constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
3861
4417
  this._config = config;
3862
4418
  this._statusUpdate = statusUpdate;
3863
4419
  this._getCurrentStatus = getCurrentStatus;
4420
+ this._getDiagnostics = getDiagnostics;
3864
4421
  this._onUpdateStatus = onUpdateStatus;
3865
4422
  this._onReset = onReset;
3866
4423
  }
3867
4424
  async getConfig() {
3868
- var _a, _b;
3869
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4425
+ return this._config?.values ?? {};
4426
+ }
4427
+ /**
4428
+ * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
4429
+ */
4430
+ async getDiagnostics({ keys } = {}) {
4431
+ const diagnostics = await this._getDiagnostics();
4432
+ return {
4433
+ timestamp: /* @__PURE__ */ new Date(),
4434
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)({
4435
+ truncate: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4436
+ humanize: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4437
+ })))
4438
+ };
3870
4439
  }
3871
4440
  async updateStatus({ status }) {
3872
4441
  await this._onUpdateStatus(status);
3873
4442
  }
3874
4443
  // TODO(burdon): Standardize interval option in stream request?
3875
4444
  queryStatus({ interval = 3e3 } = {}) {
3876
- return new import_codec_protobuf14.Stream(({ next }) => {
4445
+ return new import_codec_protobuf15.Stream(({ next }) => {
3877
4446
  const update = () => {
3878
4447
  next({
3879
4448
  status: this._getCurrentStatus()
@@ -3918,7 +4487,7 @@ var ServiceRegistry = class {
3918
4487
  };
3919
4488
 
3920
4489
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3921
- function _ts_decorate4(decorators, target, key, desc) {
4490
+ function _ts_decorate7(decorators, target, key, desc) {
3922
4491
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3923
4492
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3924
4493
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3928,23 +4497,22 @@ function _ts_decorate4(decorators, target, key, desc) {
3928
4497
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3929
4498
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3930
4499
  }
3931
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
4500
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
3932
4501
  var createDefaultModelFactory = () => {
3933
- return new import_model_factory.ModelFactory().registerModel(import_document_model.DocumentModel).registerModel(import_text_model.TextModel);
4502
+ return new import_model_factory.ModelFactory().registerModel(import_document_model2.DocumentModel).registerModel(import_text_model.TextModel);
3934
4503
  };
3935
- var ClientServicesHost = class {
4504
+ var ClientServicesHost = class ClientServicesHost2 {
3936
4505
  constructor({
3937
4506
  config,
3938
4507
  modelFactory = createDefaultModelFactory(),
3939
- // TODO(burdon): Create ApolloLink abstraction (see Client).
3940
4508
  transportFactory,
3941
4509
  signalManager,
3942
- connectionLog,
3943
4510
  storage,
3944
4511
  // TODO(wittjosiah): Turn this on by default.
3945
4512
  lockKey,
3946
4513
  callbacks
3947
4514
  } = {}) {
4515
+ this._tracingService = import_tracing4.TRACE_PROCESSOR.createTraceSender();
3948
4516
  this._statusUpdate = new import_async17.Event();
3949
4517
  this._opening = false;
3950
4518
  this._open = false;
@@ -3963,7 +4531,7 @@ var ClientServicesHost = class {
3963
4531
  lockKey,
3964
4532
  onAcquire: () => {
3965
4533
  if (!this._opening) {
3966
- void this.open();
4534
+ void this.open(new import_context10.Context());
3967
4535
  }
3968
4536
  },
3969
4537
  onRelease: () => this.close()
@@ -3972,13 +4540,15 @@ var ClientServicesHost = class {
3972
4540
  this._systemService = new SystemServiceImpl({
3973
4541
  config: this._config,
3974
4542
  statusUpdate: this._statusUpdate,
3975
- getCurrentStatus: () => this.isOpen ? import_services12.SystemStatus.ACTIVE : import_services12.SystemStatus.INACTIVE,
4543
+ getCurrentStatus: () => this.isOpen ? import_services14.SystemStatus.ACTIVE : import_services14.SystemStatus.INACTIVE,
4544
+ getDiagnostics: () => {
4545
+ return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4546
+ },
3976
4547
  onUpdateStatus: async (status) => {
3977
- var _a, _b;
3978
- if (!this.isOpen && status === import_services12.SystemStatus.ACTIVE) {
3979
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
3980
- } else if (this.isOpen && status === import_services12.SystemStatus.INACTIVE) {
3981
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4548
+ if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
4549
+ await this._resourceLock?.acquire();
4550
+ } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
4551
+ await this._resourceLock?.release();
3982
4552
  }
3983
4553
  },
3984
4554
  onReset: async () => {
@@ -3987,12 +4557,19 @@ var ClientServicesHost = class {
3987
4557
  });
3988
4558
  this._loggingService = new LoggingServiceImpl();
3989
4559
  this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
3990
- SystemService: this._systemService
4560
+ SystemService: this._systemService,
4561
+ TracingService: this._tracingService
3991
4562
  });
3992
4563
  }
3993
4564
  get isOpen() {
3994
4565
  return this._open;
3995
4566
  }
4567
+ get config() {
4568
+ return this._config;
4569
+ }
4570
+ get context() {
4571
+ return this._serviceContext;
4572
+ }
3996
4573
  get serviceRegistry() {
3997
4574
  return this._serviceRegistry;
3998
4575
  }
@@ -4008,59 +4585,125 @@ var ClientServicesHost = class {
4008
4585
  * Can only be called once.
4009
4586
  */
4010
4587
  initialize({ config, ...options }) {
4011
- var _a, _b, _c;
4012
- (0, import_tiny_invariant13.default)(!this._open, "service host is open");
4588
+ (0, import_invariant14.invariant)(!this._open, "service host is open", {
4589
+ F: __dxlog_file17,
4590
+ L: 181,
4591
+ S: this,
4592
+ A: [
4593
+ "!this._open",
4594
+ "'service host is open'"
4595
+ ]
4596
+ });
4597
+ (0, import_log16.log)("initializing...", void 0, {
4598
+ F: __dxlog_file17,
4599
+ L: 182,
4600
+ S: this,
4601
+ C: (f, a) => f(...a)
4602
+ });
4013
4603
  if (config) {
4014
- (0, import_tiny_invariant13.default)(!this._config, "config already set");
4604
+ (0, import_invariant14.invariant)(!this._config, "config already set", {
4605
+ F: __dxlog_file17,
4606
+ L: 185,
4607
+ S: this,
4608
+ A: [
4609
+ "!this._config",
4610
+ "'config already set'"
4611
+ ]
4612
+ });
4015
4613
  this._config = config;
4016
4614
  if (!this._storage) {
4017
4615
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
4018
4616
  }
4019
4617
  }
4020
4618
  const { connectionLog = true, transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
4021
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4022
- }), signalManager = new import_messaging.WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4619
+ iceServers: this._config?.get("runtime.services.ice")
4620
+ }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4023
4621
  this._signalManager = signalManager;
4024
- (0, import_tiny_invariant13.default)(!this._networkManager, "network manager already set");
4622
+ (0, import_invariant14.invariant)(!this._networkManager, "network manager already set", {
4623
+ F: __dxlog_file17,
4624
+ L: 201,
4625
+ S: this,
4626
+ A: [
4627
+ "!this._networkManager",
4628
+ "'network manager already set'"
4629
+ ]
4630
+ });
4025
4631
  this._networkManager = new import_network_manager2.NetworkManager({
4026
4632
  log: connectionLog,
4027
4633
  transportFactory,
4028
4634
  signalManager
4029
4635
  });
4636
+ (0, import_log16.log)("initialized", void 0, {
4637
+ F: __dxlog_file17,
4638
+ L: 208,
4639
+ S: this,
4640
+ C: (f, a) => f(...a)
4641
+ });
4030
4642
  }
4031
- async open() {
4032
- var _a, _b, _c;
4643
+ async open(ctx) {
4033
4644
  if (this._open) {
4034
4645
  return;
4035
4646
  }
4036
4647
  const traceId = import_keys11.PublicKey.random().toHex();
4037
- import_log15.log.trace("dxos.sdk.client-services-host.open", import_protocols9.trace.begin({
4648
+ import_log16.log.trace("dxos.client-services.host.open", import_protocols10.trace.begin({
4038
4649
  id: traceId
4039
4650
  }), {
4040
- F: __dxlog_file14,
4041
- L: 203,
4651
+ F: __dxlog_file17,
4652
+ L: 219,
4042
4653
  S: this,
4043
4654
  C: (f, a) => f(...a)
4044
4655
  });
4045
- (0, import_tiny_invariant13.default)(this._config, "config not set");
4046
- (0, import_tiny_invariant13.default)(this._storage, "storage not set");
4047
- (0, import_tiny_invariant13.default)(this._signalManager, "signal manager not set");
4048
- (0, import_tiny_invariant13.default)(this._networkManager, "network manager not set");
4656
+ (0, import_invariant14.invariant)(this._config, "config not set", {
4657
+ F: __dxlog_file17,
4658
+ L: 221,
4659
+ S: this,
4660
+ A: [
4661
+ "this._config",
4662
+ "'config not set'"
4663
+ ]
4664
+ });
4665
+ (0, import_invariant14.invariant)(this._storage, "storage not set", {
4666
+ F: __dxlog_file17,
4667
+ L: 222,
4668
+ S: this,
4669
+ A: [
4670
+ "this._storage",
4671
+ "'storage not set'"
4672
+ ]
4673
+ });
4674
+ (0, import_invariant14.invariant)(this._signalManager, "signal manager not set", {
4675
+ F: __dxlog_file17,
4676
+ L: 223,
4677
+ S: this,
4678
+ A: [
4679
+ "this._signalManager",
4680
+ "'signal manager not set'"
4681
+ ]
4682
+ });
4683
+ (0, import_invariant14.invariant)(this._networkManager, "network manager not set", {
4684
+ F: __dxlog_file17,
4685
+ L: 224,
4686
+ S: this,
4687
+ A: [
4688
+ "this._networkManager",
4689
+ "'network manager not set'"
4690
+ ]
4691
+ });
4049
4692
  this._opening = true;
4050
- (0, import_log15.log)("opening...", {
4051
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4693
+ (0, import_log16.log)("opening...", {
4694
+ lockKey: this._resourceLock?.lockKey
4052
4695
  }, {
4053
- F: __dxlog_file14,
4054
- L: 211,
4696
+ F: __dxlog_file17,
4697
+ L: 227,
4055
4698
  S: this,
4056
4699
  C: (f, a) => f(...a)
4057
4700
  });
4058
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4701
+ await this._resourceLock?.acquire();
4059
4702
  await this._loggingService.open();
4060
4703
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4061
4704
  this._serviceRegistry.setServices({
4062
4705
  SystemService: this._systemService,
4063
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4706
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4064
4707
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4065
4708
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4066
4709
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4070,6 +4713,7 @@ var ClientServicesHost = class {
4070
4713
  DataService: new import_echo_pipeline4.DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4071
4714
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4072
4715
  LoggingService: this._loggingService,
4716
+ TracingService: this._tracingService,
4073
4717
  // TODO(burdon): Move to new protobuf definitions.
4074
4718
  DevtoolsHost: new DevtoolsServiceImpl({
4075
4719
  events: new DevtoolsHostEvents(),
@@ -4077,39 +4721,38 @@ var ClientServicesHost = class {
4077
4721
  context: this._serviceContext
4078
4722
  })
4079
4723
  });
4080
- await this._serviceContext.open();
4724
+ await this._serviceContext.open(ctx);
4081
4725
  this._opening = false;
4082
4726
  this._open = true;
4083
4727
  this._statusUpdate.emit();
4084
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4085
- (0, import_log15.log)("opened", {
4728
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4729
+ (0, import_log16.log)("opened", {
4086
4730
  deviceKey
4087
4731
  }, {
4088
- F: __dxlog_file14,
4089
- L: 266,
4732
+ F: __dxlog_file17,
4733
+ L: 284,
4090
4734
  S: this,
4091
4735
  C: (f, a) => f(...a)
4092
4736
  });
4093
- import_log15.log.trace("dxos.sdk.client-services-host.open", import_protocols9.trace.end({
4737
+ import_log16.log.trace("dxos.client-services.host.open", import_protocols10.trace.end({
4094
4738
  id: traceId
4095
4739
  }), {
4096
- F: __dxlog_file14,
4097
- L: 267,
4740
+ F: __dxlog_file17,
4741
+ L: 285,
4098
4742
  S: this,
4099
4743
  C: (f, a) => f(...a)
4100
4744
  });
4101
4745
  }
4102
4746
  async close() {
4103
- var _a;
4104
4747
  if (!this._open) {
4105
4748
  return;
4106
4749
  }
4107
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4108
- (0, import_log15.log)("closing...", {
4750
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4751
+ (0, import_log16.log)("closing...", {
4109
4752
  deviceKey
4110
4753
  }, {
4111
- F: __dxlog_file14,
4112
- L: 277,
4754
+ F: __dxlog_file17,
4755
+ L: 296,
4113
4756
  S: this,
4114
4757
  C: (f, a) => f(...a)
4115
4758
  });
@@ -4120,72 +4763,84 @@ var ClientServicesHost = class {
4120
4763
  await this._serviceContext.close();
4121
4764
  this._open = false;
4122
4765
  this._statusUpdate.emit();
4123
- (0, import_log15.log)("closed", {
4766
+ (0, import_log16.log)("closed", {
4124
4767
  deviceKey
4125
4768
  }, {
4126
- F: __dxlog_file14,
4127
- L: 283,
4769
+ F: __dxlog_file17,
4770
+ L: 302,
4128
4771
  S: this,
4129
4772
  C: (f, a) => f(...a)
4130
4773
  });
4131
4774
  }
4132
4775
  async reset() {
4133
- var _a, _b, _c;
4134
4776
  const traceId = import_keys11.PublicKey.random().toHex();
4135
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols9.trace.begin({
4777
+ import_log16.log.trace("dxos.sdk.client-services-host.reset", import_protocols10.trace.begin({
4136
4778
  id: traceId
4137
4779
  }), {
4138
- F: __dxlog_file14,
4139
- L: 288,
4780
+ F: __dxlog_file17,
4781
+ L: 307,
4140
4782
  S: this,
4141
4783
  C: (f, a) => f(...a)
4142
4784
  });
4143
- (0, import_log15.log)("resetting...", void 0, {
4144
- F: __dxlog_file14,
4145
- L: 290,
4785
+ (0, import_log16.log)("resetting...", void 0, {
4786
+ F: __dxlog_file17,
4787
+ L: 309,
4146
4788
  S: this,
4147
4789
  C: (f, a) => f(...a)
4148
4790
  });
4149
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4791
+ await this._serviceContext?.close();
4150
4792
  await this._storage.reset();
4151
- (0, import_log15.log)("reset", void 0, {
4152
- F: __dxlog_file14,
4153
- L: 293,
4793
+ (0, import_log16.log)("reset", void 0, {
4794
+ F: __dxlog_file17,
4795
+ L: 312,
4154
4796
  S: this,
4155
4797
  C: (f, a) => f(...a)
4156
4798
  });
4157
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols9.trace.end({
4799
+ import_log16.log.trace("dxos.sdk.client-services-host.reset", import_protocols10.trace.end({
4158
4800
  id: traceId
4159
4801
  }), {
4160
- F: __dxlog_file14,
4161
- L: 294,
4802
+ F: __dxlog_file17,
4803
+ L: 313,
4162
4804
  S: this,
4163
4805
  C: (f, a) => f(...a)
4164
4806
  });
4165
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4807
+ await this._callbacks?.onReset?.();
4166
4808
  }
4167
4809
  };
4168
- _ts_decorate4([
4169
- import_async17.synchronized
4810
+ _ts_decorate7([
4811
+ import_tracing4.trace.info()
4812
+ ], ClientServicesHost.prototype, "_opening", void 0);
4813
+ _ts_decorate7([
4814
+ import_tracing4.trace.info()
4815
+ ], ClientServicesHost.prototype, "_open", void 0);
4816
+ _ts_decorate7([
4817
+ import_async17.synchronized,
4818
+ import_tracing4.trace.span()
4170
4819
  ], ClientServicesHost.prototype, "open", null);
4171
- _ts_decorate4([
4172
- import_async17.synchronized
4820
+ _ts_decorate7([
4821
+ import_async17.synchronized,
4822
+ import_tracing4.trace.span()
4173
4823
  ], ClientServicesHost.prototype, "close", null);
4824
+ ClientServicesHost = _ts_decorate7([
4825
+ import_tracing4.trace.resource()
4826
+ ], ClientServicesHost);
4174
4827
 
4175
4828
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
4176
4829
  var import_async19 = require("@dxos/async");
4177
4830
  var import_client_protocol7 = require("@dxos/client-protocol");
4178
- var import_log16 = require("@dxos/log");
4831
+ var import_context11 = require("@dxos/context");
4832
+ var import_log17 = require("@dxos/log");
4179
4833
  var import_messaging2 = require("@dxos/messaging");
4180
4834
  var import_network_manager3 = require("@dxos/network-manager");
4181
- var import_util9 = require("@dxos/util");
4835
+ var import_util11 = require("@dxos/util");
4182
4836
 
4183
4837
  // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
4184
- var import_tiny_invariant14 = __toESM(require("tiny-invariant"));
4185
4838
  var import_async18 = require("@dxos/async");
4186
4839
  var import_client_protocol6 = require("@dxos/client-protocol");
4840
+ var import_invariant15 = require("@dxos/invariant");
4187
4841
  var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
4188
4842
  var import_rpc2 = require("@dxos/rpc");
4843
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/shell-runtime.ts";
4189
4844
  var ShellRuntimeImpl = class {
4190
4845
  constructor(_port) {
4191
4846
  this._port = _port;
@@ -4211,7 +4866,15 @@ var ShellRuntimeImpl = class {
4211
4866
  });
4212
4867
  }
4213
4868
  async setAppContext(context) {
4214
- (0, import_tiny_invariant14.default)(this._appRpc, "runtime not open");
4869
+ (0, import_invariant15.invariant)(this._appRpc, "runtime not open", {
4870
+ F: __dxlog_file18,
4871
+ L: 44,
4872
+ S: this,
4873
+ A: [
4874
+ "this._appRpc",
4875
+ "'runtime not open'"
4876
+ ]
4877
+ });
4215
4878
  await this._appRpc.rpc.AppService.setContext(context);
4216
4879
  }
4217
4880
  async open() {
@@ -4233,14 +4896,13 @@ var ShellRuntimeImpl = class {
4233
4896
  await this._appRpc.open();
4234
4897
  }
4235
4898
  async close() {
4236
- var _a;
4237
- await ((_a = this._appRpc) == null ? void 0 : _a.close());
4899
+ await this._appRpc?.close();
4238
4900
  this._appRpc = void 0;
4239
4901
  }
4240
4902
  };
4241
4903
 
4242
4904
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
4243
- function _ts_decorate5(decorators, target, key, desc) {
4905
+ function _ts_decorate8(decorators, target, key, desc) {
4244
4906
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4245
4907
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4246
4908
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4250,7 +4912,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4250
4912
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4251
4913
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4252
4914
  }
4253
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts";
4915
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts";
4254
4916
  var LOCK_KEY = "DXOS_RESOURCE_LOCK";
4255
4917
  var IFrameHostRuntime = class {
4256
4918
  constructor({ config, origin, appPort, shellPort }) {
@@ -4270,15 +4932,14 @@ var IFrameHostRuntime = class {
4270
4932
  return this._shellRuntime;
4271
4933
  }
4272
4934
  async start() {
4273
- var _a;
4274
- (0, import_log16.log)("starting...", void 0, {
4275
- F: __dxlog_file15,
4276
- L: 70,
4935
+ (0, import_log17.log)("starting...", void 0, {
4936
+ F: __dxlog_file19,
4937
+ L: 71,
4277
4938
  S: this,
4278
4939
  C: (f, a) => f(...a)
4279
4940
  });
4280
4941
  try {
4281
- this._config = await (0, import_util9.getAsyncValue)(this._configProvider);
4942
+ this._config = await (0, import_util11.getAsyncValue)(this._configProvider);
4282
4943
  this._transportFactory = (0, import_network_manager3.createWebRTCTransportFactory)({
4283
4944
  iceServers: this._config.get("runtime.services.ice")
4284
4945
  });
@@ -4315,59 +4976,58 @@ var IFrameHostRuntime = class {
4315
4976
  ...middleware
4316
4977
  });
4317
4978
  await Promise.all([
4318
- this._clientServices.open(),
4979
+ this._clientServices.open(new import_context11.Context()),
4319
4980
  this._clientRpc.open(),
4320
- (_a = this._shellRuntime) == null ? void 0 : _a.open()
4981
+ this._shellRuntime?.open()
4321
4982
  ]);
4322
4983
  this._ready.wake(void 0);
4323
- (0, import_log16.log)("started", void 0, {
4324
- F: __dxlog_file15,
4325
- L: 113,
4984
+ (0, import_log17.log)("started", void 0, {
4985
+ F: __dxlog_file19,
4986
+ L: 114,
4326
4987
  S: this,
4327
4988
  C: (f, a) => f(...a)
4328
4989
  });
4329
4990
  } catch (err) {
4330
4991
  this._ready.wake(err);
4331
- import_log16.log.catch(err, void 0, {
4332
- F: __dxlog_file15,
4333
- L: 116,
4992
+ import_log17.log.catch(err, void 0, {
4993
+ F: __dxlog_file19,
4994
+ L: 117,
4334
4995
  S: this,
4335
4996
  C: (f, a) => f(...a)
4336
4997
  });
4337
4998
  }
4338
4999
  }
4339
5000
  async stop() {
4340
- var _a;
4341
- (0, import_log16.log)("stopping...", void 0, {
4342
- F: __dxlog_file15,
4343
- L: 121,
5001
+ (0, import_log17.log)("stopping...", void 0, {
5002
+ F: __dxlog_file19,
5003
+ L: 122,
4344
5004
  S: this,
4345
5005
  C: (f, a) => f(...a)
4346
5006
  });
4347
5007
  await this._clientRpc.close();
4348
5008
  await this._clientServices.close();
4349
- await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
4350
- (0, import_log16.log)("stopped", void 0, {
4351
- F: __dxlog_file15,
4352
- L: 125,
5009
+ await this._shellRuntime?.close();
5010
+ (0, import_log17.log)("stopped", void 0, {
5011
+ F: __dxlog_file19,
5012
+ L: 126,
4353
5013
  S: this,
4354
5014
  C: (f, a) => f(...a)
4355
5015
  });
4356
5016
  }
4357
5017
  };
4358
- _ts_decorate5([
4359
- import_log16.logInfo
5018
+ _ts_decorate8([
5019
+ import_log17.logInfo
4360
5020
  ], IFrameHostRuntime.prototype, "origin", void 0);
4361
5021
 
4362
5022
  // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
4363
5023
  var import_async20 = require("@dxos/async");
4364
5024
  var import_client_protocol8 = require("@dxos/client-protocol");
4365
5025
  var import_errors6 = require("@dxos/errors");
4366
- var import_log17 = require("@dxos/log");
5026
+ var import_log18 = require("@dxos/log");
4367
5027
  var import_network_manager4 = require("@dxos/network-manager");
4368
5028
  var import_rpc3 = require("@dxos/rpc");
4369
- var import_util10 = require("@dxos/util");
4370
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts";
5029
+ var import_util12 = require("@dxos/util");
5030
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts";
4371
5031
  var IFrameProxyRuntime = class {
4372
5032
  constructor({ config, systemPort, shellPort }) {
4373
5033
  this._id = String(Math.floor(Math.random() * 1e6));
@@ -4383,8 +5043,7 @@ var IFrameProxyRuntime = class {
4383
5043
  return this._shellRuntime;
4384
5044
  }
4385
5045
  async open(origin) {
4386
- var _a;
4387
- this._config = await (0, import_util10.getAsyncValue)(this._configProvider);
5046
+ this._config = await (0, import_util12.getAsyncValue)(this._configProvider);
4388
5047
  this._transportService = new import_network_manager4.WebRTCTransportService({
4389
5048
  iceServers: this._config.get("runtime.services.ice")
4390
5049
  });
@@ -4415,20 +5074,19 @@ var IFrameProxyRuntime = class {
4415
5074
  lockKey
4416
5075
  });
4417
5076
  } catch (err) {
4418
- import_log17.log.catch(err, void 0, {
4419
- F: __dxlog_file16,
5077
+ import_log18.log.catch(err, void 0, {
5078
+ F: __dxlog_file20,
4420
5079
  L: 85,
4421
5080
  S: this,
4422
5081
  C: (f, a) => f(...a)
4423
5082
  });
4424
5083
  throw new import_errors6.RemoteServiceConnectionError("Failed to connect to worker");
4425
5084
  }
4426
- await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
5085
+ await this._shellRuntime?.open();
4427
5086
  }
4428
5087
  async close() {
4429
- var _a;
4430
5088
  this._release.wake();
4431
- await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
5089
+ await this._shellRuntime?.close();
4432
5090
  await this._systemRpc.rpc.WorkerService.stop();
4433
5091
  await this._systemRpc.close();
4434
5092
  }
@@ -4439,18 +5097,19 @@ var IFrameProxyRuntime = class {
4439
5097
 
4440
5098
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
4441
5099
  var import_async22 = require("@dxos/async");
4442
- var import_log19 = require("@dxos/log");
5100
+ var import_context12 = require("@dxos/context");
5101
+ var import_log20 = require("@dxos/log");
4443
5102
  var import_messaging3 = require("@dxos/messaging");
4444
5103
  var import_network_manager5 = require("@dxos/network-manager");
4445
5104
 
4446
5105
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
4447
- var import_tiny_invariant15 = __toESM(require("tiny-invariant"));
4448
5106
  var import_async21 = require("@dxos/async");
4449
5107
  var import_client_protocol9 = require("@dxos/client-protocol");
4450
- var import_log18 = require("@dxos/log");
5108
+ var import_invariant16 = require("@dxos/invariant");
5109
+ var import_log19 = require("@dxos/log");
4451
5110
  var import_rpc4 = require("@dxos/rpc");
4452
- var import_util11 = require("@dxos/util");
4453
- function _ts_decorate6(decorators, target, key, desc) {
5111
+ var import_util13 = require("@dxos/util");
5112
+ function _ts_decorate9(decorators, target, key, desc) {
4454
5113
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4455
5114
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4456
5115
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4460,12 +5119,20 @@ function _ts_decorate6(decorators, target, key, desc) {
4460
5119
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4461
5120
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4462
5121
  }
4463
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts";
5122
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts";
4464
5123
  var WorkerSession = class {
4465
5124
  constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }) {
4466
5125
  this._startTrigger = new import_async21.Trigger();
4467
- this.onClose = new import_util11.Callback();
4468
- (0, import_tiny_invariant15.default)(serviceHost);
5126
+ this.onClose = new import_util13.Callback();
5127
+ (0, import_invariant16.invariant)(serviceHost, void 0, {
5128
+ F: __dxlog_file21,
5129
+ L: 49,
5130
+ S: this,
5131
+ A: [
5132
+ "serviceHost",
5133
+ ""
5134
+ ]
5135
+ });
4469
5136
  this._serviceHost = serviceHost;
4470
5137
  const middleware = {
4471
5138
  handleCall: async (method, params, handler) => {
@@ -4512,8 +5179,8 @@ var WorkerSession = class {
4512
5179
  try {
4513
5180
  await this.close();
4514
5181
  } catch (err) {
4515
- import_log18.log.catch(err, void 0, {
4516
- F: __dxlog_file17,
5182
+ import_log19.log.catch(err, void 0, {
5183
+ F: __dxlog_file21,
4517
5184
  L: 99,
4518
5185
  S: this,
4519
5186
  C: (f, a) => f(...a)
@@ -4529,8 +5196,8 @@ var WorkerSession = class {
4529
5196
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
4530
5197
  }
4531
5198
  async open() {
4532
- import_log18.log.info("opening...", void 0, {
4533
- F: __dxlog_file17,
5199
+ import_log19.log.info("opening...", void 0, {
5200
+ F: __dxlog_file21,
4534
5201
  L: 113,
4535
5202
  S: this,
4536
5203
  C: (f, a) => f(...a)
@@ -4546,26 +5213,26 @@ var WorkerSession = class {
4546
5213
  if (this.lockKey) {
4547
5214
  void this._afterLockReleases(this.lockKey, () => this.close());
4548
5215
  }
4549
- import_log18.log.info("opened", void 0, {
4550
- F: __dxlog_file17,
4551
- L: 120,
5216
+ import_log19.log.info("opened", void 0, {
5217
+ F: __dxlog_file21,
5218
+ L: 124,
4552
5219
  S: this,
4553
5220
  C: (f, a) => f(...a)
4554
5221
  });
4555
5222
  }
4556
5223
  async close() {
4557
- import_log18.log.info("closing...", void 0, {
4558
- F: __dxlog_file17,
4559
- L: 124,
5224
+ import_log19.log.info("closing...", void 0, {
5225
+ F: __dxlog_file21,
5226
+ L: 128,
4560
5227
  S: this,
4561
5228
  C: (f, a) => f(...a)
4562
5229
  });
4563
5230
  try {
4564
5231
  await this.onClose.callIfSet();
4565
5232
  } catch (err) {
4566
- import_log18.log.catch(err, void 0, {
4567
- F: __dxlog_file17,
4568
- L: 128,
5233
+ import_log19.log.catch(err, void 0, {
5234
+ F: __dxlog_file21,
5235
+ L: 132,
4569
5236
  S: this,
4570
5237
  C: (f, a) => f(...a)
4571
5238
  });
@@ -4574,9 +5241,9 @@ var WorkerSession = class {
4574
5241
  this._clientRpc.close(),
4575
5242
  this._iframeRpc.close()
4576
5243
  ]);
4577
- import_log18.log.info("closed", void 0, {
4578
- F: __dxlog_file17,
4579
- L: 132,
5244
+ import_log19.log.info("closed", void 0, {
5245
+ F: __dxlog_file21,
5246
+ L: 136,
4580
5247
  S: this,
4581
5248
  C: (f, a) => f(...a)
4582
5249
  });
@@ -4584,10 +5251,10 @@ var WorkerSession = class {
4584
5251
  async _maybeOpenShell() {
4585
5252
  try {
4586
5253
  await (0, import_async21.asyncTimeout)(this._shellClientRpc.open(), 1e3);
4587
- } catch (e) {
4588
- import_log18.log.info("No shell connected.", void 0, {
4589
- F: __dxlog_file17,
4590
- L: 139,
5254
+ } catch {
5255
+ import_log19.log.info("No shell connected.", void 0, {
5256
+ F: __dxlog_file21,
5257
+ L: 143,
4591
5258
  S: this,
4592
5259
  C: (f, a) => f(...a)
4593
5260
  });
@@ -4598,15 +5265,15 @@ var WorkerSession = class {
4598
5265
  }).then(callback);
4599
5266
  }
4600
5267
  };
4601
- _ts_decorate6([
4602
- import_log18.logInfo
5268
+ _ts_decorate9([
5269
+ import_log19.logInfo
4603
5270
  ], WorkerSession.prototype, "origin", void 0);
4604
- _ts_decorate6([
4605
- import_log18.logInfo
5271
+ _ts_decorate9([
5272
+ import_log19.logInfo
4606
5273
  ], WorkerSession.prototype, "lockKey", void 0);
4607
5274
 
4608
5275
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
4609
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-runtime.ts";
5276
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-runtime.ts";
4610
5277
  var WorkerRuntime = class {
4611
5278
  // prettier-ignore
4612
5279
  constructor(_configProvider) {
@@ -4626,9 +5293,9 @@ var WorkerRuntime = class {
4626
5293
  return this._clientServices;
4627
5294
  }
4628
5295
  async start() {
4629
- (0, import_log19.log)("starting...", void 0, {
4630
- F: __dxlog_file18,
4631
- L: 48,
5296
+ (0, import_log20.log)("starting...", void 0, {
5297
+ F: __dxlog_file22,
5298
+ L: 49,
4632
5299
  S: this,
4633
5300
  C: (f, a) => f(...a)
4634
5301
  });
@@ -4640,19 +5307,19 @@ var WorkerRuntime = class {
4640
5307
  signalManager: signals ? new import_messaging3.WebsocketSignalManager(signals) : new import_messaging3.MemorySignalManager(new import_messaging3.MemorySignalManagerContext()),
4641
5308
  transportFactory: this._transportFactory
4642
5309
  });
4643
- await this._clientServices.open();
5310
+ await this._clientServices.open(new import_context12.Context());
4644
5311
  this._ready.wake(void 0);
4645
- (0, import_log19.log)("started", void 0, {
4646
- F: __dxlog_file18,
4647
- L: 62,
5312
+ (0, import_log20.log)("started", void 0, {
5313
+ F: __dxlog_file22,
5314
+ L: 63,
4648
5315
  S: this,
4649
5316
  C: (f, a) => f(...a)
4650
5317
  });
4651
5318
  } catch (err) {
4652
5319
  this._ready.wake(err);
4653
- import_log19.log.catch(err, void 0, {
4654
- F: __dxlog_file18,
4655
- L: 65,
5320
+ import_log20.log.catch(err, void 0, {
5321
+ F: __dxlog_file22,
5322
+ L: 66,
4656
5323
  S: this,
4657
5324
  C: (f, a) => f(...a)
4658
5325
  });
@@ -4684,9 +5351,9 @@ var WorkerRuntime = class {
4684
5351
  * Selects one of the existing session fro WebRTC networking.
4685
5352
  */
4686
5353
  _reconnectWebrtc() {
4687
- (0, import_log19.log)("reconnecting webrtc...", void 0, {
4688
- F: __dxlog_file18,
4689
- L: 102,
5354
+ (0, import_log20.log)("reconnecting webrtc...", void 0, {
5355
+ F: __dxlog_file22,
5356
+ L: 103,
4690
5357
  S: this,
4691
5358
  C: (f, a) => f(...a)
4692
5359
  });
@@ -4733,6 +5400,7 @@ var WorkerRuntime = class {
4733
5400
  WorkerSession,
4734
5401
  createAuthProvider,
4735
5402
  createDefaultModelFactory,
5403
+ createDiagnostics,
4736
5404
  createStorageObjects,
4737
5405
  getNetworkPeers,
4738
5406
  isLocked,