@dxos/client-services 0.4.10-main.35b4a08 → 0.4.10-main.36e0428

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 (120) hide show
  1. package/dist/lib/browser/{chunk-24G2JACZ.mjs → chunk-T4NJPSMU.mjs} +1446 -1145
  2. package/dist/lib/browser/chunk-T4NJPSMU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +20 -6
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +141 -119
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-6X2EZZDT.cjs → chunk-2L6Y2DJQ.cjs} +1350 -1133
  9. package/dist/lib/node/chunk-2L6Y2DJQ.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +55 -41
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +139 -120
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +5 -0
  18. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -0
  19. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +5 -0
  20. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -0
  21. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts +15 -0
  22. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -0
  23. package/dist/types/src/packlets/{services → diagnostics}/diagnostics.d.ts +1 -1
  24. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -0
  25. package/dist/types/src/packlets/diagnostics/index.d.ts +4 -0
  26. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  28. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
  29. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  30. package/dist/types/src/packlets/invitations/index.d.ts +1 -0
  31. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  32. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
  33. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  34. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  35. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  36. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +8 -4
  37. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  38. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +44 -0
  39. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
  40. package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
  41. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  42. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  43. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  44. package/dist/types/src/packlets/services/index.d.ts +1 -1
  45. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  46. package/dist/types/src/packlets/services/service-context.d.ts +12 -10
  47. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  48. package/dist/types/src/packlets/services/service-host.d.ts +5 -1
  49. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  50. package/dist/types/src/packlets/services/util.d.ts +1 -0
  51. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  52. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +8 -3
  53. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  54. package/dist/types/src/packlets/spaces/data-space.d.ts +4 -3
  55. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  56. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  57. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  58. package/dist/types/src/packlets/storage/level.d.ts +4 -0
  59. package/dist/types/src/packlets/storage/level.d.ts.map +1 -0
  60. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  61. package/dist/types/src/packlets/storage/util.d.ts +4 -0
  62. package/dist/types/src/packlets/storage/util.d.ts.map +1 -0
  63. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  64. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  65. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  66. package/dist/types/src/packlets/testing/test-builder.d.ts +10 -4
  67. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  68. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  69. package/dist/types/src/version.d.ts +1 -1
  70. package/package.json +36 -34
  71. package/src/index.ts +1 -0
  72. package/src/packlets/devices/devices-service.test.ts +1 -1
  73. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +94 -0
  74. package/src/packlets/diagnostics/diagnostics-broadcast.ts +20 -0
  75. package/src/packlets/diagnostics/diagnostics-collector.ts +65 -0
  76. package/src/packlets/{services → diagnostics}/diagnostics.ts +2 -2
  77. package/src/packlets/diagnostics/index.ts +7 -0
  78. package/src/packlets/identity/identity-manager.ts +1 -0
  79. package/src/packlets/identity/identity-service.test.ts +1 -1
  80. package/src/packlets/identity/identity.test.ts +3 -0
  81. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  82. package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
  83. package/src/packlets/invitations/index.ts +1 -0
  84. package/src/packlets/invitations/invitation-extension.ts +28 -1
  85. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  86. package/src/packlets/invitations/invitations-handler.ts +75 -96
  87. package/src/packlets/invitations/invitations-manager.ts +271 -0
  88. package/src/packlets/invitations/invitations-service.ts +23 -168
  89. package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
  90. package/src/packlets/network/network-service.test.ts +1 -1
  91. package/src/packlets/services/automerge-host.test.ts +13 -7
  92. package/src/packlets/services/index.ts +1 -1
  93. package/src/packlets/services/service-context.test.ts +9 -6
  94. package/src/packlets/services/service-context.ts +31 -26
  95. package/src/packlets/services/service-host.test.ts +6 -0
  96. package/src/packlets/services/service-host.ts +33 -25
  97. package/src/packlets/services/service-registry.test.ts +1 -1
  98. package/src/packlets/services/util.ts +2 -0
  99. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  100. package/src/packlets/spaces/data-space-manager.ts +56 -13
  101. package/src/packlets/spaces/data-space.ts +14 -19
  102. package/src/packlets/spaces/spaces-service.test.ts +1 -1
  103. package/src/packlets/storage/index.ts +1 -0
  104. package/src/packlets/storage/level.ts +20 -0
  105. package/src/packlets/storage/storage.ts +3 -9
  106. package/src/packlets/storage/util.ts +19 -0
  107. package/src/packlets/system/system-service.ts +1 -1
  108. package/src/packlets/testing/invitation-utils.ts +100 -97
  109. package/src/packlets/testing/test-builder.ts +40 -9
  110. package/src/packlets/vault/worker-runtime.ts +3 -1
  111. package/src/version.ts +1 -1
  112. package/dist/lib/browser/chunk-24G2JACZ.mjs.map +0 -7
  113. package/dist/lib/node/chunk-6X2EZZDT.cjs.map +0 -7
  114. package/dist/types/src/packlets/indexing/index.d.ts +0 -2
  115. package/dist/types/src/packlets/indexing/index.d.ts.map +0 -1
  116. package/dist/types/src/packlets/indexing/util.d.ts +0 -15
  117. package/dist/types/src/packlets/indexing/util.d.ts.map +0 -1
  118. package/dist/types/src/packlets/services/diagnostics.d.ts.map +0 -1
  119. package/src/packlets/indexing/index.ts +0 -5
  120. package/src/packlets/indexing/util.ts +0 -89
@@ -26,19 +26,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_6X2EZZDT_exports = {};
30
- __export(chunk_6X2EZZDT_exports, {
29
+ var chunk_2L6Y2DJQ_exports = {};
30
+ __export(chunk_2L6Y2DJQ_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
+ ClientServicesProviderResource: () => ClientServicesProviderResource,
33
34
  DataSpace: () => DataSpace,
34
35
  DataSpaceManager: () => DataSpaceManager,
35
36
  DeviceInvitationProtocol: () => DeviceInvitationProtocol,
36
37
  DevtoolsHostEvents: () => DevtoolsHostEvents,
37
38
  DevtoolsServiceImpl: () => DevtoolsServiceImpl,
39
+ DiagnosticsCollector: () => DiagnosticsCollector,
38
40
  Identity: () => Identity,
39
41
  IdentityManager: () => IdentityManager,
40
42
  IdentityServiceImpl: () => IdentityServiceImpl,
41
43
  InvitationsHandler: () => InvitationsHandler,
44
+ InvitationsManager: () => InvitationsManager,
42
45
  InvitationsServiceImpl: () => InvitationsServiceImpl,
43
46
  Lock: () => Lock,
44
47
  ServiceContext: () => ServiceContext,
@@ -46,11 +49,14 @@ __export(chunk_6X2EZZDT_exports, {
46
49
  SpaceInvitationProtocol: () => SpaceInvitationProtocol,
47
50
  SpacesServiceImpl: () => SpacesServiceImpl,
48
51
  TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
52
+ createAdmissionKeypair: () => createAdmissionKeypair,
49
53
  createAuthProvider: () => createAuthProvider,
54
+ createCollectDiagnosticsBroadcastHandler: () => createCollectDiagnosticsBroadcastHandler,
55
+ createCollectDiagnosticsBroadcastSender: () => createCollectDiagnosticsBroadcastSender,
50
56
  createDiagnostics: () => createDiagnostics,
57
+ createLevel: () => createLevel,
51
58
  createStorageObjects: () => createStorageObjects,
52
59
  getNetworkPeers: () => getNetworkPeers,
53
- invitationExpired: () => invitationExpired,
54
60
  isLocked: () => isLocked,
55
61
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
56
62
  subscribeToFeeds: () => subscribeToFeeds,
@@ -60,7 +66,7 @@ __export(chunk_6X2EZZDT_exports, {
60
66
  subscribeToSpaces: () => subscribeToSpaces,
61
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
68
  });
63
- module.exports = __toCommonJS(chunk_6X2EZZDT_exports);
69
+ module.exports = __toCommonJS(chunk_2L6Y2DJQ_exports);
64
70
  var import_async = require("@dxos/async");
65
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
72
  var import_feed_store = require("@dxos/feed-store");
@@ -114,7 +120,7 @@ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
114
120
  var import_async7 = require("@dxos/async");
115
121
  var import_client_protocol2 = require("@dxos/client-protocol");
116
122
  var import_context4 = require("@dxos/context");
117
- var import_credentials7 = require("@dxos/credentials");
123
+ var import_crypto = require("@dxos/crypto");
118
124
  var import_invariant5 = require("@dxos/invariant");
119
125
  var import_keys5 = require("@dxos/keys");
120
126
  var import_log4 = require("@dxos/log");
@@ -124,6 +130,7 @@ var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
124
130
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
125
131
  var import_async8 = require("@dxos/async");
126
132
  var import_context5 = require("@dxos/context");
133
+ var import_crypto2 = require("@dxos/crypto");
127
134
  var import_invariant6 = require("@dxos/invariant");
128
135
  var import_keys6 = require("@dxos/keys");
129
136
  var import_log5 = require("@dxos/log");
@@ -131,63 +138,62 @@ var import_protocols5 = require("@dxos/protocols");
131
138
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
132
139
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
133
140
  var import_teleport = require("@dxos/teleport");
134
- var import_async9 = require("@dxos/async");
135
141
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
136
- var import_context6 = require("@dxos/context");
137
- var import_invariant7 = require("@dxos/invariant");
138
- var import_log6 = require("@dxos/log");
139
142
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
140
- var import_credentials8 = require("@dxos/credentials");
143
+ var import_credentials7 = require("@dxos/credentials");
141
144
  var import_feed_store3 = require("@dxos/feed-store");
142
- var import_invariant8 = require("@dxos/invariant");
143
- var import_log7 = require("@dxos/log");
145
+ var import_invariant7 = require("@dxos/invariant");
146
+ var import_log6 = require("@dxos/log");
144
147
  var import_protocols6 = require("@dxos/protocols");
145
148
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
149
+ var import_credentials8 = require("@dxos/protocols/proto/dxos/halo/credentials");
150
+ var import_async9 = require("@dxos/async");
151
+ var import_client_protocol3 = require("@dxos/client-protocol");
152
+ var import_context6 = require("@dxos/context");
153
+ var import_credentials9 = require("@dxos/credentials");
154
+ var import_echo_pipeline = require("@dxos/echo-pipeline");
155
+ var import_invariant8 = require("@dxos/invariant");
156
+ var import_keys7 = require("@dxos/keys");
157
+ var import_log7 = require("@dxos/log");
158
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
146
159
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
147
160
  var import_debug2 = require("@dxos/debug");
148
161
  var import_rpc = require("@dxos/rpc");
149
162
  var import_tracing3 = require("@dxos/tracing");
150
- var import_codec_protobuf10 = require("@dxos/codec-protobuf");
151
- var import_credentials9 = require("@dxos/credentials");
152
- var import_invariant9 = require("@dxos/invariant");
153
- var import_protocols7 = require("@dxos/protocols");
154
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
155
- var import_tracing4 = require("@dxos/tracing");
156
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
157
163
  var import_async10 = require("@dxos/async");
158
- var import_client_protocol3 = require("@dxos/client-protocol");
164
+ var import_client_protocol4 = require("@dxos/client-protocol");
159
165
  var import_context7 = require("@dxos/context");
160
166
  var import_debug3 = require("@dxos/debug");
161
- var import_echo_db = require("@dxos/echo-db");
162
- var import_echo_pipeline = require("@dxos/echo-pipeline");
163
167
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
164
- var import_invariant10 = require("@dxos/invariant");
165
- var import_keys7 = require("@dxos/keys");
168
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
169
+ var import_echo_schema = require("@dxos/echo-schema");
170
+ var import_invariant9 = require("@dxos/invariant");
171
+ var import_keys8 = require("@dxos/keys");
166
172
  var import_log8 = require("@dxos/log");
167
- var import_protocols8 = require("@dxos/protocols");
168
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
173
+ var import_protocols7 = require("@dxos/protocols");
174
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
169
175
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
170
176
  var import_timeframe2 = require("@dxos/timeframe");
171
- var import_tracing5 = require("@dxos/tracing");
177
+ var import_tracing4 = require("@dxos/tracing");
172
178
  var import_util4 = require("@dxos/util");
173
179
  var import_async11 = require("@dxos/async");
174
180
  var import_credentials11 = require("@dxos/credentials");
175
181
  var import_async12 = require("@dxos/async");
176
182
  var import_context8 = require("@dxos/context");
177
- var import_invariant11 = require("@dxos/invariant");
178
- var import_keys8 = require("@dxos/keys");
183
+ var import_invariant10 = require("@dxos/invariant");
184
+ var import_keys9 = require("@dxos/keys");
179
185
  var import_log9 = require("@dxos/log");
180
- var import_protocols9 = require("@dxos/protocols");
186
+ var import_protocols8 = require("@dxos/protocols");
181
187
  var import_teleport2 = require("@dxos/teleport");
182
188
  var import_util5 = require("@dxos/util");
183
189
  var import_async13 = require("@dxos/async");
184
190
  var import_context9 = require("@dxos/context");
185
191
  var import_credentials12 = require("@dxos/credentials");
186
- var import_invariant12 = require("@dxos/invariant");
187
- var import_keys9 = require("@dxos/keys");
192
+ var import_invariant11 = require("@dxos/invariant");
193
+ var import_keys10 = require("@dxos/keys");
188
194
  var import_log10 = require("@dxos/log");
189
- var import_protocols10 = require("@dxos/protocols");
190
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
195
+ var import_protocols9 = require("@dxos/protocols");
196
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
191
197
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
192
198
  var import_util6 = require("@dxos/util");
193
199
  var import_credentials13 = require("@dxos/credentials");
@@ -195,69 +201,82 @@ var import_debug4 = require("@dxos/debug");
195
201
  var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
196
202
  var import_timeframe3 = require("@dxos/timeframe");
197
203
  var import_async14 = require("@dxos/async");
198
- var import_codec_protobuf11 = require("@dxos/codec-protobuf");
204
+ var import_codec_protobuf10 = require("@dxos/codec-protobuf");
199
205
  var import_debug5 = require("@dxos/debug");
200
- var import_invariant13 = require("@dxos/invariant");
206
+ var import_invariant12 = require("@dxos/invariant");
201
207
  var import_log11 = require("@dxos/log");
202
- var import_protocols11 = require("@dxos/protocols");
203
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
208
+ var import_protocols10 = require("@dxos/protocols");
209
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
204
210
  var import_async15 = require("@dxos/async");
205
211
  var import_context10 = require("@dxos/context");
206
212
  var import_credentials15 = require("@dxos/credentials");
207
213
  var import_debug6 = require("@dxos/debug");
208
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
214
+ var import_echo_db = require("@dxos/echo-db");
215
+ var import_echo_pipeline4 = require("@dxos/echo-pipeline");
209
216
  var import_feed_store4 = require("@dxos/feed-store");
210
- var import_indexing = require("@dxos/indexing");
211
- var import_invariant14 = require("@dxos/invariant");
217
+ var import_invariant13 = require("@dxos/invariant");
212
218
  var import_keyring = require("@dxos/keyring");
213
- var import_keys10 = require("@dxos/keys");
219
+ var import_keys11 = require("@dxos/keys");
214
220
  var import_log12 = require("@dxos/log");
221
+ var import_protocols11 = require("@dxos/protocols");
222
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
223
+ var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
224
+ var import_tracing5 = require("@dxos/tracing");
225
+ var import_util7 = require("@dxos/util");
226
+ var import_codec_protobuf11 = require("@dxos/codec-protobuf");
227
+ var import_credentials16 = require("@dxos/credentials");
228
+ var import_invariant14 = require("@dxos/invariant");
215
229
  var import_protocols12 = require("@dxos/protocols");
216
230
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
217
- var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
218
231
  var import_tracing6 = require("@dxos/tracing");
219
- var import_util7 = require("@dxos/util");
220
- var import_automerge = require("@dxos/automerge/automerge");
221
- var import_debug7 = require("@dxos/debug");
222
- var import_protocols13 = require("@dxos/protocols");
223
- var import_invariant15 = require("@dxos/invariant");
224
- var import_lock_file = require("@dxos/lock-file");
225
- var import_log13 = require("@dxos/log");
226
- var import_client_protocol4 = require("@dxos/client-protocol");
227
- var import_protocols14 = require("@dxos/protocols");
228
- var import_config = require("@dxos/protocols/proto/dxos/config");
229
- var import_random_access_storage = require("@dxos/random-access-storage");
232
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
233
+ var import_config = require("@dxos/config");
234
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
235
+ var import_tracing7 = require("@dxos/tracing");
230
236
  var import_util8 = require("@dxos/util");
231
237
  var import_async16 = require("@dxos/async");
232
238
  var import_client_protocol5 = require("@dxos/client-protocol");
233
239
  var import_context11 = require("@dxos/context");
234
- var import_echo_pipeline4 = require("@dxos/echo-pipeline");
235
- var E = __toESM(require("@dxos/echo-schema"));
236
- var import_indexing2 = require("@dxos/indexing");
237
- var import_invariant16 = require("@dxos/invariant");
238
- var import_keys11 = require("@dxos/keys");
239
- var import_log14 = require("@dxos/log");
240
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
241
+ var import_echo_schema2 = require("@dxos/echo-schema");
242
+ var import_invariant15 = require("@dxos/invariant");
243
+ var import_keys12 = require("@dxos/keys");
244
+ var import_log13 = require("@dxos/log");
240
245
  var import_messaging = require("@dxos/messaging");
241
246
  var import_network_manager2 = require("@dxos/network-manager");
242
- var import_protocols15 = require("@dxos/protocols");
243
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
244
- var import_tracing7 = require("@dxos/tracing");
247
+ var import_protocols13 = require("@dxos/protocols");
248
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
249
+ var import_tracing8 = require("@dxos/tracing");
245
250
  var import_util9 = require("@dxos/util");
246
251
  var import_websocket_rpc = require("@dxos/websocket-rpc");
247
252
  var import_async17 = require("@dxos/async");
248
253
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
254
+ var import_invariant16 = require("@dxos/invariant");
255
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
249
256
  var import_invariant17 = require("@dxos/invariant");
250
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
257
+ var import_lock_file = require("@dxos/lock-file");
258
+ var import_log14 = require("@dxos/log");
251
259
  var import_async18 = require("@dxos/async");
252
260
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
253
- var import_keys12 = require("@dxos/keys");
261
+ var import_keys13 = require("@dxos/keys");
254
262
  var import_log15 = require("@dxos/log");
255
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
263
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
256
264
  var import_util10 = require("@dxos/util");
257
265
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
258
- var import_codec_protobuf15 = require("@dxos/codec-protobuf");
259
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
266
+ var import_protocols14 = require("@dxos/protocols");
267
+ var import_config2 = require("@dxos/protocols/proto/dxos/config");
268
+ var import_random_access_storage = require("@dxos/random-access-storage");
269
+ var import_client_protocol6 = require("@dxos/client-protocol");
270
+ var import_config3 = require("@dxos/protocols/proto/dxos/config");
260
271
  var import_util11 = require("@dxos/util");
272
+ var import_level = require("level");
273
+ var import_node_path = __toESM(require("node:path"));
274
+ var import_keys14 = require("@dxos/keys");
275
+ var import_codec_protobuf15 = require("@dxos/codec-protobuf");
276
+ var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
277
+ var import_util12 = require("@dxos/util");
278
+ var import_keys15 = require("@dxos/keys");
279
+ var import_util13 = require("@dxos/util");
261
280
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
262
281
  return new import_codec_protobuf.Stream(({ next }) => {
263
282
  const subscriptions = new import_async.EventSubscriptions();
@@ -1275,7 +1294,9 @@ var IdentityManager = class {
1275
1294
  C: (f, a) => f(...a)
1276
1295
  });
1277
1296
  },
1278
- memberKey: identityKey
1297
+ memberKey: identityKey,
1298
+ onDelegatedInvitationStatusChange: async () => {
1299
+ }
1279
1300
  });
1280
1301
  }
1281
1302
  };
@@ -1372,10 +1393,13 @@ var DeviceInvitationProtocol = class {
1372
1393
  kind: import_services2.Invitation.Kind.DEVICE
1373
1394
  };
1374
1395
  }
