@dxos/client-services 0.6.13-main.548ca8d → 0.6.13-main.ed424a1

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 (70) hide show
  1. package/dist/lib/browser/{chunk-UEQIHAL2.mjs → chunk-IPWEAPT2.mjs} +728 -379
  2. package/dist/lib/browser/chunk-IPWEAPT2.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +5 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +5 -1
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-MA5EWTRH.cjs → chunk-DJIOUOAF.cjs} +769 -422
  9. package/dist/lib/node/chunk-DJIOUOAF.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +49 -45
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +12 -8
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/node-esm/{chunk-AIBLDI4U.mjs → chunk-MMU5KC57.mjs} +728 -379
  16. package/dist/lib/node-esm/chunk-MMU5KC57.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +5 -1
  18. package/dist/lib/node-esm/index.mjs.map +1 -1
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +5 -1
  21. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  22. package/dist/types/src/index.d.ts +1 -0
  23. package/dist/types/src/index.d.ts.map +1 -1
  24. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +35 -0
  25. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -0
  26. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +10 -0
  27. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -0
  28. package/dist/types/src/packlets/agents/index.d.ts +3 -0
  29. package/dist/types/src/packlets/agents/index.d.ts.map +1 -0
  30. package/dist/types/src/packlets/identity/identity-manager.d.ts +11 -7
  31. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  32. package/dist/types/src/packlets/identity/identity.d.ts +4 -2
  33. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  34. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  35. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  36. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  37. package/dist/types/src/packlets/services/service-context.d.ts +4 -1
  38. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  39. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  40. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +1 -0
  41. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  42. package/dist/types/src/packlets/spaces/data-space.d.ts +1 -0
  43. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  44. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +4 -0
  45. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  46. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  47. package/dist/types/src/version.d.ts +1 -1
  48. package/package.json +38 -38
  49. package/src/index.ts +1 -0
  50. package/src/packlets/agents/edge-agent-manager.ts +163 -0
  51. package/src/packlets/agents/edge-agent-service.ts +42 -0
  52. package/src/packlets/agents/index.ts +6 -0
  53. package/src/packlets/identity/identity-manager.test.ts +26 -10
  54. package/src/packlets/identity/identity-manager.ts +19 -19
  55. package/src/packlets/identity/identity.test.ts +2 -0
  56. package/src/packlets/identity/identity.ts +21 -12
  57. package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
  58. package/src/packlets/invitations/edge-invitation-handler.ts +6 -5
  59. package/src/packlets/invitations/invitations-handler.ts +1 -2
  60. package/src/packlets/services/service-context.ts +75 -45
  61. package/src/packlets/services/service-host.ts +8 -0
  62. package/src/packlets/spaces/data-space-manager.ts +4 -2
  63. package/src/packlets/spaces/data-space.ts +3 -0
  64. package/src/packlets/spaces/edge-feed-replicator.test.ts +5 -6
  65. package/src/packlets/spaces/notarization-plugin.ts +27 -0
  66. package/src/packlets/testing/test-builder.ts +4 -0
  67. package/src/version.ts +1 -1
  68. package/dist/lib/browser/chunk-UEQIHAL2.mjs.map +0 -7
  69. package/dist/lib/node/chunk-MA5EWTRH.cjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-AIBLDI4U.mjs.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_MA5EWTRH_exports = {};
