agentcash 0.3.7 → 0.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.
- package/dist/cjs/run-server.cjs +196 -141
- package/dist/esm/{chunk-ED4QVIZH.js → chunk-32YHLL2C.js} +2 -2
- package/dist/esm/chunk-32YHLL2C.js.map +1 -0
- package/dist/esm/{chunk-7E4JDDBW.js → chunk-4LQWOM4E.js} +109 -61
- package/dist/esm/chunk-4LQWOM4E.js.map +1 -0
- package/dist/esm/{chunk-PCCYUD6X.js → chunk-DCP6SZGV.js} +3 -3
- package/dist/esm/{chunk-PJFATGPH.js → chunk-EO4BIJAO.js} +22 -9
- package/dist/esm/{chunk-PJFATGPH.js.map → chunk-EO4BIJAO.js.map} +1 -1
- package/dist/esm/{chunk-RP5AGYAT.js → chunk-P42WA7HK.js} +104 -118
- package/dist/esm/chunk-P42WA7HK.js.map +1 -0
- package/dist/esm/{chunk-SBLBP4FH.js → chunk-SA77G2FD.js} +2 -2
- package/dist/esm/{chunk-EVE4PTLY.js → chunk-TRGCJSV2.js} +2 -2
- package/dist/esm/{commands-JXKV7VMY.js → commands-LLWKNNYS.js} +7 -7
- package/dist/esm/{fund-IALSHTLH.js → fund-3DJLQ6CN.js} +4 -4
- package/dist/esm/index.js +9 -9
- package/dist/esm/{install-IP2RBDST.js → install-5W2EUVFJ.js} +5 -5
- package/dist/esm/lib.d.ts +39 -4
- package/dist/esm/lib.js +4 -4
- package/dist/esm/{server-BEKXJWYB.js → server-2U24UCUE.js} +22 -14
- package/dist/esm/server-2U24UCUE.js.map +1 -0
- package/dist/esm/shared/operations/index.d.ts +1 -1
- package/dist/esm/shared/operations/index.js +4 -4
- package/package.json +3 -3
- package/dist/esm/chunk-7E4JDDBW.js.map +0 -1
- package/dist/esm/chunk-ED4QVIZH.js.map +0 -1
- package/dist/esm/chunk-RP5AGYAT.js.map +0 -1
- package/dist/esm/server-BEKXJWYB.js.map +0 -1
- /package/dist/esm/{chunk-PCCYUD6X.js.map → chunk-DCP6SZGV.js.map} +0 -0
- /package/dist/esm/{chunk-SBLBP4FH.js.map → chunk-SA77G2FD.js.map} +0 -0
- /package/dist/esm/{chunk-EVE4PTLY.js.map → chunk-TRGCJSV2.js.map} +0 -0
- /package/dist/esm/{commands-JXKV7VMY.js.map → commands-LLWKNNYS.js.map} +0 -0
- /package/dist/esm/{fund-IALSHTLH.js.map → fund-3DJLQ6CN.js.map} +0 -0
- /package/dist/esm/{install-IP2RBDST.js.map → install-5W2EUVFJ.js.map} +0 -0
package/dist/cjs/run-server.cjs
CHANGED
|
@@ -104187,6 +104187,8 @@ var safeParse4 = (surface2, schema, value) => {
|
|
|
104187
104187
|
};
|
|
104188
104188
|
|
|
104189
104189
|
// src/shared/neverthrow/fetch/index.ts
|
|
104190
|
+
var DEFAULT_FETCH_TIMEOUT = 1e4;
|
|
104191
|
+
var DEFAULT_USER_FETCH_TIMEOUT = 3e4;
|
|
104190
104192
|
var IMAGE_TYPES = /* @__PURE__ */ new Set([
|
|
104191
104193
|
"image/png",
|
|
104192
104194
|
"image/jpeg",
|
|
@@ -104206,19 +104208,28 @@ var fetchHttpErr = (surface2, response) => fetchErr(surface2, {
|
|
|
104206
104208
|
message: response.statusText,
|
|
104207
104209
|
response
|
|
104208
104210
|
});
|
|
104209
|
-
var safeFetch = (surface2, request) => {
|
|
104211
|
+
var safeFetch = (surface2, request, timeout) => {
|
|
104212
|
+
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
|
104210
104213
|
return resultFromPromise(
|
|
104211
104214
|
errorType2,
|
|
104212
104215
|
surface2,
|
|
104213
|
-
fetch(request),
|
|
104214
|
-
(error48) =>
|
|
104215
|
-
|
|
104216
|
-
|
|
104217
|
-
|
|
104216
|
+
fetch(request, ...signal ? [{ signal }] : []),
|
|
104217
|
+
(error48) => {
|
|
104218
|
+
if (error48 instanceof DOMException && (error48.name === "TimeoutError" || error48.name === "AbortError")) {
|
|
104219
|
+
return {
|
|
104220
|
+
cause: "timeout",
|
|
104221
|
+
message: timeout ? `Request timed out after ${timeout}ms. You can increase the timeout by passing a larger value in the 'timeout' parameter.` : "Request was aborted"
|
|
104222
|
+
};
|
|
104223
|
+
}
|
|
104224
|
+
return {
|
|
104225
|
+
cause: "network",
|
|
104226
|
+
message: error48 instanceof Error ? error48.message : "Network error"
|
|
104227
|
+
};
|
|
104228
|
+
}
|
|
104218
104229
|
);
|
|
104219
104230
|
};
|
|
104220
|
-
var safeFetchJson = (surface2, request, schema) => {
|
|
104221
|
-
return safeFetch(surface2, request).andThen((response) => {
|
|
104231
|
+
var safeFetchJson = (surface2, request, schema, timeout) => {
|
|
104232
|
+
return safeFetch(surface2, request, timeout).andThen((response) => {
|
|
104222
104233
|
if (!response.ok) {
|
|
104223
104234
|
return fetchHttpErr(surface2, response);
|
|
104224
104235
|
}
|
|
@@ -109407,11 +109418,11 @@ async function getTempoBalance({
|
|
|
109407
109418
|
|
|
109408
109419
|
// src/shared/operations/fetch-with-payment.ts
|
|
109409
109420
|
function createFetchWithPayment(options) {
|
|
109410
|
-
const { surface: surface2, clients, paymentMethod, beforePayment } = options;
|
|
109421
|
+
const { surface: surface2, clients, paymentMethod, beforePayment, timeout } = options;
|
|
109411
109422
|
return async (request) => {
|
|
109412
109423
|
const clonedRequest = request.clone();
|
|
109413
109424
|
const fallbackRequest = request.clone();
|
|
109414
|
-
const probeResult = await safeFetch(surface2, request);
|
|
109425
|
+
const probeResult = await safeFetch(surface2, request, timeout);
|
|
109415
109426
|
if (probeResult.isErr()) {
|
|
109416
109427
|
return fetchErr(surface2, probeResult.error);
|
|
109417
109428
|
}
|
|
@@ -109430,7 +109441,8 @@ function createFetchWithPayment(options) {
|
|
|
109430
109441
|
response,
|
|
109431
109442
|
clonedRequest,
|
|
109432
109443
|
clients.x402,
|
|
109433
|
-
beforePayment
|
|
109444
|
+
beforePayment,
|
|
109445
|
+
timeout
|
|
109434
109446
|
);
|
|
109435
109447
|
}
|
|
109436
109448
|
const available = detectPaymentProtocols(response);
|
|
@@ -109446,7 +109458,8 @@ function createFetchWithPayment(options) {
|
|
|
109446
109458
|
response,
|
|
109447
109459
|
clonedRequest,
|
|
109448
109460
|
clients.x402,
|
|
109449
|
-
beforePayment
|
|
109461
|
+
beforePayment,
|
|
109462
|
+
timeout
|
|
109450
109463
|
);
|
|
109451
109464
|
if (result.isErr() && fallback) {
|
|
109452
109465
|
return fallback === "mpp" ? handleMppPayment(surface2, response, fallbackRequest, options) : handleX402Payment(
|
|
@@ -109454,7 +109467,8 @@ function createFetchWithPayment(options) {
|
|
|
109454
109467
|
response,
|
|
109455
109468
|
fallbackRequest,
|
|
109456
109469
|
clients.x402,
|
|
109457
|
-
beforePayment
|
|
109470
|
+
beforePayment,
|
|
109471
|
+
timeout
|
|
109458
109472
|
);
|
|
109459
109473
|
}
|
|
109460
109474
|
return result;
|
|
@@ -109506,7 +109520,7 @@ async function pickByBalance(surface2, response, options) {
|
|
|
109506
109520
|
log.info(`Protocol selection \u2014 x402: $${x402Balance}, mpp: $${mppBalance}`);
|
|
109507
109521
|
return x402Balance >= mppBalance ? "x402" : "mpp";
|
|
109508
109522
|
}
|
|
109509
|
-
async function handleX402Payment(surface2, response, clonedRequest, client, beforePayment) {
|
|
109523
|
+
async function handleX402Payment(surface2, response, clonedRequest, client, beforePayment, timeout) {
|
|
109510
109524
|
const paymentRequiredResult = await safeGetPaymentRequired(
|
|
109511
109525
|
surface2,
|
|
109512
109526
|
client,
|
|
@@ -109562,34 +109576,36 @@ async function handleX402Payment(surface2, response, clonedRequest, client, befo
|
|
|
109562
109576
|
"Access-Control-Expose-Headers",
|
|
109563
109577
|
"PAYMENT-RESPONSE,X-PAYMENT-RESPONSE"
|
|
109564
109578
|
);
|
|
109565
|
-
return await safeFetch(surface2, clonedRequest).andThen(
|
|
109566
|
-
|
|
109567
|
-
|
|
109568
|
-
|
|
109569
|
-
|
|
109570
|
-
|
|
109571
|
-
|
|
109572
|
-
|
|
109573
|
-
|
|
109574
|
-
|
|
109575
|
-
|
|
109576
|
-
|
|
109577
|
-
|
|
109578
|
-
|
|
109579
|
-
|
|
109580
|
-
|
|
109581
|
-
|
|
109582
|
-
|
|
109583
|
-
|
|
109584
|
-
|
|
109585
|
-
|
|
109586
|
-
|
|
109587
|
-
|
|
109588
|
-
|
|
109589
|
-
|
|
109579
|
+
return await safeFetch(surface2, clonedRequest, timeout).andThen(
|
|
109580
|
+
(paidResponse) => {
|
|
109581
|
+
const settlementResult = safeGetPaymentSettlement(
|
|
109582
|
+
surface2,
|
|
109583
|
+
client,
|
|
109584
|
+
paidResponse
|
|
109585
|
+
);
|
|
109586
|
+
return x402Ok({
|
|
109587
|
+
response: paidResponse,
|
|
109588
|
+
paymentInfo: {
|
|
109589
|
+
protocol: "x402",
|
|
109590
|
+
price: tokenStringToNumber(
|
|
109591
|
+
paymentPayload.accepted.amount
|
|
109592
|
+
).toLocaleString("en-US", {
|
|
109593
|
+
style: "currency",
|
|
109594
|
+
currency: "USD"
|
|
109595
|
+
}),
|
|
109596
|
+
...settlementResult.isOk() ? {
|
|
109597
|
+
payment: {
|
|
109598
|
+
success: settlementResult.value.success,
|
|
109599
|
+
transactionHash: settlementResult.value.transaction
|
|
109600
|
+
}
|
|
109601
|
+
} : {}
|
|
109602
|
+
}
|
|
109603
|
+
});
|
|
109604
|
+
}
|
|
109605
|
+
);
|
|
109590
109606
|
}
|
|
109591
109607
|
async function handleMppPayment(surface2, response, clonedRequest, options) {
|
|
109592
|
-
const { clients, beforePayment } = options;
|
|
109608
|
+
const { clients, beforePayment, timeout } = options;
|
|
109593
109609
|
const mppxClient = clients.mpp;
|
|
109594
109610
|
if (clonedRequest.headers.has("Authorization")) {
|
|
109595
109611
|
return mppErr(surface2, {
|
|
@@ -109635,26 +109651,31 @@ async function handleMppPayment(surface2, response, clonedRequest, options) {
|
|
|
109635
109651
|
}
|
|
109636
109652
|
const credential = credentialResult.value;
|
|
109637
109653
|
clonedRequest.headers.set("Authorization", credential);
|
|
109638
|
-
return await safeFetch(surface2, clonedRequest).andThen(
|
|
109639
|
-
|
|
109640
|
-
|
|
109641
|
-
|
|
109642
|
-
|
|
109643
|
-
|
|
109644
|
-
|
|
109645
|
-
|
|
109646
|
-
|
|
109647
|
-
|
|
109648
|
-
|
|
109649
|
-
|
|
109650
|
-
|
|
109651
|
-
|
|
109652
|
-
|
|
109653
|
-
|
|
109654
|
-
|
|
109655
|
-
|
|
109656
|
-
|
|
109657
|
-
|
|
109654
|
+
return await safeFetch(surface2, clonedRequest, timeout).andThen(
|
|
109655
|
+
(paidResponse) => {
|
|
109656
|
+
const receiptResult = safeGetMppReceipt(surface2, paidResponse);
|
|
109657
|
+
const priceDisplay = amount2 ? Number(formatUnits(BigInt(amount2), decimals2)).toLocaleString(
|
|
109658
|
+
"en-US",
|
|
109659
|
+
{
|
|
109660
|
+
style: "currency",
|
|
109661
|
+
currency: "USD"
|
|
109662
|
+
}
|
|
109663
|
+
) : void 0;
|
|
109664
|
+
return mppOk({
|
|
109665
|
+
response: paidResponse,
|
|
109666
|
+
paymentInfo: {
|
|
109667
|
+
protocol: "mpp",
|
|
109668
|
+
...priceDisplay ? { price: priceDisplay } : {},
|
|
109669
|
+
...receiptResult.isOk() ? {
|
|
109670
|
+
payment: {
|
|
109671
|
+
success: true,
|
|
109672
|
+
transactionHash: receiptResult.value.reference
|
|
109673
|
+
}
|
|
109674
|
+
} : {}
|
|
109675
|
+
}
|
|
109676
|
+
});
|
|
109677
|
+
}
|
|
109678
|
+
);
|
|
109658
109679
|
}
|
|
109659
109680
|
|
|
109660
109681
|
// src/server/tools/response/index.ts
|
|
@@ -109809,7 +109830,8 @@ var requestSchema = zod_default.object({
|
|
|
109809
109830
|
url: zod_default.url().describe("The endpoint URL"),
|
|
109810
109831
|
method: zod_default.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe("HTTP method. Defaults to GET for fetch operations."),
|
|
109811
109832
|
body: zod_default.unknown().optional().describe("Request body for POST/PUT/PATCH methods"),
|
|
109812
|
-
headers: zod_default.record(zod_default.string(), zod_default.string()).optional().describe("Additional headers to include").default({})
|
|
109833
|
+
headers: zod_default.record(zod_default.string(), zod_default.string()).optional().describe("Additional headers to include").default({}),
|
|
109834
|
+
timeout: zod_default.number().int().positive().optional().describe("Request timeout in milliseconds")
|
|
109813
109835
|
});
|
|
109814
109836
|
var buildRequest2 = ({
|
|
109815
109837
|
input,
|
|
@@ -109987,7 +110009,8 @@ var registerFetchTool = ({
|
|
|
109987
110009
|
paymentMethod,
|
|
109988
110010
|
account,
|
|
109989
110011
|
flags,
|
|
109990
|
-
beforePayment
|
|
110012
|
+
beforePayment,
|
|
110013
|
+
timeout: input.timeout ?? DEFAULT_USER_FETCH_TIMEOUT
|
|
109991
110014
|
})(request);
|
|
109992
110015
|
if (fetchResult.isErr()) {
|
|
109993
110016
|
return mcpError(fetchResult);
|
|
@@ -110061,7 +110084,8 @@ var registerAuthTools = ({
|
|
|
110061
110084
|
const httpClient = new x402HTTPClient(new x402Client());
|
|
110062
110085
|
const firstResult = await safeFetch(
|
|
110063
110086
|
toolName2,
|
|
110064
|
-
buildRequest2({ input, address: account.address, sessionId })
|
|
110087
|
+
buildRequest2({ input, address: account.address, sessionId }),
|
|
110088
|
+
input.timeout ?? DEFAULT_USER_FETCH_TIMEOUT
|
|
110065
110089
|
);
|
|
110066
110090
|
if (firstResult.isErr()) {
|
|
110067
110091
|
return mcpError(firstResult);
|
|
@@ -110113,7 +110137,11 @@ var registerAuthTools = ({
|
|
|
110113
110137
|
sessionId
|
|
110114
110138
|
});
|
|
110115
110139
|
authedRequest.headers.set("SIGN-IN-WITH-X", siwxHeader);
|
|
110116
|
-
const authedResult = await safeFetch(
|
|
110140
|
+
const authedResult = await safeFetch(
|
|
110141
|
+
toolName2,
|
|
110142
|
+
authedRequest,
|
|
110143
|
+
input.timeout ?? DEFAULT_USER_FETCH_TIMEOUT
|
|
110144
|
+
);
|
|
110117
110145
|
if (authedResult.isErr()) {
|
|
110118
110146
|
return mcpError(authedResult);
|
|
110119
110147
|
}
|
|
@@ -110227,15 +110255,14 @@ async function fetchOpenApiSpec(origin) {
|
|
|
110227
110255
|
if (cached2) return cached2;
|
|
110228
110256
|
const uniqueUrls = [
|
|
110229
110257
|
`${origin}/openapi.json`,
|
|
110230
|
-
`${origin}/.well-known/openapi.json
|
|
110231
|
-
`${origin}/.well-known/x402`,
|
|
110232
|
-
`${origin}/.well-known/mpp`
|
|
110258
|
+
`${origin}/.well-known/openapi.json`
|
|
110233
110259
|
];
|
|
110234
110260
|
for (const url3 of uniqueUrls) {
|
|
110235
110261
|
log.debug(`Fetching OpenAPI spec from: ${url3}`);
|
|
110236
110262
|
const fetchResult = await safeFetch(
|
|
110237
110263
|
"fetchOpenApiSpec",
|
|
110238
|
-
new Request(url3, { headers: { Accept: "application/json" } })
|
|
110264
|
+
new Request(url3, { headers: { Accept: "application/json" } }),
|
|
110265
|
+
DEFAULT_FETCH_TIMEOUT
|
|
110239
110266
|
);
|
|
110240
110267
|
if (fetchResult.isErr()) {
|
|
110241
110268
|
log.debug(`Failed to fetch OpenAPI spec from: ${url3}`);
|
|
@@ -110423,6 +110450,7 @@ function getIndexEntry(origin, path2, method) {
|
|
|
110423
110450
|
}
|
|
110424
110451
|
|
|
110425
110452
|
// src/shared/operations/check-endpoint.ts
|
|
110453
|
+
var TEMPO_DEFAULT_CHAIN_ID = 4217;
|
|
110426
110454
|
var SUPPORTED_METHODS = [
|
|
110427
110455
|
"GET",
|
|
110428
110456
|
"POST",
|
|
@@ -110473,37 +110501,12 @@ async function probeMethod({
|
|
|
110473
110501
|
headers,
|
|
110474
110502
|
includeMethodErrors
|
|
110475
110503
|
}) {
|
|
110476
|
-
const
|
|
110477
|
-
|
|
110504
|
+
const request = buildProbeRequest(url3, method, body, headers);
|
|
110505
|
+
const responseResult = await safeFetch(
|
|
110478
110506
|
surface2,
|
|
110479
|
-
|
|
110480
|
-
|
|
110481
|
-
cause: "cache_lookup",
|
|
110482
|
-
message: e instanceof Error ? e.message : String(e)
|
|
110483
|
-
})
|
|
110507
|
+
request,
|
|
110508
|
+
DEFAULT_FETCH_TIMEOUT
|
|
110484
110509
|
);
|
|
110485
|
-
if (cachedSchemaResult.isOk() && cachedSchemaResult.value) {
|
|
110486
|
-
const cachedSchema = cachedSchemaResult.value;
|
|
110487
|
-
const origin = new URL(url3).origin;
|
|
110488
|
-
const path2 = new URL(url3).pathname || "/";
|
|
110489
|
-
const indexEntry = getIndexEntry(origin, path2, method);
|
|
110490
|
-
return {
|
|
110491
|
-
method,
|
|
110492
|
-
source: "openapi",
|
|
110493
|
-
requiresPayment: true,
|
|
110494
|
-
schema: cachedSchema,
|
|
110495
|
-
...indexEntry?.price ? { estimatedPrice: indexEntry.price } : {},
|
|
110496
|
-
...indexEntry?.protocols ? { protocols: indexEntry.protocols } : {},
|
|
110497
|
-
...indexEntry?.summary ? { summary: indexEntry.summary } : {}
|
|
110498
|
-
};
|
|
110499
|
-
}
|
|
110500
|
-
if (cachedSchemaResult.isErr()) {
|
|
110501
|
-
log.debug(
|
|
110502
|
-
`Cache lookup failed for ${method} ${url3}, falling back to 402 probe`
|
|
110503
|
-
);
|
|
110504
|
-
}
|
|
110505
|
-
const request = buildProbeRequest(url3, method, body, headers);
|
|
110506
|
-
const responseResult = await safeFetch(surface2, request);
|
|
110507
110510
|
if (responseResult.isErr()) {
|
|
110508
110511
|
log.debug(`${method} ${url3} probe failed`, responseResult.error);
|
|
110509
110512
|
return null;
|
|
@@ -110513,7 +110516,6 @@ async function probeMethod({
|
|
|
110513
110516
|
if (includeMethodErrors && (response.status === 404 || response.status === 405)) {
|
|
110514
110517
|
return {
|
|
110515
110518
|
method,
|
|
110516
|
-
source: "probe",
|
|
110517
110519
|
requiresPayment: false,
|
|
110518
110520
|
statusCode: response.status
|
|
110519
110521
|
};
|
|
@@ -110524,46 +110526,50 @@ async function probeMethod({
|
|
|
110524
110526
|
if (response.status !== 402) {
|
|
110525
110527
|
return {
|
|
110526
110528
|
method,
|
|
110527
|
-
source: "probe",
|
|
110528
110529
|
requiresPayment: false,
|
|
110529
110530
|
statusCode: response.status
|
|
110530
110531
|
};
|
|
110531
110532
|
}
|
|
110532
110533
|
const protocols = detectPaymentProtocols(response);
|
|
110533
|
-
const
|
|
110534
|
+
const paymentOptions = [];
|
|
110535
|
+
let schema;
|
|
110536
|
+
const endpointSchemaResult = await resultFromPromise(
|
|
110537
|
+
"openapi",
|
|
110538
|
+
surface2,
|
|
110539
|
+
getEndpointSchema(url3, method),
|
|
110540
|
+
(e) => ({
|
|
110541
|
+
cause: "schema_fetch",
|
|
110542
|
+
message: e instanceof Error ? e.message : String(e)
|
|
110543
|
+
})
|
|
110544
|
+
);
|
|
110545
|
+
if (endpointSchemaResult.isOk() && endpointSchemaResult.value) {
|
|
110546
|
+
schema = endpointSchemaResult.value;
|
|
110547
|
+
} else if (endpointSchemaResult.isErr()) {
|
|
110548
|
+
log.debug(`Failed to fetch OpenAPI schema for: ${url3}`);
|
|
110549
|
+
}
|
|
110534
110550
|
if (protocols.includes("mpp")) {
|
|
110535
|
-
const
|
|
110536
|
-
if (challengeResult.isOk()) {
|
|
110537
|
-
const challenge2 = challengeResult.value;
|
|
110551
|
+
for (const challenge2 of parseMppChallenges(response)) {
|
|
110538
110552
|
const currency = challenge2.request.currency;
|
|
110539
110553
|
const amount2 = challenge2.request.amount;
|
|
110540
110554
|
const decimals2 = challenge2.request.decimals ?? 6;
|
|
110541
|
-
|
|
110542
|
-
const
|
|
110543
|
-
|
|
110544
|
-
|
|
110545
|
-
|
|
110546
|
-
|
|
110547
|
-
|
|
110548
|
-
|
|
110549
|
-
|
|
110550
|
-
|
|
110551
|
-
|
|
110552
|
-
|
|
110553
|
-
|
|
110554
|
-
|
|
110555
|
+
const recipient = challenge2.request.recipient;
|
|
110556
|
+
const methodDetails = challenge2.request.methodDetails;
|
|
110557
|
+
const chainId = methodDetails?.chainId ?? TEMPO_DEFAULT_CHAIN_ID;
|
|
110558
|
+
const network = `tempo:${String(chainId)}`;
|
|
110559
|
+
const description = challenge2.description ?? schema?.summary;
|
|
110560
|
+
if (amount2 && currency) {
|
|
110561
|
+
paymentOptions.push({
|
|
110562
|
+
protocol: "mpp",
|
|
110563
|
+
paymentMethod: challenge2.method,
|
|
110564
|
+
intent: challenge2.intent,
|
|
110565
|
+
realm: challenge2.realm,
|
|
110566
|
+
price: tokenStringToNumber(amount2, decimals2),
|
|
110567
|
+
network,
|
|
110568
|
+
asset: currency,
|
|
110569
|
+
...recipient ? { recipient } : {},
|
|
110570
|
+
...description ? { description } : {}
|
|
110571
|
+
});
|
|
110555
110572
|
}
|
|
110556
|
-
paymentMethods.push({
|
|
110557
|
-
protocol: "mpp",
|
|
110558
|
-
method: challenge2.method,
|
|
110559
|
-
intent: challenge2.intent,
|
|
110560
|
-
realm: challenge2.realm,
|
|
110561
|
-
...challenge2.description ? { description: challenge2.description } : {},
|
|
110562
|
-
...amount2 ? { price: tokenStringToNumber(amount2, decimals2) } : {},
|
|
110563
|
-
...currency ? { currency } : {},
|
|
110564
|
-
...schema ? { schema } : {},
|
|
110565
|
-
network: `tempo:${challenge2.method}`
|
|
110566
|
-
});
|
|
110567
110573
|
}
|
|
110568
110574
|
}
|
|
110569
110575
|
if (protocols.includes("x402")) {
|
|
@@ -110575,26 +110581,74 @@ async function probeMethod({
|
|
|
110575
110581
|
);
|
|
110576
110582
|
if (paymentRequiredResult.isOk()) {
|
|
110577
110583
|
const { resource, extensions, accepts } = paymentRequiredResult.value;
|
|
110584
|
+
if (!schema) {
|
|
110585
|
+
const inputSchema = getInputSchema(extensions);
|
|
110586
|
+
if (inputSchema) schema = inputSchema;
|
|
110587
|
+
}
|
|
110578
110588
|
for (const accept of accepts) {
|
|
110579
|
-
|
|
110589
|
+
paymentOptions.push({
|
|
110580
110590
|
protocol: "x402",
|
|
110581
|
-
...resource,
|
|
110582
|
-
schema: getInputSchema(extensions),
|
|
110583
110591
|
price: tokenStringToNumber(accept.amount),
|
|
110584
110592
|
network: accept.network,
|
|
110585
|
-
asset: accept.asset
|
|
110593
|
+
asset: accept.asset,
|
|
110594
|
+
...accept.payTo ? { recipient: accept.payTo } : {},
|
|
110595
|
+
...resource.description ? { description: resource.description } : {},
|
|
110596
|
+
...resource.mimeType ? { mimeType: resource.mimeType } : {}
|
|
110586
110597
|
});
|
|
110587
110598
|
}
|
|
110588
110599
|
}
|
|
110589
110600
|
}
|
|
110601
|
+
let estimatedPrice;
|
|
110602
|
+
let summary;
|
|
110603
|
+
const indexResult = resultFromThrowable(
|
|
110604
|
+
"openapi",
|
|
110605
|
+
surface2,
|
|
110606
|
+
() => {
|
|
110607
|
+
const origin = new URL(url3).origin;
|
|
110608
|
+
const path2 = new URL(url3).pathname || "/";
|
|
110609
|
+
return getIndexEntry(origin, path2, method);
|
|
110610
|
+
},
|
|
110611
|
+
(e) => ({
|
|
110612
|
+
cause: "index_lookup",
|
|
110613
|
+
message: e instanceof Error ? e.message : String(e)
|
|
110614
|
+
})
|
|
110615
|
+
);
|
|
110616
|
+
if (indexResult.isOk() && indexResult.value) {
|
|
110617
|
+
if (indexResult.value.price) estimatedPrice = indexResult.value.price;
|
|
110618
|
+
if (indexResult.value.summary) summary = indexResult.value.summary;
|
|
110619
|
+
}
|
|
110590
110620
|
return {
|
|
110591
110621
|
method,
|
|
110592
|
-
source: "probe",
|
|
110593
110622
|
requiresPayment: true,
|
|
110594
110623
|
statusCode: response.status,
|
|
110595
110624
|
protocols,
|
|
110596
|
-
|
|
110597
|
-
|
|
110625
|
+
paymentOptions,
|
|
110626
|
+
...schema ? { schema } : {},
|
|
110627
|
+
...estimatedPrice ? { estimatedPrice } : {},
|
|
110628
|
+
...summary ? { summary } : {}
|
|
110629
|
+
};
|
|
110630
|
+
}
|
|
110631
|
+
function parseMppChallenges(response) {
|
|
110632
|
+
const header = response.headers.get("WWW-Authenticate");
|
|
110633
|
+
if (!header) return [];
|
|
110634
|
+
const challenges = [];
|
|
110635
|
+
for (const segment of header.split(/,\s*(?=Payment\s)/i)) {
|
|
110636
|
+
const result = resultFromThrowable(
|
|
110637
|
+
"mpp",
|
|
110638
|
+
"check-endpoint",
|
|
110639
|
+
() => Challenge_exports.deserialize(segment.trim()),
|
|
110640
|
+
(e) => ({
|
|
110641
|
+
cause: "challenge_parse",
|
|
110642
|
+
message: e instanceof Error ? e.message : String(e)
|
|
110643
|
+
})
|
|
110644
|
+
);
|
|
110645
|
+
if (result.isOk()) {
|
|
110646
|
+
challenges.push(result.value);
|
|
110647
|
+
} else {
|
|
110648
|
+
log.debug("Failed to parse MPP challenge segment", result.error.message);
|
|
110649
|
+
}
|
|
110650
|
+
}
|
|
110651
|
+
return challenges;
|
|
110598
110652
|
}
|
|
110599
110653
|
function buildProbeRequest(url3, method, body, headers) {
|
|
110600
110654
|
const supportsBody = ["POST", "PUT", "PATCH"].includes(method);
|
|
@@ -110796,7 +110850,7 @@ var import_path2 = require("path");
|
|
|
110796
110850
|
var import_url = require("url");
|
|
110797
110851
|
function getVersion2() {
|
|
110798
110852
|
if (true) {
|
|
110799
|
-
return "0.
|
|
110853
|
+
return "0.4.0";
|
|
110800
110854
|
}
|
|
110801
110855
|
const __dirname3 = (0, import_path2.dirname)((0, import_url.fileURLToPath)(importMetaUrl));
|
|
110802
110856
|
const pkg = JSON.parse(
|
|
@@ -110934,7 +110988,8 @@ async function fetchLlmsTxt(surface2, origin) {
|
|
|
110934
110988
|
log.debug(`Fetching llms.txt from: ${llmsTxtUrl}`);
|
|
110935
110989
|
const result = await safeFetch(
|
|
110936
110990
|
surface2,
|
|
110937
|
-
new Request(llmsTxtUrl, { headers: { Accept: "text/plain" } })
|
|
110991
|
+
new Request(llmsTxtUrl, { headers: { Accept: "text/plain" } }),
|
|
110992
|
+
DEFAULT_FETCH_TIMEOUT
|
|
110938
110993
|
);
|
|
110939
110994
|
if (result.isErr()) return null;
|
|
110940
110995
|
if (!result.value.ok) return null;
|
|
@@ -110951,7 +111006,7 @@ async function discoverResources(surface2, url3) {
|
|
|
110951
111006
|
]);
|
|
110952
111007
|
if (!spec?.paths) {
|
|
110953
111008
|
log.debug(
|
|
110954
|
-
`No OpenAPI spec found for ${origin}. Tried: /openapi.json, /.well-known/openapi.json
|
|
111009
|
+
`No OpenAPI spec found for ${origin}. Tried: /openapi.json, /.well-known/openapi.json`
|
|
110955
111010
|
);
|
|
110956
111011
|
return null;
|
|
110957
111012
|
}
|
|
@@ -111047,7 +111102,7 @@ function registerDiscoveryTools(server) {
|
|
|
111047
111102
|
return mcpSuccessJson({
|
|
111048
111103
|
found: false,
|
|
111049
111104
|
origin,
|
|
111050
|
-
error: "No OpenAPI spec found. Tried: /openapi.json, /.well-known/openapi.json
|
|
111105
|
+
error: "No OpenAPI spec found. Tried: /openapi.json, /.well-known/openapi.json"
|
|
111051
111106
|
});
|
|
111052
111107
|
}
|
|
111053
111108
|
);
|
|
@@ -111256,7 +111311,7 @@ var registerOrigins = ({ server }) => {
|
|
|
111256
111311
|
}
|
|
111257
111312
|
};
|
|
111258
111313
|
var getResourceResponse = async (resource, request) => {
|
|
111259
|
-
const fetchResult = await safeFetch(surface, request);
|
|
111314
|
+
const fetchResult = await safeFetch(surface, request, DEFAULT_FETCH_TIMEOUT);
|
|
111260
111315
|
if (fetchResult.isErr()) {
|
|
111261
111316
|
return err2("fetch", surface, {
|
|
111262
111317
|
cause: "network",
|
|
@@ -111532,7 +111587,7 @@ var import_path3 = require("path");
|
|
|
111532
111587
|
var import_url2 = require("url");
|
|
111533
111588
|
function getVersion3() {
|
|
111534
111589
|
if (true) {
|
|
111535
|
-
return "0.
|
|
111590
|
+
return "0.4.0";
|
|
111536
111591
|
}
|
|
111537
111592
|
const __dirname3 = (0, import_path3.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
|
|
111538
111593
|
const pkg = JSON.parse(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getWalletInfo,
|
|
3
3
|
submitErrorReport
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-P42WA7HK.js";
|
|
5
5
|
|
|
6
6
|
// src/shared/operations/index.ts
|
|
7
7
|
async function getWalletInfo2(surface, address, flags) {
|
|
@@ -19,4 +19,4 @@ export {
|
|
|
19
19
|
getWalletInfo2 as getWalletInfo,
|
|
20
20
|
submitErrorReport2 as submitErrorReport
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
22
|
+
//# sourceMappingURL=chunk-32YHLL2C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/operations/index.ts"],"sourcesContent":["/**\n * Published entry point: `agentcash/operations`\n *\n * All exports return plain types (no Result<> from neverthrow) to avoid\n * leaking @agentcash/neverthrow/types into published .d.ts files.\n */\n\nimport type { Address } from 'viem';\nimport type { GlobalFlags } from '@/types';\n\n// ── Discover ──\n// Already returns plain type (DiscoveryResult | null)\nexport { discoverResources, type DiscoveryResult } from './discover';\n\n// ── Check Endpoint ──\nexport {\n checkEndpoint,\n type CheckEndpointOptions,\n type CheckEndpointResult,\n type ProbeMethodResult,\n type PaymentOption,\n type MppPaymentOption,\n type X402PaymentOption,\n type SupportedMethod,\n SUPPORTED_METHODS,\n} from './check-endpoint';\n\n// ── Wallet Info ──\nimport { getWalletInfo as _getWalletInfo } from './wallet-info';\nexport type { WalletInfoResult } from './wallet-info';\n\nexport async function getWalletInfo(\n surface: string,\n address: Address,\n flags: GlobalFlags\n) {\n const result = await _getWalletInfo(surface, address, flags);\n if (result.isErr()) throw new Error(result.error.message);\n return result.value;\n}\n\n// ── Report Error ──\nimport { submitErrorReport as _submitErrorReport } from './report-error';\nexport type { ErrorReportResult } from './report-error';\n\nexport async function submitErrorReport(\n surface: string,\n input: {\n tool: string;\n summary: string;\n errorMessage: string;\n resource?: string;\n stack?: string;\n fullReport?: string;\n },\n address: Address,\n dev: boolean\n) {\n const result = await _submitErrorReport(surface, input, address, dev);\n if (result.isErr()) throw new Error(result.error.message);\n return result.value;\n}\n"],"mappings":";;;;;;AA+BA,eAAsBA,eACpB,SACA,SACA,OACA;AACA,QAAM,SAAS,MAAM,cAAe,SAAS,SAAS,KAAK;AAC3D,MAAI,OAAO,MAAM,EAAG,OAAM,IAAI,MAAM,OAAO,MAAM,OAAO;AACxD,SAAO,OAAO;AAChB;AAMA,eAAsBC,mBACpB,SACA,OAQA,SACA,KACA;AACA,QAAM,SAAS,MAAM,kBAAmB,SAAS,OAAO,SAAS,GAAG;AACpE,MAAI,OAAO,MAAM,EAAG,OAAM,IAAI,MAAM,OAAO,MAAM,OAAO;AACxD,SAAO,OAAO;AAChB;","names":["getWalletInfo","submitErrorReport"]}
|