@dxos/client-services 0.3.11-main.7ff9773 → 0.3.11-main.800163e

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 (53) hide show
  1. package/dist/lib/browser/{chunk-5EFJSN6A.mjs → chunk-GUFT4GX3.mjs} +164 -82
  2. package/dist/lib/browser/chunk-GUFT4GX3.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +4 -11
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-34H4H2HZ.cjs → chunk-GNBZGQOY.cjs} +300 -218
  8. package/dist/lib/node/chunk-GNBZGQOY.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +37 -37
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +11 -18
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -0
  14. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +28 -3
  16. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -0
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/diagnostics.d.ts +5 -2
  22. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  23. package/dist/types/src/packlets/services/platform.d.ts +1 -14
  24. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  26. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space.d.ts +1 -0
  29. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  30. package/dist/types/src/packlets/system/system-service.d.ts +2 -1
  31. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  32. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  33. package/dist/types/src/version.d.ts +1 -1
  34. package/package.json +35 -35
  35. package/src/packlets/identity/identity-manager.ts +1 -1
  36. package/src/packlets/invitations/device-invitation-protocol.test.ts +14 -0
  37. package/src/packlets/invitations/device-invitation-protocol.ts +14 -0
  38. package/src/packlets/invitations/invitation-protocol.ts +44 -6
  39. package/src/packlets/invitations/invitations-handler.ts +19 -17
  40. package/src/packlets/invitations/space-invitation-protocol.test.ts +28 -0
  41. package/src/packlets/invitations/space-invitation-protocol.ts +11 -0
  42. package/src/packlets/network/network-service.ts +1 -0
  43. package/src/packlets/services/diagnostics.ts +20 -1
  44. package/src/packlets/services/platform.ts +7 -19
  45. package/src/packlets/spaces/automerge-space-state.ts +4 -0
  46. package/src/packlets/spaces/data-space-manager.ts +5 -1
  47. package/src/packlets/spaces/data-space.ts +21 -1
  48. package/src/packlets/spaces/spaces-service.ts +1 -1
  49. package/src/packlets/system/system-service.ts +6 -0
  50. package/src/packlets/testing/invitation-utils.ts +2 -10
  51. package/src/version.ts +1 -1
  52. package/dist/lib/browser/chunk-5EFJSN6A.mjs.map +0 -7
  53. package/dist/lib/node/chunk-34H4H2HZ.cjs.map +0 -7
