@toon-protocol/client-mcp 0.5.3 → 0.7.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.
@@ -3,6 +3,7 @@ import {
3
3
  DEFAULT_KEYSTORE_PASSWORD,
4
4
  ILP_PEER_INFO_KIND,
5
5
  ToonError,
6
+ arweaveUrls,
6
7
  buildIlpPrepare,
7
8
  configDir,
8
9
  decodeEventFromToon,
@@ -14,7 +15,7 @@ import {
14
15
  isEventExpired,
15
16
  parseIlpPeerInfo,
16
17
  readConfigFile
17
- } from "./chunk-3UECPDBJ.js";
18
+ } from "./chunk-76CTU2A5.js";
18
19
  import {
19
20
  __require
20
21
  } from "./chunk-F22GNSF6.js";
@@ -1377,7 +1378,8 @@ function mapAnnouncement(event, opts) {
1377
1378
  chain: family,
1378
1379
  chainKey,
1379
1380
  // EVM chainKeys are `evm:<network>:<chainId>`; non-EVM carry no numeric id.
1380
- chainId: family === "evm" ? Number(chainKey.split(":")[2] ?? 0) : 0,
1381
+ // Tolerate the 2-part `evm:<chainId>` form some connectors advertise.
1382
+ chainId: family === "evm" ? Number(chainKey.split(":")[2] ?? chainKey.split(":")[1] ?? 0) : 0,
1381
1383
  settlementAddress,
1382
1384
  ...info.preferredTokens?.[chainKey] ? { tokenAddress: info.preferredTokens[chainKey] } : {},
1383
1385
  ...info.tokenNetworks?.[chainKey] ? { tokenNetwork: info.tokenNetworks[chainKey] } : {}
@@ -1699,8 +1701,10 @@ var ClientRunner = class {
1699
1701
  /** Derive a per-apex ToonClientConfig from the default (shared identity/transport). */
1700
1702
  deriveApexClientConfig(btpUrl, destination) {
1701
1703
  const base = this.config.toonClientConfig;
1704
+ const derivedProxyUrl = btpUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://").replace(/:443(\/|$)/, "$1").replace(/\/btp\/?$/, "").replace(/\/$/, "");
1702
1705
  return {
1703
1706
  ...base,
1707
+ ...derivedProxyUrl ? { proxyUrl: derivedProxyUrl } : {},
1704
1708
  btpUrl,
1705
1709
  destinationAddress: destination,
1706
1710
  // Distinct nonce-watermark store per apex so parallel ChannelManagers in
@@ -1973,7 +1977,7 @@ var ClientRunner = class {
1973
1977
  const fee = req.fee !== void 0 ? BigInt(req.fee) : apex.feePerEvent;
1974
1978
  const claim = await apex.client.signBalanceProof(channelId, fee);
1975
1979
  const result = await apex.client.publishEvent(req.event, {
1976
- ...req.destination ? { destination: req.destination } : {},
1980
+ destination: req.destination ?? this.config.publishDestination,
1977
1981
  claim,
1978
1982
  ilpAmount: fee
1979
1983
  });
@@ -2021,24 +2025,24 @@ var ClientRunner = class {
2021
2025
  const fee = req.fee !== void 0 ? BigInt(req.fee) : apex.feePerEvent;
2022
2026
  const upload = await apex.client.uploadBlob({
2023
2027
  blobData,
2028
+ destination: this.config.storeDestination,
2024
2029
  ...req.mime ? { contentType: req.mime } : {},
2025
2030
  ilpAmount: fee
2026
2031
  });
2027
2032
  if (!upload.success || !upload.txId) {
2028
2033
  throw new PublishRejectedError(upload.error ?? "blob upload rejected");
2029
2034
  }
2030
- const url = `${ARWEAVE_GATEWAY}/${upload.txId}`;
2035
+ const { url, fallbacks } = arweaveUrls(upload.txId, this.config.arweaveGateways);
2031
2036
  const kind = req.kind ?? 1063;
2032
2037
  const signed = await apex.client.signEvent({
2033
2038
  kind,
2034
2039
  created_at: nowSeconds(),
2035
- tags: this.buildMediaTags(kind, url, req),
2040
+ tags: this.buildMediaTags(kind, url, fallbacks, req),
2036
2041
  content: req.caption ?? ""
2037
2042
  });
2038
2043
  const pub = await this.publish({
2039
2044
  event: signed,
2040
- ...req.fee ? { fee: req.fee } : {},
2041
- ...req.btpUrl ? { btpUrl: req.btpUrl } : {}
2045
+ ...req.fee ? { fee: req.fee } : {}
2042
2046
  });
2043
2047
  return { ...pub, url, txId: upload.txId };
2044
2048
  }
@@ -2076,14 +2080,26 @@ var ClientRunner = class {
2076
2080
  }
2077
2081
  return latest;
2078
2082
  }
2079
- /** Tags for a published media event referencing an Arweave URL. */
2080
- buildMediaTags(kind, url, req) {
2083
+ /**
2084
+ * Tags for a published media event referencing an Arweave URL. `url` is the
2085
+ * primary gateway; `fallbacks` are mirror URLs for the same tx id on other
2086
+ * gateways, emitted so readers can fail over if the primary is unreachable.
2087
+ */
2088
+ buildMediaTags(kind, url, fallbacks, req) {
2081
2089
  const mime = req.mime ?? "application/octet-stream";
2082
2090
  const extra = normalizeTags(req.tags);
2083
2091
  if (kind === 1063) {
2084
- return [["url", url], ["m", mime], ...extra];
2085
- }
2086
- return [["imeta", `url ${url}`, `m ${mime}`], ...extra];
2092
+ return [
2093
+ ["url", url],
2094
+ ["m", mime],
2095
+ ...fallbacks.map((f) => ["fallback", f]),
2096
+ ...extra
2097
+ ];
2098
+ }
2099
+ return [
2100
+ ["imeta", `url ${url}`, `m ${mime}`, ...fallbacks.map((f) => `fallback ${f}`)],
2101
+ ...extra
2102
+ ];
2087
2103
  }
2088
2104
  /** Open (or return) a payment channel on the selected (or default) apex. */
2089
2105
  async openChannel(destination, btpUrl) {
@@ -2234,7 +2250,6 @@ var InvalidPayloadError = class extends Error {
2234
2250
  this.name = "InvalidPayloadError";
2235
2251
  }
2236
2252
  };
2237
- var ARWEAVE_GATEWAY = "https://arweave.net";
2238
2253
  function nowSeconds() {
2239
2254
  return Math.floor(Date.now() / 1e3);
2240
2255
  }
@@ -2525,4 +2540,4 @@ export {
2525
2540
  PublishRejectedError,
2526
2541
  registerRoutes
2527
2542
  };
2528
- //# sourceMappingURL=chunk-CAGUIHZV.js.map
2543
+ //# sourceMappingURL=chunk-EY5GFEDH.js.map