@toon-protocol/client-mcp 0.10.7 → 0.10.9

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.
@@ -12498,7 +12498,7 @@ var DaemonUnreachableError = class extends Error {
12498
12498
  baseUrl;
12499
12499
  causedBy;
12500
12500
  };
12501
- var ControlClient = class {
12501
+ var ControlClient = class _ControlClient {
12502
12502
  baseUrl;
12503
12503
  timeoutMs;
12504
12504
  fetchImpl;
@@ -12551,7 +12551,7 @@ var ControlClient = class {
12551
12551
  return this.request("GET", "/channels");
12552
12552
  }
12553
12553
  balances() {
12554
- return this.request("GET", "/balances");
12554
+ return this.request("GET", "/balances", void 0, { timeoutMs: 12e3 });
12555
12555
  }
12556
12556
  depositToChannel(body) {
12557
12557
  return this.request("POST", "/channels/deposit", body);
@@ -12590,10 +12590,36 @@ var ControlClient = class {
12590
12590
  fundWallet(body = {}) {
12591
12591
  return this.request("POST", "/fund-wallet", body);
12592
12592
  }
12593
- async request(method, path, body) {
12593
+ /**
12594
+ * Whether an HTTP method is safe to transparently retry. Idempotent reads
12595
+ * (GET) and deletes can be replayed verbatim; a mutating POST cannot — the
12596
+ * daemon may have already applied it before the socket failed, so retrying
12597
+ * risks a double publish/fund/deposit.
12598
+ */
12599
+ static isIdempotent(method) {
12600
+ return method === "GET" || method === "DELETE";
12601
+ }
12602
+ async request(method, path, body, opts) {
12603
+ const attempts = _ControlClient.isIdempotent(method) ? 3 : 1;
12604
+ let lastErr;
12605
+ for (let attempt = 1; attempt <= attempts; attempt++) {
12606
+ try {
12607
+ return await this.attemptOnce(method, path, body, opts?.timeoutMs);
12608
+ } catch (err) {
12609
+ lastErr = err;
12610
+ if (attempt < attempts && err instanceof DaemonUnreachableError) {
12611
+ await new Promise((r) => setTimeout(r, 50 * attempt));
12612
+ continue;
12613
+ }
12614
+ throw err;
12615
+ }
12616
+ }
12617
+ throw lastErr;
12618
+ }
12619
+ async attemptOnce(method, path, body, timeoutMs = this.timeoutMs) {
12594
12620
  const url = `${this.baseUrl}${path}`;
12595
12621
  const controller = new AbortController();
12596
- const timer = setTimeout(() => controller.abort(), this.timeoutMs);
12622
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
12597
12623
  let res;
12598
12624
  try {
12599
12625
  res = await this.fetchImpl(url, {
@@ -12603,6 +12629,13 @@ var ControlClient = class {
12603
12629
  signal: controller.signal
12604
12630
  });
12605
12631
  } catch (err) {
12632
+ if (controller.signal.aborted) {
12633
+ throw new ControlApiError(
12634
+ `control request ${method} ${path} timed out after ${timeoutMs}ms`,
12635
+ 504,
12636
+ true
12637
+ );
12638
+ }
12606
12639
  throw new DaemonUnreachableError(this.baseUrl, err);
12607
12640
  } finally {
12608
12641
  clearTimeout(timer);
@@ -12768,4 +12801,4 @@ export {
12768
12801
  @scure/bip32/lib/esm/index.js:
12769
12802
  (*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
12770
12803
  */
12771
- //# sourceMappingURL=chunk-XYR3ACYX.js.map
12804
+ //# sourceMappingURL=chunk-UHITXU5V.js.map