30
- __export(chunk_MA5EWTRH_exports, {
29
+ var chunk_DJIOUOAF_exports = {};
30
+ __export(chunk_DJIOUOAF_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -36,6 +36,8 @@ __export(chunk_MA5EWTRH_exports, {
36
36
  DevtoolsHostEvents: () => DevtoolsHostEvents,
37
37
  DevtoolsServiceImpl: () => DevtoolsServiceImpl,
38
38
  DiagnosticsCollector: () => DiagnosticsCollector,
39
+ EdgeAgentManager: () => EdgeAgentManager,
40
+ EdgeAgentServiceImpl: () => EdgeAgentServiceImpl,
39
41
  EdgeFeedReplicator: () => EdgeFeedReplicator,
40
42
  Identity: () => Identity,
41
43
  IdentityManager: () => IdentityManager,
@@ -70,7 +72,7 @@ __export(chunk_MA5EWTRH_exports, {
70
72
  subscribeToSpaces: () => subscribeToSpaces,
71
73
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
72
74
  });
73
- module.exports = __toCommonJS(chunk_MA5EWTRH_exports);
75
+ module.exports = __toCommonJS(chunk_DJIOUOAF_exports);
74
76
  var import_async = require("@dxos/async");
75
77
  var import_codec_protobuf = require("@dxos/codec-protobuf");
76
78
  var import_feed_store = require("@dxos/feed-store");
@@ -219,6 +221,7 @@ var import_invariant10 = require("@dxos/invariant");
219
221
  var import_log12 = require("@dxos/log");
220
222
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
221
223
  var import_util9 = require("@dxos/util");
224
+ var import_credentials17 = require("@dxos/credentials");
222
225
  var import_invariant11 = require("@dxos/invariant");
223
226
  var import_protocols8 = require("@dxos/protocols");
224
227
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
@@ -275,23 +278,23 @@ var import_invitations5 = require("@dxos/protocols/proto/dxos/halo/invitations")
275
278
  var import_util11 = require("@dxos/util");
276
279
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
277
280
  var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
278
- var import_credentials17 = require("@dxos/credentials");
281
+ var import_credentials18 = require("@dxos/credentials");
279
282
  var import_feed_store5 = require("@dxos/feed-store");
280
283
  var import_invariant17 = require("@dxos/invariant");
281
284
  var import_log19 = require("@dxos/log");
282
285
  var import_protocols13 = require("@dxos/protocols");
283
286
  var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
284
- var import_credentials18 = require("@dxos/protocols/proto/dxos/halo/credentials");
287
+ var import_credentials19 = require("@dxos/protocols/proto/dxos/halo/credentials");
285
288
  var import_async20 = require("@dxos/async");
286
289
  var import_client_protocol6 = require("@dxos/client-protocol");
287
290
  var import_context14 = require("@dxos/context");
288
- var import_credentials19 = require("@dxos/credentials");
291
+ var import_credentials20 = require("@dxos/credentials");
289
292
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
290
293
  var import_invariant18 = require("@dxos/invariant");
291
294
  var import_keys14 = require("@dxos/keys");
292
295
  var import_log20 = require("@dxos/log");
293
296
  var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
294
- var import_credentials20 = require("@dxos/protocols/proto/dxos/halo/credentials");
297
+ var import_credentials21 = require("@dxos/protocols/proto/dxos/halo/credentials");
295
298
  var import_invariant19 = require("@dxos/invariant");
296
299
  var import_lock_file = require("@dxos/lock-file");
297
300
  var import_log21 = require("@dxos/log");
@@ -301,64 +304,74 @@ var import_rpc = require("@dxos/rpc");
301
304
  var import_tracing9 = require("@dxos/tracing");
302
305
  var import_async21 = require("@dxos/async");
303
306
  var import_context15 = require("@dxos/context");
304
- var import_credentials21 = require("@dxos/credentials");
305
- var import_debug6 = require("@dxos/debug");
306
- var import_echo_pipeline5 = require("@dxos/echo-pipeline");
307
- var import_edge_client2 = require("@dxos/edge-client");
308
- var import_feed_store6 = require("@dxos/feed-store");
309
307
  var import_invariant20 = require("@dxos/invariant");
310
- var import_keyring = require("@dxos/keyring");
311
308
  var import_keys15 = require("@dxos/keys");
312
309
  var import_log22 = require("@dxos/log");
313
310
  var import_protocols14 = require("@dxos/protocols");
314
311
  var import_services19 = require("@dxos/protocols/proto/dxos/client/services");
312
+ var import_codec_protobuf12 = require("@dxos/codec-protobuf");
313
+ var import_protocols15 = require("@dxos/protocols");
314
+ var import_services20 = require("@dxos/protocols/proto/dxos/client/services");
315
+ var import_async22 = require("@dxos/async");
316
+ var import_context16 = require("@dxos/context");
317
+ var import_credentials22 = require("@dxos/credentials");
318
+ var import_debug6 = require("@dxos/debug");
319
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
320
+ var import_edge_client2 = require("@dxos/edge-client");
321
+ var import_feed_store6 = require("@dxos/feed-store");
322
+ var import_invariant21 = require("@dxos/invariant");
323
+ var import_keyring = require("@dxos/keyring");
324
+ var import_keys16 = require("@dxos/keys");
325
+ var import_log23 = require("@dxos/log");
326
+ var import_protocols16 = require("@dxos/protocols");
327
+ var import_services21 = require("@dxos/protocols/proto/dxos/client/services");
315
328
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
316
329
  var import_tracing10 = require("@dxos/tracing");
317
330
  var import_util12 = require("@dxos/util");
318
- var import_protocols15 = require("@dxos/protocols");
331
+ var import_protocols17 = require("@dxos/protocols");
319
332
  var import_config2 = require("@dxos/protocols/proto/dxos/config");
320
333
  var import_random_access_storage = require("@dxos/random-access-storage");
321
334
  var import_client_protocol7 = require("@dxos/client-protocol");
322
335
  var import_config3 = require("@dxos/protocols/proto/dxos/config");
323
336
  var import_util13 = require("@dxos/util");
324
337
  var import_node_path = __toESM(require("node:path"));
325
- var import_keys16 = require("@dxos/keys");
338
+ var import_keys17 = require("@dxos/keys");
326
339
  var import_kv_store = require("@dxos/kv-store");
327
340
  var import_automerge_repo = require("@dxos/automerge/automerge-repo");
328
- var import_invariant21 = require("@dxos/invariant");
329
- var import_log23 = require("@dxos/log");
330
- var import_protocols16 = require("@dxos/protocols");
341
+ var import_invariant22 = require("@dxos/invariant");
342
+ var import_log24 = require("@dxos/log");
343
+ var import_protocols18 = require("@dxos/protocols");
331
344
  var import_util14 = require("@dxos/util");
332
- var import_async22 = require("@dxos/async");
345
+ var import_async23 = require("@dxos/async");
333
346
  var import_client_protocol8 = require("@dxos/client-protocol");
334
- var import_context16 = require("@dxos/context");
347
+ var import_context17 = require("@dxos/context");
335
348
  var import_edge_client3 = require("@dxos/edge-client");
336
- var import_invariant22 = require("@dxos/invariant");
337
- var import_keys17 = require("@dxos/keys");
338
- var import_log24 = require("@dxos/log");
349
+ var import_invariant23 = require("@dxos/invariant");
350
+ var import_keys18 = require("@dxos/keys");
351
+ var import_log25 = require("@dxos/log");
339
352
  var import_messaging = require("@dxos/messaging");
340
353
  var import_network_manager2 = require("@dxos/network-manager");
341
- var import_protocols17 = require("@dxos/protocols");
342
- var import_services20 = require("@dxos/protocols/proto/dxos/client/services");
354
+ var import_protocols19 = require("@dxos/protocols");
355
+ var import_services22 = require("@dxos/protocols/proto/dxos/client/services");
343
356
  var import_tracing11 = require("@dxos/tracing");
344
357
  var import_websocket_rpc = require("@dxos/websocket-rpc");
345
- var import_async23 = require("@dxos/async");
346
- var import_codec_protobuf12 = require("@dxos/codec-protobuf");
347
- var import_invariant23 = require("@dxos/invariant");
348
- var import_services21 = require("@dxos/protocols/proto/dxos/client/services");
349
358
  var import_async24 = require("@dxos/async");
350
359
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
351
- var import_keys18 = require("@dxos/keys");
352
- var import_util15 = require("@dxos/util");
360
+ var import_invariant24 = require("@dxos/invariant");
361
+ var import_services23 = require("@dxos/protocols/proto/dxos/client/services");
353
362
  var import_async25 = require("@dxos/async");
354
363
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
355
364
  var import_keys19 = require("@dxos/keys");
356
- var import_log25 = require("@dxos/log");
357
- var import_services22 = require("@dxos/protocols/proto/dxos/client/services");
358
- var import_util16 = require("@dxos/util");
365
+ var import_util15 = require("@dxos/util");
366
+ var import_async26 = require("@dxos/async");
359
367
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
368
+ var import_keys20 = require("@dxos/keys");
369
+ var import_log26 = require("@dxos/log");
370
+ var import_services24 = require("@dxos/protocols/proto/dxos/client/services");
371
+ var import_util16 = require("@dxos/util");
360
372
  var import_codec_protobuf16 = require("@dxos/codec-protobuf");
361
- var import_services23 = require("@dxos/protocols/proto/dxos/client/services");
373
+ var import_codec_protobuf17 = require("@dxos/codec-protobuf");
374
+ var import_services25 = require("@dxos/protocols/proto/dxos/client/services");
362
375
  var import_util17 = require("@dxos/util");
363
376
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/feeds.ts";
364
377
  var subscribeToFeeds = ({ feedStore, spaceManager }, { feedKeys }) => {
@@ -718,7 +731,7 @@ var DevtoolsServiceImpl = class {
718
731
  });
719
732
  }
720
733
  };
721
- var DXOS_VERSION = "0.6.13-main.548ca8d";
734
+ var DXOS_VERSION = "0.6.13-main.ed424a1";
722
735
  var getPlatform = () => {
723
736
  if (process.browser) {
724
737
  if (typeof window !== "undefined") {
@@ -1711,6 +1724,7 @@ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/sr
1711
1724
  var DEFAULT_RETRY_TIMEOUT = 1e3;
1712
1725
  var DEFAULT_SUCCESS_DELAY = 1e3;
1713
1726
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
1727
+ var DEFAULT_ACTIVE_EDGE_POLLING_INTERVAL = 3e3;
1714
1728
  var MAX_EDGE_RETRIES = 2;
1715
1729
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
1716
1730
  var credentialCodec = import_proto2.schema.getCodecForType("dxos.halo.credentials.Credential");
@@ -1721,11 +1735,44 @@ var NotarizationPlugin = class extends import_context6.Resource {
1721
1735
  this._extensions = /* @__PURE__ */ new Set();
1722
1736
  this._processedCredentials = new import_util5.ComplexSet(import_keys5.PublicKey.hash);
1723
1737
  this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys5.PublicKey.hash);
1738
+ this._activeEdgePollingIntervalHandle = void 0;
1724
1739
  this._spaceId = params.spaceId;
1740
+ this._activeEdgePollingInterval = params.activeEdgePollingInterval ?? DEFAULT_ACTIVE_EDGE_POLLING_INTERVAL;
1725
1741
  if (params.edgeClient && params.edgeFeatures?.feedReplicator) {
1726
1742
  this._edgeClient = params.edgeClient;
1727
1743
  }
1728
1744
  }
1745
+ setActiveEdgePollingEnabled(enabled) {
1746
+ (0, import_invariant5.invariant)(this.isOpen, void 0, {
1747
+ F: __dxlog_file7,
1748
+ L: 109,
1749
+ S: this,
1750
+ A: [
1751
+ "this.isOpen",
1752
+ ""
1753
+ ]
1754
+ });
1755
+ const client = this._edgeClient;
1756
+ (0, import_invariant5.invariant)(client, void 0, {
1757
+ F: __dxlog_file7,
1758
+ L: 111,
1759
+ S: this,
1760
+ A: [
1761
+ "client",
1762
+ ""
1763
+ ]
1764
+ });
1765
+ if (enabled && !this._activeEdgePollingIntervalHandle) {
1766
+ this._activeEdgePollingIntervalHandle = setInterval(() => {
1767
+ if (this._writer) {
1768
+ this._notarizePendingEdgeCredentials(client, this._writer);
1769
+ }
1770
+ }, this._activeEdgePollingInterval);
1771
+ } else if (!enabled && this._activeEdgePollingIntervalHandle) {
1772
+ clearInterval(this._activeEdgePollingIntervalHandle);
1773
+ this._activeEdgePollingIntervalHandle = void 0;
1774
+ }
1775
+ }
1729
1776
  get hasWriter() {
1730
1777
  return !!this._writer;
1731
1778
  }
@@ -1735,6 +1782,10 @@ var NotarizationPlugin = class extends import_context6.Resource {
1735
1782
  }
1736
1783
  }
1737
1784
  async _close() {
1785
+ if (this._activeEdgePollingIntervalHandle) {
1786
+ clearInterval(this._activeEdgePollingIntervalHandle);
1787
+ this._activeEdgePollingIntervalHandle = void 0;
1788
+ }
1738
1789
  await this._ctx.dispose();
1739
1790
  }
1740
1791
  /**
@@ -1745,13 +1796,13 @@ var NotarizationPlugin = class extends import_context6.Resource {
1745
1796
  credentials
1746
1797
  }, {
1747
1798
  F: __dxlog_file7,
1748
- L: 126,
1799
+ L: 153,
1749
1800
  S: this,
1750
1801
  C: (f, a) => f(...a)
1751
1802
  });
1752
1803
  (0, import_invariant5.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
1753
1804
  F: __dxlog_file7,
1754
- L: 127,
1805
+ L: 154,
1755
1806
  S: this,
1756
1807
  A: [
1757
1808
  "credentials.every((credential) => credential.id)",
@@ -1765,7 +1816,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1765
1816
  err
1766
1817
  }, {
1767
1818
  F: __dxlog_file7,
1768
- L: 135,
1819
+ L: 162,
1769
1820
  S: this,
1770
1821
  C: (f, a) => f(...a)
1771
1822
  });
@@ -1797,7 +1848,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1797
1848
  ]);
1798
1849
  (0, import_log6.log)("done", void 0, {
1799
1850
  F: __dxlog_file7,
1800
- L: 160,
1851
+ L: 187,
1801
1852
  S: this,
1802
1853
  C: (f, a) => f(...a)
1803
1854
  });
@@ -1820,7 +1871,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1820
1871
  retryIn: retryTimeout
1821
1872
  }, {
1822
1873
  F: __dxlog_file7,
1823
- L: 183,
1874
+ L: 210,
1824
1875
  S: this,
1825
1876
  C: (f, a) => f(...a)
1826
1877
  });
@@ -1834,7 +1885,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1834
1885
  credentialId: credentials.map((credential) => credential.id)
1835
1886
  }, {
1836
1887
  F: __dxlog_file7,
1837
- L: 190,
1888
+ L: 217,
1838
1889
  S: this,
1839
1890
  C: (f, a) => f(...a)
1840
1891
  });
@@ -1843,7 +1894,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1843
1894
  });
1844
1895
  (0, import_log6.log)("success", void 0, {
1845
1896
  F: __dxlog_file7,
1846
- L: 194,
1897
+ L: 221,
1847
1898
  S: this,
1848
1899
  C: (f, a) => f(...a)
1849
1900
  });
@@ -1852,7 +1903,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1852
1903
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
1853
1904
  import_log6.log.info("error notarizing (recoverable)", err, {
1854
1905
  F: __dxlog_file7,
1855
- L: 199,
1906
+ L: 226,
1856
1907
  S: this,
1857
1908
  C: (f, a) => f(...a)
1858
1909
  });
@@ -1881,7 +1932,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1881
1932
  });
1882
1933
  (0, import_log6.log)("edge notarization success", void 0, {
1883
1934
  F: __dxlog_file7,
1884
- L: 227,
1935
+ L: 254,
1885
1936
  S: this,
1886
1937
  C: (f, a) => f(...a)
1887
1938
  });
@@ -1904,7 +1955,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1904
1955
  setWriter(writer) {
1905
1956
  (0, import_invariant5.invariant)(!this._writer, "Writer already set.", {
1906
1957
  F: __dxlog_file7,
1907
- L: 247,
1958
+ L: 274,
1908
1959
  S: this,
1909
1960
  A: [
1910
1961
  "!this._writer",
@@ -1934,7 +1985,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1934
1985
  if (!credentials.length) {
1935
1986
  (0, import_log6.log)("edge did not return credentials for notarization", void 0, {
1936
1987
  F: __dxlog_file7,
1937
- L: 269,
1988
+ L: 296,
1938
1989
  S: this,
1939
1990
  C: (f, a) => f(...a)
1940
1991
  });
@@ -1944,7 +1995,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1944
1995
  count: credentials.length
1945
1996
  }, {
1946
1997
  F: __dxlog_file7,
1947
- L: 273,
1998
+ L: 300,
1948
1999
  S: this,
1949
2000
  C: (f, a) => f(...a)
1950
2001
  });
@@ -1957,7 +2008,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1957
2008
  count: decodedCredentials.length
1958
2009
  }, {
1959
2010
  F: __dxlog_file7,
1960
- L: 282,
2011
+ L: 309,
1961
2012
  S: this,
1962
2013
  C: (f, a) => f(...a)
1963
2014
  });
@@ -1985,7 +2036,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
1985
2036
  for (const credential of credentials) {
1986
2037
  (0, import_invariant5.invariant)(credential.id, "Credential must have an id", {
1987
2038
  F: __dxlog_file7,
1988
- L: 308,
2039
+ L: 335,
1989
2040
  S: this,
1990
2041
  A: [
1991
2042
  "credential.id",
@@ -2009,7 +2060,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
2009
2060
  peer: extension.localPeerId
2010
2061
  }, {
2011
2062
  F: __dxlog_file7,
2012
- L: 323,
2063
+ L: 350,
2013
2064
  S: this,
2014
2065
  C: (f, a) => f(...a)
2015
2066
  });
@@ -2021,7 +2072,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
2021
2072
  peer: extension.localPeerId
2022
2073
  }, {
2023
2074
  F: __dxlog_file7,
2024
- L: 328,
2075
+ L: 355,
2025
2076
  S: this,
2026
2077
  C: (f, a) => f(...a)
2027
2078
  });
@@ -2038,7 +2089,7 @@ var NotarizationPlugin = class extends import_context6.Resource {
2038
2089
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2039
2090
  }, {
2040
2091
  F: __dxlog_file7,
2041
- L: 340,
2092
+ L: 367,
2042
2093
  S: this,
2043
2094
  C: (f, a) => f(...a)
2044
2095
  });
@@ -2054,7 +2105,7 @@ var handleEdgeError = (error) => {
2054
2105
  if (!(error instanceof import_protocols4.EdgeCallFailedError) || error.errorData) {
2055
2106
  import_log6.log.catch(error, void 0, {
2056
2107
  F: __dxlog_file7,
2057
- L: 354,
2108
+ L: 381,
2058
2109
  S: void 0,
2059
2110
  C: (f, a) => f(...a)
2060
2111
  });
@@ -2063,7 +2114,7 @@ var handleEdgeError = (error) => {
2063
2114
  reason: error.reason
2064
2115
  }, {
2065
2116
  F: __dxlog_file7,
2066
- L: 356,
2117
+ L: 383,
2067
2118
  S: void 0,
2068
2119
  C: (f, a) => f(...a)
2069
2120
  });
@@ -2269,7 +2320,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2269
2320
  async _open() {
2270
2321
  (0, import_log9.log)("open", void 0, {
2271
2322
  F: __dxlog_file9,
2272
- L: 198,
2323
+ L: 199,
2273
2324
  S: this,
2274
2325
  C: (f, a) => f(...a)
2275
2326
  });
@@ -2277,7 +2328,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2277
2328
  id: this._instanceId
2278
2329
  }), {
2279
2330
  F: __dxlog_file9,
2280
- L: 199,
2331
+ L: 200,
2281
2332
  S: this,
2282
2333
  C: (f, a) => f(...a)
2283
2334
  });
@@ -2285,7 +2336,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2285
2336
  spaces: this._metadataStore.spaces.length
2286
2337
  }, {
2287
2338
  F: __dxlog_file9,
2288
- L: 200,
2339
+ L: 201,
2289
2340
  S: this,
2290
2341
  C: (f, a) => f(...a)
2291
2342
  });
@@ -2295,7 +2346,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2295
2346
  spaceMetadata
2296
2347
  }, {
2297
2348
  F: __dxlog_file9,
2298
- L: 204,
2349
+ L: 205,
2299
2350
  S: this,
2300
2351
  C: (f, a) => f(...a)
2301
2352
  });
@@ -2306,7 +2357,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2306
2357
  err
2307
2358
  }, {
2308
2359
  F: __dxlog_file9,
2309
- L: 207,
2360
+ L: 208,
2310
2361
  S: this,
2311
2362
  C: (f, a) => f(...a)
2312
2363
  });
@@ -2317,7 +2368,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2317
2368
  id: this._instanceId
2318
2369
  }), {
2319
2370
  F: __dxlog_file9,
2320
- L: 213,
2371
+ L: 214,
2321
2372
  S: this,
2322
2373
  C: (f, a) => f(...a)
2323
2374
  });
@@ -2325,7 +2376,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2325
2376
  async _close() {
2326
2377
  (0, import_log9.log)("close", void 0, {
2327
2378
  F: __dxlog_file9,
2328
- L: 218,
2379
+ L: 219,
2329
2380
  S: this,
2330
2381
  C: (f, a) => f(...a)
2331
2382
  });
@@ -2340,7 +2391,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2340
2391
  async createSpace() {
2341
2392
  (0, import_invariant7.invariant)(this._lifecycleState === import_context7.LifecycleState.OPEN, "Not open.", {
2342
2393
  F: __dxlog_file9,
2343
- L: 230,
2394
+ L: 231,
2344
2395
  S: this,
2345
2396
  A: [
2346
2397
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2361,7 +2412,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2361
2412
  spaceKey
2362
2413
  }, {
2363
2414
  F: __dxlog_file9,
2364
- L: 242,
2415
+ L: 243,
2365
2416
  S: this,
2366
2417
  C: (f, a) => f(...a)
2367
2418
  });
@@ -2373,7 +2424,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2373
2424
  const memberCredential = credentials[1];
2374
2425
  (0, import_invariant7.invariant)((0, import_credentials9.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2375
2426
  F: __dxlog_file9,
2376
- L: 252,
2427
+ L: 253,
2377
2428
  S: this,
2378
2429
  A: [
2379
2430
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2405,7 +2456,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2405
2456
  spaceId: space.id
2406
2457
  }, {
2407
2458
  F: __dxlog_file9,
2408
- L: 277,
2459
+ L: 278,
2409
2460
  S: this,
2410
2461
  C: (f, a) => f(...a)
2411
2462
  });
@@ -2426,7 +2477,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2426
2477
  keys: []
2427
2478
  }
2428
2479
  };
2429
- const propertiesId = (0, import_echo_schema2.generateEchoId)();
2480
+ const propertiesId = (0, import_echo_schema2.createObjectId)();
2430
2481
  document.change((doc) => {
2431
2482
  (0, import_util7.setDeep)(doc, [
2432
2483
  "objects",
@@ -2440,7 +2491,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2440
2491
  const automergeIndex = space.automergeSpaceState.rootUrl;
2441
2492
  (0, import_invariant7.invariant)(automergeIndex, void 0, {
2442
2493
  F: __dxlog_file9,
2443
- L: 310,
2494
+ L: 311,
2444
2495
  S: this,
2445
2496
  A: [
2446
2497
  "automergeIndex",
@@ -2457,13 +2508,13 @@ var DataSpaceManager = class extends import_context7.Resource {
2457
2508
  opts
2458
2509
  }, {
2459
2510
  F: __dxlog_file9,
2460
- L: 319,
2511
+ L: 320,
2461
2512
  S: this,
2462
2513
  C: (f, a) => f(...a)
2463
2514
  });
2464
2515
  (0, import_invariant7.invariant)(this._lifecycleState === import_context7.LifecycleState.OPEN, "Not open.", {
2465
2516
  F: __dxlog_file9,
2466
- L: 320,
2517
+ L: 321,
2467
2518
  S: this,
2468
2519
  A: [
2469
2520
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2472,7 +2523,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2472
2523
  });
2473
2524
  (0, import_invariant7.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
2474
2525
  F: __dxlog_file9,
2475
- L: 321,
2526
+ L: 322,
2476
2527
  S: this,
2477
2528
  A: [
2478
2529
  "!this._spaces.has(opts.spaceKey)",
@@ -2496,7 +2547,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2496
2547
  const space = this._spaceManager.spaces.get(options.spaceKey);
2497
2548
  (0, import_invariant7.invariant)(space, void 0, {
2498
2549
  F: __dxlog_file9,
2499
- L: 341,
2550
+ L: 342,
2500
2551
  S: this,
2501
2552
  A: [
2502
2553
  "space",
@@ -2509,7 +2560,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2509
2560
  const credentials = await (0, import_credentials9.createAdmissionCredentials)(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
2510
2561
  (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2511
2562
  F: __dxlog_file9,
2512
- L: 360,
2563
+ L: 361,
2513
2564
  S: this,
2514
2565
  A: [
2515
2566
  "credentials[0].credential",
@@ -2519,7 +2570,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2519
2570
  const spaceMemberCredential = credentials[0].credential.credential;
2520
2571
  (0, import_invariant7.invariant)((0, import_credentials9.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2521
2572
  F: __dxlog_file9,
2522
- L: 362,
2573
+ L: 363,
2523
2574
  S: this,
2524
2575
  A: [
2525
2576
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2557,7 +2608,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2557
2608
  const space = this._spaces.get(spaceKey);
2558
2609
  (0, import_invariant7.invariant)(space, "Space not found.", {
2559
2610
  F: __dxlog_file9,
2560
- L: 399,
2611
+ L: 400,
2561
2612
  S: this,
2562
2613
  A: [
2563
2614
  "space",
@@ -2582,7 +2633,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2582
2633
  metadata
2583
2634
  }, {
2584
2635
  F: __dxlog_file9,
2585
- L: 418,
2636
+ L: 419,
2586
2637
  S: this,
2587
2638
  C: (f, a) => f(...a)
2588
2639
  });
@@ -2626,7 +2677,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2626
2677
  err
2627
2678
  }, {
2628
2679
  F: __dxlog_file9,
2629
- L: 460,
2680
+ L: 461,
2630
2681
  S: this,
2631
2682
  C: (f, a) => f(...a)
2632
2683
  });
@@ -2636,7 +2687,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2636
2687
  onAuthFailure: () => {
2637
2688
  import_log9.log.warn("auth failure", void 0, {
2638
2689
  F: __dxlog_file9,
2639
- L: 465,
2690
+ L: 466,
2640
2691
  S: this,
2641
2692
  C: (f, a) => f(...a)
2642
2693
  });
@@ -2669,7 +2720,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2669
2720
  space: space.key
2670
2721
  }, {
2671
2722
  F: __dxlog_file9,
2672
- L: 492,
2723
+ L: 493,
2673
2724
  S: this,
2674
2725
  C: (f, a) => f(...a)
2675
2726
  });
@@ -2680,7 +2731,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2680
2731
  open: this._lifecycleState === import_context7.LifecycleState.OPEN
2681
2732
  }, {
2682
2733
  F: __dxlog_file9,
2683
- L: 495,
2734
+ L: 496,
2684
2735
  S: this,
2685
2736
  C: (f, a) => f(...a)
2686
2737
  });
@@ -2699,7 +2750,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2699
2750
  space: space.key
2700
2751
  }, {
2701
2752
  F: __dxlog_file9,
2702
- L: 503,
2753
+ L: 504,
2703
2754
  S: this,
2704
2755
  C: (f, a) => f(...a)
2705
2756
  });
@@ -2708,7 +2759,8 @@ var DataSpaceManager = class extends import_context7.Resource {
2708
2759
  cache: metadata.cache,
2709
2760
  edgeConnection: this._edgeConnection,
2710
2761
  edgeHttpClient: this._edgeHttpClient,
2711
- edgeFeatures: this._edgeFeatures
2762
+ edgeFeatures: this._edgeFeatures,
2763
+ activeEdgeNotarizationPollingInterval: this._runtimeParams?.activeEdgeNotarizationPollingInterval
2712
2764
  });
2713
2765
  dataSpace.postOpen.append(async () => {
2714
2766
  const setting = dataSpace.getEdgeReplicationSetting();
@@ -2719,7 +2771,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2719
2771
  spaceId: dataSpace.id
2720
2772
  }, {
2721
2773
  F: __dxlog_file9,
2722
- L: 516,
2774
+ L: 518,
2723
2775
  S: this,
2724
2776
  C: (f, a) => f(...a)
2725
2777
  });
@@ -2749,7 +2801,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2749
2801
  space: space.key
2750
2802
  }, {
2751
2803
  F: __dxlog_file9,
2752
- L: 543,
2804
+ L: 545,
2753
2805
  S: this,
2754
2806
  C: (f, a) => f(...a)
2755
2807
  });
@@ -2782,7 +2834,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2782
2834
  closedSessions
2783
2835
  }, {
2784
2836
  F: __dxlog_file9,
2785
- L: 569,
2837
+ L: 571,
2786
2838
  S: this,
2787
2839
  C: (f, a) => f(...a)
2788
2840
  });
@@ -2797,7 +2849,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2797
2849
  peerId: peerState.peerId
2798
2850
  }, {
2799
2851
  F: __dxlog_file9,
2800
- L: 583,
2852
+ L: 585,
2801
2853
  S: this,
2802
2854
  C: (f, a) => f(...a)
2803
2855
  });
@@ -3211,7 +3263,7 @@ var Identity = class {
3211
3263
  deviceKey: params.deviceKey
3212
3264
  }, {
3213
3265
  F: __dxlog_file11,
3214
- L: 78,
3266
+ L: 79,
3215
3267
  S: this,
3216
3268
  C: (f, a) => f(...a)
3217
3269
  });
@@ -3252,10 +3304,13 @@ var Identity = class {
3252
3304
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
3253
3305
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
3254
3306
  await this.space.spaceState.addCredentialProcessor(this._defaultSpaceStateMachine);
3307
+ await this.space.open(ctx);
3308
+ }
3309
+ async joinNetwork() {
3255
3310
  if (this._edgeFeedReplicator) {
3256
3311
  this.space.protocol.feedAdded.append(this._onFeedAdded);
3257
3312
  }
3258
- await this.space.open(ctx);
3313
+ await this.space.startProtocol();
3259
3314
  await this._edgeFeedReplicator?.open();
3260
3315
  }
3261
3316
  async close(ctx) {
@@ -3285,6 +3340,9 @@ var Identity = class {
3285
3340
  get controlPipeline() {
3286
3341
  return this.space.controlPipeline;
3287
3342
  }
3343
+ get haloSpaceId() {
3344
+ return this.space.id;
3345
+ }
3288
3346
  get haloSpaceKey() {
3289
3347
  return this.space.key;
3290
3348
  }
@@ -3307,7 +3365,7 @@ var Identity = class {
3307
3365
  getIdentityCredentialSigner() {
3308
3366
  (0, import_invariant6.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3309
3367
  F: __dxlog_file11,
3310
- L: 189,
3368
+ L: 195,
3311
3369
  S: this,
3312
3370
  A: [
3313
3371
  "this._deviceStateMachine.deviceCredentialChain",
@@ -3351,20 +3409,21 @@ var Identity = class {
3351
3409
  dataFeedKey
3352
3410
  }, {
3353
3411
  F: __dxlog_file11,
3354
- L: 214,
3412
+ L: 220,
3355
3413
  S: this,
3356
3414
  C: (f, a) => f(...a)
3357
3415
  });
3358
3416
  const signer = this.getIdentityCredentialSigner();
3417
+ const deviceCredential = await signer.createCredential({
3418
+ subject: deviceKey,
3419
+ assertion: {
3420
+ "@type": "dxos.halo.credentials.AuthorizedDevice",
3421
+ identityKey: this.identityKey,
3422
+ deviceKey
3423
+ }
3424
+ });
3359
3425
  await (0, import_feed_store2.writeMessages)(this.controlPipeline.writer, [
3360
- await signer.createCredential({
3361
- subject: deviceKey,
3362
- assertion: {
3363
- "@type": "dxos.halo.credentials.AuthorizedDevice",
3364
- identityKey: this.identityKey,
3365
- deviceKey
3366
- }
3367
- }),
3426
+ deviceCredential,
3368
3427
  await signer.createCredential({
3369
3428
  subject: controlFeedKey,
3370
3429
  assertion: {
@@ -3390,6 +3449,7 @@ var Identity = class {
3390
3449
  credential
3391
3450
  }
3392
3451
  })));
3452
+ return deviceCredential;
3393
3453
  }
3394
3454
  };
3395
3455
  _ts_decorate4([
@@ -3422,7 +3482,6 @@ var IdentityManager = class {
3422
3482
  this._edgeFeatures = params.edgeFeatures;
3423
3483
  this._devicePresenceAnnounceInterval = params.devicePresenceAnnounceInterval ?? DEVICE_PRESENCE_ANNOUNCE_INTERVAL;
3424
3484
  this._devicePresenceOfflineTimeout = params.devicePresenceOfflineTimeout ?? DEVICE_PRESENCE_OFFLINE_TIMEOUT;
3425
- this._callbacks = params.callbacks;
3426
3485
  }
3427
3486
  get identity() {
3428
3487
  return this._identity;
@@ -3433,7 +3492,7 @@ var IdentityManager = class {
3433
3492
  id: traceId
3434
3493
  }), {
3435
3494
  F: __dxlog_file12,
3436
- L: 121,
3495
+ L: 116,
3437
3496
  S: this,
3438
3497
  C: (f, a) => f(...a)
3439
3498
  });
@@ -3442,7 +3501,7 @@ var IdentityManager = class {
3442
3501
  identityRecord
3443
3502
  }, {
3444
3503
  F: __dxlog_file12,
3445
- L: 124,
3504
+ L: 119,
3446
3505
  S: this,
3447
3506
  C: (f, a) => f(...a)
3448
3507
  });
@@ -3455,7 +3514,7 @@ var IdentityManager = class {
3455
3514
  displayName: this._identity.profileDocument?.displayName
3456
3515
  }, {
3457
3516
  F: __dxlog_file12,
3458
- L: 129,
3517
+ L: 124,
3459
3518
  S: this,
3460
3519
  C: (f, a) => f(...a)
3461
3520
  });
@@ -3465,7 +3524,7 @@ var IdentityManager = class {
3465
3524
  id: traceId
3466
3525
  }), {
3467
3526
  F: __dxlog_file12,
3468
- L: 136,
3527
+ L: 131,
3469
3528
  S: this,
3470
3529
  C: (f, a) => f(...a)
3471
3530
  });
@@ -3473,13 +3532,13 @@ var IdentityManager = class {
3473
3532
  async close() {
3474
3533
  await this._identity?.close(new import_context8.Context(void 0, {
3475
3534
  F: __dxlog_file12,
3476
- L: 140
3535
+ L: 135
3477
3536
  }));
3478
3537
  }
3479
3538
  async createIdentity({ displayName, deviceProfile } = {}) {
3480
3539
  (0, import_invariant9.invariant)(!this._identity, "Identity already exists.", {
3481
3540
  F: __dxlog_file12,
3482
- L: 145,
3541
+ L: 140,
3483
3542
  S: this,
3484
3543
  A: [
3485
3544
  "!this._identity",
@@ -3488,7 +3547,7 @@ var IdentityManager = class {
3488
3547
  });
3489
3548
  (0, import_log11.log)("creating identity...", void 0, {
3490
3549
  F: __dxlog_file12,
3491
- L: 146,
3550
+ L: 141,
3492
3551
  S: this,
3493
3552
  C: (f, a) => f(...a)
3494
3553
  });
@@ -3506,13 +3565,13 @@ var IdentityManager = class {
3506
3565
  const identity = await this._constructIdentity(identityRecord);
3507
3566
  await identity.open(new import_context8.Context(void 0, {
3508
3567
  F: __dxlog_file12,
3509
- L: 161
3568
+ L: 156
3510
3569
  }));
3511
3570
  {
3512
3571
  const generator = new import_credentials14.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
3513
3572
  (0, import_invariant9.invariant)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3514
3573
  F: __dxlog_file12,
3515
- L: 165,
3574
+ L: 160,
3516
3575
  S: this,
3517
3576
  A: [
3518
3577
  "identityRecord.haloSpace.genesisFeedKey",
@@ -3521,7 +3580,7 @@ var IdentityManager = class {
3521
3580
  });
3522
3581
  (0, import_invariant9.invariant)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3523
3582
  F: __dxlog_file12,
3524
- L: 166,
3583
+ L: 161,
3525
3584
  S: this,
3526
3585
  A: [
3527
3586
  "identityRecord.haloSpace.dataFeedKey",
@@ -3560,7 +3619,7 @@ var IdentityManager = class {
3560
3619
  displayName: this._identity.profileDocument?.displayName
3561
3620
  }, {
3562
3621
  F: __dxlog_file12,
3563
- L: 208,
3622
+ L: 199,
3564
3623
  S: this,
3565
3624
  C: (f, a) => f(...a)
3566
3625
  });
@@ -3571,7 +3630,7 @@ var IdentityManager = class {
3571
3630
  profile: identity.profileDocument
3572
3631
  }, {
3573
3632
  F: __dxlog_file12,
3574
- L: 214,
3633
+ L: 205,
3575
3634
  S: this,
3576
3635
  C: (f, a) => f(...a)
3577
3636
  });
@@ -3601,20 +3660,20 @@ var IdentityManager = class {
3601
3660
  };
3602
3661
  }
3603
3662
  /**
3604
- * Accept an existing identity. Expects its device key to be authorized (now or later).
3663
+ * Prepare an identity object as the first step of acceptIdentity flow.
3605
3664
  */
3606
- async acceptIdentity(params) {
3665
+ async prepareIdentity(params) {
3607
3666
  (0, import_log11.log)("accepting identity", {
3608
3667
  params
3609
3668
  }, {
3610
3669
  F: __dxlog_file12,
3611
- L: 252,
3670
+ L: 244,
3612
3671
  S: this,
3613
3672
  C: (f, a) => f(...a)
3614
3673
  });
3615
3674
  (0, import_invariant9.invariant)(!this._identity, "Identity already exists.", {
3616
3675
  F: __dxlog_file12,
3617
- L: 253,
3676
+ L: 245,
3618
3677
  S: this,
3619
3678
  A: [
3620
3679
  "!this._identity",
@@ -3635,23 +3694,32 @@ var IdentityManager = class {
3635
3694
  const identity = await this._constructIdentity(identityRecord);
3636
3695
  await identity.open(new import_context8.Context(void 0, {
3637
3696
  F: __dxlog_file12,
3638
- L: 268
3697
+ L: 259
3639
3698
  }));
3699
+ return {
3700
+ identity,
3701
+ identityRecord
3702
+ };
3703
+ }
3704
+ /**
3705
+ * Accept an existing identity. Expects its device key to be authorized (now or later).
3706
+ */
3707
+ async acceptIdentity(identity, identityRecord, profile) {
3640
3708
  this._identity = identity;
3641
- await this._metadataStore.setIdentityRecord(identityRecord);
3642
3709
  await this._identity.ready();
3710
+ await this._metadataStore.setIdentityRecord(identityRecord);
3643
3711
  import_log11.log.trace("dxos.halo.identity", {
3644
- identityKey: identityRecord.identityKey,
3712
+ identityKey: this._identity.identityKey,
3645
3713
  displayName: this._identity.profileDocument?.displayName
3646
3714
  }, {
3647
3715
  F: __dxlog_file12,
3648
- L: 272,
3716
+ L: 273,
3649
3717
  S: this,
3650
3718
  C: (f, a) => f(...a)
3651
3719
  });
3652
3720
  await this.updateDeviceProfile({
3653
3721
  ...this.createDefaultDeviceProfile(),
3654
- ...params.deviceProfile
3722
+ ...profile
3655
3723
  });
3656
3724
  this.stateUpdate.emit();
3657
3725
  (0, import_log11.log)("accepted identity", {
@@ -3659,11 +3727,10 @@ var IdentityManager = class {
3659
3727
  deviceKey: identity.deviceKey
3660
3728
  }, {
3661
3729
  F: __dxlog_file12,
3662
- L: 282,
3730
+ L: 284,
3663
3731
  S: this,
3664
3732
  C: (f, a) => f(...a)
3665
3733
  });
3666
- return identity;
3667
3734
  }
3668
3735
  /**
3669
3736
  * Update the profile document of an existing identity.
@@ -3671,7 +3738,7 @@ var IdentityManager = class {
3671
3738
  async updateProfile(profile) {
3672
3739
  (0, import_invariant9.invariant)(this._identity, "Identity not initialized.", {
3673
3740
  F: __dxlog_file12,
3674
- L: 290,
3741
+ L: 291,
3675
3742
  S: this,
3676
3743
  A: [
3677
3744
  "this._identity",
@@ -3702,7 +3769,7 @@ var IdentityManager = class {
3702
3769
  async updateDeviceProfile(profile) {
3703
3770
  (0, import_invariant9.invariant)(this._identity, "Identity not initialized.", {
3704
3771
  F: __dxlog_file12,
3705
- L: 307,
3772
+ L: 308,
3706
3773
  S: this,
3707
3774
  A: [
3708
3775
  "this._identity",
@@ -3738,7 +3805,7 @@ var IdentityManager = class {
3738
3805
  async _constructIdentity(identityRecord) {
3739
3806
  (0, import_invariant9.invariant)(!this._identity, void 0, {
3740
3807
  F: __dxlog_file12,
3741
- L: 333,
3808
+ L: 334,
3742
3809
  S: this,
3743
3810
  A: [
3744
3811
  "!this._identity",
@@ -3749,7 +3816,7 @@ var IdentityManager = class {
3749
3816
  identityRecord
3750
3817
  }, {
3751
3818
  F: __dxlog_file12,
3752
- L: 334,
3819
+ L: 335,
3753
3820
  S: this,
3754
3821
  C: (f, a) => f(...a)
3755
3822
  });
@@ -3764,7 +3831,7 @@ var IdentityManager = class {
3764
3831
  });
3765
3832
  (0, import_invariant9.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
3766
3833
  F: __dxlog_file12,
3767
- L: 347,
3834
+ L: 348,
3768
3835
  S: this,
3769
3836
  A: [
3770
3837
  "identityRecord.haloSpace.controlFeedKey",
@@ -3776,7 +3843,7 @@ var IdentityManager = class {
3776
3843
  });
3777
3844
  (0, import_invariant9.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
3778
3845
  F: __dxlog_file12,
3779
- L: 351,
3846
+ L: 352,
3780
3847
  S: this,
3781
3848
  A: [
3782
3849
  "identityRecord.haloSpace.dataFeedKey",
@@ -3813,11 +3880,10 @@ var IdentityManager = class {
3813
3880
  identityKey: identityRecord.identityKey
3814
3881
  }, {
3815
3882
  F: __dxlog_file12,
3816
- L: 380,
3883
+ L: 381,
3817
3884
  S: this,
3818
3885
  C: (f, a) => f(...a)
3819
3886
  });
3820
- this._callbacks?.onIdentityConstruction?.(identity);
3821
3887
  if (identityRecord.haloSpace.controlTimeframe) {
3822
3888
  identity.controlPipeline.state.setTargetTimeframe(identityRecord.haloSpace.controlTimeframe);
3823
3889
  }
@@ -4077,7 +4143,7 @@ var DataSpace = class {
4077
4143
  constructor(params) {
4078
4144
  this._ctx = new import_context4.Context(void 0, {
4079
4145
  F: __dxlog_file14,
4080
- L: 95
4146
+ L: 96
4081
4147
  });
4082
4148
  this._cache = void 0;
4083
4149
  this._edgeFeedReplicator = void 0;
@@ -4106,7 +4172,8 @@ var DataSpace = class {
4106
4172
  this._notarizationPlugin = new NotarizationPlugin({
4107
4173
  spaceId: this._inner.id,
4108
4174
  edgeClient: params.edgeHttpClient,
4109
- edgeFeatures: params.edgeFeatures
4175
+ edgeFeatures: params.edgeFeatures,
4176
+ activeEdgePollingInterval: params.activeEdgeNotarizationPollingInterval
4110
4177
  });
4111
4178
  this.authVerifier = new TrustedKeySetAuthVerifier({
4112
4179
  trustedKeysProvider: () => new import_util4.ComplexSet(import_keys4.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== import_credentials3.SpaceMember.Role.REMOVED).map((member) => member.key)),
@@ -4125,7 +4192,7 @@ var DataSpace = class {
4125
4192
  state: import_services4.SpaceState[this._state]
4126
4193
  }, {
4127
4194
  F: __dxlog_file14,
4128
- L: 170,
4195
+ L: 172,
4129
4196
  S: this,
4130
4197
  C: (f, a) => f(...a)
4131
4198
  });
@@ -4184,15 +4251,16 @@ var DataSpace = class {
4184
4251
  }
4185
4252
  await this._inner.open(new import_context4.Context(void 0, {
4186
4253
  F: __dxlog_file14,
4187
- L: 244
4254
+ L: 246
4188
4255
  }));
4256
+ await this._inner.startProtocol();
4189
4257
  await this._edgeFeedReplicator?.open();
4190
4258
  this._state = import_services4.SpaceState.SPACE_CONTROL_ONLY;
4191
4259
  (0, import_log4.log)("new state", {
4192
4260
  state: import_services4.SpaceState[this._state]
4193
4261
  }, {
4194
4262
  F: __dxlog_file14,
4195
- L: 249,
4263
+ L: 252,
4196
4264
  S: this,
4197
4265
  C: (f, a) => f(...a)
4198
4266
  });
@@ -4212,14 +4280,14 @@ var DataSpace = class {
4212
4280
  state: import_services4.SpaceState[this._state]
4213
4281
  }, {
4214
4282
  F: __dxlog_file14,
4215
- L: 268,
4283
+ L: 271,
4216
4284
  S: this,
4217
4285
  C: (f, a) => f(...a)
4218
4286
  });
4219
4287
  await this._ctx.dispose();
4220
4288
  this._ctx = new import_context4.Context(void 0, {
4221
4289
  F: __dxlog_file14,
4222
- L: 270
4290
+ L: 273
4223
4291
  });
4224
4292
  if (this._edgeFeedReplicator) {
4225
4293
  this.inner.protocol.feedAdded.remove(this._onFeedAdded);
@@ -4252,7 +4320,7 @@ var DataSpace = class {
4252
4320
  if (err instanceof import_protocols3.CancelledError || err instanceof import_context4.ContextDisposedError) {
4253
4321
  (0, import_log4.log)("data pipeline initialization cancelled", err, {
4254
4322
  F: __dxlog_file14,
4255
- L: 308,
4323
+ L: 311,
4256
4324
  S: this,
4257
4325
  C: (f, a) => f(...a)
4258
4326
  });
@@ -4260,7 +4328,7 @@ var DataSpace = class {
4260
4328
  }
4261
4329
  import_log4.log.error("Error initializing data pipeline", err, {
4262
4330
  F: __dxlog_file14,
4263
- L: 312,
4331
+ L: 315,
4264
4332
  S: this,
4265
4333
  C: (f, a) => f(...a)
4266
4334
  });
@@ -4269,7 +4337,7 @@ var DataSpace = class {
4269
4337
  state: import_services4.SpaceState[this._state]
4270
4338
  }, {
4271
4339
  F: __dxlog_file14,
4272
- L: 314,
4340
+ L: 317,
4273
4341
  S: this,
4274
4342
  C: (f, a) => f(...a)
4275
4343
  });
@@ -4289,13 +4357,13 @@ var DataSpace = class {
4289
4357
  state: import_services4.SpaceState[this._state]
4290
4358
  }, {
4291
4359
  F: __dxlog_file14,
4292
- L: 330,
4360
+ L: 333,
4293
4361
  S: this,
4294
4362
  C: (f, a) => f(...a)
4295
4363
  });
4296
4364
  (0, import_log4.log)("initializing control pipeline", void 0, {
4297
4365
  F: __dxlog_file14,
4298
- L: 332,
4366
+ L: 335,
4299
4367
  S: this,
4300
4368
  C: (f, a) => f(...a)
4301
4369
  });
@@ -4304,21 +4372,21 @@ var DataSpace = class {
4304
4372
  const ready = this.stateUpdate.waitForCondition(() => this._state === import_services4.SpaceState.SPACE_READY);
4305
4373
  (0, import_log4.log)("initializing automerge root", void 0, {
4306
4374
  F: __dxlog_file14,
4307
- L: 340,
4375
+ L: 343,
4308
4376
  S: this,
4309
4377
  C: (f, a) => f(...a)
4310
4378
  });
4311
4379
  this._automergeSpaceState.startProcessingRootDocs();
4312
4380
  (0, import_log4.log)("waiting for space to be ready", void 0, {
4313
4381
  F: __dxlog_file14,
4314
- L: 344,
4382
+ L: 347,
4315
4383
  S: this,
4316
4384
  C: (f, a) => f(...a)
4317
4385
  });
4318
4386
  await ready;
4319
4387
  (0, import_log4.log)("space is ready", void 0, {
4320
4388
  F: __dxlog_file14,
4321
- L: 346,
4389
+ L: 349,
4322
4390
  S: this,
4323
4391
  C: (f, a) => f(...a)
4324
4392
  });
@@ -4330,7 +4398,7 @@ var DataSpace = class {
4330
4398
  state: import_services4.SpaceState[this._state]
4331
4399
  }, {
4332
4400
  F: __dxlog_file14,
4333
- L: 353,
4401
+ L: 356,
4334
4402
  S: this,
4335
4403
  C: (f, a) => f(...a)
4336
4404
  });
@@ -4347,7 +4415,7 @@ var DataSpace = class {
4347
4415
  await this._createWritableFeeds();
4348
4416
  (0, import_log4.log)("writable feeds created", void 0, {
4349
4417
  F: __dxlog_file14,
4350
- L: 370,
4418
+ L: 373,
4351
4419
  S: this,
4352
4420
  C: (f, a) => f(...a)
4353
4421
  });
@@ -4401,7 +4469,7 @@ var DataSpace = class {
4401
4469
  count: credentials.length
4402
4470
  }, {
4403
4471
  F: __dxlog_file14,
4404
- L: 428,
4472
+ L: 431,
4405
4473
  S: this,
4406
4474
  C: (f, a) => f(...a)
4407
4475
  });
@@ -4412,14 +4480,14 @@ var DataSpace = class {
4412
4480
  });
4413
4481
  (0, import_log4.log)("credentials notarized", void 0, {
4414
4482
  F: __dxlog_file14,
4415
- L: 432,
4483
+ L: 435,
4416
4484
  S: this,
4417
4485
  C: (f, a) => f(...a)
4418
4486
  });
4419
4487
  } catch (err) {
4420
4488
  import_log4.log.error("error notarizing credentials for feed admission", err, {
4421
4489
  F: __dxlog_file14,
4422
- L: 434,
4490
+ L: 437,
4423
4491
  S: this,
4424
4492
  C: (f, a) => f(...a)
4425
4493
  });
@@ -4434,7 +4502,7 @@ var DataSpace = class {
4434
4502
  rootUrl
4435
4503
  }, {
4436
4504
  F: __dxlog_file14,
4437
- L: 444,
4505
+ L: 447,
4438
4506
  S: this,
4439
4507
  C: (f, a) => f(...a)
4440
4508
  });
@@ -4486,7 +4554,7 @@ var DataSpace = class {
4486
4554
  err
4487
4555
  }, {
4488
4556
  F: __dxlog_file14,
4489
- L: 487,
4557
+ L: 490,
4490
4558
  S: this,
4491
4559
  C: (f, a) => f(...a)
4492
4560
  });
@@ -4576,7 +4644,7 @@ var DataSpace = class {
4576
4644
  state: import_services4.SpaceState[this._state]
4577
4645
  }, {
4578
4646
  F: __dxlog_file14,
4579
- L: 569,
4647
+ L: 572,
4580
4648
  S: this,
4581
4649
  C: (f, a) => f(...a)
4582
4650
  });
@@ -4661,7 +4729,7 @@ var DeviceInvitationProtocol = class {
4661
4729
  async admit(_, request) {
4662
4730
  (0, import_invariant11.invariant)(request.device, void 0, {
4663
4731
  F: __dxlog_file15,
4664
- L: 50,
4732
+ L: 51,
4665
4733
  S: this,
4666
4734
  A: [
4667
4735
  "request.device",
@@ -4669,13 +4737,23 @@ var DeviceInvitationProtocol = class {
4669
4737
  ]
4670
4738
  });
4671
4739
  const identity = this._getIdentity();
4672
- await identity.admitDevice(request.device);
4740
+ const credential = await identity.admitDevice(request.device);
4741
+ (0, import_invariant11.invariant)((0, import_credentials17.getCredentialAssertion)(credential)["@type"] === "dxos.halo.credentials.AuthorizedDevice", void 0, {
4742
+ F: __dxlog_file15,
4743
+ L: 54,
4744
+ S: this,
4745
+ A: [
4746
+ "getCredentialAssertion(credential)['@type'] === 'dxos.halo.credentials.AuthorizedDevice'",
4747
+ ""
4748
+ ]
4749
+ });
4673
4750
  return {
4674
4751
  device: {
4675
4752
  identityKey: identity.identityKey,
4676
4753
  haloSpaceKey: identity.haloSpaceKey,
4677
4754
  genesisFeedKey: identity.haloGenesisFeedKey,
4678
- controlTimeframe: identity.controlPipeline.state.timeframe
4755
+ controlTimeframe: identity.controlPipeline.state.timeframe,
4756
+ credential
4679
4757
  }
4680
4758
  };
4681
4759
  }
@@ -4707,7 +4785,7 @@ var DeviceInvitationProtocol = class {
4707
4785
  async accept(response, request) {
4708
4786
  (0, import_invariant11.invariant)(response.device, void 0, {
4709
4787
  F: __dxlog_file15,
4710
- L: 95,
4788
+ L: 98,
4711
4789
  S: this,
4712
4790
  A: [
4713
4791
  "response.device",
@@ -4717,7 +4795,7 @@ var DeviceInvitationProtocol = class {
4717
4795
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
4718
4796
  (0, import_invariant11.invariant)(request.device, void 0, {
4719
4797
  F: __dxlog_file15,
4720
- L: 98,
4798
+ L: 101,
4721
4799
  S: this,
4722
4800
  A: [
4723
4801
  "request.device",
@@ -4733,7 +4811,8 @@ var DeviceInvitationProtocol = class {
4733
4811
  controlFeedKey,
4734
4812
  dataFeedKey,
4735
4813
  controlTimeframe,
4736
- deviceProfile: profile
4814
+ deviceProfile: profile,
4815
+ authorizedDeviceCredential: response.device.credential
4737
4816
  });
4738
4817
  return {
4739
4818
  identityKey
@@ -4884,15 +4963,16 @@ var EdgeInvitationHandler = class {
4884
4963
  return await this._client.joinSpaceByInvitation(spaceId, request);
4885
4964
  } catch (error) {
4886
4965
  if (error instanceof import_protocols10.EdgeAuthChallengeError) {
4887
- guardedState.set(this, import_services12.Invitation.State.AUTHENTICATING);
4888
4966
  const publicKey = guardedState.current.guestKeypair?.publicKey;
4889
4967
  const privateKey = guardedState.current.guestKeypair?.privateKey;
4890
4968
  if (!privateKey || !publicKey) {
4891
4969
  throw error;
4892
4970
  }
4893
- const signature = await (0, import_crypto2.ed25519Signature)(privateKey, Buffer.from(error.challenge, "base64"));
4894
- request.signature = Buffer.from(signature).toString("base64");
4895
- return this._client.joinSpaceByInvitation(spaceId, request);
4971
+ const signature = (0, import_crypto2.sign)(Buffer.from(error.challenge, "base64"), privateKey);
4972
+ return this._client.joinSpaceByInvitation(spaceId, {
4973
+ ...request,
4974
+ signature: Buffer.from(signature).toString("base64")
4975
+ });
4896
4976
  } else {
4897
4977
  throw error;
4898
4978
  }
@@ -5930,7 +6010,7 @@ var InvitationsHandler = class {
5930
6010
  const edgeInvitationHandler = new EdgeInvitationHandler(this._connectionParams?.edgeInvitations, this._edgeClient, {
5931
6011
  onInvitationSuccess: async (admissionResponse, admissionRequest) => {
5932
6012
  const result = await protocol.accept(admissionResponse, admissionRequest);
5933
- (0, import_log13.log)("admitted by edge", {
6013
+ import_log13.log.info("admitted by edge", {
5934
6014
  ...protocol.toJSON()
5935
6015
  }, {
5936
6016
  F: __dxlog_file21,
@@ -6047,7 +6127,6 @@ var InvitationsHandler = class {
6047
6127
  S: this,
6048
6128
  C: (f, a) => f(...a)
6049
6129
  });
6050
- setState(import_services11.Invitation.State.AUTHENTICATING);
6051
6130
  const signature = (0, import_crypto.sign)(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
6052
6131
  const response = await extension.rpc.InvitationHostService.authenticate({
6053
6132
  signedChallenge: signature
@@ -6232,7 +6311,7 @@ var SpaceInvitationProtocol = class {
6232
6311
  const spaceMemberCredential = await this._spaceManager.admitMember({
6233
6312
  spaceKey: this._spaceKey,
6234
6313
  identityKey: request.space.identityKey,
6235
- role: invitation.role ?? import_credentials18.SpaceMember.Role.ADMIN,
6314
+ role: invitation.role ?? import_credentials19.SpaceMember.Role.ADMIN,
6236
6315
  profile: guestProfile,
6237
6316
  delegationCredentialId: invitation.delegationCredentialId
6238
6317
  });
@@ -6284,11 +6363,11 @@ var SpaceInvitationProtocol = class {
6284
6363
  S: this,
6285
6364
  C: (f, a) => f(...a)
6286
6365
  });
6287
- const credential = await (0, import_credentials17.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
6366
+ const credential = await (0, import_credentials18.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
6288
6367
  invitationId: invitation.invitationId,
6289
6368
  authMethod: invitation.authMethod,
6290
6369
  swarmKey: invitation.swarmKey,
6291
- role: invitation.role ?? import_credentials18.SpaceMember.Role.ADMIN,
6370
+ role: invitation.role ?? import_credentials19.SpaceMember.Role.ADMIN,
6292
6371
  expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
6293
6372
  multiUse: invitation.multiUse ?? false,
6294
6373
  guestKey: invitation.authMethod === import_services17.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
@@ -6345,7 +6424,7 @@ var SpaceInvitationProtocol = class {
6345
6424
  S: this,
6346
6425
  C: (f, a) => f(...a)
6347
6426
  });
6348
- const credential = await (0, import_credentials17.createCancelDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
6427
+ const credential = await (0, import_credentials18.createCancelDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
6349
6428
  (0, import_invariant17.invariant)(credential.credential, void 0, {
6350
6429
  F: __dxlog_file22,
6351
6430
  L: 144,
@@ -6395,7 +6474,7 @@ var SpaceInvitationProtocol = class {
6395
6474
  ]
6396
6475
  });
6397
6476
  const { credential, controlTimeframe, dataTimeframe } = response.space;
6398
- const assertion = (0, import_credentials17.getCredentialAssertion)(credential);
6477
+ const assertion = (0, import_credentials18.getCredentialAssertion)(credential);
6399
6478
  (0, import_invariant17.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6400
6479
  F: __dxlog_file22,
6401
6480
  L: 182,
@@ -6631,8 +6710,8 @@ var InvitationsManager = class {
6631
6710
  }
6632
6711
  }
6633
6712
  _createInvitation(protocol, options) {
6634
- const { invitationId = import_keys14.PublicKey.random().toHex(), type = import_services18.Invitation.Type.INTERACTIVE, authMethod = import_services18.Invitation.AuthMethod.SHARED_SECRET, state = import_services18.Invitation.State.INIT, timeout = import_client_protocol6.INVITATION_TIMEOUT, swarmKey = import_keys14.PublicKey.random(), persistent = options?.authMethod !== import_services18.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = import_credentials20.SpaceMember.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
6635
- const authCode = options?.authCode ?? (authMethod === import_services18.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials19.generatePasscode)(import_client_protocol6.AUTHENTICATION_CODE_LENGTH) : void 0);
6713
+ const { invitationId = import_keys14.PublicKey.random().toHex(), type = import_services18.Invitation.Type.INTERACTIVE, authMethod = import_services18.Invitation.AuthMethod.SHARED_SECRET, state = import_services18.Invitation.State.INIT, timeout = import_client_protocol6.INVITATION_TIMEOUT, swarmKey = import_keys14.PublicKey.random(), persistent = options?.authMethod !== import_services18.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = import_credentials21.SpaceMember.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
6714
+ const authCode = options?.authCode ?? (authMethod === import_services18.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials20.generatePasscode)(import_client_protocol6.AUTHENTICATION_CODE_LENGTH) : void 0);
6636
6715
  return {
6637
6716
  invitationId,
6638
6717
  type,
@@ -6915,6 +6994,250 @@ function _ts_decorate9(decorators, target, key, desc) {
6915
6994
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6916
6995
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6917
6996
  }
6997
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/agents/edge-agent-manager.ts";
6998
+ var AGENT_STATUS_QUERY_RETRY_INTERVAL = 5e3;
6999
+ var AGENT_STATUS_QUERY_RETRY_JITTER = 1e3;
7000
+ var EdgeAgentManager = class extends import_context15.Resource {
7001
+ constructor(_edgeFeatures, _edgeHttpClient, _dataSpaceManager, _identity) {
7002
+ super();
7003
+ this._edgeFeatures = _edgeFeatures;
7004
+ this._edgeHttpClient = _edgeHttpClient;
7005
+ this._dataSpaceManager = _dataSpaceManager;
7006
+ this._identity = _identity;
7007
+ this.agentStatusChanged = new import_async21.Event();
7008
+ this._lastKnownDeviceCount = 0;
7009
+ }
7010
+ get agentStatus() {
7011
+ return this._agentStatus;
7012
+ }
7013
+ get agentExists() {
7014
+ return this._agentStatus && this._agentStatus !== import_protocols14.EdgeAgentStatus.NOT_FOUND;
7015
+ }
7016
+ async createAgent() {
7017
+ (0, import_invariant20.invariant)(this.isOpen, void 0, {
7018
+ F: __dxlog_file25,
7019
+ L: 52,
7020
+ S: this,
7021
+ A: [
7022
+ "this.isOpen",
7023
+ ""
7024
+ ]
7025
+ });
7026
+ (0, import_invariant20.invariant)(this._edgeHttpClient, void 0, {
7027
+ F: __dxlog_file25,
7028
+ L: 53,
7029
+ S: this,
7030
+ A: [
7031
+ "this._edgeHttpClient",
7032
+ ""
7033
+ ]
7034
+ });
7035
+ (0, import_invariant20.invariant)(this._edgeFeatures?.agents, void 0, {
7036
+ F: __dxlog_file25,
7037
+ L: 54,
7038
+ S: this,
7039
+ A: [
7040
+ "this._edgeFeatures?.agents",
7041
+ ""
7042
+ ]
7043
+ });
7044
+ const response = await this._edgeHttpClient.createAgent({
7045
+ identityKey: this._identity.identityKey.toHex(),
7046
+ haloSpaceId: this._identity.haloSpaceId,
7047
+ haloSpaceKey: this._identity.haloSpaceKey.toHex()
7048
+ });
7049
+ const deviceKey = import_keys15.PublicKey.fromHex(response.deviceKey);
7050
+ await this._identity.admitDevice({
7051
+ deviceKey,
7052
+ controlFeedKey: import_keys15.PublicKey.fromHex(response.feedKey),
7053
+ // TODO: agents don't have data feed, should be removed
7054
+ dataFeedKey: import_keys15.PublicKey.random()
7055
+ });
7056
+ (0, import_log22.log)("agent created", response, {
7057
+ F: __dxlog_file25,
7058
+ L: 71,
7059
+ S: this,
7060
+ C: (f, a) => f(...a)
7061
+ });
7062
+ this._updateStatus(import_protocols14.EdgeAgentStatus.ACTIVE, deviceKey);
7063
+ }
7064
+ async _open() {
7065
+ const isEnabled = this._edgeHttpClient && this._edgeFeatures?.agents;
7066
+ (0, import_log22.log)("edge agent manager open", {
7067
+ isEnabled
7068
+ }, {
7069
+ F: __dxlog_file25,
7070
+ L: 79,
7071
+ S: this,
7072
+ C: (f, a) => f(...a)
7073
+ });
7074
+ if (!isEnabled) {
7075
+ return;
7076
+ }
7077
+ this._lastKnownDeviceCount = this._identity.authorizedDeviceKeys.size;
7078
+ this._fetchAgentStatusTask = new import_async21.DeferredTask(this._ctx, async () => {
7079
+ await this._fetchAgentStatus();
7080
+ });
7081
+ this._fetchAgentStatusTask.schedule();
7082
+ this._dataSpaceManager.updated.on(this._ctx, () => {
7083
+ if (this._agentDeviceKey) {
7084
+ this._ensureAgentIsInSpaces(this._agentDeviceKey);
7085
+ }
7086
+ });
7087
+ this._identity.stateUpdate.on(this._ctx, () => {
7088
+ const maybeAgentWasCreated = this._identity.authorizedDeviceKeys.size > this._lastKnownDeviceCount;
7089
+ if (this.agentExists || !maybeAgentWasCreated) {
7090
+ return;
7091
+ }
7092
+ this._lastKnownDeviceCount = this._identity.authorizedDeviceKeys.size;
7093
+ this._fetchAgentStatusTask?.schedule();
7094
+ });
7095
+ }
7096
+ async _close() {
7097
+ this._fetchAgentStatusTask = void 0;
7098
+ this._lastKnownDeviceCount = 0;
7099
+ }
7100
+ async _fetchAgentStatus() {
7101
+ (0, import_invariant20.invariant)(this._edgeHttpClient, void 0, {
7102
+ F: __dxlog_file25,
7103
+ L: 113,
7104
+ S: this,
7105
+ A: [
7106
+ "this._edgeHttpClient",
7107
+ ""
7108
+ ]
7109
+ });
7110
+ try {
7111
+ (0, import_log22.log)("fetching agent status", void 0, {
7112
+ F: __dxlog_file25,
7113
+ L: 115,
7114
+ S: this,
7115
+ C: (f, a) => f(...a)
7116
+ });
7117
+ const { agent } = await this._edgeHttpClient.getAgentStatus({
7118
+ ownerIdentityKey: this._identity.identityKey
7119
+ });
7120
+ const wasAgentCreatedDuringQuery = this._agentStatus === import_protocols14.EdgeAgentStatus.ACTIVE;
7121
+ if (!wasAgentCreatedDuringQuery) {
7122
+ const deviceKey = agent.deviceKey ? import_keys15.PublicKey.fromHex(agent.deviceKey) : void 0;
7123
+ this._updateStatus(agent.status, deviceKey);
7124
+ }
7125
+ } catch (err) {
7126
+ if (err instanceof import_protocols14.EdgeCallFailedError) {
7127
+ if (!err.isRetryable) {
7128
+ import_log22.log.warn("non retryable error on agent status fetch attempt", {
7129
+ err
7130
+ }, {
7131
+ F: __dxlog_file25,
7132
+ L: 125,
7133
+ S: this,
7134
+ C: (f, a) => f(...a)
7135
+ });
7136
+ return;
7137
+ }
7138
+ }
7139
+ const retryAfterMs = AGENT_STATUS_QUERY_RETRY_INTERVAL + Math.random() * AGENT_STATUS_QUERY_RETRY_JITTER;
7140
+ import_log22.log.info("agent status fetching failed", {
7141
+ err,
7142
+ retryAfterMs
7143
+ }, {
7144
+ F: __dxlog_file25,
7145
+ L: 130,
7146
+ S: this,
7147
+ C: (f, a) => f(...a)
7148
+ });
7149
+ (0, import_async21.scheduleTask)(this._ctx, () => this._fetchAgentStatusTask?.schedule(), retryAfterMs);
7150
+ }
7151
+ }
7152
+ /**
7153
+ * We don't want notarization plugin to always actively poll edge looking for credentials to notarize,
7154
+ * because most of the time we'll be getting an empty response.
7155
+ * Instead, we stay in active polling mode while there are spaces where we don't see our agent's feed.
7156
+ */
7157
+ _ensureAgentIsInSpaces(agentDeviceKey) {
7158
+ for (const space of this._dataSpaceManager.spaces.values()) {
7159
+ if ([
7160
+ import_services19.SpaceState.SPACE_INACTIVE,
7161
+ import_services19.SpaceState.SPACE_CLOSED
7162
+ ].includes(space.state)) {
7163
+ continue;
7164
+ }
7165
+ const agentFeedNeedsNotarization = !space.inner.spaceState.feeds.values().some((feed) => feed.assertion.deviceKey.equals(agentDeviceKey));
7166
+ space.notarizationPlugin.setActiveEdgePollingEnabled(agentFeedNeedsNotarization);
7167
+ import_log22.log.info("set active edge polling", {
7168
+ enabled: agentFeedNeedsNotarization,
7169
+ spaceId: space.id
7170
+ }, {
7171
+ F: __dxlog_file25,
7172
+ L: 150,
7173
+ S: this,
7174
+ C: (f, a) => f(...a)
7175
+ });
7176
+ }
7177
+ }
7178
+ _updateStatus(status, deviceKey) {
7179
+ this._agentStatus = status;
7180
+ this._agentDeviceKey = deviceKey;
7181
+ this.agentStatusChanged.emit(status);
7182
+ if (deviceKey) {
7183
+ this._ensureAgentIsInSpaces(deviceKey);
7184
+ }
7185
+ import_log22.log.info("agent status update", {
7186
+ status
7187
+ }, {
7188
+ F: __dxlog_file25,
7189
+ L: 161,
7190
+ S: this,
7191
+ C: (f, a) => f(...a)
7192
+ });
7193
+ }
7194
+ };
7195
+ _ts_decorate9([
7196
+ import_async21.synchronized
7197
+ ], EdgeAgentManager.prototype, "createAgent", null);
7198
+ var EdgeAgentServiceImpl = class {
7199
+ constructor(_agentManagerProvider) {
7200
+ this._agentManagerProvider = _agentManagerProvider;
7201
+ }
7202
+ async createAgent() {
7203
+ return (await this._agentManagerProvider()).createAgent();
7204
+ }
7205
+ queryAgentStatus() {
7206
+ return new import_codec_protobuf12.Stream(({ ctx, next }) => {
7207
+ next({
7208
+ status: import_services20.QueryAgentStatusResponse.AgentStatus.UNKNOWN
7209
+ });
7210
+ void this._agentManagerProvider().then((agentManager) => {
7211
+ next({
7212
+ status: mapStatus(agentManager.agentStatus)
7213
+ });
7214
+ agentManager.agentStatusChanged.on(ctx, (newStatus) => {
7215
+ next({
7216
+ status: mapStatus(newStatus)
7217
+ });
7218
+ });
7219
+ });
7220
+ });
7221
+ }
7222
+ };
7223
+ var mapStatus = (agentStatus) => {
7224
+ switch (agentStatus) {
7225
+ case import_protocols15.EdgeAgentStatus.ACTIVE:
7226
+ return import_services20.QueryAgentStatusResponse.AgentStatus.ACTIVE;
7227
+ case import_protocols15.EdgeAgentStatus.INACTIVE:
7228
+ return import_services20.QueryAgentStatusResponse.AgentStatus.INACTIVE;
7229
+ case import_protocols15.EdgeAgentStatus.NOT_FOUND:
7230
+ return import_services20.QueryAgentStatusResponse.AgentStatus.NOT_FOUND;
7231
+ case void 0:
7232
+ return import_services20.QueryAgentStatusResponse.AgentStatus.UNKNOWN;
7233
+ }
7234
+ };
7235
+ function _ts_decorate10(decorators, target, key, desc) {
7236
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7237
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7238
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
7239
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7240
+ }
6918
7241
  function _using_ctx3() {
6919
7242
  var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
6920
7243
  var err = new Error();
@@ -6977,8 +7300,8 @@ function _using_ctx3() {
6977
7300
  }
6978
7301
  };
6979
7302
  }
6980
- var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
6981
- var ServiceContext = class extends import_context15.Resource {
7303
+ var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
7304
+ var ServiceContext = class extends import_context16.Resource {
6982
7305
  constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
6983
7306
  super();
6984
7307
  this.storage = storage;
@@ -6989,12 +7312,12 @@ var ServiceContext = class extends import_context15.Resource {
6989
7312
  this._edgeHttpClient = _edgeHttpClient;
6990
7313
  this._runtimeParams = _runtimeParams;
6991
7314
  this._edgeFeatures = _edgeFeatures;
6992
- this._edgeIdentityUpdateMutex = new import_async21.Mutex();
6993
- this.initialized = new import_async21.Trigger();
7315
+ this._edgeIdentityUpdateMutex = new import_async22.Mutex();
7316
+ this.initialized = new import_async22.Trigger();
6994
7317
  this._meshReplicator = void 0;
6995
7318
  this._echoEdgeReplicator = void 0;
6996
7319
  this._handlerFactories = /* @__PURE__ */ new Map();
6997
- this._instanceId = import_keys15.PublicKey.random().toHex();
7320
+ this._instanceId = import_keys16.PublicKey.random().toHex();
6998
7321
  this.metadataStore = new import_echo_pipeline5.MetadataStore(storage.createDirectory("metadata"));
6999
7322
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
7000
7323
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
@@ -7023,50 +7346,7 @@ var ServiceContext = class extends import_context15.Resource {
7023
7346
  devicePresenceOfflineTimeout: this._runtimeParams?.devicePresenceOfflineTimeout,
7024
7347
  devicePresenceAnnounceInterval: this._runtimeParams?.devicePresenceAnnounceInterval,
7025
7348
  edgeConnection: this._edgeConnection,
7026
- edgeFeatures: this._edgeFeatures,
7027
- callbacks: {
7028
- onIdentityConstruction: (identity) => {
7029
- if (this._edgeConnection) {
7030
- (0, import_async21.scheduleMicroTask)(this._ctx, async () => {
7031
- try {
7032
- var _usingCtx = _using_ctx3();
7033
- const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
7034
- import_log22.log.info("Setting identity on edge connection", {
7035
- identity: identity.identityKey.toHex(),
7036
- oldIdentity: this._edgeConnection.identityKey,
7037
- swarms: this.networkManager.topics
7038
- }, {
7039
- F: __dxlog_file25,
7040
- L: 147,
7041
- S: this,
7042
- C: (f, a) => f(...a)
7043
- });
7044
- await (0, import_debug6.warnAfterTimeout)(1e4, "Waiting for identity to be ready for edge connection", async () => {
7045
- await identity.ready();
7046
- });
7047
- (0, import_invariant20.invariant)(identity.deviceCredentialChain, void 0, {
7048
- F: __dxlog_file25,
7049
- L: 157,
7050
- S: this,
7051
- A: [
7052
- "identity.deviceCredentialChain",
7053
- ""
7054
- ]
7055
- });
7056
- this._edgeConnection.setIdentity(await (0, import_edge_client2.createChainEdgeIdentity)(identity.signer, identity.identityKey, identity.deviceKey, identity.deviceCredentialChain, []));
7057
- this.networkManager.setPeerInfo({
7058
- identityKey: identity.identityKey.toHex(),
7059
- peerKey: identity.deviceKey.toHex()
7060
- });
7061
- } catch (_) {
7062
- _usingCtx.e = _;
7063
- } finally {
7064
- _usingCtx.d();
7065
- }
7066
- });
7067
- }
7068
- }
7069
- }
7349
+ edgeFeatures: this._edgeFeatures
7070
7350
  });
7071
7351
  this.echoHost = new import_echo_pipeline5.EchoHost({
7072
7352
  kv: this.level
@@ -7074,7 +7354,7 @@ var ServiceContext = class extends import_context15.Resource {
7074
7354
  this._meshReplicator = new import_echo_pipeline5.MeshEchoReplicator();
7075
7355
  this.invitations = new InvitationsHandler(this.networkManager, this._edgeHttpClient, _runtimeParams?.invitationConnectionDefaultParams);
7076
7356
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
7077
- this._handlerFactories.set(import_services19.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
7357
+ this._handlerFactories.set(import_services21.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
7078
7358
  if (!this._runtimeParams?.disableP2pReplication) {
7079
7359
  this._meshReplicator = new import_echo_pipeline5.MeshEchoReplicator();
7080
7360
  }
@@ -7086,24 +7366,23 @@ var ServiceContext = class extends import_context15.Resource {
7086
7366
  }
7087
7367
  async _open(ctx) {
7088
7368
  await this._checkStorageVersion();
7089
- (0, import_log22.log)("opening...", void 0, {
7090
- F: __dxlog_file25,
7091
- L: 218,
7369
+ (0, import_log23.log)("opening...", void 0, {
7370
+ F: __dxlog_file26,
7371
+ L: 186,
7092
7372
  S: this,
7093
7373
  C: (f, a) => f(...a)
7094
7374
  });
7095
- import_log22.log.trace("dxos.sdk.service-context.open", import_protocols14.trace.begin({
7375
+ import_log23.log.trace("dxos.sdk.service-context.open", import_protocols16.trace.begin({
7096
7376
  id: this._instanceId
7097
7377
  }), {
7098
- F: __dxlog_file25,
7099
- L: 219,
7378
+ F: __dxlog_file26,
7379
+ L: 187,
7100
7380
  S: this,
7101
7381
  C: (f, a) => f(...a)
7102
7382
  });
7103
- if (this._edgeConnection) {
7104
- this._edgeConnection.setIdentity(await (0, import_edge_client2.createEphemeralEdgeIdentity)());
7105
- await this._edgeConnection.open();
7106
- }
7383
+ await this.identityManager.open(ctx);
7384
+ await this._setNetworkIdentity();
7385
+ await this._edgeConnection?.open();
7107
7386
  await this.signalManager.open();
7108
7387
  await this.networkManager.open();
7109
7388
  await this.echoHost.open(ctx);
@@ -7115,38 +7394,38 @@ var ServiceContext = class extends import_context15.Resource {
7115
7394
  }
7116
7395
  await this.metadataStore.load();
7117
7396
  await this.spaceManager.open();
7118
- await this.identityManager.open(ctx);
7119
7397
  if (this.identityManager.identity) {
7398
+ await this.identityManager.identity.joinNetwork();
7120
7399
  await this._initialize(ctx);
7121
7400
  }
7122
7401
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
7123
- (0, import_log22.log)("loaded persistent invitations", {
7402
+ (0, import_log23.log)("loaded persistent invitations", {
7124
7403
  count: loadedInvitations.invitations?.length
7125
7404
  }, {
7126
- F: __dxlog_file25,
7127
- L: 246,
7405
+ F: __dxlog_file26,
7406
+ L: 215,
7128
7407
  S: this,
7129
7408
  C: (f, a) => f(...a)
7130
7409
  });
7131
- import_log22.log.trace("dxos.sdk.service-context.open", import_protocols14.trace.end({
7410
+ import_log23.log.trace("dxos.sdk.service-context.open", import_protocols16.trace.end({
7132
7411
  id: this._instanceId
7133
7412
  }), {
7134
- F: __dxlog_file25,
7135
- L: 248,
7413
+ F: __dxlog_file26,
7414
+ L: 217,
7136
7415
  S: this,
7137
7416
  C: (f, a) => f(...a)
7138
7417
  });
7139
- (0, import_log22.log)("opened", void 0, {
7140
- F: __dxlog_file25,
7141
- L: 249,
7418
+ (0, import_log23.log)("opened", void 0, {
7419
+ F: __dxlog_file26,
7420
+ L: 218,
7142
7421
  S: this,
7143
7422
  C: (f, a) => f(...a)
7144
7423
  });
7145
7424
  }
7146
7425
  async _close(ctx) {
7147
- (0, import_log22.log)("closing...", void 0, {
7148
- F: __dxlog_file25,
7149
- L: 253,
7426
+ (0, import_log23.log)("closing...", void 0, {
7427
+ F: __dxlog_file26,
7428
+ L: 222,
7150
7429
  S: this,
7151
7430
  C: (f, a) => f(...a)
7152
7431
  });
@@ -7154,6 +7433,7 @@ var ServiceContext = class extends import_context15.Resource {
7154
7433
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
7155
7434
  }
7156
7435
  await this.dataSpaceManager?.close();
7436
+ await this.edgeAgentManager?.close();
7157
7437
  await this.identityManager.close();
7158
7438
  await this.spaceManager.close();
7159
7439
  await this.feedStore.close();
@@ -7162,26 +7442,28 @@ var ServiceContext = class extends import_context15.Resource {
7162
7442
  await this.networkManager.close();
7163
7443
  await this.signalManager.close();
7164
7444
  await this._edgeConnection?.close();
7165
- (0, import_log22.log)("closed", void 0, {
7166
- F: __dxlog_file25,
7167
- L: 268,
7445
+ (0, import_log23.log)("closed", void 0, {
7446
+ F: __dxlog_file26,
7447
+ L: 238,
7168
7448
  S: this,
7169
7449
  C: (f, a) => f(...a)
7170
7450
  });
7171
7451
  }
7172
7452
  async createIdentity(params = {}) {
7173
7453
  const identity = await this.identityManager.createIdentity(params);
7174
- await this._initialize(new import_context15.Context(void 0, {
7175
- F: __dxlog_file25,
7176
- L: 273
7454
+ await this._setNetworkIdentity();
7455
+ await identity.joinNetwork();
7456
+ await this._initialize(new import_context16.Context(void 0, {
7457
+ F: __dxlog_file26,
7458
+ L: 245
7177
7459
  }));
7178
7460
  return identity;
7179
7461
  }
7180
7462
  getInvitationHandler(invitation) {
7181
7463
  const factory = this._handlerFactories.get(invitation.kind);
7182
- (0, import_invariant20.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
7183
- F: __dxlog_file25,
7184
- L: 279,
7464
+ (0, import_invariant21.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
7465
+ F: __dxlog_file26,
7466
+ L: 251,
7185
7467
  S: this,
7186
7468
  A: [
7187
7469
  "factory",
@@ -7199,24 +7481,29 @@ var ServiceContext = class extends import_context15.Resource {
7199
7481
  }
7200
7482
  }
7201
7483
  async _acceptIdentity(params) {
7202
- const identity = await this.identityManager.acceptIdentity(params);
7203
- await this._initialize(new import_context15.Context(void 0, {
7204
- F: __dxlog_file25,
7205
- L: 295
7484
+ const { identity, identityRecord } = await this.identityManager.prepareIdentity(params);
7485
+ await this._setNetworkIdentity({
7486
+ deviceCredential: params.authorizedDeviceCredential
7487
+ });
7488
+ await identity.joinNetwork();
7489
+ await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
7490
+ await this._initialize(new import_context16.Context(void 0, {
7491
+ F: __dxlog_file26,
7492
+ L: 270
7206
7493
  }));
7207
7494
  return identity;
7208
7495
  }
7209
7496
  async _checkStorageVersion() {
7210
7497
  await this.metadataStore.load();
7211
- if (this.metadataStore.version !== import_protocols14.STORAGE_VERSION) {
7212
- throw new import_protocols14.InvalidStorageVersionError(import_protocols14.STORAGE_VERSION, this.metadataStore.version);
7498
+ if (this.metadataStore.version !== import_protocols16.STORAGE_VERSION) {
7499
+ throw new import_protocols16.InvalidStorageVersionError(import_protocols16.STORAGE_VERSION, this.metadataStore.version);
7213
7500
  }
7214
7501
  }
7215
7502
  // Called when identity is created.
7216
7503
  async _initialize(ctx) {
7217
- (0, import_log22.log)("initializing spaces...", void 0, {
7218
- F: __dxlog_file25,
7219
- L: 310,
7504
+ (0, import_log23.log)("initializing spaces...", void 0, {
7505
+ F: __dxlog_file26,
7506
+ L: 285,
7220
7507
  S: this,
7221
7508
  C: (f, a) => f(...a)
7222
7509
  });
@@ -7250,10 +7537,12 @@ var ServiceContext = class extends import_context15.Resource {
7250
7537
  edgeFeatures: this._edgeFeatures
7251
7538
  });
7252
7539
  await this.dataSpaceManager.open();
7253
- this._handlerFactories.set(import_services19.Invitation.Kind.SPACE, (invitation) => {
7254
- (0, import_invariant20.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
7255
- F: __dxlog_file25,
7256
- L: 340,
7540
+ this.edgeAgentManager = new EdgeAgentManager(this._edgeFeatures, this._edgeHttpClient, this.dataSpaceManager, identity);
7541
+ await this.edgeAgentManager.open();
7542
+ this._handlerFactories.set(import_services21.Invitation.Kind.SPACE, (invitation) => {
7543
+ (0, import_invariant21.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
7544
+ F: __dxlog_file26,
7545
+ L: 323,
7257
7546
  S: this,
7258
7547
  A: [
7259
7548
  "this.dataSpaceManager",
@@ -7265,7 +7554,7 @@ var ServiceContext = class extends import_context15.Resource {
7265
7554
  this.initialized.wake();
7266
7555
  this._deviceSpaceSync = {
7267
7556
  processCredential: async (credential) => {
7268
- const assertion = (0, import_credentials21.getCredentialAssertion)(credential);
7557
+ const assertion = (0, import_credentials22.getCredentialAssertion)(credential);
7269
7558
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
7270
7559
  return;
7271
7560
  }
@@ -7273,33 +7562,33 @@ var ServiceContext = class extends import_context15.Resource {
7273
7562
  return;
7274
7563
  }
7275
7564
  if (!this.dataSpaceManager) {
7276
- (0, import_log22.log)("dataSpaceManager not initialized yet, ignoring space admission", {
7565
+ (0, import_log23.log)("dataSpaceManager not initialized yet, ignoring space admission", {
7277
7566
  details: assertion
7278
7567
  }, {
7279
- F: __dxlog_file25,
7280
- L: 356,
7568
+ F: __dxlog_file26,
7569
+ L: 339,
7281
7570
  S: this,
7282
7571
  C: (f, a) => f(...a)
7283
7572
  });
7284
7573
  return;
7285
7574
  }
7286
7575
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
7287
- (0, import_log22.log)("space already exists, ignoring space admission", {
7576
+ (0, import_log23.log)("space already exists, ignoring space admission", {
7288
7577
  details: assertion
7289
7578
  }, {
7290
- F: __dxlog_file25,
7291
- L: 360,
7579
+ F: __dxlog_file26,
7580
+ L: 343,
7292
7581
  S: this,
7293
7582
  C: (f, a) => f(...a)
7294
7583
  });
7295
7584
  return;
7296
7585
  }
7297
7586
  try {
7298
- (0, import_log22.log)("accepting space recorded in halo", {
7587
+ (0, import_log23.log)("accepting space recorded in halo", {
7299
7588
  details: assertion
7300
7589
  }, {
7301
- F: __dxlog_file25,
7302
- L: 365,
7590
+ F: __dxlog_file26,
7591
+ L: 348,
7303
7592
  S: this,
7304
7593
  C: (f, a) => f(...a)
7305
7594
  });
@@ -7308,9 +7597,9 @@ var ServiceContext = class extends import_context15.Resource {
7308
7597
  genesisFeedKey: assertion.genesisFeedKey
7309
7598
  });
7310
7599
  } catch (err) {
7311
- import_log22.log.catch(err, void 0, {
7312
- F: __dxlog_file25,
7313
- L: 371,
7600
+ import_log23.log.catch(err, void 0, {
7601
+ F: __dxlog_file26,
7602
+ L: 354,
7314
7603
  S: this,
7315
7604
  C: (f, a) => f(...a)
7316
7605
  });
@@ -7319,14 +7608,65 @@ var ServiceContext = class extends import_context15.Resource {
7319
7608
  };
7320
7609
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
7321
7610
  }
7611
+ async _setNetworkIdentity(params) {
7612
+ try {
7613
+ var _usingCtx = _using_ctx3();
7614
+ const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
7615
+ let edgeIdentity;
7616
+ const identity = this.identityManager.identity;
7617
+ if (identity) {
7618
+ import_log23.log.info("Setting identity on edge connection", {
7619
+ identity: identity.identityKey.toHex(),
7620
+ swarms: this.networkManager.topics
7621
+ }, {
7622
+ F: __dxlog_file26,
7623
+ L: 368,
7624
+ S: this,
7625
+ C: (f, a) => f(...a)
7626
+ });
7627
+ if (params?.deviceCredential) {
7628
+ edgeIdentity = await (0, import_edge_client2.createChainEdgeIdentity)(identity.signer, identity.identityKey, identity.deviceKey, {
7629
+ credential: params.deviceCredential
7630
+ }, []);
7631
+ } else {
7632
+ await (0, import_debug6.warnAfterTimeout)(1e4, "Waiting for identity to be ready for edge connection", async () => {
7633
+ await identity.ready();
7634
+ });
7635
+ (0, import_invariant21.invariant)(identity.deviceCredentialChain, void 0, {
7636
+ F: __dxlog_file26,
7637
+ L: 386,
7638
+ S: this,
7639
+ A: [
7640
+ "identity.deviceCredentialChain",
7641
+ ""
7642
+ ]
7643
+ });
7644
+ edgeIdentity = await (0, import_edge_client2.createChainEdgeIdentity)(identity.signer, identity.identityKey, identity.deviceKey, identity.deviceCredentialChain, []);
7645
+ }
7646
+ } else {
7647
+ edgeIdentity = await (0, import_edge_client2.createEphemeralEdgeIdentity)();
7648
+ }
7649
+ if (this._edgeConnection) {
7650
+ this._edgeConnection.setIdentity(edgeIdentity);
7651
+ }
7652
+ this.networkManager.setPeerInfo({
7653
+ identityKey: edgeIdentity.identityKey,
7654
+ peerKey: edgeIdentity.peerKey
7655
+ });
7656
+ } catch (_) {
7657
+ _usingCtx.e = _;
7658
+ } finally {
7659
+ _usingCtx.d();
7660
+ }
7661
+ }
7322
7662
  };
7323
- _ts_decorate9([
7663
+ _ts_decorate10([
7324
7664
  import_tracing10.trace.span()
7325
7665
  ], ServiceContext.prototype, "_open", null);
7326
- _ts_decorate9([
7666
+ _ts_decorate10([
7327
7667
  import_tracing10.trace.span()
7328
7668
  ], ServiceContext.prototype, "_initialize", null);
7329
- ServiceContext = _ts_decorate9([
7669
+ ServiceContext = _ts_decorate10([
7330
7670
  (0, import_util12.safeInstanceof)("dxos.client-services.ServiceContext"),
7331
7671
  import_tracing10.trace.resource()
7332
7672
  ], ServiceContext);
@@ -7364,16 +7704,16 @@ var StorageDriver = import_config2.Runtime.Client.Storage.StorageDriver;
7364
7704
  var createStorageObjects = (config) => {
7365
7705
  const { persistent = false, keyStore, dataStore } = config ?? {};
7366
7706
  if (persistent && dataStore === StorageDriver.RAM) {
7367
- throw new import_protocols15.InvalidConfigError("RAM storage cannot be used in persistent mode.");
7707
+ throw new import_protocols17.InvalidConfigError("RAM storage cannot be used in persistent mode.");
7368
7708
  }
7369
7709
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
7370
- throw new import_protocols15.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
7710
+ throw new import_protocols17.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
7371
7711
  }
7372
7712
  if (persistent && keyStore === StorageDriver.RAM) {
7373
- throw new import_protocols15.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
7713
+ throw new import_protocols17.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
7374
7714
  }
7375
7715
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
7376
- throw new import_protocols15.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
7716
+ throw new import_protocols17.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
7377
7717
  }
7378
7718
  return {
7379
7719
  storage: (0, import_random_access_storage.createStorage)({
@@ -7404,12 +7744,12 @@ var toStorageType = (type) => {
7404
7744
  };
7405
7745
  var createLevel = async (config) => {
7406
7746
  const persistent = isPersistent(config);
7407
- const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys16.PublicKey.random().toHex()}`;
7747
+ const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys17.PublicKey.random().toHex()}`;
7408
7748
  const level = (0, import_kv_store.createLevel)(storagePath);
7409
7749
  await level.open();
7410
7750
  return level;
7411
7751
  };
7412
- var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
7752
+ var __dxlog_file27 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
7413
7753
  var encodeProfileArchive = (profile) => import_automerge_repo.cbor.encode(profile);
7414
7754
  var decodeProfileArchive = (data) => import_automerge_repo.cbor.decode(data);
7415
7755
  var exportProfileData = async ({ storage, level }) => {
@@ -7422,10 +7762,10 @@ var exportProfileData = async ({ storage, level }) => {
7422
7762
  {
7423
7763
  const directory = await storage.createDirectory();
7424
7764
  const files = await directory.list();
7425
- import_log23.log.info("begin exporting files", {
7765
+ import_log24.log.info("begin exporting files", {
7426
7766
  count: files.length
7427
7767
  }, {
7428
- F: __dxlog_file26,
7768
+ F: __dxlog_file27,
7429
7769
  L: 30,
7430
7770
  S: void 0,
7431
7771
  C: (f, a) => f(...a)
@@ -7435,23 +7775,23 @@ var exportProfileData = async ({ storage, level }) => {
7435
7775
  const { size } = await file.stat();
7436
7776
  const data = await file.read(0, size);
7437
7777
  archive.storage.push({
7438
- type: import_protocols16.ProfileArchiveEntryType.FILE,
7778
+ type: import_protocols18.ProfileArchiveEntryType.FILE,
7439
7779
  key: filename,
7440
7780
  value: data
7441
7781
  });
7442
7782
  }
7443
- import_log23.log.info("done exporting files", {
7783
+ import_log24.log.info("done exporting files", {
7444
7784
  count: files.length
7445
7785
  }, {
7446
- F: __dxlog_file26,
7786
+ F: __dxlog_file27,
7447
7787
  L: 41,
7448
7788
  S: void 0,
7449
7789
  C: (f, a) => f(...a)
7450
7790
  });
7451
7791
  }
7452
7792
  {
7453
- import_log23.log.info("begin exporting kv pairs", void 0, {
7454
- F: __dxlog_file26,
7793
+ import_log24.log.info("begin exporting kv pairs", void 0, {
7794
+ F: __dxlog_file27,
7455
7795
  L: 45,
7456
7796
  S: void 0,
7457
7797
  C: (f, a) => f(...a)
@@ -7463,16 +7803,16 @@ var exportProfileData = async ({ storage, level }) => {
7463
7803
  let count = 0;
7464
7804
  for await (const [key, value] of iter) {
7465
7805
  archive.storage.push({
7466
- type: import_protocols16.ProfileArchiveEntryType.KEY_VALUE,
7806
+ type: import_protocols18.ProfileArchiveEntryType.KEY_VALUE,
7467
7807
  key,
7468
7808
  value
7469
7809
  });
7470
7810
  count++;
7471
7811
  }
7472
- import_log23.log.info("done exporting kv pairs", {
7812
+ import_log24.log.info("done exporting kv pairs", {
7473
7813
  count
7474
7814
  }, {
7475
- F: __dxlog_file26,
7815
+ F: __dxlog_file27,
7476
7816
  L: 56,
7477
7817
  S: void 0,
7478
7818
  C: (f, a) => f(...a)
@@ -7485,10 +7825,10 @@ var importProfileData = async ({ storage, level }, archive) => {
7485
7825
  let count = 0;
7486
7826
  for (const entry2 of archive.storage) {
7487
7827
  switch (entry2.type) {
7488
- case import_protocols16.ProfileArchiveEntryType.FILE: {
7828
+ case import_protocols18.ProfileArchiveEntryType.FILE: {
7489
7829
  const directory = await storage.createDirectory();
7490
- (0, import_invariant21.invariant)(typeof entry2.key === "string", "Invalid key type", {
7491
- F: __dxlog_file26,
7830
+ (0, import_invariant22.invariant)(typeof entry2.key === "string", "Invalid key type", {
7831
+ F: __dxlog_file27,
7492
7832
  L: 79,
7493
7833
  S: void 0,
7494
7834
  A: [
@@ -7497,8 +7837,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7497
7837
  ]
7498
7838
  });
7499
7839
  const file = await directory.getOrCreateFile(entry2.key);
7500
- (0, import_invariant21.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
7501
- F: __dxlog_file26,
7840
+ (0, import_invariant22.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
7841
+ F: __dxlog_file27,
7502
7842
  L: 81,
7503
7843
  S: void 0,
7504
7844
  A: [
@@ -7510,9 +7850,9 @@ var importProfileData = async ({ storage, level }, archive) => {
7510
7850
  await file.close();
7511
7851
  break;
7512
7852
  }
7513
- case import_protocols16.ProfileArchiveEntryType.KEY_VALUE: {
7514
- (0, import_invariant21.invariant)(entry2.key instanceof Uint8Array, "Invalid key type", {
7515
- F: __dxlog_file26,
7853
+ case import_protocols18.ProfileArchiveEntryType.KEY_VALUE: {
7854
+ (0, import_invariant22.invariant)(entry2.key instanceof Uint8Array, "Invalid key type", {
7855
+ F: __dxlog_file27,
7516
7856
  L: 87,
7517
7857
  S: void 0,
7518
7858
  A: [
@@ -7520,8 +7860,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7520
7860
  "'Invalid key type'"
7521
7861
  ]
7522
7862
  });
7523
- (0, import_invariant21.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
7524
- F: __dxlog_file26,
7863
+ (0, import_invariant22.invariant)(entry2.value instanceof Uint8Array, "Invalid value type", {
7864
+ F: __dxlog_file27,
7525
7865
  L: 88,
7526
7866
  S: void 0,
7527
7867
  A: [
@@ -7541,27 +7881,27 @@ var importProfileData = async ({ storage, level }, archive) => {
7541
7881
  if (++count % 1e3 === 0) {
7542
7882
  await batch.write();
7543
7883
  batch = level.batch();
7544
- import_log23.log.info("importing", {
7884
+ import_log24.log.info("importing", {
7545
7885
  count,
7546
7886
  total: archive.storage.length,
7547
7887
  progress: `${(count / archive.storage.length * 100).toFixed()}%`
7548
7888
  }, {
7549
- F: __dxlog_file26,
7889
+ F: __dxlog_file27,
7550
7890
  L: 101,
7551
7891
  S: void 0,
7552
7892
  C: (f, a) => f(...a)
7553
7893
  });
7554
7894
  }
7555
7895
  }
7556
- import_log23.log.info("committing changes..", void 0, {
7557
- F: __dxlog_file26,
7896
+ import_log24.log.info("committing changes..", void 0, {
7897
+ F: __dxlog_file27,
7558
7898
  L: 109,
7559
7899
  S: void 0,
7560
7900
  C: (f, a) => f(...a)
7561
7901
  });
7562
7902
  await batch.write();
7563
7903
  };
7564
- var __dxlog_file27 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
7904
+ var __dxlog_file28 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
7565
7905
  var DevicesServiceImpl = class {
7566
7906
  constructor(_identityManager) {
7567
7907
  this._identityManager = _identityManager;
@@ -7570,7 +7910,7 @@ var DevicesServiceImpl = class {
7570
7910
  return this._identityManager.updateDeviceProfile(profile);
7571
7911
  }
7572
7912
  queryDevices() {
7573
- return new import_codec_protobuf12.Stream(({ next }) => {
7913
+ return new import_codec_protobuf13.Stream(({ next }) => {
7574
7914
  const update = () => {
7575
7915
  const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
7576
7916
  if (!deviceKeys) {
@@ -7578,8 +7918,8 @@ var DevicesServiceImpl = class {
7578
7918
  devices: []
7579
7919
  });
7580
7920
  } else {
7581
- (0, import_invariant23.invariant)(this._identityManager.identity?.presence, "presence not present", {
7582
- F: __dxlog_file27,
7921
+ (0, import_invariant24.invariant)(this._identityManager.identity?.presence, "presence not present", {
7922
+ F: __dxlog_file28,
7583
7923
  L: 32,
7584
7924
  S: this,
7585
7925
  A: [
@@ -7594,9 +7934,9 @@ var DevicesServiceImpl = class {
7594
7934
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
7595
7935
  return {
7596
7936
  deviceKey: key,
7597
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services21.DeviceKind.CURRENT : import_services21.DeviceKind.TRUSTED,
7937
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services23.DeviceKind.CURRENT : import_services23.DeviceKind.TRUSTED,
7598
7938
  profile,
7599
- presence: isMe ? import_services21.Device.PresenceState.ONLINE : peerState ? import_services21.Device.PresenceState.ONLINE : import_services21.Device.PresenceState.OFFLINE
7939
+ presence: isMe ? import_services23.Device.PresenceState.ONLINE : peerState ? import_services23.Device.PresenceState.ONLINE : import_services23.Device.PresenceState.OFFLINE
7600
7940
  };
7601
7941
  })
7602
7942
  });
@@ -7620,7 +7960,7 @@ var DevicesServiceImpl = class {
7620
7960
  presenceSubscribed = true;
7621
7961
  }
7622
7962
  };
7623
- const subscriptions = new import_async23.EventSubscriptions();
7963
+ const subscriptions = new import_async24.EventSubscriptions();
7624
7964
  if (this._identityManager.identity) {
7625
7965
  subscribeIdentity();
7626
7966
  subscribePresence();
@@ -7676,7 +8016,7 @@ var ContactsServiceImpl = class {
7676
8016
  });
7677
8017
  }
7678
8018
  return acc;
7679
- }, new import_util15.ComplexMap(import_keys18.PublicKey.hash));
8019
+ }, new import_util15.ComplexMap(import_keys19.PublicKey.hash));
7680
8020
  return {
7681
8021
  contacts: [
7682
8022
  ...contacts.values()
@@ -7684,16 +8024,16 @@ var ContactsServiceImpl = class {
7684
8024
  };
7685
8025
  }
7686
8026
  queryContacts() {
7687
- const subscribedSpaceKeySet = new import_util15.ComplexSet(import_keys18.PublicKey.hash);
7688
- return new import_codec_protobuf13.Stream(({ next, ctx }) => {
7689
- const pushUpdateTask = new import_async24.UpdateScheduler(ctx, async () => {
8027
+ const subscribedSpaceKeySet = new import_util15.ComplexSet(import_keys19.PublicKey.hash);
8028
+ return new import_codec_protobuf14.Stream(({ next, ctx }) => {
8029
+ const pushUpdateTask = new import_async25.UpdateScheduler(ctx, async () => {
7690
8030
  const contacts = await this.getContacts();
7691
8031
  next(contacts);
7692
8032
  }, {
7693
8033
  maxFrequency: 2
7694
8034
  });
7695
- (0, import_async24.scheduleTask)(ctx, async () => {
7696
- const subscriptions = new import_async24.EventSubscriptions();
8035
+ (0, import_async25.scheduleTask)(ctx, async () => {
8036
+ const subscriptions = new import_async25.EventSubscriptions();
7697
8037
  ctx.onDispose(() => subscriptions.clear());
7698
8038
  const subscribeToSpaceAndUpdate = () => {
7699
8039
  const oldSetSize = subscribedSpaceKeySet.size;
@@ -7716,19 +8056,19 @@ var ContactsServiceImpl = class {
7716
8056
  };
7717
8057
  var LoggingServiceImpl = class {
7718
8058
  constructor() {
7719
- this._logs = new import_async25.Event();
8059
+ this._logs = new import_async26.Event();
7720
8060
  this._started = Date.now();
7721
- this._sessionId = import_keys19.PublicKey.random().toHex();
8061
+ this._sessionId = import_keys20.PublicKey.random().toHex();
7722
8062
  this._logProcessor = (_config, entry2) => {
7723
8063
  this._logs.emit(entry2);
7724
8064
  };
7725
8065
  }
7726
8066
  async open() {
7727
- import_log25.log.runtimeConfig.processors.push(this._logProcessor);
8067
+ import_log26.log.runtimeConfig.processors.push(this._logProcessor);
7728
8068
  }
7729
8069
  async close() {
7730
- const index = import_log25.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
7731
- import_log25.log.runtimeConfig.processors.splice(index, 1);
8070
+ const index = import_log26.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
8071
+ import_log26.log.runtimeConfig.processors.splice(index, 1);
7732
8072
  }
7733
8073
  async controlMetrics({ reset, record }) {
7734
8074
  if (reset) {
@@ -7754,7 +8094,7 @@ var LoggingServiceImpl = class {
7754
8094
  stats: (0, import_util16.numericalValues)(events, "duration")
7755
8095
  };
7756
8096
  };
7757
- return new import_codec_protobuf14.Stream(({ next }) => {
8097
+ return new import_codec_protobuf15.Stream(({ next }) => {
7758
8098
  const update = () => {
7759
8099
  const metrics2 = {
7760
8100
  timestamp: /* @__PURE__ */ new Date(),
@@ -7776,7 +8116,7 @@ var LoggingServiceImpl = class {
7776
8116
  });
7777
8117
  }
7778
8118
  queryLogs(request) {
7779
- return new import_codec_protobuf14.Stream(({ ctx, next }) => {
8119
+ return new import_codec_protobuf15.Stream(({ ctx, next }) => {
7780
8120
  const handler = (entry2) => {
7781
8121
  if (LOG_PROCESSING > 0) {
7782
8122
  return;
@@ -7789,7 +8129,7 @@ var LoggingServiceImpl = class {
7789
8129
  }
7790
8130
  const record = {
7791
8131
  ...entry2,
7792
- context: (0, import_util16.jsonify)((0, import_log25.getContextFromEntry)(entry2)),
8132
+ context: (0, import_util16.jsonify)((0, import_log26.getContextFromEntry)(entry2)),
7793
8133
  timestamp: /* @__PURE__ */ new Date(),
7794
8134
  meta: {
7795
8135
  // TODO(dmaretskyi): Fix proto.
@@ -7815,16 +8155,16 @@ var LoggingServiceImpl = class {
7815
8155
  };
7816
8156
  var matchFilter = (filter, level, path2, options) => {
7817
8157
  switch (options) {
7818
- case import_services22.QueryLogsRequest.MatchingOptions.INCLUSIVE:
8158
+ case import_services24.QueryLogsRequest.MatchingOptions.INCLUSIVE:
7819
8159
  return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
7820
- case import_services22.QueryLogsRequest.MatchingOptions.EXPLICIT:
8160
+ case import_services24.QueryLogsRequest.MatchingOptions.EXPLICIT:
7821
8161
  return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
7822
8162
  }
7823
8163
  };
7824
8164
  var shouldLog = (entry2, request) => {
7825
- const options = request.options ?? import_services22.QueryLogsRequest.MatchingOptions.INCLUSIVE;
8165
+ const options = request.options ?? import_services24.QueryLogsRequest.MatchingOptions.INCLUSIVE;
7826
8166
  if (request.filters === void 0) {
7827
- return options === import_services22.QueryLogsRequest.MatchingOptions.INCLUSIVE;
8167
+ return options === import_services24.QueryLogsRequest.MatchingOptions.INCLUSIVE;
7828
8168
  } else {
7829
8169
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
7830
8170
  }
@@ -7836,7 +8176,7 @@ var NetworkServiceImpl = class {
7836
8176
  this.signalManager = signalManager;
7837
8177
  }
7838
8178
  queryStatus() {
7839
- return new import_codec_protobuf15.Stream(({ next }) => {
8179
+ return new import_codec_protobuf16.Stream(({ next }) => {
7840
8180
  const update = () => {
7841
8181
  next({
7842
8182
  swarm: this.networkManager.connectionState,
@@ -7880,8 +8220,8 @@ var SystemServiceImpl = class {
7880
8220
  return {
7881
8221
  timestamp: /* @__PURE__ */ new Date(),
7882
8222
  diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util17.jsonKeyReplacer)({
7883
- truncate: keys === import_services23.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
7884
- humanize: keys === import_services23.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
8223
+ truncate: keys === import_services25.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
8224
+ humanize: keys === import_services25.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
7885
8225
  })))
7886
8226
  };
7887
8227
  }
@@ -7893,7 +8233,7 @@ var SystemServiceImpl = class {
7893
8233
  }
7894
8234
  // TODO(burdon): Standardize interval option in stream request?
7895
8235
  queryStatus({ interval = 3e3 } = {}) {
7896
- return new import_codec_protobuf16.Stream(({ next }) => {
8236
+ return new import_codec_protobuf17.Stream(({ next }) => {
7897
8237
  const update = () => {
7898
8238
  next({
7899
8239
  status: this._getCurrentStatus()
@@ -7912,13 +8252,13 @@ var SystemServiceImpl = class {
7912
8252
  await this._onReset();
7913
8253
  }
7914
8254
  };
7915
- function _ts_decorate10(decorators, target, key, desc) {
8255
+ function _ts_decorate11(decorators, target, key, desc) {
7916
8256
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7917
8257
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7918
8258
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
7919
8259
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7920
8260
  }
7921
- var __dxlog_file28 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
8261
+ var __dxlog_file29 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
7922
8262
  var ClientServicesHost = class {
7923
8263
  constructor({
7924
8264
  config,
@@ -7932,7 +8272,7 @@ var ClientServicesHost = class {
7932
8272
  runtimeParams
7933
8273
  } = {}) {
7934
8274
  this._tracingService = import_tracing11.TRACE_PROCESSOR.createTraceSender();
7935
- this._statusUpdate = new import_async22.Event();
8275
+ this._statusUpdate = new import_async23.Event();
7936
8276
  this._edgeConnection = void 0;
7937
8277
  this._edgeHttpClient = void 0;
7938
8278
  this._opening = false;
@@ -7956,9 +8296,9 @@ var ClientServicesHost = class {
7956
8296
  lockKey,
7957
8297
  onAcquire: () => {
7958
8298
  if (!this._opening) {
7959
- void this.open(new import_context16.Context(void 0, {
7960
- F: __dxlog_file28,
7961
- L: 133
8299
+ void this.open(new import_context17.Context(void 0, {
8300
+ F: __dxlog_file29,
8301
+ L: 134
7962
8302
  }));
7963
8303
  }
7964
8304
  },
@@ -7968,14 +8308,14 @@ var ClientServicesHost = class {
7968
8308
  this._systemService = new SystemServiceImpl({
7969
8309
  config: () => this._config,
7970
8310
  statusUpdate: this._statusUpdate,
7971
- getCurrentStatus: () => this.isOpen ? import_services20.SystemStatus.ACTIVE : import_services20.SystemStatus.INACTIVE,
8311
+ getCurrentStatus: () => this.isOpen ? import_services22.SystemStatus.ACTIVE : import_services22.SystemStatus.INACTIVE,
7972
8312
  getDiagnostics: () => {
7973
8313
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
7974
8314
  },
7975
8315
  onUpdateStatus: async (status) => {
7976
- if (!this.isOpen && status === import_services20.SystemStatus.ACTIVE) {
8316
+ if (!this.isOpen && status === import_services22.SystemStatus.ACTIVE) {
7977
8317
  await this._resourceLock?.acquire();
7978
- } else if (this.isOpen && status === import_services20.SystemStatus.INACTIVE) {
8318
+ } else if (this.isOpen && status === import_services22.SystemStatus.INACTIVE) {
7979
8319
  await this._resourceLock?.release();
7980
8320
  }
7981
8321
  },
@@ -8014,25 +8354,25 @@ var ClientServicesHost = class {
8014
8354
  * Can only be called once.
8015
8355
  */
8016
8356
  initialize({ config, ...options }) {
8017
- (0, import_invariant22.invariant)(!this._open, "service host is open", {
8018
- F: __dxlog_file28,
8019
- L: 199,
8357
+ (0, import_invariant23.invariant)(!this._open, "service host is open", {
8358
+ F: __dxlog_file29,
8359
+ L: 200,
8020
8360
  S: this,
8021
8361
  A: [
8022
8362
  "!this._open",
8023
8363
  "'service host is open'"
8024
8364
  ]
8025
8365
  });
8026
- (0, import_log24.log)("initializing...", void 0, {
8027
- F: __dxlog_file28,
8028
- L: 200,
8366
+ (0, import_log25.log)("initializing...", void 0, {
8367
+ F: __dxlog_file29,
8368
+ L: 201,
8029
8369
  S: this,
8030
8370
  C: (f, a) => f(...a)
8031
8371
  });
8032
8372
  if (config) {
8033
- (0, import_invariant22.invariant)(!this._config, "config already set", {
8034
- F: __dxlog_file28,
8035
- L: 203,
8373
+ (0, import_invariant23.invariant)(!this._config, "config already set", {
8374
+ F: __dxlog_file29,
8375
+ L: 204,
8036
8376
  S: this,
8037
8377
  A: [
8038
8378
  "!this._config",
@@ -8045,9 +8385,9 @@ var ClientServicesHost = class {
8045
8385
  }
8046
8386
  }
8047
8387
  if (!options.signalManager) {
8048
- import_log24.log.warn("running signaling without telemetry metadata.", void 0, {
8049
- F: __dxlog_file28,
8050
- L: 211,
8388
+ import_log25.log.warn("running signaling without telemetry metadata.", void 0, {
8389
+ F: __dxlog_file29,
8390
+ L: 212,
8051
8391
  S: this,
8052
8392
  C: (f, a) => f(...a)
8053
8393
  });
@@ -8065,9 +8405,9 @@ var ClientServicesHost = class {
8065
8405
  edgeConnection: this._edgeConnection
8066
8406
  }) : new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
8067
8407
  this._signalManager = signalManager;
8068
- (0, import_invariant22.invariant)(!this._networkManager, "network manager already set", {
8069
- F: __dxlog_file28,
8070
- L: 233,
8408
+ (0, import_invariant23.invariant)(!this._networkManager, "network manager already set", {
8409
+ F: __dxlog_file29,
8410
+ L: 234,
8071
8411
  S: this,
8072
8412
  A: [
8073
8413
  "!this._networkManager",
@@ -8083,9 +8423,9 @@ var ClientServicesHost = class {
8083
8423
  peerKey: this._edgeConnection.peerKey
8084
8424
  } : void 0
8085
8425
  });
8086
- (0, import_log24.log)("initialized", void 0, {
8087
- F: __dxlog_file28,
8088
- L: 246,
8426
+ (0, import_log25.log)("initialized", void 0, {
8427
+ F: __dxlog_file29,
8428
+ L: 247,
8089
8429
  S: this,
8090
8430
  C: (f, a) => f(...a)
8091
8431
  });
@@ -8094,45 +8434,45 @@ var ClientServicesHost = class {
8094
8434
  if (this._open) {
8095
8435
  return;
8096
8436
  }
8097
- const traceId = import_keys17.PublicKey.random().toHex();
8098
- import_log24.log.trace("dxos.client-services.host.open", import_protocols17.trace.begin({
8437
+ const traceId = import_keys18.PublicKey.random().toHex();
8438
+ import_log25.log.trace("dxos.client-services.host.open", import_protocols19.trace.begin({
8099
8439
  id: traceId
8100
8440
  }), {
8101
- F: __dxlog_file28,
8102
- L: 257,
8441
+ F: __dxlog_file29,
8442
+ L: 258,
8103
8443
  S: this,
8104
8444
  C: (f, a) => f(...a)
8105
8445
  });
8106
- (0, import_invariant22.invariant)(this._config, "config not set", {
8107
- F: __dxlog_file28,
8108
- L: 259,
8446
+ (0, import_invariant23.invariant)(this._config, "config not set", {
8447
+ F: __dxlog_file29,
8448
+ L: 260,
8109
8449
  S: this,
8110
8450
  A: [
8111
8451
  "this._config",
8112
8452
  "'config not set'"
8113
8453
  ]
8114
8454
  });
8115
- (0, import_invariant22.invariant)(this._storage, "storage not set", {
8116
- F: __dxlog_file28,
8117
- L: 260,
8455
+ (0, import_invariant23.invariant)(this._storage, "storage not set", {
8456
+ F: __dxlog_file29,
8457
+ L: 261,
8118
8458
  S: this,
8119
8459
  A: [
8120
8460
  "this._storage",
8121
8461
  "'storage not set'"
8122
8462
  ]
8123
8463
  });
8124
- (0, import_invariant22.invariant)(this._signalManager, "signal manager not set", {
8125
- F: __dxlog_file28,
8126
- L: 261,
8464
+ (0, import_invariant23.invariant)(this._signalManager, "signal manager not set", {
8465
+ F: __dxlog_file29,
8466
+ L: 262,
8127
8467
  S: this,
8128
8468
  A: [
8129
8469
  "this._signalManager",
8130
8470
  "'signal manager not set'"
8131
8471
  ]
8132
8472
  });
8133
- (0, import_invariant22.invariant)(this._networkManager, "network manager not set", {
8134
- F: __dxlog_file28,
8135
- L: 262,
8473
+ (0, import_invariant23.invariant)(this._networkManager, "network manager not set", {
8474
+ F: __dxlog_file29,
8475
+ L: 263,
8136
8476
  S: this,
8137
8477
  A: [
8138
8478
  "this._networkManager",
@@ -8140,11 +8480,11 @@ var ClientServicesHost = class {
8140
8480
  ]
8141
8481
  });
8142
8482
  this._opening = true;
8143
- (0, import_log24.log)("opening...", {
8483
+ (0, import_log25.log)("opening...", {
8144
8484
  lockKey: this._resourceLock?.lockKey
8145
8485
  }, {
8146
- F: __dxlog_file28,
8147
- L: 265,
8486
+ F: __dxlog_file29,
8487
+ L: 266,
8148
8488
  S: this,
8149
8489
  C: (f, a) => f(...a)
8150
8490
  });
@@ -8159,6 +8499,10 @@ var ClientServicesHost = class {
8159
8499
  await this._serviceContext.initialized.wait();
8160
8500
  return this._serviceContext.dataSpaceManager;
8161
8501
  };
8502
+ const agentManagerProvider = async () => {
8503
+ await this._serviceContext.initialized.wait();
8504
+ return this._serviceContext.edgeAgentManager;
8505
+ };
8162
8506
  const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
8163
8507
  this._serviceRegistry.setServices({
8164
8508
  SystemService: this._systemService,
@@ -8177,7 +8521,8 @@ var ClientServicesHost = class {
8177
8521
  events: new DevtoolsHostEvents(),
8178
8522
  config: this._config,
8179
8523
  context: this._serviceContext
8180
- })
8524
+ }),
8525
+ EdgeAgentService: new EdgeAgentServiceImpl(agentManagerProvider)
8181
8526
  });
8182
8527
  await this._serviceContext.open(ctx);
8183
8528
  await identityService.open();
@@ -8196,19 +8541,19 @@ var ClientServicesHost = class {
8196
8541
  this._open = true;
8197
8542
  this._statusUpdate.emit();
8198
8543
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
8199
- (0, import_log24.log)("opened", {
8544
+ (0, import_log25.log)("opened", {
8200
8545
  deviceKey
8201
8546
  }, {
8202
- F: __dxlog_file28,
8203
- L: 354,
8547
+ F: __dxlog_file29,
8548
+ L: 362,
8204
8549
  S: this,
8205
8550
  C: (f, a) => f(...a)
8206
8551
  });
8207
- import_log24.log.trace("dxos.client-services.host.open", import_protocols17.trace.end({
8552
+ import_log25.log.trace("dxos.client-services.host.open", import_protocols19.trace.end({
8208
8553
  id: traceId
8209
8554
  }), {
8210
- F: __dxlog_file28,
8211
- L: 355,
8555
+ F: __dxlog_file29,
8556
+ L: 363,
8212
8557
  S: this,
8213
8558
  C: (f, a) => f(...a)
8214
8559
  });
@@ -8218,11 +8563,11 @@ var ClientServicesHost = class {
8218
8563
  return;
8219
8564
  }
8220
8565
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
8221
- (0, import_log24.log)("closing...", {
8566
+ (0, import_log25.log)("closing...", {
8222
8567
  deviceKey
8223
8568
  }, {
8224
- F: __dxlog_file28,
8225
- L: 366,
8569
+ F: __dxlog_file29,
8570
+ L: 374,
8226
8571
  S: this,
8227
8572
  C: (f, a) => f(...a)
8228
8573
  });
@@ -8236,44 +8581,44 @@ var ClientServicesHost = class {
8236
8581
  await this._level?.close();
8237
8582
  this._open = false;
8238
8583
  this._statusUpdate.emit();
8239
- (0, import_log24.log)("closed", {
8584
+ (0, import_log25.log)("closed", {
8240
8585
  deviceKey
8241
8586
  }, {
8242
- F: __dxlog_file28,
8243
- L: 375,
8587
+ F: __dxlog_file29,
8588
+ L: 383,
8244
8589
  S: this,
8245
8590
  C: (f, a) => f(...a)
8246
8591
  });
8247
8592
  }
8248
8593
  async reset() {
8249
- const traceId = import_keys17.PublicKey.random().toHex();
8250
- import_log24.log.trace("dxos.sdk.client-services-host.reset", import_protocols17.trace.begin({
8594
+ const traceId = import_keys18.PublicKey.random().toHex();
8595
+ import_log25.log.trace("dxos.sdk.client-services-host.reset", import_protocols19.trace.begin({
8251
8596
  id: traceId
8252
8597
  }), {
8253
- F: __dxlog_file28,
8254
- L: 380,
8598
+ F: __dxlog_file29,
8599
+ L: 388,
8255
8600
  S: this,
8256
8601
  C: (f, a) => f(...a)
8257
8602
  });
8258
- import_log24.log.info("resetting...", void 0, {
8259
- F: __dxlog_file28,
8260
- L: 382,
8603
+ import_log25.log.info("resetting...", void 0, {
8604
+ F: __dxlog_file29,
8605
+ L: 390,
8261
8606
  S: this,
8262
8607
  C: (f, a) => f(...a)
8263
8608
  });
8264
8609
  await this._serviceContext?.close();
8265
8610
  await this._storage.reset();
8266
- import_log24.log.info("reset", void 0, {
8267
- F: __dxlog_file28,
8268
- L: 385,
8611
+ import_log25.log.info("reset", void 0, {
8612
+ F: __dxlog_file29,
8613
+ L: 393,
8269
8614
  S: this,
8270
8615
  C: (f, a) => f(...a)
8271
8616
  });
8272
- import_log24.log.trace("dxos.sdk.client-services-host.reset", import_protocols17.trace.end({
8617
+ import_log25.log.trace("dxos.sdk.client-services-host.reset", import_protocols19.trace.end({
8273
8618
  id: traceId
8274
8619
  }), {
8275
- F: __dxlog_file28,
8276
- L: 386,
8620
+ F: __dxlog_file29,
8621
+ L: 394,
8277
8622
  S: this,
8278
8623
  C: (f, a) => f(...a)
8279
8624
  });
@@ -8285,21 +8630,21 @@ var ClientServicesHost = class {
8285
8630
  return identity;
8286
8631
  }
8287
8632
  };
8288
- _ts_decorate10([
8633
+ _ts_decorate11([
8289
8634
  import_tracing11.trace.info()
8290
8635
  ], ClientServicesHost.prototype, "_opening", void 0);
8291
- _ts_decorate10([
8636
+ _ts_decorate11([
8292
8637
  import_tracing11.trace.info()
8293
8638
  ], ClientServicesHost.prototype, "_open", void 0);
8294
- _ts_decorate10([
8295
- import_async22.synchronized,
8639
+ _ts_decorate11([
8640
+ import_async23.synchronized,
8296
8641
  import_tracing11.trace.span()
8297
8642
  ], ClientServicesHost.prototype, "open", null);
8298
- _ts_decorate10([
8299
- import_async22.synchronized,
8643
+ _ts_decorate11([
8644
+ import_async23.synchronized,
8300
8645
  import_tracing11.trace.span()
8301
8646
  ], ClientServicesHost.prototype, "close", null);
8302
- ClientServicesHost = _ts_decorate10([
8647
+ ClientServicesHost = _ts_decorate11([
8303
8648
  import_tracing11.trace.resource()
8304
8649
  ], ClientServicesHost);
8305
8650
  // Annotate the CommonJS export names for ESM import in node:
@@ -8312,6 +8657,8 @@ ClientServicesHost = _ts_decorate10([
8312
8657
  DevtoolsHostEvents,
8313
8658
  DevtoolsServiceImpl,
8314
8659
  DiagnosticsCollector,
8660
+ EdgeAgentManager,
8661
+ EdgeAgentServiceImpl,
8315
8662
  EdgeFeedReplicator,
8316
8663
  Identity,
8317
8664
  IdentityManager,
@@ -8346,4 +8693,4 @@ ClientServicesHost = _ts_decorate10([
8346
8693
  subscribeToSpaces,
8347
8694
  subscribeToSwarmInfo
8348
8695
  });
8349
- //# sourceMappingURL=chunk-MA5EWTRH.cjs.map
8696
+ //# sourceMappingURL=chunk-DJIOUOAF.cjs.map