agentcash 0.6.2 → 0.6.4
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 +118 -73
- package/dist/esm/{check-endpoint-BGFpMl2m.d.ts → check-endpoint-Df0YnKdr.d.ts} +8 -3
- package/dist/esm/{chunk-BAQ3QDQY.js → chunk-3STID4ZW.js} +4 -4
- package/dist/esm/chunk-3STID4ZW.js.map +1 -0
- package/dist/esm/chunk-L3LTEB5B.js +7 -0
- package/dist/esm/{chunk-CPB4JGR7.js → chunk-NFGTXPUD.js} +54 -40
- package/dist/esm/chunk-NFGTXPUD.js.map +1 -0
- package/dist/esm/{chunk-KZOOVRXW.js → chunk-RN73GKUU.js} +3 -3
- package/dist/esm/{chunk-UC3J43CE.js → chunk-YXENPVZ4.js} +2 -2
- package/dist/esm/{commands-CJHVEMHK.js → commands-D3PD4CNW.js} +15 -10
- package/dist/esm/{commands-CJHVEMHK.js.map → commands-D3PD4CNW.js.map} +1 -1
- package/dist/esm/index.js +20 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{install-7FG62LQT.js → install-KD7XNKVI.js} +2 -2
- package/dist/esm/lib.d.ts +1 -1
- package/dist/esm/lib.js +2 -2
- package/dist/esm/lib.js.map +1 -1
- package/dist/esm/{server-AO2FSPPT.js → server-NX7XT2F6.js} +70 -38
- package/dist/esm/server-NX7XT2F6.js.map +1 -0
- package/dist/esm/shared/operations/index.d.ts +1 -1
- package/dist/esm/shared/operations/index.js +4 -4
- package/dist/esm/shared/operations/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/esm/chunk-BAQ3QDQY.js.map +0 -1
- package/dist/esm/chunk-CPB4JGR7.js.map +0 -1
- package/dist/esm/chunk-EGM7SQKO.js +0 -7
- package/dist/esm/server-AO2FSPPT.js.map +0 -1
- /package/dist/esm/{chunk-EGM7SQKO.js.map → chunk-L3LTEB5B.js.map} +0 -0
- /package/dist/esm/{chunk-KZOOVRXW.js.map → chunk-RN73GKUU.js.map} +0 -0
- /package/dist/esm/{chunk-UC3J43CE.js.map → chunk-YXENPVZ4.js.map} +0 -0
- /package/dist/esm/{install-7FG62LQT.js.map → install-KD7XNKVI.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isMppEnabled
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-L3LTEB5B.js";
|
|
4
4
|
import {
|
|
5
5
|
DEFAULT_FETCH_TIMEOUT,
|
|
6
6
|
err,
|
|
@@ -90,14 +90,16 @@ function detectPaymentProtocols(response) {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// src/shared/openapi-cache.ts
|
|
93
|
-
var
|
|
93
|
+
var OPENAPI_SPEC_PATHS = [
|
|
94
|
+
"/openapi.json",
|
|
95
|
+
"/.well-known/openapi.json"
|
|
96
|
+
];
|
|
94
97
|
async function fetchOpenApiSpec(origin) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
];
|
|
98
|
+
const uniqueUrls = OPENAPI_SPEC_PATHS.map((p) => `${origin}${p}`);
|
|
99
|
+
let failure = {
|
|
100
|
+
ok: false,
|
|
101
|
+
cause: "not_found"
|
|
102
|
+
};
|
|
101
103
|
for (const url of uniqueUrls) {
|
|
102
104
|
log.debug(`Fetching OpenAPI spec from: ${url}`);
|
|
103
105
|
const fetchResult = await safeFetch(
|
|
@@ -106,6 +108,10 @@ async function fetchOpenApiSpec(origin) {
|
|
|
106
108
|
DEFAULT_FETCH_TIMEOUT
|
|
107
109
|
);
|
|
108
110
|
if (fetchResult.isErr()) {
|
|
111
|
+
const { cause, message } = fetchResult.error;
|
|
112
|
+
if (cause === "network" || cause === "timeout") {
|
|
113
|
+
failure = { ok: false, cause, message };
|
|
114
|
+
}
|
|
109
115
|
log.debug(`Failed to fetch OpenAPI spec from: ${url}`);
|
|
110
116
|
continue;
|
|
111
117
|
}
|
|
@@ -121,18 +127,24 @@ async function fetchOpenApiSpec(origin) {
|
|
|
121
127
|
})
|
|
122
128
|
);
|
|
123
129
|
if (jsonResult.isErr()) {
|
|
124
|
-
|
|
130
|
+
if (failure.cause === "not_found") {
|
|
131
|
+
failure = {
|
|
132
|
+
ok: false,
|
|
133
|
+
cause: "parse",
|
|
134
|
+
message: `Failed to parse JSON from: ${url}`
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
log.debug(`Failed to parse OpenAPI spec from: ${url}`);
|
|
125
138
|
continue;
|
|
126
139
|
}
|
|
127
140
|
const spec = jsonResult.value;
|
|
128
141
|
if (spec && typeof spec === "object" && spec.paths) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return spec;
|
|
142
|
+
log.info(`Fetched OpenAPI spec for origin: ${origin}`);
|
|
143
|
+
return { ok: true, spec };
|
|
132
144
|
}
|
|
133
145
|
}
|
|
134
146
|
log.debug(`No OpenAPI spec found for origin: ${origin}`);
|
|
135
|
-
return
|
|
147
|
+
return failure;
|
|
136
148
|
}
|
|
137
149
|
function resolveRef(spec, ref, seen) {
|
|
138
150
|
if (!ref.startsWith("#/")) return void 0;
|
|
@@ -187,8 +199,9 @@ function extractPath(url, origin) {
|
|
|
187
199
|
async function getEndpointSchema(endpointUrl, method) {
|
|
188
200
|
if (!URL.canParse(endpointUrl)) return null;
|
|
189
201
|
const origin = new URL(endpointUrl).origin;
|
|
190
|
-
const
|
|
191
|
-
if (!
|
|
202
|
+
const result = await fetchOpenApiSpec(origin);
|
|
203
|
+
if (!result.ok) return null;
|
|
204
|
+
const spec = result.spec;
|
|
192
205
|
const paths = spec.paths;
|
|
193
206
|
if (!paths) return null;
|
|
194
207
|
const path = extractPath(endpointUrl, origin);
|
|
@@ -219,12 +232,10 @@ async function getEndpointSchema(endpointUrl, method) {
|
|
|
219
232
|
const resolved = resolveRefs(spec, operation, /* @__PURE__ */ new Set());
|
|
220
233
|
return { path, method: httpMethod, ...resolved };
|
|
221
234
|
}
|
|
222
|
-
var indexCache = /* @__PURE__ */ new Map();
|
|
223
235
|
async function getOriginIndex(origin) {
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
const spec =
|
|
227
|
-
if (!spec?.paths) return null;
|
|
236
|
+
const result = await fetchOpenApiSpec(origin);
|
|
237
|
+
if (!result.ok) return null;
|
|
238
|
+
const spec = result.spec;
|
|
228
239
|
const endpoints = [];
|
|
229
240
|
for (const [path, methods] of Object.entries(
|
|
230
241
|
spec.paths
|
|
@@ -248,7 +259,6 @@ async function getOriginIndex(origin) {
|
|
|
248
259
|
}
|
|
249
260
|
}
|
|
250
261
|
}
|
|
251
|
-
indexCache.set(origin, endpoints);
|
|
252
262
|
return endpoints;
|
|
253
263
|
}
|
|
254
264
|
var OPENAPI_HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -264,9 +274,9 @@ var OPENAPI_HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
|
264
274
|
async function getSpecMethods(endpointUrl) {
|
|
265
275
|
if (!URL.canParse(endpointUrl)) return null;
|
|
266
276
|
const origin = new URL(endpointUrl).origin;
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
const paths = spec.paths;
|
|
277
|
+
const result = await fetchOpenApiSpec(origin);
|
|
278
|
+
if (!result.ok) return null;
|
|
279
|
+
const paths = result.spec.paths;
|
|
270
280
|
const path = extractPath(endpointUrl, origin);
|
|
271
281
|
let pathEntry = paths[path];
|
|
272
282
|
if (!pathEntry) {
|
|
@@ -283,8 +293,8 @@ async function getSpecMethods(endpointUrl) {
|
|
|
283
293
|
if (!pathEntry) return null;
|
|
284
294
|
return Object.keys(pathEntry).filter((k) => OPENAPI_HTTP_METHODS.has(k)).map((k) => k.toUpperCase());
|
|
285
295
|
}
|
|
286
|
-
function getIndexEntry(origin, path, method) {
|
|
287
|
-
const entries =
|
|
296
|
+
async function getIndexEntry(origin, path, method) {
|
|
297
|
+
const entries = await getOriginIndex(origin);
|
|
288
298
|
if (!entries) return void 0;
|
|
289
299
|
const m = method.toUpperCase();
|
|
290
300
|
return entries.find((e) => e.path === path && e.method === m);
|
|
@@ -394,14 +404,14 @@ async function probeMethod({
|
|
|
394
404
|
if (!schema2) return null;
|
|
395
405
|
let estimatedPrice2;
|
|
396
406
|
let summary2;
|
|
397
|
-
const indexResult2 =
|
|
407
|
+
const indexResult2 = await resultFromPromise(
|
|
398
408
|
"openapi",
|
|
399
409
|
surface,
|
|
400
|
-
() => {
|
|
410
|
+
(async () => {
|
|
401
411
|
const origin = new URL(url).origin;
|
|
402
412
|
const path = new URL(url).pathname || "/";
|
|
403
413
|
return getIndexEntry(origin, path, method);
|
|
404
|
-
},
|
|
414
|
+
})(),
|
|
405
415
|
(e) => ({
|
|
406
416
|
cause: "index_lookup",
|
|
407
417
|
message: e instanceof Error ? e.message : String(e)
|
|
@@ -512,14 +522,14 @@ async function probeMethod({
|
|
|
512
522
|
}
|
|
513
523
|
let estimatedPrice;
|
|
514
524
|
let summary;
|
|
515
|
-
const indexResult =
|
|
525
|
+
const indexResult = await resultFromPromise(
|
|
516
526
|
"openapi",
|
|
517
527
|
surface,
|
|
518
|
-
() => {
|
|
528
|
+
(async () => {
|
|
519
529
|
const origin = new URL(url).origin;
|
|
520
530
|
const path = new URL(url).pathname || "/";
|
|
521
531
|
return getIndexEntry(origin, path, method);
|
|
522
|
-
},
|
|
532
|
+
})(),
|
|
523
533
|
(e) => ({
|
|
524
534
|
cause: "index_lookup",
|
|
525
535
|
message: e instanceof Error ? e.message : String(e)
|
|
@@ -593,20 +603,23 @@ async function fetchLlmsTxt(surface, origin) {
|
|
|
593
603
|
async function discoverResources(surface, url) {
|
|
594
604
|
const origin = URL.canParse(url) ? new URL(url).origin : url;
|
|
595
605
|
log.info(`Discovering resources for origin: ${origin}`);
|
|
596
|
-
const [
|
|
606
|
+
const [specResult, instructions] = await Promise.all([
|
|
597
607
|
fetchOpenApiSpec(origin),
|
|
598
608
|
fetchLlmsTxt(surface, origin)
|
|
599
609
|
]);
|
|
600
|
-
if (!
|
|
601
|
-
log.debug(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
610
|
+
if (!specResult.ok) {
|
|
611
|
+
log.debug(`No OpenAPI spec found for ${origin}: ${specResult.cause}`);
|
|
612
|
+
return {
|
|
613
|
+
found: false,
|
|
614
|
+
cause: specResult.cause,
|
|
615
|
+
..."message" in specResult ? { message: specResult.message } : {}
|
|
616
|
+
};
|
|
605
617
|
}
|
|
618
|
+
const spec = specResult.spec;
|
|
606
619
|
const endpoints = await getOriginIndex(origin);
|
|
607
620
|
if (!endpoints || endpoints.length === 0) {
|
|
608
621
|
log.debug(`OpenAPI spec found for ${origin} but no endpoints extracted`);
|
|
609
|
-
return
|
|
622
|
+
return { found: false, cause: "not_found" };
|
|
610
623
|
}
|
|
611
624
|
log.info(`Found ${endpoints.length} endpoints for: ${origin}`);
|
|
612
625
|
const rawInfo = spec.info;
|
|
@@ -641,8 +654,9 @@ export {
|
|
|
641
654
|
tokenStringToNumber,
|
|
642
655
|
getInputSchema,
|
|
643
656
|
getSiwxExtension,
|
|
657
|
+
OPENAPI_SPEC_PATHS,
|
|
644
658
|
SUPPORTED_METHODS,
|
|
645
659
|
checkEndpoint,
|
|
646
660
|
discoverResources
|
|
647
661
|
};
|
|
648
|
-
//# sourceMappingURL=chunk-
|
|
662
|
+
//# sourceMappingURL=chunk-NFGTXPUD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/operations/check-endpoint.ts","../../src/shared/neverthrow/x402/index.ts","../../src/shared/protocol.ts","../../src/shared/openapi-cache.ts","../../src/shared/token.ts","../../src/server/lib/x402-extensions.ts","../../src/shared/operations/discover.ts"],"sourcesContent":["import { resultFromPromise, resultFromThrowable } from '@agentcash/neverthrow';\nimport { Challenge } from 'mppx';\nimport { x402Client, x402HTTPClient } from '@x402/core/client';\n\nimport { log } from '@/shared/log';\nimport { DEFAULT_FETCH_TIMEOUT, safeFetch } from '@/shared/neverthrow/fetch';\nimport { safeGetPaymentRequired } from '@/shared/neverthrow/x402';\nimport { detectPaymentProtocols } from '@/shared/protocol';\nimport { isMppEnabled } from '@/shared/mpp-enabled';\nimport {\n getEndpointSchema,\n getIndexEntry,\n getSpecMethods,\n} from '@/shared/openapi-cache';\nimport { tokenStringToNumber } from '@/shared/token';\nimport { getInputSchema } from '@/server/lib/x402-extensions';\n\nimport type { JsonObject } from '@/shared/neverthrow/json/types';\nimport type { PaymentProtocol } from '@/shared/protocol';\n\n// ─── Public types ────────────────────────────────────────────────\n\n/** Tempo mainnet chain ID, used when the MPP challenge omits methodDetails.chainId. */\nconst TEMPO_DEFAULT_CHAIN_ID = 4217;\n\nexport const SUPPORTED_METHODS = [\n 'GET',\n 'POST',\n 'PUT',\n 'DELETE',\n 'PATCH',\n] as const;\n\nexport type SupportedMethod = (typeof SUPPORTED_METHODS)[number];\n\n// ─── Payment option types (protocol-agnostic) ───────────────────\n\n/** Fields common to every payment option regardless of protocol. */\ninterface PaymentOptionBase {\n /** Protocol that issued this payment option. */\n protocol: PaymentProtocol;\n /** Human-readable price in dollars (e.g., 0.02). */\n price: number;\n /** CAIP-2 style chain identifier (e.g., \"eip155:8453\", \"tempo:4217\"). */\n network: string;\n /** Token / asset contract address. */\n asset: string;\n /** Payment destination address. */\n recipient?: string;\n /** Human-readable description of the resource being paid for. */\n description?: string;\n}\n\n/** MPP (Machine Payments Protocol) payment option. */\nexport interface MppPaymentOption extends PaymentOptionBase {\n protocol: 'mpp';\n /** Payment method identifier (e.g., \"tempo\", \"stripe\"). */\n paymentMethod: string;\n /** Payment intent type (e.g., \"charge\", \"session\"). */\n intent: string;\n /** Server protection realm. */\n realm: string;\n}\n\n/** x402 payment option. */\nexport interface X402PaymentOption extends PaymentOptionBase {\n protocol: 'x402';\n /** Response MIME type from the x402 resource descriptor. */\n mimeType?: string;\n}\n\n/** A single payment option extracted from a 402 response. */\nexport type PaymentOption = MppPaymentOption | X402PaymentOption;\n\n/** A single method's probe outcome (only 402 or 2xx responses are kept). */\nexport interface ProbeMethodResult {\n method: SupportedMethod;\n requiresPayment: boolean;\n statusCode: number;\n protocols?: PaymentProtocol[];\n paymentOptions?: PaymentOption[];\n /** OpenAPI operation schema when available. */\n schema?: JsonObject;\n /** Advisory price string from the OpenAPI x-payment-info extension. */\n estimatedPrice?: string;\n /** Human-readable summary from the OpenAPI spec. */\n summary?: string;\n}\n\nexport interface CheckEndpointResult {\n url: string;\n results: ProbeMethodResult[];\n}\n\nexport interface CheckEndpointOptions {\n surface: string;\n url: string;\n /** Methods to probe. Defaults to spec-defined methods, or all if no spec / probeAllMethods is set. */\n methods?: SupportedMethod[];\n body?: unknown;\n headers?: Record<string, string>;\n /** When true, include 404/405 responses in results. Useful when a specific method is targeted. */\n includeMethodErrors?: boolean;\n /** When true, probe all HTTP methods regardless of what the OpenAPI spec declares. */\n probeAllMethods?: boolean;\n}\n\n// ─── Public entry point ──────────────────────────────────────────\n\n/**\n * Probe an endpoint across one or more HTTP methods in parallel.\n * Returns only the methods that responded with 402 or 2xx.\n * Does not make any payment.\n */\nexport async function checkEndpoint({\n surface,\n url,\n methods,\n body,\n headers = {},\n includeMethodErrors = false,\n probeAllMethods = false,\n}: CheckEndpointOptions): Promise<CheckEndpointResult> {\n let methodsToCheck: SupportedMethod[];\n if (methods) {\n methodsToCheck = methods;\n } else if (probeAllMethods) {\n methodsToCheck = [...SUPPORTED_METHODS];\n } else {\n const specMethods = await getSpecMethods(url);\n if (specMethods?.length) {\n methodsToCheck = specMethods.filter((m): m is SupportedMethod =>\n SUPPORTED_METHODS.includes(m as SupportedMethod)\n );\n } else {\n methodsToCheck = [...SUPPORTED_METHODS];\n }\n }\n\n log.info('Checking endpoint', { url, methods: methodsToCheck });\n\n const results = await Promise.all(\n methodsToCheck.map(method =>\n probeMethod({ surface, method, url, body, headers, includeMethodErrors })\n )\n );\n\n return {\n url,\n results: results.filter((r): r is ProbeMethodResult => r !== null),\n };\n}\n\n// ─── Per-method probe (private) ──────────────────────────────────\n\ninterface ProbeMethodOptions {\n surface: string;\n method: SupportedMethod;\n url: string;\n body?: unknown;\n headers: Record<string, string>;\n includeMethodErrors: boolean;\n}\n\nasync function probeMethod({\n surface,\n method,\n url,\n body,\n headers,\n includeMethodErrors,\n}: ProbeMethodOptions): Promise<ProbeMethodResult | null> {\n // ── Kick off the OpenAPI schema fetch in parallel with the probe ──\n const schemaPromise = resultFromPromise(\n 'openapi',\n surface,\n getEndpointSchema(url, method),\n e => ({\n cause: 'schema_fetch' as const,\n message: e instanceof Error ? e.message : String(e),\n })\n );\n\n // ── Probe the endpoint to get a live 402 challenge ──\n const request = buildProbeRequest(url, method, body, headers);\n const responseResult = await safeFetch(\n surface,\n request,\n DEFAULT_FETCH_TIMEOUT\n );\n\n // Helper: build a result from the OpenAPI spec alone (no probe data).\n const fallbackToSpec = async (): Promise<ProbeMethodResult | null> => {\n const schemaResult = await schemaPromise;\n const schema =\n schemaResult.isOk() && schemaResult.value\n ? schemaResult.value\n : undefined;\n\n if (!schema) return null;\n\n let estimatedPrice: string | undefined;\n let summary: string | undefined;\n\n const indexResult = await resultFromPromise(\n 'openapi',\n surface,\n (async () => {\n const origin = new URL(url).origin;\n const path = new URL(url).pathname || '/';\n return getIndexEntry(origin, path, method);\n })(),\n e => ({\n cause: 'index_lookup' as const,\n message: e instanceof Error ? e.message : String(e),\n })\n );\n let protocols: PaymentProtocol[] | undefined;\n\n if (indexResult.isOk() && indexResult.value) {\n if (indexResult.value.price) estimatedPrice = indexResult.value.price;\n if (indexResult.value.summary) summary = indexResult.value.summary;\n if (indexResult.value.protocols?.length) {\n protocols = indexResult.value.protocols as PaymentProtocol[];\n }\n }\n\n return {\n method,\n requiresPayment: true,\n statusCode: 402,\n schema,\n ...(protocols ? { protocols } : {}),\n ...(estimatedPrice ? { estimatedPrice } : {}),\n ...(summary ? { summary } : {}),\n };\n };\n\n if (responseResult.isErr()) {\n log.debug(`${method} ${url} probe failed`, responseResult.error);\n return fallbackToSpec();\n }\n\n const response = responseResult.value;\n\n // Non-402 error — fall back to OpenAPI spec if available\n if (!response.ok && response.status !== 402) {\n if (\n includeMethodErrors &&\n (response.status === 404 || response.status === 405)\n ) {\n return {\n method,\n requiresPayment: false,\n statusCode: response.status,\n };\n }\n log.debug(\n `${method} ${url} returned ${response.status} — falling back to spec`\n );\n return fallbackToSpec();\n }\n\n // 2xx success — include (no payment required)\n if (response.status !== 402) {\n return {\n method,\n requiresPayment: false,\n statusCode: response.status,\n };\n }\n\n // 402 — extract payment details\n const protocols = detectPaymentProtocols(response);\n const paymentOptions: PaymentOption[] = [];\n\n // Await the OpenAPI schema we kicked off earlier\n let schema: JsonObject | undefined;\n const endpointSchemaResult = await schemaPromise;\n if (endpointSchemaResult.isOk() && endpointSchemaResult.value) {\n schema = endpointSchemaResult.value;\n } else if (endpointSchemaResult.isErr()) {\n log.debug(`Failed to fetch OpenAPI schema for: ${url}`);\n }\n\n if (isMppEnabled() && protocols.includes('mpp')) {\n for (const challenge of parseMppChallenges(response)) {\n const currency = challenge.request.currency as string | undefined;\n const amount = challenge.request.amount as string | undefined;\n const decimals = (challenge.request.decimals as number | undefined) ?? 6;\n const recipient = challenge.request.recipient as string | undefined;\n const methodDetails = challenge.request.methodDetails as\n | { chainId?: number }\n | undefined;\n\n const chainId = methodDetails?.chainId ?? TEMPO_DEFAULT_CHAIN_ID;\n const network = `tempo:${String(chainId)}`;\n\n const description =\n challenge.description ??\n ((schema as Record<string, unknown> | undefined)?.summary as\n | string\n | undefined);\n\n if (amount && currency) {\n paymentOptions.push({\n protocol: 'mpp',\n paymentMethod: challenge.method,\n intent: challenge.intent,\n realm: challenge.realm,\n price: tokenStringToNumber(amount, decimals),\n network,\n asset: currency,\n ...(recipient ? { recipient } : {}),\n ...(description ? { description } : {}),\n });\n }\n }\n }\n\n if (protocols.includes('x402')) {\n const client = new x402HTTPClient(new x402Client());\n\n const paymentRequiredResult = await safeGetPaymentRequired(\n surface,\n client,\n response\n );\n\n if (paymentRequiredResult.isOk()) {\n const { resource, extensions, accepts } = paymentRequiredResult.value;\n\n // Fall back to probe schema only if OpenAPI didn't provide one\n if (!schema) {\n const inputSchema = getInputSchema(extensions);\n if (inputSchema) schema = inputSchema as JsonObject;\n }\n\n for (const accept of accepts) {\n paymentOptions.push({\n protocol: 'x402',\n price: tokenStringToNumber(accept.amount),\n network: accept.network,\n asset: accept.asset,\n ...(accept.payTo ? { recipient: accept.payTo } : {}),\n ...(resource.description\n ? { description: resource.description }\n : {}),\n ...(resource.mimeType ? { mimeType: resource.mimeType } : {}),\n });\n }\n }\n }\n\n // Extract summary and estimatedPrice from OpenAPI index (best-effort)\n let estimatedPrice: string | undefined;\n let summary: string | undefined;\n\n const indexResult = await resultFromPromise(\n 'openapi',\n surface,\n (async () => {\n const origin = new URL(url).origin;\n const path = new URL(url).pathname || '/';\n return getIndexEntry(origin, path, method);\n })(),\n e => ({\n cause: 'index_lookup' as const,\n message: e instanceof Error ? e.message : String(e),\n })\n );\n if (indexResult.isOk() && indexResult.value) {\n if (indexResult.value.price) estimatedPrice = indexResult.value.price;\n if (indexResult.value.summary) summary = indexResult.value.summary;\n }\n\n return {\n method,\n requiresPayment: true,\n statusCode: response.status,\n protocols,\n paymentOptions,\n ...(schema ? { schema } : {}),\n ...(estimatedPrice ? { estimatedPrice } : {}),\n ...(summary ? { summary } : {}),\n };\n}\n\n// ─── MPP multi-challenge parser (private) ────────────────────────\n\n/**\n * Parse all MPP challenges from a 402 response.\n *\n * A server may include multiple `WWW-Authenticate: Payment ...` headers\n * to offer different payment methods (e.g., Tempo and Stripe).\n * `Headers.get()` joins them with `, ` so we split on the `Payment `\n * boundary and parse each challenge individually.\n */\nfunction parseMppChallenges(response: Response): Challenge.Challenge[] {\n const header = response.headers.get('WWW-Authenticate');\n if (!header) return [];\n\n const challenges: Challenge.Challenge[] = [];\n\n for (const segment of header.split(/,\\s*(?=Payment\\s)/i)) {\n const result = resultFromThrowable(\n 'mpp',\n 'check-endpoint',\n () => Challenge.deserialize(segment.trim()),\n e => ({\n cause: 'challenge_parse' as const,\n message: e instanceof Error ? e.message : String(e),\n })\n );\n if (result.isOk()) {\n challenges.push(result.value);\n } else {\n log.debug('Failed to parse MPP challenge segment', result.error.message);\n }\n }\n\n return challenges;\n}\n\n// ─── Request builder (private) ───────────────────────────────────\n\nfunction buildProbeRequest(\n url: string,\n method: string,\n body: unknown,\n headers: Record<string, string>\n): Request {\n const supportsBody = ['POST', 'PUT', 'PATCH'].includes(method);\n const requestBody =\n supportsBody && body\n ? typeof body === 'string'\n ? body\n : JSON.stringify(body)\n : undefined;\n\n return new Request(url, {\n method,\n body: requestBody,\n headers: {\n ...(requestBody ? { 'Content-Type': 'application/json' } : {}),\n ...headers,\n },\n });\n}\n","import {\n err,\n ok,\n resultFromPromise,\n resultFromThrowable,\n} from '@agentcash/neverthrow';\nimport { createSIWxPayload } from '@x402/extensions/sign-in-with-x';\n\nimport type { BaseX402Error } from './types';\nimport type { x402HTTPClient } from '@x402/core/http';\nimport type { PaymentRequired } from '@x402/core/types';\nimport type { CompleteSIWxInfo } from '@x402/extensions/sign-in-with-x';\nimport type { PrivateKeyAccount } from 'viem';\n\nconst errorType = 'x402';\n\nexport const x402Ok = <T>(value: T) => ok(value);\nexport const x402Err = (cause: string, error: BaseX402Error) =>\n err(errorType, cause, error);\n\nconst x402ResultFromPromise = <T>(\n surface: string,\n promise: Promise<T>,\n error: (e: unknown) => BaseX402Error\n) => resultFromPromise(errorType, surface, promise, error);\n\nconst x402ResultFromThrowable = <T>(\n surface: string,\n fn: () => T,\n error: (e: unknown) => BaseX402Error\n) => resultFromThrowable(errorType, surface, fn, error);\n\nexport const safeGetPaymentRequired = (\n surface: string,\n client: x402HTTPClient,\n response: Response\n) => {\n return x402ResultFromPromise(\n surface,\n response.json().then(\n json =>\n client.getPaymentRequiredResponse(\n name => response.headers.get(name),\n json\n ),\n () =>\n client.getPaymentRequiredResponse(name => response.headers.get(name))\n ),\n error => ({\n cause: 'parse_payment_required',\n message:\n error instanceof Error\n ? error.message\n : 'Failed to parse payment required',\n })\n );\n};\n\nexport const safeCreatePaymentPayload = (\n surface: string,\n client: x402HTTPClient,\n paymentRequired: PaymentRequired\n) => {\n return x402ResultFromPromise(\n surface,\n client.createPaymentPayload(paymentRequired),\n error => ({\n cause: 'create_payment_payload',\n message:\n error instanceof Error\n ? error.message\n : 'Failed to create payment payload',\n })\n );\n};\n\nexport const safeGetPaymentSettlement = (\n surface: string,\n client: x402HTTPClient,\n response: Response\n) => {\n return x402ResultFromThrowable(\n surface,\n () => client.getPaymentSettleResponse(name => response.headers.get(name)),\n error => ({\n cause: 'get_payment_settlement',\n message:\n error instanceof Error\n ? error.message\n : 'Failed to get payment settlement',\n })\n );\n};\n\nexport const safeCreateSIWxPayload = (\n surface: string,\n serverInfo: CompleteSIWxInfo,\n signer: PrivateKeyAccount\n) => {\n return x402ResultFromPromise(\n surface,\n createSIWxPayload(serverInfo, signer),\n error => ({\n cause: 'create_siwx_payload',\n message:\n error instanceof Error\n ? error.message\n : 'Failed to create SIWX payload',\n })\n );\n};\n","import { isMppEnabled } from '@/shared/mpp-enabled';\n\nexport type PaymentProtocol = 'x402' | 'mpp';\n\n/**\n * Detects all payment protocols present in a 402 response.\n * MPP responses include a `WWW-Authenticate` header starting with \"Payment\".\n * x402 responses include a `payment-required` header.\n * If neither is explicitly detected, defaults to x402.\n *\n * MPP detection is gated behind {@link isMppEnabled} so it never surfaces\n * in agent context on the `latest` dist-tag.\n */\nexport function detectPaymentProtocols(response: Response): PaymentProtocol[] {\n const protocols: PaymentProtocol[] = [];\n if (isMppEnabled()) {\n const wwwAuth = response.headers.get('WWW-Authenticate');\n if (wwwAuth?.startsWith('Payment')) {\n protocols.push('mpp');\n }\n }\n const paymentRequired = response.headers.get('payment-required');\n if (paymentRequired) {\n protocols.push('x402');\n }\n // If we couldn't detect either explicitly, default to x402\n if (protocols.length === 0) {\n protocols.push('x402');\n }\n return protocols;\n}\n\n/**\n * Convenience: returns the first/preferred protocol from a 402 response.\n * Useful when a single protocol must be chosen (e.g. for payment).\n */\nexport function detectPaymentProtocol(response: Response): PaymentProtocol {\n return detectPaymentProtocols(response)[0]!;\n}\n","import { resultFromPromise } from '@agentcash/neverthrow';\n\nimport { DEFAULT_FETCH_TIMEOUT, safeFetch } from './neverthrow/fetch';\nimport { log } from './log';\n\nimport type { JsonObject, JsonValue } from './neverthrow/json/types';\n\nexport interface EndpointSummary {\n path: string; // \"/api/apollo/people/search\"\n method: string; // \"POST\"\n summary: string; // \"Search for people by name, email, or domain\"\n price?: string; // \"$0.02\" — from x-payment-info, advisory only\n protocols?: string[]; // [\"x402\", \"mpp\"] — from x-payment-info\n}\n\nexport type SpecFetchResult =\n | { ok: true; spec: JsonObject }\n | { ok: false; cause: 'not_found' }\n | { ok: false; cause: 'network' | 'timeout' | 'parse'; message: string };\n\n/** Well-known paths tried for OpenAPI spec discovery. */\nexport const OPENAPI_SPEC_PATHS = [\n '/openapi.json',\n '/.well-known/openapi.json',\n];\n\n/**\n * Fetch an OpenAPI spec for an origin.\n * Tries multiple well-known locations in order.\n *\n * Returns a discriminated result so callers can distinguish\n * \"no spec exists\" from \"couldn't reach the server\".\n */\nexport async function fetchOpenApiSpec(\n origin: string\n): Promise<SpecFetchResult> {\n const uniqueUrls = OPENAPI_SPEC_PATHS.map(p => `${origin}${p}`);\n\n // Track the most informative failure. Network/timeout errors take\n // priority over not_found because they mean the server may be unreachable.\n let failure: SpecFetchResult & { ok: false } = {\n ok: false,\n cause: 'not_found',\n };\n\n for (const url of uniqueUrls) {\n log.debug(`Fetching OpenAPI spec from: ${url}`);\n const fetchResult = await safeFetch(\n 'fetchOpenApiSpec',\n new Request(url, { headers: { Accept: 'application/json' } }),\n DEFAULT_FETCH_TIMEOUT\n );\n\n if (fetchResult.isErr()) {\n const { cause, message } = fetchResult.error;\n if (cause === 'network' || cause === 'timeout') {\n failure = { ok: false, cause, message };\n }\n log.debug(`Failed to fetch OpenAPI spec from: ${url}`);\n continue;\n }\n\n const response = fetchResult.value;\n if (!response.ok) continue;\n\n const jsonResult = await resultFromPromise(\n 'json',\n 'fetchOpenApiSpec',\n response.json() as Promise<JsonObject>,\n () => ({\n cause: 'parse' as const,\n message: `Failed to parse JSON from: ${url}`,\n })\n );\n\n if (jsonResult.isErr()) {\n if (failure.cause === 'not_found') {\n failure = {\n ok: false,\n cause: 'parse',\n message: `Failed to parse JSON from: ${url}`,\n };\n }\n log.debug(`Failed to parse OpenAPI spec from: ${url}`);\n continue;\n }\n\n const spec = jsonResult.value;\n\n // Basic validation - must have paths\n if (spec && typeof spec === 'object' && spec.paths) {\n log.info(`Fetched OpenAPI spec for origin: ${origin}`);\n return { ok: true, spec };\n }\n }\n\n log.debug(`No OpenAPI spec found for origin: ${origin}`);\n return failure;\n}\n\n/**\n * Resolve a JSON $ref pointer within the spec.\n * Only supports local refs: \"#/components/schemas/Foo\"\n */\nfunction resolveRef(\n spec: JsonObject,\n ref: string,\n seen: Set<string>\n): JsonValue | undefined {\n if (!ref.startsWith('#/')) return undefined;\n if (seen.has(ref)) return { $circular: ref } as unknown as JsonValue;\n seen.add(ref);\n\n const parts = ref.slice(2).split('/');\n let current: JsonValue = spec;\n\n for (const part of parts) {\n if (\n current == null ||\n typeof current !== 'object' ||\n Array.isArray(current)\n )\n return undefined;\n const next: JsonValue | undefined = current[part];\n if (next === undefined) return undefined;\n current = next;\n }\n\n if (\n current != null &&\n typeof current === 'object' &&\n !Array.isArray(current)\n ) {\n return resolveRefs(spec, current, seen);\n }\n return current;\n}\n\n/**\n * Recursively resolve all $ref pointers in a JSON object.\n * Keeps it shallow enough to avoid context bloat - max depth 4.\n */\nfunction resolveRefs(\n spec: JsonObject,\n obj: JsonObject,\n seen: Set<string>,\n depth = 0\n): JsonObject {\n if (depth > 4) return obj;\n\n const result: JsonObject = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (key === '$ref' && typeof value === 'string') {\n const resolved = resolveRef(spec, value, seen);\n if (\n resolved != null &&\n typeof resolved === 'object' &&\n !Array.isArray(resolved)\n ) {\n Object.assign(result, resolved);\n } else {\n result[key] = value;\n }\n } else if (\n value != null &&\n typeof value === 'object' &&\n !Array.isArray(value)\n ) {\n result[key] = resolveRefs(spec, value, seen, depth + 1);\n } else if (Array.isArray(value)) {\n result[key] = value.map(item => {\n if (item != null && typeof item === 'object' && !Array.isArray(item)) {\n return resolveRefs(spec, item, seen, depth + 1);\n }\n return item;\n });\n } else {\n result[key] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Normalize a URL path for matching against OpenAPI spec paths.\n * e.g. \"https://example.com/api/foo\" -> \"/api/foo\"\n */\nfunction extractPath(url: string, origin: string): string {\n if (url.startsWith(origin)) {\n return url.slice(origin.length) || '/';\n }\n return URL.canParse(url) ? new URL(url).pathname : url;\n}\n\n/**\n * Extract the schema for a specific endpoint from the OpenAPI spec.\n * Returns the operation object with resolved $refs, or null if not found.\n */\nexport async function getEndpointSchema(\n endpointUrl: string,\n method?: string\n): Promise<JsonObject | null> {\n if (!URL.canParse(endpointUrl)) return null;\n const origin = new URL(endpointUrl).origin;\n\n const result = await fetchOpenApiSpec(origin);\n if (!result.ok) return null;\n const spec = result.spec;\n\n const paths = spec.paths as JsonObject | undefined;\n if (!paths) return null;\n\n const path = extractPath(endpointUrl, origin);\n const httpMethod = (method ?? 'post').toLowerCase();\n\n // Try exact match first, then try path patterns\n let pathEntry = paths[path] as JsonObject | undefined;\n\n if (!pathEntry) {\n // Try matching against parameterized paths like /api/foo/{id}\n for (const [specPath, specEntry] of Object.entries(paths)) {\n if (specEntry == null || typeof specEntry !== 'object') continue;\n\n const pattern = specPath.replace(/\\{[^}]+\\}/g, '[^/]+');\n const regex = new RegExp(`^${pattern}$`);\n if (regex.test(path)) {\n pathEntry = specEntry as JsonObject;\n break;\n }\n }\n }\n\n if (!pathEntry) {\n log.debug(`No OpenAPI path entry found for: ${path}`);\n return null;\n }\n\n const operation = pathEntry[httpMethod] as JsonObject | undefined;\n if (!operation) {\n log.debug(\n `No OpenAPI operation found for ${httpMethod.toUpperCase()} ${path}`\n );\n return null;\n }\n\n const resolved = resolveRefs(spec, operation, new Set());\n return { path, method: httpMethod, ...resolved };\n}\n\n// ── Lightweight Endpoint Index ──\n\n/**\n * Build a lightweight index for an origin.\n * Fetches the OpenAPI spec, then extracts\n * path + method + summary + x-payment-info for each operation.\n */\nexport async function getOriginIndex(\n origin: string\n): Promise<EndpointSummary[] | null> {\n const result = await fetchOpenApiSpec(origin);\n if (!result.ok) return null;\n const spec = result.spec;\n\n const endpoints: EndpointSummary[] = [];\n for (const [path, methods] of Object.entries(\n spec.paths as Record<string, JsonObject>\n )) {\n for (const [method, operation] of Object.entries(methods)) {\n if (typeof operation === 'object' && operation !== null) {\n const op = operation as Record<string, unknown>;\n const paymentInfo = op['x-payment-info'] as\n | Record<string, unknown>\n | undefined;\n const entry: EndpointSummary = {\n path,\n method: method.toUpperCase(),\n summary: (op.summary as string) || (op.description as string) || '',\n };\n if (paymentInfo?.price != null) {\n entry.price = `$${paymentInfo.price as number}`;\n }\n if (Array.isArray(paymentInfo?.protocols)) {\n entry.protocols = paymentInfo.protocols as string[];\n }\n endpoints.push(entry);\n }\n }\n }\n\n return endpoints;\n}\n\n/** HTTP methods that represent operations in an OpenAPI path entry. */\nconst OPENAPI_HTTP_METHODS = new Set([\n 'get',\n 'post',\n 'put',\n 'delete',\n 'patch',\n 'head',\n 'options',\n 'trace',\n]);\n\n/**\n * Return the HTTP methods defined in the OpenAPI spec for a given endpoint URL.\n * Returns null if no spec or path entry is available (caller should fall back to probing all methods).\n */\nexport async function getSpecMethods(\n endpointUrl: string\n): Promise<string[] | null> {\n if (!URL.canParse(endpointUrl)) return null;\n const origin = new URL(endpointUrl).origin;\n\n const result = await fetchOpenApiSpec(origin);\n if (!result.ok) return null;\n\n const paths = result.spec.paths as JsonObject;\n const path = extractPath(endpointUrl, origin);\n\n let pathEntry = paths[path] as JsonObject | undefined;\n\n if (!pathEntry) {\n for (const [specPath, specEntry] of Object.entries(paths)) {\n if (specEntry == null || typeof specEntry !== 'object') continue;\n const pattern = specPath.replace(/\\{[^}]+\\}/g, '[^/]+');\n const regex = new RegExp(`^${pattern}$`);\n if (regex.test(path)) {\n pathEntry = specEntry as JsonObject;\n break;\n }\n }\n }\n\n if (!pathEntry) return null;\n\n return Object.keys(pathEntry)\n .filter(k => OPENAPI_HTTP_METHODS.has(k))\n .map(k => k.toUpperCase());\n}\n\n/**\n * Look up a single endpoint entry from the origin index.\n * Fetches the OpenAPI spec if needed.\n */\nexport async function getIndexEntry(\n origin: string,\n path: string,\n method: string\n): Promise<EndpointSummary | undefined> {\n const entries = await getOriginIndex(origin);\n if (!entries) return undefined;\n\n const m = method.toUpperCase();\n return entries.find(e => e.path === path && e.method === m);\n}\n","import { formatUnits } from 'viem';\n\nexport const tokenStringToNumber = (amount: string, decimals = 6) => {\n return Number(formatUnits(BigInt(amount), decimals));\n};\n","import type { PaymentRequired } from '@x402/core/types';\nimport type { DiscoveryExtension } from '@x402/extensions/bazaar';\nimport type {\n CompleteSIWxInfo,\n SIWxExtensionInfo,\n SupportedChain,\n} from '@x402/extensions/sign-in-with-x';\n\nconst getBazaarExtension = (extensions: PaymentRequired['extensions']) => {\n const { bazaar } = extensions ?? {};\n\n if (!bazaar) {\n return undefined;\n }\n\n return bazaar as DiscoveryExtension;\n};\n\nexport const getInputSchema = (extensions: PaymentRequired['extensions']) =>\n getBazaarExtension(extensions)?.schema.properties.input;\n\nexport const getSiwxExtension = (\n extensions: PaymentRequired['extensions']\n): CompleteSIWxInfo | undefined => {\n const siwx = extensions?.['sign-in-with-x'] as\n | { info?: SIWxExtensionInfo; supportedChains?: SupportedChain[] }\n | undefined;\n\n if (!siwx?.info) {\n return undefined;\n }\n\n // Pick the first EVM chain from supportedChains, falling back to defaults\n const chain = siwx.supportedChains?.find(c =>\n c.chainId.startsWith('eip155:')\n );\n\n return {\n ...siwx.info,\n chainId: chain?.chainId ?? 'eip155:8453',\n type: chain?.type ?? 'eip191',\n signatureScheme: chain?.signatureScheme,\n };\n};\n","import { log } from '@/shared/log';\nimport {\n DEFAULT_FETCH_TIMEOUT,\n safeFetch,\n safeParseResponse,\n} from '@/shared/neverthrow/fetch';\nimport { fetchOpenApiSpec, getOriginIndex } from '@/shared/openapi-cache';\n\nimport type { EndpointSummary } from '@/shared/openapi-cache';\n\nexport interface OpenApiInfo {\n title: string;\n version?: string;\n description?: string;\n}\n\nexport interface DiscoveryResult {\n origin: string;\n source: 'openapi';\n info?: OpenApiInfo;\n endpoints: EndpointSummary[];\n instructions?: string;\n}\n\nexport interface DiscoverFailure {\n found: false;\n cause: 'not_found' | 'network' | 'timeout' | 'parse';\n message?: string;\n}\n\n/**\n * Fetch llms.txt instructions from an origin (best-effort).\n */\nasync function fetchLlmsTxt(\n surface: string,\n origin: string\n): Promise<string | null> {\n const llmsTxtUrl = `${origin}/llms.txt`;\n log.debug(`Fetching llms.txt from: ${llmsTxtUrl}`);\n\n const result = await safeFetch(\n surface,\n new Request(llmsTxtUrl, { headers: { Accept: 'text/plain' } }),\n DEFAULT_FETCH_TIMEOUT\n );\n\n if (result.isErr()) return null;\n\n if (!result.value.ok) return null;\n\n const parseResult = await safeParseResponse(surface, result.value);\n if (parseResult.isErr() || parseResult.value.type !== 'text') return null;\n\n return parseResult.value.data;\n}\n\n/**\n * Discover payment-protected resources on an origin.\n * Fetches OpenAPI spec, builds endpoint index, and fetches llms.txt instructions.\n *\n * Returns DiscoveryResult on success, DiscoverFailure with cause on failure.\n */\nexport async function discoverResources(\n surface: string,\n url: string\n): Promise<DiscoveryResult | DiscoverFailure> {\n const origin = URL.canParse(url) ? new URL(url).origin : url;\n\n log.info(`Discovering resources for origin: ${origin}`);\n\n // Fetch OpenAPI spec and llms.txt in parallel\n const [specResult, instructions] = await Promise.all([\n fetchOpenApiSpec(origin),\n fetchLlmsTxt(surface, origin),\n ]);\n\n if (!specResult.ok) {\n log.debug(`No OpenAPI spec found for ${origin}: ${specResult.cause}`);\n return {\n found: false,\n cause: specResult.cause,\n ...('message' in specResult ? { message: specResult.message } : {}),\n };\n }\n\n const spec = specResult.spec;\n\n // Build the lightweight endpoint index\n const endpoints = await getOriginIndex(origin);\n\n if (!endpoints || endpoints.length === 0) {\n log.debug(`OpenAPI spec found for ${origin} but no endpoints extracted`);\n return { found: false, cause: 'not_found' };\n }\n\n log.info(`Found ${endpoints.length} endpoints for: ${origin}`);\n\n // Extract info from the OpenAPI spec (title, version, description)\n const rawInfo = spec.info as Record<string, unknown> | undefined;\n const info: OpenApiInfo | undefined =\n rawInfo && typeof rawInfo.title === 'string'\n ? {\n title: rawInfo.title,\n ...(typeof rawInfo.version === 'string'\n ? { version: rawInfo.version }\n : {}),\n ...(typeof rawInfo.description === 'string'\n ? { description: rawInfo.description }\n : {}),\n }\n : undefined;\n\n return {\n origin,\n source: 'openapi',\n ...(info ? { info } : {}),\n endpoints: endpoints.map(({ path, method, summary, price, protocols }) => ({\n path,\n method,\n summary,\n ...(price ? { price } : {}),\n ...(protocols ? { protocols } : {}),\n })),\n ...(instructions ? { instructions } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AACA,SAAS,iBAAiB;AAC1B,SAAS,YAAY,sBAAsB;;;ACI3C,SAAS,yBAAyB;AAQlC,IAAM,YAAY;AAEX,IAAM,SAAS,CAAI,UAAa,GAAG,KAAK;AACxC,IAAM,UAAU,CAAC,OAAe,UACrC,IAAI,WAAW,OAAO,KAAK;AAE7B,IAAM,wBAAwB,CAC5B,SACA,SACA,UACG,kBAAkB,WAAW,SAAS,SAAS,KAAK;AAEzD,IAAM,0BAA0B,CAC9B,SACA,IACA,UACG,oBAAoB,WAAW,SAAS,IAAI,KAAK;AAE/C,IAAM,yBAAyB,CACpC,SACA,QACA,aACG;AACH,SAAO;AAAA,IACL;AAAA,IACA,SAAS,KAAK,EAAE;AAAA,MACd,UACE,OAAO;AAAA,QACL,UAAQ,SAAS,QAAQ,IAAI,IAAI;AAAA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
|
+
} from "./chunk-L3LTEB5B.js";
|
|
4
4
|
import {
|
|
5
5
|
MCP_VERSION
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YXENPVZ4.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-
|
|
122
|
+
//# sourceMappingURL=chunk-RN73GKUU.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.
|
|
7
|
+
return "0.6.4";
|
|
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-
|
|
22
|
+
//# sourceMappingURL=chunk-YXENPVZ4.js.map
|
|
@@ -6,20 +6,20 @@ import {
|
|
|
6
6
|
createFetchWithAuth,
|
|
7
7
|
createFetchWithPayment,
|
|
8
8
|
requestSchema
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-3STID4ZW.js";
|
|
10
10
|
import {
|
|
11
11
|
TEMPO_RPC_URL,
|
|
12
12
|
getWalletInfo,
|
|
13
13
|
submitErrorReport
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-RN73GKUU.js";
|
|
15
15
|
import {
|
|
16
16
|
checkEndpoint,
|
|
17
17
|
discoverResources
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-NFGTXPUD.js";
|
|
19
|
+
import "./chunk-L3LTEB5B.js";
|
|
20
20
|
import {
|
|
21
21
|
MCP_VERSION
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-YXENPVZ4.js";
|
|
23
23
|
import {
|
|
24
24
|
DEFAULT_NETWORK,
|
|
25
25
|
getWallet,
|
|
@@ -460,7 +460,7 @@ async function checkCommand(args, flags) {
|
|
|
460
460
|
// src/cli/commands/discover.ts
|
|
461
461
|
async function discoverCommand(args, flags) {
|
|
462
462
|
const result = await discoverResources("cli:discover", args.url);
|
|
463
|
-
if (result) {
|
|
463
|
+
if ("endpoints" in result) {
|
|
464
464
|
return outputAndExit(
|
|
465
465
|
successResponse({
|
|
466
466
|
found: true,
|
|
@@ -477,9 +477,9 @@ async function discoverCommand(args, flags) {
|
|
|
477
477
|
return outputAndExit(
|
|
478
478
|
errorResponse({
|
|
479
479
|
code: "GENERAL_ERROR",
|
|
480
|
-
message: `No OpenAPI spec found for ${origin}. Tried: /openapi.json, /.well-known/openapi.json`,
|
|
480
|
+
message: result.message ?? `No OpenAPI spec found for ${origin}. Tried: /openapi.json, /.well-known/openapi.json`,
|
|
481
481
|
surface: "cli:discover",
|
|
482
|
-
cause:
|
|
482
|
+
cause: result.cause,
|
|
483
483
|
details: { origin }
|
|
484
484
|
}),
|
|
485
485
|
flags
|
|
@@ -550,6 +550,10 @@ async function walletRedeemCommand(args, flags) {
|
|
|
550
550
|
flags
|
|
551
551
|
);
|
|
552
552
|
}
|
|
553
|
+
async function walletAddressCommand(_args, flags) {
|
|
554
|
+
const { account } = await getWalletOrExit(flags);
|
|
555
|
+
return outputAndExit(successResponse({ address: account.address }), flags);
|
|
556
|
+
}
|
|
553
557
|
|
|
554
558
|
// src/cli/commands/report-error.ts
|
|
555
559
|
var SURFACE6 = "cli:report-error";
|
|
@@ -583,7 +587,7 @@ async function reportErrorCommand(args, flags) {
|
|
|
583
587
|
|
|
584
588
|
// src/cli/commands/server.ts
|
|
585
589
|
async function serverCommand(flags) {
|
|
586
|
-
const { startServer } = await import("./server-
|
|
590
|
+
const { startServer } = await import("./server-NX7XT2F6.js");
|
|
587
591
|
await startServer(flags);
|
|
588
592
|
}
|
|
589
593
|
export {
|
|
@@ -594,7 +598,8 @@ export {
|
|
|
594
598
|
registerCommand,
|
|
595
599
|
reportErrorCommand,
|
|
596
600
|
serverCommand,
|
|
601
|
+
walletAddressCommand,
|
|
597
602
|
walletInfoCommand,
|
|
598
603
|
walletRedeemCommand
|
|
599
604
|
};
|
|
600
|
-
//# sourceMappingURL=commands-
|
|
605
|
+
//# sourceMappingURL=commands-D3PD4CNW.js.map
|