1375
- async admit(request) {
1396
+ async delegate(invitation) {
1397
+ throw new Error("delegation not supported");
1398
+ }
1399
+ async admit(_, request) {
1376
1400
  (0, import_invariant4.invariant)(request.device, void 0, {
1377
1401
  F: __dxlog_file5,
1378
- L: 37,
1402
+ L: 42,
1379
1403
  S: this,
1380
1404
  A: [
1381
1405
  "request.device",
@@ -1421,7 +1445,7 @@ var DeviceInvitationProtocol = class {
1421
1445
  async accept(response, request) {
1422
1446
  (0, import_invariant4.invariant)(response.device, void 0, {
1423
1447
  F: __dxlog_file5,
1424
- L: 82,
1448
+ L: 87,
1425
1449
  S: this,
1426
1450
  A: [
1427
1451
  "response.device",
@@ -1431,7 +1455,7 @@ var DeviceInvitationProtocol = class {
1431
1455
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1432
1456
  (0, import_invariant4.invariant)(request.device, void 0, {
1433
1457
  F: __dxlog_file5,
1434
- L: 85,
1458
+ L: 90,
1435
1459
  S: this,
1436
1460
  A: [
1437
1461
  "request.device",
@@ -1470,6 +1494,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1470
1494
  this._callbacks = _callbacks;
1471
1495
  this._ctx = new import_context5.Context();
1472
1496
  this._remoteOptionsTrigger = new import_async8.Trigger();
1497
+ this._challenge = void 0;
1473
1498
  this.invitation = void 0;
1474
1499
  this.guestProfile = void 0;
1475
1500
  this.authenticationPassed = false;
@@ -1484,7 +1509,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1484
1509
  options: async (options) => {
1485
1510
  (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1486
1511
  F: __dxlog_file6,
1487
- L: 87,
1512
+ L: 90,
1488
1513
  S: this,
1489
1514
  A: [
1490
1515
  "!this._remoteOptions",
@@ -1501,7 +1526,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1501
1526
  id: traceId
1502
1527
  }), {
1503
1528
  F: __dxlog_file6,
1504
- L: 96,
1529
+ L: 99,
1505
1530
  S: this,
1506
1531
  C: (f, a) => f(...a)
1507
1532
  });
@@ -1511,7 +1536,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1511
1536
  invitationId
1512
1537
  }, {
1513
1538
  F: __dxlog_file6,
1514
- L: 100,
1539
+ L: 103,
1515
1540
  S: this,
1516
1541
  C: (f, a) => f(...a)
1517
1542
  });
@@ -1525,7 +1550,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1525
1550
  guestProfile: profile
1526
1551
  }, {
1527
1552
  F: __dxlog_file6,
1528
- L: 109,
1553
+ L: 112,
1529
1554
  S: this,
1530
1555
  C: (f, a) => f(...a)
1531
1556
  });
@@ -1534,25 +1559,27 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1534
1559
  ...this.invitation,
1535
1560
  state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
1536
1561
  });
1562
+ this._challenge = this.invitation.authMethod === import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
1537
1563
  import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1538
1564
  id: traceId
1539
1565
  }), {
1540
1566
  F: __dxlog_file6,
1541
- L: 116,
1567
+ L: 122,
1542
1568
  S: this,
1543
1569
  C: (f, a) => f(...a)
1544
1570
  });
1545
1571
  return {
1546
- authMethod: this.invitation.authMethod
1572
+ authMethod: this.invitation.authMethod,
1573
+ challenge: this._challenge
1547
1574
  };
1548
1575
  },
1549
- authenticate: async ({ authCode: code }) => {
1576
+ authenticate: async ({ authCode: code, signedChallenge }) => {
1550
1577
  const traceId = import_keys6.PublicKey.random().toHex();
1551
1578
  import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1552
1579
  id: traceId
1553
1580
  }), {
1554
1581
  F: __dxlog_file6,
1555
- L: 124,
1582
+ L: 131,
1556
1583
  S: this,
1557
1584
  C: (f, a) => f(...a)
1558
1585
  });
@@ -1560,14 +1587,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1560
1587
  authCode: code
1561
1588
  }, {
1562
1589
  F: __dxlog_file6,
1563
- L: 125,
1590
+ L: 132,
1564
1591
  S: this,
1565
1592
  C: (f, a) => f(...a)
1566
1593
  });
1567
1594
  let status = import_invitations2.AuthenticationResponse.Status.OK;
1568
1595
  (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1569
1596
  F: __dxlog_file6,
1570
- L: 128,
1597
+ L: 135,
1571
1598
  S: this,
1572
1599
  A: [
1573
1600
  "this.invitation",
@@ -1578,7 +1605,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1578
1605
  case import_services4.Invitation.AuthMethod.NONE: {
1579
1606
  (0, import_log5.log)("authentication not required", void 0, {
1580
1607
  F: __dxlog_file6,
1581
- L: 131,
1608
+ L: 138,
1582
1609
  S: this,
1583
1610
  C: (f, a) => f(...a)
1584
1611
  });
@@ -1598,12 +1625,25 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1598
1625
  }
1599
1626
  break;
1600
1627
  }
1628
+ case import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY: {
1629
+ if (!this.invitation.guestKeypair) {
1630
+ status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1631
+ break;
1632
+ }
1633
+ const isSignatureValid = this._challenge && (0, import_crypto2.verify)(this._challenge, Buffer.from(signedChallenge ?? []), this.invitation.guestKeypair.publicKey.asBuffer());
1634
+ if (isSignatureValid) {
1635
+ this.authenticationPassed = true;
1636
+ } else {
1637
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_SIGNATURE;
1638
+ }
1639
+ break;
1640
+ }
1601
1641
  default: {
1602
1642
  import_log5.log.error("invalid authentication method", {
1603
1643
  authMethod: this.invitation.authMethod
1604
1644
  }, {
1605
1645
  F: __dxlog_file6,
1606
- L: 149,
1646
+ L: 176,
1607
1647
  S: this,
1608
1648
  C: (f, a) => f(...a)
1609
1649
  });
@@ -1618,7 +1658,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1618
1658
  }
1619
1659
  }), {
1620
1660
  F: __dxlog_file6,
1621
- L: 155,
1661
+ L: 182,
1622
1662
  S: this,
1623
1663
  C: (f, a) => f(...a)
1624
1664
  });
@@ -1632,14 +1672,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1632
1672
  id: traceId
1633
1673
  }), {
1634
1674
  F: __dxlog_file6,
1635
- L: 161,
1675
+ L: 188,
1636
1676
  S: this,
1637
1677
  C: (f, a) => f(...a)
1638
1678
  });
1639
1679
  try {
1640
1680
  (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1641
1681
  F: __dxlog_file6,
1642
- L: 164,
1682
+ L: 191,
1643
1683
  S: this,
1644
1684
  A: [
1645
1685
  "this.invitation",
@@ -1654,7 +1694,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1654
1694
  id: traceId
1655
1695
  }), {
1656
1696
  F: __dxlog_file6,
1657
- L: 172,
1697
+ L: 199,
1658
1698
  S: this,
1659
1699
  C: (f, a) => f(...a)
1660
1700
  });
@@ -1711,7 +1751,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1711
1751
  options: async (options) => {
1712
1752
  (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1713
1753
  F: __dxlog_file6,
1714
- L: 239,
1754
+ L: 266,
1715
1755
  S: this,
1716
1756
  A: [
1717
1757
  "!this._remoteOptions",
@@ -1738,7 +1778,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1738
1778
  try {
1739
1779
  (0, import_log5.log)("begin options", void 0, {
1740
1780
  F: __dxlog_file6,
1741
- L: 260,
1781
+ L: 287,
1742
1782
  S: this,
1743
1783
  C: (f, a) => f(...a)
1744
1784
  });
@@ -1750,7 +1790,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1750
1790
  }));
1751
1791
  (0, import_log5.log)("end options", void 0, {
1752
1792
  F: __dxlog_file6,
1753
- L: 263,
1793
+ L: 290,
1754
1794
  S: this,
1755
1795
  C: (f, a) => f(...a)
1756
1796
  });
@@ -1764,7 +1804,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1764
1804
  } catch (err) {
1765
1805
  (0, import_log5.log)("openError", err, {
1766
1806
  F: __dxlog_file6,
1767
- L: 273,
1807
+ L: 300,
1768
1808
  S: this,
1769
1809
  C: (f, a) => f(...a)
1770
1810
  });
@@ -1774,7 +1814,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1774
1814
  async onClose() {
1775
1815
  (0, import_log5.log)("onClose", void 0, {
1776
1816
  F: __dxlog_file6,
1777
- L: 279,
1817
+ L: 306,
1778
1818
  S: this,
1779
1819
  C: (f, a) => f(...a)
1780
1820
  });
@@ -1790,49 +1830,7 @@ var InvitationsHandler = class {
1790
1830
  constructor(_networkManager) {
1791
1831
  this._networkManager = _networkManager;
1792
1832
  }
1793
- createInvitation(protocol, options) {
1794
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400 } = options ?? {};
1795
- const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1796
- (0, import_invariant5.invariant)(protocol, void 0, {
1797
- F: __dxlog_file7,
1798
- L: 84,
1799
- S: this,
1800
- A: [
1801
- "protocol",
1802
- ""
1803
- ]
1804
- });
1805
- const invitation = {
1806
- invitationId,
1807
- type,
1808
- authMethod,
1809
- state,
1810
- swarmKey,
1811
- authCode,
1812
- timeout,
1813
- persistent,
1814
- created,
1815
- lifetime,
1816
- ...protocol.getInvitationContext()
1817
- };
1818
- const stream = new import_async7.PushStream();
1819
- const ctx = new import_context4.Context({
1820
- onError: (err) => {
1821
- stream.error(err);
1822
- void ctx.dispose();
1823
- }
1824
- });
1825
- ctx.onDispose(() => {
1826
- (0, import_log4.log)("complete", {
1827
- ...protocol.toJSON()
1828
- }, {
1829
- F: __dxlog_file7,
1830
- L: 109,
1831
- S: this,
1832
- C: (f, a) => f(...a)
1833
- });
1834
- stream.complete();
1835
- });
1833
+ handleInvitationFlow(ctx, stream, protocol, invitation) {
1836
1834
  const createExtension = () => {
1837
1835
  const extension = new InvitationHostExtension({
1838
1836
  onStateUpdate: (invitation2) => {
@@ -1841,8 +1839,8 @@ var InvitationsHandler = class {
1841
1839
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1842
1840
  });
1843
1841
  },
1844
- resolveInvitation: async ({ invitationId: invitationId2 }) => {
1845
- if (invitationId2 && invitationId2 !== invitation.invitationId) {
1842
+ resolveInvitation: async ({ invitationId }) => {
1843
+ if (invitationId && invitationId !== invitation.invitationId) {
1846
1844
  return void 0;
1847
1845
  }
1848
1846
  return invitation;
@@ -1852,14 +1850,14 @@ var InvitationsHandler = class {
1852
1850
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1853
1851
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1854
1852
  F: __dxlog_file7,
1855
- L: 130,
1853
+ L: 87,
1856
1854
  S: this,
1857
1855
  A: [
1858
1856
  "deviceKey",
1859
1857
  ""
1860
1858
  ]
1861
1859
  });
1862
- const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1860
+ const admissionResponse = await protocol.admit(invitation, admissionRequest, extension.guestProfile);
1863
1861
  extension.completedTrigger.wake(deviceKey);
1864
1862
  return admissionResponse;
1865
1863
  } catch (err) {
@@ -1875,7 +1873,7 @@ var InvitationsHandler = class {
1875
1873
  id: traceId
1876
1874
  }), {
1877
1875
  F: __dxlog_file7,
1878
- L: 148,
1876
+ L: 105,
1879
1877
  S: this,
1880
1878
  C: (f, a) => f(...a)
1881
1879
  });
@@ -1883,7 +1881,7 @@ var InvitationsHandler = class {
1883
1881
  ...protocol.toJSON()
1884
1882
  }, {
1885
1883
  F: __dxlog_file7,
1886
- L: 149,
1884
+ L: 106,
1887
1885
  S: this,
1888
1886
  C: (f, a) => f(...a)
1889
1887
  });
@@ -1892,14 +1890,14 @@ var InvitationsHandler = class {
1892
1890
  state: import_services3.Invitation.State.CONNECTED
1893
1891
  });
1894
1892
  const deviceKey = await extension.completedTrigger.wait({
1895
- timeout
1893
+ timeout: invitation.timeout
1896
1894
  });
1897
1895
  (0, import_log4.log)("admitted guest", {
1898
1896
  guest: deviceKey,
1899
1897
  ...protocol.toJSON()
1900
1898
  }, {
1901
1899
  F: __dxlog_file7,
1902
- L: 152,
1900
+ L: 109,
1903
1901
  S: this,
1904
1902
  C: (f, a) => f(...a)
1905
1903
  });
@@ -1911,7 +1909,7 @@ var InvitationsHandler = class {
1911
1909
  id: traceId
1912
1910
  }), {
1913
1911
  F: __dxlog_file7,
1914
- L: 154,
1912
+ L: 111,
1915
1913
  S: this,
1916
1914
  C: (f, a) => f(...a)
1917
1915
  });
@@ -1921,7 +1919,7 @@ var InvitationsHandler = class {
1921
1919
  ...protocol.toJSON()
1922
1920
  }, {
1923
1921
  F: __dxlog_file7,
1924
- L: 157,
1922
+ L: 114,
1925
1923
  S: this,
1926
1924
  C: (f, a) => f(...a)
1927
1925
  });
@@ -1932,7 +1930,7 @@ var InvitationsHandler = class {
1932
1930
  } else {
1933
1931
  import_log4.log.error("failed", err, {
1934
1932
  F: __dxlog_file7,
1935
- L: 160,
1933
+ L: 117,
1936
1934
  S: this,
1937
1935
  C: (f, a) => f(...a)
1938
1936
  });
@@ -1943,12 +1941,12 @@ var InvitationsHandler = class {
1943
1941
  error: err
1944
1942
  }), {
1945
1943
  F: __dxlog_file7,
1946
- L: 163,
1944
+ L: 120,
1947
1945
  S: this,
1948
1946
  C: (f, a) => f(...a)
1949
1947
  });
1950
1948
  } finally {
1951
- if (type !== import_services3.Invitation.Type.MULTIUSE) {
1949
+ if (!invitation.multiUse) {
1952
1950
  await swarmConnection.close();
1953
1951
  await ctx.dispose();
1954
1952
  }
@@ -1964,7 +1962,7 @@ var InvitationsHandler = class {
1964
1962
  ...protocol.toJSON()
1965
1963
  }, {
1966
1964
  F: __dxlog_file7,
1967
- L: 178,
1965
+ L: 135,
1968
1966
  S: this,
1969
1967
  C: (f, a) => f(...a)
1970
1968
  });
@@ -1975,7 +1973,7 @@ var InvitationsHandler = class {
1975
1973
  } else {
1976
1974
  import_log4.log.error("failed", err, {
1977
1975
  F: __dxlog_file7,
1978
- L: 181,
1976
+ L: 138,
1979
1977
  S: this,
1980
1978
  C: (f, a) => f(...a)
1981
1979
  });
@@ -1985,11 +1983,11 @@ var InvitationsHandler = class {
1985
1983
  });
1986
1984
  return extension;
1987
1985
  };
1988
- if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
1986
+ if (invitation.lifetime && invitation.created) {
1989
1987
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1990
1988
  import_log4.log.warn("invitation has already expired", void 0, {
1991
1989
  F: __dxlog_file7,
1992
- L: 192,
1990
+ L: 149,
1993
1991
  S: this,
1994
1992
  C: (f, a) => f(...a)
1995
1993
  });
@@ -2023,24 +2021,12 @@ var InvitationsHandler = class {
2023
2021
  state: import_services3.Invitation.State.CONNECTING
2024
2022
  });
2025
2023
  });
2026
- const observable = new import_client_protocol2.CancellableInvitation({
2027
- initialInvitation: invitation,
2028
- subscriber: stream.observable,
2029
- onCancel: async () => {
2030
- stream.next({
2031
- ...invitation,
2032
- state: import_services3.Invitation.State.CANCELLED
2033
- });
2034
- await ctx.dispose();
2035
- }
2036
- });
2037
- return observable;
2038
2024
  }
2039
2025
  acceptInvitation(protocol, invitation, deviceProfile) {
2040
2026
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2041
2027
  (0, import_invariant5.invariant)(protocol, void 0, {
2042
2028
  F: __dxlog_file7,
2043
- L: 246,
2029
+ L: 191,
2044
2030
  S: this,
2045
2031
  A: [
2046
2032
  "protocol",
@@ -2050,7 +2036,7 @@ var InvitationsHandler = class {
2050
2036
  if (deviceProfile) {
2051
2037
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2052
2038
  F: __dxlog_file7,
2053
- L: 250,
2039
+ L: 194,
2054
2040
  S: this,
2055
2041
  A: [
2056
2042
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2065,7 +2051,7 @@ var InvitationsHandler = class {
2065
2051
  const setState = (newData) => {
2066
2052
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2067
2053
  F: __dxlog_file7,
2068
- L: 261,
2054
+ L: 205,
2069
2055
  S: this,
2070
2056
  A: [
2071
2057
  "newData.state !== undefined",
@@ -2085,7 +2071,7 @@ var InvitationsHandler = class {
2085
2071
  ...protocol.toJSON()
2086
2072
  }, {
2087
2073
  F: __dxlog_file7,
2088
- L: 269,
2074
+ L: 213,
2089
2075
  S: this,
2090
2076
  C: (f, a) => f(...a)
2091
2077
  });
@@ -2095,7 +2081,7 @@ var InvitationsHandler = class {
2095
2081
  } else {
2096
2082
  import_log4.log.warn("auth failed", err, {
2097
2083
  F: __dxlog_file7,
2098
- L: 272,
2084
+ L: 216,
2099
2085
  S: this,
2100
2086
  C: (f, a) => f(...a)
2101
2087
  });
@@ -2109,7 +2095,7 @@ var InvitationsHandler = class {
2109
2095
  ...protocol.toJSON()
2110
2096
  }, {
2111
2097
  F: __dxlog_file7,
2112
- L: 280,
2098
+ L: 224,
2113
2099
  S: this,
2114
2100
  C: (f, a) => f(...a)
2115
2101
  });
@@ -2124,7 +2110,7 @@ var InvitationsHandler = class {
2124
2110
  currentState
2125
2111
  }, {
2126
2112
  F: __dxlog_file7,
2127
- L: 290,
2113
+ L: 234,
2128
2114
  S: this,
2129
2115
  C: (f, a) => f(...a)
2130
2116
  });
@@ -2139,7 +2125,7 @@ var InvitationsHandler = class {
2139
2125
  id: traceId
2140
2126
  }), {
2141
2127
  F: __dxlog_file7,
2142
- L: 299,
2128
+ L: 243,
2143
2129
  S: this,
2144
2130
  C: (f, a) => f(...a)
2145
2131
  });
@@ -2151,7 +2137,7 @@ var InvitationsHandler = class {
2151
2137
  ...protocol.toJSON()
2152
2138
  }, {
2153
2139
  F: __dxlog_file7,
2154
- L: 307,
2140
+ L: 251,
2155
2141
  S: this,
2156
2142
  C: (f, a) => f(...a)
2157
2143
  });
@@ -2162,7 +2148,7 @@ var InvitationsHandler = class {
2162
2148
  ...protocol.toJSON()
2163
2149
  }, {
2164
2150
  F: __dxlog_file7,
2165
- L: 311,
2151
+ L: 255,
2166
2152
  S: this,
2167
2153
  C: (f, a) => f(...a)
2168
2154
  });
@@ -2172,62 +2158,28 @@ var InvitationsHandler = class {
2172
2158
  response: introductionResponse
2173
2159
  }, {
2174
2160
  F: __dxlog_file7,
2175
- L: 315,
2161
+ L: 259,
2176
2162
  S: this,
2177
2163
  C: (f, a) => f(...a)
2178
2164
  });
2179
2165
  invitation.authMethod = introductionResponse.authMethod;
2180
2166
  if (isAuthenticationRequired(invitation)) {
2181
- for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2182
- (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2183
- F: __dxlog_file7,
2184
- L: 321,
2185
- S: this,
2186
- C: (f, a) => f(...a)
2187
- });
2188
- setState({
2189
- state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
2190
- });
2191
- const authCode = await authenticated.wait({
2192
- timeout
2193
- });
2194
- (0, import_log4.log)("sending authentication request", void 0, {
2195
- F: __dxlog_file7,
2196
- L: 325,
2197
- S: this,
2198
- C: (f, a) => f(...a)
2199
- });
2200
- setState({
2201
- state: import_services3.Invitation.State.AUTHENTICATING
2202
- });
2203
- const response = await extension.rpc.InvitationHostService.authenticate({
2204
- authCode
2205
- });
2206
- if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
2167
+ switch (invitation.authMethod) {
2168
+ case import_services3.Invitation.AuthMethod.SHARED_SECRET:
2169
+ await this._handleGuestOtpAuth(extension, setState, authenticated, {
2170
+ timeout
2171
+ });
2172
+ break;
2173
+ case import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY:
2174
+ await this._handleGuestKpkAuth(extension, setState, invitation, introductionResponse);
2207
2175
  break;
2208
- }
2209
- if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
2210
- if (attempt === MAX_OTP_ATTEMPTS) {
2211
- throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2212
- } else {
2213
- (0, import_log4.log)("retrying invalid code", {
2214
- attempt
2215
- }, {
2216
- F: __dxlog_file7,
2217
- L: 336,
2218
- S: this,
2219
- C: (f, a) => f(...a)
2220
- });
2221
- authenticated.reset();
2222
- }
2223
- }
2224
2176
  }
2225
2177
  }
2226
2178
  (0, import_log4.log)("request admission", {
2227
2179
  ...protocol.toJSON()
2228
2180
  }, {
2229
2181
  F: __dxlog_file7,
2230
- L: 344,
2182
+ L: 275,
2231
2183
  S: this,
2232
2184
  C: (f, a) => f(...a)
2233
2185
  });
@@ -2239,7 +2191,7 @@ var InvitationsHandler = class {
2239
2191
  ...protocol.toJSON()
2240
2192
  }, {
2241
2193
  F: __dxlog_file7,
2242
- L: 355,
2194
+ L: 286,
2243
2195
  S: this,
2244
2196
  C: (f, a) => f(...a)
2245
2197
  });
@@ -2252,7 +2204,7 @@ var InvitationsHandler = class {
2252
2204
  id: traceId
2253
2205
  }), {
2254
2206
  F: __dxlog_file7,
2255
- L: 357,
2207
+ L: 288,
2256
2208
  S: this,
2257
2209
  C: (f, a) => f(...a)
2258
2210
  });
@@ -2262,7 +2214,7 @@ var InvitationsHandler = class {
2262
2214
  ...protocol.toJSON()
2263
2215
  }, {
2264
2216
  F: __dxlog_file7,
2265
- L: 360,
2217
+ L: 291,
2266
2218
  S: this,
2267
2219
  C: (f, a) => f(...a)
2268
2220
  });
@@ -2272,7 +2224,7 @@ var InvitationsHandler = class {
2272
2224
  } else {
2273
2225
  (0, import_log4.log)("auth failed", err, {
2274
2226
  F: __dxlog_file7,
2275
- L: 363,
2227
+ L: 294,
2276
2228
  S: this,
2277
2229
  C: (f, a) => f(...a)
2278
2230
  });
@@ -2283,7 +2235,7 @@ var InvitationsHandler = class {
2283
2235
  error: err
2284
2236
  }), {
2285
2237
  F: __dxlog_file7,
2286
- L: 366,
2238
+ L: 297,
2287
2239
  S: this,
2288
2240
  C: (f, a) => f(...a)
2289
2241
  });
@@ -2301,7 +2253,7 @@ var InvitationsHandler = class {
2301
2253
  ...protocol.toJSON()
2302
2254
  }, {
2303
2255
  F: __dxlog_file7,
2304
- L: 377,
2256
+ L: 308,
2305
2257
  S: this,
2306
2258
  C: (f, a) => f(...a)
2307
2259
  });
