agentcash
Version:
Generic MCP server for calling x402-protected APIs with automatic payment handling
100 lines (99 loc) • 2.9 kB
JavaScript
import {
cliFetchRequestSchema
} from "./chunk-YOY6D3SX.js";
import "./chunk-MCJ446SE.js";
import "./chunk-CCWBMXQT.js";
import {
executeFetch,
getFetchResultMetadata
} from "./chunk-YIECO2O4.js";
import "./chunk-H2JGMFEG.js";
import "./chunk-4TIYIVZF.js";
import "./chunk-IKPLMFAK.js";
import "./chunk-LNJIXYCU.js";
import "./chunk-EM6OE6WL.js";
import {
safeParseResponse
} from "./chunk-RAS5DZPQ.js";
import {
getWalletOrExit
} from "./chunk-7AT3NXJ2.js";
import "./chunk-F3KGAMIA.js";
import "./chunk-HTGTKVXB.js";
import "./chunk-KVSTJRSJ.js";
import "./chunk-FB5CMO3J.js";
import "./chunk-U6FRXL3X.js";
import "./chunk-QZCSZB7E.js";
import {
errorResponse,
fromNeverthrowError,
outputAndExit,
successResponse
} from "./chunk-7EBJ4BCH.js";
import "./chunk-YPFBBTA2.js";
import "./chunk-YWNBUUBR.js";
import "./chunk-ITCDZXBZ.js";
// src/cli/commands/fetch.ts
var SURFACE = "cli:fetch";
var fetchCommand = async (input) => {
const requestInput = cliFetchRequestSchema.safeParse(input);
if (!requestInput.success) {
return outputAndExit(
errorResponse({
code: "INVALID_INPUT",
message: requestInput.error.message,
surface: SURFACE,
cause: "validation"
}),
input
);
}
const wallets = await getWalletOrExit(input);
const fetchResult = await executeFetch(requestInput.data, {
surface: SURFACE,
wallets,
flags: input,
params: input
});
if (fetchResult.isErr()) {
return outputAndExit(fromNeverthrowError(fetchResult), input);
}
const { response, paymentInfo } = fetchResult.value;
const resultMetadata = getFetchResultMetadata(response, paymentInfo);
if (!response.ok) {
const parseResult = await safeParseResponse(SURFACE, response);
return outputAndExit(
errorResponse({
code: "HTTP_ERROR",
message: response.statusText,
surface: SURFACE,
cause: "http",
details: parseResult.match(
(data2) => ({
statusCode: response.status,
type: data2.type,
body: data2.type === "json" || data2.type === "text" ? data2.data : void 0,
...resultMetadata
}),
() => ({ statusCode: response.status, ...resultMetadata })
)
}),
input
);
}
const parseResponseResult = await safeParseResponse(SURFACE, response);
if (parseResponseResult.isErr()) {
const error = fromNeverthrowError(parseResponseResult);
return outputAndExit(
errorResponse({ ...error.error, details: resultMetadata }),
input
);
}
const parsedResponse = parseResponseResult.value;
const data = parsedResponse.type === "json" || parsedResponse.type === "text" ? parsedResponse.data : { type: parsedResponse.type };
outputAndExit(successResponse(data, resultMetadata), input);
};
export {
fetchCommand
};
//# sourceMappingURL=fetch-SC43UYLV.js.map