@dxos/client-services 0.1.41 → 0.1.45-next.45667d4

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 (164) hide show
  1. package/dist/lib/browser/{chunk-T73F4MV4.mjs → chunk-IHSMRQ3L.mjs} +985 -867
  2. package/dist/lib/browser/chunk-IHSMRQ3L.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +7 -3
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +121 -297
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +589 -469
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +688 -740
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/index.d.ts +1 -0
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/packlets/devices/devices-service.d.ts +1 -1
  15. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  16. package/dist/types/src/packlets/devtools/devtools.d.ts +4 -2
  17. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  18. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  19. package/dist/types/src/packlets/devtools/network.d.ts +5 -4
  20. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  21. package/dist/types/src/packlets/identity/authenticator.d.ts +1 -1
  22. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  23. package/dist/types/src/packlets/identity/identity-manager.d.ts +2 -4
  24. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  25. package/dist/types/src/packlets/identity/identity.d.ts +1 -1
  26. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  27. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +2 -3
  28. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  29. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -3
  30. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -2
  32. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  33. package/dist/types/src/packlets/network/network-service.d.ts +6 -4
  34. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  35. package/dist/types/src/packlets/services/client-rpc-server.d.ts +2 -2
  36. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  37. package/dist/types/src/packlets/services/index.d.ts +0 -1
  38. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  39. package/dist/types/src/packlets/services/local-client-services.d.ts +1 -1
  40. package/dist/types/src/packlets/services/local-client-services.d.ts.map +1 -1
  41. package/dist/types/src/packlets/services/service-context.d.ts +4 -2
  42. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  43. package/dist/types/src/packlets/services/service-host.d.ts +16 -9
  44. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  45. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +12 -7
  46. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  47. package/dist/types/src/packlets/spaces/data-space.d.ts +15 -10
  48. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  49. package/dist/types/src/packlets/spaces/genesis.d.ts +5 -0
  50. package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -0
  51. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +4 -4
  52. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  53. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -1
  54. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  55. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  56. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  57. package/dist/types/src/packlets/testing/credential-utils.d.ts +1 -1
  58. package/dist/types/src/packlets/testing/index.d.ts +0 -1
  59. package/dist/types/src/packlets/testing/index.d.ts.map +1 -1
  60. package/dist/types/src/packlets/testing/invitation-utils.d.ts +13 -7
  61. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  62. package/dist/types/src/packlets/testing/test-builder.d.ts +35 -32
  63. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  64. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +1 -1
  65. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  66. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts +5 -2
  67. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  68. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +1 -1
  69. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +1 -1
  70. package/dist/types/src/packlets/vault/worker-runtime.d.ts +1 -1
  71. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  72. package/dist/types/src/packlets/vault/worker-session.d.ts +4 -7
  73. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  74. package/package.json +30 -31
  75. package/src/index.ts +1 -0
  76. package/src/packlets/devices/devices-service.ts +5 -5
  77. package/src/packlets/devtools/devtools.ts +25 -4
  78. package/src/packlets/devtools/feeds.ts +10 -10
  79. package/src/packlets/devtools/keys.ts +6 -6
  80. package/src/packlets/devtools/network.ts +14 -13
  81. package/src/packlets/devtools/spaces.ts +4 -4
  82. package/src/packlets/identity/authenticator.test.ts +1 -1
  83. package/src/packlets/identity/authenticator.ts +2 -2
  84. package/src/packlets/identity/identity-manager.test.ts +17 -13
  85. package/src/packlets/identity/identity-manager.ts +21 -22
  86. package/src/packlets/identity/identity-service.ts +3 -3
  87. package/src/packlets/identity/identity.test.ts +65 -36
  88. package/src/packlets/identity/identity.ts +17 -17
  89. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  90. package/src/packlets/invitations/device-invitation-protocol.ts +7 -7
  91. package/src/packlets/invitations/invitation-extension.ts +16 -27
  92. package/src/packlets/invitations/invitations-handler.ts +17 -25
  93. package/src/packlets/invitations/invitations-service.ts +11 -11
  94. package/src/packlets/invitations/space-invitation-protocol.test.ts +9 -9
  95. package/src/packlets/invitations/space-invitation-protocol.ts +11 -12
  96. package/src/packlets/logging/logging-service.ts +8 -3
  97. package/src/packlets/network/network-service.test.ts +8 -8
  98. package/src/packlets/network/network-service.ts +20 -8
  99. package/src/packlets/services/client-rpc-server.ts +5 -5
  100. package/src/packlets/services/index.ts +0 -1
  101. package/src/packlets/services/local-client-services.ts +1 -1
  102. package/src/packlets/services/service-context.test.ts +3 -3
  103. package/src/packlets/services/service-context.ts +26 -24
  104. package/src/packlets/services/service-host.test.ts +6 -6
  105. package/src/packlets/services/service-host.ts +57 -31
  106. package/src/packlets/services/service-registry.test.ts +20 -38
  107. package/src/packlets/spaces/data-space-manager.test.ts +17 -29
  108. package/src/packlets/spaces/data-space-manager.ts +29 -35
  109. package/src/packlets/spaces/data-space.ts +73 -47
  110. package/src/packlets/spaces/genesis.ts +81 -0
  111. package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
  112. package/src/packlets/spaces/notarization-plugin.ts +12 -12
  113. package/src/packlets/spaces/spaces-service.test.ts +2 -2
  114. package/src/packlets/spaces/spaces-service.ts +21 -10
  115. package/src/packlets/storage/storage.ts +3 -3
  116. package/src/packlets/system/system-service.test.ts +1 -1
  117. package/src/packlets/system/system-service.ts +1 -1
  118. package/src/packlets/testing/credential-utils.ts +4 -4
  119. package/src/packlets/testing/index.ts +0 -1
  120. package/src/packlets/testing/invitation-utils.ts +28 -33
  121. package/src/packlets/testing/test-builder.ts +132 -168
  122. package/src/packlets/vault/iframe-host-runtime.ts +8 -11
  123. package/src/packlets/vault/iframe-proxy-runtime.ts +25 -9
  124. package/src/packlets/vault/shell-runtime.ts +4 -4
  125. package/src/packlets/vault/vault-resource-lock.ts +2 -2
  126. package/src/packlets/vault/worker-runtime.ts +7 -9
  127. package/src/packlets/vault/worker-session.ts +24 -45
  128. package/dist/lib/browser/chunk-T73F4MV4.mjs.map +0 -7
  129. package/dist/types/src/packlets/services/utils.d.ts +0 -7
  130. package/dist/types/src/packlets/services/utils.d.ts.map +0 -1
  131. package/dist/types/src/packlets/testing/host-test-builder.d.ts +0 -43
  132. package/dist/types/src/packlets/testing/host-test-builder.d.ts.map +0 -1
  133. package/dist/types/src/packlets/tests/client-services.test.d.ts +0 -2
  134. package/dist/types/src/packlets/tests/client-services.test.d.ts.map +0 -1
  135. package/dist/types/src/packlets/tests/client.test.d.ts +0 -2
  136. package/dist/types/src/packlets/tests/client.test.d.ts.map +0 -1
  137. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts +0 -2
  138. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts.map +0 -1
  139. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts +0 -2
  140. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts.map +0 -1
  141. package/dist/types/src/packlets/tests/halo-profile.test.d.ts +0 -2
  142. package/dist/types/src/packlets/tests/halo-profile.test.d.ts.map +0 -1
  143. package/dist/types/src/packlets/tests/invitations.test.d.ts +0 -2
  144. package/dist/types/src/packlets/tests/invitations.test.d.ts.map +0 -1
  145. package/dist/types/src/packlets/tests/shared-worker.test.d.ts +0 -2
  146. package/dist/types/src/packlets/tests/shared-worker.test.d.ts.map +0 -1
  147. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts +0 -2
  148. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts.map +0 -1
  149. package/dist/types/src/packlets/tests/spaces.test.d.ts +0 -2
  150. package/dist/types/src/packlets/tests/spaces.test.d.ts.map +0 -1
  151. package/dist/types/src/packlets/tests/text.test.d.ts +0 -2
  152. package/dist/types/src/packlets/tests/text.test.d.ts.map +0 -1
  153. package/src/packlets/services/utils.ts +0 -53
  154. package/src/packlets/testing/host-test-builder.ts +0 -163
  155. package/src/packlets/tests/client-services.test.ts +0 -222
  156. package/src/packlets/tests/client.test.ts +0 -140
  157. package/src/packlets/tests/halo-credentials.test.ts +0 -94
  158. package/src/packlets/tests/halo-persistent.test.ts +0 -53
  159. package/src/packlets/tests/halo-profile.test.ts +0 -48
  160. package/src/packlets/tests/invitations.test.ts +0 -389
  161. package/src/packlets/tests/shared-worker.test.ts +0 -92
  162. package/src/packlets/tests/spaces-invitations.test.ts +0 -46
  163. package/src/packlets/tests/spaces.test.ts +0 -147
  164. package/src/packlets/tests/text.test.ts +0 -206
@@ -8,9 +8,6 @@ import { PublicKey } from "@dxos/keys";
8
8
  import { ComplexMap } from "@dxos/util";
9
9
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
10
10
  return new Stream(({ next }) => {
11
- if ((feedKeys == null ? void 0 : feedKeys.length) === 0) {
12
- return;
13
- }
14
11
  const subscriptions = new EventSubscriptions();
15
12
  const feedMap = new ComplexMap(PublicKey.hash);
16
13
  const update = () => {
@@ -19,13 +16,14 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
19
16
  if (!feedMap.has(feed.key)) {
20
17
  feedMap.set(feed.key, feed);
21
18
  feed.on("close", update);
22
- subscriptions.add(feed.off("close", update));
19
+ subscriptions.add(() => feed.off("close", update));
23
20
  }
24
21
  });
25
22
  next({
26
23
  feeds: Array.from(feedMap.values()).map((feed) => ({
27
24
  feedKey: feed.key,
28
- length: feed.properties.length
25
+ length: feed.properties.length,
26
+ diskUsage: feed.core.byteLength
29
27
  }))
30
28
  });
31
29
  };
@@ -79,10 +77,10 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
79
77
  import { Stream as Stream2 } from "@dxos/codec-protobuf";
80
78
  import { Context } from "@dxos/context";
81
79
  import { PublicKey as PublicKey2 } from "@dxos/keys";