@@ -2311,7 +2263,7 @@ var InvitationsHandler = class {
2311
2263
  } else {
2312
2264
  (0, import_log4.log)("auth failed", err, {
2313
2265
  F: __dxlog_file7,
2314
- L: 380,
2266
+ L: 311,
2315
2267
  S: this,
2316
2268
  C: (f, a) => f(...a)
2317
2269
  });
@@ -2328,7 +2280,7 @@ var InvitationsHandler = class {
2328
2280
  } else {
2329
2281
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2330
2282
  F: __dxlog_file7,
2331
- L: 394,
2283
+ L: 325,
2332
2284
  S: this,
2333
2285
  A: [
2334
2286
  "invitation.swarmKey",
@@ -2366,198 +2318,110 @@ var InvitationsHandler = class {
2366
2318
  });
2367
2319
  return observable;
2368
2320
  }
2321
+ async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2322
+ for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2323
+ (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2324
+ F: __dxlog_file7,
2325
+ L: 365,
2326
+ S: this,
2327
+ C: (f, a) => f(...a)
2328
+ });
2329
+ setState({
2330
+ state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
2331
+ });
2332
+ const authCode = await authenticated.wait(options);
2333
+ (0, import_log4.log)("sending authentication request", void 0, {
2334
+ F: __dxlog_file7,
2335
+ L: 369,
2336
+ S: this,
2337
+ C: (f, a) => f(...a)
2338
+ });
2339
+ setState({
2340
+ state: import_services3.Invitation.State.AUTHENTICATING
2341
+ });
2342
+ const response = await extension.rpc.InvitationHostService.authenticate({
2343
+ authCode
2344
+ });
2345
+ if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
2346
+ break;
2347
+ }
2348
+ if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
2349
+ if (attempt === MAX_OTP_ATTEMPTS) {
2350
+ throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2351
+ } else {
2352
+ (0, import_log4.log)("retrying invalid code", {
2353
+ attempt
2354
+ }, {
2355
+ F: __dxlog_file7,
2356
+ L: 380,
2357
+ S: this,
2358
+ C: (f, a) => f(...a)
2359
+ });
2360
+ authenticated.reset();
2361
+ }
2362
+ }
2363
+ }
2364
+ }
2365
+ async _handleGuestKpkAuth(extension, setState, invitation, introductionResponse) {
2366
+ if (invitation.guestKeypair?.privateKey == null) {
2367
+ throw new Error("keypair missing in the invitation");
2368
+ }
2369
+ if (introductionResponse.challenge == null) {
2370
+ throw new Error("challenge missing in the introduction");
2371
+ }
2372
+ (0, import_log4.log)("sending authentication request", void 0, {
2373
+ F: __dxlog_file7,
2374
+ L: 399,
2375
+ S: this,
2376
+ C: (f, a) => f(...a)
2377
+ });
2378
+ setState({
2379
+ state: import_services3.Invitation.State.AUTHENTICATING
2380
+ });
2381
+ const signature = (0, import_crypto.sign)(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
2382
+ const response = await extension.rpc.InvitationHostService.authenticate({
2383
+ signedChallenge: signature
2384
+ });
2385
+ if (response.status !== import_invitations.AuthenticationResponse.Status.OK) {
2386
+ throw new Error(`Authentication failed with code: ${response.status}`);
2387
+ }
2388
+ }
2369
2389
  };
2370
- var invitationExpired = (invitation) => {
2371
- return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2390
+ var createAdmissionKeypair = () => {
2391
+ const keypair = (0, import_crypto.createKeyPair)();
2392
+ return {
2393
+ publicKey: import_keys5.PublicKey.from(keypair.publicKey),
2394
+ privateKey: keypair.secretKey
2395
+ };
2372
2396
  };
2373
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2374
2397
  var InvitationsServiceImpl = class {
2375
- constructor(_invitationsHandler, _getHandler, _metadataStore) {
2376
- this._invitationsHandler = _invitationsHandler;
2377
- this._getHandler = _getHandler;
2378
- this._metadataStore = _metadataStore;
2379
- this._createInvitations = /* @__PURE__ */ new Map();
2380
- this._acceptInvitations = /* @__PURE__ */ new Map();
2381
- this._invitationCreated = new import_async9.Event();
2382
- this._invitationAccepted = new import_async9.Event();
2383
- this._removedCreated = new import_async9.Event();
2384
- this._removedAccepted = new import_async9.Event();
2385
- this._saved = new import_async9.Event();
2386
- this._persistentInvitationsLoadedEvent = new import_async9.Event();
2387
- this._persistentInvitationsLoaded = false;
2398
+ constructor(_invitationsManager) {
2399
+ this._invitationsManager = _invitationsManager;
2388
2400
  }
2389
2401
  // TODO(burdon): Guest/host label.
2390
2402
  getLoggingContext() {
2391
2403
  return {};
2392
2404
  }
2393
2405
  createInvitation(options) {
2394
- let invitation;
2395
- const savePersistentInvitationCtx = new import_context6.Context();
2396
- const existingInvitation = this._createInvitations.get(options.invitationId);
2397
- if (existingInvitation) {
2398
- invitation = existingInvitation;
2399
- } else {
2400
- const handler = this._getHandler(options);
2401
- invitation = this._invitationsHandler.createInvitation(handler, options);
2402
- this._createInvitations.set(invitation.get().invitationId, invitation);
2403
- this._invitationCreated.emit(invitation.get());
2404
- }
2405
2406
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2406
- if (invitation.get().persistent) {
2407
- (0, import_async9.scheduleTask)(savePersistentInvitationCtx, async () => {
2408
- try {
2409
- await this._metadataStore.addInvitation(invitation.get());
2410
- this._saved.emit(invitation.get());
2411
- } catch (err) {
2412
- close(err);
2413
- }
2414
- });
2415
- }
2416
- invitation.subscribe((invitation2) => {
2417
- next(invitation2);
2418
- }, async (err) => {
2419
- await savePersistentInvitationCtx.dispose();
2420
- close(err);
2421
- }, async () => {
2422
- close();
2423
- if (invitation.get().persistent) {
2424
- await savePersistentInvitationCtx.dispose();
2425
- await this._metadataStore.removeInvitation(invitation.get().invitationId);
2426
- }
2427
- this._createInvitations.delete(invitation.get().invitationId);
2428
- if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2429
- this._removedCreated.emit(invitation.get());
2430
- }
2431
- });
2407
+ void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
2432
2408
  });
2433
2409
  }
2434
- async loadPersistentInvitations() {
2435
- const persistentInvitations = this._metadataStore.getInvitations();
2436
- const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2437
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2438
- (0, import_invariant7.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2439
- F: __dxlog_file8,
2440
- L: 109,
2441
- S: this,
2442
- A: [
2443
- "!this._createInvitations.get(persistentInvitation.invitationId)",
2444
- "'invitation already exists'"
2445
- ]
2446
- });
2447
- const handler = this._getHandler(persistentInvitation);
2448
- const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2449
- this._createInvitations.set(invitation.get().invitationId, invitation);
2450
- this._invitationCreated.emit(invitation.get());
2451
- return persistentInvitation;
2452
- });
2453
- this._persistentInvitationsLoadedEvent.emit();
2454
- this._persistentInvitationsLoaded = true;
2455
- return {
2456
- invitations: cInvitations
2457
- };
2458
- }
2459
- acceptInvitation({ invitation: options, deviceProfile }) {
2460
- let invitation;
2461
- if (deviceProfile) {
2462
- (0, import_invariant7.invariant)(options.kind === import_services5.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2463
- F: __dxlog_file8,
2464
- L: 127,
2465
- S: this,
2466
- A: [
2467
- "options.kind === Invitation.Kind.DEVICE",
2468
- "'deviceProfile provided for non-device invitation'"
2469
- ]
2470
- });
2471
- }
2472
- const existingInvitation = this._acceptInvitations.get(options.invitationId);
2473
- if (existingInvitation) {
2474
- invitation = existingInvitation;
2475
- } else {
2476
- const handler = this._getHandler(options);
2477
- invitation = this._invitationsHandler.acceptInvitation(handler, options, deviceProfile);
2478
- this._acceptInvitations.set(invitation.get().invitationId, invitation);
2479
- this._invitationAccepted.emit(invitation.get());
2480
- }
2410
+ acceptInvitation(request) {
2411
+ const invitation = this._invitationsManager.acceptInvitation(request);
2481
2412
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2482
- invitation.subscribe((invitation2) => {
2483
- next(invitation2);
2484
- }, (err) => {
2485
- close(err);
2486
- }, () => {
2487
- close();
2488
- this._acceptInvitations.delete(invitation.get().invitationId);
2489
- if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2490
- this._removedAccepted.emit(invitation.get());
2491
- }
2492
- });
2413
+ invitation.subscribe(next, close, close);
2493
2414
  });
2494
2415
  }
