UNPKG

agentcash

Version:

Generic MCP server for calling x402-protected APIs with automatic payment handling

74 lines (73 loc) • 1.98 kB
import { closeMppSession } from "./chunk-FRESP5ZE.js"; import "./chunk-H2JGMFEG.js"; import "./chunk-RAS5DZPQ.js"; import { getWalletOrExit } from "./chunk-7AT3NXJ2.js"; import "./chunk-F3KGAMIA.js"; import "./chunk-HTGTKVXB.js"; import "./chunk-KVSTJRSJ.js"; import "./chunk-QZCSZB7E.js"; import { errorResponse, fromNeverthrowError, outputAndExit, successResponse } from "./chunk-7EBJ4BCH.js"; import "./chunk-YWNBUUBR.js"; import "./chunk-ITCDZXBZ.js"; // src/cli/commands/sessions.ts var SURFACE = "cli:sessions-close"; var CHANNEL_ID_PATTERN = /^0x[0-9a-fA-F]{64}$/; var CUMULATIVE_PATTERN = /^[0-9]+$/; var sessionsCloseCommand = async (args) => { if (!CHANNEL_ID_PATTERN.test(args.channelId)) { return outputAndExit( errorResponse({ code: "INVALID_INPUT", message: "channelId must be a 0x-prefixed 32-byte hex string", surface: SURFACE, cause: "validation" }), args ); } if (args.cumulativeAmountRaw !== void 0 && !CUMULATIVE_PATTERN.test(args.cumulativeAmountRaw)) { return outputAndExit( errorResponse({ code: "INVALID_INPUT", message: "--cumulative-amount-raw must be a non-negative integer (raw atomic units)", surface: SURFACE, cause: "validation" }), args ); } const wallets = await getWalletOrExit(args); const result = await closeMppSession( { channelId: args.channelId, url: args.url, cumulativeAmountRaw: args.cumulativeAmountRaw }, { surface: SURFACE, wallets, flags: args } ); if (result.isErr()) { return outputAndExit(fromNeverthrowError(result), args); } const { channelId, cumulativeAmount, transactionHash } = result.value; return outputAndExit( successResponse({ channelId, cumulativeAmount, ...transactionHash ? { transactionHash } : {} }), args ); }; export { sessionsCloseCommand }; //# sourceMappingURL=sessions-RXMJRALZ.js.map