82
- var subscribeToNetworkStatus = ({ networkManager }) => new Stream2(({ next, close }) => {
80
+ var subscribeToNetworkStatus = ({ signalManager }) => new Stream2(({ next, close }) => {
83
81
  const update = () => {
84
82
  try {
85
- const status = networkManager.signalManager.getStatus();
83
+ const status = signalManager.getStatus();
86
84
  next({
87
85
  servers: status
88
86
  });
@@ -90,12 +88,12 @@ var subscribeToNetworkStatus = ({ networkManager }) => new Stream2(({ next, clos
90
88
  close(err);
91
89
  }
92
90
  };
93
- networkManager.signalManager.statusChanged.on(update);
91
+ signalManager.statusChanged.on(() => update());
94
92
  update();
95
93
  });
96
- var subscribeToSignal = ({ networkManager }) => new Stream2(({ next }) => {
94
+ var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
97
95
  const ctx = new Context();
98
- networkManager.signalManager.onMessage.on(ctx, (message) => {
96
+ signalManager.onMessage.on(ctx, (message) => {
99
97
  next({
100
98
  message: {
101
99
  author: message.author.asUint8Array(),
@@ -105,7 +103,7 @@ var subscribeToSignal = ({ networkManager }) => new Stream2(({ next }) => {
105
103
  receivedAt: new Date()
106
104
  });
107
105
  });
108
- networkManager.signalManager.swarmEvent.on(ctx, (swarmEvent) => {
106
+ signalManager.swarmEvent.on(ctx, (swarmEvent) => {
109
107
  next({
110
108
  swarmEvent: swarmEvent.swarmEvent,
111
109
  receivedAt: new Date()
@@ -204,16 +202,16 @@ import { Event as AsyncEvent } from "@dxos/async";
204
202
  import { Stream as Stream5 } from "@dxos/codec-protobuf";
205
203
 
206
204
  // packages/sdk/client-services/src/packlets/devtools/keys.ts
205
+ import { scheduleTask } from "@dxos/async";
207
206
  import { Stream as Stream4 } from "@dxos/codec-protobuf";
208
- var subscribeToKeyringKeys = ({ keyring }) => new Stream4(({ next }) => {
209
- const update = () => {
207
+ var subscribeToKeyringKeys = ({ keyring }) => new Stream4(({ next, ctx }) => {
208
+ const update = async () => {
210
209
  next({
211
- keys: keyring.list()
210
+ keys: await keyring.list()
212
211
  });
213
212
  };
214
- const unsubscribe = keyring.keysUpdate.on(update);
215
- update();
216
- return unsubscribe;
213
+ keyring.keysUpdate.on(ctx, update);
214
+ scheduleTask(ctx, update);
217
215
  });
218
216
 
219
217
  // packages/sdk/client-services/src/packlets/devtools/devtools.ts
@@ -238,6 +236,24 @@ var DevtoolsServiceImpl = class {
238
236
  getConfig(request) {
239
237
  throw new Error();
240
238
  }
239
+ async getStorageInfo() {
240
+ var _a, _b, _c, _d, _e;
241
+ const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
242
+ used: 0
243
+ };
244
+ const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
245
+ return {
246
+ type: this.params.context.storage.type,
247
+ storageUsage: storageUsage.used,
248
+ originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
249
+ usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
250
+ };
251
+ }
252
+ async getSnapshots() {
253
+ return {
254
+ snapshots: await this.params.context.snapshotStore.listSnapshots()
255
+ };
256
+ }
241
257
  resetStorage(request) {
242
258
  throw new Error();
243
259
  }
@@ -288,12 +304,12 @@ var DevtoolsServiceImpl = class {
288
304
  }
289
305
  subscribeToSignalStatus(request) {
290
306
  return subscribeToNetworkStatus({
291
- networkManager: this.params.context.networkManager
307
+ signalManager: this.params.context.signalManager
292
308
  });
293
309
  }
294
310
  subscribeToSignal() {
295
311
  return subscribeToSignal({
296
- networkManager: this.params.context.networkManager
312
+ signalManager: this.params.context.signalManager
297
313
  });
298
314
  }
299
315
  subscribeToSwarmInfo() {
@@ -578,19 +594,18 @@ var IdentityManager = class {
578
594
  this._feedStore = _feedStore;
579
595
  this._spaceManager = _spaceManager;
580
596
  this.stateUpdate = new Event2();
581
- this._instanceId = PublicKey3.random().toHex();
582
597
  }
583
598
  get identity() {
584
599
  return this._identity;
585
600
  }
586
601
  async open() {
587
602
  var _a;
588
- log3.trace("dxos.halo.identity-manager", trace.begin({
589
- id: this._instanceId,
590
- parentId: this._traceParent
603
+ const traceId = PublicKey3.random().toHex();
604
+ log3.trace("dxos.halo.identity-manager.open", trace.begin({
605
+ id: traceId
591
606
  }), {
592
607
  file: "identity-manager.ts",
593
- line: 72,
608
+ line: 70,
594
609
  scope: this,
595
610
  callSite: (f, a) => f(...a)
596
611
  });
@@ -600,7 +615,7 @@ var IdentityManager = class {
600
615
  identityRecord
601
616
  }, {
602
617
  file: "identity-manager.ts",
603
- line: 76,
618
+ line: 74,
604
619
  scope: this,
605
620
  callSite: (f, a) => f(...a)
606
621
  });
@@ -613,31 +628,31 @@ var IdentityManager = class {
613
628
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
614
629
  }, {
615
630
  file: "identity-manager.ts",
616
- line: 81,
631
+ line: 79,
617
632
  scope: this,
618
633
  callSite: (f, a) => f(...a)
619
634
  });
620
635
  this.stateUpdate.emit();
621
636
  }
622
- }
623
- async close() {
624
- var _a;
625
- await ((_a = this._identity) == null ? void 0 : _a.close());
626
- log3.trace("dxos.halo.identity-manager", trace.end({
627
- id: this._instanceId
637
+ log3.trace("dxos.halo.identity-manager.open", trace.end({
638
+ id: traceId
628
639
  }), {
629
640
  file: "identity-manager.ts",
630
- line: 91,
641
+ line: 85,
631
642
  scope: this,
632
643
  callSite: (f, a) => f(...a)
633
644
  });
634
645
  }
646
+ async close() {
647
+ var _a;
648
+ await ((_a = this._identity) == null ? void 0 : _a.close());
649
+ }
635
650
  async createIdentity({ displayName } = {}) {
636
651
  var _a;
637
652
  assert2(!this._identity, "Identity already exists.");
638
653
  log3("creating identity...", {}, {
639
654
  file: "identity-manager.ts",
640
- line: 96,
655
+ line: 94,
641
656
  scope: this,
642
657
  callSite: (f, a) => f(...a)
643
658
  });
@@ -686,7 +701,7 @@ var IdentityManager = class {
686
701
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
687
702
  }, {
688
703
  file: "identity-manager.ts",
689
- line: 151,
704
+ line: 149,
690
705
  scope: this,
691
706
  callSite: (f, a) => f(...a)
692
707
  });
@@ -696,7 +711,7 @@ var IdentityManager = class {
696
711
  deviceKey: identity.deviceKey
697
712
  }, {
698
713
  file: "identity-manager.ts",
699
- line: 157,
714
+ line: 155,
700
715
  scope: this,
701
716
  callSite: (f, a) => f(...a)
702
717
  });
@@ -711,7 +726,7 @@ var IdentityManager = class {
711
726
  params
712
727
  }, {
713
728
  file: "identity-manager.ts",
714
- line: 165,
729
+ line: 163,
715
730
  scope: this,
716
731
  callSite: (f, a) => f(...a)
717
732
  });
@@ -737,7 +752,7 @@ var IdentityManager = class {
737
752
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
738
753
  }, {
739
754
  file: "identity-manager.ts",
740
- line: 185,
755
+ line: 183,
741
756
  scope: this,
742
757
  callSite: (f, a) => f(...a)
743
758
  });
@@ -747,7 +762,7 @@ var IdentityManager = class {
747
762
  deviceKey: identity.deviceKey
748
763
  }, {
749
764
  file: "identity-manager.ts",
750
- line: 191,
765
+ line: 189,
751
766
  scope: this,
752
767
  callSite: (f, a) => f(...a)
753
768
  });
@@ -759,7 +774,7 @@ var IdentityManager = class {
759
774
  identityRecord
760
775
  }, {
761
776
  file: "identity-manager.ts",
762
- line: 197,
777
+ line: 195,
763
778
  scope: this,
764
779
  callSite: (f, a) => f(...a)
765
780
  });
@@ -792,7 +807,7 @@ var IdentityManager = class {
792
807
  identityKey: identityRecord.identityKey
793
808
  }, {
794
809
  file: "identity-manager.ts",
795
- line: 225,
810
+ line: 223,
796
811
  scope: this,
797
812
  callSite: (f, a) => f(...a)
798
813
  });
@@ -809,7 +824,8 @@ var IdentityManager = class {
809
824
  },
810
825
  swarmIdentity,
811
826
  onNetworkConnection: () => {
812
- }
827
+ },
828
+ memberKey: identityKey
813
829
  });
814
830
  }
815
831
  };
@@ -929,8 +945,8 @@ var DeviceInvitationProtocol = class {
929
945
 
930
946
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
931
947
  import assert6 from "@dxos/node-std/assert";
932
- import { PushStream, scheduleTask, sleep, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
933
- import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT, ON_CLOSE_DELAY } from "@dxos/client";
948
+ import { PushStream, scheduleTask as scheduleTask2, sleep, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
949
+ import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT, ON_CLOSE_DELAY } from "@dxos/client-protocol";
934
950
  import { Context as Context4 } from "@dxos/context";
935
951
  import { generatePasscode } from "@dxos/credentials";
936
952
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2 } from "@dxos/errors";
@@ -979,11 +995,10 @@ var InvitationHostExtension = class extends RpcExtension {
979
995
  introduce: async (request) => {
980
996
  const traceId = PublicKey4.random().toHex();
981
997
  log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
982
- id: traceId,
983
- parentId: this._traceParent
998
+ id: traceId
984
999
  }), {
985
1000
  file: "invitation-extension.ts",
986
- line: 78,
1001
+ line: 76,
987
1002
  scope: this,
988
1003
  callSite: (f, a) => f(...a)
989
1004
  });
@@ -992,7 +1007,7 @@ var InvitationHostExtension = class extends RpcExtension {
992
1007
  id: traceId
993
1008
  }), {
994
1009
  file: "invitation-extension.ts",
995
- line: 83,
1010
+ line: 78,
996
1011
  scope: this,
997
1012
  callSite: (f, a) => f(...a)
998
1013
  });
@@ -1001,11 +1016,10 @@ var InvitationHostExtension = class extends RpcExtension {
1001
1016
  authenticate: async (request) => {
1002
1017
  const traceId = PublicKey4.random().toHex();
1003
1018
  log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
1004
- id: traceId,
1005
- parentId: this._traceParent
1019
+ id: traceId
1006
1020
  }), {
1007
1021
  file: "invitation-extension.ts",
1008
- line: 89,
1022
+ line: 84,
1009
1023
  scope: this,
1010
1024
  callSite: (f, a) => f(...a)
1011
1025
  });
@@ -1017,7 +1031,7 @@ var InvitationHostExtension = class extends RpcExtension {
1017
1031
  }
1018
1032
  }), {
1019
1033
  file: "invitation-extension.ts",
1020
- line: 94,
1034
+ line: 86,
1021
1035
  scope: this,
1022
1036
  callSite: (f, a) => f(...a)
1023
1037
  });
@@ -1026,11 +1040,10 @@ var InvitationHostExtension = class extends RpcExtension {
1026
1040
  admit: async (request) => {
1027
1041
  const traceId = PublicKey4.random().toHex();
1028
1042
  log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
1029
- id: traceId,
1030
- parentId: this._traceParent
1043
+ id: traceId
1031
1044
  }), {
1032
1045
  file: "invitation-extension.ts",
1033
- line: 100,
1046
+ line: 92,
1034
1047
  scope: this,
1035
1048
  callSite: (f, a) => f(...a)
1036
1049
  });
@@ -1039,7 +1052,7 @@ var InvitationHostExtension = class extends RpcExtension {
1039
1052
  id: traceId
1040
1053
  }), {
1041
1054
  file: "invitation-extension.ts",
1042
- line: 105,
1055
+ line: 94,
1043
1056
  scope: this,
1044
1057
  callSite: (f, a) => f(...a)
1045
1058
  });
@@ -1113,7 +1126,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1113
1126
  try {
1114
1127
  log4("begin options", {}, {
1115
1128
  file: "invitation-extension.ts",
1116
- line: 189,
1129
+ line: 178,
1117
1130
  scope: this,
1118
1131
  callSite: (f, a) => f(...a)
1119
1132
  });
@@ -1125,7 +1138,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1125
1138
  }));
1126
1139
  log4("end options", {}, {
1127
1140
  file: "invitation-extension.ts",
1128
- line: 192,
1141
+ line: 181,
1129
1142
  scope: this,
1130
1143
  callSite: (f, a) => f(...a)
1131
1144
  });
@@ -1139,7 +1152,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1139
1152
  } catch (err) {
1140
1153
  log4("openError", err, {
1141
1154
  file: "invitation-extension.ts",
1142
- line: 202,
1155
+ line: 191,
1143
1156
  scope: this,
1144
1157
  callSite: (f, a) => f(...a)
1145
1158
  });
@@ -1149,7 +1162,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1149
1162
  async onClose() {
1150
1163
  log4("onClose", {}, {
1151
1164
  file: "invitation-extension.ts",
1152
- line: 208,
1165
+ line: 197,
1153
1166
  scope: this,
1154
1167
  callSite: (f, a) => f(...a)
1155
1168
  });
@@ -1160,6 +1173,9 @@ var InvitationGuestExtension = class extends RpcExtension {
1160
1173
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1161
1174
  var MAX_OTP_ATTEMPTS = 3;
1162
1175
  var InvitationsHandler = class {
1176
+ /**
1177
+ * @internal
1178
+ */
1163
1179
  constructor(_networkManager) {
1164
1180
  this._networkManager = _networkManager;
1165
1181
  }
@@ -1190,7 +1206,7 @@ var InvitationsHandler = class {
1190
1206
  ...protocol.toJSON()
1191
1207
  }, {
1192
1208
  file: "invitations-handler.ts",
1193
- line: 99,
1209
+ line: 98,
1194
1210
  scope: this,
1195
1211
  callSite: (f, a) => f(...a)
1196
1212
  });
@@ -1208,7 +1224,7 @@ var InvitationsHandler = class {
1208
1224
  ...protocol.toJSON()
1209
1225
  }, {
1210
1226
  file: "invitations-handler.ts",
1211
- line: 112,
1227
+ line: 111,
1212
1228
  scope: this,
1213
1229
  callSite: (f, a) => f(...a)
1214
1230
  });
@@ -1227,7 +1243,7 @@ var InvitationsHandler = class {
1227
1243
  authCode: code
1228
1244
  }, {
1229
1245
  file: "invitations-handler.ts",
1230
- line: 131,
1246
+ line: 130,
1231
1247
  scope: this,
1232
1248
  callSite: (f, a) => f(...a)
1233
1249
  });
@@ -1236,7 +1252,7 @@ var InvitationsHandler = class {
1236
1252
  case Invitation2.AuthMethod.NONE: {
1237
1253
  log5("authentication not required", {}, {
1238
1254
  file: "invitations-handler.ts",
1239
- line: 136,
1255
+ line: 135,
1240
1256
  scope: this,
1241
1257
  callSite: (f, a) => f(...a)
1242
1258
  });
@@ -1261,7 +1277,7 @@ var InvitationsHandler = class {
1261
1277
  authMethod: invitation.authMethod
1262
1278
  }, {
1263
1279
  file: "invitations-handler.ts",
1264
- line: 154,
1280
+ line: 153,
1265
1281
  scope: this,
1266
1282
  callSite: (f, a) => f(...a)
1267
1283
  });
@@ -1290,15 +1306,14 @@ var InvitationsHandler = class {
1290
1306
  }
1291
1307
  },
1292
1308
  onOpen: () => {
1293
- scheduleTask(ctx, async () => {
1309
+ scheduleTask2(ctx, async () => {
1294
1310
  const traceId = PublicKey5.random().toHex();
1295
1311
  try {
1296
1312
  log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.begin({
1297
- id: traceId,
1298
- parentId: this._traceParent
1313
+ id: traceId
1299
1314
  }), {
1300
1315
  file: "invitations-handler.ts",
1301
- line: 189,
1316
+ line: 188,
1302
1317
  scope: this,
1303
1318
  callSite: (f, a) => f(...a)
1304
1319
  });
@@ -1306,7 +1321,7 @@ var InvitationsHandler = class {
1306
1321
  ...protocol.toJSON()
1307
1322
  }, {
1308
1323
  file: "invitations-handler.ts",
1309
- line: 193,
1324
+ line: 189,
1310
1325
  scope: this,
1311
1326
  callSite: (f, a) => f(...a)
1312
1327
  });
@@ -1322,7 +1337,7 @@ var InvitationsHandler = class {
1322
1337
  ...protocol.toJSON()
1323
1338
  }, {
1324
1339
  file: "invitations-handler.ts",
1325
- line: 196,
1340
+ line: 192,
1326
1341
  scope: this,
1327
1342
  callSite: (f, a) => f(...a)
1328
1343
  });
@@ -1334,7 +1349,7 @@ var InvitationsHandler = class {
1334
1349
  id: traceId
1335
1350
  }), {
1336
1351
  file: "invitations-handler.ts",
1337
- line: 198,
1352
+ line: 194,
1338
1353
  scope: this,
1339
1354
  callSite: (f, a) => f(...a)
1340
1355
  });
@@ -1344,7 +1359,7 @@ var InvitationsHandler = class {
1344
1359
  ...protocol.toJSON()
1345
1360
  }, {
1346
1361
  file: "invitations-handler.ts",
1347
- line: 201,
1362
+ line: 197,
1348
1363
  scope: this,
1349
1364
  callSite: (f, a) => f(...a)
1350
1365
  });
@@ -1355,7 +1370,7 @@ var InvitationsHandler = class {
1355
1370
  } else {
1356
1371
  log5.error("failed", err, {
1357
1372
  file: "invitations-handler.ts",
1358
- line: 204,
1373
+ line: 200,
1359
1374
  scope: this,
1360
1375
  callSite: (f, a) => f(...a)
1361
1376
  });
@@ -1366,7 +1381,7 @@ var InvitationsHandler = class {
1366
1381
  error: err
1367
1382
  }), {
1368
1383
  file: "invitations-handler.ts",
1369
- line: 207,
1384
+ line: 203,
1370
1385
  scope: this,
1371
1386
  callSite: (f, a) => f(...a)
1372
1387
  });
@@ -1387,7 +1402,7 @@ var InvitationsHandler = class {
1387
1402
  ...protocol.toJSON()
1388
1403
  }, {
1389
1404
  file: "invitations-handler.ts",
1390
- line: 221,
1405
+ line: 217,
1391
1406
  scope: this,
1392
1407
  callSite: (f, a) => f(...a)
1393
1408
  });
@@ -1398,7 +1413,7 @@ var InvitationsHandler = class {
1398
1413
  } else {
1399
1414
  log5.error("failed", err, {
1400
1415
  file: "invitations-handler.ts",
1401
- line: 224,
1416
+ line: 220,
1402
1417
  scope: this,
1403
1418
  callSite: (f, a) => f(...a)
1404
1419
  });
@@ -1406,10 +1421,9 @@ var InvitationsHandler = class {
1406
1421
  }
1407
1422
  }
1408
1423
  });
1409
- extension._traceParent = this._traceParent;
1410
1424
  return extension;
1411
1425
  };
1412
- scheduleTask(ctx, async () => {
1426
+ scheduleTask2(ctx, async () => {
1413
1427
  const topic = invitation.swarmKey;
1414
1428
  const swarmConnection = await this._networkManager.joinSwarm({
1415
1429
  topic,
@@ -1459,7 +1473,7 @@ var InvitationsHandler = class {
1459
1473
  ...protocol.toJSON()
1460
1474
  }, {
1461
1475
  file: "invitations-handler.ts",
1462
- line: 279,
1476
+ line: 274,
1463
1477
  scope: this,
1464
1478
  callSite: (f, a) => f(...a)
1465
1479
  });
@@ -1469,7 +1483,7 @@ var InvitationsHandler = class {
1469
1483
  } else {
1470
1484
  log5.warn("auth failed", err, {
1471
1485
  file: "invitations-handler.ts",
1472
- line: 282,
1486
+ line: 277,
1473
1487
  scope: this,
1474
1488
  callSite: (f, a) => f(...a)
1475
1489
  });
@@ -1483,7 +1497,7 @@ var InvitationsHandler = class {
1483
1497
  ...protocol.toJSON()
1484
1498
  }, {
1485
1499
  file: "invitations-handler.ts",
1486
- line: 290,
1500
+ line: 285,
1487
1501
  scope: this,
1488
1502
  callSite: (f, a) => f(...a)
1489
1503
  });
@@ -1498,7 +1512,7 @@ var InvitationsHandler = class {
1498
1512
  currentState
1499
1513
  }, {
1500
1514
  file: "invitations-handler.ts",
1501
- line: 300,
1515
+ line: 295,
1502
1516
  scope: this,
1503
1517
  callSite: (f, a) => f(...a)
1504
1518
  });
@@ -1506,27 +1520,26 @@ var InvitationsHandler = class {
1506
1520
  stream.error(new Error("Remote peer disconnected."));
1507
1521
  }
1508
1522
  });
1509
- scheduleTask(ctx, async () => {
1523
+ scheduleTask2(ctx, async () => {
1510
1524
  const traceId = PublicKey5.random().toHex();
1511
1525
  try {
1512
1526
  log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.begin({
1513
- id: traceId,
1514
- parentId: this._traceParent
1527
+ id: traceId
1515
1528
  }), {
1516
1529
  file: "invitations-handler.ts",
1517
- line: 309,
1530
+ line: 304,
1518
1531
  scope: this,
1519
1532
  callSite: (f, a) => f(...a)
1520
1533
  });
1521
1534
  if (++connectionCount > 1) {
1522
1535
  throw new Error(`multiple connections detected: ${connectionCount}`);
1523
1536
  }
1524
- scheduleTask(ctx, () => ctx.raise(new TimeoutError(timeout)), timeout);
1537
+ scheduleTask2(ctx, () => ctx.raise(new TimeoutError(timeout)), timeout);
1525
1538
  log5("connected", {
1526
1539
  ...protocol.toJSON()
1527
1540
  }, {
1528
1541
  file: "invitations-handler.ts",
1529
- line: 320,
1542
+ line: 312,
1530
1543
  scope: this,
1531
1544
  callSite: (f, a) => f(...a)
1532
1545
  });
@@ -1537,7 +1550,7 @@ var InvitationsHandler = class {
1537
1550
  ...protocol.toJSON()
1538
1551
  }, {
1539
1552
  file: "invitations-handler.ts",
1540
- line: 324,
1553
+ line: 316,
1541
1554
  scope: this,
1542
1555
  callSite: (f, a) => f(...a)
1543
1556
  });
@@ -1547,7 +1560,7 @@ var InvitationsHandler = class {
1547
1560
  response: introductionResponse
1548
1561
  }, {
1549
1562
  file: "invitations-handler.ts",
1550
- line: 328,
1563
+ line: 320,
1551
1564
  scope: this,
1552
1565
  callSite: (f, a) => f(...a)
1553
1566
  });
@@ -1559,7 +1572,7 @@ var InvitationsHandler = class {
1559
1572
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1560
1573
  log5("guest waiting for authentication code...", {}, {
1561
1574
  file: "invitations-handler.ts",
1562
- line: 337,
1575
+ line: 329,
1563
1576
  scope: this,
1564
1577
  callSite: (f, a) => f(...a)
1565
1578
  });
@@ -1571,7 +1584,7 @@ var InvitationsHandler = class {
1571
1584
  });
1572
1585
  log5("sending authentication request", {}, {
1573
1586
  file: "invitations-handler.ts",
1574
- line: 341,
1587
+ line: 333,
1575
1588
  scope: this,
1576
1589
  callSite: (f, a) => f(...a)
1577
1590
  });
@@ -1592,7 +1605,7 @@ var InvitationsHandler = class {
1592
1605
  attempt
1593
1606
  }, {
1594
1607
  file: "invitations-handler.ts",
1595
- line: 352,
1608
+ line: 344,
1596
1609
  scope: this,
1597
1610
  callSite: (f, a) => f(...a)
1598
1611
  });
@@ -1609,7 +1622,7 @@ var InvitationsHandler = class {
1609
1622
  ...protocol.toJSON()
1610
1623
  }, {
1611
1624
  file: "invitations-handler.ts",
1612
- line: 363,
1625
+ line: 355,
1613
1626
  scope: this,
1614
1627
  callSite: (f, a) => f(...a)
1615
1628
  });
@@ -1620,7 +1633,7 @@ var InvitationsHandler = class {
1620
1633
  ...protocol.toJSON()
1621
1634
  }, {
1622
1635
  file: "invitations-handler.ts",
1623
- line: 371,
1636
+ line: 363,
1624
1637
  scope: this,
1625
1638
  callSite: (f, a) => f(...a)
1626
1639
  });
@@ -1632,7 +1645,7 @@ var InvitationsHandler = class {
1632
1645
  id: traceId
1633
1646
  }), {
1634
1647
  file: "invitations-handler.ts",
1635
- line: 373,
1648
+ line: 365,
1636
1649
  scope: this,
1637
1650
  callSite: (f, a) => f(...a)
1638
1651
  });