2495
- async authenticate({ invitationId, authCode }) {
2496
- (0, import_log6.log)("authenticating...", void 0, {
2497
- F: __dxlog_file8,
2498
- L: 160,
2499
- S: this,
2500
- C: (f, a) => f(...a)
2501
- });
2502
- (0, import_invariant7.invariant)(invitationId, void 0, {
2503
- F: __dxlog_file8,
2504
- L: 161,
2505
- S: this,
2506
- A: [
2507
- "invitationId",
2508
- ""
2509
- ]
2510
- });
2511
- const observable = this._acceptInvitations.get(invitationId);
2512
- if (!observable) {
2513
- import_log6.log.warn("invalid invitation", {
2514
- invitationId
2515
- }, {
2516
- F: __dxlog_file8,
2517
- L: 164,
2518
- S: this,
2519
- C: (f, a) => f(...a)
2520
- });
2521
- } else {
2522
- await observable.authenticate(authCode);
2523
- }
2416
+ async authenticate(request) {
2417
+ return this._invitationsManager.authenticate(request);
2524
2418
  }
2525
- async cancelInvitation({ invitationId }) {
2526
- (0, import_log6.log)("cancelInvitation...", {
2527
- invitationId
2528
- }, {
2529
- F: __dxlog_file8,
2530
- L: 171,
2531
- S: this,
2532
- C: (f, a) => f(...a)
2533
- });
2534
- (0, import_invariant7.invariant)(invitationId, void 0, {
2535
- F: __dxlog_file8,
2536
- L: 172,
2537
- S: this,
2538
- A: [
2539
- "invitationId",
2540
- ""
2541
- ]
2542
- });
2543
- const created = this._createInvitations.get(invitationId);
2544
- const accepted = this._acceptInvitations.get(invitationId);
2545
- if (created) {
2546
- await created.cancel();
2547
- this._createInvitations.delete(invitationId);
2548
- this._removedCreated.emit(created.get());
2549
- if (created.get().persistent) {
2550
- await this._metadataStore.removeInvitation(created.get().invitationId);
2551
- }
2552
- } else if (accepted) {
2553
- await accepted.cancel();
2554
- this._acceptInvitations.delete(invitationId);
2555
- this._removedAccepted.emit(accepted.get());
2556
- }
2419
+ async cancelInvitation(request) {
2420
+ return this._invitationsManager.cancelInvitation(request);
2557
2421
  }
2558
2422
  queryInvitations() {
2559
2423
  return new import_codec_protobuf8.Stream(({ next, ctx }) => {
2560
- this._invitationCreated.on(ctx, (invitation) => {
2424
+ this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
2561
2425
  next({
2562
2426
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2563
2427
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2566,7 +2430,7 @@ var InvitationsServiceImpl = class {
2566
2430
  ]
2567
2431
  });
2568
2432
  });
2569
- this._invitationAccepted.on(ctx, (invitation) => {
2433
+ this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
2570
2434
  next({
2571
2435
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2572
2436
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2575,7 +2439,7 @@ var InvitationsServiceImpl = class {
2575
2439
  ]
2576
2440
  });
2577
2441
  });
2578
- this._removedCreated.on(ctx, (invitation) => {
2442
+ this._invitationsManager.removedCreated.on(ctx, (invitation) => {
2579
2443
  next({
2580
2444
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2581
2445
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2584,7 +2448,7 @@ var InvitationsServiceImpl = class {
2584
2448
  ]
2585
2449
  });
2586
2450
  });
2587
- this._removedAccepted.on(ctx, (invitation) => {
2451
+ this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
2588
2452
  next({
2589
2453
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2590
2454
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2593,7 +2457,7 @@ var InvitationsServiceImpl = class {
2593
2457
  ]
2594
2458
  });
2595
2459
  });
2596
- this._saved.on(ctx, (invitation) => {
2460
+ this._invitationsManager.saved.on(ctx, (invitation) => {
2597
2461
  next({
2598
2462
  action: import_services5.QueryInvitationsResponse.Action.SAVED,
2599
2463
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2605,32 +2469,25 @@ var InvitationsServiceImpl = class {
2605
2469
  next({
2606
2470
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2607
2471
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2608
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2472
+ invitations: this._invitationsManager.getCreatedInvitations(),
2609
2473
  existing: true
2610
2474
  });
2611
2475
  next({
2612
2476
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2613
2477
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2614
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2478
+ invitations: this._invitationsManager.getAcceptedInvitations(),
2615
2479
  existing: true
2616
2480
  });
2617
- if (this._persistentInvitationsLoaded) {
2481
+ this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
2618
2482
  next({
2619
2483
  action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2620
2484
  type: import_services5.QueryInvitationsResponse.Type.CREATED
2621
2485
  });
2622
- } else {
2623
- this._persistentInvitationsLoadedEvent.on(ctx, () => {
2624
- next({
2625
- action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2626
- type: import_services5.QueryInvitationsResponse.Type.CREATED
2627
- });
2628
- });
2629
- }
2486
+ });
2630
2487
  });
2631
2488
  }
2632
2489
  };
2633
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2490
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2634
2491
  var SpaceInvitationProtocol = class {
2635
2492
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2636
2493
  this._spaceManager = _spaceManager;
@@ -2650,10 +2507,10 @@ var SpaceInvitationProtocol = class {
2650
2507
  spaceKey: this._spaceKey
2651
2508
  };
2652
2509
  }
2653
- async admit(request, guestProfile) {
2654
- (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2655
- F: __dxlog_file9,
2656
- L: 47,
2510
+ async admit(invitation, request, guestProfile) {
2511
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2512
+ F: __dxlog_file8,
2513
+ L: 55,
2657
2514
  S: this,
2658
2515
  A: [
2659
2516
  "this._spaceKey",
@@ -2661,18 +2518,18 @@ var SpaceInvitationProtocol = class {
2661
2518
  ]
2662
2519
  });
2663
2520
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2664
- (0, import_invariant8.invariant)(space, void 0, {
2665
- F: __dxlog_file9,
2666
- L: 49,
2521
+ (0, import_invariant7.invariant)(space, void 0, {
2522
+ F: __dxlog_file8,
2523
+ L: 57,
2667
2524
  S: this,
2668
2525
  A: [
2669
2526
  "space",
2670
2527
  ""
2671
2528
  ]
2672
2529
  });
2673
- (0, import_invariant8.invariant)(request.space, void 0, {
2674
- F: __dxlog_file9,
2675
- L: 51,
2530
+ (0, import_invariant7.invariant)(request.space, void 0, {
2531
+ F: __dxlog_file8,
2532
+ L: 59,
2676
2533
  S: this,
2677
2534
  A: [
2678
2535
  "request.space",
@@ -2680,19 +2537,19 @@ var SpaceInvitationProtocol = class {
2680
2537
  ]
2681
2538
  });
2682
2539
  const { identityKey, deviceKey } = request.space;
2683
- (0, import_log7.log)("writing guest credentials", {
2540
+ (0, import_log6.log)("writing guest credentials", {
2684
2541
  host: this._signingContext.deviceKey,
2685
2542
  guest: deviceKey
2686
2543
  }, {
2687
- F: __dxlog_file9,
2688
- L: 54,
2544
+ F: __dxlog_file8,
2545
+ L: 62,
2689
2546
  S: this,
2690
2547
  C: (f, a) => f(...a)
2691
2548
  });
2692
- const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2693
- (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2694
- F: __dxlog_file9,
2695
- L: 65,
2549
+ const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2550
+ (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2551
+ F: __dxlog_file8,
2552
+ L: 74,
2696
2553
  S: this,
2697
2554
  A: [
2698
2555
  "credentials[0].credential",
@@ -2700,9 +2557,9 @@ var SpaceInvitationProtocol = class {
2700
2557
  ]
2701
2558
  });
2702
2559
  const spaceMemberCredential = credentials[0].credential.credential;
2703
- (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2704
- F: __dxlog_file9,
2705
- L: 67,
2560
+ (0, import_invariant7.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2561
+ F: __dxlog_file8,
2562
+ L: 76,
2706
2563
  S: this,
2707
2564
  A: [
2708
2565
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2717,6 +2574,69 @@ var SpaceInvitationProtocol = class {
2717
2574
  }
2718
2575
  };
2719
2576
  }
2577
+ async delegate(invitation) {
2578
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2579
+ F: __dxlog_file8,
2580
+ L: 89,
2581
+ S: this,
2582
+ A: [
2583
+ "this._spaceKey",
2584
+ ""
2585
+ ]
2586
+ });
2587
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
2588
+ (0, import_invariant7.invariant)(space, void 0, {
2589
+ F: __dxlog_file8,
2590
+ L: 91,
2591
+ S: this,
2592
+ A: [
2593
+ "space",
2594
+ ""
2595
+ ]
2596
+ });
2597
+ if (invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
2598
+ (0, import_invariant7.invariant)(invitation.guestKeypair?.publicKey, void 0, {
2599
+ F: __dxlog_file8,
2600
+ L: 93,
2601
+ S: this,
2602
+ A: [
2603
+ "invitation.guestKeypair?.publicKey",
2604
+ ""
2605
+ ]
2606
+ });
2607
+ }
2608
+ (0, import_log6.log)("writing delegate space invitation", {
2609
+ host: this._signingContext.deviceKey,
2610
+ id: invitation.invitationId
2611
+ }, {
2612
+ F: __dxlog_file8,
2613
+ L: 96,
2614
+ S: this,
2615
+ C: (f, a) => f(...a)
2616
+ });
2617
+ const credential = await (0, import_credentials7.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
2618
+ invitationId: invitation.invitationId,
2619
+ authMethod: invitation.authMethod,
2620
+ swarmKey: invitation.swarmKey,
2621
+ role: import_credentials8.SpaceMember.Role.ADMIN,
2622
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2623
+ multiUse: invitation.multiUse ?? false,
2624
+ guestKey: invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2625
+ });
2626
+ (0, import_invariant7.invariant)(credential.credential, void 0, {
2627
+ F: __dxlog_file8,
2628
+ L: 116,
2629
+ S: this,
2630
+ A: [
2631
+ "credential.credential",
2632
+ ""
2633
+ ]
2634
+ });
2635
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, [
2636
+ credential
2637
+ ]);
2638
+ return credential.credential.credential.id;
2639
+ }
2720
2640
  checkInvitation(invitation) {
2721
2641
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2722
2642
  return new import_protocols6.AlreadyJoinedError("Already joined space.");
@@ -2740,9 +2660,9 @@ var SpaceInvitationProtocol = class {
2740
2660
  };
2741
2661
  }
2742
2662
  async accept(response) {
2743
- (0, import_invariant8.invariant)(response.space, void 0, {
2744
- F: __dxlog_file9,
2745
- L: 107,
2663
+ (0, import_invariant7.invariant)(response.space, void 0, {
2664
+ F: __dxlog_file8,
2665
+ L: 149,
2746
2666
  S: this,
2747
2667
  A: [
2748
2668
  "response.space",
@@ -2750,19 +2670,19 @@ var SpaceInvitationProtocol = class {
2750
2670
  ]
2751
2671
  });
2752
2672
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2753
- const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2754
- (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2755
- F: __dxlog_file9,
2756
- L: 110,
2673
+ const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
2674
+ (0, import_invariant7.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2675
+ F: __dxlog_file8,
2676
+ L: 152,
2757
2677
  S: this,
2758
2678
  A: [
2759
2679
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
2760
2680
  "'Invalid credential'"
2761
2681
  ]
2762
2682
  });
2763
- (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2764
- F: __dxlog_file9,
2765
- L: 111,
2683
+ (0, import_invariant7.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2684
+ F: __dxlog_file8,
2685
+ L: 153,
2766
2686
  S: this,
2767
2687
  A: [
2768
2688
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2784,6 +2704,284 @@ var SpaceInvitationProtocol = class {
2784
2704
  };
2785
2705
  }
2786
2706
  };
2707
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2708
+ var InvitationsManager = class {
2709
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2710
+ this._invitationsHandler = _invitationsHandler;
2711
+ this._getHandler = _getHandler;
2712
+ this._metadataStore = _metadataStore;
2713
+ this._createInvitations = /* @__PURE__ */ new Map();
2714
+ this._acceptInvitations = /* @__PURE__ */ new Map();
2715
+ this.invitationCreated = new import_async9.Event();
2716
+ this.invitationAccepted = new import_async9.Event();
2717
+ this.removedCreated = new import_async9.Event();
2718
+ this.removedAccepted = new import_async9.Event();
2719
+ this.saved = new import_async9.Event();
2720
+ this._persistentInvitationsLoadedEvent = new import_async9.Event();
2721
+ this._persistentInvitationsLoaded = false;
2722
+ }
2723
+ async createInvitation(options) {
2724
+ if (options.invitationId) {
2725
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2726
+ if (existingInvitation) {
2727
+ return existingInvitation;
2728
+ }
2729
+ }
2730
+ const handler = this._getHandler(options);
2731
+ const invitation = this._createInvitation(handler, options);
2732
+ const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
2733
+ this._createInvitations.set(invitation.invitationId, observableInvitation);
2734
+ this.invitationCreated.emit(invitation);
2735
+ this._onInvitationComplete(observableInvitation, async () => {
2736
+ this._createInvitations.delete(observableInvitation.get().invitationId);
2737
+ this.removedCreated.emit(observableInvitation.get());
2738
+ if (observableInvitation.get().persistent) {
2739
+ await this._safeDeleteInvitation(observableInvitation.get());
2740
+ }
2741
+ });
2742
+ try {
2743
+ await this._persistIfRequired(handler, stream, invitation);
2744
+ } catch (err) {
2745
+ import_log7.log.catch(err, void 0, {
2746
+ F: __dxlog_file9,
2747
+ L: 76,
2748
+ S: this,
2749
+ C: (f, a) => f(...a)
2750
+ });
2751
+ await observableInvitation.cancel();
2752
+ return observableInvitation;
2753
+ }
2754
+ this._invitationsHandler.handleInvitationFlow(ctx, stream, handler, observableInvitation.get());
2755
+ return observableInvitation;
2756
+ }
2757
+ async loadPersistentInvitations() {
2758
+ if (this._persistentInvitationsLoaded) {
2759
+ const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
2760
+ return {
2761
+ invitations
2762
+ };
2763
+ }
2764
+ try {
2765
+ const persistentInvitations = this._metadataStore.getInvitations();
2766
+ const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2767
+ const loadTasks = freshInvitations.map((persistentInvitation) => {
2768
+ (0, import_invariant8.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2769
+ F: __dxlog_file9,
2770
+ L: 97,
2771
+ S: this,
2772
+ A: [
2773
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2774
+ "'invitation already exists'"
2775
+ ]
2776
+ });
2777
+ return this.createInvitation({
2778
+ ...persistentInvitation,
2779
+ persistent: false
2780
+ });
2781
+ });
2782
+ const cInvitations = await Promise.all(loadTasks);
2783
+ return {
2784
+ invitations: cInvitations.map((invitation) => invitation.get())
2785
+ };
2786
+ } catch (err) {
2787
+ import_log7.log.catch(err, void 0, {
2788
+ F: __dxlog_file9,
2789
+ L: 104,
2790
+ S: this,
2791
+ C: (f, a) => f(...a)
2792
+ });
2793
+ return {
2794
+ invitations: []
2795
+ };
2796
+ } finally {
2797
+ this._persistentInvitationsLoadedEvent.emit();
2798
+ this._persistentInvitationsLoaded = true;
2799
+ }
2800
+ }
2801
+ acceptInvitation(request) {
2802
+ const options = request.invitation;
2803
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
2804
+ if (existingInvitation) {
2805
+ return existingInvitation;
2806
+ }
2807
+ const handler = this._getHandler(options);
2808
+ const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
2809
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
2810
+ this.invitationAccepted.emit(invitation.get());
2811
+ this._onInvitationComplete(invitation, () => {
2812
+ this._acceptInvitations.delete(invitation.get().invitationId);
2813
+ this.removedAccepted.emit(invitation.get());
2814
+ });
2815
+ return invitation;
2816
+ }
2817
+ async authenticate({ invitationId, authCode }) {
2818
+ (0, import_log7.log)("authenticating...", void 0, {
2819
+ F: __dxlog_file9,
2820
+ L: 133,
2821
+ S: this,
2822
+ C: (f, a) => f(...a)
2823
+ });
2824
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2825
+ F: __dxlog_file9,
2826
+ L: 134,
2827
+ S: this,
2828
+ A: [
2829
+ "invitationId",
2830
+ ""
2831
+ ]
2832
+ });
2833
+ const observable = this._acceptInvitations.get(invitationId);
2834
+ if (!observable) {
2835
+ import_log7.log.warn("invalid invitation", {
2836
+ invitationId
2837
+ }, {
2838
+ F: __dxlog_file9,
2839
+ L: 137,
2840
+ S: this,
2841
+ C: (f, a) => f(...a)
2842
+ });
2843
+ } else {
2844
+ await observable.authenticate(authCode);
2845
+ }
2846
+ }
2847
+ async cancelInvitation({ invitationId }) {
2848
+ (0, import_log7.log)("cancelInvitation...", {
2849
+ invitationId
2850
+ }, {
2851
+ F: __dxlog_file9,
2852
+ L: 144,
2853
+ S: this,
2854
+ C: (f, a) => f(...a)
2855
+ });
2856
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2857
+ F: __dxlog_file9,
2858
+ L: 145,
2859
+ S: this,
2860
+ A: [
2861
+ "invitationId",
2862
+ ""
2863
+ ]
2864
+ });
2865
+ const created = this._createInvitations.get(invitationId);
2866
+ if (created) {
2867
+ if (created.get().persistent) {
2868
+ await this._metadataStore.removeInvitation(invitationId);
2869
+ }
2870
+ await created.cancel();
2871
+ this._createInvitations.delete(invitationId);
2872
+ this.removedCreated.emit(created.get());
2873
+ return;
2874
+ }
2875
+ const accepted = this._acceptInvitations.get(invitationId);
2876
+ if (accepted) {
2877
+ await accepted.cancel();
2878
+ this._acceptInvitations.delete(invitationId);
2879
+ this.removedAccepted.emit(accepted.get());
2880
+ }
2881
+ }
2882
+ getCreatedInvitations() {
2883
+ return [
2884
+ ...this._createInvitations.values()
2885
+ ].map((i) => i.get());
2886
+ }
2887
+ getAcceptedInvitations() {
2888
+ return [
2889
+ ...this._acceptInvitations.values()
2890
+ ].map((i) => i.get());
2891
+ }
2892
+ onPersistentInvitationsLoaded(ctx, callback) {
2893
+ if (this._persistentInvitationsLoaded) {
2894
+ callback();
2895
+ } else {
2896
+ this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2897
+ }
2898
+ }
2899
+ _createInvitation(protocol, options) {
2900
+ const { invitationId = import_keys7.PublicKey.random().toHex(), type = import_services7.Invitation.Type.INTERACTIVE, authMethod = import_services7.Invitation.AuthMethod.SHARED_SECRET, state = import_services7.Invitation.State.INIT, timeout = import_client_protocol3.INVITATION_TIMEOUT, swarmKey = import_keys7.PublicKey.random(), persistent = options?.authMethod !== import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
2901
+ const authCode = options?.authCode ?? (authMethod === import_services7.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol3.AUTHENTICATION_CODE_LENGTH) : void 0);
2902
+ return {
2903
+ invitationId,
2904
+ type,
2905
+ authMethod,
2906
+ state,
2907
+ swarmKey,
2908
+ authCode,
2909
+ timeout,
2910
+ persistent: persistent && type !== import_services7.Invitation.Type.DELEGATED,
2911
+ guestKeypair: guestKeypair ?? (authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2912
+ created,
2913
+ lifetime,
2914
+ multiUse,
2915
+ delegationCredentialId: options?.delegationCredentialId,
2916
+ ...protocol.getInvitationContext()
2917
+ };
2918
+ }
2919
+ _createObservableInvitation(handler, invitation) {
2920
+ const stream = new import_async9.PushStream();
2921
+ const ctx = new import_context6.Context({
2922
+ onError: (err) => {
2923
+ stream.error(err);
2924
+ void ctx.dispose();
2925
+ }
2926
+ });
2927
+ ctx.onDispose(() => {
2928
+ (0, import_log7.log)("complete", {
2929
+ ...handler.toJSON()
2930
+ }, {
2931
+ F: __dxlog_file9,
2932
+ L: 228,
2933
+ S: this,
2934
+ C: (f, a) => f(...a)
2935
+ });
2936
+ stream.complete();
2937
+ });
2938
+ const observableInvitation = new import_client_protocol3.CancellableInvitation({
2939
+ initialInvitation: invitation,
2940
+ subscriber: stream.observable,
2941
+ onCancel: async () => {
2942
+ stream.next({
2943
+ ...invitation,
2944
+ state: import_services7.Invitation.State.CANCELLED
2945
+ });
2946
+ await ctx.dispose();
2947
+ }
2948
+ });
2949
+ return {
2950
+ ctx,
2951
+ stream,
2952
+ observableInvitation
2953
+ };
2954
+ }
2955
+ async _persistIfRequired(handler, changeStream, invitation) {
2956
+ if (invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId == null) {
2957
+ const delegationCredentialId = await handler.delegate(invitation);
2958
+ changeStream.next({
2959
+ ...invitation,
2960
+ delegationCredentialId
2961
+ });
2962
+ } else if (invitation.persistent) {
2963
+ await this._metadataStore.addInvitation(invitation);
2964
+ this.saved.emit(invitation);
2965
+ }
2966
+ }
2967
+ async _safeDeleteInvitation(invitation) {
2968
+ try {
2969
+ await this._metadataStore.removeInvitation(invitation.invitationId);
2970
+ } catch (err) {
2971
+ import_log7.log.catch(err, void 0, {
2972
+ F: __dxlog_file9,
2973
+ L: 260,
2974
+ S: this,
2975
+ C: (f, a) => f(...a)
2976
+ });
2977
+ }
2978
+ }
2979
+ _onInvitationComplete(invitation, callback) {
2980
+ invitation.subscribe(() => {
2981
+ }, () => {
2982
+ }, callback);
2983
+ }
2984
+ };
2787
2985
  function _ts_decorate3(decorators, target, key, desc) {
2788
2986
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2789
2987
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2811,189 +3009,54 @@ var ClientRpcServer = class {
2811
3009
  if (this._handleCall) {
2812
3010
  return this._handleCall(methodName, params2, handler);
2813
3011
  } else {
2814
- return handler(methodName, params2);
2815
- }
2816
- },
2817
- streamHandler: (method, params2) => {
2818
- const [serviceName, methodName] = (0, import_rpc.parseMethodName)(method);
2819
- const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
2820
- this._callMetrics.inc(`${serviceName}.${methodName} request stream`);
2821
- if (this._handleStream) {
2822
- return import_codec_protobuf9.Stream.map(import_codec_protobuf9.Stream.unwrapPromise(this._handleStream(methodName, params2, handler)), (data) => {
2823
- this._callMetrics.inc(`${serviceName}.${methodName} response stream`);
2824
- return data;
2825
- });
2826
- } else {
2827
- return handler(methodName, params2);
2828
- }
2829
- }
2830
- });
2831
- }
2832
- get _services() {
2833
- return Object.keys(this._serviceRegistry.services);
2834
- }
2835
- async open() {
2836
- await this._rpcPeer.open();
2837
- }
2838
- async close() {
2839
- await this._rpcPeer.close();
2840
- }
2841
- _getServiceHandler(serviceName) {
2842
- if (!this._handlerCache.has(serviceName)) {
2843
- const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? (0, import_debug2.raise)(new Error(`Service not available: ${serviceName}`));
2844
- const service = this._serviceRegistry.services[key];
2845
- if (!service) {
2846
- throw new Error(`Service not available: ${serviceName}`);
2847
- }
2848
- this._handlerCache.set(serviceName, descriptor.createServer(service));
2849
- }
2850
- return this._handlerCache.get(serviceName);
2851
- }
2852
- };
2853
- _ts_decorate3([
2854
- import_tracing3.trace.metricsCounter()
2855
- ], ClientRpcServer.prototype, "_callMetrics", void 0);
2856
- _ts_decorate3([
2857
- import_tracing3.trace.info()
2858
- ], ClientRpcServer.prototype, "_services", null);
2859
- ClientRpcServer = _ts_decorate3([
2860
- import_tracing3.trace.resource()
2861
- ], ClientRpcServer);
2862
- var getPlatform = () => {
2863
- if (process.browser) {
2864
- if (typeof window !== "undefined") {
2865
- const { userAgent } = window.navigator;
2866
- return {
2867
- type: import_services8.Platform.PLATFORM_TYPE.BROWSER,
2868
- userAgent,
2869
- uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2870
- };
2871
- } else {
2872
- return {
2873
- type: import_services8.Platform.PLATFORM_TYPE.SHARED_WORKER,
2874
- uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2875
- };
2876
- }
2877
- } else {
2878
- const { platform: platform2, version, arch } = process;
2879
- return {
2880
- type: import_services8.Platform.PLATFORM_TYPE.NODE,
2881
- platform: platform2,
2882
- arch,
2883
- runtime: version,
2884
- uptime: Math.floor(process.uptime()),
2885
- memory: process.memoryUsage()
2886
- };
2887
- }
2888
- };
2889
- var DXOS_VERSION = "0.4.10-main.35b4a08";
2890
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2891
- var DEFAULT_TIMEOUT = 1e3;
2892
- var createDiagnostics = async (clientServices, serviceContext, config) => {
2893
- const diagnostics = {
2894
- created: (/* @__PURE__ */ new Date()).toISOString(),
2895
- platform: getPlatform(),
2896
- client: {
2897
- version: DXOS_VERSION,
2898
- storage: {
2899
- version: import_protocols7.STORAGE_VERSION
2900
- }
2901
- },
2902
- trace: import_tracing4.TRACE_PROCESSOR.getDiagnostics()
2903
- };
2904
- {
2905
- (0, import_invariant9.invariant)(clientServices.LoggingService, "SystemService is not available.", {
2906
- F: __dxlog_file10,
2907
- L: 108,
2908
- S: void 0,
2909
- A: [
2910
- "clientServices.LoggingService",
2911
- "'SystemService is not available.'"
2912
- ]
2913
- });
2914
- diagnostics.metrics = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
2915
- timeout: DEFAULT_TIMEOUT
2916
- }).catch(() => void 0);
2917
- }
2918
- if (typeof navigator !== "undefined" && navigator.storage) {
2919
- const map = /* @__PURE__ */ new Map();
2920
- const dir = await navigator.storage.getDirectory();
2921
- for await (const filename of dir?.keys()) {
2922
- const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2923
- if (idx === -1) {
2924
- continue;
2925
- }
2926
- map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2927
- }
2928
- diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2929
- file,
2930
- count
2931
- }));
2932
- }
2933
- const identity = serviceContext.identityManager.identity;
2934
- if (identity) {
2935
- diagnostics.identity = {
2936
- identityKey: identity.identityKey,
2937
- spaceKey: identity.space.key,
2938
- profile: identity.profileDocument
2939
- };
2940
- const { devices } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
2941
- timeout: DEFAULT_TIMEOUT
2942
- }).catch(() => void 0) ?? {};
2943
- diagnostics.devices = devices;
2944
- if (serviceContext.dataSpaceManager) {
2945
- diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2946
- }
2947
- const { feeds = [] } = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2948
- timeout: DEFAULT_TIMEOUT
2949
- }).catch(() => void 0) ?? {};
2950
- diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2951
- feedKey,
2952
- bytes,
2953
- length
2954
- }));
2955
- const status = await (0, import_codec_protobuf10.getFirstStreamValue)(clientServices.NetworkService.queryStatus(), {
2956
- timeout: DEFAULT_TIMEOUT
2957
- }).catch(() => void 0);
2958
- diagnostics.networkStatus = status;
2959
- diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
2960
- }
2961
- diagnostics.config = config.values;
2962
- return diagnostics;
2963
- };
2964
- var getSpaceStats = async (space) => {
2965
- const stats = {
2966
- key: space.key,
2967
- metrics: space.metrics,
2968
- epochs: space.inner.spaceState.credentials.filter((0, import_credentials9.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
2969
- ...credential.subject.assertion,
2970
- id: credential.id
2971
- })),
2972
- members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2973
- identity: {
2974
- identityKey: member.key,
2975
- profile: {
2976
- displayName: member.assertion.profile?.displayName
3012
+ return handler(methodName, params2);
2977
3013
  }
2978
3014
  },
2979
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services7.SpaceMember.PresenceState.ONLINE : import_services7.SpaceMember.PresenceState.OFFLINE
2980
- })),
2981
- pipeline: {
2982
- // TODO(burdon): Pick properties from credentials if needed.
2983
- currentEpoch: space.automergeSpaceState.lastEpoch,
2984
- appliedEpoch: space.automergeSpaceState.lastEpoch,
2985
- controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
2986
- currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2987
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2988
- totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
3015
+ streamHandler: (method, params2) => {
3016
+ const [serviceName, methodName] = (0, import_rpc.parseMethodName)(method);
3017
+ const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
3018
+ this._callMetrics.inc(`${serviceName}.${methodName} request stream`);
3019
+ if (this._handleStream) {
3020
+ return import_codec_protobuf9.Stream.map(import_codec_protobuf9.Stream.unwrapPromise(this._handleStream(methodName, params2, handler)), (data) => {
3021
+ this._callMetrics.inc(`${serviceName}.${methodName} response stream`);
3022
+ return data;
3023
+ });
3024
+ } else {
3025
+ return handler(methodName, params2);
3026
+ }
3027
+ }
3028
+ });
3029
+ }
3030
+ get _services() {
3031
+ return Object.keys(this._serviceRegistry.services);
3032
+ }
3033
+ async open() {
3034
+ await this._rpcPeer.open();
3035
+ }
3036
+ async close() {
3037
+ await this._rpcPeer.close();
3038
+ }
3039
+ _getServiceHandler(serviceName) {
3040
+ if (!this._handlerCache.has(serviceName)) {
3041
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? (0, import_debug2.raise)(new Error(`Service not available: ${serviceName}`));
3042
+ const service = this._serviceRegistry.services[key];
3043
+ if (!service) {
3044
+ throw new Error(`Service not available: ${serviceName}`);
3045
+ }
3046
+ this._handlerCache.set(serviceName, descriptor.createServer(service));
2989
3047
  }
2990
- };
2991
- if (stats.metrics) {
2992
- const { open, ready } = stats.metrics;
2993
- stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
3048
+ return this._handlerCache.get(serviceName);
2994
3049
  }
2995
- return stats;
2996
3050
  };
3051
+ _ts_decorate3([
3052
+ import_tracing3.trace.metricsCounter()
3053
+ ], ClientRpcServer.prototype, "_callMetrics", void 0);
3054
+ _ts_decorate3([
3055
+ import_tracing3.trace.info()
3056
+ ], ClientRpcServer.prototype, "_services", null);
3057
+ ClientRpcServer = _ts_decorate3([
3058
+ import_tracing3.trace.resource()
3059
+ ], ClientRpcServer);
2997
3060
  var AutomergeSpaceState = class {
2998
3061
  constructor(_onNewRoot) {
2999
3062
  this._onNewRoot = _onNewRoot;
@@ -3028,7 +3091,7 @@ var AutomergeSpaceState = class {
3028
3091
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
3029
3092
  }
3030
3093
  };
3031
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3094
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3032
3095
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3033
3096
  var DEFAULT_SUCCESS_DELAY = 1e3;
3034
3097
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -3038,8 +3101,8 @@ var NotarizationPlugin = class {
3038
3101
  this._ctx = new import_context8.Context();
3039
3102
  this._extensionOpened = new import_async12.Event();
3040
3103
  this._extensions = /* @__PURE__ */ new Set();
3041
- this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
3042
- this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys8.PublicKey.hash);
3104
+ this._processedCredentials = new import_util5.ComplexSet(import_keys9.PublicKey.hash);
3105
+ this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
3043
3106
  }
