@dxos/client-services 0.6.5 → 0.6.6-staging.23d123d

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 (52) hide show
  1. package/dist/lib/browser/{chunk-GIAH3RXX.mjs → chunk-ZMCIQNPA.mjs} +907 -442
  2. package/dist/lib/browser/chunk-ZMCIQNPA.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +28 -13
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +21 -4
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-NDXK2NIM.cjs → chunk-Z3CQD2CB.cjs} +1065 -607
  9. package/dist/lib/node/chunk-Z3CQD2CB.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +77 -62
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +27 -8
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  16. package/dist/types/src/packlets/services/service-context.d.ts +6 -1
  17. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  18. package/dist/types/src/packlets/services/service-host.d.ts +1 -0
  19. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  20. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +29 -12
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/data-space.d.ts +7 -0
  23. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +35 -0
  25. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -0
  26. package/dist/types/src/packlets/spaces/index.d.ts +1 -0
  27. package/dist/types/src/packlets/spaces/index.d.ts.map +1 -1
  28. package/dist/types/src/packlets/testing/invitation-utils.d.ts +2 -0
  29. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  30. package/dist/types/src/packlets/testing/test-builder.d.ts +3 -1
  31. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  32. package/dist/types/src/packlets/worker/worker-runtime.d.ts +8 -3
  33. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  34. package/dist/types/src/version.d.ts +1 -1
  35. package/dist/types/src/version.d.ts.map +1 -1
  36. package/package.json +38 -36
  37. package/src/packlets/invitations/invitations-handler.test.ts +1 -0
  38. package/src/packlets/invitations/invitations-handler.ts +12 -0
  39. package/src/packlets/invitations/space-invitation-protocol.test.ts +23 -1
  40. package/src/packlets/services/service-context.ts +44 -12
  41. package/src/packlets/services/service-host.ts +26 -4
  42. package/src/packlets/spaces/data-space-manager.test.ts +6 -0
  43. package/src/packlets/spaces/data-space-manager.ts +80 -36
  44. package/src/packlets/spaces/data-space.ts +36 -2
  45. package/src/packlets/spaces/edge-feed-replicator.ts +249 -0
  46. package/src/packlets/spaces/index.ts +1 -0
  47. package/src/packlets/testing/invitation-utils.ts +2 -2
  48. package/src/packlets/testing/test-builder.ts +20 -12
  49. package/src/packlets/worker/worker-runtime.ts +32 -10
  50. package/src/version.ts +1 -5
  51. package/dist/lib/browser/chunk-GIAH3RXX.mjs.map +0 -7
  52. package/dist/lib/node/chunk-NDXK2NIM.cjs.map +0 -7
@@ -359,7 +359,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
359
359
  import { TRACE_PROCESSOR } from "@dxos/tracing";
360
360
 
361
361
  // packages/sdk/client-services/src/version.ts
362
- var DXOS_VERSION = "0.6.5";
362
+ var DXOS_VERSION = "0.6.6-staging.23d123d";
363
363
 
364
364
  // packages/sdk/client-services/src/packlets/services/platform.ts
365
365
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -2772,6 +2772,14 @@ var InvitationsHandler = class {
2772
2772
  ""
2773
2773
  ]
2774
2774
  });
2775
+ const timeoutInactive = () => {
2776
+ if (guardedState.mutex.isLocked()) {
2777
+ scheduleTask3(ctx, timeoutInactive, timeout);
2778
+ } else {
2779
+ guardedState.set(null, Invitation4.State.TIMEOUT);
2780
+ }
2781
+ };
2782
+ scheduleTask3(ctx, timeoutInactive, timeout);
2775
2783
  await this._joinSwarm(ctx, invitation, InvitationOptions4.Role.GUEST, createExtension);
2776
2784
  guardedState.set(null, Invitation4.State.CONNECTING);
2777
2785
  }
@@ -2865,7 +2873,7 @@ var InvitationsHandler = class {
2865
2873
  oldState: stateToString(invitation.state)
2866
2874
  }, {
2867
2875
  F: __dxlog_file13,
2868
- L: 449,
2876
+ L: 461,
2869
2877
  S: this,
2870
2878
  C: (f, a) => f(...a)
2871
2879
  });
@@ -2876,7 +2884,7 @@ var InvitationsHandler = class {
2876
2884
  oldState: stateToString(invitation.state)
2877
2885
  }, {
2878
2886
  F: __dxlog_file13,
2879
- L: 455,
2887
+ L: 467,
2880
2888
  S: this,
2881
2889
  C: (f, a) => f(...a)
2882
2890
  });