@@ -1642,7 +1655,7 @@ var InvitationsHandler = class {
1642
1655
  ...protocol.toJSON()
1643
1656
  }, {
1644
1657
  file: "invitations-handler.ts",
1645
- line: 376,
1658
+ line: 368,
1646
1659
  scope: this,
1647
1660
  callSite: (f, a) => f(...a)
1648
1661
  });
@@ -1652,7 +1665,7 @@ var InvitationsHandler = class {
1652
1665
  } else {
1653
1666
  log5("auth failed", err, {
1654
1667
  file: "invitations-handler.ts",
1655
- line: 379,
1668
+ line: 371,
1656
1669
  scope: this,
1657
1670
  callSite: (f, a) => f(...a)
1658
1671
  });
@@ -1663,7 +1676,7 @@ var InvitationsHandler = class {
1663
1676
  error: err
1664
1677
  }), {
1665
1678
  file: "invitations-handler.ts",
1666
- line: 382,
1679
+ line: 374,
1667
1680
  scope: this,
1668
1681
  callSite: (f, a) => f(...a)
1669
1682
  });
@@ -1681,7 +1694,7 @@ var InvitationsHandler = class {
1681
1694
  ...protocol.toJSON()
1682
1695
  }, {
1683
1696
  file: "invitations-handler.ts",
1684
- line: 393,
1697
+ line: 385,
1685
1698
  scope: this,
1686
1699
  callSite: (f, a) => f(...a)
1687
1700
  });
@@ -1691,7 +1704,7 @@ var InvitationsHandler = class {
1691
1704
  } else {
1692
1705
  log5("auth failed", err, {
1693
1706
  file: "invitations-handler.ts",
1694
- line: 396,
1707
+ line: 388,
1695
1708
  scope: this,
1696
1709
  callSite: (f, a) => f(...a)
1697
1710
  });
@@ -1701,7 +1714,7 @@ var InvitationsHandler = class {
1701
1714
  });
1702
1715
  return extension;
1703
1716
  };
