agentcash 0.8.0 → 0.8.2
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.
- package/dist/cjs/run-server.cjs +167 -37
- package/dist/esm/{chunk-YQFK4U62.js → chunk-36KCO2CQ.js} +2 -2
- package/dist/esm/{chunk-Z2R7VYNM.js → chunk-3WG74L5Z.js} +86 -17
- package/dist/esm/chunk-3WG74L5Z.js.map +1 -0
- package/dist/esm/{chunk-W7DAJMFQ.js → chunk-4ALGXM6F.js} +11 -4
- package/dist/esm/chunk-4ALGXM6F.js.map +1 -0
- package/dist/esm/{chunk-ZDDDU5O2.js → chunk-5GVHLIVV.js} +2 -2
- package/dist/esm/{chunk-7ZEXMJYJ.js → chunk-B2JUF6FK.js} +3 -3
- package/dist/esm/{chunk-6PU3XK6I.js → chunk-CM4BCEDY.js} +2 -2
- package/dist/esm/{chunk-6PU3XK6I.js.map → chunk-CM4BCEDY.js.map} +1 -1
- package/dist/esm/{chunk-UN3PRLTL.js → chunk-DXPPE7QC.js} +5 -5
- package/dist/esm/{chunk-5ELAEV2M.js → chunk-EQTHURHC.js} +5 -24
- package/dist/esm/chunk-EQTHURHC.js.map +1 -0
- package/dist/esm/{chunk-62B3GENJ.js → chunk-FFYCYLF4.js} +6 -6
- package/dist/esm/chunk-I7DEUXBL.js +7 -0
- package/dist/esm/{chunk-ZOVLXKVL.js → chunk-KAEAFW3A.js} +1 -13
- package/dist/esm/chunk-KAEAFW3A.js.map +1 -0
- package/dist/esm/{chunk-4R52CY5Q.js → chunk-LKZJ456N.js} +2 -2
- package/dist/esm/{chunk-OHA3LLUQ.js → chunk-NCBPOUV6.js} +3 -3
- package/dist/esm/{chunk-C36IAW7R.js → chunk-NPZ6POPF.js} +3 -3
- package/dist/esm/{chunk-VR5I67WE.js → chunk-RD4Y3CJX.js} +2 -2
- package/dist/esm/{commands-YSOBBE4N.js → commands-ZBVUG2Q5.js} +62 -23
- package/dist/esm/commands-ZBVUG2Q5.js.map +1 -0
- package/dist/esm/{fund-PRV53MDA.js → fund-IZ2RYDXT.js} +7 -7
- package/dist/esm/index.js +62 -25
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{install-QT37XD4R.js → install-LUCT7K6W.js} +10 -10
- package/dist/esm/lib.js +4 -4
- package/dist/esm/{server-QARME5NA.js → server-EH7FWUSW.js} +88 -27
- package/dist/esm/server-EH7FWUSW.js.map +1 -0
- package/dist/esm/shared/operations/index.js +7 -7
- package/package.json +1 -1
- package/dist/esm/chunk-5ELAEV2M.js.map +0 -1
- package/dist/esm/chunk-FBPC4LGY.js +0 -7
- package/dist/esm/chunk-W7DAJMFQ.js.map +0 -1
- package/dist/esm/chunk-Z2R7VYNM.js.map +0 -1
- package/dist/esm/chunk-ZOVLXKVL.js.map +0 -1
- package/dist/esm/commands-YSOBBE4N.js.map +0 -1
- package/dist/esm/server-QARME5NA.js.map +0 -1
- /package/dist/esm/{chunk-YQFK4U62.js.map → chunk-36KCO2CQ.js.map} +0 -0
- /package/dist/esm/{chunk-ZDDDU5O2.js.map → chunk-5GVHLIVV.js.map} +0 -0
- /package/dist/esm/{chunk-7ZEXMJYJ.js.map → chunk-B2JUF6FK.js.map} +0 -0
- /package/dist/esm/{chunk-UN3PRLTL.js.map → chunk-DXPPE7QC.js.map} +0 -0
- /package/dist/esm/{chunk-62B3GENJ.js.map → chunk-FFYCYLF4.js.map} +0 -0
- /package/dist/esm/{chunk-FBPC4LGY.js.map → chunk-I7DEUXBL.js.map} +0 -0
- /package/dist/esm/{chunk-4R52CY5Q.js.map → chunk-LKZJ456N.js.map} +0 -0
- /package/dist/esm/{chunk-OHA3LLUQ.js.map → chunk-NCBPOUV6.js.map} +0 -0
- /package/dist/esm/{chunk-C36IAW7R.js.map → chunk-NPZ6POPF.js.map} +0 -0
- /package/dist/esm/{chunk-VR5I67WE.js.map → chunk-RD4Y3CJX.js.map} +0 -0
- /package/dist/esm/{fund-PRV53MDA.js.map → fund-IZ2RYDXT.js.map} +0 -0
- /package/dist/esm/{install-QT37XD4R.js.map → install-LUCT7K6W.js.map} +0 -0
package/dist/cjs/run-server.cjs
CHANGED
|
@@ -6860,12 +6860,12 @@ var require_dist = __commonJS({
|
|
|
6860
6860
|
throw new Error(`Unknown format "${name}"`);
|
|
6861
6861
|
return f;
|
|
6862
6862
|
};
|
|
6863
|
-
function addFormats(ajv, list2,
|
|
6863
|
+
function addFormats(ajv, list2, fs11, exportName) {
|
|
6864
6864
|
var _a2;
|
|
6865
6865
|
var _b;
|
|
6866
6866
|
(_a2 = (_b = ajv.opts.code).formats) !== null && _a2 !== void 0 ? _a2 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
6867
6867
|
for (const f of list2)
|
|
6868
|
-
ajv.addFormat(f,
|
|
6868
|
+
ajv.addFormat(f, fs11[f]);
|
|
6869
6869
|
}
|
|
6870
6870
|
module2.exports = exports2 = formatsPlugin;
|
|
6871
6871
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -47364,7 +47364,7 @@ var require_node_gyp_build = __commonJS({
|
|
|
47364
47364
|
"../../../node_modules/.pnpm/node-gyp-build@4.8.4/node_modules/node-gyp-build/node-gyp-build.js"(exports2, module2) {
|
|
47365
47365
|
"use strict";
|
|
47366
47366
|
init_cjs_shims();
|
|
47367
|
-
var
|
|
47367
|
+
var fs11 = require("fs");
|
|
47368
47368
|
var path2 = require("path");
|
|
47369
47369
|
var os2 = require("os");
|
|
47370
47370
|
var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
@@ -47425,7 +47425,7 @@ var require_node_gyp_build = __commonJS({
|
|
|
47425
47425
|
};
|
|
47426
47426
|
function readdirSync2(dir) {
|
|
47427
47427
|
try {
|
|
47428
|
-
return
|
|
47428
|
+
return fs11.readdirSync(dir);
|
|
47429
47429
|
} catch (err3) {
|
|
47430
47430
|
return [];
|
|
47431
47431
|
}
|
|
@@ -47519,7 +47519,7 @@ var require_node_gyp_build = __commonJS({
|
|
|
47519
47519
|
return typeof window !== "undefined" && window.process && window.process.type === "renderer";
|
|
47520
47520
|
}
|
|
47521
47521
|
function isAlpine(platform3) {
|
|
47522
|
-
return platform3 === "linux" &&
|
|
47522
|
+
return platform3 === "linux" && fs11.existsSync("/etc/alpine-release");
|
|
47523
47523
|
}
|
|
47524
47524
|
load.parseTags = parseTags;
|
|
47525
47525
|
load.matchTags = matchTags;
|
|
@@ -64755,7 +64755,7 @@ init_cjs_shims();
|
|
|
64755
64755
|
// src/shared/log.ts
|
|
64756
64756
|
init_cjs_shims();
|
|
64757
64757
|
|
|
64758
|
-
// ../../internal/neverthrow/
|
|
64758
|
+
// ../../internal/neverthrow/src/index.ts
|
|
64759
64759
|
init_cjs_shims();
|
|
64760
64760
|
|
|
64761
64761
|
// ../../../node_modules/.pnpm/neverthrow@8.2.0/node_modules/neverthrow/dist/index.es.js
|
|
@@ -65238,7 +65238,7 @@ var Err = class {
|
|
|
65238
65238
|
};
|
|
65239
65239
|
var fromThrowable = Result.fromThrowable;
|
|
65240
65240
|
|
|
65241
|
-
// ../../internal/neverthrow/
|
|
65241
|
+
// ../../internal/neverthrow/src/index.ts
|
|
65242
65242
|
function resultFromPromise(type4, surface2, promise3, error48) {
|
|
65243
65243
|
return ResultAsync.fromPromise(promise3, (e) => ({
|
|
65244
65244
|
...error48(e),
|
|
@@ -113816,7 +113816,7 @@ var import_path2 = require("path");
|
|
|
113816
113816
|
var import_url = require("url");
|
|
113817
113817
|
function getVersion2() {
|
|
113818
113818
|
if (true) {
|
|
113819
|
-
return "0.8.
|
|
113819
|
+
return "0.8.2";
|
|
113820
113820
|
}
|
|
113821
113821
|
const __dirname3 = (0, import_path2.dirname)((0, import_url.fileURLToPath)(importMetaUrl));
|
|
113822
113822
|
const pkg = JSON.parse(
|
|
@@ -113979,7 +113979,7 @@ var TEMPO_TOKEN_ADDRESS = "0x20c0000000000000000000000000000000000000";
|
|
|
113979
113979
|
|
|
113980
113980
|
// src/shared/mpp-enabled.ts
|
|
113981
113981
|
init_cjs_shims();
|
|
113982
|
-
var isMppEnabled = () => "0.8.
|
|
113982
|
+
var isMppEnabled = () => "0.8.2".includes("-mpp");
|
|
113983
113983
|
|
|
113984
113984
|
// src/shared/operations/fetch-with-payment.ts
|
|
113985
113985
|
init_cjs_shims();
|
|
@@ -114848,9 +114848,35 @@ async function getTempoBalance({
|
|
|
114848
114848
|
};
|
|
114849
114849
|
}
|
|
114850
114850
|
|
|
114851
|
+
// src/shared/settings.ts
|
|
114852
|
+
init_cjs_shims();
|
|
114853
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
114854
|
+
var SETTINGS_FILE = configFile("settings.json");
|
|
114855
|
+
var settingsSchema = zod_default.looseObject({
|
|
114856
|
+
maxAmount: zod_default.number().positive()
|
|
114857
|
+
}).partial();
|
|
114858
|
+
var getSettings = () => {
|
|
114859
|
+
if (!import_fs4.default.existsSync(SETTINGS_FILE)) {
|
|
114860
|
+
return {};
|
|
114861
|
+
}
|
|
114862
|
+
const content = import_fs4.default.readFileSync(SETTINGS_FILE, "utf-8");
|
|
114863
|
+
const result = settingsSchema.safeParse(JSON.parse(content));
|
|
114864
|
+
if (!result.success) {
|
|
114865
|
+
return {};
|
|
114866
|
+
}
|
|
114867
|
+
return result.data;
|
|
114868
|
+
};
|
|
114869
|
+
var setSettings = (settings) => {
|
|
114870
|
+
const existing = getSettings();
|
|
114871
|
+
const newSettings = settingsSchema.parse({ ...existing, ...settings });
|
|
114872
|
+
import_fs4.default.writeFileSync(SETTINGS_FILE, JSON.stringify(newSettings, null, 2));
|
|
114873
|
+
};
|
|
114874
|
+
|
|
114851
114875
|
// src/shared/operations/fetch-with-payment.ts
|
|
114876
|
+
var DEFAULT_MAX_AMOUNT = 5;
|
|
114852
114877
|
function createFetchWithPayment(options) {
|
|
114853
|
-
const { surface: surface2, clients, paymentMethod, beforePayment, timeout } = options;
|
|
114878
|
+
const { surface: surface2, clients, paymentMethod, beforePayment, timeout, maxAmount } = options;
|
|
114879
|
+
const effectiveMaxAmount = maxAmount ?? getSettings().maxAmount ?? DEFAULT_MAX_AMOUNT;
|
|
114854
114880
|
return async (request) => {
|
|
114855
114881
|
const clonedRequest = request.clone();
|
|
114856
114882
|
const fallbackRequest = request.clone();
|
|
@@ -114866,7 +114892,13 @@ function createFetchWithPayment(options) {
|
|
|
114866
114892
|
const response = probeResult.value;
|
|
114867
114893
|
if (paymentMethod !== "auto") {
|
|
114868
114894
|
if (paymentMethod === "mpp") {
|
|
114869
|
-
return handleMppPayment(
|
|
114895
|
+
return handleMppPayment(
|
|
114896
|
+
surface2,
|
|
114897
|
+
response,
|
|
114898
|
+
clonedRequest,
|
|
114899
|
+
options,
|
|
114900
|
+
effectiveMaxAmount
|
|
114901
|
+
);
|
|
114870
114902
|
}
|
|
114871
114903
|
return handleX402Payment(
|
|
114872
114904
|
surface2,
|
|
@@ -114874,7 +114906,8 @@ function createFetchWithPayment(options) {
|
|
|
114874
114906
|
clonedRequest,
|
|
114875
114907
|
clients.x402,
|
|
114876
114908
|
beforePayment,
|
|
114877
|
-
timeout
|
|
114909
|
+
timeout,
|
|
114910
|
+
effectiveMaxAmount
|
|
114878
114911
|
);
|
|
114879
114912
|
}
|
|
114880
114913
|
const available = detectPaymentProtocols(response);
|
|
@@ -114885,22 +114918,36 @@ function createFetchWithPayment(options) {
|
|
|
114885
114918
|
preferred = await pickByBalance(surface2, response, options);
|
|
114886
114919
|
}
|
|
114887
114920
|
const fallback = available.length > 1 ? preferred === "mpp" ? "x402" : "mpp" : null;
|
|
114888
|
-
const result = preferred === "mpp" ? await handleMppPayment(
|
|
114921
|
+
const result = preferred === "mpp" ? await handleMppPayment(
|
|
114922
|
+
surface2,
|
|
114923
|
+
response,
|
|
114924
|
+
clonedRequest,
|
|
114925
|
+
options,
|
|
114926
|
+
effectiveMaxAmount
|
|
114927
|
+
) : await handleX402Payment(
|
|
114889
114928
|
surface2,
|
|
114890
114929
|
response,
|
|
114891
114930
|
clonedRequest,
|
|
114892
114931
|
clients.x402,
|
|
114893
114932
|
beforePayment,
|
|
114894
|
-
timeout
|
|
114933
|
+
timeout,
|
|
114934
|
+
effectiveMaxAmount
|
|
114895
114935
|
);
|
|
114896
114936
|
if (result.isErr() && fallback) {
|
|
114897
|
-
return fallback === "mpp" ? handleMppPayment(
|
|
114937
|
+
return fallback === "mpp" ? handleMppPayment(
|
|
114938
|
+
surface2,
|
|
114939
|
+
response,
|
|
114940
|
+
fallbackRequest,
|
|
114941
|
+
options,
|
|
114942
|
+
effectiveMaxAmount
|
|
114943
|
+
) : handleX402Payment(
|
|
114898
114944
|
surface2,
|
|
114899
114945
|
response,
|
|
114900
114946
|
fallbackRequest,
|
|
114901
114947
|
clients.x402,
|
|
114902
114948
|
beforePayment,
|
|
114903
|
-
timeout
|
|
114949
|
+
timeout,
|
|
114950
|
+
effectiveMaxAmount
|
|
114904
114951
|
);
|
|
114905
114952
|
}
|
|
114906
114953
|
return result;
|
|
@@ -114952,7 +114999,7 @@ async function pickByBalance(surface2, response, options) {
|
|
|
114952
114999
|
log.info(`Protocol selection \u2014 x402: $${x402Balance}, mpp: $${mppBalance}`);
|
|
114953
115000
|
return x402Balance >= mppBalance ? "x402" : "mpp";
|
|
114954
115001
|
}
|
|
114955
|
-
async function handleX402Payment(surface2, response, clonedRequest, client, beforePayment, timeout) {
|
|
115002
|
+
async function handleX402Payment(surface2, response, clonedRequest, client, beforePayment, timeout, maxAmount) {
|
|
114956
115003
|
const paymentRequiredResult = await safeGetPaymentRequired(
|
|
114957
115004
|
surface2,
|
|
114958
115005
|
client,
|
|
@@ -114962,8 +115009,17 @@ async function handleX402Payment(surface2, response, clonedRequest, client, befo
|
|
|
114962
115009
|
return paymentRequiredResult;
|
|
114963
115010
|
}
|
|
114964
115011
|
const paymentRequired = paymentRequiredResult.value;
|
|
115012
|
+
const accept = paymentRequired.accepts[0];
|
|
115013
|
+
if (accept) {
|
|
115014
|
+
const amount2 = tokenStringToNumber(accept.amount);
|
|
115015
|
+
if (amount2 > maxAmount) {
|
|
115016
|
+
return x402Err(surface2, {
|
|
115017
|
+
cause: "payment_already_attempted",
|
|
115018
|
+
message: `Endpoint requested $${amount2} which exceeds the maximum allowed amount of $${maxAmount}. Pass a higher maxAmount on this call, or use update_settings to raise the default permanently.`
|
|
115019
|
+
});
|
|
115020
|
+
}
|
|
115021
|
+
}
|
|
114965
115022
|
if (beforePayment) {
|
|
114966
|
-
const accept = paymentRequired.accepts[0];
|
|
114967
115023
|
if (accept) {
|
|
114968
115024
|
const amount2 = tokenStringToNumber(accept.amount);
|
|
114969
115025
|
const hookResult = await resultFromPromise(
|
|
@@ -115036,7 +115092,7 @@ async function handleX402Payment(surface2, response, clonedRequest, client, befo
|
|
|
115036
115092
|
}
|
|
115037
115093
|
);
|
|
115038
115094
|
}
|
|
115039
|
-
async function handleMppPayment(surface2, response, clonedRequest, options) {
|
|
115095
|
+
async function handleMppPayment(surface2, response, clonedRequest, options, maxAmount) {
|
|
115040
115096
|
const { clients, beforePayment, timeout } = options;
|
|
115041
115097
|
const mppxClient = clients.mpp;
|
|
115042
115098
|
if (clonedRequest.headers.has("Authorization")) {
|
|
@@ -115053,6 +115109,15 @@ async function handleMppPayment(surface2, response, clonedRequest, options) {
|
|
|
115053
115109
|
const amount2 = challenge2.request.amount;
|
|
115054
115110
|
const decimals2 = challenge2.request.decimals ?? 6;
|
|
115055
115111
|
const currency2 = challenge2.request.currency;
|
|
115112
|
+
if (amount2) {
|
|
115113
|
+
const numericAmount = Number(formatUnits(BigInt(amount2), decimals2));
|
|
115114
|
+
if (numericAmount > maxAmount) {
|
|
115115
|
+
return mppErr(surface2, {
|
|
115116
|
+
cause: "mpp_payment_already_attempted",
|
|
115117
|
+
message: `Endpoint requested $${numericAmount} which exceeds the maximum allowed amount of $${maxAmount}. Pass a higher maxAmount on this call, or use update_settings to raise the default permanently.`
|
|
115118
|
+
});
|
|
115119
|
+
}
|
|
115120
|
+
}
|
|
115056
115121
|
if (beforePayment && amount2 && currency2) {
|
|
115057
115122
|
const numericAmount = Number(formatUnits(BigInt(amount2), decimals2));
|
|
115058
115123
|
const hookResult = await resultFromPromise(
|
|
@@ -115393,6 +115458,12 @@ ${PRIMARY_ORIGINS.flatMap((o) => ORIGIN_METADATA[o] ? [` ${o} \u2014 ${ORIGIN_M
|
|
|
115393
115458
|
reportError: {
|
|
115394
115459
|
mcp: `EMERGENCY ONLY. Report critical MCP tool bugs. Do NOT use for normal errors (balance, network, 4xx) \u2014 those are recoverable.`,
|
|
115395
115460
|
cli: `Report a critical bug to the agentcash team (emergency only). Do NOT use for normal errors like low balance, network timeouts, or 4xx responses \u2014 those are recoverable without filing a report.`
|
|
115461
|
+
},
|
|
115462
|
+
updateSettings: {
|
|
115463
|
+
mcp: `Update user settings (persisted to ~/.agentcash/settings.json). Currently supports maxAmount \u2014 the maximum USD amount allowed per fetch request. If a fetch response requests more than this, the payment is rejected. Returns the current settings after applying changes.`
|
|
115464
|
+
},
|
|
115465
|
+
getSettings: {
|
|
115466
|
+
mcp: `Get current user settings. Returns persisted values from ~/.agentcash/settings.json with defaults applied.`
|
|
115396
115467
|
}
|
|
115397
115468
|
};
|
|
115398
115469
|
var WORKFLOW = [
|
|
@@ -115429,7 +115500,8 @@ var REQUEST_PARAMS = {
|
|
|
115429
115500
|
};
|
|
115430
115501
|
var TOOL_PARAMS = {
|
|
115431
115502
|
fetch: {
|
|
115432
|
-
paymentMethod: "Payment protocol to use. Defaults to auto-detect."
|
|
115503
|
+
paymentMethod: "Payment protocol to use. Defaults to auto-detect.",
|
|
115504
|
+
maxAmount: "Maximum amount (in USD) to pay per request. Aborts if the endpoint requests more. Defaults to $5. Pass a higher value for known-expensive endpoints."
|
|
115433
115505
|
},
|
|
115434
115506
|
checkEndpointSchema: {
|
|
115435
115507
|
url: "Full URL of the endpoint to inspect",
|
|
@@ -115594,7 +115666,8 @@ Insufficient Tempo balance for this payment.`
|
|
|
115594
115666
|
var toolName = "fetch";
|
|
115595
115667
|
var paymentMethodEnum = isMppEnabled() ? external_exports3.enum(["x402", "mpp", "auto"]) : external_exports3.enum(["x402", "auto"]);
|
|
115596
115668
|
var fetchInputSchema = requestSchema.extend({
|
|
115597
|
-
paymentMethod: paymentMethodEnum.default("auto").optional().describe(TOOL_PARAMS.fetch.paymentMethod)
|
|
115669
|
+
paymentMethod: paymentMethodEnum.default("auto").optional().describe(TOOL_PARAMS.fetch.paymentMethod),
|
|
115670
|
+
maxAmount: external_exports3.number().positive().optional().describe(TOOL_PARAMS.fetch.maxAmount)
|
|
115598
115671
|
});
|
|
115599
115672
|
var registerFetchTool = ({
|
|
115600
115673
|
server,
|
|
@@ -115682,7 +115755,8 @@ var registerFetchTool = ({
|
|
|
115682
115755
|
account,
|
|
115683
115756
|
flags,
|
|
115684
115757
|
beforePayment,
|
|
115685
|
-
timeout: input.timeout ?? DEFAULT_USER_FETCH_TIMEOUT
|
|
115758
|
+
timeout: input.timeout ?? DEFAULT_USER_FETCH_TIMEOUT,
|
|
115759
|
+
maxAmount: input.maxAmount
|
|
115686
115760
|
})(request);
|
|
115687
115761
|
if (fetchResult.isErr()) {
|
|
115688
115762
|
return mcpError(fetchResult);
|
|
@@ -115845,18 +115919,18 @@ init_cjs_shims();
|
|
|
115845
115919
|
|
|
115846
115920
|
// src/shared/state.ts
|
|
115847
115921
|
init_cjs_shims();
|
|
115848
|
-
var
|
|
115922
|
+
var import_fs6 = __toESM(require("fs"), 1);
|
|
115849
115923
|
var STATE_FILE = configFile("state.json");
|
|
115850
115924
|
var stateSchema = zod_default.looseObject({
|
|
115851
115925
|
redeemedCodes: zod_default.array(zod_default.string())
|
|
115852
115926
|
}).partial();
|
|
115853
115927
|
var getState = () => {
|
|
115854
|
-
const stateFileExists =
|
|
115928
|
+
const stateFileExists = import_fs6.default.existsSync(STATE_FILE);
|
|
115855
115929
|
if (!stateFileExists) {
|
|
115856
|
-
|
|
115930
|
+
import_fs6.default.writeFileSync(STATE_FILE, "{}");
|
|
115857
115931
|
return {};
|
|
115858
115932
|
}
|
|
115859
|
-
const stateFileContent =
|
|
115933
|
+
const stateFileContent = import_fs6.default.readFileSync(STATE_FILE, "utf-8");
|
|
115860
115934
|
const result = stateSchema.safeParse(JSON.parse(stateFileContent));
|
|
115861
115935
|
if (!result.success) {
|
|
115862
115936
|
return {};
|
|
@@ -115866,7 +115940,7 @@ var getState = () => {
|
|
|
115866
115940
|
var setState = (state) => {
|
|
115867
115941
|
const existing = getState();
|
|
115868
115942
|
const newState = stateSchema.parse({ ...existing, ...state });
|
|
115869
|
-
|
|
115943
|
+
import_fs6.default.writeFileSync(STATE_FILE, JSON.stringify(newState, null, 2));
|
|
115870
115944
|
};
|
|
115871
115945
|
|
|
115872
115946
|
// src/shared/operations/onboarding-cta.ts
|
|
@@ -117313,6 +117387,61 @@ function registerDiscoveryTools(server) {
|
|
|
117313
117387
|
);
|
|
117314
117388
|
}
|
|
117315
117389
|
|
|
117390
|
+
// src/server/tools/settings.ts
|
|
117391
|
+
init_cjs_shims();
|
|
117392
|
+
var registerSettingsTools = ({ server }) => {
|
|
117393
|
+
server.registerTool(
|
|
117394
|
+
"update_settings",
|
|
117395
|
+
{
|
|
117396
|
+
title: "Update Settings",
|
|
117397
|
+
description: DESCRIPTIONS.updateSettings.mcp,
|
|
117398
|
+
inputSchema: external_exports3.object({
|
|
117399
|
+
maxAmount: external_exports3.number().positive().optional().describe(
|
|
117400
|
+
`Maximum amount (USD) to pay per fetch request. Current default: $${DEFAULT_MAX_AMOUNT}.`
|
|
117401
|
+
)
|
|
117402
|
+
}),
|
|
117403
|
+
annotations: {
|
|
117404
|
+
readOnlyHint: false,
|
|
117405
|
+
destructiveHint: false,
|
|
117406
|
+
idempotentHint: true,
|
|
117407
|
+
openWorldHint: false
|
|
117408
|
+
}
|
|
117409
|
+
},
|
|
117410
|
+
safeHandler((input) => {
|
|
117411
|
+
if (input.maxAmount !== void 0) {
|
|
117412
|
+
setSettings({ maxAmount: input.maxAmount });
|
|
117413
|
+
}
|
|
117414
|
+
const settings = getSettings();
|
|
117415
|
+
return Promise.resolve(
|
|
117416
|
+
mcpSuccessStructuredJson({
|
|
117417
|
+
maxAmount: settings.maxAmount ?? DEFAULT_MAX_AMOUNT
|
|
117418
|
+
})
|
|
117419
|
+
);
|
|
117420
|
+
})
|
|
117421
|
+
);
|
|
117422
|
+
server.registerTool(
|
|
117423
|
+
"get_settings",
|
|
117424
|
+
{
|
|
117425
|
+
title: "Get Settings",
|
|
117426
|
+
description: DESCRIPTIONS.getSettings.mcp,
|
|
117427
|
+
annotations: {
|
|
117428
|
+
readOnlyHint: true,
|
|
117429
|
+
destructiveHint: false,
|
|
117430
|
+
idempotentHint: true,
|
|
117431
|
+
openWorldHint: false
|
|
117432
|
+
}
|
|
117433
|
+
},
|
|
117434
|
+
safeHandler(() => {
|
|
117435
|
+
const settings = getSettings();
|
|
117436
|
+
return Promise.resolve(
|
|
117437
|
+
mcpSuccessStructuredJson({
|
|
117438
|
+
maxAmount: settings.maxAmount ?? DEFAULT_MAX_AMOUNT
|
|
117439
|
+
})
|
|
117440
|
+
);
|
|
117441
|
+
})
|
|
117442
|
+
);
|
|
117443
|
+
};
|
|
117444
|
+
|
|
117316
117445
|
// src/server/resources/origins.ts
|
|
117317
117446
|
init_cjs_shims();
|
|
117318
117447
|
var surface = "registerOrigins";
|
|
@@ -117752,16 +117881,16 @@ var registerPrompts = (props) => {
|
|
|
117752
117881
|
|
|
117753
117882
|
// src/server/lib/version.ts
|
|
117754
117883
|
init_cjs_shims();
|
|
117755
|
-
var
|
|
117884
|
+
var import_fs8 = require("fs");
|
|
117756
117885
|
var import_path3 = require("path");
|
|
117757
117886
|
var import_url2 = require("url");
|
|
117758
117887
|
function getVersion3() {
|
|
117759
117888
|
if (true) {
|
|
117760
|
-
return "0.8.
|
|
117889
|
+
return "0.8.2";
|
|
117761
117890
|
}
|
|
117762
117891
|
const __dirname3 = (0, import_path3.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
|
|
117763
117892
|
const pkg = JSON.parse(
|
|
117764
|
-
(0,
|
|
117893
|
+
(0, import_fs8.readFileSync)((0, import_path3.join)(__dirname3, "../../../package.json"), "utf-8")
|
|
117765
117894
|
);
|
|
117766
117895
|
return pkg.version;
|
|
117767
117896
|
}
|
|
@@ -117770,7 +117899,7 @@ var DIST_TAG2 = MCP_VERSION2.includes("-beta") ? "beta" : "latest";
|
|
|
117770
117899
|
|
|
117771
117900
|
// src/shared/wallet.ts
|
|
117772
117901
|
init_cjs_shims();
|
|
117773
|
-
var
|
|
117902
|
+
var import_fs9 = require("fs");
|
|
117774
117903
|
var import_path4 = require("path");
|
|
117775
117904
|
var WALLET_FILE = configFile("wallet.json");
|
|
117776
117905
|
var storedWalletSchema = zod_default.object({
|
|
@@ -117783,14 +117912,14 @@ var LEGACY_WALLET = (0, import_path4.join)(LEGACY_DIRECTORY, "wallet.json");
|
|
|
117783
117912
|
var reconcileSurface = "wallet-reconcile";
|
|
117784
117913
|
async function reconcileLegacyWallet(current, isNew) {
|
|
117785
117914
|
const noChange = { account: current, isNew };
|
|
117786
|
-
if (!(0,
|
|
117915
|
+
if (!(0, import_fs9.existsSync)(LEGACY_WALLET)) {
|
|
117787
117916
|
return noChange;
|
|
117788
117917
|
}
|
|
117789
117918
|
const legacyResult = resultFromThrowable(
|
|
117790
117919
|
"wallet",
|
|
117791
117920
|
reconcileSurface,
|
|
117792
117921
|
() => {
|
|
117793
|
-
const raw = (0,
|
|
117922
|
+
const raw = (0, import_fs9.readFileSync)(LEGACY_WALLET, "utf-8");
|
|
117794
117923
|
return storedWalletSchema.parse(JSON.parse(raw));
|
|
117795
117924
|
},
|
|
117796
117925
|
() => ({
|
|
@@ -117874,7 +118003,7 @@ async function getWallet() {
|
|
|
117874
118003
|
}
|
|
117875
118004
|
const readFileResult = await safeReadFile(walletSurface, WALLET_FILE);
|
|
117876
118005
|
if (!readFileResult.isOk()) {
|
|
117877
|
-
const fileExistsResult = (0,
|
|
118006
|
+
const fileExistsResult = (0, import_fs9.existsSync)(WALLET_FILE);
|
|
117878
118007
|
if (fileExistsResult) {
|
|
117879
118008
|
return fsErr(walletSurface, {
|
|
117880
118009
|
cause: "file_not_readable",
|
|
@@ -117927,7 +118056,7 @@ async function getWallet() {
|
|
|
117927
118056
|
|
|
117928
118057
|
// src/shared/user-origins.ts
|
|
117929
118058
|
init_cjs_shims();
|
|
117930
|
-
var
|
|
118059
|
+
var fs10 = __toESM(require("fs"), 1);
|
|
117931
118060
|
var ORIGINS_FILE = configFile("origins.json");
|
|
117932
118061
|
var userOriginSchema = zod_default.object({
|
|
117933
118062
|
url: zod_default.string(),
|
|
@@ -117939,8 +118068,8 @@ var originsFileSchema = zod_default.object({
|
|
|
117939
118068
|
added: zod_default.array(userOriginSchema)
|
|
117940
118069
|
});
|
|
117941
118070
|
function readOriginsFile() {
|
|
117942
|
-
if (!
|
|
117943
|
-
const raw =
|
|
118071
|
+
if (!fs10.existsSync(ORIGINS_FILE)) return [];
|
|
118072
|
+
const raw = fs10.readFileSync(ORIGINS_FILE, "utf-8");
|
|
117944
118073
|
const json3 = safeParseJson("user-origins", raw);
|
|
117945
118074
|
if (!json3.isOk()) return [];
|
|
117946
118075
|
const parsed = originsFileSchema.safeParse(json3.value);
|
|
@@ -118007,6 +118136,7 @@ var startServer = async (flags) => {
|
|
|
118007
118136
|
registerRedeemInviteTool(props);
|
|
118008
118137
|
registerDiscoveryTools(server);
|
|
118009
118138
|
registerTelemetryTools(props);
|
|
118139
|
+
registerSettingsTools(props);
|
|
118010
118140
|
registerPrompts(props);
|
|
118011
118141
|
await registerOrigins({ server, flags });
|
|
118012
118142
|
const transport = new StdioServerTransport();
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ok,
|
|
5
5
|
resultFromPromise,
|
|
6
6
|
resultFromThrowable
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CM4BCEDY.js";
|
|
8
8
|
import {
|
|
9
9
|
isVerbose
|
|
10
10
|
} from "./chunk-ISR6DJ53.js";
|
|
@@ -227,4 +227,4 @@ export {
|
|
|
227
227
|
safeChmod,
|
|
228
228
|
log
|
|
229
229
|
};
|
|
230
|
-
//# sourceMappingURL=chunk-
|
|
230
|
+
//# sourceMappingURL=chunk-36KCO2CQ.js.map
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
REQUEST_PARAMS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4ALGXM6F.js";
|
|
4
4
|
import {
|
|
5
5
|
getTempoBalance
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FFYCYLF4.js";
|
|
7
7
|
import {
|
|
8
8
|
isMppEnabled
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-I7DEUXBL.js";
|
|
10
10
|
import {
|
|
11
11
|
getBalance
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-B2JUF6FK.js";
|
|
13
13
|
import {
|
|
14
14
|
DEFAULT_USER_FETCH_TIMEOUT,
|
|
15
15
|
fetchErr,
|
|
16
16
|
fetchOk,
|
|
17
17
|
log,
|
|
18
18
|
safeFetch
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-36KCO2CQ.js";
|
|
20
20
|
import {
|
|
21
|
+
configFile,
|
|
21
22
|
err,
|
|
22
23
|
ok,
|
|
23
24
|
resultFromPromise,
|
|
24
25
|
resultFromThrowable
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-CM4BCEDY.js";
|
|
26
27
|
|
|
27
28
|
// src/server/tools/lib/request.ts
|
|
28
29
|
import z from "zod";
|
|
@@ -162,6 +163,30 @@ function detectPaymentProtocols(response) {
|
|
|
162
163
|
return protocols;
|
|
163
164
|
}
|
|
164
165
|
|
|
166
|
+
// src/shared/settings.ts
|
|
167
|
+
import z2 from "zod";
|
|
168
|
+
import fs from "fs";
|
|
169
|
+
var SETTINGS_FILE = configFile("settings.json");
|
|
170
|
+
var settingsSchema = z2.looseObject({
|
|
171
|
+
maxAmount: z2.number().positive()
|
|
172
|
+
}).partial();
|
|
173
|
+
var getSettings = () => {
|
|
174
|
+
if (!fs.existsSync(SETTINGS_FILE)) {
|
|
175
|
+
return {};
|
|
176
|
+
}
|
|
177
|
+
const content = fs.readFileSync(SETTINGS_FILE, "utf-8");
|
|
178
|
+
const result = settingsSchema.safeParse(JSON.parse(content));
|
|
179
|
+
if (!result.success) {
|
|
180
|
+
return {};
|
|
181
|
+
}
|
|
182
|
+
return result.data;
|
|
183
|
+
};
|
|
184
|
+
var setSettings = (settings) => {
|
|
185
|
+
const existing = getSettings();
|
|
186
|
+
const newSettings = settingsSchema.parse({ ...existing, ...settings });
|
|
187
|
+
fs.writeFileSync(SETTINGS_FILE, JSON.stringify(newSettings, null, 2));
|
|
188
|
+
};
|
|
189
|
+
|
|
165
190
|
// src/shared/operations/fetch-with-payment.ts
|
|
166
191
|
import { formatUnits as formatUnits2 } from "viem";
|
|
167
192
|
|
|
@@ -172,8 +197,10 @@ var tokenStringToNumber = (amount, decimals = 6) => {
|
|
|
172
197
|
};
|
|
173
198
|
|
|
174
199
|
// src/shared/operations/fetch-with-payment.ts
|
|
200
|
+
var DEFAULT_MAX_AMOUNT = 5;
|
|
175
201
|
function createFetchWithPayment(options) {
|
|
176
|
-
const { surface, clients, paymentMethod, beforePayment, timeout } = options;
|
|
202
|
+
const { surface, clients, paymentMethod, beforePayment, timeout, maxAmount } = options;
|
|
203
|
+
const effectiveMaxAmount = maxAmount ?? getSettings().maxAmount ?? DEFAULT_MAX_AMOUNT;
|
|
177
204
|
return async (request) => {
|
|
178
205
|
const clonedRequest = request.clone();
|
|
179
206
|
const fallbackRequest = request.clone();
|
|
@@ -189,7 +216,13 @@ function createFetchWithPayment(options) {
|
|
|
189
216
|
const response = probeResult.value;
|
|
190
217
|
if (paymentMethod !== "auto") {
|
|
191
218
|
if (paymentMethod === "mpp") {
|
|
192
|
-
return handleMppPayment(
|
|
219
|
+
return handleMppPayment(
|
|
220
|
+
surface,
|
|
221
|
+
response,
|
|
222
|
+
clonedRequest,
|
|
223
|
+
options,
|
|
224
|
+
effectiveMaxAmount
|
|
225
|
+
);
|
|
193
226
|
}
|
|
194
227
|
return handleX402Payment(
|
|
195
228
|
surface,
|
|
@@ -197,7 +230,8 @@ function createFetchWithPayment(options) {
|
|
|
197
230
|
clonedRequest,
|
|
198
231
|
clients.x402,
|
|
199
232
|
beforePayment,
|
|
200
|
-
timeout
|
|
233
|
+
timeout,
|
|
234
|
+
effectiveMaxAmount
|
|
201
235
|
);
|
|
202
236
|
}
|
|
203
237
|
const available = detectPaymentProtocols(response);
|
|
@@ -208,22 +242,36 @@ function createFetchWithPayment(options) {
|
|
|
208
242
|
preferred = await pickByBalance(surface, response, options);
|
|
209
243
|
}
|
|
210
244
|
const fallback = available.length > 1 ? preferred === "mpp" ? "x402" : "mpp" : null;
|
|
211
|
-
const result = preferred === "mpp" ? await handleMppPayment(
|
|
245
|
+
const result = preferred === "mpp" ? await handleMppPayment(
|
|
246
|
+
surface,
|
|
247
|
+
response,
|
|
248
|
+
clonedRequest,
|
|
249
|
+
options,
|
|
250
|
+
effectiveMaxAmount
|
|
251
|
+
) : await handleX402Payment(
|
|
212
252
|
surface,
|
|
213
253
|
response,
|
|
214
254
|
clonedRequest,
|
|
215
255
|
clients.x402,
|
|
216
256
|
beforePayment,
|
|
217
|
-
timeout
|
|
257
|
+
timeout,
|
|
258
|
+
effectiveMaxAmount
|
|
218
259
|
);
|
|
219
260
|
if (result.isErr() && fallback) {
|
|
220
|
-
return fallback === "mpp" ? handleMppPayment(
|
|
261
|
+
return fallback === "mpp" ? handleMppPayment(
|
|
262
|
+
surface,
|
|
263
|
+
response,
|
|
264
|
+
fallbackRequest,
|
|
265
|
+
options,
|
|
266
|
+
effectiveMaxAmount
|
|
267
|
+
) : handleX402Payment(
|
|
221
268
|
surface,
|
|
222
269
|
response,
|
|
223
270
|
fallbackRequest,
|
|
224
271
|
clients.x402,
|
|
225
272
|
beforePayment,
|
|
226
|
-
timeout
|
|
273
|
+
timeout,
|
|
274
|
+
effectiveMaxAmount
|
|
227
275
|
);
|
|
228
276
|
}
|
|
229
277
|
return result;
|
|
@@ -275,7 +323,7 @@ async function pickByBalance(surface, response, options) {
|
|
|
275
323
|
log.info(`Protocol selection \u2014 x402: $${x402Balance}, mpp: $${mppBalance}`);
|
|
276
324
|
return x402Balance >= mppBalance ? "x402" : "mpp";
|
|
277
325
|
}
|
|
278
|
-
async function handleX402Payment(surface, response, clonedRequest, client, beforePayment, timeout) {
|
|
326
|
+
async function handleX402Payment(surface, response, clonedRequest, client, beforePayment, timeout, maxAmount) {
|
|
279
327
|
const paymentRequiredResult = await safeGetPaymentRequired(
|
|
280
328
|
surface,
|
|
281
329
|
client,
|
|
@@ -285,8 +333,17 @@ async function handleX402Payment(surface, response, clonedRequest, client, befor
|
|
|
285
333
|
return paymentRequiredResult;
|
|
286
334
|
}
|
|
287
335
|
const paymentRequired = paymentRequiredResult.value;
|
|
336
|
+
const accept = paymentRequired.accepts[0];
|
|
337
|
+
if (accept) {
|
|
338
|
+
const amount = tokenStringToNumber(accept.amount);
|
|
339
|
+
if (amount > maxAmount) {
|
|
340
|
+
return x402Err(surface, {
|
|
341
|
+
cause: "payment_already_attempted",
|
|
342
|
+
message: `Endpoint requested $${amount} which exceeds the maximum allowed amount of $${maxAmount}. Pass a higher maxAmount on this call, or use update_settings to raise the default permanently.`
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
288
346
|
if (beforePayment) {
|
|
289
|
-
const accept = paymentRequired.accepts[0];
|
|
290
347
|
if (accept) {
|
|
291
348
|
const amount = tokenStringToNumber(accept.amount);
|
|
292
349
|
const hookResult = await resultFromPromise(
|
|
@@ -359,7 +416,7 @@ async function handleX402Payment(surface, response, clonedRequest, client, befor
|
|
|
359
416
|
}
|
|
360
417
|
);
|
|
361
418
|
}
|
|
362
|
-
async function handleMppPayment(surface, response, clonedRequest, options) {
|
|
419
|
+
async function handleMppPayment(surface, response, clonedRequest, options, maxAmount) {
|
|
363
420
|
const { clients, beforePayment, timeout } = options;
|
|
364
421
|
const mppxClient = clients.mpp;
|
|
365
422
|
if (clonedRequest.headers.has("Authorization")) {
|
|
@@ -376,6 +433,15 @@ async function handleMppPayment(surface, response, clonedRequest, options) {
|
|
|
376
433
|
const amount = challenge.request.amount;
|
|
377
434
|
const decimals = challenge.request.decimals ?? 6;
|
|
378
435
|
const currency = challenge.request.currency;
|
|
436
|
+
if (amount) {
|
|
437
|
+
const numericAmount = Number(formatUnits2(BigInt(amount), decimals));
|
|
438
|
+
if (numericAmount > maxAmount) {
|
|
439
|
+
return mppErr(surface, {
|
|
440
|
+
cause: "mpp_payment_already_attempted",
|
|
441
|
+
message: `Endpoint requested $${numericAmount} which exceeds the maximum allowed amount of $${maxAmount}. Pass a higher maxAmount on this call, or use update_settings to raise the default permanently.`
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
379
445
|
if (beforePayment && amount && currency) {
|
|
380
446
|
const numericAmount = Number(formatUnits2(BigInt(amount), decimals));
|
|
381
447
|
const hookResult = await resultFromPromise(
|
|
@@ -514,8 +580,11 @@ export {
|
|
|
514
580
|
safeGetPaymentRequired,
|
|
515
581
|
safeGetMppChallenge,
|
|
516
582
|
detectPaymentProtocols,
|
|
583
|
+
getSettings,
|
|
584
|
+
setSettings,
|
|
585
|
+
DEFAULT_MAX_AMOUNT,
|
|
517
586
|
createFetchWithPayment,
|
|
518
587
|
getInputSchema,
|
|
519
588
|
createFetchWithAuth
|
|
520
589
|
};
|
|
521
|
-
//# sourceMappingURL=chunk-
|
|
590
|
+
//# sourceMappingURL=chunk-3WG74L5Z.js.map
|