@@ -2895,7 +2903,7 @@ var InvitationsHandler = class {
2895
2903
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2896
2904
  log10("guest waiting for authentication code...", void 0, {
2897
2905
  F: __dxlog_file13,
2898
- L: 480,
2906
+ L: 492,
2899
2907
  S: this,
2900
2908
  C: (f, a) => f(...a)
2901
2909
  });
@@ -2903,7 +2911,7 @@ var InvitationsHandler = class {
2903
2911
  const authCode = await authenticated.wait(options);
2904
2912
  log10("sending authentication request", void 0, {
2905
2913
  F: __dxlog_file13,
2906
- L: 484,
2914
+ L: 496,
2907
2915
  S: this,
2908
2916
  C: (f, a) => f(...a)
2909
2917
  });
@@ -2922,7 +2930,7 @@ var InvitationsHandler = class {
2922
2930
  attempt
2923
2931
  }, {
2924
2932
  F: __dxlog_file13,
2925
- L: 495,
2933
+ L: 507,
2926
2934
  S: this,
2927
2935
  C: (f, a) => f(...a)
2928
2936
  });
@@ -2940,7 +2948,7 @@ var InvitationsHandler = class {
2940
2948
  }
2941
2949
  log10("sending authentication request", void 0, {
2942
2950
  F: __dxlog_file13,
2943
- L: 514,
2951
+ L: 526,
2944
2952
  S: this,
2945
2953
  C: (f, a) => f(...a)
2946
2954
  });
@@ -3896,34 +3904,405 @@ ClientRpcServer = _ts_decorate4([
3896
3904
  trace5.resource()
3897
3905
  ], ClientRpcServer);
3898
3906
 
3907
+ // packages/sdk/client-services/src/packlets/spaces/edge-feed-replicator.ts
3908
+ import { decode as decodeCbor, encode as encodeCbor } from "cbor-x";
3909
+ import { Event as Event4, Mutex as Mutex2, scheduleMicroTask } from "@dxos/async";
3910
+ import { Resource as Resource2 } from "@dxos/context";
3911
+ import { invariant as invariant12 } from "@dxos/invariant";
3912
+ import { PublicKey as PublicKey9 } from "@dxos/keys";
3913
+ import { log as log14 } from "@dxos/log";
3914
+ import { EdgeService } from "@dxos/protocols";
3915
+ import { buf } from "@dxos/protocols/buf";
3916
+ import { MessageSchema as RouterMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
3917
+ import { ComplexMap as ComplexMap2, arrayToBuffer, bufferToArray, defaultMap, rangeFromTo } from "@dxos/util";
3918
+ function _using_ctx() {
3919
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
3920
+ var err = new Error();
3921
+ err.name = "SuppressedError";
3922
+ err.suppressed = suppressed;
3923
+ err.error = error;
3924
+ return err;
3925
+ }, empty = {}, stack = [];
3926
+ function using(isAwait, value) {
3927
+ if (value != null) {
3928
+ if (Object(value) !== value) {
3929
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
3930
+ }
3931
+ if (isAwait) {
3932
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
3933
+ }
3934
+ if (dispose == null) {
3935
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
3936
+ }
3937
+ if (typeof dispose !== "function") {
3938
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
3939
+ }
3940
+ stack.push({
3941
+ v: value,
3942
+ d: dispose,
3943
+ a: isAwait
3944
+ });
3945
+ } else if (isAwait) {
3946
+ stack.push({
3947
+ d: value,
3948
+ a: isAwait
3949
+ });
3950
+ }
3951
+ return value;
3952
+ }
3953
+ return {
3954
+ e: empty,
3955
+ u: using.bind(null, false),
3956
+ a: using.bind(null, true),
3957
+ d: function() {
3958
+ var error = this.e;
3959
+ function next() {
3960
+ while (resource = stack.pop()) {
3961
+ try {
3962
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
3963
+ if (resource.a) {
3964
+ return Promise.resolve(disposalResult).then(next, err);
3965
+ }
3966
+ } catch (e) {
3967
+ return err(e);
3968
+ }
3969
+ }
3970
+ if (error !== empty)
3971
+ throw error;
3972
+ }
3973
+ function err(e) {
3974
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
3975
+ return next();
3976
+ }
3977
+ return next();
3978
+ }
3979
+ };
3980
+ }
3981
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/edge-feed-replicator.ts";
3982
+ var EdgeFeedReplicator = class extends Resource2 {
3983
+ constructor({ messenger, spaceId }) {
3984
+ super();
3985
+ this._feeds = new ComplexMap2(PublicKey9.hash);
3986
+ this._connectionCtx = void 0;
3987
+ this._connected = false;
3988
+ /**
3989
+ * Feed length at service.
3990
+ */
3991
+ this._remoteLength = new ComplexMap2(PublicKey9.hash);
3992
+ /**
3993
+ * Protects against concurrent pushes so that remote length is updated consistently.
3994
+ */
3995
+ this._pushMutex = new ComplexMap2(PublicKey9.hash);
3996
+ this._messenger = messenger;
3997
+ this._spaceId = spaceId;
3998
+ }
3999
+ async _open() {
4000
+ this._ctx.onDispose(this._messenger.addListener(async (message) => {
4001
+ if (!message.serviceId) {
4002
+ return;
4003
+ }
4004
+ const [service, ...rest] = message.serviceId.split(":");
4005
+ if (service !== "hypercore-replicator") {
4006
+ return;
4007
+ }
4008
+ const [spaceId] = rest;
4009
+ if (spaceId !== this._spaceId) {
4010
+ log14("spaceID mismatch", {
4011
+ spaceId,
4012
+ _spaceId: this._spaceId
4013
+ }, {
4014
+ F: __dxlog_file17,
4015
+ L: 62,
4016
+ S: this,
4017
+ C: (f, a) => f(...a)
4018
+ });
4019
+ return;
4020
+ }
4021
+ const payload = decodeCbor(message.payload.value);
4022
+ log14.info("recv", {
4023
+ from: message.source,
4024
+ payload
4025
+ }, {
4026
+ F: __dxlog_file17,
4027
+ L: 67,
4028
+ S: this,
4029
+ C: (f, a) => f(...a)
4030
+ });
4031
+ this._onMessage(payload);
4032
+ }));
4033
+ this._connected = true;
4034
+ this._connectionCtx = this._ctx.derive();
4035
+ for (const feed of this._feeds.values()) {
4036
+ await this._replicateFeed(feed);
4037
+ }
4038
+ }
4039
+ async _close() {
4040
+ this._connected = false;
4041
+ this._connected = false;
4042
+ await this._connectionCtx?.dispose();
4043
+ this._connectionCtx = void 0;
4044
+ this._remoteLength.clear();
4045
+ }
4046
+ async addFeed(feed) {
4047
+ log14.info("addFeed", {
4048
+ key: feed.key
4049
+ }, {
4050
+ F: __dxlog_file17,
4051
+ L: 89,
4052
+ S: this,
4053
+ C: (f, a) => f(...a)
4054
+ });
4055
+ this._feeds.set(feed.key, feed);
4056
+ if (this._connected) {
4057
+ await this._replicateFeed(feed);
4058
+ }
4059
+ }
4060
+ _getPushMutex(key) {
4061
+ return defaultMap(this._pushMutex, key, () => new Mutex2());
4062
+ }
4063
+ async _replicateFeed(feed) {
4064
+ invariant12(this._connectionCtx, void 0, {
4065
+ F: __dxlog_file17,
4066
+ L: 102,
4067
+ S: this,
4068
+ A: [
4069
+ "this._connectionCtx",
4070
+ ""
4071
+ ]
4072
+ });
4073
+ await this._sendMessage({
4074
+ type: "get-metadata",
4075
+ feedKey: feed.key.toHex()
4076
+ });
4077
+ Event4.wrap(feed.core, "append").on(this._connectionCtx, async () => {
4078
+ await this._pushBlocksIfNeeded(feed);
4079
+ });
4080
+ }
4081
+ async _sendMessage(message) {
4082
+ log14.info("sending message", {
4083
+ message
4084
+ }, {
4085
+ F: __dxlog_file17,
4086
+ L: 115,
4087
+ S: this,
4088
+ C: (f, a) => f(...a)
4089
+ });
4090
+ invariant12(message.feedKey, void 0, {
4091
+ F: __dxlog_file17,
4092
+ L: 117,
4093
+ S: this,
4094
+ A: [
4095
+ "message.feedKey",
4096
+ ""
4097
+ ]
4098
+ });
4099
+ const payloadValue = bufferToArray(encodeCbor(message));
4100
+ await this._messenger.send(buf.create(RouterMessageSchema, {
4101
+ source: {
4102
+ identityKey: this._messenger.identityKey.toHex(),
4103
+ peerKey: this._messenger.deviceKey.toHex()
4104
+ },
4105
+ serviceId: `${EdgeService.FEED_REPLICATOR}:${this._spaceId}`,
4106
+ payload: {
4107
+ value: payloadValue
4108
+ }
4109
+ }));
4110
+ }
4111
+ _onMessage(message) {
4112
+ log14.info("received message", {
4113
+ message
4114
+ }, {
4115
+ F: __dxlog_file17,
4116
+ L: 133,
4117
+ S: this,
4118
+ C: (f, a) => f(...a)
4119
+ });
4120
+ scheduleMicroTask(this._ctx, async () => {
4121
+ switch (message.type) {
4122
+ case "metadata": {
4123
+ try {
4124
+ var _usingCtx = _using_ctx();
4125
+ const feedKey = PublicKey9.fromHex(message.feedKey);
4126
+ const feed = this._feeds.get(feedKey);
4127
+ if (!feed) {
4128
+ log14.warn("Feed not found", {
4129
+ feedKey
4130
+ }, {
4131
+ F: __dxlog_file17,
4132
+ L: 141,
4133
+ S: this,
4134
+ C: (f, a) => f(...a)
4135
+ });
4136
+ return;
4137
+ }
4138
+ const _guard = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
4139
+ this._remoteLength.set(feedKey, message.length);
4140
+ if (message.length > feed.length) {
4141
+ await this._sendMessage({
4142
+ type: "request",
4143
+ feedKey: feedKey.toHex(),
4144
+ range: {
4145
+ from: feed.length,
4146
+ to: message.length
4147
+ }
4148
+ });
4149
+ } else if (message.length < feed.length) {
4150
+ await this._pushBlocks(feed, message.length, feed.length);
4151
+ }
4152
+ break;
4153
+ } catch (_) {
4154
+ _usingCtx.e = _;
4155
+ } finally {
4156
+ _usingCtx.d();
4157
+ }
4158
+ }
4159
+ case "data": {
4160
+ const feedKey = PublicKey9.fromHex(message.feedKey);
4161
+ const feed = this._feeds.get(feedKey);
4162
+ if (!feed) {
4163
+ log14.warn("Feed not found", {
4164
+ feedKey
4165
+ }, {
4166
+ F: __dxlog_file17,
4167
+ L: 166,
4168
+ S: this,
4169
+ C: (f, a) => f(...a)
4170
+ });
4171
+ return;
4172
+ }
4173
+ await this._integrateBlocks(feed, message.blocks);
4174
+ break;
4175
+ }
4176
+ default: {
4177
+ log14.warn("Unknown message", {
4178
+ ...message
4179
+ }, {
4180
+ F: __dxlog_file17,
4181
+ L: 175,
4182
+ S: this,
4183
+ C: (f, a) => f(...a)
4184
+ });
4185
+ }
4186
+ }
4187
+ });
4188
+ }
4189
+ async _pushBlocks(feed, from, to) {
4190
+ log14.info("pushing blocks", {
4191
+ feed: feed.key.toHex(),
4192
+ from,
4193
+ to
4194
+ }, {
4195
+ F: __dxlog_file17,
4196
+ L: 182,
4197
+ S: this,
4198
+ C: (f, a) => f(...a)
4199
+ });
4200
+ const blocks = await Promise.all(rangeFromTo(from, to).map(async (index) => {
4201
+ const data = await feed.get(index, {
4202
+ valueEncoding: "binary"
4203
+ });
4204
+ invariant12(data instanceof Uint8Array, void 0, {
4205
+ F: __dxlog_file17,
4206
+ L: 187,
4207
+ S: this,
4208
+ A: [
4209
+ "data instanceof Uint8Array",
4210
+ ""
4211
+ ]
4212
+ });
4213
+ const proof = await feed.proof(index);
4214
+ return {
4215
+ index,
4216
+ data,
4217
+ nodes: proof.nodes,
4218
+ signature: proof.signature
4219
+ };
4220
+ }));
4221
+ await this._sendMessage({
4222
+ type: "data",
4223
+ feedKey: feed.key.toHex(),
4224
+ blocks
4225
+ });
4226
+ this._remoteLength.set(feed.key, to);
4227
+ }
4228
+ async _integrateBlocks(feed, blocks) {
4229
+ log14.info("integrating blocks", {
4230
+ feed: feed.key.toHex(),
4231
+ blocks: blocks.length
4232
+ }, {
4233
+ F: __dxlog_file17,
4234
+ L: 208,
4235
+ S: this,
4236
+ C: (f, a) => f(...a)
4237
+ });
4238
+ for (const block of blocks) {
4239
+ if (feed.has(block.index)) {
4240
+ continue;
4241
+ }
4242
+ const blockBuffer = bufferizeBlock(block);
4243
+ await feed.putBuffer(block.index, blockBuffer.data, {
4244
+ nodes: blockBuffer.nodes,
4245
+ signature: blockBuffer.signature
4246
+ }, null);
4247
+ }
4248
+ }
4249
+ async _pushBlocksIfNeeded(feed) {
4250
+ try {
4251
+ var _usingCtx = _using_ctx();
4252
+ const _guard = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
4253
+ if (!this._remoteLength.has(feed.key)) {
4254
+ return;
4255
+ }
4256
+ const remoteLength = this._remoteLength.get(feed.key);
4257
+ if (remoteLength < feed.length) {
4258
+ await this._pushBlocks(feed, remoteLength, feed.length);
4259
+ }
4260
+ } catch (_) {
4261
+ _usingCtx.e = _;
4262
+ } finally {
4263
+ _usingCtx.d();
4264
+ }
4265
+ }
4266
+ };
4267
+ var bufferizeBlock = (block) => ({
4268
+ index: block.index,
4269
+ data: arrayToBuffer(block.data),
4270
+ nodes: block.nodes.map((node) => ({
4271
+ index: node.index,
4272
+ hash: arrayToBuffer(node.hash),
4273
+ size: node.size
4274
+ })),
4275
+ signature: arrayToBuffer(block.signature)
4276
+ });
4277
+
3899
4278
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3900
- import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
4279
+ import { Event as Event7, Mutex as Mutex3, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
3901
4280
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3902
4281
  import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3903
4282
  import { timed, warnAfterTimeout } from "@dxos/debug";
3904
4283
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3905
4284
  import { SpaceDocVersion as SpaceDocVersion2 } from "@dxos/echo-protocol";
3906
4285
  import { failedInvariant } from "@dxos/invariant";
3907
- import { PublicKey as PublicKey10 } from "@dxos/keys";
3908
- import { log as log16 } from "@dxos/log";
4286
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
4287
+ import { log as log17 } from "@dxos/log";
3909
4288
  import { CancelledError, SystemError } from "@dxos/protocols";
3910
4289
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3911
4290
  import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
3912
4291
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3913
4292
  import { trace as trace6 } from "@dxos/tracing";
3914
- import { ComplexSet as ComplexSet5 } from "@dxos/util";
4293
+ import { CallbackCollection, ComplexSet as ComplexSet5 } from "@dxos/util";
3915
4294
 
3916
4295
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
3917
- import { Event as Event4 } from "@dxos/async";
3918
- import { Resource as Resource2 } from "@dxos/context";
4296
+ import { Event as Event5 } from "@dxos/async";
4297
+ import { Resource as Resource3 } from "@dxos/context";
3919
4298
  import { checkCredentialType } from "@dxos/credentials";
3920
- var AutomergeSpaceState = class extends Resource2 {
4299
+ var AutomergeSpaceState = class extends Resource3 {
3921
4300
  constructor(_onNewRoot) {
3922
4301
  super();
3923
4302
  this._onNewRoot = _onNewRoot;
3924
4303
  this.rootUrl = void 0;
3925
4304
  this.lastEpoch = void 0;
3926
- this.onNewEpoch = new Event4();
4305
+ this.onNewEpoch = new Event5();
3927
4306
  this._isProcessingRootDocs = false;
3928
4307
  }
3929
4308
  async _open(ctx) {
@@ -3962,10 +4341,10 @@ var AutomergeSpaceState = class extends Resource2 {
3962
4341
  import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3963
4342
  import { SpaceDocVersion } from "@dxos/echo-protocol";
3964
4343
  import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3965
- import { invariant as invariant12 } from "@dxos/invariant";
3966
- import { log as log14 } from "@dxos/log";
4344
+ import { invariant as invariant13 } from "@dxos/invariant";
4345
+ import { log as log15 } from "@dxos/log";
3967
4346
  import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3968
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
4347
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3969
4348
  var LOAD_DOC_TIMEOUT = 1e4;
3970
4349
  var runEpochMigration = async (ctx, context) => {
3971
4350
  switch (context.migration) {
@@ -3990,8 +4369,8 @@ var runEpochMigration = async (ctx, context) => {
3990
4369
  };
3991
4370
  }
3992
4371
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3993
- log14.info("Fragmenting", void 0, {
3994
- F: __dxlog_file17,
4372
+ log15.info("Fragmenting", void 0, {
4373
+ F: __dxlog_file18,
3995
4374
  L: 64,
3996
4375
  S: void 0,
3997
4376
  C: (f, a) => f(...a)
@@ -4003,8 +4382,8 @@ var runEpochMigration = async (ctx, context) => {
4003
4382
  const objects = Object.entries(rootHandle.docSync().objects);
4004
4383
  const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
4005
4384
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4006
- invariant12(properties, "Properties not found", {
4007
- F: __dxlog_file17,
4385
+ invariant13(properties, "Properties not found", {
4386
+ F: __dxlog_file18,
4008
4387
  L: 75,
4009
4388
  S: void 0,
4010
4389
  A: [
@@ -4018,8 +4397,8 @@ var runEpochMigration = async (ctx, context) => {
4018
4397
  properties
4019
4398
  ])
4020
4399
  });
4021
- invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4022
- F: __dxlog_file17,
4400
+ invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4401
+ F: __dxlog_file18,
4023
4402
  L: 82,
4024
4403
  S: void 0,
4025
4404
  A: [
@@ -4059,8 +4438,8 @@ var runEpochMigration = async (ctx, context) => {
4059
4438
  const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
4060
4439
  timeout: LOAD_DOC_TIMEOUT
4061
4440
  });
4062
- invariant12(rootHandle.docSync(), "Root doc not found", {
4063
- F: __dxlog_file17,
4441
+ invariant13(rootHandle.docSync(), "Root doc not found", {
4442
+ F: __dxlog_file18,
4064
4443
  L: 115,
4065
4444
  S: void 0,
4066
4445
  A: [
@@ -4074,8 +4453,8 @@ var runEpochMigration = async (ctx, context) => {
4074
4453
  const handle = await context.echoHost.loadDoc(ctx, url, {
4075
4454
  timeout: LOAD_DOC_TIMEOUT
4076
4455
  });
4077
- invariant12(handle.docSync(), void 0, {
4078
- F: __dxlog_file17,
4456
+ invariant13(handle.docSync(), void 0, {
4457
+ F: __dxlog_file18,
4079
4458
  L: 122,
4080
4459
  S: void 0,
4081
4460
  A: [
@@ -4090,12 +4469,12 @@ var runEpochMigration = async (ctx, context) => {
4090
4469
  });
4091
4470
  newRootContent.links[id] = newHandle.url;
4092
4471
  } catch (err) {
4093
- log14.warn("Failed to migrate reference", {
4472
+ log15.warn("Failed to migrate reference", {
4094
4473
  id,
4095
4474
  url,
4096
4475
  error: err
4097
4476
  }, {
4098
- F: __dxlog_file17,
4477
+ F: __dxlog_file18,
4099
4478
  L: 128,
4100
4479
  S: void 0,
4101
4480
  C: (f, a) => f(...a)
@@ -4113,8 +4492,8 @@ var runEpochMigration = async (ctx, context) => {
4113
4492
  };
4114
4493
  }
4115
4494
  case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
4116
- invariant12(context.newAutomergeRoot, void 0, {
4117
- F: __dxlog_file17,
4495
+ invariant13(context.newAutomergeRoot, void 0, {
4496
+ F: __dxlog_file18,
4118
4497
  L: 143,
4119
4498
  S: void 0,
4120
4499
  A: [
@@ -4132,15 +4511,15 @@ var runEpochMigration = async (ctx, context) => {
4132
4511
  };
4133
4512
 
4134
4513
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
4135
- import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger8 } from "@dxos/async";
4514
+ import { DeferredTask, Event as Event6, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger8 } from "@dxos/async";
4136
4515
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
4137
- import { invariant as invariant13 } from "@dxos/invariant";
4138
- import { PublicKey as PublicKey9 } from "@dxos/keys";
4139
- import { log as log15 } from "@dxos/log";
4516
+ import { invariant as invariant14 } from "@dxos/invariant";
4517
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
4518
+ import { log as log16 } from "@dxos/log";
4140
4519
  import { schema as schema4 } from "@dxos/protocols";
4141
4520
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
4142
- import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
4143
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
4521
+ import { ComplexMap as ComplexMap3, ComplexSet as ComplexSet4, entry } from "@dxos/util";
4522
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
4144
4523
  var DEFAULT_RETRY_TIMEOUT = 1e3;
4145
4524
  var DEFAULT_SUCCESS_DELAY = 1e3;
4146
4525
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -4148,13 +4527,13 @@ var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
4148
4527
  var NotarizationPlugin = class {
4149
4528
  constructor() {
4150
4529
  this._ctx = new Context7(void 0, {
4151
- F: __dxlog_file18,
4530
+ F: __dxlog_file19,
4152
4531
  L: 62
4153
4532
  });
4154
- this._extensionOpened = new Event5();
4533
+ this._extensionOpened = new Event6();
4155
4534
  this._extensions = /* @__PURE__ */ new Set();
4156
- this._processedCredentials = new ComplexSet4(PublicKey9.hash);
4157
- this._processCredentialsTriggers = new ComplexMap2(PublicKey9.hash);
4535
+ this._processedCredentials = new ComplexSet4(PublicKey10.hash);
4536
+ this._processCredentialsTriggers = new ComplexMap3(PublicKey10.hash);
4158
4537
  }
4159
4538
  get hasWriter() {
4160
4539
  return !!this._writer;
@@ -4168,16 +4547,16 @@ var NotarizationPlugin = class {
4168
4547
  * Request credentials to be notarized.
4169
4548
  */
4170
4549
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
4171
- log15("notarize", {
4550
+ log16("notarize", {
4172
4551
  credentials
4173
4552
  }, {
4174
- F: __dxlog_file18,
4553
+ F: __dxlog_file19,
4175
4554
  L: 90,
4176
4555
  S: this,
4177
4556
  C: (f, a) => f(...a)
4178
4557
  });
4179
- invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
4180
- F: __dxlog_file18,
4558
+ invariant14(credentials.every((credential) => credential.id), "Credentials must have an id", {
4559
+ F: __dxlog_file19,
4181
4560
  L: 91,
4182
4561
  S: this,
4183
4562
  A: [
@@ -4188,10 +4567,10 @@ var NotarizationPlugin = class {
4188
4567
  const errors = new Trigger8();
4189
4568
  const ctx = this._ctx.derive({
4190
4569
  onError: (err) => {
4191
- log15.warn("Notarization error", {
4570
+ log16.warn("Notarization error", {
4192
4571
  err
4193
4572
  }, {
4194
- F: __dxlog_file18,
4573
+ F: __dxlog_file19,
4195
4574
  L: 99,
4196
4575
  S: this,
4197
4576
  C: (f, a) => f(...a)
@@ -4203,11 +4582,11 @@ var NotarizationPlugin = class {
4203
4582
  opCtx?.onDispose(() => ctx.dispose());
4204
4583
  if (timeout !== 0) {
4205
4584
  scheduleTask4(ctx, () => {
4206
- log15.warn("Notarization timeout", {
4585
+ log16.warn("Notarization timeout", {
4207
4586
  timeout,
4208
4587
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
4209
4588
  }, {
4210
- F: __dxlog_file18,
4589
+ F: __dxlog_file19,
4211
4590
  L: 111,
4212
4591
  S: this,
4213
4592
  C: (f, a) => f(...a)
@@ -4227,10 +4606,10 @@ var NotarizationPlugin = class {
4227
4606
  ...this._extensions
4228
4607
  ].find((peer2) => !peersTried.has(peer2));
4229
4608
  if (!peer) {
4230
- log15.info("Exhausted all peers to notarize with", {
4609
+ log16.info("Exhausted all peers to notarize with", {
4231
4610
  retryIn: retryTimeout
4232
4611
  }, {
4233
- F: __dxlog_file18,
4612
+ F: __dxlog_file19,
4234
4613
  L: 136,
4235
4614
  S: this,
4236
4615
  C: (f, a) => f(...a)
@@ -4240,11 +4619,11 @@ var NotarizationPlugin = class {
4240
4619
  return;
4241
4620
  }
4242
4621
  peersTried.add(peer);
4243
- log15("try notarizing", {
4622
+ log16("try notarizing", {
4244
4623
  peer: peer.localPeerId,
4245
4624
  credentialId: credentials.map((credential) => credential.id)
4246
4625
  }, {
4247
- F: __dxlog_file18,
4626
+ F: __dxlog_file19,
4248
4627
  L: 143,
4249
4628
  S: this,
4250
4629
  C: (f, a) => f(...a)
@@ -4252,8 +4631,8 @@ var NotarizationPlugin = class {
4252
4631
  await peer.rpc.NotarizationService.notarize({
4253
4632
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
4254
4633
  });
4255
- log15("success", void 0, {
4256
- F: __dxlog_file18,
4634
+ log16("success", void 0, {
4635
+ F: __dxlog_file19,
4257
4636
  L: 147,
4258
4637
  S: this,
4259
4638
  C: (f, a) => f(...a)
@@ -4261,8 +4640,8 @@ var NotarizationPlugin = class {
4261
4640
  await sleep2(successDelay);
4262
4641
  } catch (err) {
4263
4642
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
4264
- log15.info("error notarizing (recoverable)", err, {
4265
- F: __dxlog_file18,
4643
+ log16.info("error notarizing (recoverable)", err, {
4644
+ F: __dxlog_file19,
4266
4645
  L: 151,
4267
4646
  S: this,
4268
4647
  C: (f, a) => f(...a)
@@ -4279,8 +4658,8 @@ var NotarizationPlugin = class {
4279
4658
  allNotarized,
4280
4659
  errors.wait()
4281
4660
  ]);
4282
- log15("done", void 0, {
4283
- F: __dxlog_file18,
4661
+ log16("done", void 0, {
4662
+ F: __dxlog_file19,
4284
4663
  L: 162,
4285
4664
  S: this,
4286
4665
  C: (f, a) => f(...a)
@@ -4301,8 +4680,8 @@ var NotarizationPlugin = class {
4301
4680
  this._processCredentialsTriggers.delete(credential.id);
4302
4681
  }
4303
4682
  setWriter(writer) {
4304
- invariant13(!this._writer, "Writer already set.", {
4305
- F: __dxlog_file18,
4683
+ invariant14(!this._writer, "Writer already set.", {
4684
+ F: __dxlog_file19,
4306
4685
  L: 181,
4307
4686
  S: this,
4308
4687
  A: [
@@ -4326,8 +4705,8 @@ var NotarizationPlugin = class {
4326
4705
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
4327
4706
  }
4328
4707
  for (const credential of request.credentials ?? []) {
4329
- invariant13(credential.id, "Credential must have an id", {
4330
- F: __dxlog_file18,
4708
+ invariant14(credential.id, "Credential must have an id", {
4709
+ F: __dxlog_file19,
4331
4710
  L: 200,
4332
4711
  S: this,
4333
4712
  A: [
@@ -4344,10 +4723,10 @@ var NotarizationPlugin = class {
4344
4723
  createExtension() {
4345
4724
  const extension = new NotarizationTeleportExtension({
4346
4725
  onOpen: async () => {
4347
- log15("extension opened", {
4726
+ log16("extension opened", {
4348
4727
  peer: extension.localPeerId
4349
4728
  }, {
4350
- F: __dxlog_file18,
4729
+ F: __dxlog_file19,
4351
4730
  L: 211,
4352
4731
  S: this,
4353
4732
  C: (f, a) => f(...a)
@@ -4356,10 +4735,10 @@ var NotarizationPlugin = class {
4356
4735
  this._extensionOpened.emit();
4357
4736
  },
4358
4737
  onClose: async () => {
4359
- log15("extension closed", {
4738
+ log16("extension closed", {
4360
4739
  peer: extension.localPeerId
4361
4740
  }, {
4362
- F: __dxlog_file18,
4741
+ F: __dxlog_file19,
4363
4742
  L: 216,
4364
4743
  S: this,
4365
4744
  C: (f, a) => f(...a)
@@ -4413,7 +4792,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4413
4792
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4414
4793
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4415
4794
  }
4416
- function _using_ctx() {
4795
+ function _using_ctx2() {
4417
4796
  var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4418
4797
  var err = new Error();
4419
4798
  err.name = "SuppressedError";
@@ -4476,26 +4855,32 @@ function _using_ctx() {
4476
4855
  }
4477
4856
  };
4478
4857
  }
4479
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4858
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4480
4859
  var DataSpace = class {
4481
4860
  constructor(params) {
4482
4861
  this._ctx = new Context8(void 0, {
4483
- F: __dxlog_file19,
4484
- L: 84
4862
+ F: __dxlog_file20,
4863
+ L: 87
4485
4864
  });
4486
4865
  this._notarizationPlugin = new NotarizationPlugin();
4487
4866
  this._cache = void 0;
4867
+ this._edgeFeedReplicator = void 0;
4488
4868
  // TODO(dmaretskyi): Move into Space?
4489
4869
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
4490
- this._epochProcessingMutex = new Mutex2();
4870
+ this._epochProcessingMutex = new Mutex3();
4491
4871
  this._state = SpaceState2.SPACE_CLOSED;
4492
4872
  this._databaseRoot = null;
4493
4873
  /**
4494
4874
  * Error for _state === SpaceState.SPACE_ERROR.
4495
4875
  */
4496
4876
  this.error = void 0;
4497
- this.stateUpdate = new Event6();
4877
+ this.stateUpdate = new Event7();
4878
+ this.postOpen = new CallbackCollection();
4879
+ this.preClose = new CallbackCollection();
4498
4880
  this.metrics = {};
4881
+ this._onFeedAdded = async (feed) => {
4882
+ await this._edgeFeedReplicator.addFeed(feed);
4883
+ };
4499
4884
  this._inner = params.inner;
4500
4885
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
4501
4886
  this._gossip = params.gossip;
@@ -4507,17 +4892,23 @@ var DataSpace = class {
4507
4892
  this._callbacks = params.callbacks ?? {};
4508
4893
  this._echoHost = params.echoHost;
4509
4894
  this.authVerifier = new TrustedKeySetAuthVerifier({
4510
- trustedKeysProvider: () => new ComplexSet5(PublicKey10.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember4.Role.REMOVED).map((member) => member.key)),
4895
+ trustedKeysProvider: () => new ComplexSet5(PublicKey11.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember4.Role.REMOVED).map((member) => member.key)),
4511
4896
  update: this._inner.stateUpdate,
4512
4897
  authTimeout: AUTH_TIMEOUT2
4513
4898
  });
4514
4899
  this._cache = params.cache;
4900
+ if (params.edgeConnection) {
4901
+ this._edgeFeedReplicator = new EdgeFeedReplicator({
4902
+ messenger: params.edgeConnection,
4903
+ spaceId: this.id
4904
+ });
4905
+ }
4515
4906
  this._state = params.initialState;
4516
- log16("new state", {
4907
+ log17("new state", {
4517
4908
  state: SpaceState2[this._state]
4518
4909
  }, {
4519
- F: __dxlog_file19,
4520
- L: 146,
4910
+ F: __dxlog_file20,
4911
+ L: 157,
4521
4912
  S: this,
4522
4913
  C: (f, a) => f(...a)
4523
4914
  });
@@ -4571,42 +4962,52 @@ var DataSpace = class {
4571
4962
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4572
4963
  await this._automergeSpaceState.open();
4573
4964
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4965
+ if (this._edgeFeedReplicator) {
4966
+ this.inner.protocol.feedAdded.append(this._onFeedAdded);
4967
+ }
4574
4968
  await this._inner.open(new Context8(void 0, {
4575
- F: __dxlog_file19,
4576
- L: 215
4969
+ F: __dxlog_file20,
4970
+ L: 231
4577
4971
  }));
4972
+ await this._edgeFeedReplicator?.open();
4578
4973
  this._state = SpaceState2.SPACE_CONTROL_ONLY;
4579
- log16("new state", {
4974
+ log17("new state", {
4580
4975
  state: SpaceState2[this._state]
4581
4976
  }, {
4582
- F: __dxlog_file19,
4583
- L: 217,
4977
+ F: __dxlog_file20,
4978
+ L: 236,
4584
4979
  S: this,
4585
4980
  C: (f, a) => f(...a)
4586
4981
  });
4587
4982
  this.stateUpdate.emit();
4588
4983
  this.metrics = {};
4589
4984
  this.metrics.open = /* @__PURE__ */ new Date();
4985
+ await this.postOpen.callSerial();
4590
4986
  }
4591
4987
  async close() {
4592
4988
  await this._close();
4593
4989
  }
4594
4990
  async _close() {
4595
4991
  await this._callbacks.beforeClose?.();
4992
+ await this.preClose.callSerial();
4596
4993
  this._state = SpaceState2.SPACE_CLOSED;
4597
- log16("new state", {
4994
+ log17("new state", {
4598
4995
  state: SpaceState2[this._state]
4599
4996
  }, {
4600
- F: __dxlog_file19,
4601
- L: 231,
4997
+ F: __dxlog_file20,
4998
+ L: 255,
4602
4999
  S: this,
4603
5000
  C: (f, a) => f(...a)
4604
5001
  });
4605
5002
  await this._ctx.dispose();
4606
5003
  this._ctx = new Context8(void 0, {
4607
- F: __dxlog_file19,
4608
- L: 233
5004
+ F: __dxlog_file20,
5005
+ L: 257
4609
5006
  });
5007
+ if (this._edgeFeedReplicator) {
5008
+ this.inner.protocol.feedAdded.remove(this._onFeedAdded);
5009
+ }
5010
+ await this._edgeFeedReplicator?.close();
4610
5011
  await this.authVerifier.close();
4611
5012
  await this._inner.close();
4612
5013
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -4632,26 +5033,26 @@ var DataSpace = class {
4632
5033
  await this.initializeDataPipeline();
4633
5034
  } catch (err) {
4634
5035
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4635
- log16("data pipeline initialization cancelled", err, {
4636
- F: __dxlog_file19,
4637
- L: 265,
5036
+ log17("data pipeline initialization cancelled", err, {
5037
+ F: __dxlog_file20,
5038
+ L: 295,
4638
5039
  S: this,
4639
5040
  C: (f, a) => f(...a)
4640
5041
  });
4641
5042
  return;
4642
5043
  }
4643
- log16.error("Error initializing data pipeline", err, {
4644
- F: __dxlog_file19,
4645
- L: 269,
5044
+ log17.error("Error initializing data pipeline", err, {
5045
+ F: __dxlog_file20,
5046
+ L: 299,
4646
5047
  S: this,
4647
5048
  C: (f, a) => f(...a)
4648
5049
  });
4649
5050
  this._state = SpaceState2.SPACE_ERROR;
4650
- log16("new state", {
5051
+ log17("new state", {
4651
5052
  state: SpaceState2[this._state]
4652
5053
  }, {
4653
- F: __dxlog_file19,
4654
- L: 271,
5054
+ F: __dxlog_file20,
5055
+ L: 301,
4655
5056
  S: this,
4656
5057
  C: (f, a) => f(...a)
4657
5058
  });
@@ -4667,11 +5068,11 @@ var DataSpace = class {
4667
5068
  throw new SystemError("Invalid operation");
4668
5069
  }
4669
5070
  this._state = SpaceState2.SPACE_INITIALIZING;
4670
- log16("new state", {
5071
+ log17("new state", {
4671
5072
  state: SpaceState2[this._state]
4672
5073
  }, {
4673
- F: __dxlog_file19,
4674
- L: 287,
5074
+ F: __dxlog_file20,
5075
+ L: 317,
4675
5076
  S: this,
4676
5077
  C: (f, a) => f(...a)
4677
5078
  });
@@ -4684,11 +5085,11 @@ var DataSpace = class {
4684
5085
  async _enterReadyState() {
4685
5086
  await this._callbacks.beforeReady?.();
4686
5087
  this._state = SpaceState2.SPACE_READY;
4687
- log16("new state", {
5088
+ log17("new state", {
4688
5089
  state: SpaceState2[this._state]
4689
5090
  }, {
4690
- F: __dxlog_file19,
4691
- L: 306,
5091
+ F: __dxlog_file20,
5092
+ L: 336,
4692
5093
  S: this,
4693
5094
  C: (f, a) => f(...a)
4694
5095
  });
@@ -4702,9 +5103,9 @@ var DataSpace = class {
4702
5103
  });
4703
5104
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4704
5105
  await this._createWritableFeeds();
4705
- log16("writable feeds created", void 0, {
4706
- F: __dxlog_file19,
4707
- L: 322,
5106
+ log17("writable feeds created", void 0, {
5107
+ F: __dxlog_file20,
5108
+ L: 352,
4708
5109
  S: this,
4709
5110
  C: (f, a) => f(...a)
4710
5111
  });
@@ -4762,12 +5163,12 @@ var DataSpace = class {
4762
5163
  }
4763
5164
  }
4764
5165
  _onNewAutomergeRoot(rootUrl) {
4765
- log16("loading automerge root doc for space", {
5166
+ log17("loading automerge root doc for space", {
4766
5167
  space: this.key,
4767
5168
  rootUrl
4768
5169
  }, {
4769
- F: __dxlog_file19,
4770
- L: 388,
5170
+ F: __dxlog_file20,
5171
+ L: 418,
4771
5172
  S: this,
4772
5173
  C: (f, a) => f(...a)
4773
5174
  });
@@ -4775,7 +5176,7 @@ var DataSpace = class {
4775
5176
  queueMicrotask(async () => {
4776
5177
  try {
4777
5178
  try {
4778
- var _usingCtx = _using_ctx();
5179
+ var _usingCtx = _using_ctx2();
4779
5180
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4780
5181
  await cancelWithContext4(this._ctx, handle.whenReady());
4781
5182
  });
@@ -4813,13 +5214,13 @@ var DataSpace = class {
4813
5214
  if (err instanceof ContextDisposedError3) {
4814
5215
  return;
4815
5216
  }
4816
- log16.warn("error loading automerge root doc", {
5217
+ log17.warn("error loading automerge root doc", {
4817
5218
  space: this.key,
4818
5219
  rootUrl,
4819
5220
  err
4820
5221
  }, {
4821
- F: __dxlog_file19,
4822
- L: 431,
5222
+ F: __dxlog_file20,
5223
+ L: 461,
4823
5224
  S: this,
4824
5225
  C: (f, a) => f(...a)
4825
5226
  });
@@ -4905,11 +5306,11 @@ var DataSpace = class {
4905
5306
  await this._close();
4906
5307
  }
4907
5308
  this._state = SpaceState2.SPACE_INACTIVE;
4908
- log16("new state", {
5309
+ log17("new state", {
4909
5310
  state: SpaceState2[this._state]
4910
5311
  }, {
4911
- F: __dxlog_file19,
4912
- L: 513,
5312
+ F: __dxlog_file20,
5313
+ L: 543,
4913
5314
  S: this,
4914
5315
  C: (f, a) => f(...a)
4915
5316
  });
@@ -4966,25 +5367,24 @@ DataSpace = _ts_decorate5([
4966
5367
  ], DataSpace);
4967
5368
 
4968
5369
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4969
- import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
5370
+ import { Event as Event8, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4970
5371
  import { PropertiesType } from "@dxos/client-protocol";
4971
- import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
4972
- import { getCredentialAssertion as getCredentialAssertion3, createAdmissionCredentials } from "@dxos/credentials";
5372
+ import { LifecycleState, Resource as Resource4, cancelWithContext as cancelWithContext5 } from "@dxos/context";
5373
+ import { createAdmissionCredentials, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4973
5374
  import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4974
- import { AuthStatus } from "@dxos/echo-pipeline";
4975
- import { CredentialServerExtension } from "@dxos/echo-pipeline";
5375
+ import { AuthStatus, CredentialServerExtension } from "@dxos/echo-pipeline";
4976
5376
  import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion3, encodeReference } from "@dxos/echo-protocol";
4977
5377
  import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4978
5378
  import { writeMessages as writeMessages3 } from "@dxos/feed-store";
4979
- import { invariant as invariant14 } from "@dxos/invariant";
4980
- import { PublicKey as PublicKey11 } from "@dxos/keys";
4981
- import { log as log17 } from "@dxos/log";
4982
- import { trace as Trace2, AlreadyJoinedError as AlreadyJoinedError3 } from "@dxos/protocols";
5379
+ import { invariant as invariant15 } from "@dxos/invariant";
5380
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
5381
+ import { log as log18 } from "@dxos/log";
5382
+ import { AlreadyJoinedError as AlreadyJoinedError3, trace as Trace2 } from "@dxos/protocols";
4983
5383
  import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4984
5384
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4985
5385
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4986
5386
  import { trace as trace7 } from "@dxos/tracing";
4987
- import { ComplexMap as ComplexMap3, assignDeep, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
5387
+ import { ComplexMap as ComplexMap4, assignDeep, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4988
5388
 
4989
5389
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4990
5390
  import { createCredential } from "@dxos/credentials";
@@ -5067,28 +5467,31 @@ function _ts_decorate6(decorators, target, key, desc) {
5067
5467
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5068
5468
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5069
5469
  }
5070
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
5470
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
5071
5471
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
5072
5472
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
5073
5473
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
5074
- var DataSpaceManager = class {
5075
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, _params) {
5076
- this._spaceManager = _spaceManager;
5077
- this._metadataStore = _metadataStore;
5078
- this._keyring = _keyring;
5079
- this._signingContext = _signingContext;
5080
- this._feedStore = _feedStore;
5081
- this._echoHost = _echoHost;
5082
- this._invitationsManager = _invitationsManager;
5083
- this._params = _params;
5084
- this._ctx = new Context9(void 0, {
5085
- F: __dxlog_file20,
5086
- L: 104
5087
- });
5088
- this.updated = new Event7();
5089
- this._spaces = new ComplexMap3(PublicKey11.hash);
5090
- this._isOpen = false;
5091
- this._instanceId = PublicKey11.random().toHex();
5474
+ var DataSpaceManager = class extends Resource4 {
5475
+ constructor(params) {
5476
+ super();
5477
+ this.updated = new Event8();
5478
+ this._spaces = new ComplexMap4(PublicKey12.hash);
5479
+ this._instanceId = PublicKey12.random().toHex();
5480
+ this._edgeConnection = void 0;
5481
+ this._meshReplicator = void 0;
5482
+ this._echoEdgeReplicator = void 0;
5483
+ this._runtimeParams = void 0;
5484
+ this._spaceManager = params.spaceManager;
5485
+ this._metadataStore = params.metadataStore;
5486
+ this._keyring = params.keyring;
5487
+ this._signingContext = params.signingContext;
5488
+ this._feedStore = params.feedStore;
5489
+ this._echoHost = params.echoHost;
5490
+ this._meshReplicator = params.meshReplicator;
5491
+ this._invitationsManager = params.invitationsManager;
5492
+ this._edgeConnection = params.edgeConnection;
5493
+ this._echoEdgeReplicator = params.echoEdgeReplicator;
5494
+ this._runtimeParams = params.runtimeParams;
5092
5495
  trace7.diagnostic({
5093
5496
  id: "spaces",
5094
5497
  name: "Spaces",
@@ -5116,72 +5519,69 @@ var DataSpaceManager = class {
5116
5519
  get spaces() {
5117
5520
  return this._spaces;
5118
5521
  }
5119
- async open() {
5120
- log17("open", void 0, {
5121
- F: __dxlog_file20,
5122
- L: 156,
5522
+ async _open() {
5523
+ log18("open", void 0, {
5524
+ F: __dxlog_file21,
5525
+ L: 187,
5123
5526
  S: this,
5124
5527
  C: (f, a) => f(...a)
5125
5528
  });
5126
- log17.trace("dxos.echo.data-space-manager.open", Trace2.begin({
5529
+ log18.trace("dxos.echo.data-space-manager.open", Trace2.begin({
5127
5530
  id: this._instanceId
5128
5531
  }), {
5129
- F: __dxlog_file20,
5130
- L: 157,
5532
+ F: __dxlog_file21,
5533
+ L: 188,
5131
5534
  S: this,
5132
5535
  C: (f, a) => f(...a)
5133
5536
  });
5134
- log17("metadata loaded", {
5537
+ log18("metadata loaded", {
5135
5538
  spaces: this._metadataStore.spaces.length
5136
5539
  }, {
5137
- F: __dxlog_file20,
5138
- L: 158,
5540
+ F: __dxlog_file21,
5541
+ L: 189,
5139
5542
  S: this,
5140
5543
  C: (f, a) => f(...a)
5141
5544
  });
5142
5545
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
5143
5546
  try {
5144
- log17("load space", {
5547
+ log18("load space", {
5145
5548
  spaceMetadata
5146
5549
  }, {
5147
- F: __dxlog_file20,
5148
- L: 162,
5550
+ F: __dxlog_file21,
5551
+ L: 193,
5149
5552
  S: this,
5150
5553
  C: (f, a) => f(...a)
5151
5554
  });
5152
5555
  await this._constructSpace(spaceMetadata);
5153
5556
  } catch (err) {
5154
- log17.error("Error loading space", {
5557
+ log18.error("Error loading space", {
5155
5558
  spaceMetadata,
5156
5559
  err
5157
5560
  }, {
5158
- F: __dxlog_file20,
5159
- L: 165,
5561
+ F: __dxlog_file21,
5562
+ L: 196,
5160
5563
  S: this,
5161
5564
  C: (f, a) => f(...a)
5162
5565
  });
5163
5566
  }
5164
5567
  });
5165
- this._isOpen = true;
5166
5568
  this.updated.emit();
5167
- log17.trace("dxos.echo.data-space-manager.open", Trace2.end({
5569
+ log18.trace("dxos.echo.data-space-manager.open", Trace2.end({
5168
5570
  id: this._instanceId
5169
5571
  }), {
5170
- F: __dxlog_file20,
5171
- L: 172,
5572
+ F: __dxlog_file21,
5573
+ L: 202,
5172
5574
  S: this,
5173
5575
  C: (f, a) => f(...a)
5174
5576
  });
5175
5577
  }
5176
- async close() {
5177
- log17("close", void 0, {
5178
- F: __dxlog_file20,
5179
- L: 177,
5578
+ async _close() {
5579
+ log18("close", void 0, {
5580
+ F: __dxlog_file21,
5581
+ L: 207,
5180
5582
  S: this,
5181
5583
  C: (f, a) => f(...a)
5182
5584
  });
5183
- this._isOpen = false;
5184
- await this._ctx.dispose();
5185
5585
  for (const space of this._spaces.values()) {
5186
5586
  await space.close();
5187
5587
  }
@@ -5191,12 +5591,12 @@ var DataSpaceManager = class {
5191
5591
  * Creates a new space writing the genesis credentials to the control feed.
5192
5592
  */
5193
5593
  async createSpace() {
5194
- invariant14(this._isOpen, "Not open.", {
5195
- F: __dxlog_file20,
5196
- L: 191,
5594
+ invariant15(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
5595
+ F: __dxlog_file21,
5596
+ L: 219,
5197
5597
  S: this,
5198
5598
  A: [
5199
- "this._isOpen",
5599
+ "this._lifecycleState === LifecycleState.OPEN",
5200
5600
  "'Not open.'"
5201
5601
  ]
5202
5602
  });
@@ -5210,11 +5610,11 @@ var DataSpaceManager = class {
5210
5610
  dataFeedKey,
5211
5611
  state: SpaceState3.SPACE_ACTIVE
5212
5612
  };
5213
- log17("creating space...", {
5613
+ log18("creating space...", {
5214
5614
  spaceKey
5215
5615
  }, {
5216
- F: __dxlog_file20,
5217
- L: 203,
5616
+ F: __dxlog_file21,
5617
+ L: 231,
5218
5618
  S: this,
5219
5619
  C: (f, a) => f(...a)
5220
5620
  });
@@ -5224,9 +5624,9 @@ var DataSpaceManager = class {
5224
5624
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
5225
5625
  await this._metadataStore.addSpace(metadata);
5226
5626
  const memberCredential = credentials[1];
5227
- invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5228
- F: __dxlog_file20,
5229
- L: 213,
5627
+ invariant15(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5628
+ F: __dxlog_file21,
5629
+ L: 241,
5230
5630
  S: this,
5231
5631
  A: [
5232
5632
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5253,12 +5653,12 @@ var DataSpaceManager = class {
5253
5653
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5254
5654
  }
5255
5655
  default:
5256
- log17.warn("unknown space version", {
5656
+ log18.warn("unknown space version", {
5257
5657
  version: space.databaseRoot.getVersion(),
5258
5658
  spaceId: space.id
5259
5659
  }, {
5260
- F: __dxlog_file20,
5261
- L: 238,
5660
+ F: __dxlog_file21,
5661
+ L: 266,
5262
5662
  S: this,
5263
5663
  C: (f, a) => f(...a)
5264
5664
  });
@@ -5291,9 +5691,9 @@ var DataSpaceManager = class {
5291
5691
  }
5292
5692
  async _getSpaceRootDocument(space) {
5293
5693
  const automergeIndex = space.automergeSpaceState.rootUrl;
5294
- invariant14(automergeIndex, void 0, {
5295
- F: __dxlog_file20,
5296
- L: 271,
5694
+ invariant15(automergeIndex, void 0, {
5695
+ F: __dxlog_file21,
5696
+ L: 299,
5297
5697
  S: this,
5298
5698
  A: [
5299
5699
  "automergeIndex",
@@ -5306,26 +5706,26 @@ var DataSpaceManager = class {
5306
5706
  }
5307
5707
  // TODO(burdon): Rename join space.
5308
5708
  async acceptSpace(opts) {
5309
- log17("accept space", {
5709
+ log18("accept space", {
5310
5710
  opts
5311
5711
  }, {
5312
- F: __dxlog_file20,
5313
- L: 280,
5712
+ F: __dxlog_file21,
5713
+ L: 308,
5314
5714
  S: this,
5315
5715
  C: (f, a) => f(...a)
5316
5716
  });
5317
- invariant14(this._isOpen, "Not open.", {
5318
- F: __dxlog_file20,
5319
- L: 281,
5717
+ invariant15(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
5718
+ F: __dxlog_file21,
5719
+ L: 309,
5320
5720
  S: this,
5321
5721
  A: [
5322
- "this._isOpen",
5722
+ "this._lifecycleState === LifecycleState.OPEN",
5323
5723
  "'Not open.'"
5324
5724
  ]
5325
5725
  });
5326
- invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
5327
- F: __dxlog_file20,
5328
- L: 282,
5726
+ invariant15(!this._spaces.has(opts.spaceKey), "Space already exists.", {
5727
+ F: __dxlog_file21,
5728
+ L: 310,
5329
5729
  S: this,
5330
5730
  A: [
5331
5731
  "!this._spaces.has(opts.spaceKey)",
@@ -5347,9 +5747,9 @@ var DataSpaceManager = class {
5347
5747
  }
5348
5748
  async admitMember(options) {
5349
5749
  const space = this._spaceManager.spaces.get(options.spaceKey);
5350
- invariant14(space, void 0, {
5351
- F: __dxlog_file20,
5352
- L: 302,
5750
+ invariant15(space, void 0, {
5751
+ F: __dxlog_file21,
5752
+ L: 330,
5353
5753
  S: this,
5354
5754
  A: [
5355
5755
  "space",
@@ -5360,9 +5760,9 @@ var DataSpaceManager = class {
5360
5760
  throw new AlreadyJoinedError3();
5361
5761
  }
5362
5762
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
5363
- invariant14(credentials[0].credential, void 0, {
5364
- F: __dxlog_file20,
5365
- L: 321,
5763
+ invariant15(credentials[0].credential, void 0, {
5764
+ F: __dxlog_file21,
5765
+ L: 349,
5366
5766
  S: this,
5367
5767
  A: [
5368
5768
  "credentials[0].credential",
@@ -5370,9 +5770,9 @@ var DataSpaceManager = class {
5370
5770
  ]
5371
5771
  });
5372
5772
  const spaceMemberCredential = credentials[0].credential.credential;
5373
- invariant14(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5374
- F: __dxlog_file20,
5375
- L: 323,
5773
+ invariant15(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5774
+ F: __dxlog_file21,
5775
+ L: 351,
5376
5776
  S: this,
5377
5777
  A: [
5378
5778
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5406,11 +5806,11 @@ var DataSpaceManager = class {
5406
5806
  });
5407
5807
  }
5408
5808
  async _constructSpace(metadata) {
5409
- log17("construct space", {
5809
+ log18("construct space", {
5410
5810
  metadata
5411
5811
  }, {
5412
- F: __dxlog_file20,
5413
- L: 358,
5812
+ F: __dxlog_file21,
5813
+ L: 386,
5414
5814
  S: this,
5415
5815
  C: (f, a) => f(...a)
5416
5816
  });
@@ -5418,8 +5818,8 @@ var DataSpaceManager = class {
5418
5818
  localPeerId: this._signingContext.deviceKey
5419
5819
  });
5420
5820
  const presence = new Presence2({
5421
- announceInterval: this._params?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
5422
- offlineTimeout: this._params?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
5821
+ announceInterval: this._runtimeParams?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
5822
+ offlineTimeout: this._runtimeParams?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
5423
5823
  identityKey: this._signingContext.identityKey,
5424
5824
  gossip
5425
5825
  });
@@ -5447,17 +5847,13 @@ var DataSpaceManager = class {
5447
5847
  remotePeerId: session.remotePeerId
5448
5848
  }));
5449
5849
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
5450
- await this._echoHost.authorizeDevice(space.key, session.remotePeerId);
5451
- if (!session.isOpen) {
5452
- return;
5453
- }
5454
- session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
5850
+ await this._connectEchoMeshReplicator(space, session);
5455
5851
  } catch (err) {
5456
- log17.warn("error on authorized connection", {
5852
+ log18.warn("error on authorized connection", {
5457
5853
  err
5458
5854
  }, {
5459
- F: __dxlog_file20,
5460
- L: 403,
5855
+ F: __dxlog_file21,
5856
+ L: 427,
5461
5857
  S: this,
5462
5858
  C: (f, a) => f(...a)
5463
5859
  });
@@ -5465,9 +5861,9 @@ var DataSpaceManager = class {
5465
5861
  }
5466
5862
  }),
5467
5863
  onAuthFailure: () => {
5468
- log17.warn("auth failure", void 0, {
5469
- F: __dxlog_file20,
5470
- L: 408,
5864
+ log18.warn("auth failure", void 0, {
5865
+ F: __dxlog_file21,
5866
+ L: 432,
5471
5867
  S: this,
5472
5868
  C: (f, a) => f(...a)
5473
5869
  });
@@ -5496,26 +5892,26 @@ var DataSpaceManager = class {
5496
5892
  signingContext: this._signingContext,
5497
5893
  callbacks: {
5498
5894
  beforeReady: async () => {
5499
- log17("before space ready", {
5895
+ log18("before space ready", {
5500
5896
  space: space.key
5501
5897
  }, {
5502
- F: __dxlog_file20,
5503
- L: 435,
5898
+ F: __dxlog_file21,
5899
+ L: 459,
5504
5900
  S: this,
5505
5901
  C: (f, a) => f(...a)
5506
5902
  });
5507
5903
  },
5508
5904
  afterReady: async () => {
5509
- log17("after space ready", {
5905
+ log18("after space ready", {
5510
5906
  space: space.key,
5511
- open: this._isOpen
5907
+ open: this._lifecycleState === LifecycleState.OPEN
5512
5908
  }, {
5513
- F: __dxlog_file20,
5514
- L: 438,
5909
+ F: __dxlog_file21,
5910
+ L: 462,
5515
5911
  S: this,
5516
5912
  C: (f, a) => f(...a)
5517
5913
  });
5518
- if (this._isOpen) {
5914
+ if (this._lifecycleState === LifecycleState.OPEN) {
5519
5915
  await this._createDelegatedInvitations(dataSpace, [
5520
5916
  ...space.spaceState.invitations.entries()
5521
5917
  ]);
@@ -5526,17 +5922,24 @@ var DataSpaceManager = class {
5526
5922
  }
5527
5923
  },
5528
5924
  beforeClose: async () => {
5529
- log17("before space close", {
5925
+ log18("before space close", {
5530
5926
  space: space.key
5531
5927
  }, {
5532
- F: __dxlog_file20,
5533
- L: 446,
5928
+ F: __dxlog_file21,
5929
+ L: 470,
5534
5930
  S: this,
5535
5931
  C: (f, a) => f(...a)
5536
5932
  });
5537
5933
  }
5538
5934
  },
5539
- cache: metadata.cache
5935
+ cache: metadata.cache,
5936
+ edgeConnection: this._edgeConnection
5937
+ });
5938
+ dataSpace.postOpen.append(async () => {
5939
+ await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
5940
+ });
5941
+ dataSpace.preClose.append(async () => {
5942
+ await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
5540
5943
  });
5541
5944
  presence.newPeer.on((peerState) => {
5542
5945
  if (dataSpace.state === SpaceState3.SPACE_READY) {
@@ -5549,6 +5952,24 @@ var DataSpaceManager = class {
5549
5952
  this._spaces.set(metadata.key, dataSpace);
5550
5953
  return dataSpace;
5551
5954
  }
5955
+ async _connectEchoMeshReplicator(space, session) {
5956
+ const replicator = this._meshReplicator;
5957
+ if (!replicator) {
5958
+ log18.warn("p2p automerge replication disabled", {
5959
+ space: space.key
5960
+ }, {
5961
+ F: __dxlog_file21,
5962
+ L: 500,
5963
+ S: this,
5964
+ C: (f, a) => f(...a)
5965
+ });
5966
+ return;
5967
+ }
5968
+ await replicator.authorizeDevice(space.key, session.remotePeerId);
5969
+ if (session.isOpen) {
5970
+ session.addExtension("dxos.mesh.teleport.automerge", replicator.createExtension());
5971
+ }
5972
+ }
5552
5973
  _handleMemberRoleChanges(presence, spaceProtocol, memberInfo) {
5553
5974
  let closedSessions = 0;
5554
5975
  for (const member of memberInfo) {
@@ -5561,17 +5982,17 @@ var DataSpaceManager = class {
5561
5982
  return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
5562
5983
  });
5563
5984
  sessionsToClose.forEach((session) => {
5564
- void session.close().catch(log17.error);
5985
+ void session.close().catch(log18.error);
5565
5986
  });
5566
5987
  closedSessions += sessionsToClose.length;
5567
5988
  }
5568
- log17("processed member role changes", {
5989
+ log18("processed member role changes", {
5569
5990
  roleChangeCount: memberInfo.length,
5570
5991
  peersOnline: presence.getPeersOnline().length,
5571
5992
  closedSessions
5572
5993
  }, {
5573
- F: __dxlog_file20,
5574
- L: 482,
5994
+ F: __dxlog_file21,
5995
+ L: 526,
5575
5996
  S: this,
5576
5997
  C: (f, a) => f(...a)
5577
5998
  });
@@ -5582,15 +6003,15 @@ var DataSpaceManager = class {
5582
6003
  if (role === SpaceMember6.Role.REMOVED) {
5583
6004
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
5584
6005
  if (session != null) {
5585
- log17("closing a session with a removed peer", {
6006
+ log18("closing a session with a removed peer", {
5586
6007
  peerId: peerState.peerId
5587
6008
  }, {
5588
- F: __dxlog_file20,
5589
- L: 496,
6009
+ F: __dxlog_file21,
6010
+ L: 540,
5590
6011
  S: this,
5591
6012
  C: (f, a) => f(...a)
5592
6013
  });
5593
- void session.close().catch(log17.error);
6014
+ void session.close().catch(log18.error);
5594
6015
  }
5595
6016
  }
5596
6017
  }
@@ -5632,10 +6053,10 @@ var DataSpaceManager = class {
5632
6053
  };
5633
6054
  _ts_decorate6([
5634
6055
  synchronized2
5635
- ], DataSpaceManager.prototype, "open", null);
6056
+ ], DataSpaceManager.prototype, "_open", null);
5636
6057
  _ts_decorate6([
5637
6058
  synchronized2
5638
- ], DataSpaceManager.prototype, "close", null);
6059
+ ], DataSpaceManager.prototype, "_close", null);
5639
6060
  _ts_decorate6([
5640
6061
  synchronized2
5641
6062
  ], DataSpaceManager.prototype, "createSpace", null);
@@ -5652,12 +6073,12 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
5652
6073
  import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5653
6074
  import { raise as raise2 } from "@dxos/debug";
5654
6075
  import { writeMessages as writeMessages4 } from "@dxos/feed-store";
5655
- import { invariant as invariant15 } from "@dxos/invariant";
5656
- import { log as log18 } from "@dxos/log";
6076
+ import { invariant as invariant16 } from "@dxos/invariant";
6077
+ import { log as log19 } from "@dxos/log";
5657
6078
  import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
5658
6079
  import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5659
6080
  import { trace as trace8 } from "@dxos/tracing";
5660
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
6081
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5661
6082
  var SpacesServiceImpl = class {
5662
6083
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5663
6084
  this._identityManager = _identityManager;
@@ -5700,8 +6121,8 @@ var SpacesServiceImpl = class {
5700
6121
  });
5701
6122
  }
5702
6123
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5703
- invariant15(credentials[0].credential, void 0, {
5704
- F: __dxlog_file21,
6124
+ invariant16(credentials[0].credential, void 0, {
6125
+ F: __dxlog_file22,
5705
6126
  L: 102,
5706
6127
  S: this,
5707
6128
  A: [
@@ -5710,8 +6131,8 @@ var SpacesServiceImpl = class {
5710
6131
  ]
5711
6132
  });
5712
6133
  const spaceMemberCredential = credentials[0].credential.credential;
5713
- invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5714
- F: __dxlog_file21,
6134
+ invariant16(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
6135
+ F: __dxlog_file22,
5715
6136
  L: 104,
5716
6137
  S: this,
5717
6138
  A: [
@@ -5726,10 +6147,10 @@ var SpacesServiceImpl = class {
5726
6147
  const scheduler = new UpdateScheduler(ctx, async () => {
5727
6148
  const dataSpaceManager = await this._getDataSpaceManager();
5728
6149
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5729
- log18("update", () => ({
6150
+ log19("update", () => ({
5730
6151
  ids: spaces.map((space) => space.id)
5731
6152
  }), {
5732
- F: __dxlog_file21,
6153
+ F: __dxlog_file22,
5733
6154
  L: 115,
5734
6155
  S: this,
5735
6156
  C: (f, a) => f(...a)
@@ -5820,8 +6241,8 @@ var SpacesServiceImpl = class {
5820
6241
  }
5821
6242
  });
5822
6243
  } else {
5823
- invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5824
- F: __dxlog_file21,
6244
+ invariant16(!credential.id, "Id on unsigned credentials is not allowed", {
6245
+ F: __dxlog_file22,
5825
6246
  L: 213,
5826
6247
  S: this,
5827
6248
  A: [
@@ -5829,8 +6250,8 @@ var SpacesServiceImpl = class {
5829
6250
  "'Id on unsigned credentials is not allowed'"
5830
6251
  ]
5831
6252
  });
5832
- invariant15(this._identityManager.identity, "Identity is not available", {
5833
- F: __dxlog_file21,
6253
+ invariant16(this._identityManager.identity, "Identity is not available", {
6254
+ F: __dxlog_file22,
5834
6255
  L: 214,
5835
6256
  S: this,
5836
6257
  A: [
@@ -5839,8 +6260,8 @@ var SpacesServiceImpl = class {
5839
6260
  ]
5840
6261
  });
5841
6262
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5842
- invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5843
- F: __dxlog_file21,
6263
+ invariant16(credential.issuer.equals(signer.getIssuer()), void 0, {
6264
+ F: __dxlog_file22,
5844
6265
  L: 216,
5845
6266
  S: this,
5846
6267
  A: [
@@ -5889,8 +6310,8 @@ var SpacesServiceImpl = class {
5889
6310
  }
5890
6311
  async _joinByAdmission({ credential }) {
5891
6312
  const assertion = getCredentialAssertion4(credential);
5892
- invariant15(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
5893
- F: __dxlog_file21,
6313
+ invariant16(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6314
+ F: __dxlog_file22,
5894
6315
  L: 250,
5895
6316
  S: this,
5896
6317
  A: [
@@ -5899,8 +6320,8 @@ var SpacesServiceImpl = class {
5899
6320
  ]
5900
6321
  });
5901
6322
  const myIdentity = this._identityManager.identity;
5902
- invariant15(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
5903
- F: __dxlog_file21,
6323
+ invariant16(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
6324
+ F: __dxlog_file22,
5904
6325
  L: 252,
5905
6326
  S: this,
5906
6327
  A: [
@@ -5988,16 +6409,16 @@ var getChannelId = (channel) => `user-channel/${channel}`;
5988
6409
 
5989
6410
  // packages/sdk/client-services/src/packlets/services/service-context.ts
5990
6411
  import { Trigger as Trigger9 } from "@dxos/async";
5991
- import { Context as Context10, Resource as Resource3 } from "@dxos/context";
6412
+ import { Context as Context9, Resource as Resource5 } from "@dxos/context";
5992
6413
  import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
5993
6414
  import { failUndefined as failUndefined2 } from "@dxos/debug";
5994
- import { EchoHost } from "@dxos/echo-db";
5995
- import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
6415
+ import { EchoEdgeReplicator, EchoHost } from "@dxos/echo-db";
6416
+ import { MeshEchoReplicator, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
5996
6417
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
5997
- import { invariant as invariant16 } from "@dxos/invariant";
6418
+ import { invariant as invariant17 } from "@dxos/invariant";
5998
6419
  import { Keyring } from "@dxos/keyring";
5999
- import { PublicKey as PublicKey12 } from "@dxos/keys";
6000
- import { log as log19 } from "@dxos/log";
6420
+ import { PublicKey as PublicKey13 } from "@dxos/keys";
6421
+ import { log as log20 } from "@dxos/log";
6001
6422
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
6002
6423
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
6003
6424
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -6013,18 +6434,21 @@ function _ts_decorate7(decorators, target, key, desc) {
6013
6434
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6014
6435
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6015
6436
  }
6016
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
6017
- var ServiceContext = class extends Resource3 {
6018
- constructor(storage, level, networkManager, signalManager, _runtimeParams) {
6437
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
6438
+ var ServiceContext = class extends Resource5 {
6439
+ constructor(storage, level, networkManager, signalManager, _edgeConnection, _runtimeParams) {
6019
6440
  super();
6020
6441
  this.storage = storage;
6021
6442
  this.level = level;
6022
6443
  this.networkManager = networkManager;
6023
6444
  this.signalManager = signalManager;
6445
+ this._edgeConnection = _edgeConnection;
6024
6446
  this._runtimeParams = _runtimeParams;
6025
6447
  this.initialized = new Trigger9();
6448
+ this._meshReplicator = void 0;
6449
+ this._echoEdgeReplicator = void 0;
6026
6450
  this._handlerFactories = /* @__PURE__ */ new Map();
6027
- this._instanceId = PublicKey12.random().toHex();
6451
+ this._instanceId = PublicKey13.random().toHex();
6028
6452
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
6029
6453
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
6030
6454
  this.blobStore = new BlobStore(storage.createDirectory("blobs"));
@@ -6044,7 +6468,8 @@ var ServiceContext = class extends Resource3 {
6044
6468
  networkManager: this.networkManager,
6045
6469
  blobStore: this.blobStore,
6046
6470
  metadataStore: this.metadataStore,
6047
- snapshotStore: this.snapshotStore
6471
+ snapshotStore: this.snapshotStore,
6472
+ disableP2pReplication: this._runtimeParams?.disableP2pReplication
6048
6473
  });
6049
6474
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
6050
6475
  this.echoHost = new EchoHost({
@@ -6053,26 +6478,41 @@ var ServiceContext = class extends Resource3 {
6053
6478
  this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
6054
6479
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
6055
6480
  this._handlerFactories.set(Invitation8.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
6481
+ if (!this._runtimeParams?.disableP2pReplication) {
6482
+ this._meshReplicator = new MeshEchoReplicator();
6483
+ }
6484
+ if (this._edgeConnection) {
6485
+ this._echoEdgeReplicator = new EchoEdgeReplicator({
6486
+ edgeConnection: this._edgeConnection
6487
+ });
6488
+ }
6056
6489
  }
6057
6490
  async _open(ctx) {
6058
6491
  await this._checkStorageVersion();
6059
- log19("opening...", void 0, {
6060
- F: __dxlog_file22,
6061
- L: 149,
6492
+ log20("opening...", void 0, {
6493
+ F: __dxlog_file23,
6494
+ L: 166,
6062
6495
  S: this,
6063
6496
  C: (f, a) => f(...a)
6064
6497
  });
6065
- log19.trace("dxos.sdk.service-context.open", trace9.begin({
6498
+ log20.trace("dxos.sdk.service-context.open", trace9.begin({
6066
6499
  id: this._instanceId
6067
6500
  }), {
6068
- F: __dxlog_file22,
6069
- L: 150,
6501
+ F: __dxlog_file23,
6502
+ L: 167,
6070
6503
  S: this,
6071
6504
  C: (f, a) => f(...a)
6072
6505
  });
6073
6506
  await this.signalManager.open();
6074
6507
  await this.networkManager.open();
6508
+ await this._edgeConnection?.open();
6075
6509
  await this.echoHost.open(ctx);
6510
+ if (this._meshReplicator) {
6511
+ await this.echoHost.addReplicator(this._meshReplicator);
6512
+ }
6513
+ if (this._echoEdgeReplicator) {
6514
+ await this.echoHost.addReplicator(this._echoEdgeReplicator);
6515
+ }
6076
6516
  await this.metadataStore.load();
6077
6517
  await this.spaceManager.open();
6078
6518
  await this.identityManager.open(ctx);
@@ -6080,33 +6520,33 @@ var ServiceContext = class extends Resource3 {
6080
6520
  await this._initialize(ctx);
6081
6521
  }
6082
6522
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
6083
- log19("loaded persistent invitations", {
6523
+ log20("loaded persistent invitations", {
6084
6524
  count: loadedInvitations.invitations?.length
6085
6525
  }, {
6086
- F: __dxlog_file22,
6087
- L: 163,
6526
+ F: __dxlog_file23,
6527
+ L: 189,
6088
6528
  S: this,
6089
6529
  C: (f, a) => f(...a)
6090
6530
  });
6091
- log19.trace("dxos.sdk.service-context.open", trace9.end({
6531
+ log20.trace("dxos.sdk.service-context.open", trace9.end({
6092
6532
  id: this._instanceId
6093
6533
  }), {
6094
- F: __dxlog_file22,
6095
- L: 165,
6534
+ F: __dxlog_file23,
6535
+ L: 191,
6096
6536
  S: this,
6097
6537
  C: (f, a) => f(...a)
6098
6538
  });
6099
- log19("opened", void 0, {
6100
- F: __dxlog_file22,
6101
- L: 166,
6539
+ log20("opened", void 0, {
6540
+ F: __dxlog_file23,
6541
+ L: 192,
6102
6542
  S: this,
6103
6543
  C: (f, a) => f(...a)
6104
6544
  });
6105
6545
  }
6106
6546
  async _close(ctx) {
6107
- log19("closing...", void 0, {
6108
- F: __dxlog_file22,
6109
- L: 170,
6547
+ log20("closing...", void 0, {
6548
+ F: __dxlog_file23,
6549
+ L: 196,
6110
6550
  S: this,
6111
6551
  C: (f, a) => f(...a)
6112
6552
  });
@@ -6121,26 +6561,27 @@ var ServiceContext = class extends Resource3 {
6121
6561
  await this.echoHost.close(ctx);
6122
6562
  await this.networkManager.close();
6123
6563
  await this.signalManager.close();
6124
- log19("closed", void 0, {
6125
- F: __dxlog_file22,
6126
- L: 182,
6564
+ await this._edgeConnection?.close();
6565
+ log20("closed", void 0, {
6566
+ F: __dxlog_file23,
6567
+ L: 211,
6127
6568
  S: this,
6128
6569
  C: (f, a) => f(...a)
6129
6570
  });
6130
6571
  }
6131
6572
  async createIdentity(params = {}) {
6132
6573
  const identity = await this.identityManager.createIdentity(params);
6133
- await this._initialize(new Context10(void 0, {
6134
- F: __dxlog_file22,
6135
- L: 187
6574
+ await this._initialize(new Context9(void 0, {
6575
+ F: __dxlog_file23,
6576
+ L: 216
6136
6577
  }));
6137
6578
  return identity;
6138
6579
  }
6139
6580
  getInvitationHandler(invitation) {
6140
6581
  const factory = this._handlerFactories.get(invitation.kind);
6141
- invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
6142
- F: __dxlog_file22,
6143
- L: 193,
6582
+ invariant17(factory, `Unknown invitation kind: ${invitation.kind}`, {
6583
+ F: __dxlog_file23,
6584
+ L: 222,
6144
6585
  S: this,
6145
6586
  A: [
6146
6587
  "factory",
@@ -6159,9 +6600,9 @@ var ServiceContext = class extends Resource3 {
6159
6600
  }
6160
6601
  async _acceptIdentity(params) {
6161
6602
  const identity = await this.identityManager.acceptIdentity(params);
6162
- await this._initialize(new Context10(void 0, {
6163
- F: __dxlog_file22,
6164
- L: 209
6603
+ await this._initialize(new Context9(void 0, {
6604
+ F: __dxlog_file23,
6605
+ L: 238
6165
6606
  }));
6166
6607
  return identity;
6167
6608
  }
@@ -6173,9 +6614,9 @@ var ServiceContext = class extends Resource3 {
6173
6614
  }
6174
6615
  // Called when identity is created.
6175
6616
  async _initialize(ctx) {
6176
- log19("initializing spaces...", void 0, {
6177
- F: __dxlog_file22,
6178
- L: 224,
6617
+ log20("initializing spaces...", void 0, {
6618
+ F: __dxlog_file23,
6619
+ L: 253,
6179
6620
  S: this,
6180
6621
  C: (f, a) => f(...a)
6181
6622
  });
@@ -6193,12 +6634,24 @@ var ServiceContext = class extends Resource3 {
6193
6634
  });
6194
6635
  }
6195
6636
  };
6196
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
6637
+ this.dataSpaceManager = new DataSpaceManager({
6638
+ spaceManager: this.spaceManager,
6639
+ metadataStore: this.metadataStore,
6640
+ keyring: this.keyring,
6641
+ signingContext,
6642
+ feedStore: this.feedStore,
6643
+ echoHost: this.echoHost,
6644
+ invitationsManager: this.invitationsManager,
6645
+ edgeConnection: this._edgeConnection,
6646
+ echoEdgeReplicator: this._echoEdgeReplicator,
6647
+ meshReplicator: this._meshReplicator,
6648
+ runtimeParams: this._runtimeParams
6649
+ });
6197
6650
  await this.dataSpaceManager.open();
6198
6651
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
6199
- invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
6200
- F: __dxlog_file22,
6201
- L: 249,
6652
+ invariant17(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
6653
+ F: __dxlog_file23,
6654
+ L: 281,
6202
6655
  S: this,
6203
6656
  A: [
6204
6657
  "this.dataSpaceManager",
@@ -6218,33 +6671,33 @@ var ServiceContext = class extends Resource3 {
6218
6671
  return;
6219
6672
  }
6220
6673
  if (!this.dataSpaceManager) {
6221
- log19("dataSpaceManager not initialized yet, ignoring space admission", {
6674
+ log20("dataSpaceManager not initialized yet, ignoring space admission", {
6222
6675
  details: assertion
6223
6676
  }, {
6224
- F: __dxlog_file22,
6225
- L: 265,
6677
+ F: __dxlog_file23,
6678
+ L: 297,
6226
6679
  S: this,
6227
6680
  C: (f, a) => f(...a)
6228
6681
  });
6229
6682
  return;
6230
6683
  }
6231
6684
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
6232
- log19("space already exists, ignoring space admission", {
6685
+ log20("space already exists, ignoring space admission", {
6233
6686
  details: assertion
6234
6687
  }, {
6235
- F: __dxlog_file22,
6236
- L: 269,
6688
+ F: __dxlog_file23,
6689
+ L: 301,
6237
6690
  S: this,
6238
6691
  C: (f, a) => f(...a)
6239
6692
  });
6240
6693
  return;
6241
6694
  }
6242
6695
  try {
6243
- log19("accepting space recorded in halo", {
6696
+ log20("accepting space recorded in halo", {
6244
6697
  details: assertion
6245
6698
  }, {
6246
- F: __dxlog_file22,
6247
- L: 274,
6699
+ F: __dxlog_file23,
6700
+ L: 306,
6248
6701
  S: this,
6249
6702
  C: (f, a) => f(...a)
6250
6703
  });
@@ -6253,9 +6706,9 @@ var ServiceContext = class extends Resource3 {
6253
6706
  genesisFeedKey: assertion.genesisFeedKey
6254
6707
  });
6255
6708
  } catch (err) {
6256
- log19.catch(err, void 0, {
6257
- F: __dxlog_file22,
6258
- L: 280,
6709
+ log20.catch(err, void 0, {
6710
+ F: __dxlog_file23,
6711
+ L: 312,
6259
6712
  S: this,
6260
6713
  C: (f, a) => f(...a)
6261
6714
  });
@@ -6364,11 +6817,11 @@ var toStorageType = (type) => {
6364
6817
 
6365
6818
  // packages/sdk/client-services/src/packlets/storage/level.ts
6366
6819
  import path from "@dxos/node-std/path";
6367
- import { PublicKey as PublicKey13 } from "@dxos/keys";
6820
+ import { PublicKey as PublicKey14 } from "@dxos/keys";
6368
6821
  import { createLevel as createKV } from "@dxos/kv-store";
6369
6822
  var createLevel = async (config) => {
6370
6823
  const persistent = isPersistent(config);
6371
- const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
6824
+ const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey14.random().toHex()}`;
6372
6825
  const level = createKV(storagePath);
6373
6826
  await level.open();
6374
6827
  return level;
@@ -6376,11 +6829,11 @@ var createLevel = async (config) => {
6376
6829
 
6377
6830
  // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6378
6831
  import { cbor } from "@dxos/automerge/automerge-repo";
6379
- import { invariant as invariant17 } from "@dxos/invariant";
6380
- import { log as log20 } from "@dxos/log";
6832
+ import { invariant as invariant18 } from "@dxos/invariant";
6833
+ import { log as log21 } from "@dxos/log";
6381
6834
  import { ProfileArchiveEntryType } from "@dxos/protocols";
6382
- import { arrayToBuffer } from "@dxos/util";
6383
- var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6835
+ import { arrayToBuffer as arrayToBuffer2 } from "@dxos/util";
6836
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6384
6837
  var encodeProfileArchive = (profile) => cbor.encode(profile);
6385
6838
  var decodeProfileArchive = (data) => cbor.decode(data);
6386
6839
  var exportProfileData = async ({ storage, level }) => {
@@ -6393,10 +6846,10 @@ var exportProfileData = async ({ storage, level }) => {
6393
6846
  {
6394
6847
  const directory = await storage.createDirectory();
6395
6848
  const files = await directory.list();
6396
- log20.info("begin exporting files", {
6849
+ log21.info("begin exporting files", {
6397
6850
  count: files.length
6398
6851
  }, {
6399
- F: __dxlog_file23,
6852
+ F: __dxlog_file24,
6400
6853
  L: 30,
6401
6854
  S: void 0,
6402
6855
  C: (f, a) => f(...a)
@@ -6411,18 +6864,18 @@ var exportProfileData = async ({ storage, level }) => {
6411
6864
  value: data
6412
6865
  });
6413
6866
  }
6414
- log20.info("done exporting files", {
6867
+ log21.info("done exporting files", {
6415
6868
  count: files.length
6416
6869
  }, {
6417
- F: __dxlog_file23,
6870
+ F: __dxlog_file24,
6418
6871
  L: 41,
6419
6872
  S: void 0,
6420
6873
  C: (f, a) => f(...a)
6421
6874
  });
6422
6875
  }
6423
6876
  {
6424
- log20.info("begin exporting kv pairs", void 0, {
6425
- F: __dxlog_file23,
6877
+ log21.info("begin exporting kv pairs", void 0, {
6878
+ F: __dxlog_file24,
6426
6879
  L: 45,
6427
6880
  S: void 0,
6428
6881
  C: (f, a) => f(...a)
@@ -6440,10 +6893,10 @@ var exportProfileData = async ({ storage, level }) => {
6440
6893
  });
6441
6894
  count++;
6442
6895
  }
6443
- log20.info("done exporting kv pairs", {
6896
+ log21.info("done exporting kv pairs", {
6444
6897
  count
6445
6898
  }, {
6446
- F: __dxlog_file23,
6899
+ F: __dxlog_file24,
6447
6900
  L: 56,
6448
6901
  S: void 0,
6449
6902
  C: (f, a) => f(...a)
@@ -6458,8 +6911,8 @@ var importProfileData = async ({ storage, level }, archive) => {
6458
6911
  switch (entry2.type) {
6459
6912
  case ProfileArchiveEntryType.FILE: {
6460
6913
  const directory = await storage.createDirectory();
6461
- invariant17(typeof entry2.key === "string", "Invalid key type", {
6462
- F: __dxlog_file23,
6914
+ invariant18(typeof entry2.key === "string", "Invalid key type", {
6915
+ F: __dxlog_file24,
6463
6916
  L: 79,
6464
6917
  S: void 0,
6465
6918
  A: [
@@ -6468,8 +6921,8 @@ var importProfileData = async ({ storage, level }, archive) => {
6468
6921
  ]
6469
6922
  });
6470
6923
  const file = await directory.getOrCreateFile(entry2.key);
6471
- invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6472
- F: __dxlog_file23,
6924
+ invariant18(entry2.value instanceof Uint8Array, "Invalid value type", {
6925
+ F: __dxlog_file24,
6473
6926
  L: 81,
6474
6927
  S: void 0,
6475
6928
  A: [
@@ -6477,13 +6930,13 @@ var importProfileData = async ({ storage, level }, archive) => {
6477
6930
  "'Invalid value type'"
6478
6931
  ]
6479
6932
  });
6480
- await file.write(0, arrayToBuffer(entry2.value));
6933
+ await file.write(0, arrayToBuffer2(entry2.value));
6481
6934
  await file.close();
6482
6935
  break;
6483
6936
  }
6484
6937
  case ProfileArchiveEntryType.KEY_VALUE: {
6485
- invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6486
- F: __dxlog_file23,
6938
+ invariant18(entry2.key instanceof Uint8Array, "Invalid key type", {
6939
+ F: __dxlog_file24,
6487
6940
  L: 87,
6488
6941
  S: void 0,
6489
6942
  A: [
@@ -6491,8 +6944,8 @@ var importProfileData = async ({ storage, level }, archive) => {
6491
6944
  "'Invalid key type'"
6492
6945
  ]
6493
6946
  });
6494
- invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6495
- F: __dxlog_file23,
6947
+ invariant18(entry2.value instanceof Uint8Array, "Invalid value type", {
6948
+ F: __dxlog_file24,
6496
6949
  L: 88,
6497
6950
  S: void 0,
6498
6951
  A: [
@@ -6512,20 +6965,20 @@ var importProfileData = async ({ storage, level }, archive) => {
6512
6965
  if (++count % 1e3 === 0) {
6513
6966
  await batch.write();
6514
6967
  batch = level.batch();
6515
- log20.info("importing", {
6968
+ log21.info("importing", {
6516
6969
  count,
6517
6970
  total: archive.storage.length,
6518
6971
  progress: `${(count / archive.storage.length * 100).toFixed()}%`
6519
6972
  }, {
6520
- F: __dxlog_file23,
6973
+ F: __dxlog_file24,
6521
6974
  L: 101,
6522
6975
  S: void 0,
6523
6976
  C: (f, a) => f(...a)
6524
6977
  });
6525
6978
  }
6526
6979
  }
6527
- log20.info("committing changes..", void 0, {
6528
- F: __dxlog_file23,
6980
+ log21.info("committing changes..", void 0, {
6981
+ F: __dxlog_file24,
6529
6982
  L: 109,
6530
6983
  S: void 0,
6531
6984
  C: (f, a) => f(...a)
@@ -6534,14 +6987,15 @@ var importProfileData = async ({ storage, level }, archive) => {
6534
6987
  };
6535
6988
 
6536
6989
  // packages/sdk/client-services/src/packlets/services/service-host.ts
6537
- import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
6990
+ import { Event as Event10, synchronized as synchronized3 } from "@dxos/async";
6538
6991
  import { clientServiceBundle } from "@dxos/client-protocol";
6539
- import { Context as Context11 } from "@dxos/context";
6540
- import { invariant as invariant19 } from "@dxos/invariant";
6541
- import { PublicKey as PublicKey16 } from "@dxos/keys";
6542
- import { log as log22 } from "@dxos/log";
6992
+ import { Context as Context10 } from "@dxos/context";
6993
+ import { EdgeClient } from "@dxos/edge-client";
6994
+ import { invariant as invariant20 } from "@dxos/invariant";
6995
+ import { PublicKey as PublicKey17 } from "@dxos/keys";
6996
+ import { log as log23 } from "@dxos/log";
6543
6997
  import { WebsocketSignalManager } from "@dxos/messaging";
6544
- import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
6998
+ import { SwarmNetworkManager, createIceProvider, createSimplePeerTransportFactory } from "@dxos/network-manager";
6545
6999
  import { trace as trace10 } from "@dxos/protocols";
6546
7000
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
6547
7001
  import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
@@ -6550,9 +7004,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
6550
7004
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
6551
7005
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
6552
7006
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
6553
- import { invariant as invariant18 } from "@dxos/invariant";
7007
+ import { invariant as invariant19 } from "@dxos/invariant";
6554
7008
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
6555
- var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
7009
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6556
7010
  var DevicesServiceImpl = class {
6557
7011
  constructor(_identityManager) {
6558
7012
  this._identityManager = _identityManager;
@@ -6569,8 +7023,8 @@ var DevicesServiceImpl = class {
6569
7023
  devices: []
6570
7024
  });
6571
7025
  } else {
6572
- invariant18(this._identityManager.identity?.presence, "presence not present", {
6573
- F: __dxlog_file24,
7026
+ invariant19(this._identityManager.identity?.presence, "presence not present", {
7027
+ F: __dxlog_file25,
6574
7028
  L: 32,
6575
7029
  S: this,
6576
7030
  A: [
@@ -6632,8 +7086,8 @@ var DevicesServiceImpl = class {
6632
7086
  // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
6633
7087
  import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask7, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
6634
7088
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
6635
- import { PublicKey as PublicKey14 } from "@dxos/keys";
6636
- import { ComplexMap as ComplexMap4, ComplexSet as ComplexSet6 } from "@dxos/util";
7089
+ import { PublicKey as PublicKey15 } from "@dxos/keys";
7090
+ import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
6637
7091
  var ContactsServiceImpl = class {
6638
7092
  constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
6639
7093
  this._identityManager = _identityManager;
@@ -6673,7 +7127,7 @@ var ContactsServiceImpl = class {
6673
7127
  });
6674
7128
  }
6675
7129
  return acc;
6676
- }, new ComplexMap4(PublicKey14.hash));
7130
+ }, new ComplexMap5(PublicKey15.hash));
6677
7131
  return {
6678
7132
  contacts: [
6679
7133
  ...contacts.values()
@@ -6681,7 +7135,7 @@ var ContactsServiceImpl = class {
6681
7135
  };
6682
7136
  }
6683
7137
  queryContacts() {
6684
- const subscribedSpaceKeySet = new ComplexSet6(PublicKey14.hash);
7138
+ const subscribedSpaceKeySet = new ComplexSet6(PublicKey15.hash);
6685
7139
  return new Stream12(({ next, ctx }) => {
6686
7140
  const pushUpdateTask = new UpdateScheduler2(ctx, async () => {
6687
7141
  const contacts = await this.getContacts();
@@ -6713,27 +7167,27 @@ var ContactsServiceImpl = class {
6713
7167
  };
6714
7168
 
6715
7169
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
6716
- import { Event as Event8 } from "@dxos/async";
7170
+ import { Event as Event9 } from "@dxos/async";
6717
7171
  import { Stream as Stream13 } from "@dxos/codec-protobuf";
6718
- import { PublicKey as PublicKey15 } from "@dxos/keys";
6719
- import { getContextFromEntry, log as log21 } from "@dxos/log";
7172
+ import { PublicKey as PublicKey16 } from "@dxos/keys";
7173
+ import { getContextFromEntry, log as log22 } from "@dxos/log";
6720
7174
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
6721
7175
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
6722
7176
  var LoggingServiceImpl = class {
6723
7177
  constructor() {
6724
- this._logs = new Event8();
7178
+ this._logs = new Event9();
6725
7179
  this._started = Date.now();
6726
- this._sessionId = PublicKey15.random().toHex();
7180
+ this._sessionId = PublicKey16.random().toHex();
6727
7181
  this._logProcessor = (_config, entry2) => {
6728
7182
  this._logs.emit(entry2);
6729
7183
  };
6730
7184
  }
6731
7185
  async open() {
6732
- log21.runtimeConfig.processors.push(this._logProcessor);
7186
+ log22.runtimeConfig.processors.push(this._logProcessor);
6733
7187
  }
6734
7188
  async close() {
6735
- const index = log21.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6736
- log21.runtimeConfig.processors.splice(index, 1);
7189
+ const index = log22.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
7190
+ log22.runtimeConfig.processors.splice(index, 1);
6737
7191
  }
6738
7192
  async controlMetrics({ reset, record }) {
6739
7193
  if (reset) {
@@ -6937,7 +7391,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6937
7391
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6938
7392
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6939
7393
  }
6940
- var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
7394
+ var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6941
7395
  var ClientServicesHost = class {
6942
7396
  constructor({
6943
7397
  config,
@@ -6951,13 +7405,17 @@ var ClientServicesHost = class {
6951
7405
  runtimeParams
6952
7406
  } = {}) {
6953
7407
  this._tracingService = TRACE_PROCESSOR3.createTraceSender();
6954
- this._statusUpdate = new Event9();
7408
+ this._statusUpdate = new Event10();
7409
+ this._edgeConnection = void 0;
6955
7410
  this._opening = false;
6956
7411
  this._open = false;
6957
7412
  this._storage = storage;
6958
7413
  this._level = level;
6959
7414
  this._callbacks = callbacks;
6960
7415
  this._runtimeParams = runtimeParams ?? {};
7416
+ if (this._runtimeParams.disableP2pReplication === void 0) {
7417
+ this._runtimeParams.disableP2pReplication = config?.get("runtime.client.disableP2pReplication", false);
7418
+ }
6961
7419
  if (config) {
6962
7420
  this.initialize({
6963
7421
  config,
@@ -6970,9 +7428,9 @@ var ClientServicesHost = class {
6970
7428
  lockKey,
6971
7429
  onAcquire: () => {
6972
7430
  if (!this._opening) {
6973
- void this.open(new Context11(void 0, {
6974
- F: __dxlog_file25,
6975
- L: 121
7431
+ void this.open(new Context10(void 0, {
7432
+ F: __dxlog_file26,
7433
+ L: 132
6976
7434
  }));
6977
7435
  }
6978
7436
  },
@@ -7028,25 +7486,25 @@ var ClientServicesHost = class {
7028
7486
  * Can only be called once.
7029
7487
  */
7030
7488
  initialize({ config, ...options }) {
7031
- invariant19(!this._open, "service host is open", {
7032
- F: __dxlog_file25,
7033
- L: 187,
7489
+ invariant20(!this._open, "service host is open", {
7490
+ F: __dxlog_file26,
7491
+ L: 198,
7034
7492
  S: this,
7035
7493
  A: [
7036
7494
  "!this._open",
7037
7495
  "'service host is open'"
7038
7496
  ]
7039
7497
  });
7040
- log22("initializing...", void 0, {
7041
- F: __dxlog_file25,
7042
- L: 188,
7498
+ log23("initializing...", void 0, {
7499
+ F: __dxlog_file26,
7500
+ L: 199,
7043
7501
  S: this,
7044
7502
  C: (f, a) => f(...a)
7045
7503
  });
7046
7504
  if (config) {
7047
- invariant19(!this._config, "config already set", {
7048
- F: __dxlog_file25,
7049
- L: 191,
7505
+ invariant20(!this._config, "config already set", {
7506
+ F: __dxlog_file26,
7507
+ L: 202,
7050
7508
  S: this,
7051
7509
  A: [
7052
7510
  "!this._config",
@@ -7059,20 +7517,20 @@ var ClientServicesHost = class {
7059
7517
  }
7060
7518
  }
7061
7519
  if (!options.signalManager) {
7062
- log22.warn("running signaling without telemetry metadata.", void 0, {
7063
- F: __dxlog_file25,
7064
- L: 199,
7520
+ log23.warn("running signaling without telemetry metadata.", void 0, {
7521
+ F: __dxlog_file26,
7522
+ L: 210,
7065
7523
  S: this,
7066
7524
  C: (f, a) => f(...a)
7067
7525
  });
7068
7526
  }
7069
7527
  const { connectionLog = true, transportFactory = createSimplePeerTransportFactory({
7070
7528
  iceServers: this._config?.get("runtime.services.ice")
7071
- }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
7529
+ }, this._config?.get("runtime.services.iceProviders") && createIceProvider(this._config.get("runtime.services.iceProviders"))), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
7072
7530
  this._signalManager = signalManager;
7073
- invariant19(!this._networkManager, "network manager already set", {
7074
- F: __dxlog_file25,
7075
- L: 210,
7531
+ invariant20(!this._networkManager, "network manager already set", {
7532
+ F: __dxlog_file26,
7533
+ L: 223,
7076
7534
  S: this,
7077
7535
  A: [
7078
7536
  "!this._networkManager",
@@ -7084,9 +7542,15 @@ var ClientServicesHost = class {
7084
7542
  transportFactory,
7085
7543
  signalManager
7086
7544
  });
7087
- log22("initialized", void 0, {
7088
- F: __dxlog_file25,
7089
- L: 217,
7545
+ const edgeEndpoint = config?.get("runtime.services.edge.url");
7546
+ if (edgeEndpoint) {
7547
+ this._edgeConnection = new EdgeClient(PublicKey17.random(), PublicKey17.random(), {
7548
+ socketEndpoint: edgeEndpoint
7549
+ });
7550
+ }
7551
+ log23("initialized", void 0, {
7552
+ F: __dxlog_file26,
7553
+ L: 238,
7090
7554
  S: this,
7091
7555
  C: (f, a) => f(...a)
7092
7556
  });
@@ -7095,45 +7559,45 @@ var ClientServicesHost = class {
7095
7559
  if (this._open) {
7096
7560
  return;
7097
7561
  }
7098
- const traceId = PublicKey16.random().toHex();
7099
- log22.trace("dxos.client-services.host.open", trace10.begin({
7562
+ const traceId = PublicKey17.random().toHex();
7563
+ log23.trace("dxos.client-services.host.open", trace10.begin({
7100
7564
  id: traceId
7101
7565
  }), {
7102
- F: __dxlog_file25,
7103
- L: 228,
7566
+ F: __dxlog_file26,
7567
+ L: 249,
7104
7568
  S: this,
7105
7569
  C: (f, a) => f(...a)
7106
7570
  });
7107
- invariant19(this._config, "config not set", {
7108
- F: __dxlog_file25,
7109
- L: 230,
7571
+ invariant20(this._config, "config not set", {
7572
+ F: __dxlog_file26,
7573
+ L: 251,
7110
7574
  S: this,
7111
7575
  A: [
7112
7576
  "this._config",
7113
7577
  "'config not set'"
7114
7578
  ]
7115
7579
  });
7116
- invariant19(this._storage, "storage not set", {
7117
- F: __dxlog_file25,
7118
- L: 231,
7580
+ invariant20(this._storage, "storage not set", {
7581
+ F: __dxlog_file26,
7582
+ L: 252,
7119
7583
  S: this,
7120
7584
  A: [
7121
7585
  "this._storage",
7122
7586
  "'storage not set'"
7123
7587
  ]
7124
7588
  });
7125
- invariant19(this._signalManager, "signal manager not set", {
7126
- F: __dxlog_file25,
7127
- L: 232,
7589
+ invariant20(this._signalManager, "signal manager not set", {
7590
+ F: __dxlog_file26,
7591
+ L: 253,
7128
7592
  S: this,
7129
7593
  A: [
7130
7594
  "this._signalManager",
7131
7595
  "'signal manager not set'"
7132
7596
  ]
7133
7597
  });
7134
- invariant19(this._networkManager, "network manager not set", {
7135
- F: __dxlog_file25,
7136
- L: 233,
7598
+ invariant20(this._networkManager, "network manager not set", {
7599
+ F: __dxlog_file26,
7600
+ L: 254,
7137
7601
  S: this,
7138
7602
  A: [
7139
7603
  "this._networkManager",
@@ -7141,11 +7605,11 @@ var ClientServicesHost = class {
7141
7605
  ]
7142
7606
  });
7143
7607
  this._opening = true;
7144
- log22("opening...", {
7608
+ log23("opening...", {
7145
7609
  lockKey: this._resourceLock?.lockKey
7146
7610
  }, {
7147
- F: __dxlog_file25,
7148
- L: 236,
7611
+ F: __dxlog_file26,
7612
+ L: 257,
7149
7613
  S: this,
7150
7614
  C: (f, a) => f(...a)
7151
7615
  });
@@ -7155,7 +7619,7 @@ var ClientServicesHost = class {
7155
7619
  }
7156
7620
  await this._level.open();
7157
7621
  await this._loggingService.open();
7158
- this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
7622
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._edgeConnection, this._runtimeParams);
7159
7623
  const dataSpaceManagerProvider = async () => {
7160
7624
  await this._serviceContext.initialized.wait();
7161
7625
  return this._serviceContext.dataSpaceManager;
@@ -7197,19 +7661,19 @@ var ClientServicesHost = class {
7197
7661
  this._open = true;
7198
7662
  this._statusUpdate.emit();
7199
7663
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
7200
- log22("opened", {
7664
+ log23("opened", {
7201
7665
  deviceKey
7202
7666
  }, {
7203
- F: __dxlog_file25,
7204
- L: 322,
7667
+ F: __dxlog_file26,
7668
+ L: 344,
7205
7669
  S: this,
7206
7670
  C: (f, a) => f(...a)
7207
7671
  });
7208
- log22.trace("dxos.client-services.host.open", trace10.end({
7672
+ log23.trace("dxos.client-services.host.open", trace10.end({
7209
7673
  id: traceId
7210
7674
  }), {
7211
- F: __dxlog_file25,
7212
- L: 323,
7675
+ F: __dxlog_file26,
7676
+ L: 345,
7213
7677
  S: this,
7214
7678
  C: (f, a) => f(...a)
7215
7679
  });
@@ -7219,11 +7683,11 @@ var ClientServicesHost = class {
7219
7683
  return;
7220
7684
  }
7221
7685
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
7222
- log22("closing...", {
7686
+ log23("closing...", {
7223
7687
  deviceKey
7224
7688
  }, {
7225
- F: __dxlog_file25,
7226
- L: 334,
7689
+ F: __dxlog_file26,
7690
+ L: 356,
7227
7691
  S: this,
7228
7692
  C: (f, a) => f(...a)
7229
7693
  });
@@ -7237,44 +7701,44 @@ var ClientServicesHost = class {
7237
7701
  await this._level?.close();
7238
7702
  this._open = false;
7239
7703
  this._statusUpdate.emit();
7240
- log22("closed", {
7704
+ log23("closed", {
7241
7705
  deviceKey
7242
7706
  }, {
7243
- F: __dxlog_file25,
7244
- L: 343,
7707
+ F: __dxlog_file26,
7708
+ L: 365,
7245
7709
  S: this,
7246
7710
  C: (f, a) => f(...a)
7247
7711
  });
7248
7712
  }
7249
7713
  async reset() {
7250
- const traceId = PublicKey16.random().toHex();
7251
- log22.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7714
+ const traceId = PublicKey17.random().toHex();
7715
+ log23.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7252
7716
  id: traceId
7253
7717
  }), {
7254
- F: __dxlog_file25,
7255
- L: 348,
7718
+ F: __dxlog_file26,
7719
+ L: 370,
7256
7720
  S: this,
7257
7721
  C: (f, a) => f(...a)
7258
7722
  });
7259
- log22.info("resetting...", void 0, {
7260
- F: __dxlog_file25,
7261
- L: 350,
7723
+ log23.info("resetting...", void 0, {
7724
+ F: __dxlog_file26,
7725
+ L: 372,
7262
7726
  S: this,
7263
7727
  C: (f, a) => f(...a)
7264
7728
  });
7265
7729
  await this._serviceContext?.close();
7266
7730
  await this._storage.reset();
7267
- log22.info("reset", void 0, {
7268
- F: __dxlog_file25,
7269
- L: 353,
7731
+ log23.info("reset", void 0, {
7732
+ F: __dxlog_file26,
7733
+ L: 375,
7270
7734
  S: this,
7271
7735
  C: (f, a) => f(...a)
7272
7736
  });
7273
- log22.trace("dxos.sdk.client-services-host.reset", trace10.end({
7737
+ log23.trace("dxos.sdk.client-services-host.reset", trace10.end({
7274
7738
  id: traceId
7275
7739
  }), {
7276
- F: __dxlog_file25,
7277
- L: 354,
7740
+ F: __dxlog_file26,
7741
+ L: 376,
7278
7742
  S: this,
7279
7743
  C: (f, a) => f(...a)
7280
7744
  });
@@ -7334,6 +7798,7 @@ export {
7334
7798
  Lock,
7335
7799
  isLocked,
7336
7800
  ClientRpcServer,
7801
+ EdgeFeedReplicator,
7337
7802
  DataSpace,
7338
7803
  DataSpaceManager,
7339
7804
  SpacesServiceImpl,
@@ -7347,4 +7812,4 @@ export {
7347
7812
  importProfileData,
7348
7813
  ClientServicesHost
7349
7814
  };
7350
- //# sourceMappingURL=chunk-GIAH3RXX.mjs.map
7815
+ //# sourceMappingURL=chunk-ZMCIQNPA.mjs.map