1704
- scheduleTask(ctx, async () => {
1717
+ scheduleTask2(ctx, async () => {
1705
1718
  assert6(invitation.swarmKey);
1706
1719
  const topic = invitation.swarmKey;
1707
1720
  const swarmConnection = await this._networkManager.joinSwarm({
@@ -1940,7 +1953,7 @@ var SpaceInvitationProtocol = class {
1940
1953
  guest: deviceKey
1941
1954
  }, {
1942
1955
  file: "space-invitation-protocol.ts",
1943
- line: 51,
1956
+ line: 50,
1944
1957
  scope: this,
1945
1958
  callSite: (f, a) => f(...a)
1946
1959
  });
@@ -1993,353 +2006,60 @@ var SpaceInvitationProtocol = class {
1993
2006
  }
1994
2007
  };
1995
2008
 
1996
- // packages/sdk/client-services/src/packlets/storage/storage.ts
1997
- import { InvalidConfigError } from "@dxos/errors";
1998
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
1999
- import { createStorage, StorageType } from "@dxos/random-access-storage";
2000
- var StorageDriver = Runtime.Client.Storage.StorageDriver;
2001
- var createStorageObjects = (config) => {
2002
- const { path = "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
2003
- if (persistent && storageType === StorageDriver.RAM) {
2004
- throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
2005
- }
2006
- if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
2007
- throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
2008
- }
2009
- if (persistent && keyStorage === StorageDriver.RAM) {
2010
- throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
2011
- }
2012
- if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
2013
- throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
2014
- }
2015
- return {
2016
- storage: createStorage({
2017
- type: persistent ? toStorageType(storageType) : StorageType.RAM,
2018
- root: `${path}/`
2019
- })
2020
- };
2021
- };
2022
- var toStorageType = (type) => {
2023
- switch (type) {
2024
- case void 0:
2025
- return void 0;
2026
- case StorageDriver.RAM:
2027
- return StorageType.RAM;
2028
- case StorageDriver.CHROME:
2029
- return StorageType.CHROME;
2030
- case StorageDriver.FIREFOX:
2031
- return StorageType.FIREFOX;
2032
- case StorageDriver.IDB:
2033
- return StorageType.IDB;
2034
- case StorageDriver.NODE:
2035
- return StorageType.NODE;
2036
- case StorageDriver.WEBFS:
2037
- return StorageType.WEBFS;
2038
- default:
2039
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
2040
- }
2041
- };
2009
+ // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2010
+ import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2011
+ import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2012
+ import { timed } from "@dxos/debug";
2013
+ import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2014
+ import { CancelledError, SystemError } from "@dxos/errors";
2015
+ import { PublicKey as PublicKey7 } from "@dxos/keys";
2016
+ import { log as log9 } from "@dxos/log";
2017
+ import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2018
+ import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2019
+ import { ComplexSet as ComplexSet2 } from "@dxos/util";
2042
2020
 
2043
- // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
2021
+ // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2044
2022
  import assert9 from "@dxos/node-std/assert";
2045
- import { Event as Event4 } from "@dxos/async";
2046
- import { appServiceBundle, shellServiceBundle } from "@dxos/client";
2047
- import { ShellLayout } from "@dxos/protocols/proto/dxos/iframe";
2048
- import { createProtoRpcPeer } from "@dxos/rpc";
2049
- var ShellRuntimeImpl = class {
2050
- constructor(_port) {
2051
- this._port = _port;
2052
- this.layoutUpdate = new Event4();
2053
- this._layout = ShellLayout.DEFAULT;
2054
- }
2055
- get layout() {
2056
- return this._layout;
2057
- }
2058
- get invitationCode() {
2059
- return this._invitationCode;
2060
- }
2061
- get spaceKey() {
2062
- return this._spaceKey;
2063
- }
2064
- setLayout(layout, options = {}) {
2065
- this._layout = layout;
2066
- this._invitationCode = options.invitationCode;
2067
- this._spaceKey = options.spaceKey;
2068
- this.layoutUpdate.emit({
2069
- layout,
2070
- ...options
2071
- });
2072
- }
2073
- async setAppContext(context) {
2074
- assert9(this._appRpc, "runtime not open");
2075
- await this._appRpc.rpc.AppService.setContext(context);
2023
+ import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep as sleep2, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2024
+ import { Context as Context5, rejectOnDispose } from "@dxos/context";
2025
+ import { PublicKey as PublicKey6 } from "@dxos/keys";
2026
+ import { log as log8 } from "@dxos/log";
2027
+ import { schema as schema3 } from "@dxos/protocols";
2028
+ import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2029
+ import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2030
+ var DEFAULT_RETRY_TIMEOUT = 1e3;
2031
+ var DEFAULT_SUCCESS_DELAY = 1e3;
2032
+ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2033
+ var NotarizationPlugin = class {
2034
+ constructor() {
2035
+ this._ctx = new Context5();
2036
+ this._extensionOpened = new Event4();
2037
+ this._extensions = /* @__PURE__ */ new Set();
2038
+ this._processedCredentials = new ComplexSet(PublicKey6.hash);
2039
+ this._processCredentialsTriggers = new ComplexMap2(PublicKey6.hash);
2076
2040
  }
2077
2041
  async open() {
2078
- this._appRpc = createProtoRpcPeer({
2079
- requested: appServiceBundle,
2080
- exposed: shellServiceBundle,
2081
- handlers: {
2082
- ShellService: {
2083
- setLayout: async (request) => {
2084
- this._layout = request.layout;
2085
- this._invitationCode = request.invitationCode;
2086
- this._spaceKey = request.spaceKey;
2087
- this.layoutUpdate.emit(request);
2088
- }
2089
- }
2090
- },
2091
- port: this._port
2092
- });
2093
- await this._appRpc.open();
2094
2042
  }
2095
2043
  async close() {
2096
- var _a;
2097
- await ((_a = this._appRpc) == null ? void 0 : _a.close());
2098
- this._appRpc = void 0;
2099
- }
2100
- };
2101
- var MemoryShellRuntime = class {
2102
- constructor({ layout, invitationCode, spaceKey } = {}) {
2103
- this.layoutUpdate = new Event4();
2104
- this.contextUpdate = new Event4();
2105
- this._layout = layout != null ? layout : ShellLayout.DEFAULT;
2106
- this._invitationCode = invitationCode;
2107
- this._spaceKey = spaceKey;
2108
- }
2109
- get layout() {
2110
- return this._layout;
2111
- }
2112
- get invitationCode() {
2113
- return this._invitationCode;
2114
- }
2115
- get spaceKey() {
2116
- return this._spaceKey;
2044
+ await this._ctx.dispose();
2117
2045
  }
2118
- setLayout(layout, options = {}) {
2119
- this._layout = layout;
2120
- this._invitationCode = options.invitationCode;
2121
- this._spaceKey = options.spaceKey;
2122
- this.layoutUpdate.emit({
2123
- layout,
2124
- ...options
2046
+ /**
2047
+ * Request credentials to be notarized.
2048
+ */
2049
+ async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2050
+ log8("notarize", {
2051
+ credentials
2052
+ }, {
2053
+ file: "notarization-plugin.ts",
2054
+ line: 85,
2055
+ scope: this,
2056
+ callSite: (f, a) => f(...a)
2125
2057
  });
2126
- }
2127
- async setAppContext(context) {
2128
- this.contextUpdate.emit(context);
2129
- }
2130
- };
2131
-
2132
- // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
2133
- import { Trigger as Trigger9 } from "@dxos/async";
2134
- import { log as log20, logInfo as logInfo3 } from "@dxos/log";
2135
- import { MemorySignalManager as MemorySignalManager3, MemorySignalManagerContext as MemorySignalManagerContext3, WebsocketSignalManager as WebsocketSignalManager3 } from "@dxos/messaging";
2136
- import { createWebRTCTransportFactory as createWebRTCTransportFactory2, NetworkManager as NetworkManager3 } from "@dxos/network-manager";
2137
- import { getAsyncValue as getAsyncValue2 } from "@dxos/util";
2138
-
2139
- // packages/sdk/client-services/src/packlets/services/service-host.ts
2140
- import assert14 from "@dxos/node-std/assert";
2141
- import { Event as Event9 } from "@dxos/async";
2142
- import { clientServiceBundle, createDefaultModelFactory, PublicKey as PublicKey10 } from "@dxos/client";
2143
- import { DataServiceImpl } from "@dxos/echo-pipeline";
2144
- import { log as log18 } from "@dxos/log";
2145
- import { trace as trace6 } from "@dxos/protocols";
2146
- import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
2147
-
2148
- // packages/sdk/client-services/src/packlets/devices/devices-service.ts
2149
- import { EventSubscriptions as EventSubscriptions2 } from "@dxos/async";
2150
- import { Stream as Stream8 } from "@dxos/codec-protobuf";
2151
- import { DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
2152
- var DevicesServiceImpl = class {
2153
- constructor(_identityManager) {
2154
- this._identityManager = _identityManager;
2155
- }
2156
- updateDevice(request) {
2157
- throw new Error("Method not implemented.");
2158
- }
2159
- queryDevices() {
2160
- return new Stream8(({ next }) => {
2161
- const update = () => {
2162
- var _a;
2163
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
2164
- if (!deviceKeys) {
2165
- next({
2166
- devices: []
2167
- });
2168
- } else {
2169
- next({
2170
- devices: Array.from(deviceKeys.values()).map((key) => {
2171
- var _a2;
2172
- return {
2173
- deviceKey: key,
2174
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
2175
- };
2176
- })
2177
- });
2178
- }
2179
- };
2180
- const subscriptions = new EventSubscriptions2();
2181
- subscriptions.add(this._identityManager.stateUpdate.on(() => {
2182
- update();
2183
- if (this._identityManager.identity) {
2184
- subscriptions.add(this._identityManager.identity.stateUpdate.on(() => {
2185
- update();
2186
- }));
2187
- }
2188
- }));
2189
- update();
2190
- return () => subscriptions.clear();
2191
- });
2192
- }
2193
- };
2194
-
2195
- // packages/sdk/client-services/src/packlets/logging/logging-service.ts
2196
- import { Event as Event5 } from "@dxos/async";
2197
- import { Stream as Stream9 } from "@dxos/codec-protobuf";
2198
- import { log as log8, shouldLog } from "@dxos/log";
2199
- var LoggingServiceImpl = class {
2200
- constructor() {
2201
- this._logs = new Event5();
2202
- this._logProcessor = (_config, entry2) => {
2203
- this._logs.emit(entry2);
2204
- };
2205
- }
2206
- async open() {
2207
- log8.runtimeConfig.processors.push(this._logProcessor);
2208
- }
2209
- async close() {
2210
- const index = log8.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
2211
- log8.runtimeConfig.processors.splice(index, 1);
2212
- }
2213
- queryLogs(request) {
2214
- var _a;
2215
- const filters = ((_a = request.filters) == null ? void 0 : _a.length) ? request.filters : void 0;
2216
- return new Stream9(({ ctx, next }) => {
2217
- const handler = (entry2) => {
2218
- var _a2;
2219
- if (((_a2 = entry2.meta) == null ? void 0 : _a2.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
2220
- return;
2221
- }
2222
- if (shouldLog(entry2, filters)) {
2223
- next(jsonify(entry2));
2224
- }
2225
- };
2226
- ctx.onDispose(() => {
2227
- this._logs.off(handler);
2228
- });
2229
- this._logs.on(handler);
2230
- });
2231
- }
2232
- };
2233
- var jsonify = (value) => {
2234
- if (typeof value === "function") {
2235
- return null;
2236
- } else if (typeof value === "object" && value !== null) {
2237
- if (Array.isArray(value)) {
2238
- return value.map(jsonify);
2239
- } else {
2240
- if (typeof value.toJSON === "function") {
2241
- return value.toJSON();
2242
- }
2243
- const res = {};
2244
- for (const key of Object.keys(value)) {
2245
- res[key] = jsonify(value[key]);
2246
- }
2247
- return res;
2248
- }
2249
- } else {
2250
- return value;
2251
- }
2252
- };
2253
-
2254
- // packages/sdk/client-services/src/packlets/network/network-service.ts
2255
- import { Stream as Stream10 } from "@dxos/codec-protobuf";
2256
- var NetworkServiceImpl = class {
2257
- constructor(networkManager) {
2258
- this.networkManager = networkManager;
2259
- }
2260
- subscribeToNetworkStatus() {
2261
- return new Stream10(({ next }) => {
2262
- const unsubscribe = this.networkManager.connectionStateChanged.on((state) => next({
2263
- state
2264
- }));
2265
- next({
2266
- state: this.networkManager.connectionState
2267
- });
2268
- return unsubscribe;
2269
- });
2270
- }
2271
- async setNetworkOptions(request) {
2272
- await this.networkManager.setConnectionState(request.state);
2273
- }
2274
- };
2275
-
2276
- // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2277
- import assert11 from "@dxos/node-std/assert";
2278
- import { Event as Event8, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2279
- import { SpaceState as SpaceState2 } from "@dxos/client";
2280
- import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2281
- import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2282
- import { SnapshotManager, spaceGenesis } from "@dxos/echo-pipeline";
2283
- import { PublicKey as PublicKey8 } from "@dxos/keys";
2284
- import { log as log11 } from "@dxos/log";
2285
- import { trace as trace4 } from "@dxos/protocols";
2286
- import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2287
- import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
2288
-
2289
- // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2290
- import { Event as Event7, scheduleTask as scheduleTask3, trackLeaks } from "@dxos/async";
2291
- import { SpaceState } from "@dxos/client";
2292
- import { Context as Context6 } from "@dxos/context";
2293
- import { timed } from "@dxos/debug";
2294
- import { createMappedFeedWriter, DataPipeline } from "@dxos/echo-pipeline";
2295
- import { CancelledError, SystemError } from "@dxos/errors";
2296
- import { PublicKey as PublicKey7 } from "@dxos/keys";
2297
- import { log as log10 } from "@dxos/log";
2298
- import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2299
- import { ComplexSet as ComplexSet2 } from "@dxos/util";
2300
-
2301
- // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2302
- import assert10 from "@dxos/node-std/assert";
2303
- import { DeferredTask, Event as Event6, scheduleTask as scheduleTask2, sleep as sleep2, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2304
- import { Context as Context5, rejectOnDispose } from "@dxos/context";
2305
- import { PublicKey as PublicKey6 } from "@dxos/keys";
2306
- import { log as log9 } from "@dxos/log";
2307
- import { schema as schema3 } from "@dxos/protocols";
2308
- import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2309
- import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2310
- var DEFAULT_RETRY_TIMEOUT = 1e3;
2311
- var DEFAULT_SUCCESS_DELAY = 1e3;
2312
- var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2313
- var NotarizationPlugin = class {
2314
- constructor() {
2315
- this._ctx = new Context5();
2316
- this._extensionOpened = new Event6();
2317
- this._extensions = /* @__PURE__ */ new Set();
2318
- this._processedCredentials = new ComplexSet(PublicKey6.hash);
2319
- this._processCredentialsTriggers = new ComplexMap2(PublicKey6.hash);
2320
- }
2321
- async open() {
2322
- }
2323
- async close() {
2324
- await this._ctx.dispose();
2325
- }
2326
- /**
2327
- * Request credentials to be notarized.
2328
- */
2329
- async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2330
- log9("notarize", {
2331
- credentials
2332
- }, {
2333
- file: "notarization-plugin.ts",
2334
- line: 85,
2335
- scope: this,
2336
- callSite: (f, a) => f(...a)
2337
- });
2338
- assert10(credentials.every((credential) => credential.id), "Credentials must have an id");
2058
+ assert9(credentials.every((credential) => credential.id), "Credentials must have an id");
2339
2059
  const errors = new Trigger4();
2340
2060
  const ctx = this._ctx.derive({
2341
2061
  onError: (err) => {
2342
- log9.warn("Notarization error", {
2062
+ log8.warn("Notarization error", {
2343
2063
  err
2344
2064
  }, {
2345
2065
  file: "notarization-plugin.ts",
@@ -2353,8 +2073,8 @@ var NotarizationPlugin = class {
2353
2073
  });
2354
2074
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2355
2075
  if (timeout !== 0) {
2356
- scheduleTask2(ctx, () => {
2357
- log9.warn("Notarization timeout", {
2076
+ scheduleTask3(ctx, () => {
2077
+ log8.warn("Notarization timeout", {
2358
2078
  timeout,
2359
2079
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2360
2080
  }, {
@@ -2378,7 +2098,7 @@ var NotarizationPlugin = class {
2378
2098
  ...this._extensions
2379
2099
  ].find((peer2) => !peersTried.has(peer2));
2380
2100
  if (!peer) {
2381
- log9.warn("Exhausted all peers to notarize with", {
2101
+ log8.warn("Exhausted all peers to notarize with", {
2382
2102
  retryIn: retryTimeout
2383
2103
  }, {
2384
2104
  file: "notarization-plugin.ts",
@@ -2387,11 +2107,11 @@ var NotarizationPlugin = class {
2387
2107
  callSite: (f, a) => f(...a)
2388
2108
  });
2389
2109
  peersTried.clear();
2390
- scheduleTask2(ctx, () => notarizeTask.schedule(), retryTimeout);
2110
+ scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
2391
2111
  return;
2392
2112
  }
2393
2113
  peersTried.add(peer);
2394
- log9("try notarizing", {
2114
+ log8("try notarizing", {
2395
2115
  peer: peer.localPeerId,
2396
2116
  credentialId: credentials.map((credential) => credential.id)
2397
2117
  }, {
@@ -2403,7 +2123,7 @@ var NotarizationPlugin = class {
2403
2123
  await peer.rpc.NotarizationService.notarize({
2404
2124
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2405
2125
  });
2406
- log9("success", {}, {
2126
+ log8("success", {}, {
2407
2127
  file: "notarization-plugin.ts",
2408
2128
  line: 142,
2409
2129
  scope: this,
@@ -2411,7 +2131,7 @@ var NotarizationPlugin = class {
2411
2131
  });
2412
2132
  await sleep2(successDelay);
2413
2133
  } catch (err) {
2414
- log9.warn("error notarizing (recoverable)", err, {
2134
+ log8.warn("error notarizing (recoverable)", err, {
2415
2135
  file: "notarization-plugin.ts",
2416
2136
  line: 145,
2417
2137
  scope: this,
@@ -2428,7 +2148,7 @@ var NotarizationPlugin = class {
2428
2148
  allNotarized,
2429
2149
  errors.wait()
2430
2150
  ]);
2431
- log9("done", {}, {
2151
+ log8("done", {}, {
2432
2152
  file: "notarization-plugin.ts",
2433
2153
  line: 155,
2434
2154
  scope: this,
@@ -2451,7 +2171,7 @@ var NotarizationPlugin = class {
2451
2171
  this._processCredentialsTriggers.delete(credential.id);
2452
2172
  }
2453
2173
  setWriter(writer) {
2454
- assert10(!this._writer, "Writer already set.");
2174
+ assert9(!this._writer, "Writer already set.");
2455
2175
  this._writer = writer;
2456
2176
  }
2457
2177
  async _waitUntilProcessed(id) {
@@ -2469,7 +2189,7 @@ var NotarizationPlugin = class {
2469
2189
  throw new Error("Writer not set");
2470
2190
  }
2471
2191
  for (const credential of (_a = request.credentials) != null ? _a : []) {
2472
- assert10(credential.id, "Credential must have an id");
2192
+ assert9(credential.id, "Credential must have an id");
2473
2193
  if (this._processedCredentials.has(credential.id)) {
2474
2194
  continue;
2475
2195
  }
@@ -2479,7 +2199,7 @@ var NotarizationPlugin = class {
2479
2199
  createExtension() {
2480
2200
  const extension = new NotarizationTeleportExtension({
2481
2201
  onOpen: async () => {
2482
- log9("extension opened", {
2202
+ log8("extension opened", {
2483
2203
  peer: extension.localPeerId
2484
2204
  }, {
2485
2205
  file: "notarization-plugin.ts",
@@ -2491,7 +2211,7 @@ var NotarizationPlugin = class {
2491
2211
  this._extensionOpened.emit();
2492
2212
  },
2493
2213
  onClose: async () => {
2494
- log9("extension closed", {
2214
+ log8("extension closed", {
2495
2215
  peer: extension.localPeerId
2496
2216
  }, {
2497
2217
  file: "notarization-plugin.ts",
@@ -2553,7 +2273,12 @@ var DataSpace = class DataSpace2 {
2553
2273
  constructor(params) {
2554
2274
  this._ctx = new Context6();
2555
2275
  this._state = SpaceState.CLOSED;
2556
- this.stateUpdate = new Event7();
2276
+ /**
2277
+ * Error for _state === SpaceState.ERROR.
2278
+ */
2279
+ this.error = void 0;
2280
+ this.stateUpdate = new Event5();
2281
+ this.metrics = {};
2557
2282
  var _a;
2558
2283
  this._inner = params.inner;
2559
2284
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -2564,21 +2289,13 @@ var DataSpace = class DataSpace2 {
2564
2289
  this._metadataStore = params.metadataStore;
2565
2290
  this._signingContext = params.signingContext;
2566
2291
  this._callbacks = (_a = params.callbacks) != null ? _a : {};
2567
- this._dataPipeline = new DataPipeline({
2568
- modelFactory: params.modelFactory,
2569
- metadataStore: params.metadataStore,
2570
- snapshotManager: params.snapshotManager,
2571
- memberKey: params.memberKey,
2572
- spaceKey: this._inner.key,
2573
- feedInfoProvider: (feedKey) => this._inner.spaceState.feeds.get(feedKey),
2574
- snapshotId: params.snapshotId
2575
- });
2576
2292
  this.authVerifier = new TrustedKeySetAuthVerifier({
2577
2293
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2578
2294
  update: this._inner.stateUpdate,
2579
2295
  authTimeout: AUTH_TIMEOUT2
2580
2296
  });
2581
2297
  this._notarizationPluginConsumer = this._inner.spaceState.registerProcessor(new NotarizationPlugin());
2298
+ this._cache = params.cache;
2582
2299
  }
2583
2300
  get key() {
2584
2301
  return this._inner.key;
@@ -2594,7 +2311,7 @@ var DataSpace = class DataSpace2 {
2594
2311
  return this._inner;
2595
2312
  }
2596
2313
  get dataPipeline() {
2597
- return this._dataPipeline;
2314
+ return this._inner.dataPipeline;
2598
2315
  }
2599
2316
  get presence() {
2600
2317
  return this._presence;
@@ -2602,16 +2319,19 @@ var DataSpace = class DataSpace2 {
2602
2319
  get notarizationPlugin() {
2603
2320
  return this._notarizationPluginConsumer.processor;
2604
2321
  }
2322
+ get cache() {
2323
+ return this._cache;
2324
+ }
2605
2325
  async open() {
2606
2326
  await this.notarizationPlugin.open();
2607
2327
  await this._notarizationPluginConsumer.open();
2608
2328
  await this._inner.open();
2609
2329
  this._state = SpaceState.INACTIVE;
2330
+ this.metrics.open = new Date();
2610
2331
  }
2611
2332
  async close() {
2612
2333
  this._state = SpaceState.CLOSED;
2613
2334
  await this._ctx.dispose();
2614
- await this._dataPipeline.close();
2615
2335
  await this.authVerifier.close();
2616
2336
  await this._inner.close();
2617
2337
  await this._notarizationPluginConsumer.close();
@@ -2628,25 +2348,31 @@ var DataSpace = class DataSpace2 {
2628
2348
  * Initialize the data pipeline in a separate task.
2629
2349
  */
2630
2350
  initializeDataPipelineAsync() {
2631
- scheduleTask3(this._ctx, async () => {
2351
+ scheduleTask4(this._ctx, async () => {
2632
2352
  try {
2353
+ this.metrics.pipelineInitBegin = new Date();
2633
2354
  await this.initializeDataPipeline();
2634
2355
  } catch (err) {
2635
2356
  if (err instanceof CancelledError) {
2636
- log10("Data pipeline initialization cancelled", err, {
2357
+ log9("Data pipeline initialization cancelled", err, {
2637
2358
  file: "data-space.ts",
2638
- line: 178,
2359
+ line: 173,
2639
2360
  scope: this,
2640
2361
  callSite: (f, a) => f(...a)
2641
2362
  });
2642
2363
  return;
2643
2364
  }
2644
- log10.error("Error initializing data pipeline", err, {
2365
+ log9.error("Error initializing data pipeline", err, {
2645
2366
  file: "data-space.ts",
2646
- line: 182,
2367
+ line: 177,
2647
2368
  scope: this,
2648
2369
  callSite: (f, a) => f(...a)
2649
2370
  });
2371
+ this._state = SpaceState.ERROR;
2372
+ this.error = err;
2373
+ this.stateUpdate.emit();
2374
+ } finally {
2375
+ this.metrics.ready = new Date();
2650
2376
  }
2651
2377
  });
2652
2378
  }
@@ -2660,10 +2386,11 @@ var DataSpace = class DataSpace2 {
2660
2386
  ctx: this._ctx,
2661
2387
  breakOnStall: false
2662
2388
  });
2389
+ this.metrics.controlPipelineReady = new Date();
2663
2390
  await this._createWritableFeeds();
2664
- log10("Writable feeds created", {}, {
2391
+ log9("Writable feeds created", {}, {
2665
2392
  file: "data-space.ts",
2666
- line: 200,
2393
+ line: 202,
2667
2394
  scope: this,
2668
2395
  callSite: (f, a) => f(...a)
2669
2396
  });
@@ -2673,28 +2400,23 @@ var DataSpace = class DataSpace2 {
2673
2400
  credential
2674
2401
  }
2675
2402
  }), this._inner.controlPipeline.writer));
2676
- await this._dataPipeline.open({
2677
- openPipeline: async (start) => {
2678
- const pipeline = await this._inner.createDataPipeline({
2679
- start
2680
- });
2681
- await pipeline.start();
2682
- return pipeline;
2683
- }
2684
- });
2685
- log10("waiting for data pipeline to reach target timeframe", {}, {
2403
+ await this._inner.initializeDataPipeline();
2404
+ this.metrics.dataPipelineOpen = new Date();
2405
+ await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2406
+ log9("waiting for data pipeline to reach target timeframe", {}, {
2686
2407
  file: "data-space.ts",
2687
- line: 220,
2408
+ line: 221,
2688
2409
  scope: this,
2689
2410
  callSite: (f, a) => f(...a)
2690
2411
  });
2691
- await this._dataPipeline.pipelineState.waitUntilReachedTargetTimeframe({
2412
+ await this._inner.dataPipeline.pipelineState.waitUntilReachedTargetTimeframe({
2692
2413
  ctx: this._ctx,
2693
2414
  breakOnStall: false
2694
2415
  });
2695
- log10("data pipeline ready", {}, {
2416
+ this.metrics.dataPipelineReady = new Date();
2417
+ log9("data pipeline ready", {}, {
2696
2418
  file: "data-space.ts",
2697
- line: 227,
2419
+ line: 230,
2698
2420
  scope: this,
2699
2421
  callSite: (f, a) => f(...a)
2700
2422
  });
@@ -2746,6 +2468,27 @@ var DataSpace = class DataSpace2 {
2746
2468
  }
2747
2469
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2748
2470
  }
2471
+ async createEpoch() {
2472
+ var _a, _b;
2473
+ const epoch = await this.dataPipeline.createEpoch();
2474
+ await this.inner.controlPipeline.writer.write({
2475
+ credential: {
2476
+ credential: await this._signingContext.credentialSigner.createCredential({
2477
+ subject: this.key,
2478
+ assertion: {
2479
+ "@type": "dxos.halo.credentials.Epoch",
2480
+ ...epoch
2481
+ }
2482
+ })
2483
+ }
2484
+ });
2485
+ for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2486
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2487
+ if (indexBeforeEpoch) {
2488
+ await feed.clear(0, indexBeforeEpoch + 1);
2489
+ }
2490
+ }
2491
+ }
2749
2492
  };
2750
2493
  __decorate([
2751
2494
  timed(1e4)
@@ -2754,6 +2497,88 @@ DataSpace = __decorate([
2754
2497
  trackLeaks("open", "close")
2755
2498
  ], DataSpace);
2756
2499
 
2500
+ // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2501
+ import assert10 from "@dxos/node-std/assert";
2502
+ import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2503
+ import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
2504
+ import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2505
+ import { PublicKey as PublicKey8 } from "@dxos/keys";
2506
+ import { log as log10 } from "@dxos/log";
2507
+ import { trace as trace4 } from "@dxos/protocols";
2508
+ import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2509
+ import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2510
+ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
2511
+
2512
+ // packages/sdk/client-services/src/packlets/spaces/genesis.ts
2513
+ import { createCredential } from "@dxos/credentials";
2514
+ import { failUndefined as failUndefined2 } from "@dxos/debug";
2515
+ import { AdmittedFeed as AdmittedFeed4, SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
2516
+ import { Timeframe } from "@dxos/timeframe";
2517
+ var spaceGenesis = async (keyring, signingContext, space) => {
2518
+ var _a, _b, _c, _d;
2519
+ const credentials = [
2520
+ await createCredential({
2521
+ signer: keyring,
2522
+ issuer: space.key,
2523
+ subject: space.key,
2524
+ assertion: {
2525
+ "@type": "dxos.halo.credentials.SpaceGenesis",
2526
+ spaceKey: space.key
2527
+ }
2528
+ }),
2529
+ await createCredential({
2530
+ signer: keyring,
2531
+ issuer: space.key,
2532
+ subject: signingContext.identityKey,
2533
+ assertion: {
2534
+ "@type": "dxos.halo.credentials.SpaceMember",
2535
+ spaceKey: space.key,
2536
+ role: SpaceMember.Role.ADMIN,
2537
+ profile: signingContext.profile,
2538
+ genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
2539
+ }
2540
+ }),
2541
+ await signingContext.credentialSigner.createCredential({
2542
+ subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
2543
+ assertion: {
2544
+ "@type": "dxos.halo.credentials.AdmittedFeed",
2545
+ spaceKey: space.key,
2546
+ identityKey: signingContext.identityKey,
2547
+ deviceKey: signingContext.deviceKey,
2548
+ designation: AdmittedFeed4.Designation.CONTROL
2549
+ }
2550
+ }),
2551
+ await signingContext.credentialSigner.createCredential({
2552
+ subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
2553
+ assertion: {
2554
+ "@type": "dxos.halo.credentials.AdmittedFeed",
2555
+ spaceKey: space.key,
2556
+ identityKey: signingContext.identityKey,
2557
+ deviceKey: signingContext.deviceKey,
2558
+ designation: AdmittedFeed4.Designation.DATA
2559
+ }
2560
+ }),
2561
+ await signingContext.credentialSigner.createCredential({
2562
+ subject: (_d = space.key) != null ? _d : failUndefined2(),
2563
+ assertion: {
2564
+ "@type": "dxos.halo.credentials.Epoch",
2565
+ number: 0,
2566
+ previousId: void 0,
2567
+ timeframe: new Timeframe(),
2568
+ snapshotCid: void 0
2569
+ }
2570
+ })
2571
+ ];
2572
+ for (const credential of credentials) {
2573
+ await space.controlPipeline.writer.write({
2574
+ credential: {
2575
+ credential
2576
+ }
2577
+ });
2578
+ }
2579
+ return credentials;
2580
+ };
2581
+
2757
2582
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2758
2583
  var __decorate2 = function(decorators, target, key, desc) {
2759
2584
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2766,17 +2591,15 @@ var __decorate2 = function(decorators, target, key, desc) {
2766
2591
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2767
2592
  };
2768
2593
  var DataSpaceManager = class DataSpaceManager2 {
2769
- constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _modelFactory, _feedStore, _snapshotStore) {
2594
+ constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore) {
2770
2595
  this._spaceManager = _spaceManager;
2771
2596
  this._metadataStore = _metadataStore;
2772
2597
  this._dataServiceSubscriptions = _dataServiceSubscriptions;
2773
2598
  this._keyring = _keyring;
2774
2599
  this._signingContext = _signingContext;
2775
- this._modelFactory = _modelFactory;
2776
2600
  this._feedStore = _feedStore;
2777
- this._snapshotStore = _snapshotStore;
2778
2601
  this._ctx = new Context7();
2779
- this.updated = new Event8();
2602
+ this.updated = new Event6();
2780
2603
  this._spaces = new ComplexMap3(PublicKey8.hash);
2781
2604
  this._isOpen = false;
2782
2605
  this._instanceId = PublicKey8.random().toHex();
@@ -2786,49 +2609,48 @@ var DataSpaceManager = class DataSpaceManager2 {
2786
2609
  return this._spaces;
2787
2610
  }
2788
2611
  async open() {
2789
- log11("open", {}, {
2612
+ log10("open", {}, {
2790
2613
  file: "data-space-manager.ts",
2791
- line: 83,
2614
+ line: 80,
2792
2615
  scope: this,
2793
2616
  callSite: (f, a) => f(...a)
2794
2617
  });
2795
- log11.trace("dxos.echo.data-space-manager", trace4.begin({
2796
- id: this._instanceId,
2797
- parentId: this._traceParent
2618
+ log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
2619
+ id: this._instanceId
2798
2620
  }), {
2799
2621
  file: "data-space-manager.ts",
2800
- line: 84,
2622
+ line: 81,
2801
2623
  scope: this,
2802
2624
  callSite: (f, a) => f(...a)
2803
2625
  });
2804
2626
  await this._metadataStore.load();
2805
- log11("metadata loaded", {
2627
+ log10("metadata loaded", {
2806
2628
  spaces: this._metadataStore.spaces.length
2807
2629
  }, {
2808
2630
  file: "data-space-manager.ts",
2809
- line: 86,
2631
+ line: 83,
2810
2632
  scope: this,
2811
2633
  callSite: (f, a) => f(...a)
2812
2634
  });
2813
2635
  for (const spaceMetadata of this._metadataStore.spaces) {
2814
2636
  try {
2815
- log11("load space", {
2637
+ log10("load space", {
2816
2638
  spaceMetadata
2817
2639
  }, {
2818
2640
  file: "data-space-manager.ts",
2819
- line: 90,
2641
+ line: 87,
2820
2642
  scope: this,
2821
2643
  callSite: (f, a) => f(...a)
2822
2644
  });
2823
2645
  const space = await this._constructSpace(spaceMetadata);
2824
2646
  space.initializeDataPipelineAsync();
2825
2647
  } catch (err) {
2826
- log11.error("Error loading space", {
2648
+ log10.error("Error loading space", {
2827
2649
  spaceMetadata,
2828
2650
  err
2829
2651
  }, {
2830
2652
  file: "data-space-manager.ts",
2831
- line: 94,
2653
+ line: 91,
2832
2654
  scope: this,
2833
2655
  callSite: (f, a) => f(...a)
2834
2656
  });
@@ -2836,11 +2658,19 @@ var DataSpaceManager = class DataSpaceManager2 {
2836
2658
  }
2837
2659
  this._isOpen = true;
2838
2660
  this.updated.emit();
2661
+ log10.trace("dxos.echo.data-space-manager.open", trace4.end({
2662
+ id: this._instanceId
2663
+ }), {
2664
+ file: "data-space-manager.ts",
2665
+ line: 97,
2666
+ scope: this,
2667
+ callSite: (f, a) => f(...a)
2668
+ });
2839
2669
  }
2840
2670
  async close() {
2841
- log11("close", {}, {
2671
+ log10("close", {}, {
2842
2672
  file: "data-space-manager.ts",
2843
- line: 104,
2673
+ line: 102,
2844
2674
  scope: this,
2845
2675
  callSite: (f, a) => f(...a)
2846
2676
  });
@@ -2849,20 +2679,12 @@ var DataSpaceManager = class DataSpaceManager2 {
2849
2679
  for (const space of this._spaces.values()) {
2850
2680
  await space.close();
2851
2681
  }
2852
- log11.trace("dxos.echo.data-space-manager", trace4.end({
2853
- id: this._instanceId
2854
- }), {
2855
- file: "data-space-manager.ts",
2856
- line: 110,
2857
- scope: this,
2858
- callSite: (f, a) => f(...a)
2859
- });
2860
2682
  }
2861
2683
  /**
2862
2684
  * Creates a new space writing the genesis credentials to the control feed.
2863
2685
  */
2864
2686
  async createSpace() {
2865
- assert11(this._isOpen, "Not open.");
2687
+ assert10(this._isOpen, "Not open.");
2866
2688
  const spaceKey = await this._keyring.createKey();
2867
2689
  const controlFeedKey = await this._keyring.createKey();
2868
2690
  const dataFeedKey = await this._keyring.createKey();
@@ -2872,11 +2694,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2872
2694
  controlFeedKey,
2873
2695
  dataFeedKey
2874
2696
  };
2875
- log11("creating space...", {
2697
+ log10("creating space...", {
2876
2698
  spaceKey
2877
2699
  }, {
2878
2700
  file: "data-space-manager.ts",
2879
- line: 129,
2701
+ line: 126,
2880
2702
  scope: this,
2881
2703
  callSite: (f, a) => f(...a)
2882
2704
  });
@@ -2884,7 +2706,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2884
2706
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
2885
2707
  await this._metadataStore.addSpace(metadata);
2886
2708
  const memberCredential = credentials[1];
2887
- assert11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2709
+ assert10(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2888
2710
  await this._signingContext.recordCredential(memberCredential);
2889
2711
  await space.initializeDataPipeline();
2890
2712
  this.updated.emit();
@@ -2892,16 +2714,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2892
2714
  }
2893
2715
  // TODO(burdon): Rename join space.
2894
2716
  async acceptSpace(opts) {
2895
- log11("accept space", {
2717
+ log10("accept space", {
2896
2718
  opts
2897
2719
  }, {
2898
2720
  file: "data-space-manager.ts",
2899
- line: 148,
2721
+ line: 145,
2900
2722
  scope: this,
2901
2723
  callSite: (f, a) => f(...a)
2902
2724
  });
2903
- assert11(this._isOpen, "Not open.");
2904
- assert11(!this._spaces.has(opts.spaceKey), "Space already exists.");
2725
+ assert10(this._isOpen, "Not open.");
2726
+ assert10(!this._spaces.has(opts.spaceKey), "Space already exists.");
2905
2727
  const metadata = {
2906
2728
  key: opts.spaceKey,
2907
2729
  genesisFeedKey: opts.genesisFeedKey,
@@ -2920,17 +2742,17 @@ var DataSpaceManager = class DataSpaceManager2 {
2920
2742
  * TODO(dmaretskyi): Consider removing.
2921
2743
  */
2922
2744
  async waitUntilSpaceReady(spaceKey) {
2923
- await cancelWithContext2(this._ctx, this.updated.waitForCondition(() => {
2745
+ await cancelWithContext3(this._ctx, this.updated.waitForCondition(() => {
2924
2746
  const space = this._spaces.get(spaceKey);
2925
2747
  return !!space && space.state === SpaceState2.READY;
2926
2748
  }));
2927
2749
  }
2928
2750
  async _constructSpace(metadata) {
2929
- log11("construct space", {
2751
+ log10("construct space", {
2930
2752
  metadata
2931
2753
  }, {
2932
2754
  file: "data-space-manager.ts",
2933
- line: 184,
2755
+ line: 181,
2934
2756
  scope: this,
2935
2757
  callSite: (f, a) => f(...a)
2936
2758
  });
@@ -2943,7 +2765,6 @@ var DataSpaceManager = class DataSpaceManager2 {
2943
2765
  identityKey: this._signingContext.identityKey,
2944
2766
  gossip
2945
2767
  });
2946
- const snapshotManager = new SnapshotManager(this._snapshotStore);
2947
2768
  const controlFeed = metadata.controlFeedKey && await this._feedStore.openFeed(metadata.controlFeedKey, {
2948
2769
  writable: true
2949
2770
  });
@@ -2961,43 +2782,40 @@ var DataSpaceManager = class DataSpaceManager2 {
2961
2782
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
2962
2783
  remotePeerId: session.remotePeerId
2963
2784
  }));
2964
- session.addExtension("dxos.mesh.teleport.objectsync", snapshotManager.objectSync.createExtension());
2785
+ session.addExtension("dxos.mesh.teleport.objectsync", space.snapshotManager.objectSync.createExtension());
2965
2786
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2966
- }
2787
+ },
2788
+ memberKey: this._signingContext.identityKey
2967
2789
  });
2968
2790
  controlFeed && space.setControlFeed(controlFeed);
2969
2791
  dataFeed && space.setDataFeed(dataFeed);
2970
2792
  const dataSpace = new DataSpace({
2971
2793
  inner: space,
2972
- modelFactory: this._modelFactory,
2973
2794
  metadataStore: this._metadataStore,
2974
- snapshotManager,
2975
2795
  gossip,
2976
2796
  presence,
2977
- memberKey: this._signingContext.identityKey,
2978
2797
  keyring: this._keyring,
2979
2798
  feedStore: this._feedStore,
2980
2799
  signingContext: this._signingContext,
2981
- snapshotId: metadata.snapshot,
2982
2800
  callbacks: {
2983
2801
  beforeReady: async () => {
2984
- log11("before space ready", {
2802
+ log10("before space ready", {
2985
2803
  space: space.key
2986
2804
  }, {
2987
2805
  file: "data-space-manager.ts",
2988
- line: 233,
2806
+ line: 226,
2989
2807
  scope: this,
2990
2808
  callSite: (f, a) => f(...a)
2991
2809
  });
2992
- this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseBackend.createDataServiceHost());
2810
+ this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2993
2811
  },
2994
2812
  afterReady: async () => {
2995
- log11("after space ready", {
2813
+ log10("after space ready", {
2996
2814
  space: space.key,
2997
2815
  open: this._isOpen
2998
2816
  }, {
2999
2817
  file: "data-space-manager.ts",
3000
- line: 240,
2818
+ line: 233,
3001
2819
  scope: this,
3002
2820
  callSite: (f, a) => f(...a)
3003
2821
  });
@@ -3005,182 +2823,490 @@ var DataSpaceManager = class DataSpaceManager2 {
3005
2823
  this.updated.emit();
3006
2824
  }
3007
2825
  }
3008
- }
2826
+ },
2827
+ cache: metadata.cache
3009
2828
  });
3010
2829
  await dataSpace.open();
3011
2830
  if (metadata.controlTimeframe) {
3012
2831
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
3013
2832
  }
3014
- if (metadata.dataTimeframe) {
3015
- dataSpace.dataPipeline.setTargetTimeframe(metadata.dataTimeframe);
2833
+ if (metadata.dataTimeframe) {
2834
+ dataSpace.dataPipeline.setTargetTimeframe(metadata.dataTimeframe);
2835
+ }
2836
+ this._spaces.set(metadata.key, dataSpace);
2837
+ return dataSpace;
2838
+ }
2839
+ };
2840
+ __decorate2([
2841
+ synchronized
2842
+ ], DataSpaceManager.prototype, "open", null);
2843
+ __decorate2([
2844
+ synchronized
2845
+ ], DataSpaceManager.prototype, "close", null);
2846
+ __decorate2([
2847
+ synchronized
2848
+ ], DataSpaceManager.prototype, "createSpace", null);
2849
+ __decorate2([
2850
+ synchronized
2851
+ ], DataSpaceManager.prototype, "acceptSpace", null);
2852
+ DataSpaceManager = __decorate2([
2853
+ trackLeaks2("open", "close")
2854
+ ], DataSpaceManager);
2855
+
2856
+ // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2857
+ import { EventSubscriptions as EventSubscriptions2, scheduleTask as scheduleTask5 } from "@dxos/async";
2858
+ import { Stream as Stream8 } from "@dxos/codec-protobuf";
2859
+ import { raise, todo as todo2 } from "@dxos/debug";
2860
+ import { SpaceNotFoundError } from "@dxos/echo-pipeline";
2861
+ import { log as log11 } from "@dxos/log";
2862
+ import { encodeError } from "@dxos/protocols";
2863
+ import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/client/services";
2864
+ import { humanize } from "@dxos/util";
2865
+ var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
2866
+ var SpacesServiceImpl = class {
2867
+ constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
2868
+ this._identityManager = _identityManager;
2869
+ this._spaceManager = _spaceManager;
2870
+ this._dataServiceSubscriptions = _dataServiceSubscriptions;
2871
+ this._getDataSpaceManager = _getDataSpaceManager;
2872
+ }
2873
+ async createSpace() {
2874
+ if (!this._identityManager.identity) {
2875
+ throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
2876
+ }
2877
+ const dataSpaceManager = await this._getDataSpaceManager();
2878
+ const space = await dataSpaceManager.createSpace();
2879
+ return this._transformSpace(space);
2880
+ }
2881
+ async updateSpace(request) {
2882
+ todo2();
2883
+ }
2884
+ querySpaces() {
2885
+ return new Stream8(({ next, ctx }) => {
2886
+ const onUpdate = async () => {
2887
+ const dataSpaceManager = await this._getDataSpaceManager();
2888
+ const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
2889
+ log11("update", {
2890
+ spaces
2891
+ }, {
2892
+ file: "spaces-service.ts",
2893
+ line: 62,
2894
+ scope: this,
2895
+ callSite: (f, a) => f(...a)
2896
+ });
2897
+ next({
2898
+ spaces
2899
+ });
2900
+ };
2901
+ scheduleTask5(ctx, async () => {
2902
+ const dataSpaceManager = await this._getDataSpaceManager();
2903
+ const subscriptions = new EventSubscriptions2();
2904
+ ctx.onDispose(() => subscriptions.clear());
2905
+ const subscribeSpaces = () => {
2906
+ subscriptions.clear();
2907
+ for (const space of dataSpaceManager.spaces.values()) {
2908
+ subscriptions.add(space.stateUpdate.on(ctx, onUpdate));
2909
+ subscriptions.add(space.presence.updated.on(ctx, onUpdate));
2910
+ space.inner.controlPipeline.state.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate);
2911
+ if (space.dataPipeline.pipelineState) {
2912
+ subscriptions.add(space.dataPipeline.pipelineState.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate));
2913
+ }
2914
+ }
2915
+ };
2916
+ dataSpaceManager.updated.on(ctx, () => {
2917
+ subscribeSpaces();
2918
+ void onUpdate();
2919
+ });
2920
+ subscribeSpaces();
2921
+ void onUpdate();
2922
+ });
2923
+ if (!this._identityManager.identity) {
2924
+ next({
2925
+ spaces: []
2926
+ });
2927
+ }
2928
+ });
2929
+ }
2930
+ async postMessage({ spaceKey, channel, message }) {
2931
+ var _a;
2932
+ const dataSpaceManager = await this._getDataSpaceManager();
2933
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
2934
+ await space.postMessage(getChannelId(channel), message);
2935
+ }
2936
+ subscribeMessages({ spaceKey, channel }) {
2937
+ return new Stream8(({ ctx, next }) => {
2938
+ scheduleTask5(ctx, async () => {
2939
+ var _a;
2940
+ const dataSpaceManager = await this._getDataSpaceManager();
2941
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
2942
+ const handle = space.listen(getChannelId(channel), (message) => {
2943
+ next(message);
2944
+ });
2945
+ ctx.onDispose(() => handle.unsubscribe());
2946
+ });
2947
+ });
2948
+ }
2949
+ queryCredentials({ spaceKey }) {
2950
+ return new Stream8(({ ctx, next }) => {
2951
+ var _a;
2952
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
2953
+ const processor = space.spaceState.registerProcessor({
2954
+ process: async (credential) => {
2955
+ next(credential);
2956
+ }
2957
+ });
2958
+ ctx.onDispose(() => processor.close());
2959
+ scheduleTask5(ctx, () => processor.open());
2960
+ });
2961
+ }
2962
+ async writeCredentials({ spaceKey, credentials }) {
2963
+ var _a;
2964
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
2965
+ for (const credential of credentials != null ? credentials : []) {
2966
+ await space.controlPipeline.writer.write({
2967
+ credential: {
2968
+ credential
2969
+ }
2970
+ });
2971
+ }
2972
+ }
2973
+ async createEpoch({ spaceKey }) {
2974
+ var _a;
2975
+ const dataSpaceManager = await this._getDataSpaceManager();
2976
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
2977
+ await space.createEpoch();
2978
+ }
2979
+ _transformSpace(space) {
2980
+ var _a, _b, _c, _d, _e;
2981
+ return {
2982
+ spaceKey: space.key,
2983
+ state: space.state,
2984
+ error: space.error ? encodeError(space.error) : void 0,
2985
+ pipeline: {
2986
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2987
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2988
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2989
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2990
+ dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2991
+ currentDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.timeframe,
2992
+ targetDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.targetTimeframe,
2993
+ totalDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.endTimeframe
2994
+ },
2995
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2996
+ var _a2, _b2, _c2;
2997
+ return {
2998
+ identity: {
2999
+ identityKey: member.key,
3000
+ profile: {
3001
+ displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : humanize(member.key)
3002
+ }
3003
+ },
3004
+ presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember2.PresenceState.ONLINE : SpaceMember2.PresenceState.OFFLINE
3005
+ };
3006
+ }),
3007
+ cache: space.cache,
3008
+ metrics: space.metrics
3009
+ };
3010
+ }
3011
+ };
3012
+ var getChannelId = (channel) => `user-channel/${channel}`;
3013
+
3014
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
3015
+ import { InvalidConfigError } from "@dxos/errors";
3016
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
3017
+ import { createStorage, StorageType } from "@dxos/random-access-storage";
3018
+ var StorageDriver = Runtime.Client.Storage.StorageDriver;
3019
+ var createStorageObjects = (config) => {
3020
+ const { path = "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
3021
+ if (persistent && storageType === StorageDriver.RAM) {
3022
+ throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
3023
+ }
3024
+ if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
3025
+ throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
3026
+ }
3027
+ if (persistent && keyStorage === StorageDriver.RAM) {
3028
+ throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
3029
+ }
3030
+ if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
3031
+ throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
3032
+ }
3033
+ return {
3034
+ storage: createStorage({
3035
+ type: persistent ? toStorageType(storageType) : StorageType.RAM,
3036
+ root: `${path}/`
3037
+ })
3038
+ };
3039
+ };
3040
+ var toStorageType = (type) => {
3041
+ switch (type) {
3042
+ case void 0:
3043
+ return void 0;
3044
+ case StorageDriver.RAM:
3045
+ return StorageType.RAM;
3046
+ case StorageDriver.CHROME:
3047
+ return StorageType.CHROME;
3048
+ case StorageDriver.FIREFOX:
3049
+ return StorageType.FIREFOX;
3050
+ case StorageDriver.IDB:
3051
+ return StorageType.IDB;
3052
+ case StorageDriver.NODE:
3053
+ return StorageType.NODE;
3054
+ case StorageDriver.WEBFS:
3055
+ return StorageType.WEBFS;
3056
+ default:
3057
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
3058
+ }
3059
+ };
3060
+
3061
+ // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3062
+ import assert11 from "@dxos/node-std/assert";
3063
+ import { Event as Event7 } from "@dxos/async";
3064
+ import { appServiceBundle, shellServiceBundle } from "@dxos/client-protocol";
3065
+ import { ShellLayout } from "@dxos/protocols/proto/dxos/iframe";
3066
+ import { createProtoRpcPeer } from "@dxos/rpc";
3067
+ var ShellRuntimeImpl = class {
3068
+ constructor(_port) {
3069
+ this._port = _port;
3070
+ this.layoutUpdate = new Event7();
3071
+ this._layout = ShellLayout.DEFAULT;
3072
+ }
3073
+ get layout() {
3074
+ return this._layout;
3075
+ }
3076
+ get invitationCode() {
3077
+ return this._invitationCode;
3078
+ }
3079
+ get spaceKey() {
3080
+ return this._spaceKey;
3081
+ }
3082
+ setLayout(layout, options = {}) {
3083
+ this._layout = layout;
3084
+ this._invitationCode = options.invitationCode;
3085
+ this._spaceKey = options.spaceKey;
3086
+ this.layoutUpdate.emit({
3087
+ layout,
3088
+ ...options
3089
+ });
3090
+ }
3091
+ async setAppContext(context) {
3092
+ assert11(this._appRpc, "runtime not open");
3093
+ await this._appRpc.rpc.AppService.setContext(context);
3094
+ }
3095
+ async open() {
3096
+ this._appRpc = createProtoRpcPeer({
3097
+ requested: appServiceBundle,
3098
+ exposed: shellServiceBundle,
3099
+ handlers: {
3100
+ ShellService: {
3101
+ setLayout: async (request) => {
3102
+ this._layout = request.layout;
3103
+ this._invitationCode = request.invitationCode;
3104
+ this._spaceKey = request.spaceKey;
3105
+ this.layoutUpdate.emit(request);
3106
+ }
3107
+ }
3108
+ },
3109
+ port: this._port
3110
+ });
3111
+ await this._appRpc.open();
3112
+ }
3113
+ async close() {
3114
+ var _a;
3115
+ await ((_a = this._appRpc) == null ? void 0 : _a.close());
3116
+ this._appRpc = void 0;
3117
+ }
3118
+ };
3119
+ var MemoryShellRuntime = class {
3120
+ constructor({ layout, invitationCode, spaceKey } = {}) {
3121
+ this.layoutUpdate = new Event7();
3122
+ this.contextUpdate = new Event7();
3123
+ this._layout = layout != null ? layout : ShellLayout.DEFAULT;
3124
+ this._invitationCode = invitationCode;
3125
+ this._spaceKey = spaceKey;
3126
+ }
3127
+ get layout() {
3128
+ return this._layout;
3129
+ }
3130
+ get invitationCode() {
3131
+ return this._invitationCode;
3132
+ }
3133
+ get spaceKey() {
3134
+ return this._spaceKey;
3135
+ }
3136
+ setLayout(layout, options = {}) {
3137
+ this._layout = layout;
3138
+ this._invitationCode = options.invitationCode;
3139
+ this._spaceKey = options.spaceKey;
3140
+ this.layoutUpdate.emit({
3141
+ layout,
3142
+ ...options
3143
+ });
3144
+ }
3145
+ async setAppContext(context) {
3146
+ this.contextUpdate.emit(context);
3147
+ }
3148
+ };
3149
+
3150
+ // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3151
+ import { Trigger as Trigger10 } from "@dxos/async";
3152
+ import { log as log19, logInfo as logInfo3 } from "@dxos/log";
3153
+ import { MemorySignalManager as MemorySignalManager2, MemorySignalManagerContext as MemorySignalManagerContext2, WebsocketSignalManager as WebsocketSignalManager3 } from "@dxos/messaging";
3154
+ import { createWebRTCTransportFactory as createWebRTCTransportFactory2 } from "@dxos/network-manager";
3155
+ import { getAsyncValue as getAsyncValue2 } from "@dxos/util";
3156
+
3157
+ // packages/sdk/client-services/src/packlets/services/service-host.ts
3158
+ import assert14 from "@dxos/node-std/assert";
3159
+ import { Event as Event9 } from "@dxos/async";
3160
+ import { clientServiceBundle, createDefaultModelFactory } from "@dxos/client-protocol";
3161
+ import { DataServiceImpl } from "@dxos/echo-pipeline";
3162
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
3163
+ import { log as log18 } from "@dxos/log";
3164
+ import { WebsocketSignalManager as WebsocketSignalManager2 } from "@dxos/messaging";
3165
+ import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
3166
+ import { trace as trace6 } from "@dxos/protocols";
3167
+ import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
3168
+
3169
+ // packages/sdk/client-services/src/packlets/devices/devices-service.ts
3170
+ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
3171
+ import { Stream as Stream9 } from "@dxos/codec-protobuf";
3172
+ import { DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
3173
+ var DevicesServiceImpl = class {
3174
+ constructor(_identityManager) {
3175
+ this._identityManager = _identityManager;
3176
+ }
3177
+ updateDevice(request) {
3178
+ throw new Error("Method not implemented.");
3179
+ }
3180
+ queryDevices() {
3181
+ return new Stream9(({ next }) => {
3182
+ const update = () => {
3183
+ var _a;
3184
+ const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
3185
+ if (!deviceKeys) {
3186
+ next({
3187
+ devices: []
3188
+ });
3189
+ } else {
3190
+ next({
3191
+ devices: Array.from(deviceKeys.values()).map((key) => {
3192
+ var _a2;
3193
+ return {
3194
+ deviceKey: key,
3195
+ kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
3196
+ };
3197
+ })
3198
+ });
3199
+ }
3200
+ };
3201
+ const subscriptions = new EventSubscriptions3();
3202
+ subscriptions.add(this._identityManager.stateUpdate.on(() => {
3203
+ update();
3204
+ if (this._identityManager.identity) {
3205
+ subscriptions.add(this._identityManager.identity.stateUpdate.on(() => {
3206
+ update();
3207
+ }));
3208
+ }
3209
+ }));
3210
+ update();
3211
+ return () => subscriptions.clear();
3212
+ });
3213
+ }
3214
+ };
3215
+
3216
+ // packages/sdk/client-services/src/packlets/logging/logging-service.ts
3217
+ import { Event as Event8 } from "@dxos/async";
3218
+ import { Stream as Stream10 } from "@dxos/codec-protobuf";
3219
+ import { log as log12, shouldLog } from "@dxos/log";
3220
+ var LoggingServiceImpl = class {
3221
+ constructor() {
3222
+ this._logs = new Event8();
3223
+ this._logProcessor = (_config, entry2) => {
3224
+ this._logs.emit(entry2);
3225
+ };
3226
+ }
3227
+ async open() {
3228
+ log12.runtimeConfig.processors.push(this._logProcessor);
3229
+ }
3230
+ async close() {
3231
+ const index = log12.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
3232
+ log12.runtimeConfig.processors.splice(index, 1);
3233
+ }
3234
+ queryLogs(request) {
3235
+ var _a;
3236
+ const filters = ((_a = request.filters) == null ? void 0 : _a.length) ? request.filters : void 0;
3237
+ return new Stream10(({ ctx, next }) => {
3238
+ const handler = (entry2) => {
3239
+ var _a2;
3240
+ if (((_a2 = entry2.meta) == null ? void 0 : _a2.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3241
+ return;
3242
+ }
3243
+ if (shouldLog(entry2, filters)) {
3244
+ next(jsonify(entry2));
3245
+ }
3246
+ };
3247
+ ctx.onDispose(() => {
3248
+ this._logs.off(handler);
3249
+ });
3250
+ this._logs.on(handler);
3251
+ });
3252
+ }
3253
+ };
3254
+ var jsonify = (value, handles = /* @__PURE__ */ new WeakSet()) => {
3255
+ if (typeof value === "function") {
3256
+ return null;
3257
+ } else if (typeof value === "object" && value !== null) {
3258
+ if (handles.has(value)) {
3259
+ return null;
3260
+ }
3261
+ handles.add(value);
3262
+ if (Array.isArray(value)) {
3263
+ return value.map((x) => jsonify(x, handles));
3264
+ } else {
3265
+ if (typeof value.toJSON === "function") {
3266
+ return value.toJSON();
3267
+ }
3268
+ const res = {};
3269
+ for (const key of Object.keys(value)) {
3270
+ res[key] = jsonify(value[key], handles);
3271
+ }
3272
+ return res;
3016
3273
  }
3017
- this._spaces.set(metadata.key, dataSpace);
3018
- return dataSpace;
3274
+ } else {
3275
+ return value;
3019
3276
  }
3020
3277
  };
3021
- __decorate2([
3022
- synchronized
3023
- ], DataSpaceManager.prototype, "open", null);
3024
- __decorate2([
3025
- synchronized
3026
- ], DataSpaceManager.prototype, "close", null);
3027
- __decorate2([
3028
- synchronized
3029
- ], DataSpaceManager.prototype, "createSpace", null);
3030
- __decorate2([
3031
- synchronized
3032
- ], DataSpaceManager.prototype, "acceptSpace", null);
3033
- DataSpaceManager = __decorate2([
3034
- trackLeaks2("open", "close")
3035
- ], DataSpaceManager);
3036
3278
 
3037
- // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
3038
- import { EventSubscriptions as EventSubscriptions3, scheduleTask as scheduleTask4 } from "@dxos/async";
3279
+ // packages/sdk/client-services/src/packlets/network/network-service.ts
3039
3280
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
3040
- import { raise, todo as todo2 } from "@dxos/debug";
3041
- import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3042
- import { log as log12 } from "@dxos/log";
3043
- import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
3044
- import { humanize } from "@dxos/util";
3045
- var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
3046
- var SpacesServiceImpl = class {
3047
- constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
3048
- this._identityManager = _identityManager;
3049
- this._spaceManager = _spaceManager;
3050
- this._dataServiceSubscriptions = _dataServiceSubscriptions;
3051
- this._getDataSpaceManager = _getDataSpaceManager;
3052
- }
3053
- async createSpace() {
3054
- if (!this._identityManager.identity) {
3055
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
3056
- }
3057
- const dataSpaceManager = await this._getDataSpaceManager();
3058
- const space = await dataSpaceManager.createSpace();
3059
- return this._transformSpace(space);
3060
- }
3061
- async updateSpace(request) {
3062
- todo2();
3281
+ var NetworkServiceImpl = class {
3282
+ constructor(networkManager, signalManager) {
3283
+ this.networkManager = networkManager;
3284
+ this.signalManager = signalManager;
3063
3285
  }
3064
- querySpaces() {
3065
- return new Stream11(({ next, ctx }) => {
3066
- const onUpdate = async () => {
3067
- const dataSpaceManager = await this._getDataSpaceManager();
3068
- const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
3069
- log12("update", {
3070
- spaces
3071
- }, {
3072
- file: "spaces-service.ts",
3073
- line: 60,
3074
- scope: this,
3075
- callSite: (f, a) => f(...a)
3076
- });
3286
+ queryStatus() {
3287
+ return new Stream11(({ next }) => {
3288
+ const update = () => {
3077
3289
  next({
3078
- spaces
3290
+ swarm: this.networkManager.connectionState,
3291
+ signaling: this.signalManager.getStatus().map(({ host, state }) => ({
3292
+ server: host,
3293
+ state
3294
+ }))
3079
3295
  });
3080
3296
  };
3081
- scheduleTask4(ctx, async () => {
3082
- const dataSpaceManager = await this._getDataSpaceManager();
3083
- const subscriptions = new EventSubscriptions3();
3084
- ctx.onDispose(() => subscriptions.clear());
3085
- const subscribeSpaces = () => {
3086
- subscriptions.clear();
3087
- for (const space of dataSpaceManager.spaces.values()) {
3088
- subscriptions.add(space.stateUpdate.on(ctx, onUpdate));
3089
- subscriptions.add(space.presence.updated.on(ctx, onUpdate));
3090
- space.inner.controlPipeline.state.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate);
3091
- if (space.dataPipeline.pipelineState) {
3092
- subscriptions.add(space.dataPipeline.pipelineState.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate));
3093
- }
3094
- }
3095
- };
3096
- dataSpaceManager.updated.on(ctx, () => {
3097
- subscribeSpaces();
3098
- void onUpdate();
3099
- });
3100
- subscribeSpaces();
3101
- void onUpdate();
3102
- });
3103
- if (!this._identityManager.identity) {
3104
- next({
3105
- spaces: []
3106
- });
3107
- }
3108
- });
3109
- }
3110
- async postMessage({ spaceKey, channel, message }) {
3111
- var _a;
3112
- const dataSpaceManager = await this._getDataSpaceManager();
3113
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3114
- await space.postMessage(getChannelId(channel), message);
3115
- }
3116
- subscribeMessages({ spaceKey, channel }) {
3117
- return new Stream11(({ ctx, next }) => {
3118
- scheduleTask4(ctx, async () => {
3119
- var _a;
3120
- const dataSpaceManager = await this._getDataSpaceManager();
3121
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3122
- const handle = space.listen(getChannelId(channel), (message) => {
3123
- next(message);
3124
- });
3125
- ctx.onDispose(() => handle.unsubscribe());
3126
- });
3127
- });
3128
- }
3129
- queryCredentials({ spaceKey }) {
3130
- return new Stream11(({ ctx, next }) => {
3131
- var _a;
3132
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3133
- const processor = space.spaceState.registerProcessor({
3134
- process: async (credential) => {
3135
- next(credential);
3136
- }
3137
- });
3138
- ctx.onDispose(() => processor.close());
3139
- scheduleTask4(ctx, () => processor.open());
3297
+ const unsubscribeSwarm = this.networkManager.connectionStateChanged.on(() => update());
3298
+ const unsubscribeSignal = this.signalManager.statusChanged.on(() => update());
3299
+ update();
3300
+ return () => {
3301
+ unsubscribeSwarm();
3302
+ unsubscribeSignal();
3303
+ };
3140
3304
  });
3141
3305
  }
3142
- async writeCredentials({ spaceKey, credentials }) {
3143
- var _a;
3144
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3145
- for (const credential of credentials != null ? credentials : []) {
3146
- await space.controlPipeline.writer.write({
3147
- credential: {
3148
- credential
3149
- }
3150
- });
3151
- }
3152
- }
3153
- _transformSpace(space) {
3154
- var _a, _b, _c, _d, _e;
3155
- return {
3156
- spaceKey: space.key,
3157
- state: space.state,
3158
- pipeline: {
3159
- controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
3160
- currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3161
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3162
- totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3163
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3164
- currentDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.timeframe,
3165
- targetDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.targetTimeframe,
3166
- totalDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.endTimeframe
3167
- },
3168
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3169
- var _a2, _b2, _c2;
3170
- return {
3171
- identity: {
3172
- identityKey: member.key,
3173
- profile: {
3174
- displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : humanize(member.key)
3175
- }
3176
- },
3177
- presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
3178
- };
3179
- })
3180
- };
3306
+ async updateConfig(request) {
3307
+ await this.networkManager.setConnectionState(request.swarm);
3181
3308
  }
3182
3309
  };
3183
- var getChannelId = (channel) => `user-channel/${channel}`;
3184
3310
 
3185
3311
  // packages/sdk/client-services/src/packlets/system/system-service.ts
3186
3312
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
@@ -3221,7 +3347,8 @@ var SystemServiceImpl = class {
3221
3347
  };
3222
3348
 
3223
3349
  // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3224
- import { iframeServiceBundle, workerServiceBundle } from "@dxos/client";
3350
+ import { Trigger as Trigger5 } from "@dxos/async";
3351
+ import { iframeServiceBundle, workerServiceBundle } from "@dxos/client-protocol";
3225
3352
  import { RemoteServiceConnectionError } from "@dxos/errors";
3226
3353
  import { log as log13 } from "@dxos/log";
3227
3354
  import { WebRTCTransportService } from "@dxos/network-manager";
@@ -3229,6 +3356,8 @@ import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
3229
3356
  import { getAsyncValue } from "@dxos/util";
3230
3357
  var IFrameProxyRuntime = class {
3231
3358
  constructor({ config, systemPort, shellPort }) {
3359
+ this._id = String(Math.floor(Math.random() * 1e6));
3360
+ this._release = new Trigger5();
3232
3361
  this._configProvider = config;
3233
3362
  this._systemPort = systemPort;
3234
3363
  this._shellPort = shellPort;
@@ -3249,24 +3378,32 @@ var IFrameProxyRuntime = class {
3249
3378
  requested: workerServiceBundle,
3250
3379
  exposed: iframeServiceBundle,
3251
3380
  handlers: {
3252
- BridgeService: this._transportService,
3253
- IframeService: {
3254
- async heartbeat() {
3255
- }
3256
- }
3381
+ BridgeService: this._transportService
3257
3382
  },
3258
3383
  port: this._systemPort,
3259
3384
  timeout: 200
3260
3385
  });
3386
+ let lockKey;
3387
+ if (typeof navigator !== "undefined") {
3388
+ lockKey = this._lockKey(origin);
3389
+ this._release = new Trigger5();
3390
+ const ready = new Trigger5();
3391
+ void navigator.locks.request(lockKey, async () => {
3392
+ ready.wake();
3393
+ await this._release.wait();
3394
+ });
3395
+ await ready.wait();
3396
+ }
3261
3397
  try {
3262
3398
  await this._systemRpc.open();
3263
3399
  await this._systemRpc.rpc.WorkerService.start({
3264
- origin
3400
+ origin,
3401
+ lockKey
3265
3402
  });
3266
3403
  } catch (err) {
3267
3404
  log13.catch(err, {}, {
3268
3405
  file: "iframe-proxy-runtime.ts",
3269
- line: 74,
3406
+ line: 85,
3270
3407
  scope: this,
3271
3408
  callSite: (f, a) => f(...a)
3272
3409
  });
@@ -3276,14 +3413,18 @@ var IFrameProxyRuntime = class {
3276
3413
  }
3277
3414
  async close() {
3278
3415
  var _a;
3416
+ this._release.wake();
3279
3417
  await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3280
3418
  await this._systemRpc.rpc.WorkerService.stop();
3281
3419
  await this._systemRpc.close();
3282
3420
  }
3421
+ _lockKey(origin) {
3422
+ return `${origin}-${this._id}`;
3423
+ }
3283
3424
  };
3284
3425
 
3285
3426
  // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3286
- import { asyncTimeout, Trigger as Trigger5 } from "@dxos/async";
3427
+ import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3287
3428
  import { log as log14, logInfo } from "@dxos/log";
3288
3429
  var __decorate3 = function(decorators, target, key, desc) {
3289
3430
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3302,7 +3443,7 @@ var Message;
3302
3443
  var VaultResourceLock = class {
3303
3444
  constructor({ lockKey, onAcquire, onRelease }) {
3304
3445
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3305
- this._releaseTrigger = new Trigger5();
3446
+ this._releaseTrigger = new Trigger6();
3306
3447
  this._lockKey = lockKey;
3307
3448
  this._onAcquire = onAcquire;
3308
3449
  this._onRelease = onRelease;
@@ -3362,14 +3503,14 @@ var VaultResourceLock = class {
3362
3503
  scope: this,
3363
3504
  callSite: (f, a) => f(...a)
3364
3505
  });
3365
- const acquired = new Trigger5();
3506
+ const acquired = new Trigger6();
3366
3507
  void navigator.locks.request(this._lockKey, {
3367
3508
  steal
3368
3509
  }, async () => {
3369
3510
  var _a, _b;
3370
3511
  await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3371
3512
  acquired.wake();
3372
- this._releaseTrigger = new Trigger5();
3513
+ this._releaseTrigger = new Trigger6();
3373
3514
  await this._releaseTrigger.wait();
3374
3515
  log14("releasing lock...", {}, {
3375
3516
  file: "vault-resource-lock.ts",
@@ -3404,15 +3545,15 @@ __decorate3([
3404
3545
  ], VaultResourceLock.prototype, "lockKey", null);
3405
3546
 
3406
3547
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3407
- import { Trigger as Trigger7 } from "@dxos/async";
3548
+ import { Trigger as Trigger8 } from "@dxos/async";
3408
3549
  import { log as log16 } from "@dxos/log";
3409
3550
  import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
3410
- import { NetworkManager, WebRTCTransportProxyFactory } from "@dxos/network-manager";
3551
+ import { WebRTCTransportProxyFactory } from "@dxos/network-manager";
3411
3552
 
3412
3553
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3413
3554
  import assert12 from "@dxos/node-std/assert";
3414
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
3415
- import { iframeServiceBundle as iframeServiceBundle2, workerServiceBundle as workerServiceBundle2 } from "@dxos/client";
3555
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger7 } from "@dxos/async";
3556
+ import { iframeServiceBundle as iframeServiceBundle2, workerServiceBundle as workerServiceBundle2 } from "@dxos/client-protocol";
3416
3557
  import { log as log15, logInfo as logInfo2 } from "@dxos/log";
3417
3558
  import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
3418
3559
  import { Callback } from "@dxos/util";
@@ -3482,14 +3623,10 @@ var __decorate4 = function(decorators, target, key, desc) {
3482
3623
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3483
3624
  };
3484
3625
  var WorkerSession = class {
3485
- constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
3486
- heartbeatInterval: 1e3
3487
- } }) {
3488
- this._startTrigger = new Trigger6();
3626
+ constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }) {
3627
+ this._startTrigger = new Trigger7();
3489
3628
  this.onClose = new Callback();
3490
- assert12(options);
3491
3629
  assert12(serviceHost);
3492
- this._options = options;
3493
3630
  this._serviceHost = serviceHost;
3494
3631
  const middleware = {
3495
3632
  handleCall: async (method, params, handler) => {
@@ -3528,6 +3665,7 @@ var WorkerSession = class {
3528
3665
  WorkerService: {
3529
3666
  start: async (request) => {
3530
3667
  this.origin = request.origin;
3668
+ this.lockKey = request.lockKey;
3531
3669
  this._startTrigger.wake();
3532
3670
  },
3533
3671
  stop: async () => {
@@ -3537,7 +3675,7 @@ var WorkerSession = class {
3537
3675
  } catch (err) {
3538
3676
  log15.catch(err, {}, {
3539
3677
  file: "worker-session.ts",
3540
- line: 107,
3678
+ line: 95,
3541
3679
  scope: this,
3542
3680
  callSite: (f, a) => f(...a)
3543
3681
  });
@@ -3548,14 +3686,13 @@ var WorkerSession = class {
3548
3686
  },
3549
3687
  port: systemPort,
3550
3688
  timeout: 1e3
3551
- // With low timeout heartbeat may fail if the tab's thread is saturated.
3552
3689
  });
3553
3690
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
3554
3691
  }
3555
3692
  async open() {
3556
3693
  log15.info("opening..", {}, {
3557
3694
  file: "worker-session.ts",
3558
- line: 121,
3695
+ line: 109,
3559
3696
  scope: this,
3560
3697
  callSite: (f, a) => f(...a)
3561
3698
  });
@@ -3567,35 +3704,14 @@ var WorkerSession = class {
3567
3704
  await this._startTrigger.wait({
3568
3705
  timeout: 3e3
3569
3706
  });
3570
- this._heartbeatTimer = setInterval(async () => {
3571
- try {
3572
- await this._iframeRpc.rpc.IframeService.heartbeat();
3573
- } catch (err1) {
3574
- log15.warn("Heartbeat failed", {
3575
- err: err1
3576
- }, {
3577
- file: "worker-session.ts",
3578
- line: 133,
3579
- scope: this,
3580
- callSite: (f, a) => f(...a)
3581
- });
3582
- try {
3583
- await this.close();
3584
- } catch (err) {
3585
- log15.catch(err, {}, {
3586
- file: "worker-session.ts",
3587
- line: 137,
3588
- scope: this,
3589
- callSite: (f, a) => f(...a)
3590
- });
3591
- }
3592
- }
3593
- }, this._options.heartbeatInterval);
3707
+ if (this.lockKey) {
3708
+ void this._afterLockReleases(this.lockKey, () => this.close());
3709
+ }
3594
3710
  }
3595
3711
  async close() {
3596
3712
  log15.info("closing..", {}, {
3597
3713
  file: "worker-session.ts",
3598
- line: 144,
3714
+ line: 119,
3599
3715
  scope: this,
3600
3716
  callSite: (f, a) => f(...a)
3601
3717
  });
@@ -3604,14 +3720,11 @@ var WorkerSession = class {
3604
3720
  } catch (err) {
3605
3721
  log15.catch(err, {}, {
3606
3722
  file: "worker-session.ts",
3607
- line: 148,
3723
+ line: 123,
3608
3724
  scope: this,
3609
3725
  callSite: (f, a) => f(...a)
3610
3726
  });
3611
3727
  }
3612
- if (this._heartbeatTimer !== void 0) {
3613
- clearInterval(this._heartbeatTimer);
3614
- }
3615
3728
  await Promise.all([
3616
3729
  this._clientRpc.close(),
3617
3730
  this._iframeRpc.close()
@@ -3623,16 +3736,23 @@ var WorkerSession = class {
3623
3736
  } catch (e) {
3624
3737
  log15.info("No shell connected.", {}, {
3625
3738
  file: "worker-session.ts",
3626
- line: 162,
3739
+ line: 133,
3627
3740
  scope: this,
3628
3741
  callSite: (f, a) => f(...a)
3629
3742
  });
3630
3743
  }
3631
3744
  }
3745
+ _afterLockReleases(lockKey, callback) {
3746
+ return navigator.locks.request(lockKey, () => {
3747
+ }).then(callback);
3748
+ }
3632
3749
  };
3633
3750
  __decorate4([
3634
3751
  logInfo2
3635
3752
  ], WorkerSession.prototype, "origin", void 0);
3753
+ __decorate4([
3754
+ logInfo2
3755
+ ], WorkerSession.prototype, "lockKey", void 0);
3636
3756
 
3637
3757
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3638
3758
  var WorkerRuntime = class {
@@ -3640,7 +3760,7 @@ var WorkerRuntime = class {
3640
3760
  constructor(_configProvider) {
3641
3761
  this._configProvider = _configProvider;
3642
3762
  this._transportFactory = new WebRTCTransportProxyFactory();
3643
- this._ready = new Trigger7();
3763
+ this._ready = new Trigger8();
3644
3764
  this.sessions = /* @__PURE__ */ new Set();
3645
3765
  this._clientServices = new ClientServicesHost();
3646
3766
  }
@@ -3659,17 +3779,14 @@ var WorkerRuntime = class {
3659
3779
  const signals = this._config.get("runtime.services.signaling");
3660
3780
  this._clientServices.initialize({
3661
3781
  config: this._config,
3662
- networkManager: new NetworkManager({
3663
- log: true,
3664
- signalManager: signals ? new WebsocketSignalManager(signals) : new MemorySignalManager(new MemorySignalManagerContext()),
3665
- transportFactory: this._transportFactory
3666
- })
3782
+ signalManager: signals ? new WebsocketSignalManager(signals) : new MemorySignalManager(new MemorySignalManagerContext()),
3783
+ transportFactory: this._transportFactory
3667
3784
  });
3668
3785
  await this._clientServices.open();
3669
3786
  this._ready.wake(void 0);
3670
3787
  log16("started", {}, {
3671
3788
  file: "worker-runtime.ts",
3672
- line: 65,
3789
+ line: 62,
3673
3790
  scope: this,
3674
3791
  callSite: (f, a) => f(...a)
3675
3792
  });
@@ -3677,7 +3794,7 @@ var WorkerRuntime = class {
3677
3794
  this._ready.wake(err);
3678
3795
  log16.catch(err, {}, {
3679
3796
  file: "worker-runtime.ts",
3680
- line: 68,
3797
+ line: 65,
3681
3798
  scope: this,
3682
3799
  callSite: (f, a) => f(...a)
3683
3800
  });
@@ -3709,6 +3826,12 @@ var WorkerRuntime = class {
3709
3826
  * Selects one of the existing session fro WebRTC networking.
3710
3827
  */
3711
3828
  _reconnectWebrtc() {
3829
+ log16("reconnecting webrtc...", {}, {
3830
+ file: "worker-runtime.ts",
3831
+ line: 102,
3832
+ scope: this,
3833
+ callSite: (f, a) => f(...a)
3834
+ });
3712
3835
  if (this._sessionForNetworking) {
3713
3836
  if (!this.sessions.has(this._sessionForNetworking)) {
3714
3837
  this._sessionForNetworking = void 0;
@@ -3728,27 +3851,27 @@ var WorkerRuntime = class {
3728
3851
 
3729
3852
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3730
3853
  import assert13 from "@dxos/node-std/assert";
3731
- import { Trigger as Trigger8 } from "@dxos/async";
3732
- import { Invitation as Invitation4 } from "@dxos/client";
3854
+ import { Trigger as Trigger9 } from "@dxos/async";
3733
3855
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3734
- import { failUndefined as failUndefined2 } from "@dxos/debug";
3856
+ import { failUndefined as failUndefined3 } from "@dxos/debug";
3735
3857
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3736
3858
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3737
3859
  import { Keyring } from "@dxos/keyring";
3738
3860
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3739
3861
  import { log as log17 } from "@dxos/log";
3740
3862
  import { trace as trace5 } from "@dxos/protocols";
3863
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
3741
3864
  var ServiceContext = class {
3742
3865
  // prettier-ignore
3743
- constructor(storage, networkManager, modelFactory) {
3866
+ constructor(storage, networkManager, signalManager, modelFactory) {
3744
3867
  this.storage = storage;
3745
3868
  this.networkManager = networkManager;
3869
+ this.signalManager = signalManager;
3746
3870
  this.modelFactory = modelFactory;
3747
- this.initialized = new Trigger8();
3871
+ this.initialized = new Trigger9();
3748
3872
  this.dataServiceSubscriptions = new DataServiceSubscriptions();
3749
3873
  this._handlerFactories = /* @__PURE__ */ new Map();
3750
3874
  this._instanceId = PublicKey9.random().toHex();
3751
- networkManager._traceParent = this._instanceId;
3752
3875
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
3753
3876
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
3754
3877
  this.keyring = new Keyring(storage.createDirectory("keyring"));
@@ -3763,33 +3886,34 @@ var ServiceContext = class {
3763
3886
  });
3764
3887
  this.spaceManager = new SpaceManager({
3765
3888
  feedStore: this.feedStore,
3766
- networkManager: this.networkManager
3889
+ networkManager: this.networkManager,
3890
+ metadataStore: this.metadataStore,
3891
+ modelFactory: this.modelFactory,
3892
+ snapshotStore: this.snapshotStore
3767
3893
  });
3768
- this.spaceManager._traceParent = this._instanceId;
3769
3894
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3770
- this.identityManager._traceParent = this._instanceId;
3771
3895
  this.invitations = new InvitationsHandler(this.networkManager);
3772
- this.invitations._traceParent = this._instanceId;
3773
3896
  this._handlerFactories.set(Invitation4.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3774
3897
  var _a;
3775
- return (_a = this.identityManager.identity) != null ? _a : failUndefined2();
3898
+ return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3776
3899
  }, this._acceptIdentity.bind(this)));
3777
3900
  }
3778
3901
  async open() {
3779
- log17.trace("dxos.sdk.service-context", trace5.begin({
3902
+ log17.trace("dxos.sdk.service-context.open", trace5.begin({
3780
3903
  id: this._instanceId
3781
3904
  }), {
3782
3905
  file: "service-context.ts",
3783
- line: 115,
3906
+ line: 119,
3784
3907
  scope: this,
3785
3908
  callSite: (f, a) => f(...a)
3786
3909
  });
3787
3910
  log17("opening...", {}, {
3788
3911
  file: "service-context.ts",
3789
- line: 117,
3912
+ line: 121,
3790
3913
  scope: this,
3791
3914
  callSite: (f, a) => f(...a)
3792
3915
  });
3916
+ await this.signalManager.open();
3793
3917
  await this.networkManager.open();
3794
3918
  await this.spaceManager.open();
3795
3919
  await this.identityManager.open();
@@ -3798,7 +3922,15 @@ var ServiceContext = class {
3798
3922
  }
3799
3923
  log17("opened", {}, {
3800
3924
  file: "service-context.ts",
3801
- line: 124,
3925
+ line: 129,
3926
+ scope: this,
3927
+ callSite: (f, a) => f(...a)
3928
+ });
3929
+ log17.trace("dxos.sdk.service-context.open", trace5.end({
3930
+ id: this._instanceId
3931
+ }), {
3932
+ file: "service-context.ts",
3933
+ line: 130,
3802
3934
  scope: this,
3803
3935
  callSite: (f, a) => f(...a)
3804
3936
  });
@@ -3807,7 +3939,7 @@ var ServiceContext = class {
3807
3939
  var _a, _b;
3808
3940
  log17("closing...", {}, {
3809
3941
  file: "service-context.ts",
3810
- line: 128,
3942
+ line: 134,
3811
3943
  scope: this,
3812
3944
  callSite: (f, a) => f(...a)
3813
3945
  });
@@ -3817,18 +3949,11 @@ var ServiceContext = class {
3817
3949
  await this.spaceManager.close();
3818
3950
  await this.feedStore.close();
3819
3951
  await this.networkManager.close();
3952
+ await this.signalManager.close();
3820
3953
  this.dataServiceSubscriptions.clear();
3821
3954
  log17("closed", {}, {
3822
3955
  file: "service-context.ts",
3823
- line: 136,
3824
- scope: this,
3825
- callSite: (f, a) => f(...a)
3826
- });
3827
- log17.trace("dxos.sdk.service-context", trace5.end({
3828
- id: this._instanceId
3829
- }), {
3830
- file: "service-context.ts",
3831
- line: 138,
3956
+ line: 143,
3832
3957
  scope: this,
3833
3958
  callSite: (f, a) => f(...a)
3834
3959
  });
@@ -3853,11 +3978,11 @@ var ServiceContext = class {
3853
3978
  var _a;
3854
3979
  log17("initializing spaces...", {}, {
3855
3980
  file: "service-context.ts",
3856
- line: 163,
3981
+ line: 168,
3857
3982
  scope: this,
3858
3983
  callSite: (f, a) => f(...a)
3859
3984
  });
3860
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined2();
3985
+ const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3861
3986
  const signingContext = {
3862
3987
  credentialSigner: identity.getIdentityCredentialSigner(),
3863
3988
  identityKey: identity.identityKey,
@@ -3871,8 +3996,7 @@ var ServiceContext = class {
3871
3996
  });
3872
3997
  }
3873
3998
  };
3874
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.feedStore, this.snapshotStore);
3875
- this.dataSpaceManager._traceParent = this._instanceId;
3999
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
3876
4000
  await this.dataSpaceManager.open();
3877
4001
  this._handlerFactories.set(Invitation4.Kind.SPACE, (invitation) => {
3878
4002
  assert13(this.dataSpaceManager, "dataSpaceManager not initialized yet");
@@ -3893,7 +4017,7 @@ var ServiceContext = class {
3893
4017
  details: assertion
3894
4018
  }, {
3895
4019
  file: "service-context.ts",
3896
- line: 205,
4020
+ line: 207,
3897
4021
  scope: this,
3898
4022
  callSite: (f, a) => f(...a)
3899
4023
  });
@@ -3904,7 +4028,7 @@ var ServiceContext = class {
3904
4028
  details: assertion
3905
4029
  }, {
3906
4030
  file: "service-context.ts",
3907
- line: 209,
4031
+ line: 211,
3908
4032
  scope: this,
3909
4033
  callSite: (f, a) => f(...a)
3910
4034
  });
@@ -3915,7 +4039,7 @@ var ServiceContext = class {
3915
4039
  details: assertion
3916
4040
  }, {
3917
4041
  file: "service-context.ts",
3918
- line: 214,
4042
+ line: 216,
3919
4043
  scope: this,
3920
4044
  callSite: (f, a) => f(...a)
3921
4045
  });
@@ -3926,7 +4050,7 @@ var ServiceContext = class {
3926
4050
  } catch (err) {
3927
4051
  log17.catch(err, {}, {
3928
4052
  file: "service-context.ts",
3929
- line: 220,
4053
+ line: 222,
3930
4054
  scope: this,
3931
4055
  callSite: (f, a) => f(...a)
3932
4056
  });
@@ -3967,7 +4091,9 @@ var ClientServicesHost = class {
3967
4091
  config,
3968
4092
  modelFactory = createDefaultModelFactory(),
3969
4093
  // TODO(burdon): Create ApolloLink abstraction (see Client).
3970
- networkManager,
4094
+ transportFactory,
4095
+ signalManager,
4096
+ connectionLog,
3971
4097
  storage,
3972
4098
  // TODO(wittjosiah): Turn this on by default.
3973
4099
  lockKey
@@ -3975,19 +4101,21 @@ var ClientServicesHost = class {
3975
4101
  this._statusUpdate = new Event9();
3976
4102
  this._opening = false;
3977
4103
  this._open = false;
3978
- this._instanceId = PublicKey10.random().toHex();
3979
4104
  this._storage = storage;
3980
4105
  this._modelFactory = modelFactory;
3981
4106
  if (config) {
3982
4107
  this.initialize({
3983
4108
  config,
3984
- networkManager
4109
+ transportFactory,
4110
+ signalManager
3985
4111
  });
3986
4112
  }
3987
4113
  this._resourceLock = lockKey ? new VaultResourceLock({
3988
4114
  lockKey,
3989
4115
  onAcquire: () => {
3990
- this._opening || this.open();
4116
+ if (!this._opening) {
4117
+ void this.open();
4118
+ }
3991
4119
  },
3992
4120
  onRelease: () => this.close()
3993
4121
  }) : void 0;
@@ -4029,7 +4157,8 @@ var ClientServicesHost = class {
4029
4157
  * Config can also be provided in the constructor.
4030
4158
  * Can only be called once.
4031
4159
  */
4032
- initialize({ config, networkManager }) {
4160
+ initialize({ config, ...options }) {
4161
+ var _a, _b, _c;
4033
4162
  assert14(!this._open, "service host is open");
4034
4163
  if (config) {
4035
4164
  assert14(!this._config, "config already set");
@@ -4038,39 +4167,47 @@ var ClientServicesHost = class {
4038
4167
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
4039
4168
  }
4040
4169
  }
4041
- if (networkManager) {
4042
- assert14(!this._networkManager, "network manager already set");
4043
- this._networkManager = networkManager;
4044
- }
4170
+ const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4171
+ iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4172
+ }), signalManager = new WebsocketSignalManager2((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4173
+ this._signalManager = signalManager;
4174
+ assert14(!this._networkManager, "network manager already set");
4175
+ this._networkManager = new NetworkManager({
4176
+ log: connectionLog,
4177
+ transportFactory,
4178
+ signalManager
4179
+ });
4045
4180
  }
4046
4181
  async open() {
4047
4182
  var _a, _b, _c;
4048
4183
  if (this._open) {
4049
4184
  return;
4050
4185
  }
4051
- log18.trace("dxos.sdk.client-services-host", trace6.begin({
4052
- id: this._instanceId
4186
+ const traceId = PublicKey10.random().toHex();
4187
+ log18.trace("dxos.sdk.client-services-host.open", trace6.begin({
4188
+ id: traceId
4053
4189
  }), {
4054
4190
  file: "service-host.ts",
4055
- line: 169,
4191
+ line: 186,
4056
4192
  scope: this,
4057
4193
  callSite: (f, a) => f(...a)
4058
4194
  });
4059
4195
  assert14(this._config, "config not set");
4060
4196
  assert14(this._storage, "storage not set");
4197
+ assert14(this._signalManager, "signal manager not set");
4061
4198
  assert14(this._networkManager, "network manager not set");
4062
4199
  this._opening = true;
4063
4200
  log18("opening...", {
4064
4201
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4065
4202
  }, {
4066
4203
  file: "service-host.ts",
4067
- line: 176,
4204
+ line: 194,
4068
4205
  scope: this,
4069
4206
  callSite: (f, a) => f(...a)
4070
4207
  });
4071
4208
  await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4072
4209
  await this._loggingService.open();
4073
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._modelFactory);
4210
+ this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4074
4211
  this._serviceRegistry.setServices({
4075
4212
  SystemService: this._systemService,
4076
4213
  IdentityService: new IdentityServiceImpl(this._serviceContext),
@@ -4081,7 +4218,7 @@ var ClientServicesHost = class {
4081
4218
  return this._serviceContext.dataSpaceManager;
4082
4219
  }),
4083
4220
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4084
- NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager),
4221
+ NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
4085
4222
  LoggingService: this._loggingService,
4086
4223
  // TODO(burdon): Move to new protobuf definitions.
4087
4224
  DevtoolsHost: new DevtoolsServiceImpl({
@@ -4099,7 +4236,15 @@ var ClientServicesHost = class {
4099
4236
  deviceKey
4100
4237
  }, {
4101
4238
  file: "service-host.ts",
4102
- line: 226,
4239
+ line: 249,
4240
+ scope: this,
4241
+ callSite: (f, a) => f(...a)
4242
+ });
4243
+ log18.trace("dxos.sdk.client-services-host.open", trace6.end({
4244
+ id: traceId
4245
+ }), {
4246
+ file: "service-host.ts",
4247
+ line: 250,
4103
4248
  scope: this,
4104
4249
  callSite: (f, a) => f(...a)
4105
4250
  });
@@ -4114,7 +4259,7 @@ var ClientServicesHost = class {
4114
4259
  deviceKey
4115
4260
  }, {
4116
4261
  file: "service-host.ts",
4117
- line: 235,
4262
+ line: 259,
4118
4263
  scope: this,
4119
4264
  callSite: (f, a) => f(...a)
4120
4265
  });
@@ -4129,24 +4274,25 @@ var ClientServicesHost = class {
4129
4274
  deviceKey
4130
4275
  }, {
4131
4276
  file: "service-host.ts",
4132
- line: 241,
4277
+ line: 265,
4133
4278
  scope: this,
4134
4279
  callSite: (f, a) => f(...a)
4135
4280
  });
4136
- log18.trace("dxos.sdk.client-services-host", trace6.end({
4137
- id: this._instanceId
4281
+ }
4282
+ async reset() {
4283
+ var _a;
4284
+ const traceId = PublicKey10.random().toHex();
4285
+ log18.trace("dxos.sdk.client-services-host.reset", trace6.begin({
4286
+ id: traceId
4138
4287
  }), {
4139
4288
  file: "service-host.ts",
4140
- line: 243,
4289
+ line: 270,
4141
4290
  scope: this,
4142
4291
  callSite: (f, a) => f(...a)
4143
4292
  });
4144
- }
4145
- async reset() {
4146
- var _a;
4147
4293
  log18("resetting...", {}, {
4148
4294
  file: "service-host.ts",
4149
- line: 247,
4295
+ line: 272,
4150
4296
  scope: this,
4151
4297
  callSite: (f, a) => f(...a)
4152
4298
  });
@@ -4154,7 +4300,15 @@ var ClientServicesHost = class {
4154
4300
  await this._storage.reset();
4155
4301
  log18("reset", {}, {
4156
4302
  file: "service-host.ts",
4157
- line: 250,
4303
+ line: 275,
4304
+ scope: this,
4305
+ callSite: (f, a) => f(...a)
4306
+ });
4307
+ log18.trace("dxos.sdk.client-services-host.reset", trace6.end({
4308
+ id: traceId
4309
+ }), {
4310
+ file: "service-host.ts",
4311
+ line: 276,
4158
4312
  scope: this,
4159
4313
  callSite: (f, a) => f(...a)
4160
4314
  });
@@ -4183,41 +4337,6 @@ var LocalClientServices = class {
4183
4337
  }
4184
4338
  };
4185
4339
 
4186
- // packages/sdk/client-services/src/packlets/services/utils.ts
4187
- import { Config } from "@dxos/config";
4188
- import { log as log19 } from "@dxos/log";
4189
- import { MemorySignalManager as MemorySignalManager2, MemorySignalManagerContext as MemorySignalManagerContext2, WebsocketSignalManager as WebsocketSignalManager2 } from "@dxos/messaging";
4190
- import { createWebRTCTransportFactory, MemoryTransportFactory, NetworkManager as NetworkManager2 } from "@dxos/network-manager";
4191
- var fromHost = (config = new Config()) => {
4192
- return new LocalClientServices({
4193
- config,
4194
- networkManager: createNetworkManager(config)
4195
- });
4196
- };
4197
- var createNetworkManager = (config, options = {}) => {
4198
- const signals = config.get("runtime.services.signaling");
4199
- if (signals) {
4200
- const { log: log1 = true, signalManager = new WebsocketSignalManager2(signals), transportFactory = createWebRTCTransportFactory({
4201
- iceServers: config.get("runtime.services.ice")
4202
- }) } = options;
4203
- return new NetworkManager2({
4204
- log: log1,
4205
- signalManager,
4206
- transportFactory
4207
- });
4208
- }
4209
- log19.warn("P2P network is not configured.", {}, {
4210
- file: "utils.ts",
4211
- line: 48,
4212
- scope: void 0,
4213
- callSite: (f, a) => f(...a)
4214
- });
4215
- return new NetworkManager2({
4216
- signalManager: new MemorySignalManager2(new MemorySignalManagerContext2()),
4217
- transportFactory: MemoryTransportFactory
4218
- });
4219
- };
4220
-
4221
4340
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
4222
4341
  var __decorate5 = function(decorators, target, key, desc) {
4223
4342
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -4232,7 +4351,7 @@ var __decorate5 = function(decorators, target, key, desc) {
4232
4351
  var LOCK_KEY = "DXOS_RESOURCE_LOCK";
4233
4352
  var IFrameHostRuntime = class {
4234
4353
  constructor({ config, origin, appPort, shellPort }) {
4235
- this._ready = new Trigger9();
4354
+ this._ready = new Trigger10();
4236
4355
  this._configProvider = config;
4237
4356
  this.origin = origin;
4238
4357
  this._appPort = appPort;
@@ -4249,7 +4368,7 @@ var IFrameHostRuntime = class {
4249
4368
  }
4250
4369
  async start() {
4251
4370
  var _a;
4252
- log20("starting...", {}, {
4371
+ log19("starting...", {}, {
4253
4372
  file: "iframe-host-runtime.ts",
4254
4373
  line: 69,
4255
4374
  scope: this,
@@ -4264,11 +4383,8 @@ var IFrameHostRuntime = class {
4264
4383
  this._clientServices = new LocalClientServices({
4265
4384
  lockKey: LOCK_KEY,
4266
4385
  config: this._config,
4267
- networkManager: new NetworkManager3({
4268
- log: true,
4269
- signalManager: signals ? new WebsocketSignalManager3(signals) : new MemorySignalManager3(new MemorySignalManagerContext3()),
4270
- transportFactory: this._transportFactory
4271
- })
4386
+ signalManager: signals ? new WebsocketSignalManager3(signals) : new MemorySignalManager2(new MemorySignalManagerContext2()),
4387
+ transportFactory: this._transportFactory
4272
4388
  });
4273
4389
  const middleware = {
4274
4390
  handleCall: async (method, params, handler) => {
@@ -4301,17 +4417,17 @@ var IFrameHostRuntime = class {
4301
4417
  (_a = this._shellRuntime) == null ? void 0 : _a.open()
4302
4418
  ]);
4303
4419
  this._ready.wake(void 0);
4304
- log20("started", {}, {
4420
+ log19("started", {}, {
4305
4421
  file: "iframe-host-runtime.ts",
4306
- line: 115,
4422
+ line: 112,
4307
4423
  scope: this,
4308
4424
  callSite: (f, a) => f(...a)
4309
4425
  });
4310
4426
  } catch (err) {
4311
4427
  this._ready.wake(err);
4312
- log20.catch(err, {}, {
4428
+ log19.catch(err, {}, {
4313
4429
  file: "iframe-host-runtime.ts",
4314
- line: 118,
4430
+ line: 115,
4315
4431
  scope: this,
4316
4432
  callSite: (f, a) => f(...a)
4317
4433
  });
@@ -4319,18 +4435,18 @@ var IFrameHostRuntime = class {
4319
4435
  }
4320
4436
  async stop() {
4321
4437
  var _a;
4322
- log20("stopping...", {}, {
4438
+ log19("stopping...", {}, {
4323
4439
  file: "iframe-host-runtime.ts",
4324
- line: 123,
4440
+ line: 120,
4325
4441
  scope: this,
4326
4442
  callSite: (f, a) => f(...a)
4327
4443
  });
4328
4444
  await this._clientRpc.close();
4329
4445
  await this._clientServices.close();
4330
4446
  await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
4331
- log20("stopped", {}, {
4447
+ log19("stopped", {}, {
4332
4448
  file: "iframe-host-runtime.ts",
4333
- line: 127,
4449
+ line: 124,
4334
4450
  scope: this,
4335
4451
  callSite: (f, a) => f(...a)
4336
4452
  });
@@ -4360,6 +4476,9 @@ export {
4360
4476
  InvitationsHandler,
4361
4477
  InvitationsServiceImpl,
4362
4478
  SpaceInvitationProtocol,
4479
+ DataSpace,
4480
+ DataSpaceManager,
4481
+ SpacesServiceImpl,
4363
4482
  createStorageObjects,
4364
4483
  ShellRuntimeImpl,
4365
4484
  MemoryShellRuntime,
@@ -4371,7 +4490,6 @@ export {
4371
4490
  ServiceContext,
4372
4491
  ServiceRegistry,
4373
4492
  ClientServicesHost,
4374
- LocalClientServices,
4375
- fromHost
4493
+ LocalClientServices
4376
4494
  };
4377
- //# sourceMappingURL=chunk-T73F4MV4.mjs.map
4495
+ //# sourceMappingURL=chunk-IHSMRQ3L.mjs.map