@@ -26,8 +26,8 @@ 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_34H4H2HZ_exports = {};
30
- __export(chunk_34H4H2HZ_exports, {
29
+ var chunk_GNBZGQOY_exports = {};
30
+ __export(chunk_GNBZGQOY_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -60,7 +60,7 @@ __export(chunk_34H4H2HZ_exports, {
60
60
  subscribeToSpaces: () => subscribeToSpaces,
61
61
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
62
  });
63
- module.exports = __toCommonJS(chunk_34H4H2HZ_exports);
63
+ module.exports = __toCommonJS(chunk_GNBZGQOY_exports);
64
64
  var import_async = require("@dxos/async");
65
65
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
66
  var import_feed_store = require("@dxos/feed-store");
@@ -108,6 +108,7 @@ var import_credentials6 = require("@dxos/credentials");
108
108
  var import_debug2 = require("@dxos/debug");
109
109
  var import_invariant3 = require("@dxos/invariant");
110
110
  var import_invariant4 = require("@dxos/invariant");
111
+ var import_protocols3 = require("@dxos/protocols");
111
112
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
112
113
  var import_async7 = require("@dxos/async");
113
114
  var import_client_protocol2 = require("@dxos/client-protocol");
@@ -117,7 +118,7 @@ var import_invariant5 = require("@dxos/invariant");
117
118
  var import_keys5 = require("@dxos/keys");
118
119
  var import_log4 = require("@dxos/log");
119
120
  var import_network_manager = require("@dxos/network-manager");
120
- var import_protocols3 = require("@dxos/protocols");
121
+ var import_protocols4 = require("@dxos/protocols");
121
122
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
122
123
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
123
124
  var import_async8 = require("@dxos/async");
@@ -125,7 +126,7 @@ var import_context5 = require("@dxos/context");
125
126
  var import_invariant6 = require("@dxos/invariant");
126
127
  var import_keys6 = require("@dxos/keys");
127
128
  var import_log5 = require("@dxos/log");
128
- var import_protocols4 = require("@dxos/protocols");
129
+ var import_protocols5 = require("@dxos/protocols");
129
130
  var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
130
131
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
131
132
  var import_teleport = require("@dxos/teleport");
@@ -138,6 +139,7 @@ var import_credentials8 = require("@dxos/credentials");
138
139
  var import_feed_store3 = require("@dxos/feed-store");
139
140
  var import_invariant8 = require("@dxos/invariant");
140
141
  var import_log7 = require("@dxos/log");
142
+ var import_protocols6 = require("@dxos/protocols");
141
143
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
142
144
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
143
145
  var import_debug3 = require("@dxos/debug");
@@ -149,17 +151,19 @@ var import_document_model = require("@dxos/document-model");
149
151
  var import_echo_db = require("@dxos/echo-db");
150
152
  var import_invariant9 = require("@dxos/invariant");
151
153
  var import_log8 = require("@dxos/log");
152
- var import_protocols5 = require("@dxos/protocols");
154
+ var import_protocols7 = require("@dxos/protocols");
153
155
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
156
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
154
157
  var import_async10 = require("@dxos/async");
155
158
  var import_client_protocol3 = require("@dxos/client-protocol");
156
159
  var import_context6 = require("@dxos/context");
157
160
  var import_debug4 = require("@dxos/debug");
158
161
  var import_echo_pipeline = require("@dxos/echo-pipeline");
162
+ var import_invariant10 = require("@dxos/invariant");
159
163
  var import_keys7 = require("@dxos/keys");
160
164
  var import_log9 = require("@dxos/log");
161
- var import_protocols6 = require("@dxos/protocols");
162
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
165
+ var import_protocols8 = require("@dxos/protocols");
166
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
163
167
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
164
168
  var import_timeframe2 = require("@dxos/timeframe");
165
169
  var import_tracing4 = require("@dxos/tracing");
@@ -167,20 +171,20 @@ var import_util4 = require("@dxos/util");
167
171
  var import_credentials11 = require("@dxos/credentials");
168
172
  var import_async11 = require("@dxos/async");
169
173
  var import_context7 = require("@dxos/context");
170
- var import_invariant10 = require("@dxos/invariant");
174
+ var import_invariant11 = require("@dxos/invariant");
171
175
  var import_keys8 = require("@dxos/keys");
172
176
  var import_log10 = require("@dxos/log");
173
- var import_protocols7 = require("@dxos/protocols");
177
+ var import_protocols9 = require("@dxos/protocols");
174
178
  var import_teleport2 = require("@dxos/teleport");
175
179
  var import_util5 = require("@dxos/util");
176
180
  var import_async12 = require("@dxos/async");
177
181
  var import_context8 = require("@dxos/context");
178
182
  var import_credentials12 = require("@dxos/credentials");
179
- var import_invariant11 = require("@dxos/invariant");
183
+ var import_invariant12 = require("@dxos/invariant");
180
184
  var import_keys9 = require("@dxos/keys");
181
185
  var import_log11 = require("@dxos/log");
182
- var import_protocols8 = require("@dxos/protocols");
183
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
186
+ var import_protocols10 = require("@dxos/protocols");
187
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
184
188
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
185
189
  var import_util6 = require("@dxos/util");
186
190
  var import_credentials13 = require("@dxos/credentials");
@@ -190,30 +194,30 @@ var import_timeframe3 = require("@dxos/timeframe");
190
194
  var import_async13 = require("@dxos/async");
191
195
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
192
196
  var import_debug6 = require("@dxos/debug");
193
- var import_invariant12 = require("@dxos/invariant");
197
+ var import_invariant13 = require("@dxos/invariant");
194
198
  var import_log12 = require("@dxos/log");
195
- var import_protocols9 = require("@dxos/protocols");
196
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
199
+ var import_protocols11 = require("@dxos/protocols");
200
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
197
201
  var import_async14 = require("@dxos/async");
198
202
  var import_context9 = require("@dxos/context");
199
203
  var import_credentials15 = require("@dxos/credentials");
200
204
  var import_debug7 = require("@dxos/debug");
201
205
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
202
206
  var import_feed_store4 = require("@dxos/feed-store");
203
- var import_invariant13 = require("@dxos/invariant");
207
+ var import_invariant14 = require("@dxos/invariant");
204
208
  var import_keyring = require("@dxos/keyring");
205
209
  var import_keys10 = require("@dxos/keys");
206
210
  var import_log13 = require("@dxos/log");
207
- var import_protocols10 = require("@dxos/protocols");
208
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
211
+ var import_protocols12 = require("@dxos/protocols");
212
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
209
213
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
210
214
  var import_tracing5 = require("@dxos/tracing");
211
215
  var import_util7 = require("@dxos/util");
212
- var import_invariant14 = require("@dxos/invariant");
216
+ var import_invariant15 = require("@dxos/invariant");
213
217
  var import_lock_file = require("@dxos/lock-file");
214
218
  var import_log14 = require("@dxos/log");
215
219
  var import_client_protocol4 = require("@dxos/client-protocol");
216
- var import_protocols11 = require("@dxos/protocols");
220
+ var import_protocols13 = require("@dxos/protocols");
217
221
  var import_config = require("@dxos/protocols/proto/dxos/config");
218
222
  var import_random_access_storage = require("@dxos/random-access-storage");
219
223
  var import_util8 = require("@dxos/util");
@@ -223,28 +227,28 @@ var import_context10 = require("@dxos/context");
223
227
  var import_document_model2 = require("@dxos/document-model");
224
228
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
225
229
  var import_echo_schema = require("@dxos/echo-schema");
226
- var import_invariant15 = require("@dxos/invariant");
230
+ var import_invariant16 = require("@dxos/invariant");
227
231
  var import_keys11 = require("@dxos/keys");
228
232
  var import_log15 = require("@dxos/log");
229
233
  var import_messaging = require("@dxos/messaging");
230
234
  var import_model_factory = require("@dxos/model-factory");
231
235
  var import_network_manager2 = require("@dxos/network-manager");
232
- var import_protocols12 = require("@dxos/protocols");
233
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
236
+ var import_protocols14 = require("@dxos/protocols");
237
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
234
238
  var import_text_model = require("@dxos/text-model");
235
239
  var import_tracing6 = require("@dxos/tracing");
236
240
  var import_websocket_rpc = require("@dxos/websocket-rpc");
237
241
  var import_async16 = require("@dxos/async");
238
242
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
239
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
243
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
240
244
  var import_async17 = require("@dxos/async");
241
245
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
242
246
  var import_log16 = require("@dxos/log");
243
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
247
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
244
248
  var import_util9 = require("@dxos/util");
245
249
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
246
250
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
247
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
251
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
248
252
  var import_util10 = require("@dxos/util");
249
253
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
250
254
  return new import_codec_protobuf.Stream(({ next }) => {
@@ -1174,7 +1178,7 @@ var IdentityManager = class {
1174
1178
  genesisFeedKey: spaceRecord.genesisFeedKey
1175
1179
  },
1176
1180
  swarmIdentity,
1177
- onNetworkConnection: () => {
1181
+ onAuthorizedConnection: () => {
1178
1182
  },
1179
1183
  onAuthFailure: () => {
1180
1184
  import_log3.log.warn("auth failure", void 0, {
@@ -1282,7 +1286,7 @@ var DeviceInvitationProtocol = class {
1282
1286
  async admit(request) {
1283
1287
  (0, import_invariant4.invariant)(request.device, void 0, {
1284
1288
  F: __dxlog_file5,
1285
- L: 35,
1289
+ L: 36,
1286
1290
  S: this,
1287
1291
  A: [
1288
1292
  "request.device",
@@ -1300,6 +1304,15 @@ var DeviceInvitationProtocol = class {
1300
1304
  }
1301
1305
  };
1302
1306
  }
1307
+ checkInvitation(invitation) {
1308
+ try {
1309
+ const identity = this._getIdentity();
1310
+ if (identity) {
1311
+ return new import_protocols3.AlreadyJoinedError("Currently only one identity per client is supported.");
1312
+ }
1313
+ } catch {
1314
+ }
1315
+ }
1303
1316
  createIntroduction() {
1304
1317
  return {};
1305
1318
  }
@@ -1318,7 +1331,7 @@ var DeviceInvitationProtocol = class {
1318
1331
  async accept(response, request) {
1319
1332
  (0, import_invariant4.invariant)(response.device, void 0, {
1320
1333
  F: __dxlog_file5,
1321
- L: 68,
1334
+ L: 80,
1322
1335
  S: this,
1323
1336
  A: [
1324
1337
  "response.device",
@@ -1328,7 +1341,7 @@ var DeviceInvitationProtocol = class {
1328
1341
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1329
1342
  (0, import_invariant4.invariant)(request.device, void 0, {
1330
1343
  F: __dxlog_file5,
1331
- L: 71,
1344
+ L: 83,
1332
1345
  S: this,
1333
1346
  A: [
1334
1347
  "request.device",
@@ -1357,10 +1370,10 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1357
1370
  constructor(_callbacks) {
1358
1371
  super({
1359
1372
  requested: {
1360
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1373
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1361
1374
  },
1362
1375
  exposed: {
1363
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1376
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1364
1377
  }
1365
1378
  });
1366
1379
  this._callbacks = _callbacks;
@@ -1393,7 +1406,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1393
1406
  introduce: async (request) => {
1394
1407
  const { profile, invitationId } = request;
1395
1408
  const traceId = import_keys6.PublicKey.random().toHex();
1396
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.begin({
1409
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.begin({
1397
1410
  id: traceId
1398
1411
  }), {
1399
1412
  F: __dxlog_file6,
@@ -1430,7 +1443,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1430
1443
  ...this.invitation,
1431
1444
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1432
1445
  });
1433
- import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.end({
1446
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1434
1447
  id: traceId
1435
1448
  }), {
1436
1449
  F: __dxlog_file6,
@@ -1444,7 +1457,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1444
1457
  },
1445
1458
  authenticate: async ({ authCode: code }) => {
1446
1459
  const traceId = import_keys6.PublicKey.random().toHex();
1447
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.begin({
1460
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1448
1461
  id: traceId
1449
1462
  }), {
1450
1463
  F: __dxlog_file6,
@@ -1507,7 +1520,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1507
1520
  break;
1508
1521
  }
1509
1522
  }
1510
- import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.end({
1523
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.end({
1511
1524
  id: traceId,
1512
1525
  data: {
1513
1526
  status
@@ -1524,7 +1537,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1524
1537
  },
1525
1538
  admit: async (request) => {
1526
1539
  const traceId = import_keys6.PublicKey.random().toHex();
1527
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.begin({
1540
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.begin({
1528
1541
  id: traceId
1529
1542
  }), {
1530
1543
  F: __dxlog_file6,
@@ -1546,7 +1559,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1546
1559
  throw new Error("Not authenticated");
1547
1560
  }
1548
1561
  const response = await this._callbacks.admit(request);
1549
- import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.end({
1562
+ import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.end({
1550
1563
  id: traceId
1551
1564
  }), {
1552
1565
  F: __dxlog_file6,
@@ -1573,7 +1586,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1573
1586
  timeout: OPTIONS_TIMEOUT
1574
1587
  }));
1575
1588
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.GUEST) {
1576
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1589
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1577
1590
  expected: import_invitations2.Options.Role.GUEST,
1578
1591
  remoteOptions: this._remoteOptions
1579
1592
  });
@@ -1591,10 +1604,10 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1591
1604
  constructor(_callbacks) {
1592
1605
  super({
1593
1606
  requested: {
1594
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1607
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1595
1608
  },
1596
1609
  exposed: {
1597
- InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
1610
+ InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
1598
1611
  }
1599
1612
  });
1600
1613
  this._callbacks = _callbacks;
@@ -1651,7 +1664,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1651
1664
  C: (f, a) => f(...a)
1652
1665
  });
1653
1666
  if (this._remoteOptions?.role !== import_invitations2.Options.Role.HOST) {
1654
- throw new import_protocols4.InvalidInvitationExtensionRoleError(void 0, {
1667
+ throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
1655
1668
  expected: import_invitations2.Options.Role.HOST,
1656
1669
  remoteOptions: this._remoteOptions
1657
1670
  });
@@ -1764,7 +1777,7 @@ var InvitationsHandler = class {
1764
1777
  (0, import_async7.scheduleTask)(ctx, async () => {
1765
1778
  const traceId = import_keys5.PublicKey.random().toHex();
1766
1779
  try {
1767
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.begin({
1780
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1768
1781
  id: traceId
1769
1782
  }), {
1770
1783
  F: __dxlog_file7,
@@ -1800,7 +1813,7 @@ var InvitationsHandler = class {
1800
1813
  ...invitation,
1801
1814
  state: import_services2.Invitation.State.SUCCESS
1802
1815
  });
1803
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.end({
1816
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1804
1817
  id: traceId
1805
1818
  }), {
1806
1819
  F: __dxlog_file7,
@@ -1831,7 +1844,7 @@ var InvitationsHandler = class {
1831
1844
  });
1832
1845
  stream.error(err);
1833
1846
  }
1834
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.error({
1847
+ import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
1835
1848
  id: traceId,
1836
1849
  error: err
1837
1850
  }), {
@@ -1849,7 +1862,7 @@ var InvitationsHandler = class {
1849
1862
  });
1850
1863
  },
1851
1864
  onError: (err) => {
1852
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
1865
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
1853
1866
  return;
1854
1867
  }
1855
1868
  if (err instanceof import_async7.TimeoutError) {
@@ -1997,7 +2010,7 @@ var InvitationsHandler = class {
1997
2010
  (0, import_async7.scheduleTask)(ctx, async () => {
1998
2011
  const traceId = import_keys5.PublicKey.random().toHex();
1999
2012
  try {
2000
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.begin({
2013
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
2001
2014
  id: traceId
2002
2015
  }), {
2003
2016
  F: __dxlog_file7,
@@ -2084,16 +2097,12 @@ var InvitationsHandler = class {
2084
2097
  }
2085
2098
  }
2086
2099
  }
2087
- } else {
2088
- setState({
2089
- state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
2090
- });
2091
2100
  }
2092
2101
  (0, import_log4.log)("request admission", {
2093
2102
  ...protocol.toJSON()
2094
2103
  }, {
2095
2104
  F: __dxlog_file7,
2096
- L: 312,
2105
+ L: 309,
2097
2106
  S: this,
2098
2107
  C: (f, a) => f(...a)
2099
2108
  });
@@ -2105,7 +2114,7 @@ var InvitationsHandler = class {
2105
2114
  ...protocol.toJSON()
2106
2115
  }, {
2107
2116
  F: __dxlog_file7,
2108
- L: 323,
2117
+ L: 320,
2109
2118
  S: this,
2110
2119
  C: (f, a) => f(...a)
2111
2120
  });
@@ -2114,11 +2123,11 @@ var InvitationsHandler = class {
2114
2123
  target: invitation.target,
2115
2124
  state: import_services2.Invitation.State.SUCCESS
2116
2125
  });
2117
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.end({
2126
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
2118
2127
  id: traceId
2119
2128
  }), {
2120
2129
  F: __dxlog_file7,
2121
- L: 325,
2130
+ L: 322,
2122
2131
  S: this,
2123
2132
  C: (f, a) => f(...a)
2124
2133
  });
@@ -2128,7 +2137,7 @@ var InvitationsHandler = class {
2128
2137
  ...protocol.toJSON()
2129
2138
  }, {
2130
2139
  F: __dxlog_file7,
2131
- L: 328,
2140
+ L: 325,
2132
2141
  S: this,
2133
2142
  C: (f, a) => f(...a)
2134
2143
  });
@@ -2138,18 +2147,18 @@ var InvitationsHandler = class {
2138
2147
  } else {
2139
2148
  (0, import_log4.log)("auth failed", err, {
2140
2149
  F: __dxlog_file7,
2141
- L: 331,
2150
+ L: 328,
2142
2151
  S: this,
2143
2152
  C: (f, a) => f(...a)
2144
2153
  });
2145
2154
  stream.error(err);
2146
2155
  }
2147
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.error({
2156
+ import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
2148
2157
  id: traceId,
2149
2158
  error: err
2150
2159
  }), {
2151
2160
  F: __dxlog_file7,
2152
- L: 334,
2161
+ L: 331,
2153
2162
  S: this,
2154
2163
  C: (f, a) => f(...a)
2155
2164
  });
@@ -2159,7 +2168,7 @@ var InvitationsHandler = class {
2159
2168
  });
2160
2169
  },
2161
2170
  onError: (err) => {
2162
- if (err instanceof import_protocols3.InvalidInvitationExtensionRoleError) {
2171
+ if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
2163
2172
  return;
2164
2173
  }
2165
2174
  if (err instanceof import_async7.TimeoutError) {
@@ -2167,7 +2176,7 @@ var InvitationsHandler = class {
2167
2176
  ...protocol.toJSON()
2168
2177
  }, {
2169
2178
  F: __dxlog_file7,
2170
- L: 345,
2179
+ L: 342,
2171
2180
  S: this,
2172
2181
  C: (f, a) => f(...a)
2173
2182
  });
@@ -2177,7 +2186,7 @@ var InvitationsHandler = class {
2177
2186
  } else {
2178
2187
  (0, import_log4.log)("auth failed", err, {
2179
2188
  F: __dxlog_file7,
2180
- L: 348,
2189
+ L: 345,
2181
2190
  S: this,
2182
2191
  C: (f, a) => f(...a)
2183
2192
  });
@@ -2188,29 +2197,34 @@ var InvitationsHandler = class {
2188
2197
  return extension;
2189
2198
  };
2190
2199
  (0, import_async7.scheduleTask)(ctx, async () => {
2191
- (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2192
- F: __dxlog_file7,
2193
- L: 358,
2194
- S: this,
2195
- A: [
2196
- "invitation.swarmKey",
2197
- ""
2198
- ]
2199
- });
2200
- const topic = invitation.swarmKey;
2201
- const swarmConnection = await this._networkManager.joinSwarm({
2202
- topic,
2203
- peerId: import_keys5.PublicKey.random(),
2204
- protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2205
- teleport.addExtension("dxos.halo.invitations", createExtension());
2206
- }),
2207
- topology: new import_network_manager.StarTopology(topic),
2208
- label: "invitation guest"
2209
- });
2210
- ctx.onDispose(() => swarmConnection.close());
2211
- setState({
2212
- state: import_services2.Invitation.State.CONNECTING
2213
- });
2200
+ const error = protocol.checkInvitation(invitation);
2201
+ if (error) {
2202
+ stream.error(error);
2203
+ } else {
2204
+ (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2205
+ F: __dxlog_file7,
2206
+ L: 359,
2207
+ S: this,
2208
+ A: [
2209
+ "invitation.swarmKey",
2210
+ ""
2211
+ ]
2212
+ });
2213
+ const topic = invitation.swarmKey;
2214
+ const swarmConnection = await this._networkManager.joinSwarm({
2215
+ topic,
2216
+ peerId: import_keys5.PublicKey.random(),
2217
+ protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
2218
+ teleport.addExtension("dxos.halo.invitations", createExtension());
2219
+ }),
2220
+ topology: new import_network_manager.StarTopology(topic),
2221
+ label: "invitation guest"
2222
+ });
2223
+ ctx.onDispose(() => swarmConnection.close());
2224
+ setState({
2225
+ state: import_services2.Invitation.State.CONNECTING
2226
+ });
2227
+ }
2214
2228
  });
2215
2229
  const observable = new import_client_protocol2.AuthenticatingInvitation({
2216
2230
  initialInvitation: invitation,
@@ -2426,7 +2440,7 @@ var SpaceInvitationProtocol = class {
2426
2440
  async admit(request, guestProfile) {
2427
2441
  (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2428
2442
  F: __dxlog_file9,
2429
- L: 46,
2443
+ L: 47,
2430
2444
  S: this,
2431
2445
  A: [
2432
2446
  "this._spaceKey",
@@ -2436,7 +2450,7 @@ var SpaceInvitationProtocol = class {
2436
2450
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2437
2451
  (0, import_invariant8.invariant)(space, void 0, {
2438
2452
  F: __dxlog_file9,
2439
- L: 48,
2453
+ L: 49,
2440
2454
  S: this,
2441
2455
  A: [
2442
2456
  "space",
@@ -2445,7 +2459,7 @@ var SpaceInvitationProtocol = class {
2445
2459
  });
2446
2460
  (0, import_invariant8.invariant)(request.space, void 0, {
2447
2461
  F: __dxlog_file9,
2448
- L: 50,
2462
+ L: 51,
2449
2463
  S: this,
2450
2464
  A: [
2451
2465
  "request.space",
@@ -2458,14 +2472,14 @@ var SpaceInvitationProtocol = class {
2458
2472
  guest: deviceKey
2459
2473
  }, {
2460
2474
  F: __dxlog_file9,
2461
- L: 53,
2475
+ L: 54,
2462
2476
  S: this,
2463
2477
  C: (f, a) => f(...a)
2464
2478
  });
2465
2479
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2466
2480
  (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2467
2481
  F: __dxlog_file9,
2468
- L: 64,
2482
+ L: 65,
2469
2483
  S: this,
2470
2484
  A: [
2471
2485
  "credentials[0].credential",
@@ -2475,7 +2489,7 @@ var SpaceInvitationProtocol = class {
2475
2489
  const spaceMemberCredential = credentials[0].credential.credential;
2476
2490
  (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2477
2491
  F: __dxlog_file9,
2478
- L: 66,
2492
+ L: 67,
2479
2493
  S: this,
2480
2494
  A: [
2481
2495
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2491,6 +2505,11 @@ var SpaceInvitationProtocol = class {
2491
2505
  }
2492
2506
  };
2493
2507
  }
2508
+ checkInvitation(invitation) {
2509
+ if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2510
+ return new import_protocols6.AlreadyJoinedError("Already joined space.");
2511
+ }
2512
+ }
2494
2513
  createIntroduction() {
2495
2514
  return {
2496
2515
  profile: this._signingContext.getProfile()
@@ -2511,7 +2530,7 @@ var SpaceInvitationProtocol = class {
2511
2530
  async accept(response) {
2512
2531
  (0, import_invariant8.invariant)(response.space, void 0, {
2513
2532
  F: __dxlog_file9,
2514
- L: 101,
2533
+ L: 108,
2515
2534
  S: this,
2516
2535
  A: [
2517
2536
  "response.space",
@@ -2522,7 +2541,7 @@ var SpaceInvitationProtocol = class {
2522
2541
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2523
2542
  (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2524
2543
  F: __dxlog_file9,
2525
- L: 104,
2544
+ L: 111,
2526
2545
  S: this,
2527
2546
  A: [
2528
2547
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2531,13 +2550,16 @@ var SpaceInvitationProtocol = class {
2531
2550
  });
2532
2551
  (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2533
2552
  F: __dxlog_file9,
2534
- L: 105,
2553
+ L: 112,
2535
2554
  S: this,
2536
2555
  A: [
2537
2556
  "credential.subject.id.equals(this._signingContext.identityKey)",
2538
2557
  ""
2539
2558
  ]
2540
2559
  });
2560
+ if (this._spaceManager.spaces.has(assertion.spaceKey)) {
2561
+ throw new import_protocols6.AlreadyJoinedError("Already joined space.");
2562
+ }
2541
2563
  await this._spaceManager.acceptSpace({
2542
2564
  spaceKey: assertion.spaceKey,
2543
2565
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2630,28 +2652,29 @@ var getPlatform = () => {
2630
2652
  if (typeof window !== "undefined") {
2631
2653
  const { userAgent } = window.navigator;
2632
2654
  return {
2633
- type: "browser",
2655
+ type: import_services7.Platform.PLATFORM_TYPE.BROWSER,
2634
2656
  userAgent,
2635
2657
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2636
2658
  };
2637
2659
  } else {
2638
2660
  return {
2639
- type: "shared-worker",
2661
+ type: import_services7.Platform.PLATFORM_TYPE.SHARED_WORKER,
2640
2662
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2641
2663
  };
2642
2664
  }
2643
2665
  } else {
2644
2666
  const { platform: platform2, version, arch } = process;
2645
2667
  return {
2646
- type: "node",
2647
- platform: `${platform2} ${version} ${arch}`,
2648
- runtime: process.version,
2668
+ type: import_services7.Platform.PLATFORM_TYPE.NODE,
2669
+ platform: platform2,
2670
+ arch,
2671
+ runtime: version,
2649
2672
  uptime: Math.floor(process.uptime()),
2650
2673
  memory: process.memoryUsage()
2651
2674
  };
2652
2675
  }
2653
2676
  };
2654
- var DXOS_VERSION = "0.3.11-main.7ff9773";
2677
+ var DXOS_VERSION = "0.3.11-main.800163e";
2655
2678
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2656
2679
  var DEFAULT_TIMEOUT = 1e3;
2657
2680
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -2661,14 +2684,14 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2661
2684
  client: {
2662
2685
  version: DXOS_VERSION,
2663
2686
  storage: {
2664
- version: import_protocols5.STORAGE_VERSION
2687
+ version: import_protocols7.STORAGE_VERSION
2665
2688
  }
2666
2689
  }
2667
2690
  };
2668
2691
  {
2669
2692
  (0, import_invariant9.invariant)(clientServices.LoggingService, "SystemService is not available.", {
2670
2693
  F: __dxlog_file10,
2671
- L: 92,
2694
+ L: 94,
2672
2695
  S: void 0,
2673
2696
  A: [
2674
2697
  "clientServices.LoggingService",
@@ -2679,6 +2702,21 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2679
2702
  timeout: DEFAULT_TIMEOUT
2680
2703
  }).catch(() => void 0);
2681
2704
  }
2705
+ if (typeof navigator !== "undefined" && navigator.storage) {
2706
+ const map = /* @__PURE__ */ new Map();
2707
+ const dir = await navigator.storage.getDirectory();
2708
+ for await (const filename of dir?.keys()) {
2709
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2710
+ if (idx === -1) {
2711
+ continue;
2712
+ }
2713
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2714
+ }
2715
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2716
+ file,
2717
+ count
2718
+ }));
2719
+ }
2682
2720
  const identity = serviceContext.identityManager.identity;
2683
2721
  if (identity) {
2684
2722
  diagnostics.identity = {
@@ -2719,7 +2757,7 @@ var getProperties = (space) => {
2719
2757
  } catch (err) {
2720
2758
  import_log8.log.warn(err.message, void 0, {
2721
2759
  F: __dxlog_file10,
2722
- L: 160,
2760
+ L: 179,
2723
2761
  S: void 0,
2724
2762
  C: (f, a) => f(...a)
2725
2763
  });
@@ -2774,7 +2812,8 @@ var getSpaceStats = async (space) => {
2774
2812
  return stats;
2775
2813
  };
2776
2814
  var AutomergeSpaceState = class {
2777
- constructor() {
2815
+ constructor(_onNewRoot) {
2816
+ this._onNewRoot = _onNewRoot;
2778
2817
  this.rootUrl = void 0;
2779
2818
  this.lastEpoch = void 0;
2780
2819
  }
@@ -2785,6 +2824,7 @@ var AutomergeSpaceState = class {
2785
2824
  this.lastEpoch = credential;
2786
2825
  if (credential.subject.assertion.automergeRoot) {
2787
2826
  this.rootUrl = credential.subject.assertion.automergeRoot;
2827
+ this._onNewRoot(this.rootUrl);
2788
2828
  }
2789
2829
  }
2790
2830
  };
@@ -2821,7 +2861,7 @@ var NotarizationPlugin = class {
2821
2861
  S: this,
2822
2862
  C: (f, a) => f(...a)
2823
2863
  });
2824
- (0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2864
+ (0, import_invariant11.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
2825
2865
  F: __dxlog_file11,
2826
2866
  L: 91,
2827
2867
  S: this,
@@ -2946,7 +2986,7 @@ var NotarizationPlugin = class {
2946
2986
  this._processCredentialsTriggers.delete(credential.id);
2947
2987
  }
2948
2988
  setWriter(writer) {
2949
- (0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
2989
+ (0, import_invariant11.invariant)(!this._writer, "Writer already set.", {
2950
2990
  F: __dxlog_file11,
2951
2991
  L: 181,
2952
2992
  S: this,
@@ -2971,7 +3011,7 @@ var NotarizationPlugin = class {
2971
3011
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2972
3012
  }
2973
3013
  for (const credential of request.credentials ?? []) {
2974
- (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
3014
+ (0, import_invariant11.invariant)(credential.id, "Credential must have an id", {
2975
3015
  F: __dxlog_file11,
2976
3016
  L: 200,
2977
3017
  S: this,
@@ -3020,10 +3060,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
3020
3060
  constructor(_params) {
3021
3061
  super({
3022
3062
  requested: {
3023
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3063
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3024
3064
  },
3025
3065
  exposed: {
3026
- NotarizationService: import_protocols7.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3066
+ NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
3027
3067
  }
3028
3068
  });
3029
3069
  this._params = _params;
@@ -3063,8 +3103,8 @@ var DataSpace = class {
3063
3103
  this._ctx = new import_context6.Context();
3064
3104
  this._notarizationPlugin = new NotarizationPlugin();
3065
3105
  this._cache = void 0;
3066
- this._automergeSpaceState = new AutomergeSpaceState();
3067
- this._state = import_services7.SpaceState.CLOSED;
3106
+ this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3107
+ this._state = import_services8.SpaceState.CLOSED;
3068
3108
  this.error = void 0;
3069
3109
  this.stateUpdate = new import_async10.Event();
3070
3110
  this.metrics = {};
@@ -3086,10 +3126,10 @@ var DataSpace = class {
3086
3126
  this._cache = params.cache;
3087
3127
  this._state = params.initialState;
3088
3128
  (0, import_log9.log)("new state", {
3089
- state: import_services7.SpaceState[this._state]
3129
+ state: import_services8.SpaceState[this._state]
3090
3130
  }, {
3091
3131
  F: __dxlog_file12,
3092
- L: 137,
3132
+ L: 138,
3093
3133
  S: this,
3094
3134
  C: (f, a) => f(...a)
3095
3135
  });
@@ -3131,12 +3171,12 @@ var DataSpace = class {
3131
3171
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3132
3172
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3133
3173
  await this._inner.open(new import_context6.Context());
3134
- this._state = import_services7.SpaceState.CONTROL_ONLY;
3174
+ this._state = import_services8.SpaceState.CONTROL_ONLY;
3135
3175
  (0, import_log9.log)("new state", {
3136
- state: import_services7.SpaceState[this._state]
3176
+ state: import_services8.SpaceState[this._state]
3137
3177
  }, {
3138
3178
  F: __dxlog_file12,
3139
- L: 189,
3179
+ L: 190,
3140
3180
  S: this,
3141
3181
  C: (f, a) => f(...a)
3142
3182
  });
@@ -3149,12 +3189,12 @@ var DataSpace = class {
3149
3189
  }
3150
3190
  async _close() {
3151
3191
  await this._callbacks.beforeClose?.();
3152
- this._state = import_services7.SpaceState.CLOSED;
3192
+ this._state = import_services8.SpaceState.CLOSED;
3153
3193
  (0, import_log9.log)("new state", {
3154
- state: import_services7.SpaceState[this._state]
3194
+ state: import_services8.SpaceState[this._state]
3155
3195
  }, {
3156
3196
  F: __dxlog_file12,
3157
- L: 203,
3197
+ L: 204,
3158
3198
  S: this,
3159
3199
  C: (f, a) => f(...a)
3160
3200
  });
@@ -3183,10 +3223,10 @@ var DataSpace = class {
3183
3223
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3184
3224
  await this.initializeDataPipeline();
3185
3225
  } catch (err) {
3186
- if (err instanceof import_protocols6.CancelledError) {
3226
+ if (err instanceof import_protocols8.CancelledError) {
3187
3227
  (0, import_log9.log)("data pipeline initialization cancelled", err, {
3188
3228
  F: __dxlog_file12,
3189
- L: 236,
3229
+ L: 237,
3190
3230
  S: this,
3191
3231
  C: (f, a) => f(...a)
3192
3232
  });
@@ -3194,16 +3234,16 @@ var DataSpace = class {
3194
3234
  }
3195
3235
  import_log9.log.error("Error initializing data pipeline", err, {
3196
3236
  F: __dxlog_file12,
3197
- L: 240,
3237
+ L: 241,
3198
3238
  S: this,
3199
3239
  C: (f, a) => f(...a)
3200
3240
  });
3201
- this._state = import_services7.SpaceState.ERROR;
3241
+ this._state = import_services8.SpaceState.ERROR;
3202
3242
  (0, import_log9.log)("new state", {
3203
- state: import_services7.SpaceState[this._state]
3243
+ state: import_services8.SpaceState[this._state]
3204
3244
  }, {
3205
3245
  F: __dxlog_file12,
3206
- L: 242,
3246
+ L: 243,
3207
3247
  S: this,
3208
3248
  C: (f, a) => f(...a)
3209
3249
  });
@@ -3215,15 +3255,15 @@ var DataSpace = class {
3215
3255
  });
3216
3256
  }
3217
3257
  async initializeDataPipeline() {
3218
- if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3219
- throw new import_protocols6.SystemError("Invalid operation");
3258
+ if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3259
+ throw new import_protocols8.SystemError("Invalid operation");
3220
3260
  }
3221
- this._state = import_services7.SpaceState.INITIALIZING;
3261
+ this._state = import_services8.SpaceState.INITIALIZING;
3222
3262
  (0, import_log9.log)("new state", {
3223
- state: import_services7.SpaceState[this._state]
3263
+ state: import_services8.SpaceState[this._state]
3224
3264
  }, {
3225
3265
  F: __dxlog_file12,
3226
- L: 258,
3266
+ L: 259,
3227
3267
  S: this,
3228
3268
  C: (f, a) => f(...a)
3229
3269
  });
@@ -3234,7 +3274,7 @@ var DataSpace = class {
3234
3274
  await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3235
3275
  (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
3236
3276
  F: __dxlog_file12,
3237
- L: 272,
3277
+ L: 273,
3238
3278
  S: this,
3239
3279
  C: (f, a) => f(...a)
3240
3280
  });
@@ -3245,17 +3285,17 @@ var DataSpace = class {
3245
3285
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3246
3286
  (0, import_log9.log)("data pipeline ready", void 0, {
3247
3287
  F: __dxlog_file12,
3248
- L: 281,
3288
+ L: 282,
3249
3289
  S: this,
3250
3290
  C: (f, a) => f(...a)
3251
3291
  });
3252
3292
  await this._callbacks.beforeReady?.();
3253
- this._state = import_services7.SpaceState.READY;
3293
+ this._state = import_services8.SpaceState.READY;
3254
3294
  (0, import_log9.log)("new state", {
3255
- state: import_services7.SpaceState[this._state]
3295
+ state: import_services8.SpaceState[this._state]
3256
3296
  }, {
3257
3297
  F: __dxlog_file12,
3258
- L: 285,
3298
+ L: 286,
3259
3299
  S: this,
3260
3300
  C: (f, a) => f(...a)
3261
3301
  });
@@ -3271,7 +3311,7 @@ var DataSpace = class {
3271
3311
  await this._createWritableFeeds();
3272
3312
  (0, import_log9.log)("writable feeds created", void 0, {
3273
3313
  F: __dxlog_file12,
3274
- L: 301,
3314
+ L: 302,
3275
3315
  S: this,
3276
3316
  C: (f, a) => f(...a)
3277
3317
  });
@@ -3328,6 +3368,40 @@ var DataSpace = class {
3328
3368
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3329
3369
  }
3330
3370
  }
3371
+ _onNewAutomergeRoot(rootUrl) {
3372
+ import_log9.log.info("loading automerge root doc for space", {
3373
+ space: this.key,
3374
+ rootUrl
3375
+ }, {
3376
+ F: __dxlog_file12,
3377
+ L: 368,
3378
+ S: this,
3379
+ C: (f, a) => f(...a)
3380
+ });
3381
+ const handle = this._automergeHost.repo.find(rootUrl);
3382
+ queueMicrotask(async () => {
3383
+ try {
3384
+ await handle.whenReady();
3385
+ const doc = handle.docSync() ?? (0, import_invariant10.failedInvariant)();
3386
+ if (!doc.experimental_spaceKey) {
3387
+ handle.change((doc2) => {
3388
+ doc2.experimental_spaceKey = this.key.toHex();
3389
+ });
3390
+ }
3391
+ } catch (err) {
3392
+ import_log9.log.warn("error loading automerge root doc", {
3393
+ space: this.key,
3394
+ rootUrl,
3395
+ err
3396
+ }, {
3397
+ F: __dxlog_file12,
3398
+ L: 381,
3399
+ S: this,
3400
+ C: (f, a) => f(...a)
3401
+ });
3402
+ }
3403
+ });
3404
+ }
3331
3405
  // TODO(dmaretskyi): Use profile from signing context.
3332
3406
  async updateOwnProfile(profile) {
3333
3407
  const credential = await this._signingContext.credentialSigner.createCredential({
@@ -3347,12 +3421,12 @@ var DataSpace = class {
3347
3421
  let epoch;
3348
3422
  switch (options?.migration) {
3349
3423
  case void 0:
3350
- case import_services7.CreateEpochRequest.Migration.NONE:
3424
+ case import_services8.CreateEpochRequest.Migration.NONE:
3351
3425
  {
3352
3426
  epoch = await this.dataPipeline.createEpoch();
3353
3427
  }
3354
3428
  break;
3355
- case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3429
+ case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3356
3430
  const document = this._automergeHost.repo.create();
3357
3431
  epoch = {
3358
3432
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3393,25 +3467,25 @@ var DataSpace = class {
3393
3467
  }
3394
3468
  }
3395
3469
  async activate() {
3396
- if (this._state !== import_services7.SpaceState.INACTIVE) {
3470
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
3397
3471
  return;
3398
3472
  }
3399
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3473
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
3400
3474
  await this._open();
3401
3475
  this.initializeDataPipelineAsync();
3402
3476
  }
3403
3477
  async deactivate() {
3404
- if (this._state === import_services7.SpaceState.INACTIVE) {
3478
+ if (this._state === import_services8.SpaceState.INACTIVE) {
3405
3479
  return;
3406
3480
  }
3407
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3481
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
3408
3482
  await this._close();
3409
- this._state = import_services7.SpaceState.INACTIVE;
3483
+ this._state = import_services8.SpaceState.INACTIVE;
3410
3484
  (0, import_log9.log)("new state", {
3411
- state: import_services7.SpaceState[this._state]
3485
+ state: import_services8.SpaceState[this._state]
3412
3486
  }, {
3413
3487
  F: __dxlog_file12,
3414
- L: 450,
3488
+ L: 470,
3415
3489
  S: this,
3416
3490
  C: (f, a) => f(...a)
3417
3491
  });
@@ -3549,7 +3623,7 @@ var DataSpaceManager = class {
3549
3623
  S: this,
3550
3624
  C: (f, a) => f(...a)
3551
3625
  });
3552
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.begin({
3626
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
3553
3627
  id: this._instanceId
3554
3628
  }), {
3555
3629
  F: __dxlog_file13,
@@ -3591,11 +3665,11 @@ var DataSpaceManager = class {
3591
3665
  this._isOpen = true;
3592
3666
  this.updated.emit();
3593
3667
  for (const space of this._spaces.values()) {
3594
- if (space.state !== import_services8.SpaceState.INACTIVE) {
3668
+ if (space.state !== import_services9.SpaceState.INACTIVE) {
3595
3669
  space.initializeDataPipelineAsync();
3596
3670
  }
3597
3671
  }
3598
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols8.trace.end({
3672
+ import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
3599
3673
  id: this._instanceId
3600
3674
  }), {
3601
3675
  F: __dxlog_file13,
@@ -3621,7 +3695,7 @@ var DataSpaceManager = class {
3621
3695
  * Creates a new space writing the genesis credentials to the control feed.
3622
3696
  */
3623
3697
  async createSpace() {
3624
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3698
+ (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
3625
3699
  F: __dxlog_file13,
3626
3700
  L: 130,
3627
3701
  S: this,
@@ -3638,7 +3712,7 @@ var DataSpaceManager = class {
3638
3712
  genesisFeedKey: controlFeedKey,
3639
3713
  controlFeedKey,
3640
3714
  dataFeedKey,
3641
- state: import_services8.SpaceState.ACTIVE
3715
+ state: import_services9.SpaceState.ACTIVE
3642
3716
  };
3643
3717
  (0, import_log11.log)("creating space...", {
3644
3718
  spaceKey
@@ -3650,12 +3724,15 @@ var DataSpaceManager = class {
3650
3724
  });
3651
3725
  const space = await this._constructSpace(metadata);
3652
3726
  const automergeRoot = this._automergeHost.repo.create();
3727
+ automergeRoot.change((doc) => {
3728
+ doc.experimental_spaceKey = spaceKey.toHex();
3729
+ });
3653
3730
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3654
3731
  await this._metadataStore.addSpace(metadata);
3655
3732
  const memberCredential = credentials[1];
3656
- (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3733
+ (0, import_invariant12.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3657
3734
  F: __dxlog_file13,
3658
- L: 151,
3735
+ L: 154,
3659
3736
  S: this,
3660
3737
  A: [
3661
3738
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3673,22 +3750,22 @@ var DataSpaceManager = class {
3673
3750
  opts
3674
3751
  }, {
3675
3752
  F: __dxlog_file13,
3676
- L: 163,
3753
+ L: 166,
3677
3754
  S: this,
3678
3755
  C: (f, a) => f(...a)
3679
3756
  });
3680
- (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3757
+ (0, import_invariant12.invariant)(this._isOpen, "Not open.", {
3681
3758
  F: __dxlog_file13,
3682
- L: 164,
3759
+ L: 167,
3683
3760
  S: this,
3684
3761
  A: [
3685
3762
  "this._isOpen",
3686
3763
  "'Not open.'"
3687
3764
  ]
3688
3765
  });
3689
- (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3766
+ (0, import_invariant12.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3690
3767
  F: __dxlog_file13,
3691
- L: 165,
3768
+ L: 168,
3692
3769
  S: this,
3693
3770
  A: [
3694
3771
  "!this._spaces.has(opts.spaceKey)",
@@ -3715,7 +3792,7 @@ var DataSpaceManager = class {
3715
3792
  async waitUntilSpaceReady(spaceKey) {
3716
3793
  await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3717
3794
  const space = this._spaces.get(spaceKey);
3718
- return !!space && space.state === import_services8.SpaceState.READY;
3795
+ return !!space && space.state === import_services9.SpaceState.READY;
3719
3796
  }));
3720
3797
  }
3721
3798
  async _constructSpace(metadata) {
@@ -3723,7 +3800,7 @@ var DataSpaceManager = class {
3723
3800
  metadata
3724
3801
  }, {
3725
3802
  F: __dxlog_file13,
3726
- L: 198,
3803
+ L: 201,
3727
3804
  S: this,
3728
3805
  C: (f, a) => f(...a)
3729
3806
  });
@@ -3750,17 +3827,18 @@ var DataSpaceManager = class {
3750
3827
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
3751
3828
  credentialAuthenticator: (0, import_util6.deferFunction)(() => dataSpace.authVerifier.verifier)
3752
3829
  },
3753
- onNetworkConnection: (session) => {
3830
+ onAuthorizedConnection: (session) => {
3754
3831
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
3755
3832
  remotePeerId: session.remotePeerId
3756
3833
  }));
3757
3834
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3835
+ this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
3758
3836
  session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
3759
3837
  },
3760
3838
  onAuthFailure: () => {
3761
3839
  import_log11.log.warn("auth failure", void 0, {
3762
3840
  F: __dxlog_file13,
3763
- L: 234,
3841
+ L: 238,
3764
3842
  S: this,
3765
3843
  C: (f, a) => f(...a)
3766
3844
  });
@@ -3771,7 +3849,7 @@ var DataSpaceManager = class {
3771
3849
  dataFeed && space.setDataFeed(dataFeed);
3772
3850
  const dataSpace = new DataSpace({
3773
3851
  inner: space,
3774
- initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
3852
+ initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
3775
3853
  metadataStore: this._metadataStore,
3776
3854
  gossip,
3777
3855
  presence,
@@ -3784,7 +3862,7 @@ var DataSpaceManager = class {
3784
3862
  space: space.key
3785
3863
  }, {
3786
3864
  F: __dxlog_file13,
3787
- L: 252,
3865
+ L: 256,
3788
3866
  S: this,
3789
3867
  C: (f, a) => f(...a)
3790
3868
  });
@@ -3796,7 +3874,7 @@ var DataSpaceManager = class {
3796
3874
  open: this._isOpen
3797
3875
  }, {
3798
3876
  F: __dxlog_file13,
3799
- L: 259,
3877
+ L: 263,
3800
3878
  S: this,
3801
3879
  C: (f, a) => f(...a)
3802
3880
  });
@@ -3809,7 +3887,7 @@ var DataSpaceManager = class {
3809
3887
  space: space.key
3810
3888
  }, {
3811
3889
  F: __dxlog_file13,
3812
- L: 265,
3890
+ L: 269,
3813
3891
  S: this,
3814
3892
  C: (f, a) => f(...a)
3815
3893
  });
@@ -3819,7 +3897,7 @@ var DataSpaceManager = class {
3819
3897
  cache: metadata.cache,
3820
3898
  automergeHost: this._automergeHost
3821
3899
  });
3822
- if (metadata.state !== import_services8.SpaceState.INACTIVE) {
3900
+ if (metadata.state !== import_services9.SpaceState.INACTIVE) {
3823
3901
  await dataSpace.open();
3824
3902
  }
3825
3903
  if (metadata.controlTimeframe) {
@@ -3857,7 +3935,7 @@ var SpacesServiceImpl = class {
3857
3935
  }
3858
3936
  async createSpace() {
3859
3937
  if (!this._identityManager.identity) {
3860
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
3938
+ throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
3861
3939
  }
3862
3940
  const dataSpaceManager = await this._getDataSpaceManager();
3863
3941
  const space = await dataSpaceManager.createSpace();
@@ -3865,17 +3943,17 @@ var SpacesServiceImpl = class {
3865
3943
  }
3866
3944
  async updateSpace({ spaceKey, state }) {
3867
3945
  const dataSpaceManager = await this._getDataSpaceManager();
3868
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
3946
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3869
3947
  if (state) {
3870
3948
  switch (state) {
3871
- case import_services9.SpaceState.ACTIVE:
3949
+ case import_services10.SpaceState.ACTIVE:
3872
3950
  await space.activate();
3873
3951
  break;
3874
- case import_services9.SpaceState.INACTIVE:
3952
+ case import_services10.SpaceState.INACTIVE:
3875
3953
  await space.deactivate();
3876
3954
  break;
3877
3955
  default:
3878
- throw new import_protocols9.ApiError("Invalid space state");
3956
+ throw new import_protocols11.ApiError("Invalid space state");
3879
3957
  }
3880
3958
  }
3881
3959
  }
@@ -3930,14 +4008,14 @@ var SpacesServiceImpl = class {
3930
4008
  }
3931
4009
  async postMessage({ spaceKey, channel, message }) {
3932
4010
  const dataSpaceManager = await this._getDataSpaceManager();
3933
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4011
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3934
4012
  await space.postMessage(getChannelId(channel), message);
3935
4013
  }
3936
4014
  subscribeMessages({ spaceKey, channel }) {
3937
4015
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
3938
4016
  (0, import_async13.scheduleTask)(ctx, async () => {
3939
4017
  const dataSpaceManager = await this._getDataSpaceManager();
3940
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4018
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3941
4019
  const handle = space.listen(getChannelId(channel), (message) => {
3942
4020
  next(message);
3943
4021
  });
@@ -3947,7 +4025,7 @@ var SpacesServiceImpl = class {
3947
4025
  }
3948
4026
  queryCredentials({ spaceKey, noTail }) {
3949
4027
  return new import_codec_protobuf11.Stream(({ ctx, next, close }) => {
3950
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4028
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3951
4029
  const processor = {
3952
4030
  processCredential: async (credential) => {
3953
4031
  next(credential);
@@ -3963,7 +4041,7 @@ var SpacesServiceImpl = class {
3963
4041
  });
3964
4042
  }
3965
4043
  async writeCredentials({ spaceKey, credentials }) {
3966
- const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4044
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
3967
4045
  for (const credential of credentials ?? []) {
3968
4046
  if (credential.proof) {
3969
4047
  await space.controlPipeline.writer.write({
@@ -3972,7 +4050,7 @@ var SpacesServiceImpl = class {
3972
4050
  }
3973
4051
  });
3974
4052
  } else {
3975
- (0, import_invariant12.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
4053
+ (0, import_invariant13.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
3976
4054
  F: __dxlog_file14,
3977
4055
  L: 168,
3978
4056
  S: this,
@@ -3981,7 +4059,7 @@ var SpacesServiceImpl = class {
3981
4059
  "'Id on unsigned credentials is not allowed'"
3982
4060
  ]
3983
4061
  });
3984
- (0, import_invariant12.invariant)(this._identityManager.identity, "Identity is not available", {
4062
+ (0, import_invariant13.invariant)(this._identityManager.identity, "Identity is not available", {
3985
4063
  F: __dxlog_file14,
3986
4064
  L: 169,
3987
4065
  S: this,
@@ -3991,7 +4069,7 @@ var SpacesServiceImpl = class {
3991
4069
  ]
3992
4070
  });
3993
4071
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
3994
- (0, import_invariant12.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
4072
+ (0, import_invariant13.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
3995
4073
  F: __dxlog_file14,
3996
4074
  L: 171,
3997
4075
  S: this,
@@ -4014,14 +4092,14 @@ var SpacesServiceImpl = class {
4014
4092
  }
4015
4093
  async createEpoch({ spaceKey }) {
4016
4094
  const dataSpaceManager = await this._getDataSpaceManager();
4017
- const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols9.SpaceNotFoundError(spaceKey));
4095
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4018
4096
  await space.createEpoch();
4019
4097
  }
4020
4098
  _serializeSpace(space) {
4021
4099
  return {
4022
4100
  spaceKey: space.key,
4023
4101
  state: space.state,
4024
- error: space.error ? (0, import_protocols9.encodeError)(space.error) : void 0,
4102
+ error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
4025
4103
  pipeline: {
4026
4104
  currentEpoch: space.dataPipeline.currentEpoch,
4027
4105
  appliedEpoch: space.dataPipeline.appliedEpoch,
@@ -4048,7 +4126,7 @@ var SpacesServiceImpl = class {
4048
4126
  displayName: member.profile?.displayName
4049
4127
  }
4050
4128
  },
4051
- presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4129
+ presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4052
4130
  peerStates: peers
4053
4131
  };
4054
4132
  }),
@@ -4105,7 +4183,7 @@ var ServiceContext = class {
4105
4183
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
4106
4184
  this.automergeHost = new import_echo_pipeline2.AutomergeHost(storage.createDirectory("automerge"));
4107
4185
  this.invitations = new InvitationsHandler(this.networkManager);
4108
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
4186
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
4109
4187
  }
4110
4188
  async open(ctx) {
4111
4189
  await this._checkStorageVersion();
@@ -4115,7 +4193,7 @@ var ServiceContext = class {
4115
4193
  S: this,
4116
4194
  C: (f, a) => f(...a)
4117
4195
  });
4118
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.begin({
4196
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
4119
4197
  id: this._instanceId
4120
4198
  }), {
4121
4199
  F: __dxlog_file15,
@@ -4131,7 +4209,7 @@ var ServiceContext = class {
4131
4209
  if (this.identityManager.identity) {
4132
4210
  await this._initialize(ctx);
4133
4211
  }
4134
- import_log13.log.trace("dxos.sdk.service-context.open", import_protocols10.trace.end({
4212
+ import_log13.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
4135
4213
  id: this._instanceId
4136
4214
  }), {
4137
4215
  F: __dxlog_file15,
@@ -4179,7 +4257,7 @@ var ServiceContext = class {
4179
4257
  }
4180
4258
  getInvitationHandler(invitation) {
4181
4259
  const factory = this._handlerFactories.get(invitation.kind);
4182
- (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4260
+ (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4183
4261
  F: __dxlog_file15,
4184
4262
  L: 173,
4185
4263
  S: this,
@@ -4205,8 +4283,8 @@ var ServiceContext = class {
4205
4283
  }
4206
4284
  async _checkStorageVersion() {
4207
4285
  await this.metadataStore.load();
4208
- if (this.metadataStore.version !== import_protocols10.STORAGE_VERSION) {
4209
- throw new import_protocols10.InvalidStorageVersionError(import_protocols10.STORAGE_VERSION, this.metadataStore.version);
4286
+ if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
4287
+ throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
4210
4288
  }
4211
4289
  }
4212
4290
  // Called when identity is created.
@@ -4233,8 +4311,8 @@ var ServiceContext = class {
4233
4311
  };
4234
4312
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore, this.automergeHost);
4235
4313
  await this.dataSpaceManager.open();
4236
- this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4237
- (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4314
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4315
+ (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4238
4316
  F: __dxlog_file15,
4239
4317
  L: 228,
4240
4318
  S: this,
@@ -4373,7 +4451,7 @@ var Lock = class {
4373
4451
  }
4374
4452
  async release() {
4375
4453
  await this._onRelease?.();
4376
- (0, import_invariant14.invariant)(this._fileHandle, "Lock is not acquired", {
4454
+ (0, import_invariant15.invariant)(this._fileHandle, "Lock is not acquired", {
4377
4455
  F: __dxlog_file16,
4378
4456
  L: 42,
4379
4457
  S: this,
@@ -4393,16 +4471,16 @@ var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4393
4471
  var createStorageObjects = (config) => {
4394
4472
  const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4395
4473
  if (persistent && dataStore === StorageDriver.RAM) {
4396
- throw new import_protocols11.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4474
+ throw new import_protocols13.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4397
4475
  }
4398
4476
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4399
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4477
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4400
4478
  }
4401
4479
  if (persistent && keyStore === StorageDriver.RAM) {
4402
- throw new import_protocols11.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4480
+ throw new import_protocols13.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4403
4481
  }
4404
4482
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4405
- throw new import_protocols11.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4483
+ throw new import_protocols13.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4406
4484
  }
4407
4485
  return {
4408
4486
  storage: (0, import_random_access_storage.createStorage)({
@@ -4450,7 +4528,7 @@ var DevicesServiceImpl = class {
4450
4528
  next({
4451
4529
  devices: Array.from(deviceKeys.entries()).map(([key, profile]) => ({
4452
4530
  deviceKey: key,
4453
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services12.DeviceKind.CURRENT : import_services12.DeviceKind.TRUSTED,
4531
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services13.DeviceKind.CURRENT : import_services13.DeviceKind.TRUSTED,
4454
4532
  profile
4455
4533
  }))
4456
4534
  });
@@ -4565,16 +4643,16 @@ var LoggingServiceImpl = class {
4565
4643
  };
4566
4644
  var matchFilter = (filter, level, path, options) => {
4567
4645
  switch (options) {
4568
- case import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE:
4646
+ case import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE:
4569
4647
  return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
4570
- case import_services13.QueryLogsRequest.MatchingOptions.EXPLICIT:
4648
+ case import_services14.QueryLogsRequest.MatchingOptions.EXPLICIT:
4571
4649
  return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
4572
4650
  }
4573
4651
  };
4574
4652
  var shouldLog = (entry2, request) => {
4575
- const options = request.options ?? import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4653
+ const options = request.options ?? import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4576
4654
  if (request.filters === void 0) {
4577
- return options === import_services13.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4655
+ return options === import_services14.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4578
4656
  } else {
4579
4657
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4580
4658
  }
@@ -4590,6 +4668,7 @@ var NetworkServiceImpl = class {
4590
4668
  const update = () => {
4591
4669
  next({
4592
4670
  swarm: this.networkManager.connectionState,
4671
+ connectionInfo: this.networkManager.connectionLog?.swarms,
4593
4672
  signaling: this.signalManager.getStatus().map(({ host, state }) => ({
4594
4673
  server: host,
4595
4674
  state
@@ -4629,11 +4708,14 @@ var SystemServiceImpl = class {
4629
4708
  return {
4630
4709
  timestamp: /* @__PURE__ */ new Date(),
4631
4710
  diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)({
4632
- truncate: keys === import_services14.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4633
- humanize: keys === import_services14.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4711
+ truncate: keys === import_services15.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4712
+ humanize: keys === import_services15.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4634
4713
  })))
4635
4714
  };
4636
4715
  }
4716
+ async getPlatform() {
4717
+ return getPlatform();
4718
+ }
4637
4719
  async updateStatus({ status }) {
4638
4720
  await this._onUpdateStatus(status);
4639
4721
  }
@@ -4723,14 +4805,14 @@ var ClientServicesHost = class {
4723
4805
  this._systemService = new SystemServiceImpl({
4724
4806
  config: this._config,
4725
4807
  statusUpdate: this._statusUpdate,
4726
- getCurrentStatus: () => this.isOpen ? import_services11.SystemStatus.ACTIVE : import_services11.SystemStatus.INACTIVE,
4808
+ getCurrentStatus: () => this.isOpen ? import_services12.SystemStatus.ACTIVE : import_services12.SystemStatus.INACTIVE,
4727
4809
  getDiagnostics: () => {
4728
4810
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4729
4811
  },
4730
4812
  onUpdateStatus: async (status) => {
4731
- if (!this.isOpen && status === import_services11.SystemStatus.ACTIVE) {
4813
+ if (!this.isOpen && status === import_services12.SystemStatus.ACTIVE) {
4732
4814
  await this._resourceLock?.acquire();
4733
- } else if (this.isOpen && status === import_services11.SystemStatus.INACTIVE) {
4815
+ } else if (this.isOpen && status === import_services12.SystemStatus.INACTIVE) {
4734
4816
  await this._resourceLock?.release();
4735
4817
  }
4736
4818
  },
@@ -4768,7 +4850,7 @@ var ClientServicesHost = class {
4768
4850
  * Can only be called once.
4769
4851
  */
4770
4852
  initialize({ config, ...options }) {
4771
- (0, import_invariant15.invariant)(!this._open, "service host is open", {
4853
+ (0, import_invariant16.invariant)(!this._open, "service host is open", {
4772
4854
  F: __dxlog_file17,
4773
4855
  L: 201,
4774
4856
  S: this,
@@ -4784,7 +4866,7 @@ var ClientServicesHost = class {
4784
4866
  C: (f, a) => f(...a)
4785
4867
  });
4786
4868
  if (config) {
4787
- (0, import_invariant15.invariant)(!this._config, "config already set", {
4869
+ (0, import_invariant16.invariant)(!this._config, "config already set", {
4788
4870
  F: __dxlog_file17,
4789
4871
  L: 205,
4790
4872
  S: this,
@@ -4802,7 +4884,7 @@ var ClientServicesHost = class {
4802
4884
  iceServers: this._config?.get("runtime.services.ice")
4803
4885
  }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4804
4886
  this._signalManager = signalManager;
4805
- (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
4887
+ (0, import_invariant16.invariant)(!this._networkManager, "network manager already set", {
4806
4888
  F: __dxlog_file17,
4807
4889
  L: 221,
4808
4890
  S: this,
@@ -4828,7 +4910,7 @@ var ClientServicesHost = class {
4828
4910
  return;
4829
4911
  }
4830
4912
  const traceId = import_keys11.PublicKey.random().toHex();
4831
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.begin({
4913
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
4832
4914
  id: traceId
4833
4915
  }), {
4834
4916
  F: __dxlog_file17,
@@ -4836,7 +4918,7 @@ var ClientServicesHost = class {
4836
4918
  S: this,
4837
4919
  C: (f, a) => f(...a)
4838
4920
  });
4839
- (0, import_invariant15.invariant)(this._config, "config not set", {
4921
+ (0, import_invariant16.invariant)(this._config, "config not set", {
4840
4922
  F: __dxlog_file17,
4841
4923
  L: 241,
4842
4924
  S: this,
@@ -4845,7 +4927,7 @@ var ClientServicesHost = class {
4845
4927
  "'config not set'"
4846
4928
  ]
4847
4929
  });
4848
- (0, import_invariant15.invariant)(this._storage, "storage not set", {
4930
+ (0, import_invariant16.invariant)(this._storage, "storage not set", {
4849
4931
  F: __dxlog_file17,
4850
4932
  L: 242,
4851
4933
  S: this,
@@ -4854,7 +4936,7 @@ var ClientServicesHost = class {
4854
4936
  "'storage not set'"
4855
4937
  ]
4856
4938
  });
4857
- (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
4939
+ (0, import_invariant16.invariant)(this._signalManager, "signal manager not set", {
4858
4940
  F: __dxlog_file17,
4859
4941
  L: 243,
4860
4942
  S: this,
@@ -4863,7 +4945,7 @@ var ClientServicesHost = class {
4863
4945
  "'signal manager not set'"
4864
4946
  ]
4865
4947
  });
4866
- (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
4948
+ (0, import_invariant16.invariant)(this._networkManager, "network manager not set", {
4867
4949
  F: __dxlog_file17,
4868
4950
  L: 244,
4869
4951
  S: this,
@@ -4927,7 +5009,7 @@ var ClientServicesHost = class {
4927
5009
  S: this,
4928
5010
  C: (f, a) => f(...a)
4929
5011
  });
4930
- import_log15.log.trace("dxos.client-services.host.open", import_protocols12.trace.end({
5012
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
4931
5013
  id: traceId
4932
5014
  }), {
4933
5015
  F: __dxlog_file17,
@@ -4968,7 +5050,7 @@ var ClientServicesHost = class {
4968
5050
  }
4969
5051
  async reset() {
4970
5052
  const traceId = import_keys11.PublicKey.random().toHex();
4971
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.begin({
5053
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
4972
5054
  id: traceId
4973
5055
  }), {
4974
5056
  F: __dxlog_file17,
@@ -4990,7 +5072,7 @@ var ClientServicesHost = class {
4990
5072
  S: this,
4991
5073
  C: (f, a) => f(...a)
4992
5074
  });
4993
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols12.trace.end({
5075
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
4994
5076
  id: traceId
4995
5077
  }), {
4996
5078
  F: __dxlog_file17,
@@ -5022,7 +5104,7 @@ var ClientServicesHost = class {
5022
5104
  });
5023
5105
  } else {
5024
5106
  const automergeIndex = space.automergeSpaceState.rootUrl;
5025
- (0, import_invariant15.invariant)(automergeIndex, void 0, {
5107
+ (0, import_invariant16.invariant)(automergeIndex, void 0, {
5026
5108
  F: __dxlog_file17,
5027
5109
  L: 375,
5028
5110
  S: this,
@@ -5092,4 +5174,4 @@ ClientServicesHost = _ts_decorate8([
5092
5174
  subscribeToSpaces,
5093
5175
  subscribeToSwarmInfo
5094
5176
  });
5095
- //# sourceMappingURL=chunk-34H4H2HZ.cjs.map
5177
+ //# sourceMappingURL=chunk-GNBZGQOY.cjs.map