@t2000/cli 9.3.0 → 9.4.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.
@@ -48231,11 +48231,11 @@ var init_fetch = __esm({
48231
48231
  return "half";
48232
48232
  }
48233
48233
  });
48234
- const hasContentType = request.headers.has("Content-Type");
48234
+ const hasContentType2 = request.headers.has("Content-Type");
48235
48235
  if (request.body != null) {
48236
48236
  request.body.cancel();
48237
48237
  }
48238
- return duplexAccessed && !hasContentType;
48238
+ return duplexAccessed && !hasContentType2;
48239
48239
  });
48240
48240
  const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils_default.isReadableStream(new Response3("").body));
48241
48241
  const resolvers = {
@@ -143935,11 +143935,18 @@ function preflightPay(input) {
143935
143935
  return PREFLIGHT_OK;
143936
143936
  }
143937
143937
  async function payWithMpp(args) {
143938
- const { signer, client, options } = args;
143938
+ const { signer, client } = args;
143939
+ let options = args.options;
143939
143940
  const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
143940
143941
  if (!pf.valid) throw new T2000Error(pf.code, pf.error);
143941
143942
  const method = (options.method ?? "GET").toUpperCase();
143942
143943
  const canHaveBody = method !== "GET" && method !== "HEAD";
143944
+ if (canHaveBody && typeof options.body === "string" && isJsonText(options.body) && !hasContentType(options.headers)) {
143945
+ options = {
143946
+ ...options,
143947
+ headers: { ...options.headers ?? {}, "content-type": "application/json" }
143948
+ };
143949
+ }
143943
143950
  const reqInit = {
143944
143951
  method,
143945
143952
  headers: options.headers,
@@ -143951,17 +143958,36 @@ async function payWithMpp(args) {
143951
143958
  }
143952
143959
  const requirements = await pickSuiExactRequirements(probe, client.network);
143953
143960
  if (requirements) {
143954
- return payViaX402({ signer, client, options, reqInit, requirements });
143961
+ const result = await payViaX402({ signer, client, options, reqInit, requirements });
143962
+ await reportDirectPayment(result, options.url);
143963
+ return result;
143955
143964
  }
143956
143965
  const headerChallenge = await parseMppSuiChallenge(probe);
143957
143966
  if (headerChallenge) {
143958
- return payViaMppHeader({ signer, client, options });
143967
+ const result = await payViaMppHeader({ signer, client, options });
143968
+ await reportDirectPayment(result, options.url);
143969
+ return result;
143959
143970
  }
143960
143971
  throw new T2000Error(
143961
143972
  "FACILITATOR_REJECTION",
143962
143973
  `Endpoint returned 402 without an x402 'exact' / sui:${client.network} requirement in the body or an MPP 'sui' challenge in WWW-Authenticate. Nothing this SDK can pay.`
143963
143974
  );
143964
143975
  }
143976
+ var MPP_REPORT_URL = "https://mpp.t2000.ai/api/mpp/report";
143977
+ var REPORT_TIMEOUT_MS = 2e3;
143978
+ async function reportDirectPayment(result, url3) {
143979
+ if (!result.paid || !result.receipt?.reference) return;
143980
+ try {
143981
+ if (new URL(url3).origin === new URL(MPP_REPORT_URL).origin) return;
143982
+ await fetch(MPP_REPORT_URL, {
143983
+ method: "POST",
143984
+ headers: { "content-type": "application/json" },
143985
+ body: JSON.stringify({ digest: result.receipt.reference, url: url3 }),
143986
+ signal: AbortSignal.timeout(REPORT_TIMEOUT_MS)
143987
+ });
143988
+ } catch {
143989
+ }
143990
+ }
143965
143991
  async function parseMppSuiChallenge(response) {
143966
143992
  try {
143967
143993
  const { Challenge } = await Promise.resolve().then(() => (init_dist9(), dist_exports));
@@ -144126,6 +144152,18 @@ async function ensureAddressBalanceCovers(args) {
144126
144152
  const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
144127
144153
  return migration.gasCostSui;
144128
144154
  }
144155
+ function isJsonText(text) {
144156
+ try {
144157
+ JSON.parse(text);
144158
+ return true;
144159
+ } catch {
144160
+ return false;
144161
+ }
144162
+ }
144163
+ function hasContentType(headers) {
144164
+ if (!headers) return false;
144165
+ return Object.keys(headers).some((k) => k.toLowerCase() === "content-type");
144166
+ }
144129
144167
  async function finalize2(response, opts) {
144130
144168
  const contentType = response.headers.get("content-type") ?? "";
144131
144169
  let body2;
@@ -146307,7 +146345,7 @@ Through this wallet you can reach essentially any major external API, billed to
146307
146345
  CRITICAL: When the user asks to use any external or paid API, names a provider (e.g. "via fal.ai", "with ElevenLabs"), or requests a capability one of the services above provides, DO NOT say you cannot reach that service, that it isn't on an allowlist, or that there's no connector \u2014 and do NOT fall back to writing a script for the user to run. You CAN do it directly through this wallet. Use t2000_services to discover the endpoint and request shape, then t2000_pay to execute, then show the user the result (display image/audio URLs returned in the response).
146308
146346
 
146309
146347
  Spending is the user's own USDC and every t2000_pay call is bounded by maxPrice. For larger or multi-step spends, state the estimated cost first and proceed once the user is happy. Use t2000_balance to check funds. The v4 wallet is payments-only; savings / lending live on audric.ai.`;
146310
- var PKG_VERSION = "9.3.0";
146348
+ var PKG_VERSION = "9.4.0";
146311
146349
  console.log = (...args) => console.error("[log]", ...args);
146312
146350
  console.warn = (...args) => console.error("[warn]", ...args);
146313
146351
  async function startMcpServer(opts) {
@@ -146392,4 +146430,4 @@ mime-types/index.js:
146392
146430
  @scure/bip39/index.js:
146393
146431
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
146394
146432
  */
146395
- //# sourceMappingURL=dist-HPMGTXOX.js.map
146433
+ //# sourceMappingURL=dist-6T57AF5D.js.map