@dxos/client-services 0.8.4-main.21d9917 → 0.8.4-main.2244d791bb

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 (38) hide show
  1. package/dist/lib/browser/{chunk-QWDES2YZ.mjs → chunk-KEV65JXY.mjs} +369 -100
  2. package/dist/lib/browser/chunk-KEV65JXY.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +19 -11
  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 +1 -1
  7. package/dist/lib/node-esm/{chunk-2ZEVKBWH.mjs → chunk-GXBTHFMG.mjs} +369 -100
  8. package/dist/lib/node-esm/chunk-GXBTHFMG.mjs.map +7 -0
  9. package/dist/lib/node-esm/index.mjs +19 -11
  10. package/dist/lib/node-esm/index.mjs.map +3 -3
  11. package/dist/lib/node-esm/meta.json +1 -1
  12. package/dist/lib/node-esm/testing/index.mjs +1 -1
  13. package/dist/types/src/packlets/logging/logging-service.d.ts +4 -0
  14. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  15. package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
  16. package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
  17. package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
  18. package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
  19. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-context.d.ts +1 -1
  21. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  23. package/dist/types/src/packlets/worker/worker-runtime.d.ts +11 -3
  24. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  25. package/dist/types/src/version.d.ts +1 -1
  26. package/dist/types/src/version.d.ts.map +1 -1
  27. package/dist/types/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +43 -43
  29. package/src/packlets/logging/logging-service.ts +4 -0
  30. package/src/packlets/services/feed-syncer.test.ts +340 -0
  31. package/src/packlets/services/feed-syncer.ts +330 -0
  32. package/src/packlets/services/platform.ts +7 -1
  33. package/src/packlets/services/service-context.ts +29 -6
  34. package/src/packlets/spaces/data-space.ts +3 -0
  35. package/src/packlets/worker/worker-runtime.ts +13 -5
  36. package/src/version.ts +1 -1
  37. package/dist/lib/browser/chunk-QWDES2YZ.mjs.map +0 -7
  38. package/dist/lib/node-esm/chunk-2ZEVKBWH.mjs.map +0 -7
@@ -403,7 +403,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
403
403
  import { TRACE_PROCESSOR } from "@dxos/tracing";
404
404
 
405
405
  // src/version.ts
406
- var DXOS_VERSION = "0.8.4-main.21d9917";
406
+ var DXOS_VERSION = "0.8.4-main.2244d791bb";
407
407
 
408
408
  // src/packlets/services/platform.ts
409
409
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -416,11 +416,16 @@ var getPlatform = () => {
416
416
  userAgent,
417
417
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
418
418
  };
419
- } else {
419
+ } else if (typeof SharedWorkerGlobalScope !== "undefined") {
420
420
  return {
421
421
  type: Platform.PLATFORM_TYPE.SHARED_WORKER,
422
422
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
423
423
  };
424
+ } else {
425
+ return {
426
+ type: Platform.PLATFORM_TYPE.DEDICATED_WORKER,
427
+ uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
428
+ };
424
429
  }
425
430
  } else {
426
431
  const { platform: platform2, version, arch } = process;
@@ -4708,9 +4713,12 @@ var DataSpace = class {
4708
4713
  C: (f, a) => f(...a)
4709
4714
  });
4710
4715
  } catch (err) {
4716
+ if (err instanceof ContextDisposedError) {
4717
+ return;
4718
+ }
4711
4719
  log12.error("error notarizing credentials for feed admission", err, {
4712
4720
  F: __dxlog_file15,
4713
- L: 453,
4721
+ L: 456,
4714
4722
  S: this,
4715
4723
  C: (f, a) => f(...a)
4716
4724
  });
@@ -4725,7 +4733,7 @@ var DataSpace = class {
4725
4733
  rootUrl
4726
4734
  }, {
4727
4735
  F: __dxlog_file15,
4728
- L: 463,
4736
+ L: 466,
4729
4737
  S: this,
4730
4738
  C: (f, a) => f(...a)
4731
4739
  });
@@ -4741,7 +4749,7 @@ var DataSpace = class {
4741
4749
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4742
4750
  handle = await cancelWithContext2(this._ctx, this._echoHost.loadDoc(Context6.default(void 0, {
4743
4751
  F: __dxlog_file15,
4744
- L: 473
4752
+ L: 476
4745
4753
  }), rootUrl, {
4746
4754
  fetchFromNetwork: true
4747
4755
  }));
@@ -4785,7 +4793,7 @@ var DataSpace = class {
4785
4793
  err
4786
4794
  }, {
4787
4795
  F: __dxlog_file15,
4788
- L: 512,
4796
+ L: 515,
4789
4797
  S: this,
4790
4798
  C: (f, a) => f(...a)
4791
4799
  });
@@ -4875,7 +4883,7 @@ var DataSpace = class {
4875
4883
  state: SpaceState4[this._state]
4876
4884
  }, {
4877
4885
  F: __dxlog_file15,
4878
- L: 594,
4886
+ L: 597,
4879
4887
  S: this,
4880
4888
  C: (f, a) => f(...a)
4881
4889
  });
