@dxos/client-services 0.4.10-main.0302e13 → 0.4.10-main.05b9ab6

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