@appsoftwareltd/etherpk-mcp 0.39.0 → 0.41.0

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.
package/dist/main.js CHANGED
@@ -820,7 +820,7 @@ function looksLikeAgentSetupCode(value) {
820
820
  }
821
821
  var package_default = {
822
822
  name: "@appsoftwareltd/etherpk-mcp",
823
- version: "0.39.0",
823
+ version: "0.41.0",
824
824
  license: "Elastic-2.0",
825
825
  description: "EtherPK Headless Client: an MCP server over a synced knowledge graph, run beside the agent on the user's own machine.",
826
826
  type: "module",
@@ -11707,6 +11707,9 @@ function createGraphSync(deps) {
11707
11707
  let openedAt = 0;
11708
11708
  let forceToken = false;
11709
11709
  let credentialRefusals = 0;
11710
+ /** Closes with 4429 in a row; a socket that closed any other way held a place, and ends the run. */
11711
+ let turnedAwayRounds = 0;
11712
+ const turnedAwayDelay = deps.turnedAwayRetryDelayMs ?? ((round) => refusalRetryDelayMs(round));
11710
11713
  let reconnectTimer;
11711
11714
  /** True while a retry waits on `reconnectTimer`: no socket is open or being made. */
11712
11715
  let retryWaiting = false;
@@ -11721,6 +11724,24 @@ function createGraphSync(deps) {
11721
11724
  attempts += 1;
11722
11725
  scheduleConnect(retryDelay(attempts));
11723
11726
  }
11727
+ /**
11728
+ * 4429: this account already holds every connection the Sync Server allows it on this graph
11729
+ * (other tabs, other devices, agents). The relay opens the socket and closes it at once, so
11730
+ * the ordinary backoff would be refused again within half a second for as long as they stay
11731
+ * open. Ask on the slower schedule of a refused write: the answer changes only when one of
11732
+ * them closes. True when `code` was that close, and the next attempt is scheduled.
11733
+ */
11734
+ function turnedAway(code) {
11735
+ if (code !== 4429) {
11736
+ turnedAwayRounds = 0;
11737
+ return false;
11738
+ }
11739
+ connection = "turned-away";
11740
+ activityChanged();
11741
+ turnedAwayRounds += 1;
11742
+ scheduleConnect(turnedAwayDelay(turnedAwayRounds));
11743
+ return true;
11744
+ }
11724
11745
  /** Stop for good: close the socket, never reconnect, and tell the owner once. */
11725
11746
  function endAccess(loss) {
11726
11747
  if (lost || disposed) return;
@@ -11788,14 +11809,16 @@ function createGraphSync(deps) {
11788
11809
  socket = void 0;
11789
11810
  forgetSocketGeneration();
11790
11811
  if (disposed || lost || protocolMismatch) return;
11812
+ const code = event?.code;
11813
+ if (turnedAway(code)) return;
11791
11814
  connection = "reconnecting";
11792
11815
  activityChanged();
11793
- if (event?.code === 4403) {
11816
+ if (code === 4403) {
11794
11817
  endAccess({ kind: "membership" });
11795
11818
  return;
11796
11819
  }
11797
11820
  if (upFor >= 1e4) attempts = 0;
11798
- if (event?.code === 4401) {
11821
+ if (code === 4401) {
11799
11822
  forceToken = true;
11800
11823
  credentialRefusals += 1;
11801
11824
  if (credentialRefusals === 1) {
@@ -27874,7 +27897,7 @@ function createServerDocumentStore(graph, options) {
27874
27897
  },
27875
27898
  async scan() {
27876
27899
  await graph.ready();
27877
- if (graph.isConnected() || await new Promise((resolve) => {
27900
+ if ((graph.isConnected() || await new Promise((resolve) => {
27878
27901
  let settled = false;
27879
27902
  const finish = (connected) => {
27880
27903
  if (settled) return;
@@ -27884,10 +27907,7 @@ function createServerDocumentStore(graph, options) {
27884
27907
  };
27885
27908
  const timer = setTimeout(() => finish(false), Math.max(0, options.readyTimeoutMs ?? 2e3));
27886
27909
  graph.connected().then(() => finish(true));
27887
- })) {
27888
- await graph.rootCaughtUp();
27889
- registryConfirmed = true;
27890
- }
27910
+ })) && await rootCaughtUpUnlessTurnedAway()) registryConfirmed = true;
27891
27911
  known = currentConcepts();
27892
27912
  docIdsByConcept = currentDocIds(docIdsByConcept);
27893
27913
  knownRegistry = currentRegistryIdentities();
@@ -28480,6 +28500,24 @@ function createServerDocumentStore(graph, options) {
28480
28500
  stopClaimWatches.add(stop);
28481
28501
  if (graph.isConnected()) release();
28482
28502
  }
28503
+ /** True once the root's catch-up finishes; false as soon as the relay turns the session away. */
28504
+ function rootCaughtUpUnlessTurnedAway() {
28505
+ return new Promise((resolve, reject) => {
28506
+ const turnedAway = () => graph.activity().connection === "turned-away";
28507
+ const finish = (caughtUp) => {
28508
+ stop();
28509
+ resolve(caughtUp);
28510
+ };
28511
+ const stop = graph.onActivity(() => {
28512
+ if (turnedAway()) finish(false);
28513
+ });
28514
+ graph.rootCaughtUp().then(() => finish(true), (error) => {
28515
+ stop();
28516
+ reject(error);
28517
+ });
28518
+ if (turnedAway()) finish(false);
28519
+ });
28520
+ }
28483
28521
  async function confirmRegistry(timeoutMs = 5e3) {
28484
28522
  if (registryConfirmed) return true;
28485
28523
  if (!graph.isConnected()) return false;