@@ -7653,17 +7661,18 @@ var mapStatus = (agentStatus) => {
7653
7661
 
7654
7662
  // src/packlets/services/service-context.ts
7655
7663
  import { Mutex as Mutex4, Trigger as Trigger7 } from "@dxos/async";
7656
- import { Context as Context10, Resource as Resource8 } from "@dxos/context";
7664
+ import { Context as Context10, Resource as Resource9 } from "@dxos/context";
7657
7665
  import { getCredentialAssertion as getCredentialAssertion6 } from "@dxos/credentials";
7658
7666
  import { failUndefined as failUndefined2, warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
7659
7667
  import { EchoEdgeReplicator, EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
7660
7668
  import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from "@dxos/edge-client";
7661
7669
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
7662
- import { invariant as invariant22 } from "@dxos/invariant";
7670
+ import { invariant as invariant23 } from "@dxos/invariant";
7663
7671
  import { Keyring } from "@dxos/keyring";
7664
7672
  import { PublicKey as PublicKey15 } from "@dxos/keys";
7665
7673
  import { log as log23 } from "@dxos/log";
7666
7674
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
7675
+ import { FeedProtocol as FeedProtocol2 } from "@dxos/protocols";
7667
7676
  import { Invitation as Invitation10 } from "@dxos/protocols/proto/dxos/client/services";
7668
7677
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
7669
7678
  import { trace as Trace3 } from "@dxos/tracing";
@@ -7889,6 +7898,246 @@ var decodeCredential = (credentialBase64) => {
7889
7898
  return codec.decode(credentialBytes);
7890
7899
  };
7891
7900
 
7901
+ // src/packlets/services/feed-syncer.ts
7902
+ import { Encoder, decode as cborXdecode } from "cbor-x";
7903
+ import * as Effect from "effect/Effect";
7904
+ import * as Schema from "effect/Schema";
7905
+ import { AsyncTask, scheduleTask as scheduleTask9 } from "@dxos/async";
7906
+ import { Resource as Resource8 } from "@dxos/context";
7907
+ import { MessageSchema } from "@dxos/edge-client";
7908
+ import { RuntimeProvider } from "@dxos/effect";
7909
+ import { SyncClient } from "@dxos/feed";
7910
+ import { invariant as invariant22 } from "@dxos/invariant";
7911
+ import { SpaceId as SpaceId4 } from "@dxos/keys";
7912
+ import { FeedProtocol } from "@dxos/protocols";
7913
+ import { EdgeService as EdgeService2 } from "@dxos/protocols";
7914
+ import { createBuf } from "@dxos/protocols/buf";
7915
+ import { bufferToArray as bufferToArray2 } from "@dxos/util";
7916
+ var __dxlog_file27 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/services/feed-syncer.ts";
7917
+ var encoder = new Encoder({
7918
+ tagUint8Array: false,
7919
+ useRecords: false
7920
+ });
7921
+ var DEFAULT_MESSAGE_BLOCKS_LIMIT = 50;
7922
+ var DEFAULT_SYNC_CONCURRENCY = 5;
7923
+ var DEFAULT_POLLING_INTERVAL = 5e3;
7924
+ var DEFAULT_POLL_REQUEST_THROTTLE_MS = 250;
7925
+ var MAX_BLOCKING_SYNC_ITERATIONS = 100;
7926
+ var FeedSyncer = class extends Resource8 {
7927
+ #syncNamespaces;
7928
+ #messageBlocksLimit;
7929
+ #syncConcurrency;
7930
+ #pollingInterval;
7931
+ #pollRequestThrottleMs;
7932
+ #runtime;
7933
+ #feedStore;
7934
+ #edgeClient;
7935
+ #syncClient;
7936
+ #getSpaceIds;
7937
+ #spacesToPoll = /* @__PURE__ */ new Set();
7938
+ /** Last time full poll was completed. */
7939
+ #lastFullPoll = null;
7940
+ #throttledPollScheduled = false;
7941
+ #lastRequestedPollAt = null;
7942
+ constructor(options) {
7943
+ super();
7944
+ this.#runtime = options.runtime;
7945
+ this.#feedStore = options.feedStore;
7946
+ this.#edgeClient = options.edgeClient;
7947
+ this.#syncClient = new SyncClient({
7948
+ peerId: options.peerId,
7949
+ feedStore: options.feedStore,
7950
+ sendMessage: this.#sendMessage.bind(this)
7951
+ });
7952
+ this.#getSpaceIds = options.getSpaceIds;
7953
+ this.#syncNamespaces = options.syncNamespaces;
7954
+ this.#messageBlocksLimit = options.messageBlocksLimit ?? DEFAULT_MESSAGE_BLOCKS_LIMIT;
7955
+ this.#syncConcurrency = options.syncConcurrency ?? DEFAULT_SYNC_CONCURRENCY;
7956
+ this.#pollingInterval = options.pollingInterval ?? DEFAULT_POLLING_INTERVAL;
7957
+ this.#pollRequestThrottleMs = options.pollRequestThrottleMs ?? DEFAULT_POLL_REQUEST_THROTTLE_MS;
7958
+ }
7959
+ async _open() {
7960
+ this._ctx.onDispose(this.#edgeClient.onMessage((msg) => {
7961
+ if (!msg.serviceId) {
7962
+ return;
7963
+ }
7964
+ const service = msg.serviceId.split(":")[0];
7965
+ if (service !== EdgeService2.QUEUE_REPLICATOR) {
7966
+ return;
7967
+ }
7968
+ const handleMessageEffect = Effect.gen(this, function* () {
7969
+ const decoded = yield* Effect.try({
7970
+ try: () => cborXdecode(msg.payload.value),
7971
+ catch: (error) => new Error(`Failed to decode feed sync message: ${error}`)
7972
+ });
7973
+ const payload = yield* Schema.validate(FeedProtocol.ProtocolMessage)(decoded);
7974
+ yield* this.#syncClient.handleMessage(payload);
7975
+ });
7976
+ void RuntimeProvider.runPromise(this.#runtime)(handleMessageEffect);
7977
+ }));
7978
+ this._ctx.onDispose(
7979
+ // NOTE: This will fire immediately if the connection is already open.
7980
+ this.#edgeClient.onReconnected(async () => {
7981
+ })
7982
+ );
7983
+ this.#feedStore.onNewBlocks.on(this._ctx, () => {
7984
+ this.#pushTask.schedule();
7985
+ });
7986
+ await this.#pollTask.open();
7987
+ await this.#pushTask.open();
7988
+ this.#resetSpacesToPoll();
7989
+ this.#pollTask.schedule();
7990
+ }
7991
+ async _close() {
7992
+ await this.#pollTask.close();
7993
+ await this.#pushTask.close();
7994
+ }
7995
+ /**
7996
+ * Schedules a best-effort pull without blocking the caller.
7997
+ */
7998
+ schedulePoll() {
7999
+ this.#resetSpacesToPoll();
8000
+ if (this.#throttledPollScheduled) {
8001
+ return;
8002
+ }
8003
+ const now = Date.now();
8004
+ const delay = this.#lastRequestedPollAt == null ? 0 : Math.max(this.#pollRequestThrottleMs - (now - this.#lastRequestedPollAt), 0);
8005
+ this.#throttledPollScheduled = true;
8006
+ scheduleTask9(this._ctx, () => {
8007
+ this.#throttledPollScheduled = false;
8008
+ this.#lastRequestedPollAt = Date.now();
8009
+ this.#pollTask.schedule();
8010
+ }, delay);
8011
+ }
8012
+ /**
8013
+ * Performs queue sync and blocks until there are no pending sync batches.
8014
+ */
8015
+ async syncBlocking({ spaceId, subspaceTag, shouldPush = true, shouldPull = true }) {
8016
+ invariant22(SpaceId4.isValid(spaceId), void 0, {
8017
+ F: __dxlog_file27,
8018
+ L: 190,
8019
+ S: this,
8020
+ A: [
8021
+ "SpaceId.isValid(spaceId)",
8022
+ ""
8023
+ ]
8024
+ });
8025
+ invariant22(FeedProtocol.isWellKnownNamespace(subspaceTag), void 0, {
8026
+ F: __dxlog_file27,
8027
+ L: 191,
8028
+ S: this,
8029
+ A: [
8030
+ "FeedProtocol.isWellKnownNamespace(subspaceTag)",
8031
+ ""
8032
+ ]
8033
+ });
8034
+ if (!shouldPush && !shouldPull) {
8035
+ return;
8036
+ }
8037
+ await RuntimeProvider.runPromise(this.#runtime)(Effect.gen(this, function* () {
8038
+ let done = false;
8039
+ let iterations = 0;
8040
+ while (!done) {
8041
+ done = true;
8042
+ if (shouldPull) {
8043
+ const pullResult = yield* this.#syncClient.pull({
8044
+ spaceId,
8045
+ feedNamespace: subspaceTag,
8046
+ limit: this.#messageBlocksLimit
8047
+ });
8048
+ done &&= pullResult.done;
8049
+ }
8050
+ if (shouldPush) {
8051
+ const pushResult = yield* this.#syncClient.push({
8052
+ spaceId,
8053
+ feedNamespace: subspaceTag,
8054
+ limit: this.#messageBlocksLimit
8055
+ });
8056
+ done &&= pushResult.done;
8057
+ }
8058
+ iterations++;
8059
+ if (iterations > MAX_BLOCKING_SYNC_ITERATIONS) {
8060
+ throw new Error("Blocking sync exceeded max iterations.");
8061
+ }
8062
+ }
8063
+ }));
8064
+ }
8065
+ #resetSpacesToPoll() {
8066
+ this.#spacesToPoll.clear();
8067
+ this.#getSpaceIds().forEach((spaceId) => {
8068
+ this.#spacesToPoll.add(spaceId);
8069
+ });
8070
+ this.#lastFullPoll = Date.now();
8071
+ }
8072
+ #sendMessage(message) {
8073
+ return Effect.gen(this, function* () {
8074
+ const encoded = encoder.encode(message);
8075
+ yield* Effect.tryPromise(async () => this.#edgeClient.send(createBuf(MessageSchema, {
8076
+ source: {
8077
+ identityKey: this.#edgeClient.identityKey,
8078
+ peerKey: this.#edgeClient.peerKey
8079
+ },
8080
+ serviceId: this.#getTargetServiceId(message),
8081
+ payload: {
8082
+ value: bufferToArray2(encoded)
8083
+ }
8084
+ })));
8085
+ });
8086
+ }
8087
+ #getTargetServiceId(message) {
8088
+ return FeedProtocol.encodeServiceId(message.feedNamespace, message.spaceId);
8089
+ }
8090
+ #pollTask = new AsyncTask(async () => Effect.gen(this, function* () {
8091
+ yield* Effect.forEach(this.#spacesToPoll, (spaceId) => Effect.gen(this, function* () {
8092
+ let doneForAllNamespaces = true;
8093
+ for (const feedNamespace of this.#syncNamespaces) {
8094
+ const { done } = yield* this.#syncClient.pull({
8095
+ spaceId,
8096
+ feedNamespace,
8097
+ limit: this.#messageBlocksLimit
8098
+ });
8099
+ if (!done) {
8100
+ doneForAllNamespaces = false;
8101
+ }
8102
+ }
8103
+ if (doneForAllNamespaces) {
8104
+ this.#spacesToPoll.delete(spaceId);
8105
+ }
8106
+ }), {
8107
+ concurrency: this.#syncConcurrency
8108
+ });
8109
+ if (this.#lastFullPoll == null || Date.now() - this.#lastFullPoll > this.#pollingInterval) {
8110
+ this.#resetSpacesToPoll();
8111
+ this.#pollTask.schedule();
8112
+ } else if (this.#spacesToPoll.size > 0) {
8113
+ this.#pollTask.schedule();
8114
+ } else {
8115
+ this.#resetSpacesToPoll();
8116
+ scheduleTask9(this._ctx, () => this.#pollTask.schedule(), Math.max(this.#pollingInterval - (Date.now() - (this.#lastFullPoll ?? 0)), 0));
8117
+ }
8118
+ }).pipe(RuntimeProvider.runPromise(this.#runtime)));
8119
+ #pushTask = new AsyncTask(async () => Effect.gen(this, function* () {
8120
+ yield* Effect.forEach(this.#getSpaceIds(), (spaceId) => Effect.gen(this, function* () {
8121
+ let doneForAllNamespaces = true;
8122
+ for (const feedNamespace of this.#syncNamespaces) {
8123
+ const { done } = yield* this.#syncClient.push({
8124
+ spaceId,
8125
+ feedNamespace,
8126
+ limit: this.#messageBlocksLimit
8127
+ });
8128
+ if (!done) {
8129
+ doneForAllNamespaces = false;
8130
+ }
8131
+ }
8132
+ if (!doneForAllNamespaces) {
8133
+ this.#pushTask.schedule();
8134
+ }
8135
+ }), {
8136
+ concurrency: this.#syncConcurrency
8137
+ });
8138
+ }).pipe(RuntimeProvider.runPromise(this.#runtime)));
8139
+ };
8140
+
7892
8141
  // src/packlets/services/service-context.ts
7893
8142
  function _ts_decorate8(decorators, target, key, desc) {
7894
8143
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -7961,8 +8210,8 @@ function _ts_dispose_resources4(env) {
7961
8210
  return next();
7962
8211
  })(env);
7963
8212
  }