3044
3107
  get hasWriter() {
3045
3108
  return !!this._writer;
@@ -3056,13 +3119,13 @@ var NotarizationPlugin = class {
3056
3119
  (0, import_log9.log)("notarize", {
3057
3120
  credentials
3058
3121
  }, {
3059
- F: __dxlog_file11,
3122
+ F: __dxlog_file10,
3060
3123
  L: 90,
3061
3124
  S: this,
3062
3125
  C: (f, a) => f(...a)
3063
3126
  });
3064
- (0, import_invariant11.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3065
- F: __dxlog_file11,
3127
+ (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
3128
+ F: __dxlog_file10,
3066
3129
  L: 91,
3067
3130
  S: this,
3068
3131
  A: [
@@ -3076,7 +3139,7 @@ var NotarizationPlugin = class {
3076
3139
  import_log9.log.warn("Notarization error", {
3077
3140
  err
3078
3141
  }, {
3079
- F: __dxlog_file11,
3142
+ F: __dxlog_file10,
3080
3143
  L: 99,
3081
3144
  S: this,
3082
3145
  C: (f, a) => f(...a)
@@ -3092,7 +3155,7 @@ var NotarizationPlugin = class {
3092
3155
  timeout,
3093
3156
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3094
3157
  }, {
3095
- F: __dxlog_file11,
3158
+ F: __dxlog_file10,
3096
3159
  L: 111,
3097
3160
  S: this,
3098
3161
  C: (f, a) => f(...a)
@@ -3115,7 +3178,7 @@ var NotarizationPlugin = class {
3115
3178
  import_log9.log.info("Exhausted all peers to notarize with", {
3116
3179
  retryIn: retryTimeout
3117
3180
  }, {
3118
- F: __dxlog_file11,
3181
+ F: __dxlog_file10,
3119
3182
  L: 136,
3120
3183
  S: this,
3121
3184
  C: (f, a) => f(...a)
@@ -3129,7 +3192,7 @@ var NotarizationPlugin = class {
3129
3192
  peer: peer.localPeerId,
3130
3193
  credentialId: credentials.map((credential) => credential.id)
3131
3194
  }, {
3132
- F: __dxlog_file11,
3195
+ F: __dxlog_file10,
3133
3196
  L: 143,
3134
3197
  S: this,
3135
3198
  C: (f, a) => f(...a)
@@ -3138,7 +3201,7 @@ var NotarizationPlugin = class {
3138
3201
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3139
3202
  });
3140
3203
  (0, import_log9.log)("success", void 0, {
3141
- F: __dxlog_file11,
3204
+ F: __dxlog_file10,
3142
3205
  L: 147,
3143
3206
  S: this,
3144
3207
  C: (f, a) => f(...a)
@@ -3147,7 +3210,7 @@ var NotarizationPlugin = class {
3147
3210
  } catch (err) {
3148
3211
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3149
3212
  import_log9.log.info("error notarizing (recoverable)", err, {
3150
- F: __dxlog_file11,
3213
+ F: __dxlog_file10,
3151
3214
  L: 151,
3152
3215
  S: this,
3153
3216
  C: (f, a) => f(...a)
@@ -3165,7 +3228,7 @@ var NotarizationPlugin = class {
3165
3228
  errors.wait()
3166
3229
  ]);
3167
3230
  (0, import_log9.log)("done", void 0, {
3168
- F: __dxlog_file11,
3231
+ F: __dxlog_file10,
3169
3232
  L: 162,
3170
3233
  S: this,
3171
3234
  C: (f, a) => f(...a)
@@ -3186,8 +3249,8 @@ var NotarizationPlugin = class {
3186
3249
  this._processCredentialsTriggers.delete(credential.id);
3187
3250
  }
3188
3251
  setWriter(writer) {
3189
- (0, import_invariant11.invariant)(!this._writer, "Writer already set.", {
3190
- F: __dxlog_file11,
3252
+ (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
3253
+ F: __dxlog_file10,
3191
3254
  L: 181,
3192
3255
  S: this,
3193
3256
  A: [
@@ -3211,8 +3274,8 @@ var NotarizationPlugin = class {
3211
3274
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3212
3275
  }
3213
3276
  for (const credential of request.credentials ?? []) {
3214
- (0, import_invariant11.invariant)(credential.id, "Credential must have an id", {
3215
- F: __dxlog_file11,
3277
+ (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
3278
+ F: __dxlog_file10,
3216
3279
  L: 200,
3217
3280
  S: this,
3218
3281
  A: [
@@ -3232,7 +3295,7 @@ var NotarizationPlugin = class {
3232
3295
  (0, import_log9.log)("extension opened", {
3233
3296
  peer: extension.localPeerId
3234
3297
  }, {
3235
- F: __dxlog_file11,
3298
+ F: __dxlog_file10,
3236
3299
  L: 211,
3237
3300
  S: this,
3238
3301
  C: (f, a) => f(...a)
@@ -3244,7 +3307,7 @@ var NotarizationPlugin = class {
3244
3307
  (0, import_log9.log)("extension closed", {
3245
3308
  peer: extension.localPeerId
3246
3309
  }, {
3247
- F: __dxlog_file11,
3310
+ F: __dxlog_file10,
3248
3311
  L: 216,
3249
3312
  S: this,
3250
3313
  C: (f, a) => f(...a)
@@ -3260,10 +3323,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
3260
3323
  constructor(_params) {
3261
3324
  super({
3262
3325
  requested: {
3263
- NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3326
+ NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3264
3327
  },
3265
3328
  exposed: {
3266
- NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3329
+ NotarizationService: import_protocols8.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3267
3330
  }
3268
3331
  });
3269
3332
  this._params = _params;
@@ -3296,14 +3359,14 @@ function _ts_decorate4(decorators, target, key, desc) {
3296
3359
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3297
3360
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3298
3361
  }
3299
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3362
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3300
3363
  var DataSpace = class {
3301
3364
  constructor(params) {
3302
3365
  this._ctx = new import_context7.Context();
3303
3366
  this._notarizationPlugin = new NotarizationPlugin();
3304
3367
  this._cache = void 0;
3305
3368
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3306
- this._state = import_services9.SpaceState.CLOSED;
3369
+ this._state = import_services8.SpaceState.CLOSED;
3307
3370
  this.error = void 0;
3308
3371
  this.stateUpdate = new import_async10.Event();
3309
3372
  this.metrics = {};
@@ -3316,19 +3379,19 @@ var DataSpace = class {
3316
3379
  this._metadataStore = params.metadataStore;
3317
3380
  this._signingContext = params.signingContext;
3318
3381
  this._callbacks = params.callbacks ?? {};
3319
- this._automergeHost = params.automergeHost;
3382
+ this._echoHost = params.echoHost;
3320
3383
  this.authVerifier = new TrustedKeySetAuthVerifier({
3321
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys7.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3384
+ trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3322
3385
  update: this._inner.stateUpdate,
3323
- authTimeout: import_client_protocol3.AUTH_TIMEOUT
3386
+ authTimeout: import_client_protocol4.AUTH_TIMEOUT
3324
3387
  });
3325
3388
  this._cache = params.cache;
3326
3389
  this._state = params.initialState;
3327
3390
  (0, import_log8.log)("new state", {
3328
- state: import_services9.SpaceState[this._state]
3391
+ state: import_services8.SpaceState[this._state]
3329
3392
  }, {
3330
- F: __dxlog_file12,
3331
- L: 140,
3393
+ F: __dxlog_file11,
3394
+ L: 135,
3332
3395
  S: this,
3333
3396
  C: (f, a) => f(...a)
3334
3397
  });
@@ -3373,12 +3436,12 @@ var DataSpace = class {
3373
3436
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3374
3437
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3375
3438
  await this._inner.open(new import_context7.Context());
3376
- this._state = import_services9.SpaceState.CONTROL_ONLY;
3439
+ this._state = import_services8.SpaceState.CONTROL_ONLY;
3377
3440
  (0, import_log8.log)("new state", {
3378
- state: import_services9.SpaceState[this._state]
3441
+ state: import_services8.SpaceState[this._state]
3379
3442
  }, {
3380
- F: __dxlog_file12,
3381
- L: 198,
3443
+ F: __dxlog_file11,
3444
+ L: 193,
3382
3445
  S: this,
3383
3446
  C: (f, a) => f(...a)
3384
3447
  });
@@ -3391,12 +3454,12 @@ var DataSpace = class {
3391
3454
  }
3392
3455
  async _close() {
3393
3456
  await this._callbacks.beforeClose?.();
3394
- this._state = import_services9.SpaceState.CLOSED;
3457
+ this._state = import_services8.SpaceState.CLOSED;
3395
3458
  (0, import_log8.log)("new state", {
3396
- state: import_services9.SpaceState[this._state]
3459
+ state: import_services8.SpaceState[this._state]
3397
3460
  }, {
3398
- F: __dxlog_file12,
3399
- L: 212,
3461
+ F: __dxlog_file11,
3462
+ L: 207,
3400
3463
  S: this,
3401
3464
  C: (f, a) => f(...a)
3402
3465
  });
@@ -3425,27 +3488,27 @@ var DataSpace = class {
3425
3488
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3426
3489
  await this.initializeDataPipeline();
3427
3490
  } catch (err) {
3428
- if (err instanceof import_protocols8.CancelledError || err instanceof import_context7.ContextDisposedError) {
3491
+ if (err instanceof import_protocols7.CancelledError || err instanceof import_context7.ContextDisposedError) {
3429
3492
  (0, import_log8.log)("data pipeline initialization cancelled", err, {
3430
- F: __dxlog_file12,
3431
- L: 245,
3493
+ F: __dxlog_file11,
3494
+ L: 240,
3432
3495
  S: this,
3433
3496
  C: (f, a) => f(...a)
3434
3497
  });
3435
3498
  return;
3436
3499
  }
3437
3500
  import_log8.log.error("Error initializing data pipeline", err, {
3438
- F: __dxlog_file12,
3439
- L: 249,
3501
+ F: __dxlog_file11,
3502
+ L: 244,
3440
3503
  S: this,
3441
3504
  C: (f, a) => f(...a)
3442
3505
  });
3443
- this._state = import_services9.SpaceState.ERROR;
3506
+ this._state = import_services8.SpaceState.ERROR;
3444
3507
  (0, import_log8.log)("new state", {
3445
- state: import_services9.SpaceState[this._state]
3508
+ state: import_services8.SpaceState[this._state]
3446
3509
  }, {
3447
- F: __dxlog_file12,
3448
- L: 251,
3510
+ F: __dxlog_file11,
3511
+ L: 246,
3449
3512
  S: this,
3450
3513
  C: (f, a) => f(...a)
3451
3514
  });
@@ -3457,15 +3520,15 @@ var DataSpace = class {
3457
3520
  });
3458
3521
  }
3459
3522
  async initializeDataPipeline() {
3460
- if (this._state !== import_services9.SpaceState.CONTROL_ONLY) {
3461
- throw new import_protocols8.SystemError("Invalid operation");
3523
+ if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3524
+ throw new import_protocols7.SystemError("Invalid operation");
3462
3525
  }
3463
- this._state = import_services9.SpaceState.INITIALIZING;
3526
+ this._state = import_services8.SpaceState.INITIALIZING;
3464
3527
  (0, import_log8.log)("new state", {
3465
- state: import_services9.SpaceState[this._state]
3528
+ state: import_services8.SpaceState[this._state]
3466
3529
  }, {
3467
- F: __dxlog_file12,
3468
- L: 267,
3530
+ F: __dxlog_file11,
3531
+ L: 262,
3469
3532
  S: this,
3470
3533
  C: (f, a) => f(...a)
3471
3534
  });
@@ -3474,18 +3537,18 @@ var DataSpace = class {
3474
3537
  this._automergeSpaceState.startProcessingRootDocs();
3475
3538
  await (0, import_context7.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3476
3539
  (0, import_log8.log)("data pipeline ready", void 0, {
3477
- F: __dxlog_file12,
3478
- L: 279,
3540
+ F: __dxlog_file11,
3541
+ L: 274,
3479
3542
  S: this,
3480
3543
  C: (f, a) => f(...a)
3481
3544
  });
3482
3545
  await this._callbacks.beforeReady?.();
3483
- this._state = import_services9.SpaceState.READY;
3546
+ this._state = import_services8.SpaceState.READY;
3484
3547
  (0, import_log8.log)("new state", {
3485
- state: import_services9.SpaceState[this._state]
3548
+ state: import_services8.SpaceState[this._state]
3486
3549
  }, {
3487
- F: __dxlog_file12,
3488
- L: 283,
3550
+ F: __dxlog_file11,
3551
+ L: 278,
3489
3552
  S: this,
3490
3553
  C: (f, a) => f(...a)
3491
3554
  });
@@ -3500,14 +3563,14 @@ var DataSpace = class {
3500
3563
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3501
3564
  await this._createWritableFeeds();
3502
3565
  (0, import_log8.log)("writable feeds created", void 0, {
3503
- F: __dxlog_file12,
3504
- L: 299,
3566
+ F: __dxlog_file11,
3567
+ L: 294,
3505
3568
  S: this,
3506
3569
  C: (f, a) => f(...a)
3507
3570
  });
3508
3571
  this.stateUpdate.emit();
3509
3572
  if (!this.notarizationPlugin.hasWriter) {
3510
- this.notarizationPlugin.setWriter((0, import_echo_pipeline.createMappedFeedWriter)((credential) => ({
3573
+ this.notarizationPlugin.setWriter((0, import_echo_pipeline2.createMappedFeedWriter)((credential) => ({
3511
3574
  credential: {
3512
3575
  credential
3513
3576
  }
@@ -3563,13 +3626,13 @@ var DataSpace = class {
3563
3626
  space: this.key,
3564
3627
  rootUrl
3565
3628
  }, {
3566
- F: __dxlog_file12,
3567
- L: 365,
3629
+ F: __dxlog_file11,
3630
+ L: 360,
3568
3631
  S: this,
3569
3632
  C: (f, a) => f(...a)
3570
3633
  });
3571
- this._automergeHost._requestedDocs.add(rootUrl);
3572
- const handle = this._automergeHost.repo.find(rootUrl);
3634
+ this._echoHost.replicateDocument(rootUrl);
3635
+ const handle = this._echoHost.automergeRepo.find(rootUrl);
3573
3636
  queueMicrotask(async () => {
3574
3637
  try {
3575
3638
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
@@ -3578,7 +3641,7 @@ var DataSpace = class {
3578
3641
  if (this._ctx.disposed) {
3579
3642
  return;
3580
3643
  }
3581
- const doc = handle.docSync() ?? (0, import_invariant10.failedInvariant)();
3644
+ const doc = handle.docSync() ?? (0, import_invariant9.failedInvariant)();
3582
3645
  if (!doc.access?.spaceKey) {
3583
3646
  handle.change((doc2) => {
3584
3647
  doc2.access = {
@@ -3595,8 +3658,8 @@ var DataSpace = class {
3595
3658
  rootUrl,
3596
3659
  err
3597
3660
  }, {
3598
- F: __dxlog_file12,
3599
- L: 388,
3661
+ F: __dxlog_file11,
3662
+ L: 383,
3600
3663
  S: this,
3601
3664
  C: (f, a) => f(...a)
3602
3665
  });
@@ -3622,7 +3685,7 @@ var DataSpace = class {
3622
3685
  let epoch;
3623
3686
  switch (options?.migration) {
3624
3687
  case void 0:
3625
- case import_services9.CreateEpochRequest.Migration.NONE:
3688
+ case import_services8.CreateEpochRequest.Migration.NONE:
3626
3689
  {
3627
3690
  epoch = {
3628
3691
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3632,9 +3695,9 @@ var DataSpace = class {
3632
3695
  };
3633
3696
  }
3634
3697
  break;
3635
- case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3698
+ case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3636
3699
  {
3637
- const document = this._automergeHost.repo.create();
3700
+ const document = this._echoHost.automergeRepo.create();
3638
3701
  epoch = {
3639
3702
  previousId: this._automergeSpaceState.lastEpoch?.id,
3640
3703
  number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
@@ -3643,15 +3706,15 @@ var DataSpace = class {
3643
3706
  };
3644
3707
  }
3645
3708
  break;
3646
- case import_services9.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3709
+ case import_services8.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3647
3710
  {
3648
3711
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3649
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3712
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3650
3713
  await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3651
- const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3652
- (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3653
- F: __dxlog_file12,
3654
- L: 438,
3714
+ const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
3715
+ (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3716
+ F: __dxlog_file11,
3717
+ L: 433,
3655
3718
  S: this,
3656
3719
  A: [
3657
3720
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3666,23 +3729,23 @@ var DataSpace = class {
3666
3729
  };
3667
3730
  }
3668
3731
  break;
3669
- case import_services9.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3732
+ case import_services8.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3670
3733
  {
3671
3734
  import_log8.log.info("Fragmenting", void 0, {
3672
- F: __dxlog_file12,
3673
- L: 450,
3735
+ F: __dxlog_file11,
3736
+ L: 445,
3674
3737
  S: this,
3675
3738
  C: (f, a) => f(...a)
3676
3739
  });
3677
3740
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3678
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3741
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3679
3742
  await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3680
3743
  const objects = Object.entries(rootHandle.docSync().objects);
3681
- const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_db.TYPE_PROPERTIES);
3744
+ const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
3682
3745
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3683
- (0, import_invariant10.invariant)(properties, "Properties not found", {
3684
- F: __dxlog_file12,
3685
- L: 460,
3746
+ (0, import_invariant9.invariant)(properties, "Properties not found", {
3747
+ F: __dxlog_file11,
3748
+ L: 455,
3686
3749
  S: this,
3687
3750
  A: [
3688
3751
  "properties",
@@ -3695,17 +3758,17 @@ var DataSpace = class {
3695
3758
  properties
3696
3759
  ])
3697
3760
  };
3698
- const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3699
- (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3700
- F: __dxlog_file12,
3701
- L: 465,
3761
+ const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
3762
+ (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3763
+ F: __dxlog_file11,
3764
+ L: 460,
3702
3765
  S: this,
3703
3766
  A: [
3704
3767
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3705
3768
  ""
3706
3769
  ]
3707
3770
  });
3708
- const docLoader = new import_echo_pipeline2.AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
3771
+ const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
3709
3772
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
3710
3773
  rootUrl: newRoot.url
3711
3774
  });
@@ -3749,25 +3812,25 @@ var DataSpace = class {
3749
3812
  ]));
3750
3813
  }
3751
3814
  async activate() {
3752
- if (this._state !== import_services9.SpaceState.INACTIVE) {
3815
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
3753
3816
  return;
3754
3817
  }
3755
- await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.ACTIVE);
3818
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
3756
3819
  await this._open();
3757
3820
  this.initializeDataPipelineAsync();
3758
3821
  }
3759
3822
  async deactivate() {
3760
- if (this._state === import_services9.SpaceState.INACTIVE) {
3823
+ if (this._state === import_services8.SpaceState.INACTIVE) {
3761
3824
  return;
3762
3825
  }
3763
- await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.INACTIVE);
3826
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
3764
3827
  await this._close();
3765
- this._state = import_services9.SpaceState.INACTIVE;
3828
+ this._state = import_services8.SpaceState.INACTIVE;
3766
3829
  (0, import_log8.log)("new state", {
3767
- state: import_services9.SpaceState[this._state]
3830
+ state: import_services8.SpaceState[this._state]
3768
3831
  }, {
3769
- F: __dxlog_file12,
3770
- L: 531,
3832
+ F: __dxlog_file11,
3833
+ L: 526,
3771
3834
  S: this,
3772
3835
  C: (f, a) => f(...a)
3773
3836
  });
@@ -3775,18 +3838,18 @@ var DataSpace = class {
3775
3838
  }
3776
3839
  };
3777
3840
  _ts_decorate4([
3778
- import_tracing5.trace.info()
3841
+ import_tracing4.trace.info()
3779
3842
  ], DataSpace.prototype, "_inner", void 0);
3780
3843
  _ts_decorate4([
3781
- import_tracing5.trace.info()
3844
+ import_tracing4.trace.info()
3782
3845
  ], DataSpace.prototype, "key", null);
3783
3846
  _ts_decorate4([
3784
- import_tracing5.trace.info({
3785
- enum: import_services9.SpaceState
3847
+ import_tracing4.trace.info({
3848
+ enum: import_services8.SpaceState
3786
3849
  })
3787
3850
  ], DataSpace.prototype, "state", null);
3788
3851
  _ts_decorate4([
3789
- import_tracing5.trace.info({
3852
+ import_tracing4.trace.info({
3790
3853
  depth: null
3791
3854
  })
3792
3855
  ], DataSpace.prototype, "_automergeInfo", null);
@@ -3797,12 +3860,12 @@ _ts_decorate4([
3797
3860
  import_async10.synchronized
3798
3861
  ], DataSpace.prototype, "close", null);
3799
3862
  _ts_decorate4([
3800
- import_tracing5.trace.span({
3863
+ import_tracing4.trace.span({
3801
3864
  showInBrowserTimeline: true
3802
3865
  })
3803
3866
  ], DataSpace.prototype, "initializeDataPipeline", null);
3804
3867
  _ts_decorate4([
3805
- import_tracing5.trace.span({
3868
+ import_tracing4.trace.span({
3806
3869
  showInBrowserTimeline: true
3807
3870
  })
3808
3871
  ], DataSpace.prototype, "_initializeAndReadControlPipeline", null);
@@ -3817,7 +3880,7 @@ _ts_decorate4([
3817
3880
  ], DataSpace.prototype, "deactivate", null);
3818
3881
  DataSpace = _ts_decorate4([
3819
3882
  (0, import_async10.trackLeaks)("open", "close"),
3820
- import_tracing5.trace.resource()
3883
+ import_tracing4.trace.resource()
3821
3884
  ], DataSpace);
3822
3885
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3823
3886
  const credentials = [
@@ -3893,22 +3956,23 @@ function _ts_decorate5(decorators, target, key, desc) {
3893
3956
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3894
3957
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3895
3958
  }
3896
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3959
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
3897
3960
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3898
3961
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3899
3962
  var DataSpaceManager = class {
3900
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, params) {
3963
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
3901
3964
  this._spaceManager = _spaceManager;
3902
3965
  this._metadataStore = _metadataStore;
3903
3966
  this._keyring = _keyring;
3904
3967
  this._signingContext = _signingContext;
3905
3968
  this._feedStore = _feedStore;
3906
- this._automergeHost = _automergeHost;
3969
+ this._echoHost = _echoHost;
3970
+ this._invitationsManager = _invitationsManager;
3907
3971
  this._ctx = new import_context9.Context();
3908
3972
  this.updated = new import_async13.Event();
3909
- this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3973
+ this._spaces = new import_util6.ComplexMap(import_keys10.PublicKey.hash);
3910
3974
  this._isOpen = false;
3911
- this._instanceId = import_keys9.PublicKey.random().toHex();
3975
+ this._instanceId = import_keys10.PublicKey.random().toHex();
3912
3976
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3913
3977
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3914
3978
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3919,24 +3983,24 @@ var DataSpaceManager = class {
3919
3983
  }
3920
3984
  async open() {
3921
3985
  (0, import_log10.log)("open", void 0, {
3922
- F: __dxlog_file13,
3923
- L: 98,
3986
+ F: __dxlog_file12,
3987
+ L: 102,
3924
3988
  S: this,
3925
3989
  C: (f, a) => f(...a)
3926
3990
  });
3927
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3991
+ import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.begin({
3928
3992
  id: this._instanceId
3929
3993
  }), {
3930
- F: __dxlog_file13,
3931
- L: 99,
3994
+ F: __dxlog_file12,
3995
+ L: 103,
3932
3996
  S: this,
3933
3997
  C: (f, a) => f(...a)
3934
3998
  });
3935
3999
  (0, import_log10.log)("metadata loaded", {
3936
4000
  spaces: this._metadataStore.spaces.length
3937
4001
  }, {
3938
- F: __dxlog_file13,
3939
- L: 100,
4002
+ F: __dxlog_file12,
4003
+ L: 104,
3940
4004
  S: this,
3941
4005
  C: (f, a) => f(...a)
3942
4006
  });
@@ -3945,8 +4009,8 @@ var DataSpaceManager = class {
3945
4009
  (0, import_log10.log)("load space", {
3946
4010
  spaceMetadata
3947
4011
  }, {
3948
- F: __dxlog_file13,
3949
- L: 104,
4012
+ F: __dxlog_file12,
4013
+ L: 108,
3950
4014
  S: this,
3951
4015
  C: (f, a) => f(...a)
3952
4016
  });
@@ -3956,8 +4020,8 @@ var DataSpaceManager = class {
3956
4020
  spaceMetadata,
3957
4021
  err
3958
4022
  }, {
3959
- F: __dxlog_file13,
3960
- L: 107,
4023
+ F: __dxlog_file12,
4024
+ L: 111,
3961
4025
  S: this,
3962
4026
  C: (f, a) => f(...a)
3963
4027
  });
@@ -3966,23 +4030,23 @@ var DataSpaceManager = class {
3966
4030
  this._isOpen = true;
3967
4031
  this.updated.emit();
3968
4032
  for (const space of this._spaces.values()) {
3969
- if (space.state !== import_services10.SpaceState.INACTIVE) {
4033
+ if (space.state !== import_services9.SpaceState.INACTIVE) {
3970
4034
  space.initializeDataPipelineAsync();
3971
4035
  }
3972
4036
  }
3973
- import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
4037
+ import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols9.trace.end({
3974
4038
  id: this._instanceId
3975
4039
  }), {
3976
- F: __dxlog_file13,
3977
- L: 120,
4040
+ F: __dxlog_file12,
4041
+ L: 124,
3978
4042
  S: this,
3979
4043
  C: (f, a) => f(...a)
3980
4044
  });
3981
4045
  }
3982
4046
  async close() {
3983
4047
  (0, import_log10.log)("close", void 0, {
3984
- F: __dxlog_file13,
3985
- L: 125,
4048
+ F: __dxlog_file12,
4049
+ L: 129,
3986
4050
  S: this,
3987
4051
  C: (f, a) => f(...a)
3988
4052
  });
@@ -3996,9 +4060,9 @@ var DataSpaceManager = class {
3996
4060
  * Creates a new space writing the genesis credentials to the control feed.
3997
4061
  */
3998
4062
  async createSpace() {
3999
- (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
4000
- F: __dxlog_file13,
4001
- L: 138,
4063
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
4064
+ F: __dxlog_file12,
4065
+ L: 142,
4002
4066
  S: this,
4003
4067
  A: [
4004
4068
  "this._isOpen",
@@ -4013,28 +4077,23 @@ var DataSpaceManager = class {
4013
4077
  genesisFeedKey: controlFeedKey,
4014
4078
  controlFeedKey,
4015
4079
  dataFeedKey,
4016
- state: import_services10.SpaceState.ACTIVE
4080
+ state: import_services9.SpaceState.ACTIVE
4017
4081
  };
4018
4082
  (0, import_log10.log)("creating space...", {
4019
4083
  spaceKey
4020
4084
  }, {
4021
- F: __dxlog_file13,
4022
- L: 150,
4085
+ F: __dxlog_file12,
4086
+ L: 154,
4023
4087
  S: this,
4024
4088
  C: (f, a) => f(...a)
4025
4089
  });
4026
- const automergeRoot = this._automergeHost.repo.create();
4027
- automergeRoot.change((doc) => {
4028
- doc.access = {
4029
- spaceKey: spaceKey.toHex()
4030
- };
4031
- });
4090
+ const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
4032
4091
  const space = await this._constructSpace(metadata);
4033
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
4092
+ const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
4034
4093
  await this._metadataStore.addSpace(metadata);
4035
4094
  const memberCredential = credentials[1];
4036
- (0, import_invariant12.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4037
- F: __dxlog_file13,
4095
+ (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4096
+ F: __dxlog_file12,
4038
4097
  L: 163,
4039
4098
  S: this,
4040
4099
  A: [
@@ -4052,13 +4111,13 @@ var DataSpaceManager = class {
4052
4111
  (0, import_log10.log)("accept space", {
4053
4112
  opts
4054
4113
  }, {
4055
- F: __dxlog_file13,
4114
+ F: __dxlog_file12,
4056
4115
  L: 175,
4057
4116
  S: this,
4058
4117
  C: (f, a) => f(...a)
4059
4118
  });
4060
- (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
4061
- F: __dxlog_file13,
4119
+ (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
4120
+ F: __dxlog_file12,
4062
4121
  L: 176,
4063
4122
  S: this,
4064
4123
  A: [
@@ -4066,8 +4125,8 @@ var DataSpaceManager = class {
4066
4125
  "'Not open.'"
4067
4126
  ]
4068
4127
  });
4069
- (0, import_invariant12.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4070
- F: __dxlog_file13,
4128
+ (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4129
+ F: __dxlog_file12,
4071
4130
  L: 177,
4072
4131
  S: this,
4073
4132
  A: [
@@ -4095,14 +4154,14 @@ var DataSpaceManager = class {
4095
4154
  async waitUntilSpaceReady(spaceKey) {
4096
4155
  await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4097
4156
  const space = this._spaces.get(spaceKey);
4098
- return !!space && space.state === import_services10.SpaceState.READY;
4157
+ return !!space && space.state === import_services9.SpaceState.READY;
4099
4158
  }));
4100
4159
  }
4101
4160
  async _constructSpace(metadata) {
4102
4161
  (0, import_log10.log)("construct space", {
4103
4162
  metadata
4104
4163
  }, {
4105
- F: __dxlog_file13,
4164
+ F: __dxlog_file12,
4106
4165
  L: 210,
4107
4166
  S: this,
4108
4167
  C: (f, a) => f(...a)
@@ -4135,37 +4194,41 @@ var DataSpaceManager = class {
4135
4194
  remotePeerId: session.remotePeerId
4136
4195
  }));
4137
4196
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
4138
- this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
4139
- session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
4197
+ this._echoHost.authorizeDevice(space.key, session.remotePeerId);
4198
+ session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4140
4199
  },
4141
4200
  onAuthFailure: () => {
4142
4201
  import_log10.log.warn("auth failure", void 0, {
4143
- F: __dxlog_file13,
4202
+ F: __dxlog_file12,
4144
4203
  L: 247,
4145
4204
  S: this,
4146
4205
  C: (f, a) => f(...a)
4147
4206
  });
4148
4207
  },
4149
- memberKey: this._signingContext.identityKey
4208
+ memberKey: this._signingContext.identityKey,
4209
+ onDelegatedInvitationStatusChange: (invitation, isActive) => {
4210
+ return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
4211
+ }
4150
4212
  });
4151
4213
  controlFeed && await space.setControlFeed(controlFeed);
4152
4214
  dataFeed && await space.setDataFeed(dataFeed);
4153
4215
  const dataSpace = new DataSpace({
4154
4216
  inner: space,
4155
- initialState: metadata.state === import_services10.SpaceState.INACTIVE ? import_services10.SpaceState.INACTIVE : import_services10.SpaceState.CLOSED,
4217
+ initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
4156
4218
  metadataStore: this._metadataStore,
4157
4219
  gossip,
4158
4220
  presence,
4159
4221
  keyring: this._keyring,
4160
4222
  feedStore: this._feedStore,
4223
+ echoHost: this._echoHost,
4161
4224
  signingContext: this._signingContext,
4162
4225
  callbacks: {
4163
4226
  beforeReady: async () => {
4164
4227
  (0, import_log10.log)("before space ready", {
4165
4228
  space: space.key
4166
4229
  }, {
4167
- F: __dxlog_file13,
4168
- L: 265,
4230
+ F: __dxlog_file12,
4231
+ L: 269,
4169
4232
  S: this,
4170
4233
  C: (f, a) => f(...a)
4171
4234
  });
@@ -4175,12 +4238,15 @@ var DataSpaceManager = class {
4175
4238
  space: space.key,
4176
4239
  open: this._isOpen
4177
4240
  }, {
4178
- F: __dxlog_file13,
4179
- L: 268,
4241
+ F: __dxlog_file12,
4242
+ L: 272,
4180
4243
  S: this,
4181
4244
  C: (f, a) => f(...a)
4182
4245
  });
4183
4246
  if (this._isOpen) {
4247
+ await this._createDelegatedInvitations(dataSpace, [
4248
+ ...space.spaceState.invitations.entries()
4249
+ ]);
4184
4250
  this.updated.emit();
4185
4251
  }
4186
4252
  },
@@ -4188,17 +4254,16 @@ var DataSpaceManager = class {
4188
4254
  (0, import_log10.log)("before space close", {
4189
4255
  space: space.key
4190
4256
  }, {
4191
- F: __dxlog_file13,
4192
- L: 274,
4257
+ F: __dxlog_file12,
4258
+ L: 279,
4193
4259
  S: this,
4194
4260
  C: (f, a) => f(...a)
4195
4261
  });
4196
4262
  }
4197
4263
  },
4198
- cache: metadata.cache,
4199
- automergeHost: this._automergeHost
4264
+ cache: metadata.cache
4200
4265
  });
4201
- if (metadata.state !== import_services10.SpaceState.INACTIVE) {
4266
+ if (metadata.state !== import_services9.SpaceState.INACTIVE) {
4202
4267
  await dataSpace.open();
4203
4268
  }
4204
4269
  if (metadata.controlTimeframe) {
@@ -4207,6 +4272,41 @@ var DataSpaceManager = class {
4207
4272
  this._spaces.set(metadata.key, dataSpace);
4208
4273
  return dataSpace;
4209
4274
  }
4275
+ async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4276
+ if (dataSpace?.state !== import_services9.SpaceState.READY) {
4277
+ return;
4278
+ }
4279
+ if (isActive) {
4280
+ await this._createDelegatedInvitations(dataSpace, [
4281
+ [
4282
+ delegatedInvitation.credentialId,
4283
+ delegatedInvitation.invitation
4284
+ ]
4285
+ ]);
4286
+ } else {
4287
+ await this._invitationsManager.cancelInvitation(delegatedInvitation.invitation);
4288
+ }
4289
+ }
4290
+ async _createDelegatedInvitations(space, invitations) {
4291
+ const tasks = invitations.map(([credentialId, invitation]) => {
4292
+ return this._invitationsManager.createInvitation({
4293
+ type: import_services9.Invitation.Type.DELEGATED,
4294
+ kind: import_services9.Invitation.Kind.SPACE,
4295
+ spaceKey: space.key,
4296
+ authMethod: invitation.authMethod,
4297
+ invitationId: invitation.invitationId,
4298
+ swarmKey: invitation.swarmKey,
4299
+ guestKeypair: invitation.guestKey ? {
4300
+ publicKey: invitation.guestKey
4301
+ } : void 0,
4302
+ lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
4303
+ multiUse: invitation.multiUse,
4304
+ delegationCredentialId: credentialId,
4305
+ persistent: false
4306
+ });
4307
+ });
4308
+ await Promise.all(tasks);
4309
+ }
4210
4310
  };
4211
4311
  _ts_decorate5([
4212
4312
  import_async13.synchronized
@@ -4223,7 +4323,7 @@ _ts_decorate5([
4223
4323
  DataSpaceManager = _ts_decorate5([
4224
4324
  (0, import_async13.trackLeaks)("open", "close")
4225
4325
  ], DataSpaceManager);
4226
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4326
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
4227
4327
  var SpacesServiceImpl = class {
4228
4328
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
4229
4329
  this._identityManager = _identityManager;
@@ -4240,29 +4340,29 @@ var SpacesServiceImpl = class {
4240
4340
  }
4241
4341
  async updateSpace({ spaceKey, state }) {
4242
4342
  const dataSpaceManager = await this._getDataSpaceManager();
4243
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4343
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4244
4344
  if (state) {
4245
4345
  switch (state) {
4246
- case import_services11.SpaceState.ACTIVE:
4346
+ case import_services10.SpaceState.ACTIVE:
4247
4347
  await space.activate();
4248
4348
  break;
4249
- case import_services11.SpaceState.INACTIVE:
4349
+ case import_services10.SpaceState.INACTIVE:
4250
4350
  await space.deactivate();
4251
4351
  break;
4252
4352
  default:
4253
- throw new import_protocols11.ApiError("Invalid space state");
4353
+ throw new import_protocols10.ApiError("Invalid space state");
4254
4354
  }
4255
4355
  }
4256
4356
  }
4257
4357
  querySpaces() {
4258
- return new import_codec_protobuf11.Stream(({ next, ctx }) => {
4358
+ return new import_codec_protobuf10.Stream(({ next, ctx }) => {
4259
4359
  const scheduler = new import_async14.UpdateScheduler(ctx, async () => {
4260
4360
  const dataSpaceManager = await this._getDataSpaceManager();
4261
4361
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
4262
4362
  (0, import_log11.log)("update", {
4263
4363
  spaces
4264
4364
  }, {
4265
- F: __dxlog_file14,
4365
+ F: __dxlog_file13,
4266
4366
  L: 77,
4267
4367
  S: this,
4268
4368
  C: (f, a) => f(...a)
@@ -4302,14 +4402,14 @@ var SpacesServiceImpl = class {
4302
4402
  }
4303
4403
  async postMessage({ spaceKey, channel, message }) {
4304
4404
  const dataSpaceManager = await this._getDataSpaceManager();
4305
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4405
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4306
4406
  await space.postMessage(getChannelId(channel), message);
4307
4407
  }
4308
4408
  subscribeMessages({ spaceKey, channel }) {
4309
- return new import_codec_protobuf11.Stream(({ ctx, next }) => {
4409
+ return new import_codec_protobuf10.Stream(({ ctx, next }) => {
4310
4410
  (0, import_async14.scheduleTask)(ctx, async () => {
4311
4411
  const dataSpaceManager = await this._getDataSpaceManager();
4312
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4412
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4313
4413
  const handle = space.listen(getChannelId(channel), (message) => {
4314
4414
  next(message);
4315
4415
  });
@@ -4318,8 +4418,8 @@ var SpacesServiceImpl = class {
4318
4418
  });
4319
4419
  }
4320
4420
  queryCredentials({ spaceKey, noTail }) {
4321
- return new import_codec_protobuf11.Stream(({ ctx, next, close }) => {
4322
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4421
+ return new import_codec_protobuf10.Stream(({ ctx, next, close }) => {
4422
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4323
4423
  const processor = {
4324
4424
  processCredential: async (credential) => {
4325
4425
  next(credential);
@@ -4335,7 +4435,7 @@ var SpacesServiceImpl = class {
4335
4435
  });
4336
4436
  }
4337
4437
  async writeCredentials({ spaceKey, credentials }) {
4338
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4438
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4339
4439
  for (const credential of credentials ?? []) {
4340
4440
  if (credential.proof) {
4341
4441
  await space.controlPipeline.writer.write({
@@ -4344,8 +4444,8 @@ var SpacesServiceImpl = class {
4344
4444
  }
4345
4445
  });
4346
4446
  } else {
4347
- (0, import_invariant13.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4348
- F: __dxlog_file14,
4447
+ (0, import_invariant12.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4448
+ F: __dxlog_file13,
4349
4449
  L: 164,
4350
4450
  S: this,
4351
4451
  A: [
@@ -4353,8 +4453,8 @@ var SpacesServiceImpl = class {
4353
4453
  "'Id on unsigned credentials is not allowed'"
4354
4454
  ]
4355
4455
  });
4356
- (0, import_invariant13.invariant)(this._identityManager.identity, "Identity is not available", {
4357
- F: __dxlog_file14,
4456
+ (0, import_invariant12.invariant)(this._identityManager.identity, "Identity is not available", {
4457
+ F: __dxlog_file13,
4358
4458
  L: 165,
4359
4459
  S: this,
4360
4460
  A: [
@@ -4363,8 +4463,8 @@ var SpacesServiceImpl = class {
4363
4463
  ]
4364
4464
  });
4365
4465
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4366
- (0, import_invariant13.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4367
- F: __dxlog_file14,
4466
+ (0, import_invariant12.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4467
+ F: __dxlog_file13,
4368
4468
  L: 167,
4369
4469
  S: this,
4370
4470
  A: [
@@ -4386,7 +4486,7 @@ var SpacesServiceImpl = class {
4386
4486
  }
4387
4487
  async createEpoch({ spaceKey, migration }) {
4388
4488
  const dataSpaceManager = await this._getDataSpaceManager();
4389
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4489
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4390
4490
  await space.createEpoch({
4391
4491
  migration
4392
4492
  });
@@ -4395,7 +4495,7 @@ var SpacesServiceImpl = class {
4395
4495
  return {
4396
4496
  spaceKey: space.key,
4397
4497
  state: space.state,
4398
- error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4498
+ error: space.error ? (0, import_protocols10.encodeError)(space.error) : void 0,
4399
4499
  pipeline: {
4400
4500
  currentEpoch: space.automergeSpaceState.lastEpoch,
4401
4501
  appliedEpoch: space.automergeSpaceState.lastEpoch,
@@ -4420,7 +4520,7 @@ var SpacesServiceImpl = class {
4420
4520
  identityKey: member.key,
4421
4521
  profile: member.profile ?? {}
4422
4522
  },
4423
- presence: member.removed ? import_services11.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
4523
+ presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4424
4524
  peerStates: peers
4425
4525
  };
4426
4526
  }),
@@ -4431,80 +4531,6 @@ var SpacesServiceImpl = class {
4431
4531
  }
4432
4532
  };
4433
4533
  var getChannelId = (channel) => `user-channel/${channel}`;
4434
- var createSelectedDocumentsIterator = (automergeHost) => (
4435
- /**
4436
- * Get object data blobs from Automerge Repo by ids.
4437
- * @param ids
4438
- */
4439
- // TODO(mykola): Unload automerge handles after usage.
4440
- async function* loadDocuments(ids) {
4441
- for (const id of ids) {
4442
- const { documentId, objectId } = import_protocols13.idCodec.decode(id);
4443
- const handle = automergeHost.repo.find(documentId);
4444
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4445
- const doc = handle.docSync();
4446
- const hash = (0, import_automerge.getHeads)(doc).join("");
4447
- yield doc.objects?.[objectId] ? [
4448
- {
4449
- id,
4450
- object: doc.objects[objectId],
4451
- currentHash: hash
4452
- }
4453
- ] : [];
4454
- }
4455
- }
4456
- );
4457
- var createDocumentsIterator = (automergeHost) => (
4458
- /**
4459
- * Recursively get all object data blobs from Automerge Repo.
4460
- * @param ids
4461
- */
4462
- // TODO(mykola): Unload automerge handles after usage.
4463
- async function* getAllDocuments() {
4464
- const visited = /* @__PURE__ */ new Set();
4465
- async function* getObjectsFromHandle(handle) {
4466
- if (visited.has(handle.documentId)) {
4467
- return;
4468
- }
4469
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4470
- const doc = handle.docSync();
4471
- const heads = (0, import_automerge.getHeads)(doc);
4472
- if (doc.objects) {
4473
- yield Object.entries(doc.objects).map(([objectId, object]) => {
4474
- return {
4475
- id: import_protocols13.idCodec.encode({
4476
- documentId: handle.documentId,
4477
- objectId
4478
- }),
4479
- object,
4480
- currentHash: heads.join("")
4481
- };
4482
- });
4483
- }
4484
- if (doc.links) {
4485
- for (const id of Object.values(doc.links)) {
4486
- if (visited.has(id)) {
4487
- continue;
4488
- }
4489
- const linkHandle = automergeHost.repo.find(id);
4490
- for await (const result of getObjectsFromHandle(linkHandle)) {
4491
- yield result;
4492
- }
4493
- }
4494
- }
4495
- visited.add(handle.documentId);
4496
- }
4497
- for (const handle of Object.values(automergeHost.repo.handles)) {
4498
- if (visited.has(handle.documentId)) {
4499
- continue;
4500
- }
4501
- for await (const result of getObjectsFromHandle(handle)) {
4502
- yield result;
4503
- }
4504
- visited.add(handle.documentId);
4505
- }
4506
- }
4507
- );
4508
4534
  function _ts_decorate6(decorators, target, key, desc) {
4509
4535
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4510
4536
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4515,18 +4541,20 @@ function _ts_decorate6(decorators, target, key, desc) {
4515
4541
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4516
4542
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4517
4543
  }
4518
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4519
- var ServiceContext = class {
4520
- constructor(storage, networkManager, signalManager, _runtimeParams) {
4544
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4545
+ var ServiceContext = class extends import_context10.Resource {
4546
+ constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4547
+ super();
4521
4548
  this.storage = storage;
4549
+ this.level = level;
4522
4550
  this.networkManager = networkManager;
4523
4551
  this.signalManager = signalManager;
4524
4552
  this._runtimeParams = _runtimeParams;
4525
4553
  this.initialized = new import_async15.Trigger();
4526
4554
  this._handlerFactories = /* @__PURE__ */ new Map();
4527
- this._instanceId = import_keys10.PublicKey.random().toHex();
4528
- this.metadataStore = new import_echo_pipeline3.MetadataStore(storage.createDirectory("metadata"));
4529
- this.snapshotStore = new import_echo_pipeline3.SnapshotStore(storage.createDirectory("snapshots"));
4555
+ this._instanceId = import_keys11.PublicKey.random().toHex();
4556
+ this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
4557
+ this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4530
4558
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4531
4559
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
4532
4560
  this.feedStore = new import_feed_store4.FeedStore({
@@ -4534,12 +4562,12 @@ var ServiceContext = class {
4534
4562
  root: storage.createDirectory("feeds"),
4535
4563
  signer: this.keyring,
4536
4564
  hypercore: {
4537
- valueEncoding: import_echo_pipeline3.valueEncoding,
4565
+ valueEncoding: import_echo_pipeline4.valueEncoding,
4538
4566
  stats: true
4539
4567
  }
4540
4568
  })
4541
4569
  });
4542
- this.spaceManager = new import_echo_pipeline3.SpaceManager({
4570
+ this.spaceManager = new import_echo_pipeline4.SpaceManager({
4543
4571
  feedStore: this.feedStore,
4544
4572
  networkManager: this.networkManager,
4545
4573
  blobStore: this.blobStore,
@@ -4547,85 +4575,84 @@ var ServiceContext = class {
4547
4575
  snapshotStore: this.snapshotStore
4548
4576
  });
4549
4577
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4550
- this.indexMetadata = new import_indexing.IndexMetadataStore({
4551
- directory: storage.createDirectory("index-metadata")
4552
- });
4553
- this.automergeHost = new import_echo_pipeline3.AutomergeHost({
4554
- directory: storage.createDirectory("automerge"),
4555
- metadata: this.indexMetadata
4556
- });
4557
- this.indexer = new import_indexing.Indexer({
4558
- indexStore: new import_indexing.IndexStore({
4559
- directory: storage.createDirectory("index-store")
4560
- }),
4561
- metadataStore: this.indexMetadata,
4562
- loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4563
- getAllDocuments: createDocumentsIterator(this.automergeHost)
4578
+ this.echoHost = new import_echo_db.EchoHost({
4579
+ kv: this.level,
4580
+ storage: this.storage
4564
4581
  });
4565
4582
  this.invitations = new InvitationsHandler(this.networkManager);
4566
- this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4583
+ this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4584
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4567
4585
  }
4568
- async open(ctx) {
4586
+ async _open(ctx) {
4569
4587
  await this._checkStorageVersion();
4570
4588
  (0, import_log12.log)("opening...", void 0, {
4571
- F: __dxlog_file15,
4589
+ F: __dxlog_file14,
4572
4590
  L: 151,
4573
4591
  S: this,
4574
4592
  C: (f, a) => f(...a)
4575
4593
  });
4576
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4594
+ import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.begin({
4577
4595
  id: this._instanceId
4578
4596
  }), {
4579
- F: __dxlog_file15,
4597
+ F: __dxlog_file14,
4580
4598
  L: 152,
4581
4599
  S: this,
4582
4600
  C: (f, a) => f(...a)
4583
4601
  });
4584
4602
  await this.signalManager.open();
4585
4603
  await this.networkManager.open();
4604
+ await this.echoHost.open(ctx);
4586
4605
  await this.metadataStore.load();
4587
4606
  await this.spaceManager.open();
4588
4607
  await this.identityManager.open(ctx);
4589
4608
  if (this.identityManager.identity) {
4590
4609
  await this._initialize(ctx);
4591
4610
  }
4592
- import_log12.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4611
+ const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4612
+ (0, import_log12.log)("loaded persistent invitations", {
4613
+ count: loadedInvitations.invitations?.length
4614
+ }, {
4615
+ F: __dxlog_file14,
4616
+ L: 165,
4617
+ S: this,
4618
+ C: (f, a) => f(...a)
4619
+ });
4620
+ import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.end({
4593
4621
  id: this._instanceId
4594
4622
  }), {
4595
- F: __dxlog_file15,
4596
- L: 162,
4623
+ F: __dxlog_file14,
4624
+ L: 167,
4597
4625
  S: this,
4598
4626
  C: (f, a) => f(...a)
4599
4627
  });
4600
4628
  (0, import_log12.log)("opened", void 0, {
4601
- F: __dxlog_file15,
4602
- L: 163,
4629
+ F: __dxlog_file14,
4630
+ L: 168,
4603
4631
  S: this,
4604
4632
  C: (f, a) => f(...a)
4605
4633
  });
4606
4634
  }
4607
- async close() {
4635
+ async _close(ctx) {
4608
4636
  (0, import_log12.log)("closing...", void 0, {
4609
- F: __dxlog_file15,
4610
- L: 167,
4637
+ F: __dxlog_file14,
4638
+ L: 172,
4611
4639
  S: this,
4612
4640
  C: (f, a) => f(...a)
4613
4641
  });
4614
4642
  if (this._deviceSpaceSync && this.identityManager.identity) {
4615
4643
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
4616
4644
  }
4617
- await this.automergeHost.close();
4618
4645
  await this.dataSpaceManager?.close();
4619
4646
  await this.identityManager.close();
4620
4647
  await this.spaceManager.close();
4621
4648
  await this.feedStore.close();
4649
+ await this.metadataStore.close();
4650
+ await this.echoHost.close(ctx);
4622
4651
  await this.networkManager.close();
4623
4652
  await this.signalManager.close();
4624
- await this.metadataStore.close();
4625
- await this.indexer.destroy();
4626
4653
  (0, import_log12.log)("closed", void 0, {
4627
- F: __dxlog_file15,
4628
- L: 180,
4654
+ F: __dxlog_file14,
4655
+ L: 184,
4629
4656
  S: this,
4630
4657
  C: (f, a) => f(...a)
4631
4658
  });
@@ -4637,9 +4664,9 @@ var ServiceContext = class {
4637
4664
  }
4638
4665
  getInvitationHandler(invitation) {
4639
4666
  const factory = this._handlerFactories.get(invitation.kind);
4640
- (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4641
- F: __dxlog_file15,
4642
- L: 191,
4667
+ (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4668
+ F: __dxlog_file14,
4669
+ L: 195,
4643
4670
  S: this,
4644
4671
  A: [
4645
4672
  "factory",
@@ -4663,15 +4690,15 @@ var ServiceContext = class {
4663
4690
  }
4664
4691
  async _checkStorageVersion() {
4665
4692
  await this.metadataStore.load();
4666
- if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
4667
- throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4693
+ if (this.metadataStore.version !== import_protocols11.STORAGE_VERSION) {
4694
+ throw new import_protocols11.InvalidStorageVersionError(import_protocols11.STORAGE_VERSION, this.metadataStore.version);
4668
4695
  }
4669
4696
  }
4670
4697
  // Called when identity is created.
4671
4698
  async _initialize(ctx) {
4672
4699
  (0, import_log12.log)("initializing spaces...", void 0, {
4673
- F: __dxlog_file15,
4674
- L: 222,
4700
+ F: __dxlog_file14,
4701
+ L: 226,
4675
4702
  S: this,
4676
4703
  C: (f, a) => f(...a)
4677
4704
  });
@@ -4689,12 +4716,12 @@ var ServiceContext = class {
4689
4716
  });
4690
4717
  }
4691
4718
  };
4692
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4719
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
4693
4720
  await this.dataSpaceManager.open();
4694
- this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4695
- (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4696
- F: __dxlog_file15,
4697
- L: 246,
4721
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4722
+ (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4723
+ F: __dxlog_file14,
4724
+ L: 251,
4698
4725
  S: this,
4699
4726
  A: [
4700
4727
  "this.dataSpaceManager",
@@ -4717,8 +4744,8 @@ var ServiceContext = class {
4717
4744
  (0, import_log12.log)("dataSpaceManager not initialized yet, ignoring space admission", {
4718
4745
  details: assertion
4719
4746
  }, {
4720
- F: __dxlog_file15,
4721
- L: 262,
4747
+ F: __dxlog_file14,
4748
+ L: 267,
4722
4749
  S: this,
4723
4750
  C: (f, a) => f(...a)
4724
4751
  });
@@ -4728,8 +4755,8 @@ var ServiceContext = class {
4728
4755
  (0, import_log12.log)("space already exists, ignoring space admission", {
4729
4756
  details: assertion
4730
4757
  }, {
4731
- F: __dxlog_file15,
4732
- L: 266,
4758
+ F: __dxlog_file14,
4759
+ L: 271,
4733
4760
  S: this,
4734
4761
  C: (f, a) => f(...a)
4735
4762
  });
@@ -4739,8 +4766,8 @@ var ServiceContext = class {
4739
4766
  (0, import_log12.log)("accepting space recorded in halo", {
4740
4767
  details: assertion
4741
4768
  }, {
4742
- F: __dxlog_file15,
4743
- L: 271,
4769
+ F: __dxlog_file14,
4770
+ L: 276,
4744
4771
  S: this,
4745
4772
  C: (f, a) => f(...a)
4746
4773
  });
@@ -4750,8 +4777,8 @@ var ServiceContext = class {
4750
4777
  });
4751
4778
  } catch (err) {
4752
4779
  import_log12.log.catch(err, void 0, {
4753
- F: __dxlog_file15,
4754
- L: 277,
4780
+ F: __dxlog_file14,
4781
+ L: 282,
4755
4782
  S: this,
4756
4783
  C: (f, a) => f(...a)
4757
4784
  });
@@ -4762,14 +4789,14 @@ var ServiceContext = class {
4762
4789
  }
4763
4790
  };
4764
4791
  _ts_decorate6([
4765
- import_tracing6.trace.span()
4766
- ], ServiceContext.prototype, "open", null);
4792
+ import_tracing5.trace.span()
4793
+ ], ServiceContext.prototype, "_open", null);
4767
4794
  _ts_decorate6([
4768
- import_tracing6.trace.span()
4795
+ import_tracing5.trace.span()
4769
4796
  ], ServiceContext.prototype, "_initialize", null);
4770
4797
  ServiceContext = _ts_decorate6([
4771
4798
  (0, import_util7.safeInstanceof)("dxos.client-services.ServiceContext"),
4772
- import_tracing6.trace.resource()
4799
+ import_tracing5.trace.resource()
4773
4800
  ], ServiceContext);
4774
4801
  var ServiceRegistry = class {
4775
4802
  // prettier-ignore
@@ -4793,103 +4820,155 @@ var ServiceRegistry = class {
4793
4820
  delete this._handlers[name];
4794
4821
  }
4795
4822
  };
4796
- function _ts_decorate7(decorators, target, key, desc) {
4797
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4798
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4799
- r = Reflect.decorate(decorators, target, key, desc);
4800
- else
4801
- for (var i = decorators.length - 1; i >= 0; i--)
4802
- if (d = decorators[i])
4803
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4804
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4805
- }
4806
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
4807
- var Lock = class {
4808
- constructor({ lockKey: lockPath, onAcquire, onRelease }) {
4809
- this._lockPath = lockPath;
4810
- this._onAcquire = onAcquire;
4811
- this._onRelease = onRelease;
4812
- }
4813
- get lockKey() {
4814
- return this._lockPath;
4815
- }
4816
- async acquire() {
4817
- (0, import_log13.log)("acquiring lock...", void 0, {
4818
- F: __dxlog_file16,
4819
- L: 32,
4820
- S: this,
4821
- C: (f, a) => f(...a)
4822
- });
4823
- this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
4824
- await this._onAcquire?.();
4825
- (0, import_log13.log)("acquired lock", void 0, {
4826
- F: __dxlog_file16,
4827
- L: 37,
4828
- S: this,
4829
- C: (f, a) => f(...a)
4830
- });
4823
+ var DXOS_VERSION = "0.4.10-main.36e0428";
4824
+ var getPlatform = () => {
4825
+ if (process.browser) {
4826
+ if (typeof window !== "undefined") {
4827
+ const { userAgent } = window.navigator;
4828
+ return {
4829
+ type: import_services13.Platform.PLATFORM_TYPE.BROWSER,
4830
+ userAgent,
4831
+ uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4832
+ };
4833
+ } else {
4834
+ return {
4835
+ type: import_services13.Platform.PLATFORM_TYPE.SHARED_WORKER,
4836
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4837
+ };
4838
+ }
4839
+ } else {
4840
+ const { platform: platform2, version, arch } = process;
4841
+ return {
4842
+ type: import_services13.Platform.PLATFORM_TYPE.NODE,
4843
+ platform: platform2,
4844
+ arch,
4845
+ runtime: version,
4846
+ uptime: Math.floor(process.uptime()),
4847
+ memory: process.memoryUsage()
4848
+ };
4831
4849
  }
4832
- async release() {
4833
- await this._onRelease?.();
4834
- (0, import_invariant15.invariant)(this._fileHandle, "Lock is not acquired", {
4835
- F: __dxlog_file16,
4836
- L: 42,
4837
- S: this,
4850
+ };
4851
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
4852
+ var DEFAULT_TIMEOUT = 1e3;
4853
+ var createDiagnostics = async (clientServices, serviceContext, config) => {
4854
+ const diagnostics = {
4855
+ created: (/* @__PURE__ */ new Date()).toISOString(),
4856
+ platform: getPlatform(),
4857
+ client: {
4858
+ version: DXOS_VERSION,
4859
+ storage: {
4860
+ version: import_protocols12.STORAGE_VERSION
4861
+ }
4862
+ },
4863
+ trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
4864
+ };
4865
+ {
4866
+ (0, import_invariant14.invariant)(clientServices.LoggingService, "SystemService is not available.", {
4867
+ F: __dxlog_file15,
4868
+ L: 108,
4869
+ S: void 0,
4838
4870
  A: [
4839
- "this._fileHandle",
4840
- "'Lock is not acquired'"
4871
+ "clientServices.LoggingService",
4872
+ "'SystemService is not available.'"
4841
4873
  ]
4842
4874
  });
4843
- await import_lock_file.LockFile.release(this._fileHandle);
4844
- }
4845
- };
4846
- _ts_decorate7([
4847
- import_log13.logInfo
4848
- ], Lock.prototype, "lockKey", null);
4849
- var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
4850
- var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4851
- var createStorageObjects = (config) => {
4852
- const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4853
- if (persistent && dataStore === StorageDriver.RAM) {
4854
- throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4875
+ diagnostics.metrics = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
4876
+ timeout: DEFAULT_TIMEOUT
4877
+ }).catch(() => void 0);
4855
4878
  }
4856
- if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4857
- throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4879
+ if (typeof navigator !== "undefined" && navigator.storage) {
4880
+ const map = /* @__PURE__ */ new Map();
4881
+ const dir = await navigator.storage.getDirectory();
4882
+ for await (const filename of dir?.keys()) {
4883
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
4884
+ if (idx === -1) {
4885
+ continue;
4886
+ }
4887
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
4888
+ }
4889
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
4890
+ file,
4891
+ count
4892
+ }));
4858
4893
  }
4859
- if (persistent && keyStore === StorageDriver.RAM) {
4860
- throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4894
+ const identity = serviceContext.identityManager.identity;
4895
+ if (identity) {
4896
+ diagnostics.identity = {
4897
+ identityKey: identity.identityKey,
4898
+ spaceKey: identity.space.key,
4899
+ profile: identity.profileDocument
4900
+ };
4901
+ const { devices } = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
4902
+ timeout: DEFAULT_TIMEOUT
4903
+ }).catch(() => void 0) ?? {};
4904
+ diagnostics.devices = devices;
4905
+ if (serviceContext.dataSpaceManager) {
4906
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
4907
+ }
4908
+ const { feeds = [] } = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
4909
+ timeout: DEFAULT_TIMEOUT
4910
+ }).catch(() => void 0) ?? {};
4911
+ diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
4912
+ feedKey,
4913
+ bytes,
4914
+ length
4915
+ }));
4916
+ const status = await (0, import_codec_protobuf11.getFirstStreamValue)(clientServices.NetworkService.queryStatus(), {
4917
+ timeout: DEFAULT_TIMEOUT
4918
+ }).catch(() => void 0);
4919
+ diagnostics.networkStatus = status;
4920
+ diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
4861
4921
  }
4862
- if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4863
- throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4922
+ diagnostics.config = config.values;
4923
+ return diagnostics;
4924
+ };
4925
+ var getSpaceStats = async (space) => {
4926
+ const stats = {
4927
+ key: space.key,
4928
+ metrics: space.metrics,
4929
+ epochs: space.inner.spaceState.credentials.filter((0, import_credentials16.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4930
+ ...credential.subject.assertion,
4931
+ id: credential.id
4932
+ })),
4933
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
4934
+ identity: {
4935
+ identityKey: member.key,
4936
+ profile: {
4937
+ displayName: member.assertion.profile?.displayName
4938
+ }
4939
+ },
4940
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services12.SpaceMember.PresenceState.ONLINE : import_services12.SpaceMember.PresenceState.OFFLINE
4941
+ })),
4942
+ pipeline: {
4943
+ // TODO(burdon): Pick properties from credentials if needed.
4944
+ currentEpoch: space.automergeSpaceState.lastEpoch,
4945
+ appliedEpoch: space.automergeSpaceState.lastEpoch,
4946
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
4947
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
4948
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
4949
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
4950
+ }
4951
+ };
4952
+ if (stats.metrics) {
4953
+ const { open, ready } = stats.metrics;
4954
+ stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
4864
4955
  }
4956
+ return stats;
4957
+ };
4958
+ var createCollectDiagnosticsBroadcastSender = () => {
4865
4959
  return {
4866
- storage: (0, import_random_access_storage.createStorage)({
4867
- type: persistent ? toStorageType(dataStore) : import_random_access_storage.StorageType.RAM,
4868
- root: `${dataRoot}/`
4869
- })
4960
+ broadcastDiagnosticsRequest: async () => void 0
4870
4961
  };
4871
4962
  };
4872
- var toStorageType = (type) => {
4873
- switch (type) {
4874
- case void 0:
4875
- return void 0;
4876
- case StorageDriver.RAM:
4877
- return import_random_access_storage.StorageType.RAM;
4878
- case StorageDriver.CHROME:
4879
- return import_random_access_storage.StorageType.CHROME;
4880
- case StorageDriver.FIREFOX:
4881
- return import_random_access_storage.StorageType.FIREFOX;
4882
- case StorageDriver.IDB:
4883
- return import_random_access_storage.StorageType.IDB;
4884
- case StorageDriver.NODE:
4885
- return import_random_access_storage.StorageType.NODE;
4886
- case StorageDriver.WEBFS:
4887
- return import_random_access_storage.StorageType.WEBFS;
4888
- default:
4889
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
4890
- }
4963
+ var createCollectDiagnosticsBroadcastHandler = (_) => {
4964
+ return {
4965
+ start: () => {
4966
+ },
4967
+ stop: () => {
4968
+ }
4969
+ };
4891
4970
  };
4892
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4971
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4893
4972
  var DevicesServiceImpl = class {
4894
4973
  constructor(_identityManager) {
4895
4974
  this._identityManager = _identityManager;
@@ -4906,8 +4985,8 @@ var DevicesServiceImpl = class {
4906
4985
  devices: []
4907
4986
  });
4908
4987
  } else {
4909
- (0, import_invariant17.invariant)(this._identityManager.identity?.presence, "presence not present", {
4910
- F: __dxlog_file17,
4988
+ (0, import_invariant16.invariant)(this._identityManager.identity?.presence, "presence not present", {
4989
+ F: __dxlog_file16,
4911
4990
  L: 32,
4912
4991
  S: this,
4913
4992
  A: [
@@ -4922,9 +5001,9 @@ var DevicesServiceImpl = class {
4922
5001
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
4923
5002
  return {
4924
5003
  deviceKey: key,
4925
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services14.DeviceKind.CURRENT : import_services14.DeviceKind.TRUSTED,
5004
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services16.DeviceKind.CURRENT : import_services16.DeviceKind.TRUSTED,
4926
5005
  profile,
4927
- presence: isMe ? import_services14.Device.PresenceState.ONLINE : peerState ? import_services14.Device.PresenceState.ONLINE : import_services14.Device.PresenceState.OFFLINE
5006
+ presence: isMe ? import_services16.Device.PresenceState.ONLINE : peerState ? import_services16.Device.PresenceState.ONLINE : import_services16.Device.PresenceState.OFFLINE
4928
5007
  };
4929
5008
  })
4930
5009
  });
@@ -4965,11 +5044,65 @@ var DevicesServiceImpl = class {
4965
5044
  });
4966
5045
  }
4967
5046
  };
5047
+ function _ts_decorate7(decorators, target, key, desc) {
5048
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5049
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
5050
+ r = Reflect.decorate(decorators, target, key, desc);
5051
+ else
5052
+ for (var i = decorators.length - 1; i >= 0; i--)
5053
+ if (d = decorators[i])
5054
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5055
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5056
+ }
5057
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
5058
+ var Lock = class {
5059
+ constructor({ lockKey: lockPath, onAcquire, onRelease }) {
5060
+ this._lockPath = lockPath;
5061
+ this._onAcquire = onAcquire;
5062
+ this._onRelease = onRelease;
5063
+ }
5064
+ get lockKey() {
5065
+ return this._lockPath;
5066
+ }
5067
+ async acquire() {
5068
+ (0, import_log14.log)("acquiring lock...", void 0, {
5069
+ F: __dxlog_file17,
5070
+ L: 32,
5071
+ S: this,
5072
+ C: (f, a) => f(...a)
5073
+ });
5074
+ this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
5075
+ await this._onAcquire?.();
5076
+ (0, import_log14.log)("acquired lock", void 0, {
5077
+ F: __dxlog_file17,
5078
+ L: 37,
5079
+ S: this,
5080
+ C: (f, a) => f(...a)
5081
+ });
5082
+ }
5083
+ async release() {
5084
+ await this._onRelease?.();
5085
+ (0, import_invariant17.invariant)(this._fileHandle, "Lock is not acquired", {
5086
+ F: __dxlog_file17,
5087
+ L: 42,
5088
+ S: this,
5089
+ A: [
5090
+ "this._fileHandle",
5091
+ "'Lock is not acquired'"
5092
+ ]
5093
+ });
5094
+ await import_lock_file.LockFile.release(this._fileHandle);
5095
+ }
5096
+ };
5097
+ _ts_decorate7([
5098
+ import_log14.logInfo
5099
+ ], Lock.prototype, "lockKey", null);
5100
+ var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
4968
5101
  var LoggingServiceImpl = class {
4969
5102
  constructor() {
4970
5103
  this._logs = new import_async18.Event();
4971
5104
  this._started = Date.now();
4972
- this._sessionId = import_keys12.PublicKey.random().toHex();
5105
+ this._sessionId = import_keys13.PublicKey.random().toHex();
4973
5106
  this._logProcessor = (_config, entry2) => {
4974
5107
  this._logs.emit(entry2);
4975
5108
  };
@@ -5064,18 +5197,18 @@ var LoggingServiceImpl = class {
5064
5197
  });
5065
5198
  }
5066
5199
  };
5067
- var matchFilter = (filter, level, path, options) => {
5200
+ var matchFilter = (filter, level, path2, options) => {
5068
5201
  switch (options) {
5069
- case import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5070
- return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
5071
- case import_services15.QueryLogsRequest.MatchingOptions.EXPLICIT:
5072
- return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
5202
+ case import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5203
+ return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5204
+ case import_services17.QueryLogsRequest.MatchingOptions.EXPLICIT:
5205
+ return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5073
5206
  }
5074
5207
  };
5075
5208
  var shouldLog = (entry2, request) => {
5076
- const options = request.options ?? import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5209
+ const options = request.options ?? import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5077
5210
  if (request.filters === void 0) {
5078
- return options === import_services15.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5211
+ return options === import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5079
5212
  } else {
5080
5213
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
5081
5214
  }
@@ -5111,6 +5244,63 @@ var NetworkServiceImpl = class {
5111
5244
  await this.networkManager.setConnectionState(request.swarm);
5112
5245
  }
5113
5246
  };
5247
+ var getRootPath = (config) => {
5248
+ const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5249
+ return `${dataRoot}/`;
5250
+ };
5251
+ var isPersistent = (config) => {
5252
+ const { persistent = false } = config ?? {};
5253
+ return config.dataStore !== void 0 && config.dataStore !== import_config3.Runtime.Client.Storage.StorageDriver.RAM || persistent;
5254
+ };
5255
+ var StorageDriver = import_config2.Runtime.Client.Storage.StorageDriver;
5256
+ var createStorageObjects = (config) => {
5257
+ const { persistent = false, keyStore, dataStore } = config ?? {};
5258
+ if (persistent && dataStore === StorageDriver.RAM) {
5259
+ throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
5260
+ }
5261
+ if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5262
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5263
+ }
5264
+ if (persistent && keyStore === StorageDriver.RAM) {
5265
+ throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5266
+ }
5267
+ if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5268
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5269
+ }
5270
+ return {
5271
+ storage: (0, import_random_access_storage.createStorage)({
5272
+ type: persistent ? toStorageType(dataStore) : import_random_access_storage.StorageType.RAM,
5273
+ root: getRootPath(config)
5274
+ })
5275
+ };
5276
+ };
5277
+ var toStorageType = (type) => {
5278
+ switch (type) {
5279
+ case void 0:
5280
+ return void 0;
5281
+ case StorageDriver.RAM:
5282
+ return import_random_access_storage.StorageType.RAM;
5283
+ case StorageDriver.CHROME:
5284
+ return import_random_access_storage.StorageType.CHROME;
5285
+ case StorageDriver.FIREFOX:
5286
+ return import_random_access_storage.StorageType.FIREFOX;
5287
+ case StorageDriver.IDB:
5288
+ return import_random_access_storage.StorageType.IDB;
5289
+ case StorageDriver.NODE:
5290
+ return import_random_access_storage.StorageType.NODE;
5291
+ case StorageDriver.WEBFS:
5292
+ return import_random_access_storage.StorageType.WEBFS;
5293
+ default:
5294
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
5295
+ }
5296
+ };
5297
+ var createLevel = async (config) => {
5298
+ const persistent = isPersistent(config);
5299
+ const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys14.PublicKey.random().toHex()}`;
5300
+ const level = new import_level.Level(storagePath);
5301
+ await level.open();
5302
+ return level;
5303
+ };
5114
5304
  var SystemServiceImpl = class {
5115
5305
  constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
5116
5306
  this._config = config;
@@ -5130,9 +5320,9 @@ var SystemServiceImpl = class {
5130
5320
  const diagnostics = await this._getDiagnostics();
5131
5321
  return {
5132
5322
  timestamp: /* @__PURE__ */ new Date(),
5133
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util11.jsonKeyReplacer)({
5134
- truncate: keys === import_services16.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5135
- humanize: keys === import_services16.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5323
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)({
5324
+ truncate: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5325
+ humanize: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5136
5326
  })))
5137
5327
  };
5138
5328
  }
@@ -5180,16 +5370,18 @@ var ClientServicesHost = class {
5180
5370
  transportFactory,
5181
5371
  signalManager,
5182
5372
  storage,
5373
+ level,
5183
5374
  // TODO(wittjosiah): Turn this on by default.
5184
5375
  lockKey,
5185
5376
  callbacks,
5186
5377
  runtimeParams
5187
5378
  } = {}) {
5188
- this._tracingService = import_tracing7.TRACE_PROCESSOR.createTraceSender();
5379
+ this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
5189
5380
  this._statusUpdate = new import_async16.Event();
5190
5381
  this._opening = false;
5191
5382
  this._open = false;
5192
5383
  this._storage = storage;
5384
+ this._level = level;
5193
5385
  this._callbacks = callbacks;
5194
5386
  this._runtimeParams = runtimeParams;
5195
5387
  if (config) {
@@ -5213,14 +5405,14 @@ var ClientServicesHost = class {
5213
5405
  this._systemService = new SystemServiceImpl({
5214
5406
  config: () => this._config,
5215
5407
  statusUpdate: this._statusUpdate,
5216
- getCurrentStatus: () => this.isOpen ? import_services13.SystemStatus.ACTIVE : import_services13.SystemStatus.INACTIVE,
5408
+ getCurrentStatus: () => this.isOpen ? import_services15.SystemStatus.ACTIVE : import_services15.SystemStatus.INACTIVE,
5217
5409
  getDiagnostics: () => {
5218
5410
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
5219
5411
  },
5220
5412
  onUpdateStatus: async (status) => {
5221
- if (!this.isOpen && status === import_services13.SystemStatus.ACTIVE) {
5413
+ if (!this.isOpen && status === import_services15.SystemStatus.ACTIVE) {
5222
5414
  await this._resourceLock?.acquire();
5223
- } else if (this.isOpen && status === import_services13.SystemStatus.INACTIVE) {
5415
+ } else if (this.isOpen && status === import_services15.SystemStatus.INACTIVE) {
5224
5416
  await this._resourceLock?.release();
5225
5417
  }
5226
5418
  },
@@ -5228,6 +5420,7 @@ var ClientServicesHost = class {
5228
5420
  await this.reset();
5229
5421
  }
5230
5422
  });
5423
+ this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5231
5424
  this._loggingService = new LoggingServiceImpl();
5232
5425
  this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
5233
5426
  SystemService: this._systemService,
@@ -5258,25 +5451,25 @@ var ClientServicesHost = class {
5258
5451
  * Can only be called once.
5259
5452
  */
5260
5453
  initialize({ config, ...options }) {
5261
- (0, import_invariant16.invariant)(!this._open, "service host is open", {
5454
+ (0, import_invariant15.invariant)(!this._open, "service host is open", {
5262
5455
  F: __dxlog_file18,
5263
- L: 179,
5456
+ L: 190,
5264
5457
  S: this,
5265
5458
  A: [
5266
5459
  "!this._open",
5267
5460
  "'service host is open'"
5268
5461
  ]
5269
5462
  });
5270
- (0, import_log14.log)("initializing...", void 0, {
5463
+ (0, import_log13.log)("initializing...", void 0, {
5271
5464
  F: __dxlog_file18,
5272
- L: 180,
5465
+ L: 191,
5273
5466
  S: this,
5274
5467
  C: (f, a) => f(...a)
5275
5468
  });
5276
5469
  if (config) {
5277
- (0, import_invariant16.invariant)(!this._config, "config already set", {
5470
+ (0, import_invariant15.invariant)(!this._config, "config already set", {
5278
5471
  F: __dxlog_file18,
5279
- L: 183,
5472
+ L: 194,
5280
5473
  S: this,
5281
5474
  A: [
5282
5475
  "!this._config",
@@ -5289,9 +5482,9 @@ var ClientServicesHost = class {
5289
5482
  }
5290
5483
  }
5291
5484
  if (!options.signalManager) {
5292
- import_log14.log.warn("running signaling without telemetry metadata.", void 0, {
5485
+ import_log13.log.warn("running signaling without telemetry metadata.", void 0, {
5293
5486
  F: __dxlog_file18,
5294
- L: 191,
5487
+ L: 202,
5295
5488
  S: this,
5296
5489
  C: (f, a) => f(...a)
5297
5490
  });
@@ -5300,9 +5493,9 @@ var ClientServicesHost = class {
5300
5493
  iceServers: this._config?.get("runtime.services.ice")
5301
5494
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5302
5495
  this._signalManager = signalManager;
5303
- (0, import_invariant16.invariant)(!this._networkManager, "network manager already set", {
5496
+ (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
5304
5497
  F: __dxlog_file18,
5305
- L: 202,
5498
+ L: 213,
5306
5499
  S: this,
5307
5500
  A: [
5308
5501
  "!this._networkManager",
@@ -5314,9 +5507,9 @@ var ClientServicesHost = class {
5314
5507
  transportFactory,
5315
5508
  signalManager
5316
5509
  });
5317
- (0, import_log14.log)("initialized", void 0, {
5510
+ (0, import_log13.log)("initialized", void 0, {
5318
5511
  F: __dxlog_file18,
5319
- L: 209,
5512
+ L: 220,
5320
5513
  S: this,
5321
5514
  C: (f, a) => f(...a)
5322
5515
  });
@@ -5325,45 +5518,45 @@ var ClientServicesHost = class {
5325
5518
  if (this._open) {
5326
5519
  return;
5327
5520
  }
5328
- const traceId = import_keys11.PublicKey.random().toHex();
5329
- import_log14.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
5521
+ const traceId = import_keys12.PublicKey.random().toHex();
5522
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols13.trace.begin({
5330
5523
  id: traceId
5331
5524
  }), {
5332
5525
  F: __dxlog_file18,
5333
- L: 220,
5526
+ L: 231,
5334
5527
  S: this,
5335
5528
  C: (f, a) => f(...a)
5336
5529
  });
5337
- (0, import_invariant16.invariant)(this._config, "config not set", {
5530
+ (0, import_invariant15.invariant)(this._config, "config not set", {
5338
5531
  F: __dxlog_file18,
5339
- L: 222,
5532
+ L: 233,
5340
5533
  S: this,
5341
5534
  A: [
5342
5535
  "this._config",
5343
5536
  "'config not set'"
5344
5537
  ]
5345
5538
  });
5346
- (0, import_invariant16.invariant)(this._storage, "storage not set", {
5539
+ (0, import_invariant15.invariant)(this._storage, "storage not set", {
5347
5540
  F: __dxlog_file18,
5348
- L: 223,
5541
+ L: 234,
5349
5542
  S: this,
5350
5543
  A: [
5351
5544
  "this._storage",
5352
5545
  "'storage not set'"
5353
5546
  ]
5354
5547
  });
5355
- (0, import_invariant16.invariant)(this._signalManager, "signal manager not set", {
5548
+ (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
5356
5549
  F: __dxlog_file18,
5357
- L: 224,
5550
+ L: 235,
5358
5551
  S: this,
5359
5552
  A: [
5360
5553
  "this._signalManager",
5361
5554
  "'signal manager not set'"
5362
5555
  ]
5363
5556
  });
5364
- (0, import_invariant16.invariant)(this._networkManager, "network manager not set", {
5557
+ (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
5365
5558
  F: __dxlog_file18,
5366
- L: 225,
5559
+ L: 236,
5367
5560
  S: this,
5368
5561
  A: [
5369
5562
  "this._networkManager",
@@ -5371,31 +5564,32 @@ var ClientServicesHost = class {
5371
5564
  ]
5372
5565
  });
5373
5566
  this._opening = true;
5374
- (0, import_log14.log)("opening...", {
5567
+ (0, import_log13.log)("opening...", {
5375
5568
  lockKey: this._resourceLock?.lockKey
5376
5569
  }, {
5377
5570
  F: __dxlog_file18,
5378
- L: 228,
5571
+ L: 239,
5379
5572
  S: this,
5380
5573
  C: (f, a) => f(...a)
5381
5574
  });
5575
+ if (!this._level) {
5576
+ this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5577
+ }
5578
+ await this._level.open();
5382
5579
  await this._resourceLock?.acquire();
5383
5580
  await this._loggingService.open();
5384
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._runtimeParams);
5581
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5385
5582
  this._serviceRegistry.setServices({
5386
5583
  SystemService: this._systemService,
5387
5584
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5388
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5585
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
5389
5586
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5390
5587
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
5391
5588
  await this._serviceContext.initialized.wait();
5392
5589
  return this._serviceContext.dataSpaceManager;
5393
5590
  }),
5394
- DataService: new import_echo_pipeline4.DataServiceImpl(this._serviceContext.automergeHost),
5395
- IndexService: new import_indexing2.IndexServiceImpl({
5396
- indexer: this._serviceContext.indexer,
5397
- automergeHost: this._serviceContext.automergeHost
5398
- }),
5591
+ DataService: this._serviceContext.echoHost.dataService,
5592
+ QueryService: this._serviceContext.echoHost.queryService,
5399
5593
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5400
5594
  LoggingService: this._loggingService,
5401
5595
  TracingService: this._tracingService,
@@ -5407,24 +5601,6 @@ var ClientServicesHost = class {
5407
5601
  })
5408
5602
  });
5409
5603
  await this._serviceContext.open(ctx);
5410
- (0, import_invariant16.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5411
- F: __dxlog_file18,
5412
- L: 289,
5413
- S: this,
5414
- A: [
5415
- "this.serviceRegistry.services.InvitationsService",
5416
- ""
5417
- ]
5418
- });
5419
- const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5420
- (0, import_log14.log)("loaded persistent invitations", {
5421
- count: loadedInvitations.invitations?.length
5422
- }, {
5423
- F: __dxlog_file18,
5424
- L: 292,
5425
- S: this,
5426
- C: (f, a) => f(...a)
5427
- });
5428
5604
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5429
5605
  if (devtoolsProxy) {
5430
5606
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
@@ -5435,23 +5611,24 @@ var ClientServicesHost = class {
5435
5611
  });
5436
5612
  void this._devtoolsProxy.open();
5437
5613
  }
5614
+ this.diagnosticsBroadcastHandler.start();
5438
5615
  this._opening = false;
5439
5616
  this._open = true;
5440
5617
  this._statusUpdate.emit();
5441
5618
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5442
- (0, import_log14.log)("opened", {
5619
+ (0, import_log13.log)("opened", {
5443
5620
  deviceKey
5444
5621
  }, {
5445
5622
  F: __dxlog_file18,
5446
- L: 309,
5623
+ L: 315,
5447
5624
  S: this,
5448
5625
  C: (f, a) => f(...a)
5449
5626
  });
5450
- import_log14.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
5627
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols13.trace.end({
5451
5628
  id: traceId
5452
5629
  }), {
5453
5630
  F: __dxlog_file18,
5454
- L: 310,
5631
+ L: 316,
5455
5632
  S: this,
5456
5633
  C: (f, a) => f(...a)
5457
5634
  });
@@ -5461,60 +5638,62 @@ var ClientServicesHost = class {
5461
5638
  return;
5462
5639
  }
5463
5640
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
5464
- (0, import_log14.log)("closing...", {
5641
+ (0, import_log13.log)("closing...", {
5465
5642
  deviceKey
5466
5643
  }, {
5467
5644
  F: __dxlog_file18,
5468
- L: 321,
5645
+ L: 327,
5469
5646
  S: this,
5470
5647
  C: (f, a) => f(...a)
5471
5648
  });
5649
+ this.diagnosticsBroadcastHandler.stop();
5472
5650
  await this._devtoolsProxy?.close();
5473
5651
  this._serviceRegistry.setServices({
5474
5652
  SystemService: this._systemService
5475
5653
  });
5476
5654
  await this._loggingService.close();
5477
5655
  await this._serviceContext.close();
5656
+ await this._level?.close();
5478
5657
  this._open = false;
5479
5658
  this._statusUpdate.emit();
5480
- (0, import_log14.log)("closed", {
5659
+ (0, import_log13.log)("closed", {
5481
5660
  deviceKey
5482
5661
  }, {
5483
5662
  F: __dxlog_file18,
5484
- L: 328,
5663
+ L: 336,
5485
5664
  S: this,
5486
5665
  C: (f, a) => f(...a)
5487
5666
  });
5488
5667
  }
5489
5668
  async reset() {
5490
- const traceId = import_keys11.PublicKey.random().toHex();
5491
- import_log14.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
5669
+ const traceId = import_keys12.PublicKey.random().toHex();
5670
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols13.trace.begin({
5492
5671
  id: traceId
5493
5672
  }), {
5494
5673
  F: __dxlog_file18,
5495
- L: 333,
5674
+ L: 341,
5496
5675
  S: this,
5497
5676
  C: (f, a) => f(...a)
5498
5677
  });
5499
- (0, import_log14.log)("resetting...", void 0, {
5678
+ (0, import_log13.log)("resetting...", void 0, {
5500
5679
  F: __dxlog_file18,
5501
- L: 335,
5680
+ L: 343,
5502
5681
  S: this,
5503
5682
  C: (f, a) => f(...a)
5504
5683
  });
5505
5684
  await this._serviceContext?.close();
5506
5685
  await this._storage.reset();
5507
- (0, import_log14.log)("reset", void 0, {
5686
+ (0, import_log13.log)("reset", void 0, {
5508
5687
  F: __dxlog_file18,
5509
- L: 338,
5688
+ L: 346,
5510
5689
  S: this,
5511
5690
  C: (f, a) => f(...a)
5512
5691
  });
5513
- import_log14.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
5692
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols13.trace.end({
5514
5693
  id: traceId
5515
5694
  }), {
5516
5695
  F: __dxlog_file18,
5517
- L: 339,
5696
+ L: 347,
5518
5697
  S: this,
5519
5698
  C: (f, a) => f(...a)
5520
5699
  });
@@ -5525,20 +5704,20 @@ var ClientServicesHost = class {
5525
5704
  await this._serviceContext.initialized.wait();
5526
5705
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5527
5706
  const automergeIndex = space.automergeSpaceState.rootUrl;
5528
- (0, import_invariant16.invariant)(automergeIndex, void 0, {
5707
+ (0, import_invariant15.invariant)(automergeIndex, void 0, {
5529
5708
  F: __dxlog_file18,
5530
- L: 351,
5709
+ L: 359,
5531
5710
  S: this,
5532
5711
  A: [
5533
5712
  "automergeIndex",
5534
5713
  ""
5535
5714
  ]
5536
5715
  });
5537
- const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5716
+ const document = await this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
5538
5717
  await document.whenReady();
5539
5718
  const properties = {
5540
5719
  system: {
5541
- type: (0, import_echo_pipeline4.encodeReference)(E.getTypeReference(import_client_protocol5.Properties))
5720
+ type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.Properties))
5542
5721
  },
5543
5722
  data: {
5544
5723
  [import_client_protocol5.defaultKey]: identity.identityKey.toHex()
@@ -5547,47 +5726,82 @@ var ClientServicesHost = class {
5547
5726
  keys: []
5548
5727
  }
5549
5728
  };
5550
- const propertiesId = import_keys11.PublicKey.random().toHex();
5729
+ const propertiesId = import_keys12.PublicKey.random().toHex();
5551
5730
  document.change((doc) => {
5552
5731
  (0, import_util9.assignDeep)(doc, [
5553
5732
  "objects",
5554
5733
  propertiesId
5555
5734
  ], properties);
5556
5735
  });
5557
- await this._serviceContext.automergeHost.repo.flush();
5736
+ await this._serviceContext.echoHost.flush();
5558
5737
  return identity;
5559
5738
  }
5560
5739
  };
5561
5740
  _ts_decorate8([
5562
- import_tracing7.trace.info()
5741
+ import_tracing8.trace.info()
5563
5742
  ], ClientServicesHost.prototype, "_opening", void 0);
5564
5743
  _ts_decorate8([
5565
- import_tracing7.trace.info()
5744
+ import_tracing8.trace.info()
5566
5745
  ], ClientServicesHost.prototype, "_open", void 0);
5567
5746
  _ts_decorate8([
5568
5747
  import_async16.synchronized,
5569
- import_tracing7.trace.span()
5748
+ import_tracing8.trace.span()
5570
5749
  ], ClientServicesHost.prototype, "open", null);
5571
5750
  _ts_decorate8([
5572
5751
  import_async16.synchronized,
5573
- import_tracing7.trace.span()
5752
+ import_tracing8.trace.span()
5574
5753
  ], ClientServicesHost.prototype, "close", null);
5575
5754
  ClientServicesHost = _ts_decorate8([
5576
- import_tracing7.trace.resource()
5755
+ import_tracing8.trace.resource()
5577
5756
  ], ClientServicesHost);
5757
+ var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
5758
+ var DiagnosticsCollector = class {
5759
+ static {
5760
+ this.broadcastSender = createCollectDiagnosticsBroadcastSender();
5761
+ }
5762
+ static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5763
+ const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5764
+ keys: options.humanize ? import_services14.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services14.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5765
+ });
5766
+ const clientDiagnostics = {
5767
+ config,
5768
+ trace: import_tracing7.TRACE_PROCESSOR.getDiagnostics()
5769
+ };
5770
+ const diagnostics = serviceDiagnostics != null ? {
5771
+ client: clientDiagnostics,
5772
+ services: serviceDiagnostics
5773
+ } : {
5774
+ client: clientDiagnostics,
5775
+ broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
5776
+ };
5777
+ return JSON.parse(JSON.stringify(diagnostics, (0, import_util8.jsonKeyReplacer)(options)));
5778
+ }
5779
+ };
5780
+ var findSystemServiceProvider = () => {
5781
+ const serviceProviders = import_tracing7.TRACE_PROCESSOR.findByAnnotation(ClientServicesProviderResource);
5782
+ const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
5783
+ return providerResource?.instance?.deref() ?? null;
5784
+ };
5785
+ var findConfigs = () => {
5786
+ const configs = import_tracing7.TRACE_PROCESSOR.findByAnnotation(import_config.ConfigResource);
5787
+ return configs.map((r) => r.instance.deref()).filter(import_util8.nonNullable);
5788
+ };
5578
5789
  // Annotate the CommonJS export names for ESM import in node:
5579
5790
  0 && (module.exports = {
5580
5791
  ClientRpcServer,
5581
5792
  ClientServicesHost,
5793
+ ClientServicesProviderResource,
5582
5794
  DataSpace,
5583
5795
  DataSpaceManager,
5584
5796
  DeviceInvitationProtocol,
5585
5797
  DevtoolsHostEvents,
5586
5798
  DevtoolsServiceImpl,
5799
+ DiagnosticsCollector,
5587
5800
  Identity,
5588
5801
  IdentityManager,
5589
5802
  IdentityServiceImpl,
5590
5803
  InvitationsHandler,
5804
+ InvitationsManager,
5591
5805
  InvitationsServiceImpl,
5592
5806
  Lock,
5593
5807
  ServiceContext,
@@ -5595,11 +5809,14 @@ ClientServicesHost = _ts_decorate8([
5595
5809
  SpaceInvitationProtocol,
5596
5810
  SpacesServiceImpl,
5597
5811
  TrustedKeySetAuthVerifier,
5812
+ createAdmissionKeypair,
5598
5813
  createAuthProvider,
5814
+ createCollectDiagnosticsBroadcastHandler,
5815
+ createCollectDiagnosticsBroadcastSender,
5599
5816
  createDiagnostics,
5817
+ createLevel,
5600
5818
  createStorageObjects,
5601
5819
  getNetworkPeers,
5602
- invitationExpired,
5603
5820
  isLocked,
5604
5821
  subscribeToFeedBlocks,
5605
5822
  subscribeToFeeds,
@@ -5609,4 +5826,4 @@ ClientServicesHost = _ts_decorate8([
5609
5826
  subscribeToSpaces,
5610
5827
  subscribeToSwarmInfo
5611
5828
  });
5612
- //# sourceMappingURL=chunk-6X2EZZDT.cjs.map
5829
+ //# sourceMappingURL=chunk-2L6Y2DJQ.cjs.map