@dxos/client-services 0.4.10-main.b3cf40d → 0.4.10-main.bb9f1bf

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