7964
- var __dxlog_file27 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
7965
- var ServiceContext = class extends Resource8 {
8213
+ var __dxlog_file28 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
8214
+ var ServiceContext = class extends Resource9 {
7966
8215
  storage;
7967
8216
  level;
7968
8217
  networkManager;
@@ -7986,6 +8235,7 @@ var ServiceContext = class extends Resource8 {
7986
8235
  echoHost;
7987
8236
  _meshReplicator = void 0;
7988
8237
  _echoEdgeReplicator = void 0;
8238
+ _feedSyncer = void 0;
7989
8239
  // Initialized after identity is initialized.
7990
8240
  dataSpaceManager;
7991
8241
  edgeAgentManager;
@@ -7995,14 +8245,14 @@ var ServiceContext = class extends Resource8 {
7995
8245
  constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtime, _runtimeProps, _edgeFeatures) {
7996
8246
  super(), this.storage = storage, this.level = level, this.networkManager = networkManager, this.signalManager = signalManager, this._edgeConnection = _edgeConnection, this._edgeHttpClient = _edgeHttpClient, this._runtime = _runtime, this._runtimeProps = _runtimeProps, this._edgeFeatures = _edgeFeatures;
7997
8247
  log23("runtimeProps", this._runtimeProps, {
7998
- F: __dxlog_file27,
7999
- L: 120,
8248
+ F: __dxlog_file28,
8249
+ L: 123,
8000
8250
  S: this,
8001
8251
  C: (f, a) => f(...a)
8002
8252
  });
8003
8253
  log23("edgeFeatures", this._edgeFeatures, {
8004
- F: __dxlog_file27,
8005
- L: 121,
8254
+ F: __dxlog_file28,
8255
+ L: 124,
8006
8256
  S: this,
8007
8257
  C: (f, a) => f(...a)
8008
8258
  });
@@ -8041,12 +8291,16 @@ var ServiceContext = class extends Resource8 {
8041
8291
  kv: this.level,
8042
8292
  peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
8043
8293
  getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
8044
- indexing: {
8045
- vector: this._runtimeProps?.enableVectorIndexing,
8046
- fullText: this._runtimeProps?.enableFullTextIndexing
8047
- },
8048
8294
  runtime: this._runtime,
8049
- localQueues: this._runtimeProps?.enableLocalQueues
8295
+ localQueues: this._runtimeProps?.enableLocalQueues,
8296
+ syncQueue: async (request) => {
8297
+ return this._feedSyncer?.syncBlocking({
8298
+ spaceId: request.spaceId,
8299
+ subspaceTag: request.subspaceTag,
8300
+ shouldPush: request.shouldPush,
8301
+ shouldPull: request.shouldPull
8302
+ });
8303
+ }
8050
8304
  });
8051
8305
  this.invitations = new InvitationsHandler(this.networkManager, this._edgeHttpClient, _runtimeProps?.invitationConnectionDefaultProps);
8052
8306
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
@@ -8060,20 +8314,33 @@ var ServiceContext = class extends Resource8 {
8060
8314
  edgeHttpClient: this._edgeHttpClient
8061
8315
  });
8062
8316
  }
8317
+ if (this.echoHost.feedStore && this._edgeConnection) {
8318
+ this._feedSyncer = new FeedSyncer({
8319
+ runtime: this._runtime,
8320
+ feedStore: this.echoHost.feedStore,
8321
+ edgeClient: this._edgeConnection,
8322
+ peerId: this.identityManager.identity?.deviceKey?.toHex() ?? "",
8323
+ getSpaceIds: () => this.echoHost.spaceIds,
8324
+ syncNamespaces: [
8325
+ FeedProtocol2.WellKnownNamespaces.data,
8326
+ FeedProtocol2.WellKnownNamespaces.trace
8327
+ ]
8328
+ });
8329
+ }
8063
8330
  }
