agentcash 0.6.2 → 0.6.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.
@@ -104303,7 +104303,7 @@ var import_path2 = require("path");
104303
104303
  var import_url = require("url");
104304
104304
  function getVersion2() {
104305
104305
  if (true) {
104306
- return "0.6.2";
104306
+ return "0.6.3";
104307
104307
  }
104308
104308
  const __dirname3 = (0, import_path2.dirname)((0, import_url.fileURLToPath)(importMetaUrl));
104309
104309
  const pkg = JSON.parse(
@@ -104466,7 +104466,7 @@ var TEMPO_TOKEN_ADDRESS = "0x20c0000000000000000000000000000000000000";
104466
104466
 
104467
104467
  // src/shared/mpp-enabled.ts
104468
104468
  init_cjs_shims();
104469
- var isMppEnabled = () => "0.6.2".includes("-mpp");
104469
+ var isMppEnabled = () => "0.6.3".includes("-mpp");
104470
104470
 
104471
104471
  // src/shared/operations/fetch-with-payment.ts
104472
104472
  init_cjs_shims();
@@ -109252,27 +109252,31 @@ var parsedResponseToToolContentPart = (data) => {
109252
109252
  };
109253
109253
 
109254
109254
  // src/server/tools/response/error.ts
109255
- var buildMcpError = (content) => {
109255
+ var buildMcpError = (content, options) => {
109256
109256
  return {
109257
109257
  content,
109258
- isError: true
109258
+ // Default: omit isError so siblings survive parallel calls.
109259
+ // Tools with outputSchema MUST pass isError: true so the SDK
109260
+ // skips output validation on error paths.
109261
+ ...options?.isError ? { isError: true } : {}
109259
109262
  };
109260
109263
  };
109261
- var mcpErrorJson = (error48) => {
109264
+ var mcpErrorJson = (error48, options) => {
109262
109265
  return safeStringifyJson("mcp-error-json", error48).match(
109263
- (success3) => buildMcpError([{ type: "text", text: success3 }]),
109264
- (error49) => buildMcpError([
109265
- { type: "text", text: JSON.stringify(error49, null, 2) }
109266
- ])
109266
+ (success3) => buildMcpError([{ type: "text", text: success3 }], options),
109267
+ (error49) => buildMcpError(
109268
+ [{ type: "text", text: JSON.stringify(error49, null, 2) }],
109269
+ options
109270
+ )
109267
109271
  );
109268
109272
  };
109269
- var mcpError = async (err3) => {
109273
+ var mcpError = async (err3, options) => {
109270
109274
  const { error: error48 } = err3;
109271
109275
  if (isFetchError(error48)) {
109272
109276
  switch (error48.cause) {
109273
109277
  case "network":
109274
109278
  case "parse":
109275
- return mcpErrorJson({ ...error48 });
109279
+ return mcpErrorJson({ ...error48 }, options);
109276
109280
  case "http":
109277
109281
  const { response, ...rest } = error48;
109278
109282
  const parseResponseResult = await safeParseResponse(
@@ -109286,10 +109290,10 @@ var mcpError = async (err3) => {
109286
109290
  () => []
109287
109291
  )
109288
109292
  ];
109289
- return buildMcpError(httpContent);
109293
+ return buildMcpError(httpContent, options);
109290
109294
  }
109291
109295
  }
109292
- return mcpErrorJson({ ...error48 });
109296
+ return mcpErrorJson({ ...error48 }, options);
109293
109297
  };
109294
109298
  var mcpErrorFetch = async (surface2, response) => {
109295
109299
  return mcpError(fetchHttpErr(surface2, response));
@@ -109327,10 +109331,26 @@ var mcpSuccessResponse = (data, extra) => {
109327
109331
  ]);
109328
109332
  };
109329
109333
 
109334
+ // src/server/tools/response/safe-handler.ts
109335
+ init_cjs_shims();
109336
+ function safeHandler(handler) {
109337
+ return async (input) => {
109338
+ try {
109339
+ return await handler(input);
109340
+ } catch (e) {
109341
+ log.error("Unhandled tool error", e);
109342
+ return mcpErrorJson({
109343
+ error: e instanceof Error ? e.message : String(e),
109344
+ cause: "unhandled_exception"
109345
+ });
109346
+ }
109347
+ };
109348
+ }
109349
+
109330
109350
  // src/server/tools/lib/request.ts
109331
109351
  init_cjs_shims();
109332
109352
  var requestSchema = zod_default.object({
109333
- url: zod_default.url().describe("The endpoint URL"),
109353
+ url: zod_default.string().describe("The endpoint URL"),
109334
109354
  method: zod_default.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe("HTTP method. Defaults to GET for fetch operations."),
109335
109355
  body: zod_default.unknown().optional().describe("Request body for POST/PUT/PATCH methods"),
109336
109356
  headers: zod_default.record(zod_default.string(), zod_default.string()).optional().describe("Additional headers to include").default({}),
@@ -110108,7 +110128,7 @@ var registerFetchTool = ({
110108
110128
  openWorldHint: true
110109
110129
  }
110110
110130
  },
110111
- async (input) => {
110131
+ safeHandler(async (input) => {
110112
110132
  const paymentMethod = input.paymentMethod ?? "auto";
110113
110133
  const coreClient = x402Client.fromConfig({
110114
110134
  schemes: [
@@ -110183,7 +110203,7 @@ var registerFetchTool = ({
110183
110203
  parseResponseResult.value,
110184
110204
  paymentInfo
110185
110205
  );
110186
- }
110206
+ })
110187
110207
  );
110188
110208
  };
110189
110209
 
@@ -110287,7 +110307,7 @@ var registerAuthTools = ({
110287
110307
  openWorldHint: true
110288
110308
  }
110289
110309
  },
110290
- async (input) => {
110310
+ safeHandler(async (input) => {
110291
110311
  const result = await createFetchWithAuth({
110292
110312
  surface: toolName2,
110293
110313
  account,
@@ -110314,7 +110334,7 @@ var registerAuthTools = ({
110314
110334
  return mcpError(parseResponseResult);
110315
110335
  }
110316
110336
  return mcpSuccessResponse(parseResponseResult.value);
110317
- }
110337
+ })
110318
110338
  );
110319
110339
  };
110320
110340
 
@@ -110385,7 +110405,7 @@ var registerWalletTools = ({
110385
110405
  async () => {
110386
110406
  const result = await getWalletInfo("get_wallet_info", address, flags);
110387
110407
  if (result.isErr()) {
110388
- return mcpError(result);
110408
+ return mcpError(result, { isError: true });
110389
110409
  }
110390
110410
  return mcpSuccessStructuredJson({
110391
110411
  address: result.value.address,
@@ -110864,7 +110884,7 @@ function buildProbeRequest(url3, method, body, headers) {
110864
110884
  // src/server/tools/check-endpoint.ts
110865
110885
  var toolName3 = "check_endpoint_schema";
110866
110886
  var checkEndpointInputSchema = zod_default.object({
110867
- url: zod_default.url().describe("The endpoint URL"),
110887
+ url: zod_default.string().describe("The endpoint URL"),
110868
110888
  method: zod_default.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe(
110869
110889
  "HTTP method to check. If omitted, all methods are probed in parallel."
110870
110890
  ),
@@ -110889,7 +110909,7 @@ var registerCheckEndpointTool = ({
110889
110909
  openWorldHint: true
110890
110910
  }
110891
110911
  },
110892
- async (input) => {
110912
+ safeHandler(async (input) => {
110893
110913
  log.info("Querying endpoint", input);
110894
110914
  const { url: url3, results } = await checkEndpoint({
110895
110915
  surface: toolName3,
@@ -110910,7 +110930,7 @@ var registerCheckEndpointTool = ({
110910
110930
  });
110911
110931
  }
110912
110932
  return mcpSuccessJson(toJsonObject({ url: url3, results }));
110913
- }
110933
+ })
110914
110934
  );
110915
110935
  };
110916
110936
 
@@ -111023,7 +111043,7 @@ var registerRedeemInviteTool = ({
111023
111043
  surface: "redeem_invite"
111024
111044
  });
111025
111045
  if (result.isErr()) {
111026
- return mcpError(result);
111046
+ return mcpError(result, { isError: true });
111027
111047
  }
111028
111048
  const { amount: amount2, txHash } = result.value;
111029
111049
  return mcpSuccessStructuredJson({
@@ -111128,7 +111148,7 @@ var registerTelemetryTools = ({
111128
111148
  );
111129
111149
  if (result.isErr()) {
111130
111150
  log.error("Failed to submit error report", result.error);
111131
- return mcpError(result);
111151
+ return mcpError(result, { isError: true });
111132
111152
  }
111133
111153
  log.info("Error report submitted successfully", {
111134
111154
  reportId: result.value.reportId
@@ -111242,7 +111262,7 @@ function registerDiscoveryTools(server) {
111242
111262
  - ${"https://stableemail.dev" /* StableEmail */} -> send emails.
111243
111263
  `,
111244
111264
  inputSchema: external_exports3.object({
111245
- url: external_exports3.url().describe(
111265
+ url: external_exports3.string().describe(
111246
111266
  "The origin URL or any URL on the origin to discover resources from"
111247
111267
  )
111248
111268
  }),
@@ -111253,7 +111273,14 @@ function registerDiscoveryTools(server) {
111253
111273
  openWorldHint: true
111254
111274
  }
111255
111275
  },
111256
- async ({ url: url3 }) => {
111276
+ safeHandler(async ({ url: url3 }) => {
111277
+ if (!URL.canParse(url3)) {
111278
+ return mcpErrorJson({
111279
+ error: "Invalid URL",
111280
+ url: url3,
111281
+ hint: "Provide a fully-formed URL like https://example.com"
111282
+ });
111283
+ }
111257
111284
  log.info(`Discovering resources for: ${url3}`);
111258
111285
  const discoverResult = await resultFromPromise(
111259
111286
  "discover",
@@ -111285,7 +111312,7 @@ function registerDiscoveryTools(server) {
111285
111312
  origin,
111286
111313
  error: "No OpenAPI spec found. Tried: /openapi.json, /.well-known/openapi.json"
111287
111314
  });
111288
- }
111315
+ })
111289
111316
  );
111290
111317
  }
111291
111318
 
@@ -111775,7 +111802,7 @@ var import_path3 = require("path");
111775
111802
  var import_url2 = require("url");
111776
111803
  function getVersion3() {
111777
111804
  if (true) {
111778
- return "0.6.2";
111805
+ return "0.6.3";
111779
111806
  }
111780
111807
  const __dirname3 = (0, import_path3.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
111781
111808
  const pkg = JSON.parse(
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  isMppEnabled
3
- } from "./chunk-EGM7SQKO.js";
3
+ } from "./chunk-ZPI2XP7U.js";
4
4
  import {
5
5
  MCP_VERSION
6
- } from "./chunk-UC3J43CE.js";
6
+ } from "./chunk-FJNT5GH6.js";
7
7
  import {
8
8
  getBalance,
9
9
  getBaseUrl,
@@ -119,4 +119,4 @@ export {
119
119
  getWalletInfo,
120
120
  submitErrorReport
121
121
  };
122
- //# sourceMappingURL=chunk-KZOOVRXW.js.map
122
+ //# sourceMappingURL=chunk-2RSGMWFW.js.map
@@ -4,7 +4,7 @@ import { dirname, join } from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  function getVersion() {
6
6
  if (true) {
7
- return "0.6.2";
7
+ return "0.6.3";
8
8
  }
9
9
  const __dirname2 = dirname(fileURLToPath(import.meta.url));
10
10
  const pkg = JSON.parse(
@@ -19,4 +19,4 @@ export {
19
19
  MCP_VERSION,
20
20
  DIST_TAG
21
21
  };
22
- //# sourceMappingURL=chunk-UC3J43CE.js.map
22
+ //# sourceMappingURL=chunk-FJNT5GH6.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isMppEnabled
3
- } from "./chunk-EGM7SQKO.js";
3
+ } from "./chunk-ZPI2XP7U.js";
4
4
  import {
5
5
  DEFAULT_FETCH_TIMEOUT,
6
6
  err,
@@ -645,4 +645,4 @@ export {
645
645
  checkEndpoint,
646
646
  discoverResources
647
647
  };
648
- //# sourceMappingURL=chunk-CPB4JGR7.js.map
648
+ //# sourceMappingURL=chunk-VU4O2YQU.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTempoBalance
3
- } from "./chunk-KZOOVRXW.js";
3
+ } from "./chunk-2RSGMWFW.js";
4
4
  import {
5
5
  detectPaymentProtocols,
6
6
  getSiwxExtension,
@@ -11,7 +11,7 @@ import {
11
11
  tokenStringToNumber,
12
12
  x402Err,
13
13
  x402Ok
14
- } from "./chunk-CPB4JGR7.js";
14
+ } from "./chunk-VU4O2YQU.js";
15
15
  import {
16
16
  getBalance
17
17
  } from "./chunk-UFSCGP67.js";
@@ -30,7 +30,7 @@ import {
30
30
  // src/server/tools/lib/request.ts
31
31
  import z from "zod";
32
32
  var requestSchema = z.object({
33
- url: z.url().describe("The endpoint URL"),
33
+ url: z.string().describe("The endpoint URL"),
34
34
  method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe("HTTP method. Defaults to GET for fetch operations."),
35
35
  body: z.unknown().optional().describe("Request body for POST/PUT/PATCH methods"),
36
36
  headers: z.record(z.string(), z.string()).optional().describe("Additional headers to include").default({}),
@@ -411,4 +411,4 @@ export {
411
411
  createFetchWithPayment,
412
412
  createFetchWithAuth
413
413
  };
414
- //# sourceMappingURL=chunk-BAQ3QDQY.js.map
414
+ //# sourceMappingURL=chunk-XVQ7S42P.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/tools/lib/request.ts","../../src/shared/neverthrow/mpp/index.ts","../../src/shared/operations/fetch-with-payment.ts","../../src/shared/operations/fetch-with-auth.ts"],"sourcesContent":["import z from 'zod';\n\nimport type { Address } from 'viem';\n\nexport const requestSchema = z.object({\n url: z.string().describe('The endpoint URL'),\n method: z\n .enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])\n .optional()\n .describe('HTTP method. Defaults to GET for fetch operations.'),\n body: z\n .unknown()\n .optional()\n .describe('Request body for POST/PUT/PATCH methods'),\n headers: z\n .record(z.string(), z.string())\n .optional()\n .describe('Additional headers to include')\n .default({}),\n timeout: z\n .number()\n .int()\n .positive()\n .optional()\n .describe('Request timeout in milliseconds'),\n});\n\ninterface BuildRequestProps {\n input: z.infer<typeof requestSchema>;\n address?: Address;\n sessionId?: string;\n provider?: string;\n}\n\nexport const buildRequest = ({\n input,\n address,\n sessionId,\n provider,\n}: BuildRequestProps) => {\n return new Request(input.url, {\n method: input.method ?? 'GET',\n body: input.body\n ? typeof input.body === 'string'\n ? input.body\n : JSON.stringify(input.body)\n : undefined,\n headers: {\n ...(input.body ? { 'Content-Type': 'application/json' } : {}),\n ...input.headers,\n ...(address\n ? { 'X-Wallet-Address': address, 'X-Client-ID': provider }\n : {}),\n ...(sessionId ? { 'X-Session-ID': sessionId } : {}),\n },\n });\n};\n","import { Challenge, Receipt } from 'mppx';\nimport {\n err,\n ok,\n resultFromPromise,\n resultFromThrowable,\n} from '@agentcash/neverthrow';\n\nimport type { BaseMppError } from './types';\nconst errorType = 'mpp';\n\nexport const mppOk = <T>(value: T) => ok(value);\nexport const mppErr = (surface: string, error: BaseMppError) =>\n err(errorType, surface, error);\n\nconst mppResultFromPromise = <T>(\n surface: string,\n promise: Promise<T>,\n error: (e: unknown) => BaseMppError\n) => resultFromPromise(errorType, surface, promise, error);\n\nconst mppResultFromThrowable = <T>(\n surface: string,\n fn: () => T,\n error: (e: unknown) => BaseMppError\n) => resultFromThrowable(errorType, surface, fn, error);\n\nexport const safeGetMppChallenge = (surface: string, response: Response) => {\n return mppResultFromThrowable(\n surface,\n () => Challenge.fromResponse(response),\n error => ({\n cause: 'parse_mpp_challenge',\n message:\n error instanceof Error\n ? error.message\n : 'Failed to parse MPP challenge from response',\n })\n );\n};\n\nexport const safeCreateMppCredential = (\n surface: string,\n mppxClient: { createCredential: (response: Response) => Promise<string> },\n response: Response\n) => {\n return mppResultFromPromise(\n surface,\n mppxClient.createCredential(response),\n error => ({\n cause: 'create_mpp_credential',\n message:\n error instanceof Error\n ? error.message\n : 'Failed to create MPP credential',\n })\n );\n};\n\nexport const safeGetMppReceipt = (surface: string, response: Response) => {\n return mppResultFromThrowable(\n surface,\n () => Receipt.fromResponse(response),\n error => ({\n cause: 'parse_mpp_receipt',\n message:\n error instanceof Error\n ? error.message\n : 'Failed to parse MPP receipt from response',\n })\n );\n};\n","import { formatUnits } from 'viem';\n\nimport type { x402HTTPClient } from '@x402/core/client';\nimport type { Address } from 'viem';\nimport type { GlobalFlags } from '@/types';\n\nimport { resultFromPromise } from '@agentcash/neverthrow';\n\nimport { fetchErr, fetchOk, safeFetch } from '@/shared/neverthrow/fetch';\nimport {\n safeCreatePaymentPayload,\n safeGetPaymentRequired,\n safeGetPaymentSettlement,\n x402Err,\n x402Ok,\n} from '@/shared/neverthrow/x402';\nimport {\n safeGetMppChallenge,\n safeCreateMppCredential,\n safeGetMppReceipt,\n mppErr,\n mppOk,\n} from '@/shared/neverthrow/mpp';\n\nimport { log } from '@/shared/log';\nimport { detectPaymentProtocols } from '@/shared/protocol';\nimport { tokenStringToNumber } from '@/shared/token';\nimport { getBalance } from '@/shared/balance';\nimport { getTempoBalance } from '@/shared/tempo-balance';\n\n/**\n * Hook called before a payment is executed.\n * Throw to abort. Return to proceed.\n * Matches existing checkBalance/checkTempoBalance throw-to-abort behavior.\n */\nexport type BeforePaymentHook = (ctx: {\n protocol: 'x402' | 'mpp';\n amount: number;\n currency: string;\n network: string;\n}) => Promise<void>;\n\nexport interface PaymentClients {\n x402: x402HTTPClient;\n mpp: { createCredential: (response: Response) => Promise<string> };\n}\n\nexport interface PaymentInfo {\n protocol: 'x402' | 'mpp';\n price?: string;\n payment?: {\n success: boolean;\n transactionHash?: string;\n };\n}\n\nexport interface FetchWithPaymentResult {\n response: Response;\n paymentInfo: PaymentInfo | null;\n}\n\nexport interface FetchWithPaymentOptions {\n surface: string;\n clients: PaymentClients;\n paymentMethod: 'x402' | 'mpp' | 'auto';\n account: { address: Address };\n flags: GlobalFlags;\n beforePayment?: BeforePaymentHook;\n timeout?: number;\n}\n\n/**\n * Create a fetch function with automatic dual-protocol payment handling.\n *\n * 1. Makes initial request\n * 2. If 402 response, detects protocol(s)\n * 3. Calls beforePayment hook (for balance checks)\n * 4. Creates payment credential/payload\n * 5. Retries request with payment headers\n */\nexport function createFetchWithPayment(options: FetchWithPaymentOptions) {\n const { surface, clients, paymentMethod, beforePayment, timeout } = options;\n\n return async (request: Request) => {\n const clonedRequest = request.clone();\n const fallbackRequest = request.clone();\n\n const probeResult = await safeFetch(surface, request, timeout);\n\n if (probeResult.isErr()) {\n return fetchErr(surface, probeResult.error);\n }\n\n // Not a 402 response — return as-is\n if (probeResult.value.status !== 402) {\n return probeResult.andThen(response =>\n fetchOk<FetchWithPaymentResult>({ response, paymentInfo: null })\n );\n }\n\n const response = probeResult.value;\n\n // User explicitly chose a protocol — use that, no fallback\n if (paymentMethod !== 'auto') {\n if (paymentMethod === 'mpp') {\n return handleMppPayment(surface, response, clonedRequest, options);\n }\n return handleX402Payment(\n surface,\n response,\n clonedRequest,\n clients.x402,\n beforePayment,\n timeout\n );\n }\n\n // Auto: detect available protocols, pick by higher balance\n const available = detectPaymentProtocols(response);\n\n let preferred: 'x402' | 'mpp';\n\n if (available.length === 1) {\n preferred = available[0]!;\n } else {\n // Both protocols available — pick by balance\n preferred = await pickByBalance(surface, response, options);\n }\n\n const fallback =\n available.length > 1 ? (preferred === 'mpp' ? 'x402' : 'mpp') : null;\n\n const result =\n preferred === 'mpp'\n ? await handleMppPayment(surface, response, clonedRequest, options)\n : await handleX402Payment(\n surface,\n response,\n clonedRequest,\n clients.x402,\n beforePayment,\n timeout\n );\n\n if (result.isErr() && fallback) {\n // Preferred failed — try fallback with a fresh request clone\n return fallback === 'mpp'\n ? handleMppPayment(surface, response, fallbackRequest, options)\n : handleX402Payment(\n surface,\n response,\n fallbackRequest,\n clients.x402,\n beforePayment,\n timeout\n );\n }\n\n return result;\n };\n}\n\n/**\n * Pick the preferred protocol by comparing wallet balances.\n * Falls back to 'mpp' if both balances fail to fetch.\n */\nasync function pickByBalance(\n surface: string,\n response: Response,\n options: FetchWithPaymentOptions\n): Promise<'x402' | 'mpp'> {\n const { account } = options;\n\n // Get x402 (USDC on Base) balance\n const x402BalanceResult = await resultFromPromise(\n 'balance',\n surface,\n getBalance({\n address: account.address,\n surface,\n }).then(r => (r.isOk() ? r.value.balance : 0)),\n () => ({\n cause: 'x402_balance' as const,\n message: 'Failed to get x402 balance',\n })\n );\n\n if (x402BalanceResult.isErr()) {\n log.debug('Balance comparison failed, defaulting to mpp');\n return 'mpp';\n }\n\n const x402Balance = x402BalanceResult.value;\n\n // Get MPP (Tempo) balance — need token address from the challenge\n let mppBalance = 0;\n const challengeResult = safeGetMppChallenge(surface, response);\n if (challengeResult.isOk()) {\n const currency = challengeResult.value.request.currency as\n | string\n | undefined;\n const decimals =\n (challengeResult.value.request.decimals as number | undefined) ?? 6;\n if (currency) {\n const tempoResult = await resultFromPromise(\n 'tempo',\n surface,\n getTempoBalance({\n address: account.address,\n tokenAddress: currency as Address,\n }),\n () => ({\n cause: 'tempo_balance' as const,\n message: 'Tempo balance check failed',\n })\n );\n if (tempoResult.isOk()) {\n mppBalance = Number(formatUnits(tempoResult.value.balance, decimals));\n }\n }\n }\n\n log.info(`Protocol selection — x402: $${x402Balance}, mpp: $${mppBalance}`);\n return x402Balance >= mppBalance ? 'x402' : 'mpp';\n}\n\nasync function handleX402Payment(\n surface: string,\n response: Response,\n clonedRequest: Request,\n client: x402HTTPClient,\n beforePayment?: BeforePaymentHook,\n timeout?: number\n) {\n const paymentRequiredResult = await safeGetPaymentRequired(\n surface,\n client,\n response\n );\n\n if (paymentRequiredResult.isErr()) {\n return paymentRequiredResult;\n }\n\n const paymentRequired = paymentRequiredResult.value;\n\n // Call beforePayment hook (e.g. balance check) before signing\n if (beforePayment) {\n const accept = paymentRequired.accepts[0];\n if (accept) {\n const amount = tokenStringToNumber(accept.amount);\n const hookResult = await resultFromPromise(\n 'x402',\n surface,\n beforePayment({\n protocol: 'x402',\n amount,\n currency: 'USDC',\n network: accept.network,\n }),\n e => ({\n cause: 'payment_already_attempted' as const,\n message:\n e instanceof Error ? e.message : 'Before-payment hook failed',\n })\n );\n if (hookResult.isErr()) {\n return x402Err(surface, hookResult.error);\n }\n }\n }\n\n const paymentPayloadResult = await safeCreatePaymentPayload(\n surface,\n client,\n paymentRequired\n );\n\n if (paymentPayloadResult.isErr()) {\n return paymentPayloadResult;\n }\n\n const paymentPayload = paymentPayloadResult.value;\n\n // Encode payment header\n const paymentHeaders = client.encodePaymentSignatureHeader(paymentPayload);\n\n // Check if this is already a retry to prevent infinite loops\n if (\n clonedRequest.headers.has('PAYMENT-SIGNATURE') ||\n clonedRequest.headers.has('X-PAYMENT')\n ) {\n return x402Err(surface, {\n cause: 'payment_already_attempted',\n message: 'Payment already attempted',\n });\n }\n\n // Add payment headers to cloned request\n for (const [key, value] of Object.entries(paymentHeaders)) {\n clonedRequest.headers.set(key, value);\n }\n clonedRequest.headers.set(\n 'Access-Control-Expose-Headers',\n 'PAYMENT-RESPONSE,X-PAYMENT-RESPONSE'\n );\n\n // Retry the request with payment\n return await safeFetch(surface, clonedRequest, timeout).andThen(\n paidResponse => {\n const settlementResult = safeGetPaymentSettlement(\n surface,\n client,\n paidResponse\n );\n\n return x402Ok<FetchWithPaymentResult>({\n response: paidResponse,\n paymentInfo: {\n protocol: 'x402',\n price: tokenStringToNumber(\n paymentPayload.accepted.amount\n ).toLocaleString('en-US', {\n style: 'currency',\n currency: 'USD',\n }),\n ...(settlementResult.isOk()\n ? {\n payment: {\n success: settlementResult.value.success,\n transactionHash: settlementResult.value.transaction,\n },\n }\n : {}),\n },\n });\n }\n );\n}\n\nasync function handleMppPayment(\n surface: string,\n response: Response,\n clonedRequest: Request,\n options: FetchWithPaymentOptions\n) {\n const { clients, beforePayment, timeout } = options;\n const mppxClient = clients.mpp;\n\n // Prevent retry loops\n if (clonedRequest.headers.has('Authorization')) {\n return mppErr(surface, {\n cause: 'mpp_payment_already_attempted',\n message: 'MPP payment already attempted',\n });\n }\n\n // Parse the challenge from the WWW-Authenticate header\n const challengeResult = safeGetMppChallenge(surface, response);\n\n if (challengeResult.isErr()) {\n return challengeResult;\n }\n\n const challenge = challengeResult.value;\n\n // Extract payment info from challenge request\n const amount = challenge.request.amount as string | undefined;\n const decimals = (challenge.request.decimals as number | undefined) ?? 6;\n const currency = challenge.request.currency as string | undefined;\n\n // Call beforePayment hook (e.g. balance check)\n if (beforePayment && amount && currency) {\n const numericAmount = Number(formatUnits(BigInt(amount), decimals));\n const hookResult = await resultFromPromise(\n 'mpp',\n surface,\n beforePayment({\n protocol: 'mpp',\n amount: numericAmount,\n currency,\n network: `tempo:${challenge.method}`,\n }),\n e => ({\n cause: 'mpp_payment_already_attempted' as const,\n message: e instanceof Error ? e.message : 'Before-payment hook failed',\n })\n );\n if (hookResult.isErr()) {\n return mppErr(surface, hookResult.error);\n }\n }\n\n // Create credential (signs transaction on Tempo)\n const credentialResult = await safeCreateMppCredential(\n surface,\n mppxClient,\n response\n );\n\n if (credentialResult.isErr()) {\n return credentialResult;\n }\n\n const credential = credentialResult.value;\n\n // Set Authorization header on cloned request\n clonedRequest.headers.set('Authorization', credential);\n\n // Retry the fetch with the credential\n return await safeFetch(surface, clonedRequest, timeout).andThen(\n paidResponse => {\n // Parse the receipt for transaction hash\n const receiptResult = safeGetMppReceipt(surface, paidResponse);\n\n const priceDisplay = amount\n ? Number(formatUnits(BigInt(amount), decimals)).toLocaleString(\n 'en-US',\n {\n style: 'currency',\n currency: 'USD',\n }\n )\n : undefined;\n\n return mppOk<FetchWithPaymentResult>({\n response: paidResponse,\n paymentInfo: {\n protocol: 'mpp',\n ...(priceDisplay ? { price: priceDisplay } : {}),\n ...(receiptResult.isOk()\n ? {\n payment: {\n success: true,\n transactionHash: receiptResult.value.reference,\n },\n }\n : {}),\n },\n });\n }\n );\n}\n","import { x402Client, x402HTTPClient } from '@x402/core/client';\nimport { encodeSIWxHeader } from '@x402/extensions/sign-in-with-x';\n\nimport type { PrivateKeyAccount } from 'viem';\n\nimport {\n DEFAULT_USER_FETCH_TIMEOUT,\n fetchOk,\n safeFetch,\n} from '@/shared/neverthrow/fetch';\nimport {\n safeCreateSIWxPayload,\n safeGetPaymentRequired,\n} from '@/shared/neverthrow/x402';\nimport { getSiwxExtension } from '@/server/lib/x402-extensions';\n\nexport type FetchWithAuthResult =\n | { outcome: 'response'; response: Response; authenticated: boolean }\n | { outcome: 'no_siwx_extension'; extensions: string[] };\n\nexport interface FetchWithAuthOptions {\n surface: string;\n account: PrivateKeyAccount;\n timeout?: number;\n}\n\n/**\n * Create a fetch function with automatic SIWX (Sign-In With X) authentication.\n *\n * 1. Makes initial request\n * 2. If 402, parses for SIWX extension\n * 3. Creates signed wallet proof\n * 4. Retries with SIGN-IN-WITH-X header\n *\n * Returns a discriminated result:\n * - `outcome: 'response'` — a Response (authenticated or not), consumer handles ok/error\n * - `outcome: 'no_siwx_extension'` — 402 without SIWX, consumer decides how to present\n */\nexport function createFetchWithAuth(options: FetchWithAuthOptions) {\n const { surface, account, timeout = DEFAULT_USER_FETCH_TIMEOUT } = options;\n\n return async (request: Request) => {\n const retryRequest = request.clone();\n const httpClient = new x402HTTPClient(new x402Client());\n\n const firstResult = await safeFetch(surface, request, timeout);\n\n if (firstResult.isErr()) return firstResult;\n\n const firstResponse = firstResult.value;\n\n if (firstResponse.status !== 402) {\n return fetchOk<FetchWithAuthResult>({\n outcome: 'response',\n response: firstResponse,\n authenticated: false,\n });\n }\n\n const paymentRequiredResult = await safeGetPaymentRequired(\n surface,\n httpClient,\n firstResponse\n );\n\n if (paymentRequiredResult.isErr()) return paymentRequiredResult;\n\n const paymentRequired = paymentRequiredResult.value;\n const siwxExtension = getSiwxExtension(paymentRequired.extensions);\n\n if (!siwxExtension) {\n return fetchOk<FetchWithAuthResult>({\n outcome: 'no_siwx_extension',\n extensions: Object.keys(paymentRequired.extensions ?? {}),\n });\n }\n\n const payloadResult = await safeCreateSIWxPayload(\n surface,\n siwxExtension,\n account\n );\n\n if (payloadResult.isErr()) return payloadResult;\n\n const siwxHeader = encodeSIWxHeader(payloadResult.value);\n\n retryRequest.headers.set('SIGN-IN-WITH-X', siwxHeader);\n\n return (await safeFetch(surface, retryRequest, timeout)).andThen(response =>\n fetchOk<FetchWithAuthResult>({\n outcome: 'response',\n response,\n authenticated: true,\n })\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,OAAO;AAIP,IAAM,gBAAgB,EAAE,OAAO;AAAA,EACpC,KAAK,EAAE,OAAO,EAAE,SAAS,kBAAkB;AAAA,EAC3C,QAAQ,EACL,KAAK,CAAC,OAAO,QAAQ,OAAO,UAAU,OAAO,CAAC,EAC9C,SAAS,EACT,SAAS,oDAAoD;AAAA,EAChE,MAAM,EACH,QAAQ,EACR,SAAS,EACT,SAAS,yCAAyC;AAAA,EACrD,SAAS,EACN,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,EAC7B,SAAS,EACT,SAAS,+BAA+B,EACxC,QAAQ,CAAC,CAAC;AAAA,EACb,SAAS,EACN,OAAO,EACP,IAAI,EACJ,SAAS,EACT,SAAS,EACT,SAAS,iCAAiC;AAC/C,CAAC;AASM,IAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAyB;AACvB,SAAO,IAAI,QAAQ,MAAM,KAAK;AAAA,IAC5B,QAAQ,MAAM,UAAU;AAAA,IACxB,MAAM,MAAM,OACR,OAAO,MAAM,SAAS,WACpB,MAAM,OACN,KAAK,UAAU,MAAM,IAAI,IAC3B;AAAA,IACJ,SAAS;AAAA,MACP,GAAI,MAAM,OAAO,EAAE,gBAAgB,mBAAmB,IAAI,CAAC;AA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AAM,wBAAwB,MAAM;AAAA,MAClC;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,QAAI,sBAAsB,MAAM,EAAG,QAAO;AAE1C,UAAM,kBAAkB,sBAAsB;AAC9C,UAAM,gBAAgB,iBAAiB,gBAAgB,UAAU;AAEjE,QAAI,CAAC,eAAe;AAClB,aAAO,QAA6B;AAAA,QAClC,SAAS;AAAA,QACT,YAAY,OAAO,KAAK,gBAAgB,cAAc,CAAC,CAAC;AAAA,MAC1D,CAAC;AAAA,IACH;AAEA,UAAM,gBAAgB,MAAM;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,QAAI,cAAc,MAAM,EAAG,QAAO;AAElC,UAAM,aAAa,iBAAiB,cAAc,KAAK;AAEvD,iBAAa,QAAQ,IAAI,kBAAkB,UAAU;AAErD,YAAQ,MAAM,UAAU,SAAS,cAAc,OAAO,GAAG;AAAA,MAAQ,cAC/D,QAA6B;AAAA,QAC3B,SAAS;AAAA,QACT;AAAA,QACA,eAAe;AAAA,MACjB,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["response"]}
@@ -0,0 +1,7 @@
1
+ // src/shared/mpp-enabled.ts
2
+ var isMppEnabled = () => "0.6.3".includes("-mpp");
3
+
4
+ export {
5
+ isMppEnabled
6
+ };
7
+ //# sourceMappingURL=chunk-ZPI2XP7U.js.map
@@ -6,20 +6,20 @@ import {
6
6
  createFetchWithAuth,
7
7
  createFetchWithPayment,
8
8
  requestSchema
9
- } from "./chunk-BAQ3QDQY.js";
9
+ } from "./chunk-XVQ7S42P.js";
10
10
  import {
11
11
  TEMPO_RPC_URL,
12
12
  getWalletInfo,
13
13
  submitErrorReport
14
- } from "./chunk-KZOOVRXW.js";
14
+ } from "./chunk-2RSGMWFW.js";
15
15
  import {
16
16
  checkEndpoint,
17
17
  discoverResources
18
- } from "./chunk-CPB4JGR7.js";
19
- import "./chunk-EGM7SQKO.js";
18
+ } from "./chunk-VU4O2YQU.js";
19
+ import "./chunk-ZPI2XP7U.js";
20
20
  import {
21
21
  MCP_VERSION
22
- } from "./chunk-UC3J43CE.js";
22
+ } from "./chunk-FJNT5GH6.js";
23
23
  import {
24
24
  DEFAULT_NETWORK,
25
25
  getWallet,
@@ -583,7 +583,7 @@ async function reportErrorCommand(args, flags) {
583
583
 
584
584
  // src/cli/commands/server.ts
585
585
  async function serverCommand(flags) {
586
- const { startServer } = await import("./server-AO2FSPPT.js");
586
+ const { startServer } = await import("./server-I6GY7YDA.js");
587
587
  await startServer(flags);
588
588
  }
589
589
  export {
@@ -597,4 +597,4 @@ export {
597
597
  walletInfoCommand,
598
598
  walletRedeemCommand
599
599
  };
600
- //# sourceMappingURL=commands-CJHVEMHK.js.map
600
+ //# sourceMappingURL=commands-JAPV6DQL.js.map
package/dist/esm/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  isMppEnabled
4
- } from "./chunk-EGM7SQKO.js";
4
+ } from "./chunk-ZPI2XP7U.js";
5
5
  import "./chunk-KPEJO3KV.js";
6
6
  import {
7
7
  MCP_VERSION
8
- } from "./chunk-UC3J43CE.js";
8
+ } from "./chunk-FJNT5GH6.js";
9
9
 
10
10
  // src/index.ts
11
11
  import yargs from "yargs";
@@ -81,7 +81,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
81
81
  default: "auto"
82
82
  }),
83
83
  async (args) => {
84
- const { fetchCommand } = await import("./commands-CJHVEMHK.js");
84
+ const { fetchCommand } = await import("./commands-JAPV6DQL.js");
85
85
  await fetchCommand(
86
86
  {
87
87
  url: args.url,
@@ -116,7 +116,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
116
116
  description: "Additional headers as JSON object"
117
117
  }),
118
118
  async (args) => {
119
- const { fetchAuthCommand } = await import("./commands-CJHVEMHK.js");
119
+ const { fetchAuthCommand } = await import("./commands-JAPV6DQL.js");
120
120
  await fetchAuthCommand(
121
121
  {
122
122
  url: args.url,
@@ -149,7 +149,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
149
149
  description: "Additional headers as JSON object"
150
150
  }),
151
151
  async (args) => {
152
- const { checkCommand } = await import("./commands-CJHVEMHK.js");
152
+ const { checkCommand } = await import("./commands-JAPV6DQL.js");
153
153
  await checkCommand(
154
154
  {
155
155
  url: args.url,
@@ -169,7 +169,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
169
169
  demandOption: true
170
170
  }),
171
171
  async (args) => {
172
- const { discoverCommand } = await import("./commands-CJHVEMHK.js");
172
+ const { discoverCommand } = await import("./commands-JAPV6DQL.js");
173
173
  await discoverCommand({ url: args.url }, args);
174
174
  }
175
175
  ).command(
@@ -181,7 +181,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
181
181
  demandOption: true
182
182
  }),
183
183
  async (args) => {
184
- const { registerCommand } = await import("./commands-CJHVEMHK.js");
184
+ const { registerCommand } = await import("./commands-JAPV6DQL.js");
185
185
  await registerCommand({ url: args.url }, args);
186
186
  }
187
187
  ).command(
@@ -192,7 +192,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
192
192
  "Get wallet address, balance, and deposit link",
193
193
  (yargs3) => yargs3,
194
194
  async (args) => {
195
- const { walletInfoCommand } = await import("./commands-CJHVEMHK.js");
195
+ const { walletInfoCommand } = await import("./commands-JAPV6DQL.js");
196
196
  await walletInfoCommand({}, args);
197
197
  }
198
198
  ).command(
@@ -204,7 +204,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
204
204
  demandOption: true
205
205
  }),
206
206
  async (args) => {
207
- const { walletRedeemCommand } = await import("./commands-CJHVEMHK.js");
207
+ const { walletRedeemCommand } = await import("./commands-JAPV6DQL.js");
208
208
  await walletRedeemCommand({ code: args.code }, args);
209
209
  }
210
210
  ).demandCommand(1, "You must specify a wallet subcommand").strict(),
@@ -236,7 +236,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
236
236
  description: "Detailed report with context and repro steps"
237
237
  }),
238
238
  async (args) => {
239
- const { reportErrorCommand } = await import("./commands-CJHVEMHK.js");
239
+ const { reportErrorCommand } = await import("./commands-JAPV6DQL.js");
240
240
  await reportErrorCommand(
241
241
  {
242
242
  tool: args.tool,
@@ -254,7 +254,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
254
254
  "Start the MCP server (default when no command specified)",
255
255
  (yargs2) => yargs2,
256
256
  async (args) => {
257
- const { serverCommand } = await import("./commands-CJHVEMHK.js");
257
+ const { serverCommand } = await import("./commands-JAPV6DQL.js");
258
258
  await serverCommand(args);
259
259
  }
260
260
  ).command(
@@ -267,7 +267,7 @@ void yargs(hideBin(process.argv)).scriptName("agentcash").usage("$0 [command] [o
267
267
  default: isClaudeCode ? "claude-code" /* ClaudeCode */ : void 0
268
268
  }),
269
269
  async (args) => {
270
- const { installMcpServer } = await import("./install-7FG62LQT.js");
270
+ const { installMcpServer } = await import("./install-DTZT2V7I.js");
271
271
  await installMcpServer(args);
272
272
  }
273
273
  ).command(
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-KPEJO3KV.js";
5
5
  import {
6
6
  DIST_TAG
7
- } from "./chunk-UC3J43CE.js";
7
+ } from "./chunk-FJNT5GH6.js";
8
8
  import {
9
9
  promptDeposit,
10
10
  wait
@@ -702,4 +702,4 @@ var installMcpServer = async (flags) => {
702
702
  export {
703
703
  installMcpServer
704
704
  };
705
- //# sourceMappingURL=install-7FG62LQT.js.map
705
+ //# sourceMappingURL=install-DTZT2V7I.js.map
package/dist/esm/lib.js CHANGED
@@ -5,8 +5,8 @@ import {
5
5
  SUPPORTED_METHODS,
6
6
  checkEndpoint,
7
7
  discoverResources
8
- } from "./chunk-CPB4JGR7.js";
9
- import "./chunk-EGM7SQKO.js";
8
+ } from "./chunk-VU4O2YQU.js";
9
+ import "./chunk-ZPI2XP7U.js";
10
10
  import "./chunk-TRPO7BKD.js";
11
11
  import "./chunk-ISR6DJ53.js";
12
12