@toon-protocol/client-mcp 0.12.0 → 0.12.2

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.
@@ -15,7 +15,7 @@ import {
15
15
  isEventExpired,
16
16
  parseIlpPeerInfo,
17
17
  readConfigFile
18
- } from "./chunk-W6T6ZK7U.js";
18
+ } from "./chunk-AYIP46A2.js";
19
19
  import {
20
20
  __require
21
21
  } from "./chunk-F22GNSF6.js";
@@ -2058,9 +2058,24 @@ var ClientRunner = class {
2058
2058
  eventId: result.eventId ?? req.event.id,
2059
2059
  ...result.data !== void 0 ? { data: result.data } : {},
2060
2060
  channelId,
2061
- nonce: apex.client.getChannelNonce(channelId)
2061
+ nonce: apex.client.getChannelNonce(channelId),
2062
+ feePaid: fee.toString(),
2063
+ channelBalanceAfter: this.channelAvailable(apex, channelId)
2062
2064
  };
2063
2065
  }
2066
+ /**
2067
+ * Available (spendable) balance for a channel after a write — locked collateral
2068
+ * minus cumulative spent, clamped at 0. Same math as {@link getChannels}; used
2069
+ * to report a truthful post-write balance in publish/upload receipts. Returns
2070
+ * undefined if the channel isn't tracked on this apex (balance unknown).
2071
+ */
2072
+ channelAvailable(apex, channelId) {
2073
+ if (!apex.client.getTrackedChannels().includes(channelId)) return void 0;
2074
+ const cumulative = apex.client.getChannelCumulativeAmount(channelId);
2075
+ const depositTotal = apex.client.getChannelDepositTotal(channelId);
2076
+ const available = depositTotal > cumulative ? depositTotal - cumulative : 0n;
2077
+ return available.toString();
2078
+ }
2064
2079
  /**
2065
2080
  * Build, sign (with the daemon-held key), and pay-to-write an event. The
2066
2081
  * caller supplies only the event shell; the private key never leaves the
@@ -2128,7 +2143,8 @@ var ClientRunner = class {
2128
2143
  `kind:${kind} publish leg failed after upload (blob stored at ${url}): ${detail}`
2129
2144
  );
2130
2145
  }
2131
- return { ...pub, url, txId: upload.txId };
2146
+ const feePaid = (fee + BigInt(pub.feePaid)).toString();
2147
+ return { ...pub, feePaid, url, txId: upload.txId };
2132
2148
  }
2133
2149
  /**
2134
2150
  * Read media bytes off disk for an upload `filePath`. The path is resolved
@@ -2769,10 +2785,27 @@ function mapError(reply, err) {
2769
2785
  if (err instanceof Error && err.name === "SettleTooEarlyError") {
2770
2786
  return sendError(reply, 425, "settle_too_early", { detail: err.message, retryable: true });
2771
2787
  }
2788
+ const funding = findChannelFundingError(err);
2789
+ if (funding) {
2790
+ return sendError(reply, 402, "insufficient_gas", {
2791
+ detail: funding.message,
2792
+ retryable: true
2793
+ });
2794
+ }
2772
2795
  return sendError(reply, 500, "internal_error", {
2773
2796
  detail: err instanceof Error ? err.message : String(err)
2774
2797
  });
2775
2798
  }
2799
+ function findChannelFundingError(err) {
2800
+ let cur = err;
2801
+ for (let i = 0; i < 10 && cur != null; i++) {
2802
+ if (cur instanceof Error && cur.name === "ChannelFundingError") {
2803
+ return cur;
2804
+ }
2805
+ cur = cur instanceof Error ? cur.cause : void 0;
2806
+ }
2807
+ return void 0;
2808
+ }
2776
2809
  function sendError(reply, status, error, extra = {}) {
2777
2810
  return reply.status(status).send({
2778
2811
  error,
@@ -2791,4 +2824,4 @@ export {
2791
2824
  PublishRejectedError,
2792
2825
  registerRoutes
2793
2826
  };
2794
- //# sourceMappingURL=chunk-74KX5LXI.js.map
2827
+ //# sourceMappingURL=chunk-EAPVMGLZ.js.map