8064
8331
  async _open(ctx) {
8065
8332
  await this._checkStorageVersion();
8066
8333
  log23("opening...", void 0, {
8067
- F: __dxlog_file27,
8068
- L: 215,
8334
+ F: __dxlog_file28,
8335
+ L: 233,
8069
8336
  S: this,
8070
8337
  C: (f, a) => f(...a)
8071
8338
  });
8072
8339
  log23.trace("dxos.sdk.service-context.open", trace9.begin({
8073
8340
  id: this._instanceId
8074
8341
  }), {
8075
- F: __dxlog_file27,
8076
- L: 216,
8342
+ F: __dxlog_file28,
8343
+ L: 234,
8077
8344
  S: this,
8078
8345
  C: (f, a) => f(...a)
8079
8346
  });
@@ -8095,37 +8362,39 @@ var ServiceContext = class extends Resource8 {
8095
8362
  await this.identityManager.identity.joinNetwork();
8096
8363
  await this._initialize(ctx);
8097
8364
  }
8365
+ await this._feedSyncer?.open();
8098
8366
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
8099
8367
  log23("loaded persistent invitations", {
8100
8368
  count: loadedInvitations.invitations?.length
8101
8369
  }, {
8102
- F: __dxlog_file27,
8103
- L: 244,
8370
+ F: __dxlog_file28,
8371
+ L: 264,
8104
8372
  S: this,
8105
8373
  C: (f, a) => f(...a)
8106
8374
  });
8107
8375
  log23.trace("dxos.sdk.service-context.open", trace9.end({
8108
8376
  id: this._instanceId
8109
8377
  }), {
8110
- F: __dxlog_file27,
8111
- L: 246,
8378
+ F: __dxlog_file28,
8379
+ L: 266,
8112
8380
  S: this,
8113
8381
  C: (f, a) => f(...a)
8114
8382
  });
8115
8383
  log23("opened", void 0, {
8116
- F: __dxlog_file27,
8117
- L: 247,
8384
+ F: __dxlog_file28,
8385
+ L: 267,
8118
8386
  S: this,
8119
8387
  C: (f, a) => f(...a)
8120
8388
  });
8121
8389
  }
