@dxos/client-services 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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 (229) hide show
  1. package/dist/lib/browser/{chunk-LZ5JMQR7.mjs → chunk-DPJ5AYTT.mjs} +2729 -4593
  2. package/dist/lib/browser/chunk-DPJ5AYTT.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
  4. package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-XJRPB3GA.mjs +22 -0
  6. package/dist/lib/browser/chunk-XJRPB3GA.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +490 -228
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
  11. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  12. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  13. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  14. package/dist/lib/browser/packlets/locks/browser.mjs +86 -0
  15. package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
  16. package/dist/lib/browser/packlets/locks/node.mjs +48 -0
  17. package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
  18. package/dist/lib/browser/testing/index.mjs +60 -90
  19. package/dist/lib/browser/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/chunk-2DT3MZRL.mjs +22 -0
  21. package/dist/lib/node-esm/chunk-2DT3MZRL.mjs.map +7 -0
  22. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
  23. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-JXUVAXX5.mjs → chunk-NAPGGOMT.mjs} +2652 -4385
  25. package/dist/lib/node-esm/chunk-NAPGGOMT.mjs.map +7 -0
  26. package/dist/lib/node-esm/index.mjs +490 -228
  27. package/dist/lib/node-esm/index.mjs.map +4 -4
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
  30. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  31. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  32. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  33. package/dist/lib/node-esm/packlets/locks/browser.mjs +86 -0
  34. package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
  35. package/dist/lib/node-esm/packlets/locks/node.mjs +48 -0
  36. package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
  37. package/dist/lib/node-esm/testing/index.mjs +60 -90
  38. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  39. package/dist/types/src/index.d.ts +1 -0
  40. package/dist/types/src/index.d.ts.map +1 -1
  41. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
  42. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
  43. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +2 -1
  44. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  45. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  46. package/dist/types/src/packlets/devtools/devtools.d.ts +2 -2
  47. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  48. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  49. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  50. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
  51. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  52. package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
  53. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
  54. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
  55. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
  56. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +2 -3
  57. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  58. package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
  59. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
  60. package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
  61. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  62. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  63. package/dist/types/src/packlets/identity/identity-manager.d.ts +6 -6
  64. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  65. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +8 -7
  66. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  67. package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
  68. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  69. package/dist/types/src/packlets/identity/identity.d.ts +8 -11
  70. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  71. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +6 -5
  72. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  73. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
  74. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  75. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  76. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  77. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +7 -4
  78. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  79. package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
  80. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
  81. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
  82. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  83. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
  84. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  85. package/dist/types/src/packlets/invitations/invitations-service.d.ts +3 -3
  86. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  87. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +4 -3
  88. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  89. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  90. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -1
  91. package/dist/types/src/packlets/locks/index.d.ts +1 -1
  92. package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
  93. package/dist/types/src/packlets/locks/node.d.ts.map +1 -1
  94. package/dist/types/src/packlets/logging/logging-service.d.ts +4 -0
  95. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  96. package/dist/types/src/packlets/network/network-service.d.ts +5 -4
  97. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  98. package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
  99. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  100. package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
  101. package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
  102. package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
  103. package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
  104. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  105. package/dist/types/src/packlets/services/service-context.d.ts +13 -9
  106. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  107. package/dist/types/src/packlets/services/service-host.d.ts +20 -7
  108. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  109. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
  110. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  111. package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
  112. package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
  113. package/dist/types/src/packlets/space-export/index.d.ts +4 -1
  114. package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
  115. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
  116. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
  117. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
  118. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
  119. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
  120. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
  121. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +7 -1
  122. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  123. package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
  124. package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
  125. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  126. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +28 -17
  127. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  128. package/dist/types/src/packlets/spaces/data-space.d.ts +26 -9
  129. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  130. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
  131. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  132. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
  133. package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
  134. package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
  135. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -9
  136. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  137. package/dist/types/src/packlets/spaces/spaces-service.d.ts +10 -7
  138. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  139. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  140. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
  141. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  142. package/dist/types/src/packlets/storage/util.d.ts.map +1 -1
  143. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  144. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  145. package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -1
  146. package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
  147. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  148. package/dist/types/src/packlets/testing/test-builder.d.ts +6 -5
  149. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  150. package/dist/types/src/packlets/worker/worker-runtime.d.ts +41 -4
  151. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  152. package/dist/types/src/packlets/worker/worker-session.d.ts +2 -4
  153. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  154. package/dist/types/src/testing/setup.d.ts.map +1 -1
  155. package/dist/types/src/version.d.ts +1 -1
  156. package/dist/types/src/version.d.ts.map +1 -1
  157. package/dist/types/tsconfig.tsbuildinfo +1 -1
  158. package/package.json +70 -55
  159. package/src/index.ts +1 -0
  160. package/src/packlets/agents/edge-agent-manager.ts +8 -5
  161. package/src/packlets/agents/edge-agent-service.ts +15 -3
  162. package/src/packlets/devices/devices-service.test.ts +0 -1
  163. package/src/packlets/devices/devices-service.ts +1 -1
  164. package/src/packlets/devtools/devtools.ts +2 -3
  165. package/src/packlets/diagnostics/diagnostics.ts +1 -2
  166. package/src/packlets/diagnostics/index.ts +1 -1
  167. package/src/packlets/identity/authenticator.ts +2 -2
  168. package/src/packlets/identity/contacts-service.ts +0 -1
  169. package/src/packlets/identity/identity-manager.test.ts +5 -5
  170. package/src/packlets/identity/identity-manager.ts +23 -22
  171. package/src/packlets/identity/identity-recovery-manager.ts +22 -18
  172. package/src/packlets/identity/identity-service.test.ts +6 -27
  173. package/src/packlets/identity/identity-service.ts +13 -81
  174. package/src/packlets/identity/identity.test.ts +6 -6
  175. package/src/packlets/identity/identity.ts +11 -34
  176. package/src/packlets/invitations/device-invitation-protocol.ts +8 -7
  177. package/src/packlets/invitations/edge-invitation-handler.ts +9 -5
  178. package/src/packlets/invitations/invitation-guest-extenstion.ts +6 -4
  179. package/src/packlets/invitations/invitation-host-extension.ts +13 -14
  180. package/src/packlets/invitations/invitation-protocol.ts +7 -4
  181. package/src/packlets/invitations/invitation-state.ts +1 -15
  182. package/src/packlets/invitations/invitations-handler.test.ts +4 -5
  183. package/src/packlets/invitations/invitations-handler.ts +74 -22
  184. package/src/packlets/invitations/invitations-manager.ts +40 -15
  185. package/src/packlets/invitations/invitations-service.ts +9 -9
  186. package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
  187. package/src/packlets/invitations/space-invitation-protocol.ts +11 -16
  188. package/src/packlets/locks/index.ts +1 -1
  189. package/src/packlets/logging/logging-service.ts +20 -16
  190. package/src/packlets/network/network-service.test.ts +0 -1
  191. package/src/packlets/network/network-service.ts +10 -8
  192. package/src/packlets/services/client-rpc-server.ts +19 -16
  193. package/src/packlets/services/feed-syncer.test.ts +340 -0
  194. package/src/packlets/services/feed-syncer.ts +377 -0
  195. package/src/packlets/services/platform.ts +7 -1
  196. package/src/packlets/services/service-context.test.ts +3 -2
  197. package/src/packlets/services/service-context.ts +139 -56
  198. package/src/packlets/services/service-host.test.ts +8 -8
  199. package/src/packlets/services/service-host.ts +76 -40
  200. package/src/packlets/services/service-registry.test.ts +0 -1
  201. package/src/packlets/space-export/archive-format.ts +42 -0
  202. package/src/packlets/space-export/index.ts +4 -1
  203. package/src/packlets/space-export/serialized-space-reader.ts +111 -0
  204. package/src/packlets/space-export/serialized-space-writer.ts +252 -0
  205. package/src/packlets/space-export/space-archive-reader.ts +64 -3
  206. package/src/packlets/space-export/space-archive-writer.ts +41 -3
  207. package/src/packlets/space-export/space-archive.test.ts +461 -0
  208. package/src/packlets/spaces/data-space-manager.test.ts +79 -13
  209. package/src/packlets/spaces/data-space-manager.ts +115 -116
  210. package/src/packlets/spaces/data-space.ts +58 -34
  211. package/src/packlets/spaces/edge-feed-replicator.test.ts +2 -2
  212. package/src/packlets/spaces/edge-feed-replicator.ts +12 -10
  213. package/src/packlets/spaces/epoch-migrations.ts +5 -5
  214. package/src/packlets/spaces/genesis.ts +6 -1
  215. package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
  216. package/src/packlets/spaces/notarization-plugin.ts +10 -9
  217. package/src/packlets/spaces/spaces-service.test.ts +18 -11
  218. package/src/packlets/spaces/spaces-service.ts +123 -24
  219. package/src/packlets/storage/storage.ts +4 -4
  220. package/src/packlets/testing/invitation-utils.ts +10 -6
  221. package/src/packlets/testing/test-builder.ts +36 -10
  222. package/src/packlets/worker/worker-runtime.ts +188 -17
  223. package/src/packlets/worker/worker-session.ts +12 -18
  224. package/src/version.ts +1 -1
  225. package/dist/lib/browser/chunk-LZ5JMQR7.mjs.map +0 -7
  226. package/dist/lib/node-esm/chunk-JXUVAXX5.mjs.map +0 -7
  227. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
  228. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
  229. package/src/packlets/identity/default-space-state-machine.ts +0 -44
