@toon-protocol/client-mcp 0.5.1 → 0.5.3

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.
@@ -6963,6 +6963,42 @@ function buildStoreWriteEnvelope(event) {
6963
6963
  const head = [REQUEST_LINE, ...HEADERS].join("\r\n");
6964
6964
  return encodeUtf8(head + "\r\n\r\n" + body);
6965
6965
  }
6966
+ var CRLF = "\r\n";
6967
+ function findHeaderEnd(bytes) {
6968
+ for (let i = 0; i + 3 < bytes.length; i++) {
6969
+ if (bytes[i] === 13 && bytes[i + 1] === 10 && bytes[i + 2] === 13 && bytes[i + 3] === 10) {
6970
+ return i + 4;
6971
+ }
6972
+ }
6973
+ return -1;
6974
+ }
6975
+ function parseFulfillHttpBytes(bytes) {
6976
+ const notHttp = {
6977
+ isHttp: false,
6978
+ status: 0,
6979
+ statusText: "",
6980
+ body: ""
6981
+ };
6982
+ const headerEnd = findHeaderEnd(bytes);
6983
+ const headBytes = headerEnd === -1 ? bytes : bytes.subarray(0, headerEnd - 2);
6984
+ const bodyBytes = headerEnd === -1 ? new Uint8Array(0) : bytes.subarray(headerEnd);
6985
+ const headText = decodeUtf8(headBytes);
6986
+ const lines = headText.split(CRLF).filter((l) => l.length > 0);
6987
+ const statusLine = lines.shift();
6988
+ if (!statusLine) return notHttp;
6989
+ if (!statusLine.trimStart().startsWith("HTTP/")) return notHttp;
6990
+ const match = /^HTTP\/\d\.\d\s+(\d{3})(?:\s+(.*))?$/.exec(statusLine.trim());
6991
+ if (!match) return notHttp;
6992
+ return {
6993
+ isHttp: true,
6994
+ status: parseInt(match[1], 10),
6995
+ statusText: match[2] ?? "",
6996
+ body: decodeUtf8(bodyBytes)
6997
+ };
6998
+ }
6999
+ function parseFulfillHttp(base64Data) {
7000
+ return parseFulfillHttpBytes(fromBase64(base64Data));
7001
+ }
6966
7002
  async function withRetry(operation, options) {
6967
7003
  const {
6968
7004
  maxRetries,
@@ -9934,15 +9970,17 @@ async function requestBlobStorage(client, secretKey, params) {
9934
9970
  return {
9935
9971
  success: false,
9936
9972
  eventId: event.id,
9937
- error: "FULFILL contained no data; expected base64-encoded Arweave tx ID"
9973
+ error: "FULFILL contained no data; expected an HTTP response with the Arweave tx ID"
9938
9974
  };
9939
9975
  }
9940
- const txId = decodeUtf8(fromBase64(result.data));
9941
- if (!ARWEAVE_TX_ID_REGEX.test(txId)) {
9976
+ let txId;
9977
+ try {
9978
+ txId = extractArweaveTxId(result.data);
9979
+ } catch (error) {
9942
9980
  return {
9943
9981
  success: false,
9944
9982
  eventId: event.id,
9945
- error: `Decoded FULFILL data is not a valid Arweave tx ID: "${txId}"`
9983
+ error: error instanceof Error ? error.message : String(error)
9946
9984
  };
9947
9985
  }
9948
9986
  return {
@@ -9951,6 +9989,49 @@ async function requestBlobStorage(client, secretKey, params) {
9951
9989
  eventId: event.id
9952
9990
  };
9953
9991
  }
9992
+ function extractArweaveTxId(base64Data) {
9993
+ const http2 = parseFulfillHttp(base64Data);
9994
+ if (!http2.isHttp) {
9995
+ const legacy = decodeUtf8(fromBase64(base64Data));
9996
+ if (!ARWEAVE_TX_ID_REGEX.test(legacy)) {
9997
+ throw new Error(
9998
+ `Decoded FULFILL data is not a valid Arweave tx ID: "${legacy}"`
9999
+ );
10000
+ }
10001
+ return legacy;
10002
+ }
10003
+ if (http2.status < 200 || http2.status >= 300) {
10004
+ const detail = http2.body ? ` - ${http2.body}` : "";
10005
+ throw new Error(
10006
+ `Blob upload failed: DVM returned HTTP ${http2.status} ${http2.statusText}`.trimEnd() + detail
10007
+ );
10008
+ }
10009
+ let parsed;
10010
+ try {
10011
+ parsed = JSON.parse(http2.body);
10012
+ } catch {
10013
+ throw new Error(
10014
+ `Blob upload response body was not valid JSON: "${http2.body}"`
10015
+ );
10016
+ }
10017
+ const body = parsed;
10018
+ if (body.accept === false) {
10019
+ const reason = typeof body.error === "string" ? `: ${body.error}` : "";
10020
+ throw new Error(`Blob upload rejected by DVM (accept:false)${reason}`);
10021
+ }
10022
+ if (typeof body.txId === "string" && ARWEAVE_TX_ID_REGEX.test(body.txId)) {
10023
+ return body.txId;
10024
+ }
10025
+ if (typeof body.data === "string" && body.data.length > 0) {
10026
+ const decoded = decodeUtf8(fromBase64(body.data));
10027
+ if (ARWEAVE_TX_ID_REGEX.test(decoded)) {
10028
+ return decoded;
10029
+ }
10030
+ }
10031
+ throw new Error(
10032
+ `Blob upload response did not contain a valid Arweave tx ID: "${http2.body}"`
10033
+ );
10034
+ }
9954
10035
  var Http402Client = class {
9955
10036
  fetchImpl;
9956
10037
  resolveClaim;
@@ -10123,7 +10204,7 @@ function parseX402Body(body) {
10123
10204
  }
10124
10205
  return version !== void 0 ? { x402Version: version } : {};
10125
10206
  }
10126
- var CRLF = "\r\n";
10207
+ var CRLF2 = "\r\n";
10127
10208
  function concatHeadAndBody(head, body) {
10128
10209
  const headBytes = encodeUtf8(head);
10129
10210
  const out = new Uint8Array(headBytes.length + body.length);
@@ -10153,10 +10234,10 @@ function serializeHttpRequest(req) {
10153
10234
  `${req.method.toUpperCase()} ${target} HTTP/1.1`,
10154
10235
  ...headers.values()
10155
10236
  ];
10156
- const head = lines.join(CRLF) + CRLF + CRLF;
10237
+ const head = lines.join(CRLF2) + CRLF2 + CRLF2;
10157
10238
  return concatHeadAndBody(head, bodyBytes);
10158
10239
  }
10159
- function findHeaderEnd(bytes) {
10240
+ function findHeaderEnd2(bytes) {
10160
10241
  for (let i = 0; i + 3 < bytes.length; i++) {
10161
10242
  if (bytes[i] === 13 && bytes[i + 1] === 10 && bytes[i + 2] === 13 && bytes[i + 3] === 10) {
10162
10243
  return i + 4;
@@ -10165,11 +10246,11 @@ function findHeaderEnd(bytes) {
10165
10246
  return -1;
10166
10247
  }
10167
10248
  function parseHttpResponse(bytes) {
10168
- const headerEnd = findHeaderEnd(bytes);
10249
+ const headerEnd = findHeaderEnd2(bytes);
10169
10250
  const headBytes = headerEnd === -1 ? bytes : bytes.subarray(0, headerEnd - 2);
10170
10251
  const body = headerEnd === -1 ? new Uint8Array(0) : bytes.subarray(headerEnd);
10171
10252
  const headText = decodeUtf8(headBytes);
10172
- const lines = headText.split(CRLF).filter((l) => l.length > 0);
10253
+ const lines = headText.split(CRLF2).filter((l) => l.length > 0);
10173
10254
  const statusLine = lines.shift();
10174
10255
  if (!statusLine) {
10175
10256
  throw new ConnectorError(
@@ -10524,6 +10605,16 @@ var ToonClient = class {
10524
10605
  error: `Event rejected: ${response.code} - ${response.message}`
10525
10606
  };
10526
10607
  }
10608
+ if (response.data) {
10609
+ const httpResult = parseFulfillHttp(response.data);
10610
+ if (httpResult.isHttp && (httpResult.status < 200 || httpResult.status >= 300)) {
10611
+ const detail = httpResult.body ? ` - ${httpResult.body}` : "";
10612
+ return {
10613
+ success: false,
10614
+ error: `Write failed: relay returned HTTP ${httpResult.status} ${httpResult.statusText}`.trimEnd() + detail
10615
+ };
10616
+ }
10617
+ }
10527
10618
  return {
10528
10619
  success: true,
10529
10620
  eventId: event.id,
@@ -12025,4 +12116,4 @@ export {
12025
12116
  @scure/bip32/lib/esm/index.js:
12026
12117
  (*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
12027
12118
  */
12028
- //# sourceMappingURL=chunk-R75M6TK6.js.map
12119
+ //# sourceMappingURL=chunk-3UECPDBJ.js.map