8122
8390
  async _close(ctx) {
8123
8391
  log23("closing...", void 0, {
8124
- F: __dxlog_file27,
8125
- L: 251,
8392
+ F: __dxlog_file28,
8393
+ L: 271,
8126
8394
  S: this,
8127
8395
  C: (f, a) => f(...a)
8128
8396
  });
8397
+ await this._feedSyncer?.close();
8129
8398
  if (this._deviceSpaceSync && this.identityManager.identity) {
8130
8399
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
8131
8400
  }
@@ -8140,8 +8409,8 @@ var ServiceContext = class extends Resource8 {
8140
8409
  await this.feedStore.close();
8141
8410
  await this.metadataStore.close();
8142
8411
  log23("closed", void 0, {
8143
- F: __dxlog_file27,
8144
- L: 267,
8412
+ F: __dxlog_file28,
8413
+ L: 290,
8145
8414
  S: this,
8146
8415
  C: (f, a) => f(...a)
8147
8416
  });
@@ -8151,8 +8420,8 @@ var ServiceContext = class extends Resource8 {
8151
8420
  await this._setNetworkIdentity();
8152
8421
  await identity.joinNetwork();
8153
8422
  await this._initialize(new Context10(void 0, {
8154
- F: __dxlog_file27,
8155
- L: 274
8423
+ F: __dxlog_file28,
8424
+ L: 297
8156
8425
  }));
8157
8426
  return identity;
8158
8427
  }
@@ -8161,9 +8430,9 @@ var ServiceContext = class extends Resource8 {
8161
8430
  throw new Error("Identity must be created before joining a space.");
8162
8431
  }
8163
8432
  const factory = this._handlerFactories.get(invitation.kind);
8164
- invariant22(factory, `Unknown invitation kind: ${invitation.kind}`, {
8165
- F: __dxlog_file27,
8166
- L: 283,
8433
+ invariant23(factory, `Unknown invitation kind: ${invitation.kind}`, {
8434
+ F: __dxlog_file28,
8435
+ L: 306,
8167
8436
  S: this,
8168
8437
  A: [
8169
8438
  "factory",
@@ -8188,8 +8457,8 @@ var ServiceContext = class extends Resource8 {
8188
8457
  await identity.joinNetwork();
8189
8458
  await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
8190
8459
  await this._initialize(new Context10(void 0, {
8191
- F: __dxlog_file27,
8192
- L: 302
8460
+ F: __dxlog_file28,
8461
+ L: 325
8193
8462
  }));
8194
8463
  return identity;
8195
8464
  }
@@ -8202,8 +8471,8 @@ var ServiceContext = class extends Resource8 {
8202
8471
  // Called when identity is created.
8203
8472
  async _initialize(ctx) {
8204
8473
  log23("initializing spaces...", void 0, {
8205
- F: __dxlog_file27,
8206
- L: 317,
8474
+ F: __dxlog_file28,
8475
+ L: 340,
8207
8476
  S: this,
8208
8477
  C: (f, a) => f(...a)
8209
8478
  });
@@ -8240,9 +8509,9 @@ var ServiceContext = class extends Resource8 {
8240
8509
  this.edgeAgentManager = new EdgeAgentManager(this._edgeFeatures, this._edgeHttpClient, this.dataSpaceManager, identity);
8241
8510
  await this.edgeAgentManager.open();
8242
8511
  this._handlerFactories.set(Invitation10.Kind.SPACE, (invitation) => {
8243
- invariant22(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
8244
- F: __dxlog_file27,
8245
- L: 355,
8512
+ invariant23(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
8513
+ F: __dxlog_file28,
8514
+ L: 378,
8246
8515
  S: this,
8247
8516
  A: [
8248
8517
  "this.dataSpaceManager",
@@ -8265,8 +8534,8 @@ var ServiceContext = class extends Resource8 {
8265
8534
  log23("dataSpaceManager not initialized yet, ignoring space admission", {
8266
8535
  details: assertion
8267
8536
  }, {
8268
- F: __dxlog_file27,
8269
- L: 371,
8537
+ F: __dxlog_file28,
8538
+ L: 394,
8270
8539
  S: this,
8271
8540
  C: (f, a) => f(...a)
8272
8541
  });
@@ -8276,8 +8545,8 @@ var ServiceContext = class extends Resource8 {
8276
8545
  log23("space already exists, ignoring space admission", {
8277
8546
  details: assertion
8278
8547
  }, {
8279
- F: __dxlog_file27,
8280
- L: 375,
8548
+ F: __dxlog_file28,
8549
+ L: 398,
8281
8550
  S: this,
8282
8551
  C: (f, a) => f(...a)
8283
8552
  });
@@ -8287,8 +8556,8 @@ var ServiceContext = class extends Resource8 {
8287
8556
  log23("accepting space recorded in halo", {
8288
8557
  details: assertion
8289
8558
  }, {
8290
- F: __dxlog_file27,
8291
- L: 380,
8559
+ F: __dxlog_file28,
8560
+ L: 403,
8292
8561
  S: this,
8293
8562
  C: (f, a) => f(...a)
8294
8563
  });
@@ -8298,8 +8567,8 @@ var ServiceContext = class extends Resource8 {
8298
8567
  });
8299
8568
  } catch (err) {
8300
8569
  log23.catch(err, void 0, {
8301
- F: __dxlog_file27,
8302
- L: 386,
8570
+ F: __dxlog_file28,
8571
+ L: 409,
8303
8572
  S: this,
8304
8573
  C: (f, a) => f(...a)
8305
8574
  });
@@ -8323,8 +8592,8 @@ var ServiceContext = class extends Resource8 {
8323
8592
  identity: identity.identityKey.toHex(),
8324
8593
  swarms: this.networkManager.topics
8325
8594
  }, {
8326
- F: __dxlog_file27,
8327
- L: 400,
8595
+ F: __dxlog_file28,
8596
+ L: 423,
8328
8597
  S: this,
8329
8598
  C: (f, a) => f(...a)
8330
8599
  });
@@ -8336,9 +8605,9 @@ var ServiceContext = class extends Resource8 {
8336
8605
  await warnAfterTimeout2(1e4, "Waiting for identity to be ready for edge connection", async () => {
8337
8606
  await identity.ready();
8338
8607
  });
8339
- invariant22(identity.deviceCredentialChain, void 0, {
8340
- F: __dxlog_file27,
8341
- L: 419,
8608
+ invariant23(identity.deviceCredentialChain, void 0, {
8609
+ F: __dxlog_file28,
8610
+ L: 442,
8342
8611
  S: this,
8343
8612
  A: [
8344
8613
  "identity.deviceCredentialChain",
@@ -8485,13 +8754,13 @@ var ServiceRegistry = class {
8485
8754
 
8486
8755
  // src/packlets/services/service-host.ts
8487
8756
  import * as SqlClient from "@effect/sql/SqlClient";
8488
- import * as Effect from "effect/Effect";
8757
+ import * as Effect2 from "effect/Effect";
8489
8758
  import { Event as Event11, synchronized as synchronized4 } from "@dxos/async";
8490
8759
  import { clientServiceBundle } from "@dxos/client-protocol";
8491
8760
  import { Context as Context11 } from "@dxos/context";
8492
8761
  import { EdgeClient, EdgeHttpClient, createStubEdgeIdentity } from "@dxos/edge-client";
8493
- import { RuntimeProvider } from "@dxos/effect";
8494
- import { invariant as invariant24 } from "@dxos/invariant";
8762
+ import { RuntimeProvider as RuntimeProvider2 } from "@dxos/effect";
8763
+ import { invariant as invariant25 } from "@dxos/invariant";
8495
8764
  import { PublicKey as PublicKey19 } from "@dxos/keys";
8496
8765
  import { log as log25 } from "@dxos/log";
8497
8766
  import { EdgeSignalManager, WebsocketSignalManager } from "@dxos/messaging";
@@ -8505,9 +8774,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
8505
8774
  // src/packlets/devices/devices-service.ts
8506
8775
  import { SubscriptionList as SubscriptionList3 } from "@dxos/async";
8507
8776
  import { Stream as Stream11 } from "@dxos/codec-protobuf/stream";
8508
- import { invariant as invariant23 } from "@dxos/invariant";
8777
+ import { invariant as invariant24 } from "@dxos/invariant";
8509
8778
  import { Device as Device2, DeviceKind as DeviceKind2, EdgeStatus as EdgeStatus3 } from "@dxos/protocols/proto/dxos/client/services";
8510
- var __dxlog_file28 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
8779
+ var __dxlog_file29 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
8511
8780
  var DevicesServiceImpl = class {
8512
8781
  _identityManager;
8513
8782
  _edgeConnection;
@@ -8527,8 +8796,8 @@ var DevicesServiceImpl = class {
8527
8796
  devices: []
8528
8797
  });
8529
8798
  } else {
8530
- invariant23(this._identityManager.identity?.presence, "presence not present", {
8531
- F: __dxlog_file28,
8799
+ invariant24(this._identityManager.identity?.presence, "presence not present", {
8800
+ F: __dxlog_file29,
8532
8801
  L: 37,
8533
8802
  S: this,
8534
8803
  A: [
@@ -8595,7 +8864,7 @@ var DevicesServiceImpl = class {
8595
8864
  };
8596
8865
 
8597
8866
  // src/packlets/identity/contacts-service.ts
8598
- import { SubscriptionList as SubscriptionList4, UpdateScheduler as UpdateScheduler2, scheduleTask as scheduleTask9 } from "@dxos/async";
8867
+ import { SubscriptionList as SubscriptionList4, UpdateScheduler as UpdateScheduler2, scheduleTask as scheduleTask10 } from "@dxos/async";
8599
8868
  import { Stream as Stream12 } from "@dxos/codec-protobuf/stream";
8600
8869
  import { PublicKey as PublicKey17 } from "@dxos/keys";
8601
8870
  import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
@@ -8657,7 +8926,7 @@ var ContactsServiceImpl = class {
8657
8926
  }, {
8658
8927
  maxFrequency: 2
8659
8928
  });
8660
- scheduleTask9(ctx, async () => {
8929
+ scheduleTask10(ctx, async () => {
8661
8930
  const subscriptions = new SubscriptionList4();
8662
8931
  ctx.onDispose(() => subscriptions.clear());
8663
8932
  const subscribeToSpaceAndUpdate = () => {
@@ -8936,7 +9205,7 @@ function _ts_decorate9(decorators, target, key, desc) {
8936
9205
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8937
9206
  return c > 3 && r && Object.defineProperty(target, key, r), r;
8938
9207
  }
8939
- var __dxlog_file29 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
9208
+ var __dxlog_file30 = "/__w/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
8940
9209
  var ClientServicesHost = class {
8941
9210
  _resourceLock;
8942
9211
  _serviceRegistry;
@@ -8990,7 +9259,7 @@ var ClientServicesHost = class {
8990
9259
  onAcquire: () => {
8991
9260
  if (!this._opening) {
8992
9261
  void this.open(new Context11(void 0, {
8993
- F: __dxlog_file29,
9262
+ F: __dxlog_file30,
8994
9263
  L: 147
8995
9264
  }));
8996
9265
  }
@@ -9045,7 +9314,7 @@ var ClientServicesHost = class {
9045
9314
  * Debugging util.
9046
9315
  */
9047
9316
  async exportSqliteDatabase() {
9048
- return await RuntimeProvider.runPromise(this._runtime)(Effect.gen(function* () {
9317
+ return await RuntimeProvider2.runPromise(this._runtime)(Effect2.gen(function* () {
9049
9318
  const sql = yield* SqlExport.SqlExport;
9050
9319
  return yield* sql.export;
9051
9320
  }));
@@ -9054,7 +9323,7 @@ var ClientServicesHost = class {
9054
9323
  * Debugging util.
9055
9324
  */
9056
9325
  async runSqliteQuery(query, params) {
9057
- return await RuntimeProvider.runPromise(this._runtime)(Effect.gen(function* () {
9326
+ return await RuntimeProvider2.runPromise(this._runtime)(Effect2.gen(function* () {
9058
9327
  const sql = yield* SqlClient.SqlClient;
9059
9328
  return yield* sql`${sql.unsafe(query, params)}`;
9060
9329
  }));
@@ -9065,8 +9334,8 @@ var ClientServicesHost = class {
9065
9334
  * Can only be called once.
9066
9335
  */
9067
9336
  initialize({ config, ...options }) {
9068
- invariant24(!this._open, "service host is open", {
9069
- F: __dxlog_file29,
9337
+ invariant25(!this._open, "service host is open", {
9338
+ F: __dxlog_file30,
9070
9339
  L: 237,
9071
9340
  S: this,
9072
9341
  A: [
@@ -9075,7 +9344,7 @@ var ClientServicesHost = class {
9075
9344
  ]
9076
9345
  });
9077
9346
  log25("initializing...", void 0, {
9078
- F: __dxlog_file29,
9347
+ F: __dxlog_file30,
9079
9348
  L: 238,
9080
9349
  S: this,
9081
9350
  C: (f, a) => f(...a)
@@ -9090,8 +9359,8 @@ var ClientServicesHost = class {
9090
9359
  if (this._runtimeProps.enableLocalQueues === void 0) {
9091
9360
  this._runtimeProps.enableLocalQueues = config?.get("runtime.client.enableLocalQueues", false);
9092
9361
  }
9093
- invariant24(!this._config, "config already set", {
9094
- F: __dxlog_file29,
9362
+ invariant25(!this._config, "config already set", {
9363
+ F: __dxlog_file30,
9095
9364
  L: 251,
9096
9365
  S: this,
9097
9366
  A: [
@@ -9119,8 +9388,8 @@ var ClientServicesHost = class {
9119
9388
  edgeConnection: this._edgeConnection
9120
9389
  }) : new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
9121
9390
  this._signalManager = signalManager;
9122
- invariant24(!this._networkManager, "network manager already set", {
9123
- F: __dxlog_file29,
9391
+ invariant25(!this._networkManager, "network manager already set", {
9392
+ F: __dxlog_file30,
9124
9393
  L: 282,
9125
9394
  S: this,
9126
9395
  A: [
@@ -9138,7 +9407,7 @@ var ClientServicesHost = class {
9138
9407
  } : void 0
9139
9408
  });
9140
9409
  log25("initialized", void 0, {
9141
- F: __dxlog_file29,
9410
+ F: __dxlog_file30,
9142
9411
  L: 295,
9143
9412
  S: this,
9144
9413
  C: (f, a) => f(...a)
@@ -9152,13 +9421,13 @@ var ClientServicesHost = class {
9152
9421
  log25.trace("dxos.client-services.host.open", trace10.begin({
9153
9422
  id: traceId
9154
9423
  }), {
9155
- F: __dxlog_file29,
9424
+ F: __dxlog_file30,
9156
9425
  L: 306,
9157
9426
  S: this,
9158
9427
  C: (f, a) => f(...a)
9159
9428
  });
9160
- invariant24(this._config, "config not set", {
9161
- F: __dxlog_file29,
9429
+ invariant25(this._config, "config not set", {
9430
+ F: __dxlog_file30,
9162
9431
  L: 308,
9163
9432
  S: this,
9164
9433
  A: [
@@ -9166,8 +9435,8 @@ var ClientServicesHost = class {
9166
9435
  "'config not set'"
9167
9436
  ]
9168
9437
  });
9169
- invariant24(this._storage, "storage not set", {
9170
- F: __dxlog_file29,
9438
+ invariant25(this._storage, "storage not set", {
9439
+ F: __dxlog_file30,
9171
9440
  L: 309,
9172
9441
  S: this,
9173
9442
  A: [
@@ -9175,8 +9444,8 @@ var ClientServicesHost = class {
9175
9444
  "'storage not set'"
9176
9445
  ]
9177
9446
  });
9178
- invariant24(this._signalManager, "signal manager not set", {
9179
- F: __dxlog_file29,
9447
+ invariant25(this._signalManager, "signal manager not set", {
9448
+ F: __dxlog_file30,
9180
9449
  L: 310,
9181
9450
  S: this,
9182
9451
  A: [
@@ -9184,8 +9453,8 @@ var ClientServicesHost = class {
9184
9453
  "'signal manager not set'"
9185
9454
  ]
9186
9455
  });
9187
- invariant24(this._networkManager, "network manager not set", {
9188
- F: __dxlog_file29,
9456
+ invariant25(this._networkManager, "network manager not set", {
9457
+ F: __dxlog_file30,
9189
9458
  L: 311,
9190
9459
  S: this,
9191
9460
  A: [
@@ -9197,7 +9466,7 @@ var ClientServicesHost = class {
9197
9466
  log25("opening...", {
9198
9467
  lockKey: this._resourceLock?.lockKey
9199
9468
  }, {
9200
- F: __dxlog_file29,
9469
+ F: __dxlog_file30,
9201
9470
  L: 314,
9202
9471
  S: this,
9203
9472
  C: (f, a) => f(...a)
@@ -9259,7 +9528,7 @@ var ClientServicesHost = class {
9259
9528
  log25("opened", {
9260
9529
  deviceKey
9261
9530
  }, {
9262
- F: __dxlog_file29,
9531
+ F: __dxlog_file30,
9263
9532
  L: 417,
9264
9533
  S: this,
9265
9534
  C: (f, a) => f(...a)
@@ -9267,7 +9536,7 @@ var ClientServicesHost = class {
9267
9536
  log25.trace("dxos.client-services.host.open", trace10.end({
9268
9537
  id: traceId
9269
9538
  }), {
9270
- F: __dxlog_file29,
9539
+ F: __dxlog_file30,
9271
9540
  L: 418,
9272
9541
  S: this,
9273
9542
  C: (f, a) => f(...a)
@@ -9281,7 +9550,7 @@ var ClientServicesHost = class {
9281
9550
  log25("closing...", {
9282
9551
  deviceKey
9283
9552
  }, {
9284
- F: __dxlog_file29,
9553
+ F: __dxlog_file30,
9285
9554
  L: 429,
9286
9555
  S: this,
9287
9556
  C: (f, a) => f(...a)
@@ -9299,7 +9568,7 @@ var ClientServicesHost = class {
9299
9568
  log25("closed", {
9300
9569
  deviceKey
9301
9570
  }, {
9302
- F: __dxlog_file29,
9571
+ F: __dxlog_file30,
9303
9572
  L: 438,
9304
9573
  S: this,
9305
9574
  C: (f, a) => f(...a)
@@ -9310,13 +9579,13 @@ var ClientServicesHost = class {
9310
9579
  log25.trace("dxos.sdk.client-services-host.reset", trace10.begin({
9311
9580
  id: traceId
9312
9581
  }), {
9313
- F: __dxlog_file29,
9582
+ F: __dxlog_file30,
9314
9583
  L: 443,
9315
9584
  S: this,
9316
9585
  C: (f, a) => f(...a)
9317
9586
  });
9318
9587
  log25.info("resetting...", void 0, {
9319
- F: __dxlog_file29,
9588
+ F: __dxlog_file30,
9320
9589
  L: 445,
9321
9590
  S: this,
9322
9591
  C: (f, a) => f(...a)
@@ -9330,7 +9599,7 @@ var ClientServicesHost = class {
9330
9599
  log25.warn("failed to clear leveldb during reset", {
9331
9600
  err
9332
9601
  }, {
9333
- F: __dxlog_file29,
9602
+ F: __dxlog_file30,
9334
9603
  L: 455,
9335
9604
  S: this,
9336
9605
  C: (f, a) => f(...a)
@@ -9338,7 +9607,7 @@ var ClientServicesHost = class {
9338
9607
  }
9339
9608
  await this._storage.reset();
9340
9609
  log25.info("reset", void 0, {
9341
- F: __dxlog_file29,
9610
+ F: __dxlog_file30,
9342
9611
  L: 458,
9343
9612
  S: this,
9344
9613
  C: (f, a) => f(...a)
@@ -9346,7 +9615,7 @@ var ClientServicesHost = class {
9346
9615
  log25.trace("dxos.sdk.client-services-host.reset", trace10.end({
9347
9616
  id: traceId
9348
9617
  }), {
9349
- F: __dxlog_file29,
9618
+ F: __dxlog_file30,
9350
9619
  L: 459,
9351
9620
  S: this,
9352
9621
  C: (f, a) => f(...a)
@@ -9418,4 +9687,4 @@ export {
9418
9687
  ServiceRegistry,
9419
9688
  ClientServicesHost
9420
9689
  };
9421
- //# sourceMappingURL=chunk-QWDES2YZ.mjs.map
9690
+ //# sourceMappingURL=chunk-KEV65JXY.mjs.map