@@ -2,13 +2,16 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
+ import * as SqlClient from '@effect/sql/SqlClient';
6
+ import * as Effect from 'effect/Effect';
7
+
5
8
  import { Event, synchronized } from '@dxos/async';
6
9
  import { type ClientServices, clientServiceBundle } from '@dxos/client-protocol';
7
- import { type Config } from '@dxos/config';
10
+ import { type Config, resolveTelemetryTag } from '@dxos/config';
8
11
  import { Context } from '@dxos/context';
9
12
  import { EdgeClient, type EdgeConnection, EdgeHttpClient, createStubEdgeIdentity } from '@dxos/edge-client';
13
+ import { RuntimeProvider } from '@dxos/effect';
10
14
  import { invariant } from '@dxos/invariant';
11
- import { PublicKey } from '@dxos/keys';
12
15
  import { type LevelDB } from '@dxos/kv-store';
13
16
  import { log } from '@dxos/log';
14
17
  import { EdgeSignalManager, type SignalManager, WebsocketSignalManager } from '@dxos/messaging';
@@ -18,10 +21,11 @@ import {
18
21
  createIceProvider,
19
22
  createRtcTransportFactory,
20
23
  } from '@dxos/network-manager';
21
- import { trace } from '@dxos/protocols';
22
24
  import { SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
23
25
  import { type Storage } from '@dxos/random-access-storage';
24
- import { TRACE_PROCESSOR, trace as Trace } from '@dxos/tracing';
26
+ import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
27
+ import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
28
+ import { trace as Trace } from '@dxos/tracing';
25
29
  import { WebsocketRpcClient } from '@dxos/websocket-rpc';
26
30
 
27
31
  import { EdgeAgentServiceImpl } from '../agents';
@@ -41,11 +45,10 @@ import { NetworkServiceImpl } from '../network';
41
45
  import { SpacesServiceImpl } from '../spaces';
42
46
  import { createLevel, createStorageObjects } from '../storage';
43
47
  import { SystemServiceImpl } from '../system';
44
-
45
- import { ServiceContext, type ServiceContextRuntimeParams } from './service-context';
48
+ import { ServiceContext, type ServiceContextRuntimeProps } from './service-context';
46
49
  import { ServiceRegistry } from './service-registry';
47
50
 
48
- export type ClientServicesHostParams = {
51
+ export type ClientServicesHostProps = {
49
52
  /**
50
53
  * Can be omitted if `initialize` is later called.
51
54
  */
@@ -57,7 +60,8 @@ export type ClientServicesHostParams = {
57
60
  level?: LevelDB;
58
61
  lockKey?: string;
59
62
  callbacks?: ClientServicesHostCallbacks;
60
- runtimeParams?: ServiceContextRuntimeParams;
63
+ runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction>;
64
+ runtimeProps?: ServiceContextRuntimeProps;
61
65
  };
62
66
 
63
67
  export type ClientServicesHostCallbacks = {
@@ -80,8 +84,6 @@ export class ClientServicesHost {
80
84
  private readonly _serviceRegistry: ServiceRegistry<ClientServices>;
81
85
  private readonly _systemService: SystemServiceImpl;
82
86
  private readonly _loggingService: LoggingServiceImpl;
83
- private readonly _tracingService = TRACE_PROCESSOR.createTraceSender();
84
-
85
87
  private readonly _statusUpdate = new Event<void>();
86
88
 
87
89
  private _config?: Config;
@@ -95,7 +97,10 @@ export class ClientServicesHost {
95
97
  private _edgeHttpClient?: EdgeHttpClient = undefined;
96
98
 
97
99
  private _serviceContext!: ServiceContext;
98
- private readonly _runtimeParams: ServiceContextRuntimeParams;
100
+ private readonly _runtime: RuntimeProvider.RuntimeProvider<
101
+ SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction
102
+ >;
103
+ private readonly _runtimeProps: ServiceContextRuntimeProps;
99
104
  private diagnosticsBroadcastHandler: CollectDiagnosticsBroadcastHandler;
100
105
 
101
106
  @Trace.info()
@@ -116,20 +121,14 @@ export class ClientServicesHost {
116
121
  // TODO(wittjosiah): Turn this on by default.
117
122
  lockKey,
118
123
  callbacks,
119
- runtimeParams,
120
- }: ClientServicesHostParams = {}) {
124
+ runtime,
125
+ runtimeProps,
126
+ }: ClientServicesHostProps) {
121
127
  this._storage = storage;
122
128
  this._level = level;
123
129
  this._callbacks = callbacks;
124
- this._runtimeParams = runtimeParams ?? {};
125
-
126
- if (this._runtimeParams.disableP2pReplication === undefined) {
127
- this._runtimeParams.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
128
- }
129
-
130
- if (this._runtimeParams.enableVectorIndexing === undefined) {
131
- this._runtimeParams.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
132
- }
130
+ this._runtime = runtime;
131
+ this._runtimeProps = runtimeProps ?? {};
133
132
 
134
133
  if (config) {
135
134
  this.initialize({ config, transportFactory, signalManager });
@@ -143,7 +142,7 @@ export class ClientServicesHost {
143
142
  void this.open(new Context());
144
143
  }
145
144
  },
146
- onRelease: () => this.close(),
145
+ onRelease: () => this.close(Context.default()),
147
146
  });
148
147
  }
149
148
 
@@ -172,7 +171,6 @@ export class ClientServicesHost {
172
171
 
173
172
  this._serviceRegistry = new ServiceRegistry<ClientServices>(clientServiceBundle, {
174
173
  SystemService: this._systemService,
175
- TracingService: this._tracingService,
176
174
  });
177
175
  }
178
176
 
@@ -200,6 +198,30 @@ export class ClientServicesHost {
200
198
  return this._serviceRegistry.services;
201
199
  }
202
200
 
201
+ /**
202
+ * Debugging util.
203
+ */
204
+ async exportSqliteDatabase(): Promise<Uint8Array> {
205
+ return await RuntimeProvider.runPromise(this._runtime)(
206
+ Effect.gen(function* () {
207
+ const sql = yield* SqlExport.SqlExport;
208
+ return yield* sql.export;
209
+ }),
210
+ );
211
+ }
212
+
213
+ /**
214
+ * Debugging util.
215
+ */
216
+ async runSqliteQuery(query: string, params?: any[]): Promise<readonly Record<string, unknown>[]> {
217
+ return await RuntimeProvider.runPromise(this._runtime)(
218
+ Effect.gen(function* () {
219
+ const sql = yield* SqlClient.SqlClient;
220
+ return yield* sql`${sql.unsafe(query, params)}`;
221
+ }),
222
+ );
223
+ }
224
+
203
225
  /**
204
226
  * Initialize the service host with the config.
205
227
  * Config can also be provided in the constructor.
@@ -210,6 +232,13 @@ export class ClientServicesHost {
210
232
  log('initializing...');
211
233
 
212
234
  if (config) {
235
+ if (this._runtimeProps.disableP2pReplication === undefined) {
236
+ this._runtimeProps.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
237
+ }
238
+ if (this._runtimeProps.enableVectorIndexing === undefined) {
239
+ this._runtimeProps.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
240
+ }
241
+
213
242
  invariant(!this._config, 'config already set');
214
243
  this._config = config;
215
244
  if (!this._storage) {
@@ -224,8 +253,9 @@ export class ClientServicesHost {
224
253
 
225
254
  const endpoint = config?.get('runtime.services.edge.url');
226
255
  if (endpoint) {
227
- this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), { socketEndpoint: endpoint });
228
- this._edgeHttpClient = new EdgeHttpClient(endpoint);
256
+ const clientTag = resolveTelemetryTag(config);
257
+ this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), { socketEndpoint: endpoint, clientTag });
258
+ this._edgeHttpClient = new EdgeHttpClient(endpoint, { clientTag });
229
259
  }
230
260
 
231
261
  const {
@@ -264,8 +294,7 @@ export class ClientServicesHost {
264
294
  return;
265
295
  }
266
296
 
267
- const traceId = PublicKey.random().toHex();
268
- log.trace('dxos.client-services.host.open', trace.begin({ id: traceId }));
297
+ log('opening service host');
269
298
 
270
299
  invariant(this._config, 'config not set');
271
300
  invariant(this._storage, 'storage not set');
@@ -291,7 +320,8 @@ export class ClientServicesHost {
291
320
  this._signalManager,
292
321
  this._edgeConnection,
293
322
  this._edgeHttpClient,
294
- this._runtimeParams,
323
+ this._runtime,
324
+ this._runtimeProps,
295
325
  this._config.get('runtime.client.edgeFeatures'),
296
326
  );
297
327
 
@@ -309,8 +339,7 @@ export class ClientServicesHost {
309
339
  this._serviceContext.identityManager,
310
340
  this._serviceContext.recoveryManager,
311
341
  this._serviceContext.keyring,
312
- () => this._serviceContext.dataSpaceManager!,
313
- (params) => this._createIdentity(params),
342
+ (params, ctx) => this._createIdentity(params, ctx),
314
343
  (profile) => this._serviceContext.broadcastProfileUpdate(profile),
315
344
  );
316
345
 
@@ -330,11 +359,13 @@ export class ClientServicesHost {
330
359
  SpacesService: new SpacesServiceImpl(
331
360
  this._serviceContext.identityManager,
332
361
  this._serviceContext.spaceManager,
362
+ this._serviceContext.echoHost,
333
363
  dataSpaceManagerProvider,
334
364
  ),
335
365
 
336
366
  DataService: this._serviceContext.echoHost.dataService,
337
367
  QueryService: this._serviceContext.echoHost.queryService,
368
+ QueueService: this._serviceContext.echoHost.queuesService,
338
369
 
339
370
  NetworkService: new NetworkServiceImpl(
340
371
  this._serviceContext.networkManager,
@@ -343,7 +374,6 @@ export class ClientServicesHost {
343
374
  ),
344
375
 
345
376
  LoggingService: this._loggingService,
346
- TracingService: this._tracingService,
347
377
 
348
378
  // TODO(burdon): Move to new protobuf definitions.
349
379
  DevtoolsHost: new DevtoolsServiceImpl({
@@ -355,8 +385,13 @@ export class ClientServicesHost {
355
385
  EdgeAgentService: new EdgeAgentServiceImpl(agentManagerProvider, this._edgeConnection),
356
386
  });
357
387
 
388
+ log('service-host: opening service context...');
358
389
  await this._serviceContext.open(ctx);
390
+ log('service-host: service context opened');
391
+
392
+ log('service-host: opening identity service...');
359
393
  await identityService.open();
394
+ log('service-host: identity service opened');
360
395
 
361
396
  const devtoolsProxy = this._config?.get('runtime.client.devtoolsProxy');
362
397
  if (devtoolsProxy) {
@@ -375,12 +410,11 @@ export class ClientServicesHost {
375
410
  this._statusUpdate.emit();
376
411
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
377
412
  log('opened', { deviceKey });
378
- log.trace('dxos.client-services.host.open', trace.end({ id: traceId }));
379
413
  }
380
414
 
381
415
  @synchronized
382
416
  @Trace.span()
383
- async close(): Promise<void> {
417
+ async close(ctx: Context): Promise<void> {
384
418
  if (!this._open) {
385
419
  return;
386
420
  }
@@ -399,23 +433,25 @@ export class ClientServicesHost {
399
433
  }
400
434
 
401
435
  async reset(): Promise<void> {
402
- const traceId = PublicKey.random().toHex();
403
- log.trace('dxos.sdk.client-services-host.reset', trace.begin({ id: traceId }));
404
-
405
436
  log.info('resetting...');
406
437
  // Emit this status update immediately so app returns to fallback.
407
438
  // This state is never cleared because the app reloads.
408
439
  this._resetting = true;
409
440
  this._statusUpdate.emit();
410
441
  await this._serviceContext?.close();
442
+ // Clear LevelDB contents to remove all persisted Echo/Automerge/index data.
443
+ try {
444
+ await this._level!.clear();
445
+ } catch (err) {
446
+ log.warn('failed to clear leveldb during reset', { err });
447
+ }
411
448
  await this._storage!.reset();
412
449
  log.info('reset');
413
- log.trace('dxos.sdk.client-services-host.reset', trace.end({ id: traceId }));
414
450
  await this._callbacks?.onReset?.();
415
451
  }
416
452
 
417
- private async _createIdentity(params: CreateIdentityOptions) {
418
- const identity = await this._serviceContext.createIdentity(params);
453
+ private async _createIdentity(params: CreateIdentityOptions, ctx?: Context) {
454
+ const identity = await this._serviceContext.createIdentity(params, ctx);
419
455
  await this._serviceContext.initialized.wait();
420
456
  return identity;
421
457
  }
@@ -15,7 +15,6 @@ import { createLinkedPorts, createProtoRpcPeer, createServiceBundle } from '@dxo
15
15
 
16
16
  import { SystemServiceImpl } from '../system';
17
17
  import { createServiceContext } from '../testing';
18
-
19
18
  import { ServiceRegistry } from './service-registry';
20
19
 
21
20
  // TODO(burdon): Create TestService (that doesn't require peers).
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { SpaceArchive } from '@dxos/protocols/proto/dxos/client/services';
6
+
7
+ const JSON_EXTENSIONS = ['.dx.json', '.dx.json.gz', '.json'];
8
+ const BINARY_EXTENSIONS = ['.tar', '.tar.gz'];
9
+
10
+ /**
11
+ * Detect the format of a space archive.
12
+ *
13
+ * Uses filename extension as the primary signal, and falls back to sniffing
14
+ * the first bytes of the archive contents to distinguish JSON from tar.
15
+ */
16
+ export const detectSpaceArchiveFormat = (archive: Pick<SpaceArchive, 'filename' | 'contents'>): SpaceArchive.Format => {
17
+ const filename = archive.filename?.toLowerCase() ?? '';
18
+ if (JSON_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
19
+ return SpaceArchive.Format.JSON;
20
+ }
21
+ if (BINARY_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
22
+ return SpaceArchive.Format.BINARY;
23
+ }
24
+
25
+ // Fall back to byte sniffing: JSON archives start with '{' (0x7B) or whitespace.
26
+ const bytes = archive.contents;
27
+ if (bytes && bytes.length > 0) {
28
+ for (let i = 0; i < Math.min(bytes.length, 16); i++) {
29
+ const byte = bytes[i];
30
+ // Skip whitespace.
31
+ if (byte === 0x20 || byte === 0x09 || byte === 0x0a || byte === 0x0d) {
32
+ continue;
33
+ }
34
+ if (byte === 0x7b /* '{' */) {
35
+ return SpaceArchive.Format.JSON;
36
+ }
37
+ break;
38
+ }
39
+ }
40
+
41
+ return SpaceArchive.Format.BINARY;
42
+ };
@@ -2,5 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './space-archive-writer';
5
+ export * from './archive-format';
6
+ export * from './serialized-space-reader';
7
+ export * from './serialized-space-writer';
6
8
  export * from './space-archive-reader';
9
+ export * from './space-archive-writer';
@@ -0,0 +1,111 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type Obj } from '@dxos/echo';
6
+ import { type SerializedSpace } from '@dxos/echo-db';
7
+ import { type DatabaseDirectory, type ObjectStructure } from '@dxos/echo-protocol';
8
+ import { assertArgument } from '@dxos/invariant';
9
+ import { type SpaceArchive } from '@dxos/protocols/proto/dxos/client/services';
10
+
11
+ const ATTR_TYPE = '@type';
12
+ const ATTR_META = '@meta';
13
+ const ATTR_DELETED = '@deleted';
14
+ const ATTR_PARENT = '@parent';
15
+ const ATTR_RELATION_SOURCE = '@relationSource';
16
+ const ATTR_RELATION_TARGET = '@relationTarget';
17
+
18
+ const INTERNAL_KEYS: ReadonlySet<string> = new Set([
19
+ 'id',
20
+ ATTR_TYPE,
21
+ ATTR_META,
22
+ ATTR_DELETED,
23
+ ATTR_PARENT,
24
+ ATTR_RELATION_SOURCE,
25
+ ATTR_RELATION_TARGET,
26
+ ]);
27
+
28
+ /**
29
+ * Parse a JSON space archive.
30
+ *
31
+ * The archive contents are expected to be the UTF-8 encoding of
32
+ * `JSON.stringify(serializedSpace)`.
33
+ */
34
+ export const readSerializedSpaceArchive = (archive: SpaceArchive): SerializedSpace => {
35
+ const text = new TextDecoder().decode(archive.contents);
36
+ const parsed = JSON.parse(text) as SerializedSpace;
37
+ assertArgument(typeof parsed === 'object' && parsed !== null, 'archive', 'Invalid JSON archive payload');
38
+ assertArgument(typeof parsed.version === 'number', 'archive', 'Missing SerializedSpace.version');
39
+ assertArgument(Array.isArray(parsed.objects), 'archive', 'Missing SerializedSpace.objects');
40
+ return parsed;
41
+ };
42
+
43
+ /**
44
+ * Convert an {@link Obj.JSON} back into an internal {@link ObjectStructure} suitable
45
+ * for embedding into a {@link DatabaseDirectory}.
46
+ */
47
+ export const objJsonToObjectStructure = (obj: Obj.JSON): ObjectStructure => {
48
+ const data: Record<string, unknown> = {};
49
+ for (const [key, value] of Object.entries(obj)) {
50
+ if (INTERNAL_KEYS.has(key)) {
51
+ continue;
52
+ }
53
+ data[key] = value;
54
+ }
55
+
56
+ const system: NonNullable<ObjectStructure['system']> = {};
57
+
58
+ const type = obj[ATTR_TYPE];
59
+ if (type) {
60
+ system.type = { '/': type as string };
61
+ }
62
+
63
+ const parent = (obj as any)[ATTR_PARENT];
64
+ if (typeof parent === 'string') {
65
+ system.parent = { '/': parent };
66
+ }
67
+
68
+ const relationSource = (obj as any)[ATTR_RELATION_SOURCE];
69
+ const relationTarget = (obj as any)[ATTR_RELATION_TARGET];
70
+ if (typeof relationSource === 'string' || typeof relationTarget === 'string') {
71
+ system.kind = 'relation';
72
+ if (typeof relationSource === 'string') {
73
+ system.source = { '/': relationSource };
74
+ }
75
+ if (typeof relationTarget === 'string') {
76
+ system.target = { '/': relationTarget };
77
+ }
78
+ } else {
79
+ system.kind = 'object';
80
+ }
81
+
82
+ if ((obj as any)[ATTR_DELETED]) {
83
+ system.deleted = true;
84
+ }
85
+
86
+ const meta = (obj as any)[ATTR_META];
87
+ return {
88
+ system,
89
+ meta: {
90
+ keys: meta?.keys ?? [],
91
+ ...(meta?.tags ? { tags: meta.tags } : {}),
92
+ },
93
+ data,
94
+ };
95
+ };
96
+
97
+ /**
98
+ * Build a new {@link DatabaseDirectory} containing every object from the archive,
99
+ * keyed by object id. The caller is responsible for stamping the `access.spaceKey`
100
+ * and version fields after the document is created.
101
+ */
102
+ export const buildDatabaseDirectoryFromObjects = (objects: readonly Obj.JSON[]): DatabaseDirectory => {
103
+ const map: Record<string, ObjectStructure> = {};
104
+ for (const obj of objects) {
105
+ map[obj.id] = objJsonToObjectStructure(obj);
106
+ }
107
+ return {
108
+ objects: map,
109
+ links: {},
110
+ };
111
+ };