agentcash 0.6.10 → 0.7.1
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 +960 -543
- package/dist/esm/check-endpoint-O2ZOEYXD.d.ts +30 -0
- package/dist/esm/{chunk-DREKGGZJ.js → chunk-4CQDDIKH.js} +2 -2
- package/dist/esm/chunk-DJS6BHZB.js +7 -0
- package/dist/esm/{chunk-CU5TC4GQ.js.map → chunk-DJS6BHZB.js.map} +1 -1
- package/dist/esm/chunk-MWRO3R4V.js +62 -0
- package/dist/esm/chunk-MWRO3R4V.js.map +1 -0
- package/dist/esm/{chunk-SDQV56RE.js → chunk-QPL3AVUK.js} +1 -1
- package/dist/esm/{chunk-SDQV56RE.js.map → chunk-QPL3AVUK.js.map} +1 -1
- package/dist/esm/{chunk-ITPKPIJC.js → chunk-RYH3NDAP.js} +120 -19
- package/dist/esm/chunk-RYH3NDAP.js.map +1 -0
- package/dist/esm/{chunk-BRDMMHEQ.js → chunk-SN5HHMIT.js} +2 -2
- package/dist/esm/{chunk-HRFGLP6E.js → chunk-UIMAHOSV.js} +3 -3
- package/dist/esm/{commands-NXFUKNPZ.js → commands-W6VY355C.js} +55 -34
- package/dist/esm/commands-W6VY355C.js.map +1 -0
- package/dist/esm/index.js +23 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/{install-U7N5DVC4.js → install-ZJC2MCDG.js} +3 -3
- package/dist/esm/lib.d.ts +2 -1
- package/dist/esm/lib.js +2 -3
- package/dist/esm/{server-UU4Y7IOG.js → server-3SY6CIP7.js} +77 -46
- package/dist/esm/server-3SY6CIP7.js.map +1 -0
- package/dist/esm/shared/operations/index.d.ts +2 -1
- package/dist/esm/shared/operations/index.js +4 -4
- package/dist/esm/shared/operations/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/esm/check-endpoint-UD2Ycr-4.d.ts +0 -115
- package/dist/esm/chunk-CU5TC4GQ.js +0 -7
- package/dist/esm/chunk-ITPKPIJC.js.map +0 -1
- package/dist/esm/chunk-V4B6FDUP.js +0 -698
- package/dist/esm/chunk-V4B6FDUP.js.map +0 -1
- package/dist/esm/commands-NXFUKNPZ.js.map +0 -1
- package/dist/esm/server-UU4Y7IOG.js.map +0 -1
- /package/dist/esm/{chunk-DREKGGZJ.js.map → chunk-4CQDDIKH.js.map} +0 -0
- /package/dist/esm/{chunk-BRDMMHEQ.js.map → chunk-SN5HHMIT.js.map} +0 -0
- /package/dist/esm/{chunk-HRFGLP6E.js.map → chunk-UIMAHOSV.js.map} +0 -0
- /package/dist/esm/{install-U7N5DVC4.js.map → install-ZJC2MCDG.js.map} +0 -0
package/dist/cjs/run-server.cjs
CHANGED
|
@@ -34,10 +34,10 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
34
34
|
));
|
|
35
35
|
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
36
36
|
|
|
37
|
-
// ../../../node_modules/.pnpm/tsup@8.5.
|
|
37
|
+
// ../../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.3_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
|
|
38
38
|
var getImportMetaUrl, importMetaUrl;
|
|
39
39
|
var init_cjs_shims = __esm({
|
|
40
|
-
"../../../node_modules/.pnpm/tsup@8.5.
|
|
40
|
+
"../../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.3_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js"() {
|
|
41
41
|
"use strict";
|
|
42
42
|
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
43
43
|
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
@@ -65024,6 +65024,9 @@ var ResultAsync = class _ResultAsync {
|
|
|
65024
65024
|
});
|
|
65025
65025
|
}
|
|
65026
65026
|
};
|
|
65027
|
+
function okAsync(value) {
|
|
65028
|
+
return new ResultAsync(Promise.resolve(new Ok(value)));
|
|
65029
|
+
}
|
|
65027
65030
|
function errAsync(err3) {
|
|
65028
65031
|
return new ResultAsync(Promise.resolve(new Err(err3)));
|
|
65029
65032
|
}
|
|
@@ -113813,7 +113816,7 @@ var import_path2 = require("path");
|
|
|
113813
113816
|
var import_url = require("url");
|
|
113814
113817
|
function getVersion2() {
|
|
113815
113818
|
if (true) {
|
|
113816
|
-
return "0.
|
|
113819
|
+
return "0.7.1";
|
|
113817
113820
|
}
|
|
113818
113821
|
const __dirname3 = (0, import_path2.dirname)((0, import_url.fileURLToPath)(importMetaUrl));
|
|
113819
113822
|
const pkg = JSON.parse(
|
|
@@ -113976,7 +113979,7 @@ var TEMPO_TOKEN_ADDRESS = "0x20c0000000000000000000000000000000000000";
|
|
|
113976
113979
|
|
|
113977
113980
|
// src/shared/mpp-enabled.ts
|
|
113978
113981
|
init_cjs_shims();
|
|
113979
|
-
var isMppEnabled = () => "0.
|
|
113982
|
+
var isMppEnabled = () => "0.7.1".includes("-mpp");
|
|
113980
113983
|
|
|
113981
113984
|
// src/shared/operations/fetch-with-payment.ts
|
|
113982
113985
|
init_cjs_shims();
|
|
@@ -115717,514 +115720,935 @@ init_cjs_shims();
|
|
|
115717
115720
|
// src/shared/operations/check-endpoint.ts
|
|
115718
115721
|
init_cjs_shims();
|
|
115719
115722
|
|
|
115720
|
-
//
|
|
115723
|
+
// ../../../node_modules/.pnpm/@agentcash+discovery@1.0.0/node_modules/@agentcash/discovery/dist/index.js
|
|
115721
115724
|
init_cjs_shims();
|
|
115722
|
-
|
|
115723
|
-
|
|
115724
|
-
|
|
115725
|
-
|
|
115726
|
-
|
|
115727
|
-
|
|
115728
|
-
|
|
115729
|
-
|
|
115730
|
-
|
|
115731
|
-
|
|
115732
|
-
|
|
115733
|
-
|
|
115734
|
-
|
|
115735
|
-
|
|
115736
|
-
|
|
115737
|
-
|
|
115738
|
-
|
|
115739
|
-
|
|
115740
|
-
|
|
115741
|
-
|
|
115742
|
-
|
|
115725
|
+
|
|
115726
|
+
// ../../../node_modules/.pnpm/@x402+core@2.6.0/node_modules/@x402/core/dist/esm/schemas/index.mjs
|
|
115727
|
+
init_cjs_shims();
|
|
115728
|
+
var NonEmptyString = external_exports4.string().min(1);
|
|
115729
|
+
var Any = external_exports4.record(external_exports4.unknown());
|
|
115730
|
+
var OptionalAny = external_exports4.record(external_exports4.unknown()).optional().nullable();
|
|
115731
|
+
var NetworkSchemaV1 = NonEmptyString;
|
|
115732
|
+
var NetworkSchemaV2 = external_exports4.string().min(3).refine((val) => val.includes(":"), {
|
|
115733
|
+
message: "Network must be in CAIP-2 format (e.g., 'eip155:84532')"
|
|
115734
|
+
});
|
|
115735
|
+
var NetworkSchema = external_exports4.union([NetworkSchemaV1, NetworkSchemaV2]);
|
|
115736
|
+
var ResourceInfoSchema = external_exports4.object({
|
|
115737
|
+
url: NonEmptyString,
|
|
115738
|
+
description: external_exports4.string().optional(),
|
|
115739
|
+
mimeType: external_exports4.string().optional()
|
|
115740
|
+
});
|
|
115741
|
+
var PaymentRequirementsV1Schema = external_exports4.object({
|
|
115742
|
+
scheme: NonEmptyString,
|
|
115743
|
+
network: NetworkSchemaV1,
|
|
115744
|
+
maxAmountRequired: NonEmptyString,
|
|
115745
|
+
resource: NonEmptyString,
|
|
115746
|
+
// URL string in V1
|
|
115747
|
+
description: external_exports4.string(),
|
|
115748
|
+
mimeType: external_exports4.string().optional(),
|
|
115749
|
+
outputSchema: Any.optional().nullable(),
|
|
115750
|
+
payTo: NonEmptyString,
|
|
115751
|
+
maxTimeoutSeconds: external_exports4.number().positive(),
|
|
115752
|
+
asset: NonEmptyString,
|
|
115753
|
+
extra: OptionalAny
|
|
115754
|
+
});
|
|
115755
|
+
var PaymentRequiredV1Schema = external_exports4.object({
|
|
115756
|
+
x402Version: external_exports4.literal(1),
|
|
115757
|
+
error: external_exports4.string().optional(),
|
|
115758
|
+
accepts: external_exports4.array(PaymentRequirementsV1Schema).min(1)
|
|
115759
|
+
});
|
|
115760
|
+
var PaymentPayloadV1Schema = external_exports4.object({
|
|
115761
|
+
x402Version: external_exports4.literal(1),
|
|
115762
|
+
scheme: NonEmptyString,
|
|
115763
|
+
network: NetworkSchemaV1,
|
|
115764
|
+
payload: Any
|
|
115765
|
+
});
|
|
115766
|
+
var PaymentRequirementsV2Schema = external_exports4.object({
|
|
115767
|
+
scheme: NonEmptyString,
|
|
115768
|
+
network: NetworkSchemaV2,
|
|
115769
|
+
amount: NonEmptyString,
|
|
115770
|
+
asset: NonEmptyString,
|
|
115771
|
+
payTo: NonEmptyString,
|
|
115772
|
+
maxTimeoutSeconds: external_exports4.number().positive(),
|
|
115773
|
+
extra: OptionalAny
|
|
115774
|
+
});
|
|
115775
|
+
var PaymentRequiredV2Schema = external_exports4.object({
|
|
115776
|
+
x402Version: external_exports4.literal(2),
|
|
115777
|
+
error: external_exports4.string().optional(),
|
|
115778
|
+
resource: ResourceInfoSchema,
|
|
115779
|
+
accepts: external_exports4.array(PaymentRequirementsV2Schema).min(1),
|
|
115780
|
+
extensions: OptionalAny
|
|
115781
|
+
});
|
|
115782
|
+
var PaymentPayloadV2Schema = external_exports4.object({
|
|
115783
|
+
x402Version: external_exports4.literal(2),
|
|
115784
|
+
resource: ResourceInfoSchema.optional(),
|
|
115785
|
+
accepted: PaymentRequirementsV2Schema,
|
|
115786
|
+
payload: Any,
|
|
115787
|
+
extensions: OptionalAny
|
|
115788
|
+
});
|
|
115789
|
+
var PaymentRequirementsSchema = external_exports4.union([
|
|
115790
|
+
PaymentRequirementsV1Schema,
|
|
115791
|
+
PaymentRequirementsV2Schema
|
|
115792
|
+
]);
|
|
115793
|
+
var PaymentRequiredSchema = external_exports4.discriminatedUnion("x402Version", [
|
|
115794
|
+
PaymentRequiredV1Schema,
|
|
115795
|
+
PaymentRequiredV2Schema
|
|
115796
|
+
]);
|
|
115797
|
+
var PaymentPayloadSchema = external_exports4.discriminatedUnion("x402Version", [
|
|
115798
|
+
PaymentPayloadV1Schema,
|
|
115799
|
+
PaymentPayloadV2Schema
|
|
115800
|
+
]);
|
|
115801
|
+
|
|
115802
|
+
// ../../../node_modules/.pnpm/@agentcash+discovery@1.0.0/node_modules/@agentcash/discovery/dist/index.js
|
|
115803
|
+
var OpenApiPaymentInfoSchema = external_exports3.object({
|
|
115804
|
+
pricingMode: external_exports3.enum(["fixed", "range", "quote"]),
|
|
115805
|
+
price: external_exports3.string().optional(),
|
|
115806
|
+
minPrice: external_exports3.string().optional(),
|
|
115807
|
+
maxPrice: external_exports3.string().optional(),
|
|
115808
|
+
protocols: external_exports3.array(external_exports3.string()).optional()
|
|
115809
|
+
});
|
|
115810
|
+
var OpenApiOperationSchema = external_exports3.object({
|
|
115811
|
+
operationId: external_exports3.string().optional(),
|
|
115812
|
+
summary: external_exports3.string().optional(),
|
|
115813
|
+
description: external_exports3.string().optional(),
|
|
115814
|
+
tags: external_exports3.array(external_exports3.string()).optional(),
|
|
115815
|
+
security: external_exports3.array(external_exports3.record(external_exports3.string(), external_exports3.array(external_exports3.string()))).optional(),
|
|
115816
|
+
parameters: external_exports3.array(
|
|
115817
|
+
external_exports3.object({
|
|
115818
|
+
in: external_exports3.string(),
|
|
115819
|
+
name: external_exports3.string(),
|
|
115820
|
+
schema: external_exports3.unknown().optional(),
|
|
115821
|
+
required: external_exports3.boolean().optional()
|
|
115822
|
+
})
|
|
115823
|
+
).optional(),
|
|
115824
|
+
requestBody: external_exports3.object({
|
|
115825
|
+
required: external_exports3.boolean().optional(),
|
|
115826
|
+
content: external_exports3.record(external_exports3.string(), external_exports3.object({ schema: external_exports3.unknown().optional() }))
|
|
115827
|
+
}).optional(),
|
|
115828
|
+
responses: external_exports3.record(external_exports3.string(), external_exports3.unknown()).optional(),
|
|
115829
|
+
"x-payment-info": OpenApiPaymentInfoSchema.optional()
|
|
115830
|
+
});
|
|
115831
|
+
var OpenApiPathItemSchema = external_exports3.object({
|
|
115832
|
+
get: OpenApiOperationSchema.optional(),
|
|
115833
|
+
post: OpenApiOperationSchema.optional(),
|
|
115834
|
+
put: OpenApiOperationSchema.optional(),
|
|
115835
|
+
delete: OpenApiOperationSchema.optional(),
|
|
115836
|
+
patch: OpenApiOperationSchema.optional(),
|
|
115837
|
+
head: OpenApiOperationSchema.optional(),
|
|
115838
|
+
options: OpenApiOperationSchema.optional(),
|
|
115839
|
+
trace: OpenApiOperationSchema.optional()
|
|
115840
|
+
});
|
|
115841
|
+
var OpenApiDocSchema = external_exports3.object({
|
|
115842
|
+
// TODO(zdql): We should inherit a canonical OpenAPI schema and then extend with our types.
|
|
115843
|
+
openapi: external_exports3.string(),
|
|
115844
|
+
info: external_exports3.object({
|
|
115845
|
+
title: external_exports3.string(),
|
|
115846
|
+
version: external_exports3.string(),
|
|
115847
|
+
description: external_exports3.string().optional(),
|
|
115848
|
+
guidance: external_exports3.string().optional()
|
|
115849
|
+
}),
|
|
115850
|
+
servers: external_exports3.array(external_exports3.object({ url: external_exports3.string() })).optional(),
|
|
115851
|
+
tags: external_exports3.array(external_exports3.object({ name: external_exports3.string() })).optional(),
|
|
115852
|
+
components: external_exports3.object({ securitySchemes: external_exports3.record(external_exports3.string(), external_exports3.unknown()).optional() }).optional(),
|
|
115853
|
+
"x-discovery": external_exports3.record(external_exports3.string(), external_exports3.unknown()).optional(),
|
|
115854
|
+
paths: external_exports3.record(external_exports3.string(), OpenApiPathItemSchema)
|
|
115855
|
+
});
|
|
115856
|
+
var WellKnownDocSchema = external_exports3.object({
|
|
115857
|
+
version: external_exports3.number().optional(),
|
|
115858
|
+
resources: external_exports3.array(external_exports3.string()).default([]),
|
|
115859
|
+
mppResources: external_exports3.array(external_exports3.string()).optional(),
|
|
115860
|
+
// isMmmEnabled
|
|
115861
|
+
description: external_exports3.string().optional(),
|
|
115862
|
+
ownershipProofs: external_exports3.array(external_exports3.string()).optional(),
|
|
115863
|
+
instructions: external_exports3.string().optional()
|
|
115864
|
+
});
|
|
115865
|
+
var WellKnownParsedSchema = external_exports3.object({
|
|
115866
|
+
routes: external_exports3.array(
|
|
115867
|
+
external_exports3.object({
|
|
115868
|
+
path: external_exports3.string(),
|
|
115869
|
+
method: external_exports3.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE"])
|
|
115870
|
+
})
|
|
115871
|
+
),
|
|
115872
|
+
instructions: external_exports3.string().optional()
|
|
115873
|
+
});
|
|
115874
|
+
function isRecord(value) {
|
|
115875
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
115876
|
+
}
|
|
115877
|
+
function hasSecurity(operation, scheme) {
|
|
115878
|
+
return operation.security?.some((s) => scheme in s) ?? false;
|
|
115879
|
+
}
|
|
115880
|
+
function has402Response(operation) {
|
|
115881
|
+
return Boolean(operation.responses?.["402"]);
|
|
115882
|
+
}
|
|
115883
|
+
function inferAuthMode(operation) {
|
|
115884
|
+
const hasXPaymentInfo = Boolean(operation["x-payment-info"]);
|
|
115885
|
+
const hasPayment = hasXPaymentInfo || has402Response(operation);
|
|
115886
|
+
const hasApiKey = hasSecurity(operation, "apiKey");
|
|
115887
|
+
const hasSiwx = hasSecurity(operation, "siwx");
|
|
115888
|
+
if (hasPayment && hasApiKey) return "apiKey+paid";
|
|
115889
|
+
if (hasXPaymentInfo) return "paid";
|
|
115890
|
+
if (hasPayment) return hasSiwx ? "siwx" : "paid";
|
|
115891
|
+
if (hasApiKey) return "apiKey";
|
|
115892
|
+
if (hasSiwx) return "siwx";
|
|
115893
|
+
return void 0;
|
|
115894
|
+
}
|
|
115895
|
+
var HTTP_METHODS = /* @__PURE__ */ new Set([
|
|
115896
|
+
"GET",
|
|
115897
|
+
"POST",
|
|
115898
|
+
"PUT",
|
|
115899
|
+
"DELETE",
|
|
115900
|
+
"PATCH",
|
|
115901
|
+
"HEAD",
|
|
115902
|
+
"OPTIONS",
|
|
115903
|
+
"TRACE"
|
|
115904
|
+
]);
|
|
115905
|
+
var DEFAULT_MISSING_METHOD = "POST";
|
|
115906
|
+
function normalizeOrigin(target) {
|
|
115907
|
+
const trimmed = target.trim();
|
|
115908
|
+
const withProtocol = /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
115909
|
+
const url3 = new URL(withProtocol);
|
|
115910
|
+
url3.pathname = "";
|
|
115911
|
+
url3.search = "";
|
|
115912
|
+
url3.hash = "";
|
|
115913
|
+
return url3.toString().replace(/\/$/, "");
|
|
115914
|
+
}
|
|
115915
|
+
function normalizePath(pathname) {
|
|
115916
|
+
const parsed = pathname.trim();
|
|
115917
|
+
if (parsed.length === 0 || parsed === "/") return "/";
|
|
115918
|
+
const pathOnly = parsed.split("?")[0]?.split("#")[0] ?? "/";
|
|
115919
|
+
const prefixed = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
|
|
115920
|
+
const normalized = prefixed.replace(/\/+/g, "/");
|
|
115921
|
+
return normalized !== "/" ? normalized.replace(/\/$/, "") : "/";
|
|
115922
|
+
}
|
|
115923
|
+
function parseMethod(value) {
|
|
115924
|
+
if (!value) return void 0;
|
|
115925
|
+
const upper = value.toUpperCase();
|
|
115926
|
+
return HTTP_METHODS.has(upper) ? upper : void 0;
|
|
115927
|
+
}
|
|
115928
|
+
function toAbsoluteUrl(origin, value) {
|
|
115929
|
+
try {
|
|
115930
|
+
if (/^https?:\/\//i.test(value)) return new URL(value);
|
|
115931
|
+
return new URL(normalizePath(value), `${origin}/`);
|
|
115932
|
+
} catch {
|
|
115933
|
+
return null;
|
|
115934
|
+
}
|
|
115935
|
+
}
|
|
115936
|
+
function toFetchError(err3) {
|
|
115937
|
+
const cause = err3 instanceof DOMException && (err3.name === "TimeoutError" || err3.name === "AbortError") ? "timeout" : "network";
|
|
115938
|
+
return { cause, message: String(err3) };
|
|
115939
|
+
}
|
|
115940
|
+
function fetchSafe(url3, init) {
|
|
115941
|
+
return ResultAsync.fromPromise(fetch(url3, init), toFetchError);
|
|
115942
|
+
}
|
|
115943
|
+
var isMmmEnabled = () => "1.0.0".includes("-mmm");
|
|
115944
|
+
var OpenApiParsedSchema = OpenApiDocSchema.transform((doc) => {
|
|
115945
|
+
const routes = [];
|
|
115946
|
+
for (const [rawPath, pathItem] of Object.entries(doc.paths)) {
|
|
115947
|
+
for (const httpMethod of [...HTTP_METHODS]) {
|
|
115948
|
+
const operation = pathItem[httpMethod.toLowerCase()];
|
|
115949
|
+
if (!operation) continue;
|
|
115950
|
+
const authMode = inferAuthMode(operation) ?? void 0;
|
|
115951
|
+
if (!authMode) continue;
|
|
115952
|
+
const p = operation["x-payment-info"];
|
|
115953
|
+
const protocols = (p?.protocols ?? []).filter(
|
|
115954
|
+
(proto) => proto !== "mpp" || isMmmEnabled()
|
|
115955
|
+
);
|
|
115956
|
+
if ((authMode === "paid" || authMode === "siwx") && !has402Response(operation)) continue;
|
|
115957
|
+
if (authMode === "paid" && protocols.length === 0) continue;
|
|
115958
|
+
const pricing = authMode === "paid" && p ? {
|
|
115959
|
+
pricingMode: p.pricingMode,
|
|
115960
|
+
...p.price ? { price: p.price } : {},
|
|
115961
|
+
...p.minPrice ? { minPrice: p.minPrice } : {},
|
|
115962
|
+
...p.maxPrice ? { maxPrice: p.maxPrice } : {}
|
|
115963
|
+
} : void 0;
|
|
115964
|
+
const summary = operation.summary ?? operation.description;
|
|
115965
|
+
routes.push({
|
|
115966
|
+
path: normalizePath(rawPath),
|
|
115967
|
+
method: httpMethod.toUpperCase(),
|
|
115968
|
+
...summary ? { summary } : {},
|
|
115969
|
+
authMode,
|
|
115970
|
+
...protocols.length ? { protocols } : {},
|
|
115971
|
+
...pricing ? { pricing } : {}
|
|
115972
|
+
});
|
|
115973
|
+
}
|
|
115974
|
+
}
|
|
115975
|
+
return {
|
|
115976
|
+
info: {
|
|
115977
|
+
title: doc.info.title,
|
|
115978
|
+
...doc.info.description ? { description: doc.info.description } : {},
|
|
115979
|
+
version: doc.info.version
|
|
115980
|
+
},
|
|
115981
|
+
routes,
|
|
115982
|
+
...doc.info.guidance ? { guidance: doc.info.guidance } : {}
|
|
115983
|
+
};
|
|
115984
|
+
});
|
|
115985
|
+
async function parseBody(response, url3) {
|
|
115986
|
+
try {
|
|
115987
|
+
const payload = await response.json();
|
|
115988
|
+
const parsed = OpenApiParsedSchema.safeParse(payload);
|
|
115989
|
+
if (!parsed.success) return null;
|
|
115990
|
+
return { raw: payload, ...parsed.data, fetchedUrl: url3 };
|
|
115991
|
+
} catch {
|
|
115992
|
+
return null;
|
|
115993
|
+
}
|
|
115994
|
+
}
|
|
115995
|
+
function getOpenAPI(origin, headers, signal, specificationOverrideUrl) {
|
|
115996
|
+
const url3 = specificationOverrideUrl ?? `${origin}/openapi.json`;
|
|
115997
|
+
return fetchSafe(url3, {
|
|
115998
|
+
method: "GET",
|
|
115999
|
+
headers: { Accept: "application/json", ...headers },
|
|
116000
|
+
signal
|
|
116001
|
+
}).andThen((response) => {
|
|
116002
|
+
if (!response.ok) return okAsync(null);
|
|
116003
|
+
return ResultAsync.fromSafePromise(parseBody(response, url3));
|
|
116004
|
+
});
|
|
116005
|
+
}
|
|
116006
|
+
function toWellKnownParsed(origin, doc) {
|
|
116007
|
+
const routes = doc.resources.flatMap((entry) => {
|
|
116008
|
+
const trimmed = entry.trim();
|
|
116009
|
+
if (!trimmed) return [];
|
|
116010
|
+
const parts = trimmed.split(/\s+/);
|
|
116011
|
+
const maybeMethod = parts.length >= 2 ? parseMethod(parts[0]) : void 0;
|
|
116012
|
+
const target = maybeMethod ? parts.slice(1).join(" ") : trimmed;
|
|
116013
|
+
const absolute = toAbsoluteUrl(origin, target);
|
|
116014
|
+
if (!absolute) return [];
|
|
116015
|
+
return [
|
|
116016
|
+
{
|
|
116017
|
+
path: normalizePath(absolute.pathname),
|
|
116018
|
+
method: maybeMethod ?? DEFAULT_MISSING_METHOD
|
|
115743
116019
|
}
|
|
115744
|
-
|
|
115745
|
-
|
|
116020
|
+
];
|
|
116021
|
+
});
|
|
116022
|
+
return { routes, ...doc.instructions ? { instructions: doc.instructions } : {} };
|
|
116023
|
+
}
|
|
116024
|
+
async function parseBody2(response, origin, url3) {
|
|
116025
|
+
try {
|
|
116026
|
+
const payload = await response.json();
|
|
116027
|
+
const doc = WellKnownDocSchema.safeParse(payload);
|
|
116028
|
+
if (!doc.success) return null;
|
|
116029
|
+
const parsed = WellKnownParsedSchema.safeParse(toWellKnownParsed(origin, doc.data));
|
|
116030
|
+
if (!parsed.success) return null;
|
|
116031
|
+
return { raw: payload, ...parsed.data, fetchedUrl: url3 };
|
|
116032
|
+
} catch {
|
|
116033
|
+
return null;
|
|
116034
|
+
}
|
|
116035
|
+
}
|
|
116036
|
+
function getWellKnown(origin, headers, signal) {
|
|
116037
|
+
const url3 = `${origin}/.well-known/x402`;
|
|
116038
|
+
return fetchSafe(url3, {
|
|
116039
|
+
method: "GET",
|
|
116040
|
+
headers: { Accept: "application/json", ...headers },
|
|
116041
|
+
signal
|
|
116042
|
+
}).andThen((response) => {
|
|
116043
|
+
if (!response.ok) return okAsync(null);
|
|
116044
|
+
return ResultAsync.fromSafePromise(parseBody2(response, origin, url3));
|
|
116045
|
+
});
|
|
116046
|
+
}
|
|
116047
|
+
function formatPrice(pricing) {
|
|
116048
|
+
if (pricing.pricingMode === "fixed") return `$${pricing.price}`;
|
|
116049
|
+
if (pricing.pricingMode === "range") return `$${pricing.minPrice}-$${pricing.maxPrice}`;
|
|
116050
|
+
return pricing.maxPrice ? `up to $${pricing.maxPrice}` : "quote";
|
|
116051
|
+
}
|
|
116052
|
+
function checkL2ForOpenAPI(openApi) {
|
|
116053
|
+
const routes = openApi.routes.map((route) => ({
|
|
116054
|
+
path: route.path,
|
|
116055
|
+
method: route.method,
|
|
116056
|
+
summary: route.summary ?? `${route.method} ${route.path}`,
|
|
116057
|
+
...route.authMode ? { authMode: route.authMode } : {},
|
|
116058
|
+
...route.pricing ? { price: formatPrice(route.pricing) } : {},
|
|
116059
|
+
...route.protocols?.length ? { protocols: route.protocols } : {}
|
|
116060
|
+
}));
|
|
116061
|
+
return {
|
|
116062
|
+
...openApi.info.title ? { title: openApi.info.title } : {},
|
|
116063
|
+
...openApi.info.description ? { description: openApi.info.description } : {},
|
|
116064
|
+
routes,
|
|
116065
|
+
source: "openapi"
|
|
116066
|
+
};
|
|
116067
|
+
}
|
|
116068
|
+
function checkL2ForWellknown(wellKnown) {
|
|
116069
|
+
const routes = wellKnown.routes.map((route) => ({
|
|
116070
|
+
path: route.path,
|
|
116071
|
+
method: route.method,
|
|
116072
|
+
summary: `${route.method} ${route.path}`,
|
|
116073
|
+
authMode: "paid",
|
|
116074
|
+
protocols: ["x402"]
|
|
116075
|
+
}));
|
|
116076
|
+
return { routes, source: "well-known/x402" };
|
|
116077
|
+
}
|
|
116078
|
+
function checkL4ForOpenAPI(openApi) {
|
|
116079
|
+
if (openApi.guidance) {
|
|
116080
|
+
return { guidance: openApi.guidance, source: "openapi" };
|
|
116081
|
+
}
|
|
116082
|
+
return null;
|
|
116083
|
+
}
|
|
116084
|
+
function checkL4ForWellknown(wellKnown) {
|
|
116085
|
+
if (wellKnown.instructions) {
|
|
116086
|
+
return { guidance: wellKnown.instructions, source: "well-known/x402" };
|
|
116087
|
+
}
|
|
116088
|
+
return null;
|
|
116089
|
+
}
|
|
116090
|
+
function estimateTokenCount(text) {
|
|
116091
|
+
return Math.ceil(text.length / 4);
|
|
116092
|
+
}
|
|
116093
|
+
var GuidanceMode = /* @__PURE__ */ ((GuidanceMode2) => {
|
|
116094
|
+
GuidanceMode2["Auto"] = "auto";
|
|
116095
|
+
GuidanceMode2["Always"] = "always";
|
|
116096
|
+
GuidanceMode2["Never"] = "never";
|
|
116097
|
+
return GuidanceMode2;
|
|
116098
|
+
})(GuidanceMode || {});
|
|
116099
|
+
var GUIDANCE_AUTO_INCLUDE_MAX_TOKENS_LENGTH = 1e3;
|
|
116100
|
+
function withGuidance(base2, l4, guidanceMode) {
|
|
116101
|
+
if (guidanceMode === "never") return { ...base2, guidanceAvailable: !!l4 };
|
|
116102
|
+
if (!l4) return { ...base2, guidanceAvailable: false };
|
|
116103
|
+
const tokens2 = estimateTokenCount(l4.guidance);
|
|
116104
|
+
if (guidanceMode === "always" || tokens2 <= GUIDANCE_AUTO_INCLUDE_MAX_TOKENS_LENGTH) {
|
|
116105
|
+
return { ...base2, guidanceAvailable: true, guidanceTokens: tokens2, guidance: l4.guidance };
|
|
116106
|
+
}
|
|
116107
|
+
return { ...base2, guidanceAvailable: true, guidanceTokens: tokens2 };
|
|
116108
|
+
}
|
|
116109
|
+
async function discoverOriginSchema(options) {
|
|
116110
|
+
const origin = normalizeOrigin(options.target);
|
|
116111
|
+
const guidanceMode = options.guidance ?? "auto";
|
|
116112
|
+
const openApiResult = await getOpenAPI(
|
|
116113
|
+
origin,
|
|
116114
|
+
options.headers,
|
|
116115
|
+
options.signal,
|
|
116116
|
+
options.specificationOverrideUrl
|
|
116117
|
+
);
|
|
116118
|
+
const openApi = openApiResult.isOk() ? openApiResult.value : null;
|
|
116119
|
+
if (openApi) {
|
|
116120
|
+
const l22 = checkL2ForOpenAPI(openApi);
|
|
116121
|
+
const l42 = checkL4ForOpenAPI(openApi);
|
|
116122
|
+
const base22 = {
|
|
116123
|
+
found: true,
|
|
116124
|
+
origin,
|
|
116125
|
+
source: "openapi",
|
|
116126
|
+
...l22.title ? { info: { title: l22.title, ...l22.description ? { description: l22.description } : {} } } : {},
|
|
116127
|
+
endpoints: l22.routes
|
|
116128
|
+
};
|
|
116129
|
+
return withGuidance(base22, l42, guidanceMode);
|
|
116130
|
+
}
|
|
116131
|
+
const wellKnownResult = await getWellKnown(origin, options.headers, options.signal);
|
|
116132
|
+
if (wellKnownResult.isErr()) {
|
|
116133
|
+
return {
|
|
116134
|
+
found: false,
|
|
116135
|
+
origin,
|
|
116136
|
+
cause: wellKnownResult.error.cause,
|
|
116137
|
+
message: wellKnownResult.error.message
|
|
116138
|
+
};
|
|
116139
|
+
}
|
|
116140
|
+
const wellKnown = wellKnownResult.value;
|
|
116141
|
+
if (!wellKnown) return { found: false, origin, cause: "not_found" };
|
|
116142
|
+
const l2 = checkL2ForWellknown(wellKnown);
|
|
116143
|
+
const l4 = checkL4ForWellknown(wellKnown);
|
|
116144
|
+
const base2 = {
|
|
116145
|
+
found: true,
|
|
116146
|
+
origin,
|
|
116147
|
+
source: "well-known/x402",
|
|
116148
|
+
endpoints: l2.routes
|
|
116149
|
+
};
|
|
116150
|
+
return withGuidance(base2, l4, guidanceMode);
|
|
116151
|
+
}
|
|
116152
|
+
function extractSchemas(accepts) {
|
|
116153
|
+
const first = accepts[0];
|
|
116154
|
+
if (!isRecord(first)) return {};
|
|
116155
|
+
const outputSchema = isRecord(first.outputSchema) ? first.outputSchema : void 0;
|
|
116156
|
+
return {
|
|
116157
|
+
...outputSchema && isRecord(outputSchema.input) ? { inputSchema: outputSchema.input } : {},
|
|
116158
|
+
...outputSchema && isRecord(outputSchema.output) ? { outputSchema: outputSchema.output } : {}
|
|
116159
|
+
};
|
|
116160
|
+
}
|
|
116161
|
+
function asNonEmptyString(value) {
|
|
116162
|
+
if (typeof value !== "string") return void 0;
|
|
116163
|
+
const trimmed = value.trim();
|
|
116164
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
116165
|
+
}
|
|
116166
|
+
function asPositiveNumber(value) {
|
|
116167
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
116168
|
+
}
|
|
116169
|
+
function extractPaymentOptions(accepts) {
|
|
116170
|
+
return accepts.flatMap((accept) => {
|
|
116171
|
+
if (!isRecord(accept)) return [];
|
|
116172
|
+
const network = asNonEmptyString(accept.network);
|
|
116173
|
+
const asset = asNonEmptyString(accept.asset);
|
|
116174
|
+
const maxAmountRequired = asNonEmptyString(accept.maxAmountRequired);
|
|
116175
|
+
if (!network || !asset || !maxAmountRequired) return [];
|
|
116176
|
+
const scheme = asNonEmptyString(accept.scheme);
|
|
116177
|
+
const payTo = asNonEmptyString(accept.payTo);
|
|
116178
|
+
const maxTimeoutSeconds = asPositiveNumber(accept.maxTimeoutSeconds);
|
|
116179
|
+
return [
|
|
116180
|
+
{
|
|
116181
|
+
protocol: "x402",
|
|
116182
|
+
version: 1,
|
|
116183
|
+
network,
|
|
116184
|
+
asset,
|
|
116185
|
+
maxAmountRequired,
|
|
116186
|
+
...scheme ? { scheme } : {},
|
|
116187
|
+
...payTo ? { payTo } : {},
|
|
116188
|
+
...maxTimeoutSeconds ? { maxTimeoutSeconds } : {}
|
|
116189
|
+
}
|
|
116190
|
+
];
|
|
116191
|
+
});
|
|
116192
|
+
}
|
|
116193
|
+
function extractSchemas2(payload) {
|
|
116194
|
+
if (!isRecord(payload)) return {};
|
|
116195
|
+
const extensions = isRecord(payload.extensions) ? payload.extensions : void 0;
|
|
116196
|
+
const bazaar = extensions && isRecord(extensions.bazaar) ? extensions.bazaar : void 0;
|
|
116197
|
+
const schema = bazaar && isRecord(bazaar.schema) ? bazaar.schema : void 0;
|
|
116198
|
+
if (!schema) return {};
|
|
116199
|
+
const schemaProps = isRecord(schema.properties) ? schema.properties : void 0;
|
|
116200
|
+
if (!schemaProps) return {};
|
|
116201
|
+
const inputProps = isRecord(schemaProps.input) ? schemaProps.input : void 0;
|
|
116202
|
+
const inputProperties = inputProps && isRecord(inputProps.properties) ? inputProps.properties : void 0;
|
|
116203
|
+
const inputSchema = (inputProperties && isRecord(inputProperties.body) ? inputProperties.body : void 0) ?? (inputProperties && isRecord(inputProperties.queryParams) ? inputProperties.queryParams : void 0);
|
|
116204
|
+
const outputProps = isRecord(schemaProps.output) ? schemaProps.output : void 0;
|
|
116205
|
+
const outputProperties = outputProps && isRecord(outputProps.properties) ? outputProps.properties : void 0;
|
|
116206
|
+
const outputSchema = outputProperties && isRecord(outputProperties.example) ? outputProperties.example : void 0;
|
|
116207
|
+
return {
|
|
116208
|
+
...inputSchema ? { inputSchema } : {},
|
|
116209
|
+
...outputSchema ? { outputSchema } : {}
|
|
116210
|
+
};
|
|
116211
|
+
}
|
|
116212
|
+
function extractPaymentOptions2(accepts) {
|
|
116213
|
+
return accepts.flatMap((accept) => {
|
|
116214
|
+
if (!isRecord(accept)) return [];
|
|
116215
|
+
const network = asNonEmptyString(accept.network);
|
|
116216
|
+
const asset = asNonEmptyString(accept.asset);
|
|
116217
|
+
const amount2 = asNonEmptyString(accept.amount);
|
|
116218
|
+
if (!network || !asset || !amount2) return [];
|
|
116219
|
+
const scheme = asNonEmptyString(accept.scheme);
|
|
116220
|
+
const payTo = asNonEmptyString(accept.payTo);
|
|
116221
|
+
const maxTimeoutSeconds = asPositiveNumber(accept.maxTimeoutSeconds);
|
|
116222
|
+
return [
|
|
116223
|
+
{
|
|
116224
|
+
protocol: "x402",
|
|
116225
|
+
version: 2,
|
|
116226
|
+
network,
|
|
116227
|
+
asset,
|
|
116228
|
+
amount: amount2,
|
|
116229
|
+
...scheme ? { scheme } : {},
|
|
116230
|
+
...payTo ? { payTo } : {},
|
|
116231
|
+
...maxTimeoutSeconds ? { maxTimeoutSeconds } : {}
|
|
116232
|
+
}
|
|
116233
|
+
];
|
|
116234
|
+
});
|
|
116235
|
+
}
|
|
116236
|
+
function parseVersion(payload) {
|
|
116237
|
+
if (!isRecord(payload)) return void 0;
|
|
116238
|
+
const v = payload.x402Version;
|
|
116239
|
+
if (v === 1 || v === 2) return v;
|
|
116240
|
+
return void 0;
|
|
116241
|
+
}
|
|
116242
|
+
function detectAuthHint(payload) {
|
|
116243
|
+
if (isRecord(payload) && isRecord(payload.extensions)) {
|
|
116244
|
+
if (payload.extensions["api-key"]) return "apiKey+paid";
|
|
116245
|
+
if (payload.extensions["sign-in-with-x"]) return "siwx";
|
|
116246
|
+
}
|
|
116247
|
+
return "paid";
|
|
116248
|
+
}
|
|
116249
|
+
function extractPaymentOptions3(payload) {
|
|
116250
|
+
if (!isRecord(payload)) return [];
|
|
116251
|
+
const version7 = parseVersion(payload);
|
|
116252
|
+
const accepts = Array.isArray(payload.accepts) ? payload.accepts : [];
|
|
116253
|
+
if (version7 === 1) return extractPaymentOptions(accepts);
|
|
116254
|
+
if (version7 === 2) return extractPaymentOptions2(accepts);
|
|
116255
|
+
return [];
|
|
116256
|
+
}
|
|
116257
|
+
function extractSchemas3(payload) {
|
|
116258
|
+
if (!isRecord(payload)) return {};
|
|
116259
|
+
const version7 = parseVersion(payload);
|
|
116260
|
+
if (version7 === 2) return extractSchemas2(payload);
|
|
116261
|
+
if (version7 === 1) {
|
|
116262
|
+
const accepts = Array.isArray(payload.accepts) ? payload.accepts : [];
|
|
116263
|
+
return extractSchemas(accepts);
|
|
116264
|
+
}
|
|
116265
|
+
return {};
|
|
116266
|
+
}
|
|
116267
|
+
function parseInputSchema(payload) {
|
|
116268
|
+
return extractSchemas3(payload).inputSchema;
|
|
116269
|
+
}
|
|
116270
|
+
function parseOutputSchema(payload) {
|
|
116271
|
+
return extractSchemas3(payload).outputSchema;
|
|
116272
|
+
}
|
|
116273
|
+
async function parsePaymentRequiredBody(response) {
|
|
116274
|
+
const payload = await response.clone().json();
|
|
116275
|
+
if (!isRecord(payload) || payload.x402Version !== 1) return null;
|
|
116276
|
+
return payload;
|
|
116277
|
+
}
|
|
116278
|
+
function parsePaymentRequiredBody2(headerValue) {
|
|
116279
|
+
const payload = JSON.parse(atob(headerValue));
|
|
116280
|
+
if (!isRecord(payload) || payload.x402Version !== 2) return null;
|
|
116281
|
+
return payload;
|
|
116282
|
+
}
|
|
116283
|
+
function isUsableStatus(status) {
|
|
116284
|
+
return status === 402 || status >= 200 && status < 300;
|
|
116285
|
+
}
|
|
116286
|
+
function detectProtocols(response) {
|
|
116287
|
+
const protocols = /* @__PURE__ */ new Set();
|
|
116288
|
+
const directHeader = response.headers.get("x-payment-protocol");
|
|
116289
|
+
if (directHeader) {
|
|
116290
|
+
for (const part of directHeader.split(",")) {
|
|
116291
|
+
const protocol = part.trim().toLowerCase();
|
|
116292
|
+
if (protocol) protocols.add(protocol);
|
|
115746
116293
|
}
|
|
115747
|
-
|
|
115748
|
-
|
|
115749
|
-
|
|
115750
|
-
|
|
115751
|
-
|
|
115752
|
-
|
|
115753
|
-
|
|
115754
|
-
|
|
115755
|
-
|
|
115756
|
-
|
|
115757
|
-
);
|
|
115758
|
-
|
|
115759
|
-
|
|
115760
|
-
|
|
115761
|
-
|
|
115762
|
-
|
|
115763
|
-
|
|
116294
|
+
}
|
|
116295
|
+
const authHeader = response.headers.get("www-authenticate")?.toLowerCase() ?? "";
|
|
116296
|
+
if (authHeader.includes("x402")) protocols.add("x402");
|
|
116297
|
+
if (isMmmEnabled() && authHeader.includes("mpp")) protocols.add("mpp");
|
|
116298
|
+
return [...protocols];
|
|
116299
|
+
}
|
|
116300
|
+
function buildProbeUrl(url3, method, inputBody) {
|
|
116301
|
+
if (!inputBody || method !== "GET" && method !== "HEAD") return url3;
|
|
116302
|
+
const u = new URL(url3);
|
|
116303
|
+
for (const [key, value] of Object.entries(inputBody)) {
|
|
116304
|
+
u.searchParams.set(key, String(value));
|
|
116305
|
+
}
|
|
116306
|
+
return u.toString();
|
|
116307
|
+
}
|
|
116308
|
+
function probeMethod(url3, method, path2, headers, signal, inputBody) {
|
|
116309
|
+
const hasBody = inputBody !== void 0 && method !== "GET" && method !== "HEAD";
|
|
116310
|
+
const probeUrl = buildProbeUrl(url3, method, inputBody);
|
|
116311
|
+
return fetchSafe(probeUrl, {
|
|
116312
|
+
method,
|
|
116313
|
+
headers: {
|
|
116314
|
+
Accept: "application/json, text/plain;q=0.9, */*;q=0.8",
|
|
116315
|
+
...hasBody ? { "Content-Type": "application/json" } : {},
|
|
116316
|
+
...headers
|
|
116317
|
+
},
|
|
116318
|
+
...hasBody ? { body: JSON.stringify(inputBody) } : {},
|
|
116319
|
+
signal
|
|
116320
|
+
}).andThen((response) => {
|
|
116321
|
+
if (!isUsableStatus(response.status)) return ResultAsync.fromSafePromise(Promise.resolve(null));
|
|
116322
|
+
return ResultAsync.fromSafePromise(
|
|
116323
|
+
(async () => {
|
|
116324
|
+
let authHint = response.status === 402 ? "paid" : "unprotected";
|
|
116325
|
+
let paymentRequiredBody;
|
|
116326
|
+
if (response.status === 402) {
|
|
116327
|
+
try {
|
|
116328
|
+
const headerValue = response.headers.get("payment-required");
|
|
116329
|
+
const parsed = headerValue !== null ? parsePaymentRequiredBody2(headerValue) : await parsePaymentRequiredBody(response);
|
|
116330
|
+
if (parsed !== null) {
|
|
116331
|
+
paymentRequiredBody = parsed;
|
|
116332
|
+
authHint = detectAuthHint(paymentRequiredBody);
|
|
116333
|
+
}
|
|
116334
|
+
} catch {
|
|
116335
|
+
}
|
|
116336
|
+
}
|
|
116337
|
+
const protocols = detectProtocols(response);
|
|
116338
|
+
const wwwAuthenticate = response.headers.get("www-authenticate") ?? void 0;
|
|
116339
|
+
return {
|
|
116340
|
+
path: path2,
|
|
116341
|
+
method,
|
|
116342
|
+
authHint,
|
|
116343
|
+
...protocols.length ? { protocols } : {},
|
|
116344
|
+
...paymentRequiredBody !== void 0 ? { paymentRequiredBody } : {},
|
|
116345
|
+
...wwwAuthenticate ? { wwwAuthenticate } : {}
|
|
115764
116346
|
};
|
|
115765
|
-
}
|
|
115766
|
-
|
|
116347
|
+
})()
|
|
116348
|
+
);
|
|
116349
|
+
});
|
|
116350
|
+
}
|
|
116351
|
+
function getProbe(url3, headers, signal, inputBody) {
|
|
116352
|
+
const path2 = normalizePath(new URL(url3).pathname || "/");
|
|
116353
|
+
return ResultAsync.fromSafePromise(
|
|
116354
|
+
Promise.all(
|
|
116355
|
+
[...HTTP_METHODS].map(
|
|
116356
|
+
(method) => probeMethod(url3, method, path2, headers, signal, inputBody).match(
|
|
116357
|
+
(result) => result,
|
|
116358
|
+
() => null
|
|
116359
|
+
)
|
|
116360
|
+
)
|
|
116361
|
+
).then((results) => results.filter((r) => r !== null))
|
|
116362
|
+
);
|
|
116363
|
+
}
|
|
116364
|
+
var TEMPO_DEFAULT_CHAIN_ID = 4217;
|
|
116365
|
+
function parseAuthParams2(segment) {
|
|
116366
|
+
const params = {};
|
|
116367
|
+
const re = /(\w+)=(?:"([^"]*)"|'([^']*)')/g;
|
|
116368
|
+
let match;
|
|
116369
|
+
while ((match = re.exec(segment)) !== null) {
|
|
116370
|
+
params[match[1]] = match[2] ?? match[3] ?? "";
|
|
116371
|
+
}
|
|
116372
|
+
return params;
|
|
116373
|
+
}
|
|
116374
|
+
function extractPaymentOptions4(wwwAuthenticate) {
|
|
116375
|
+
if (!isMmmEnabled() || !wwwAuthenticate) return [];
|
|
116376
|
+
const options = [];
|
|
116377
|
+
for (const segment of wwwAuthenticate.split(/,\s*(?=Payment\s)/i)) {
|
|
116378
|
+
const stripped = segment.replace(/^Payment\s+/i, "").trim();
|
|
116379
|
+
const params = parseAuthParams2(stripped);
|
|
116380
|
+
const paymentMethod = params["method"];
|
|
116381
|
+
const intent = params["intent"];
|
|
116382
|
+
const realm = params["realm"];
|
|
116383
|
+
const description = params["description"];
|
|
116384
|
+
const requestStr = params["request"];
|
|
116385
|
+
if (!paymentMethod || !intent || !realm || !requestStr) continue;
|
|
116386
|
+
let request;
|
|
116387
|
+
try {
|
|
116388
|
+
const parsed = JSON.parse(requestStr);
|
|
116389
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue;
|
|
116390
|
+
request = parsed;
|
|
116391
|
+
} catch {
|
|
115767
116392
|
continue;
|
|
115768
116393
|
}
|
|
115769
|
-
const
|
|
115770
|
-
|
|
115771
|
-
|
|
115772
|
-
|
|
116394
|
+
const asset = typeof request["currency"] === "string" ? request["currency"] : void 0;
|
|
116395
|
+
const amountRaw = request["amount"];
|
|
116396
|
+
const amount2 = typeof amountRaw === "string" ? amountRaw : typeof amountRaw === "number" ? String(amountRaw) : void 0;
|
|
116397
|
+
const decimals2 = typeof request["decimals"] === "number" ? request["decimals"] : void 0;
|
|
116398
|
+
const payTo = typeof request["recipient"] === "string" ? request["recipient"] : void 0;
|
|
116399
|
+
const methodDetails = request["methodDetails"];
|
|
116400
|
+
const chainId2 = methodDetails !== null && typeof methodDetails === "object" && !Array.isArray(methodDetails) && typeof methodDetails["chainId"] === "number" ? methodDetails["chainId"] : TEMPO_DEFAULT_CHAIN_ID;
|
|
116401
|
+
if (!asset || !amount2) continue;
|
|
116402
|
+
options.push({
|
|
116403
|
+
protocol: "mpp",
|
|
116404
|
+
// isMmmEnabled
|
|
116405
|
+
paymentMethod,
|
|
116406
|
+
intent,
|
|
116407
|
+
realm,
|
|
116408
|
+
network: `tempo:${String(chainId2)}`,
|
|
116409
|
+
// isMmmEnabled
|
|
116410
|
+
asset,
|
|
116411
|
+
amount: amount2,
|
|
116412
|
+
...decimals2 != null ? { decimals: decimals2 } : {},
|
|
116413
|
+
...payTo ? { payTo } : {},
|
|
116414
|
+
...description ? { description } : {}
|
|
116415
|
+
});
|
|
116416
|
+
}
|
|
116417
|
+
return options;
|
|
116418
|
+
}
|
|
116419
|
+
function findMatchingOpenApiPath(paths, targetPath) {
|
|
116420
|
+
const exact = paths[targetPath];
|
|
116421
|
+
if (isRecord(exact)) return { matchedPath: targetPath, pathItem: exact };
|
|
116422
|
+
for (const [specPath, entry] of Object.entries(paths)) {
|
|
116423
|
+
if (!isRecord(entry)) continue;
|
|
116424
|
+
const pattern = specPath.replace(/\{[^}]+\}/g, "[^/]+");
|
|
116425
|
+
const regex = new RegExp(`^${pattern}$`);
|
|
116426
|
+
if (regex.test(targetPath)) {
|
|
116427
|
+
return { matchedPath: specPath, pathItem: entry };
|
|
115773
116428
|
}
|
|
115774
116429
|
}
|
|
115775
|
-
|
|
115776
|
-
return failure;
|
|
116430
|
+
return null;
|
|
115777
116431
|
}
|
|
115778
|
-
function resolveRef2(
|
|
116432
|
+
function resolveRef2(document2, ref, seen) {
|
|
115779
116433
|
if (!ref.startsWith("#/")) return void 0;
|
|
115780
116434
|
if (seen.has(ref)) return { $circular: ref };
|
|
115781
116435
|
seen.add(ref);
|
|
115782
116436
|
const parts = ref.slice(2).split("/");
|
|
115783
|
-
let current =
|
|
116437
|
+
let current = document2;
|
|
115784
116438
|
for (const part of parts) {
|
|
115785
|
-
if (current
|
|
115786
|
-
|
|
115787
|
-
|
|
115788
|
-
if (next === void 0) return void 0;
|
|
115789
|
-
current = next;
|
|
115790
|
-
}
|
|
115791
|
-
if (current != null && typeof current === "object" && !Array.isArray(current)) {
|
|
115792
|
-
return resolveRefs(spec, current, seen);
|
|
116439
|
+
if (!isRecord(current)) return void 0;
|
|
116440
|
+
current = current[part];
|
|
116441
|
+
if (current === void 0) return void 0;
|
|
115793
116442
|
}
|
|
116443
|
+
if (isRecord(current)) return resolveRefs(document2, current, seen);
|
|
115794
116444
|
return current;
|
|
115795
116445
|
}
|
|
115796
|
-
function resolveRefs(
|
|
116446
|
+
function resolveRefs(document2, obj, seen, depth = 0) {
|
|
115797
116447
|
if (depth > 4) return obj;
|
|
115798
|
-
const
|
|
116448
|
+
const resolved = {};
|
|
115799
116449
|
for (const [key, value] of Object.entries(obj)) {
|
|
115800
116450
|
if (key === "$ref" && typeof value === "string") {
|
|
115801
|
-
const
|
|
115802
|
-
if (
|
|
115803
|
-
Object.assign(
|
|
116451
|
+
const deref = resolveRef2(document2, value, seen);
|
|
116452
|
+
if (isRecord(deref)) {
|
|
116453
|
+
Object.assign(resolved, deref);
|
|
115804
116454
|
} else {
|
|
115805
|
-
|
|
116455
|
+
resolved[key] = value;
|
|
115806
116456
|
}
|
|
115807
|
-
|
|
115808
|
-
result[key] = resolveRefs(spec, value, seen, depth + 1);
|
|
115809
|
-
} else if (Array.isArray(value)) {
|
|
115810
|
-
result[key] = value.map((item) => {
|
|
115811
|
-
if (item != null && typeof item === "object" && !Array.isArray(item)) {
|
|
115812
|
-
return resolveRefs(spec, item, seen, depth + 1);
|
|
115813
|
-
}
|
|
115814
|
-
return item;
|
|
115815
|
-
});
|
|
115816
|
-
} else {
|
|
115817
|
-
result[key] = value;
|
|
116457
|
+
continue;
|
|
115818
116458
|
}
|
|
115819
|
-
|
|
115820
|
-
|
|
115821
|
-
|
|
115822
|
-
function extractPath(url3, origin) {
|
|
115823
|
-
if (url3.startsWith(origin)) {
|
|
115824
|
-
return url3.slice(origin.length) || "/";
|
|
115825
|
-
}
|
|
115826
|
-
return URL.canParse(url3) ? new URL(url3).pathname : url3;
|
|
115827
|
-
}
|
|
115828
|
-
async function getEndpointSchema(endpointUrl, method) {
|
|
115829
|
-
if (!URL.canParse(endpointUrl)) return null;
|
|
115830
|
-
const origin = new URL(endpointUrl).origin;
|
|
115831
|
-
const result = await fetchOpenApiSpec(origin);
|
|
115832
|
-
if (!result.ok) return null;
|
|
115833
|
-
const spec = result.spec;
|
|
115834
|
-
const paths = spec.paths;
|
|
115835
|
-
if (!paths) return null;
|
|
115836
|
-
const path2 = extractPath(endpointUrl, origin);
|
|
115837
|
-
const httpMethod = (method ?? "post").toLowerCase();
|
|
115838
|
-
let pathEntry = paths[path2];
|
|
115839
|
-
if (!pathEntry) {
|
|
115840
|
-
for (const [specPath, specEntry] of Object.entries(paths)) {
|
|
115841
|
-
if (specEntry == null || typeof specEntry !== "object") continue;
|
|
115842
|
-
const pattern = specPath.replace(/\{[^}]+\}/g, "[^/]+");
|
|
115843
|
-
const regex = new RegExp(`^${pattern}$`);
|
|
115844
|
-
if (regex.test(path2)) {
|
|
115845
|
-
pathEntry = specEntry;
|
|
115846
|
-
break;
|
|
115847
|
-
}
|
|
116459
|
+
if (isRecord(value)) {
|
|
116460
|
+
resolved[key] = resolveRefs(document2, value, seen, depth + 1);
|
|
116461
|
+
continue;
|
|
115848
116462
|
}
|
|
115849
|
-
|
|
115850
|
-
|
|
115851
|
-
|
|
115852
|
-
|
|
115853
|
-
|
|
115854
|
-
const operation = pathEntry[httpMethod];
|
|
115855
|
-
if (!operation) {
|
|
115856
|
-
log.debug(
|
|
115857
|
-
`No OpenAPI operation found for ${httpMethod.toUpperCase()} ${path2}`
|
|
115858
|
-
);
|
|
115859
|
-
return null;
|
|
115860
|
-
}
|
|
115861
|
-
const resolved = resolveRefs(spec, operation, /* @__PURE__ */ new Set());
|
|
115862
|
-
return { path: path2, method: httpMethod, ...resolved };
|
|
115863
|
-
}
|
|
115864
|
-
async function getOriginIndex(origin) {
|
|
115865
|
-
const result = await fetchOpenApiSpec(origin);
|
|
115866
|
-
if (!result.ok) return null;
|
|
115867
|
-
const spec = result.spec;
|
|
115868
|
-
const endpoints = [];
|
|
115869
|
-
for (const [path2, methods] of Object.entries(
|
|
115870
|
-
spec.paths
|
|
115871
|
-
)) {
|
|
115872
|
-
for (const [method, operation] of Object.entries(methods)) {
|
|
115873
|
-
if (typeof operation === "object" && operation !== null) {
|
|
115874
|
-
const op = operation;
|
|
115875
|
-
const paymentInfo = op["x-payment-info"];
|
|
115876
|
-
const entry = {
|
|
115877
|
-
path: path2,
|
|
115878
|
-
method: method.toUpperCase(),
|
|
115879
|
-
summary: op.summary || op.description || ""
|
|
115880
|
-
};
|
|
115881
|
-
if (paymentInfo?.price != null) {
|
|
115882
|
-
entry.price = `$${paymentInfo.price}`;
|
|
115883
|
-
}
|
|
115884
|
-
if (Array.isArray(paymentInfo?.protocols)) {
|
|
115885
|
-
entry.protocols = paymentInfo.protocols;
|
|
115886
|
-
}
|
|
115887
|
-
endpoints.push(entry);
|
|
115888
|
-
}
|
|
116463
|
+
if (Array.isArray(value)) {
|
|
116464
|
+
resolved[key] = value.map(
|
|
116465
|
+
(item) => isRecord(item) ? resolveRefs(document2, item, seen, depth + 1) : item
|
|
116466
|
+
);
|
|
116467
|
+
continue;
|
|
115889
116468
|
}
|
|
116469
|
+
resolved[key] = value;
|
|
115890
116470
|
}
|
|
115891
|
-
return
|
|
116471
|
+
return resolved;
|
|
115892
116472
|
}
|
|
115893
|
-
|
|
115894
|
-
|
|
115895
|
-
|
|
115896
|
-
|
|
115897
|
-
|
|
115898
|
-
"
|
|
115899
|
-
|
|
115900
|
-
|
|
115901
|
-
|
|
115902
|
-
|
|
115903
|
-
|
|
115904
|
-
|
|
115905
|
-
const origin = new URL(endpointUrl).origin;
|
|
115906
|
-
const result = await fetchOpenApiSpec(origin);
|
|
115907
|
-
if (!result.ok) return null;
|
|
115908
|
-
const paths = result.spec.paths;
|
|
115909
|
-
const path2 = extractPath(endpointUrl, origin);
|
|
115910
|
-
let pathEntry = paths[path2];
|
|
115911
|
-
if (!pathEntry) {
|
|
115912
|
-
for (const [specPath, specEntry] of Object.entries(paths)) {
|
|
115913
|
-
if (specEntry == null || typeof specEntry !== "object") continue;
|
|
115914
|
-
const pattern = specPath.replace(/\{[^}]+\}/g, "[^/]+");
|
|
115915
|
-
const regex = new RegExp(`^${pattern}$`);
|
|
115916
|
-
if (regex.test(path2)) {
|
|
115917
|
-
pathEntry = specEntry;
|
|
115918
|
-
break;
|
|
115919
|
-
}
|
|
116473
|
+
function extractRequestBodySchema(operationSchema) {
|
|
116474
|
+
const requestBody = operationSchema.requestBody;
|
|
116475
|
+
if (!isRecord(requestBody)) return void 0;
|
|
116476
|
+
const content = requestBody.content;
|
|
116477
|
+
if (!isRecord(content)) return void 0;
|
|
116478
|
+
const jsonMediaType = content["application/json"];
|
|
116479
|
+
if (isRecord(jsonMediaType) && isRecord(jsonMediaType.schema)) {
|
|
116480
|
+
return jsonMediaType.schema;
|
|
116481
|
+
}
|
|
116482
|
+
for (const mediaType of Object.values(content)) {
|
|
116483
|
+
if (isRecord(mediaType) && isRecord(mediaType.schema)) {
|
|
116484
|
+
return mediaType.schema;
|
|
115920
116485
|
}
|
|
115921
116486
|
}
|
|
115922
|
-
|
|
115923
|
-
return Object.keys(pathEntry).filter((k) => OPENAPI_HTTP_METHODS.has(k)).map((k) => k.toUpperCase());
|
|
116487
|
+
return void 0;
|
|
115924
116488
|
}
|
|
115925
|
-
|
|
115926
|
-
const
|
|
115927
|
-
if (!
|
|
115928
|
-
|
|
115929
|
-
return entries.find((e) => e.path === path2 && e.method === m);
|
|
116489
|
+
function extractParameters(operationSchema) {
|
|
116490
|
+
const params = operationSchema.parameters;
|
|
116491
|
+
if (!Array.isArray(params)) return [];
|
|
116492
|
+
return params.filter((value) => isRecord(value));
|
|
115930
116493
|
}
|
|
115931
|
-
|
|
115932
|
-
|
|
115933
|
-
|
|
115934
|
-
|
|
115935
|
-
|
|
115936
|
-
"POST",
|
|
115937
|
-
"PUT",
|
|
115938
|
-
"DELETE",
|
|
115939
|
-
"PATCH"
|
|
115940
|
-
];
|
|
115941
|
-
function derivePaymentRequirement(protocols, paymentOptions, hasSiwxExtension) {
|
|
115942
|
-
const hasPaymentOptions = paymentOptions.length > 0;
|
|
115943
|
-
const isSiwxOnly = hasSiwxExtension && !hasPaymentOptions;
|
|
115944
|
-
if (isSiwxOnly) {
|
|
115945
|
-
return {
|
|
115946
|
-
requiresPayment: false,
|
|
115947
|
-
protocols: []
|
|
115948
|
-
};
|
|
115949
|
-
}
|
|
116494
|
+
function extractInputSchema(operationSchema) {
|
|
116495
|
+
const requestBody = extractRequestBodySchema(operationSchema);
|
|
116496
|
+
const parameters = extractParameters(operationSchema);
|
|
116497
|
+
if (!requestBody && parameters.length === 0) return void 0;
|
|
116498
|
+
if (requestBody && parameters.length === 0) return requestBody;
|
|
115950
116499
|
return {
|
|
115951
|
-
|
|
115952
|
-
|
|
116500
|
+
...requestBody ? { requestBody } : {},
|
|
116501
|
+
...parameters.length > 0 ? { parameters } : {}
|
|
115953
116502
|
};
|
|
115954
116503
|
}
|
|
115955
|
-
function
|
|
115956
|
-
|
|
115957
|
-
|
|
115958
|
-
|
|
115959
|
-
|
|
115960
|
-
|
|
115961
|
-
|
|
115962
|
-
|
|
115963
|
-
if (hasSiwxSecurity && !hasPaymentInfo && !estimatedPrice) {
|
|
115964
|
-
return false;
|
|
115965
|
-
}
|
|
115966
|
-
return true;
|
|
115967
|
-
}
|
|
115968
|
-
async function checkEndpoint({
|
|
115969
|
-
surface: surface2,
|
|
115970
|
-
url: url3,
|
|
115971
|
-
methods,
|
|
115972
|
-
body,
|
|
115973
|
-
headers = {},
|
|
115974
|
-
includeMethodErrors = false,
|
|
115975
|
-
probeAllMethods = false
|
|
115976
|
-
}) {
|
|
115977
|
-
let methodsToCheck;
|
|
115978
|
-
if (methods) {
|
|
115979
|
-
methodsToCheck = methods;
|
|
115980
|
-
} else if (probeAllMethods) {
|
|
115981
|
-
methodsToCheck = [...SUPPORTED_METHODS];
|
|
115982
|
-
} else {
|
|
115983
|
-
const specMethods = await getSpecMethods(url3);
|
|
115984
|
-
if (specMethods?.length) {
|
|
115985
|
-
methodsToCheck = specMethods.filter(
|
|
115986
|
-
(m) => SUPPORTED_METHODS.includes(m)
|
|
115987
|
-
);
|
|
115988
|
-
} else {
|
|
115989
|
-
methodsToCheck = [...SUPPORTED_METHODS];
|
|
116504
|
+
function parseOperationPrice(operation) {
|
|
116505
|
+
const paymentInfo = operation["x-payment-info"];
|
|
116506
|
+
if (!isRecord(paymentInfo)) return void 0;
|
|
116507
|
+
function toFiniteNumber(value) {
|
|
116508
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
116509
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
116510
|
+
const parsed = Number(value);
|
|
116511
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
115990
116512
|
}
|
|
116513
|
+
return void 0;
|
|
115991
116514
|
}
|
|
115992
|
-
|
|
115993
|
-
|
|
115994
|
-
|
|
115995
|
-
|
|
115996
|
-
|
|
115997
|
-
|
|
115998
|
-
return {
|
|
115999
|
-
url: url3,
|
|
116000
|
-
results: results.filter((r) => r !== null)
|
|
116001
|
-
};
|
|
116515
|
+
const fixed = toFiniteNumber(paymentInfo.price);
|
|
116516
|
+
if (fixed != null) return `$${String(fixed)}`;
|
|
116517
|
+
const min = toFiniteNumber(paymentInfo.minPrice);
|
|
116518
|
+
const max = toFiniteNumber(paymentInfo.maxPrice);
|
|
116519
|
+
if (min != null && max != null) return `$${String(min)}-$${String(max)}`;
|
|
116520
|
+
return void 0;
|
|
116002
116521
|
}
|
|
116003
|
-
|
|
116004
|
-
|
|
116005
|
-
|
|
116006
|
-
|
|
116007
|
-
|
|
116008
|
-
headers,
|
|
116009
|
-
includeMethodErrors
|
|
116010
|
-
}) {
|
|
116011
|
-
const schemaPromise = resultFromPromise(
|
|
116012
|
-
"openapi",
|
|
116013
|
-
surface2,
|
|
116014
|
-
getEndpointSchema(url3, method),
|
|
116015
|
-
(e) => ({
|
|
116016
|
-
cause: "schema_fetch",
|
|
116017
|
-
message: e instanceof Error ? e.message : String(e)
|
|
116018
|
-
})
|
|
116522
|
+
function parseOperationProtocols(operation) {
|
|
116523
|
+
const paymentInfo = operation["x-payment-info"];
|
|
116524
|
+
if (!isRecord(paymentInfo) || !Array.isArray(paymentInfo.protocols)) return void 0;
|
|
116525
|
+
const protocols = paymentInfo.protocols.filter(
|
|
116526
|
+
(protocol) => typeof protocol === "string" && protocol.length > 0 && (protocol !== "mpp" || isMmmEnabled())
|
|
116019
116527
|
);
|
|
116020
|
-
|
|
116021
|
-
|
|
116022
|
-
|
|
116023
|
-
|
|
116024
|
-
|
|
116025
|
-
);
|
|
116026
|
-
const
|
|
116027
|
-
|
|
116028
|
-
|
|
116029
|
-
|
|
116030
|
-
|
|
116031
|
-
|
|
116032
|
-
|
|
116033
|
-
|
|
116034
|
-
|
|
116035
|
-
|
|
116036
|
-
|
|
116037
|
-
|
|
116038
|
-
|
|
116039
|
-
|
|
116040
|
-
|
|
116041
|
-
|
|
116042
|
-
|
|
116043
|
-
|
|
116044
|
-
|
|
116045
|
-
|
|
116046
|
-
|
|
116047
|
-
|
|
116048
|
-
|
|
116049
|
-
|
|
116050
|
-
|
|
116051
|
-
|
|
116052
|
-
|
|
116053
|
-
|
|
116054
|
-
|
|
116055
|
-
|
|
116528
|
+
return protocols.length > 0 ? protocols : void 0;
|
|
116529
|
+
}
|
|
116530
|
+
function getL3ForOpenAPI(openApi, path2, method) {
|
|
116531
|
+
const document2 = openApi.raw;
|
|
116532
|
+
const paths = isRecord(document2.paths) ? document2.paths : void 0;
|
|
116533
|
+
if (!paths) return null;
|
|
116534
|
+
const matched = findMatchingOpenApiPath(paths, path2);
|
|
116535
|
+
if (!matched) return null;
|
|
116536
|
+
const operation = matched.pathItem[method.toLowerCase()];
|
|
116537
|
+
if (!isRecord(operation)) return null;
|
|
116538
|
+
const resolvedOperation = resolveRefs(document2, operation, /* @__PURE__ */ new Set());
|
|
116539
|
+
const summary = typeof resolvedOperation.summary === "string" ? resolvedOperation.summary : typeof resolvedOperation.description === "string" ? resolvedOperation.description : void 0;
|
|
116540
|
+
return {
|
|
116541
|
+
source: "openapi",
|
|
116542
|
+
...summary ? { summary } : {},
|
|
116543
|
+
authMode: inferAuthMode(resolvedOperation) ?? void 0,
|
|
116544
|
+
estimatedPrice: parseOperationPrice(resolvedOperation),
|
|
116545
|
+
protocols: parseOperationProtocols(resolvedOperation),
|
|
116546
|
+
inputSchema: extractInputSchema(resolvedOperation),
|
|
116547
|
+
outputSchema: resolvedOperation
|
|
116548
|
+
};
|
|
116549
|
+
}
|
|
116550
|
+
function getL3ForProbe(probe, path2, method) {
|
|
116551
|
+
const probeResult = probe.find((r) => r.path === path2 && r.method === method);
|
|
116552
|
+
if (!probeResult) return null;
|
|
116553
|
+
const inputSchema = probeResult.paymentRequiredBody ? parseInputSchema(probeResult.paymentRequiredBody) : void 0;
|
|
116554
|
+
const outputSchema = probeResult.paymentRequiredBody ? parseOutputSchema(probeResult.paymentRequiredBody) : void 0;
|
|
116555
|
+
const paymentOptions = [
|
|
116556
|
+
...probeResult.paymentRequiredBody ? extractPaymentOptions3(probeResult.paymentRequiredBody) : [],
|
|
116557
|
+
...isMmmEnabled() ? extractPaymentOptions4(probeResult.wwwAuthenticate) : []
|
|
116558
|
+
// isMmmEnabled
|
|
116559
|
+
];
|
|
116560
|
+
return {
|
|
116561
|
+
source: "probe",
|
|
116562
|
+
authMode: probeResult.authHint,
|
|
116563
|
+
...probeResult.protocols?.length ? { protocols: probeResult.protocols } : {},
|
|
116564
|
+
...inputSchema ? { inputSchema } : {},
|
|
116565
|
+
...outputSchema ? { outputSchema } : {},
|
|
116566
|
+
...paymentOptions.length ? { paymentOptions } : {}
|
|
116567
|
+
};
|
|
116568
|
+
}
|
|
116569
|
+
function getAdvisoriesForOpenAPI(openApi, path2) {
|
|
116570
|
+
return [...HTTP_METHODS].flatMap((method) => {
|
|
116571
|
+
const l3 = getL3ForOpenAPI(openApi, path2, method);
|
|
116572
|
+
return l3 ? [{ method, ...l3 }] : [];
|
|
116573
|
+
});
|
|
116574
|
+
}
|
|
116575
|
+
function getAdvisoriesForProbe(probe, path2) {
|
|
116576
|
+
return [...HTTP_METHODS].flatMap((method) => {
|
|
116577
|
+
const l3 = getL3ForProbe(probe, path2, method);
|
|
116578
|
+
return l3 ? [{ method, ...l3 }] : [];
|
|
116579
|
+
});
|
|
116580
|
+
}
|
|
116581
|
+
async function checkEndpointSchema(options) {
|
|
116582
|
+
const endpoint = new URL(options.url);
|
|
116583
|
+
const origin = normalizeOrigin(endpoint.origin);
|
|
116584
|
+
const path2 = normalizePath(endpoint.pathname || "/");
|
|
116585
|
+
if (options.sampleInputBody !== void 0) {
|
|
116586
|
+
const probeResult2 = await getProbe(
|
|
116587
|
+
options.url,
|
|
116588
|
+
options.headers,
|
|
116589
|
+
options.signal,
|
|
116590
|
+
options.sampleInputBody
|
|
116056
116591
|
);
|
|
116057
|
-
|
|
116058
|
-
method,
|
|
116059
|
-
requiresPayment,
|
|
116060
|
-
statusCode: 402,
|
|
116061
|
-
schema: schema2,
|
|
116062
|
-
...requiresPayment && protocols2 ? { protocols: protocols2 } : {},
|
|
116063
|
-
...estimatedPrice2 ? { estimatedPrice: estimatedPrice2 } : {},
|
|
116064
|
-
...summary2 ? { summary: summary2 } : {}
|
|
116065
|
-
};
|
|
116066
|
-
};
|
|
116067
|
-
if (responseResult.isErr()) {
|
|
116068
|
-
log.debug(`${method} ${url3} probe failed`, responseResult.error);
|
|
116069
|
-
return fallbackToSpec();
|
|
116070
|
-
}
|
|
116071
|
-
const response = responseResult.value;
|
|
116072
|
-
if (!response.ok && response.status !== 402) {
|
|
116073
|
-
if (includeMethodErrors && (response.status === 404 || response.status === 405)) {
|
|
116592
|
+
if (probeResult2.isErr()) {
|
|
116074
116593
|
return {
|
|
116075
|
-
|
|
116076
|
-
|
|
116077
|
-
|
|
116594
|
+
found: false,
|
|
116595
|
+
origin,
|
|
116596
|
+
path: path2,
|
|
116597
|
+
cause: probeResult2.error.cause,
|
|
116598
|
+
message: probeResult2.error.message
|
|
116078
116599
|
};
|
|
116079
116600
|
}
|
|
116080
|
-
|
|
116081
|
-
|
|
116082
|
-
|
|
116083
|
-
return fallbackToSpec();
|
|
116601
|
+
const advisories2 = getAdvisoriesForProbe(probeResult2.value, path2);
|
|
116602
|
+
if (advisories2.length > 0) return { found: true, origin, path: path2, advisories: advisories2 };
|
|
116603
|
+
return { found: false, origin, path: path2, cause: "not_found" };
|
|
116084
116604
|
}
|
|
116085
|
-
|
|
116605
|
+
const openApiResult = await getOpenAPI(origin, options.headers, options.signal);
|
|
116606
|
+
const openApi = openApiResult.isOk() ? openApiResult.value : null;
|
|
116607
|
+
if (openApi) {
|
|
116608
|
+
const advisories2 = getAdvisoriesForOpenAPI(openApi, path2);
|
|
116609
|
+
if (advisories2.length > 0) return { found: true, origin, path: path2, advisories: advisories2 };
|
|
116610
|
+
return { found: false, origin, path: path2, cause: "not_found" };
|
|
116611
|
+
}
|
|
116612
|
+
const probeResult = await getProbe(options.url, options.headers, options.signal);
|
|
116613
|
+
if (probeResult.isErr()) {
|
|
116086
116614
|
return {
|
|
116087
|
-
|
|
116088
|
-
|
|
116089
|
-
|
|
116615
|
+
found: false,
|
|
116616
|
+
origin,
|
|
116617
|
+
path: path2,
|
|
116618
|
+
cause: probeResult.error.cause,
|
|
116619
|
+
message: probeResult.error.message
|
|
116090
116620
|
};
|
|
116091
116621
|
}
|
|
116092
|
-
const
|
|
116093
|
-
|
|
116094
|
-
|
|
116095
|
-
let schema;
|
|
116096
|
-
const endpointSchemaResult = await schemaPromise;
|
|
116097
|
-
if (endpointSchemaResult.isOk() && endpointSchemaResult.value) {
|
|
116098
|
-
schema = endpointSchemaResult.value;
|
|
116099
|
-
} else if (endpointSchemaResult.isErr()) {
|
|
116100
|
-
log.debug(`Failed to fetch OpenAPI schema for: ${url3}`);
|
|
116101
|
-
}
|
|
116102
|
-
if (isMppEnabled() && protocols.includes("mpp")) {
|
|
116103
|
-
for (const challenge2 of parseMppChallenges(response)) {
|
|
116104
|
-
const currency2 = challenge2.request.currency;
|
|
116105
|
-
const amount2 = challenge2.request.amount;
|
|
116106
|
-
const decimals2 = challenge2.request.decimals ?? 6;
|
|
116107
|
-
const recipient = challenge2.request.recipient;
|
|
116108
|
-
const methodDetails = challenge2.request.methodDetails;
|
|
116109
|
-
const chainId2 = methodDetails?.chainId ?? TEMPO_DEFAULT_CHAIN_ID;
|
|
116110
|
-
const network = `tempo:${String(chainId2)}`;
|
|
116111
|
-
const description = challenge2.description ?? schema?.summary;
|
|
116112
|
-
if (amount2 && currency2) {
|
|
116113
|
-
paymentOptions.push({
|
|
116114
|
-
protocol: "mpp",
|
|
116115
|
-
paymentMethod: challenge2.method,
|
|
116116
|
-
intent: challenge2.intent,
|
|
116117
|
-
realm: challenge2.realm,
|
|
116118
|
-
price: tokenStringToNumber(amount2, decimals2),
|
|
116119
|
-
network,
|
|
116120
|
-
asset: currency2,
|
|
116121
|
-
...recipient ? { recipient } : {},
|
|
116122
|
-
...description ? { description } : {}
|
|
116123
|
-
});
|
|
116124
|
-
}
|
|
116125
|
-
}
|
|
116126
|
-
}
|
|
116127
|
-
if (protocols.includes("x402")) {
|
|
116128
|
-
const client = new x402HTTPClient(new x402Client());
|
|
116129
|
-
const paymentRequiredResult = await safeGetPaymentRequired(
|
|
116130
|
-
surface2,
|
|
116131
|
-
client,
|
|
116132
|
-
response
|
|
116133
|
-
);
|
|
116134
|
-
if (paymentRequiredResult.isOk()) {
|
|
116135
|
-
const { resource, extensions, accepts } = paymentRequiredResult.value;
|
|
116136
|
-
hasSiwxExtension = !!extensions && typeof extensions === "object" && "sign-in-with-x" in extensions;
|
|
116137
|
-
if (!schema) {
|
|
116138
|
-
const inputSchema = getInputSchema(extensions);
|
|
116139
|
-
if (inputSchema) schema = inputSchema;
|
|
116140
|
-
}
|
|
116141
|
-
for (const accept of accepts) {
|
|
116142
|
-
paymentOptions.push({
|
|
116143
|
-
protocol: "x402",
|
|
116144
|
-
price: tokenStringToNumber(accept.amount),
|
|
116145
|
-
network: accept.network,
|
|
116146
|
-
asset: accept.asset,
|
|
116147
|
-
...accept.payTo ? { recipient: accept.payTo } : {},
|
|
116148
|
-
...resource.description ? { description: resource.description } : {},
|
|
116149
|
-
...resource.mimeType ? { mimeType: resource.mimeType } : {}
|
|
116150
|
-
});
|
|
116151
|
-
}
|
|
116152
|
-
}
|
|
116153
|
-
}
|
|
116154
|
-
let estimatedPrice;
|
|
116155
|
-
let summary;
|
|
116156
|
-
const indexResult = await resultFromPromise(
|
|
116157
|
-
"openapi",
|
|
116158
|
-
surface2,
|
|
116159
|
-
(async () => {
|
|
116160
|
-
const origin = new URL(url3).origin;
|
|
116161
|
-
const path2 = new URL(url3).pathname || "/";
|
|
116162
|
-
return getIndexEntry(origin, path2, method);
|
|
116163
|
-
})(),
|
|
116164
|
-
(e) => ({
|
|
116165
|
-
cause: "index_lookup",
|
|
116166
|
-
message: e instanceof Error ? e.message : String(e)
|
|
116167
|
-
})
|
|
116168
|
-
);
|
|
116169
|
-
if (indexResult.isOk() && indexResult.value) {
|
|
116170
|
-
if (indexResult.value.price) estimatedPrice = indexResult.value.price;
|
|
116171
|
-
if (indexResult.value.summary) summary = indexResult.value.summary;
|
|
116172
|
-
}
|
|
116173
|
-
return {
|
|
116174
|
-
method,
|
|
116175
|
-
...derivePaymentRequirement(protocols, paymentOptions, hasSiwxExtension),
|
|
116176
|
-
statusCode: response.status,
|
|
116177
|
-
paymentOptions,
|
|
116178
|
-
...schema ? { schema } : {},
|
|
116179
|
-
...estimatedPrice ? { estimatedPrice } : {},
|
|
116180
|
-
...summary ? { summary } : {}
|
|
116181
|
-
};
|
|
116182
|
-
}
|
|
116183
|
-
function parseMppChallenges(response) {
|
|
116184
|
-
const header = response.headers.get("WWW-Authenticate");
|
|
116185
|
-
if (!header) return [];
|
|
116186
|
-
const challenges = [];
|
|
116187
|
-
for (const segment of header.split(/,\s*(?=Payment\s)/i)) {
|
|
116188
|
-
const result = resultFromThrowable(
|
|
116189
|
-
"mpp",
|
|
116190
|
-
"check-endpoint",
|
|
116191
|
-
() => Challenge_exports.deserialize(segment.trim()),
|
|
116192
|
-
(e) => ({
|
|
116193
|
-
cause: "challenge_parse",
|
|
116194
|
-
message: e instanceof Error ? e.message : String(e)
|
|
116195
|
-
})
|
|
116196
|
-
);
|
|
116197
|
-
if (result.isOk()) {
|
|
116198
|
-
challenges.push(result.value);
|
|
116199
|
-
} else {
|
|
116200
|
-
log.debug("Failed to parse MPP challenge segment", result.error.message);
|
|
116201
|
-
}
|
|
116202
|
-
}
|
|
116203
|
-
return challenges;
|
|
116622
|
+
const advisories = getAdvisoriesForProbe(probeResult.value, path2);
|
|
116623
|
+
if (advisories.length > 0) return { found: true, origin, path: path2, advisories };
|
|
116624
|
+
return { found: false, origin, path: path2, cause: "not_found" };
|
|
116204
116625
|
}
|
|
116205
|
-
|
|
116206
|
-
|
|
116207
|
-
|
|
116208
|
-
|
|
116209
|
-
|
|
116210
|
-
|
|
116211
|
-
|
|
116212
|
-
|
|
116213
|
-
...headers
|
|
116214
|
-
}
|
|
116626
|
+
|
|
116627
|
+
// src/shared/operations/check-endpoint.ts
|
|
116628
|
+
async function checkEndpoint(surface2, url3, methods, sampleInputBody, headers) {
|
|
116629
|
+
log.info("Checking endpoint", { surface: surface2, url: url3, methods, hasSampleInputBody: !!sampleInputBody });
|
|
116630
|
+
const result = await checkEndpointSchema({
|
|
116631
|
+
url: url3,
|
|
116632
|
+
sampleInputBody,
|
|
116633
|
+
headers
|
|
116215
116634
|
});
|
|
116635
|
+
if (!result.found) {
|
|
116636
|
+
log.error(`[checkEndpoint failed`, {
|
|
116637
|
+
surface: surface2,
|
|
116638
|
+
url: url3,
|
|
116639
|
+
cause: result.cause,
|
|
116640
|
+
message: result.message
|
|
116641
|
+
});
|
|
116642
|
+
return result;
|
|
116643
|
+
}
|
|
116644
|
+
const advisories = methods?.length ? result.advisories.filter(
|
|
116645
|
+
(a) => methods.includes(a.method)
|
|
116646
|
+
) : result.advisories;
|
|
116647
|
+
return { ...result, advisories };
|
|
116216
116648
|
}
|
|
116217
116649
|
|
|
116218
116650
|
// src/server/tools/check-endpoint.ts
|
|
116219
116651
|
var toolName3 = "check_endpoint_schema";
|
|
116220
|
-
var checkEndpointInputSchema = zod_default.object({
|
|
116221
|
-
url: zod_default.string().describe("The endpoint URL"),
|
|
116222
|
-
method: zod_default.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe(
|
|
116223
|
-
"HTTP method to check. If omitted, all methods are probed in parallel."
|
|
116224
|
-
),
|
|
116225
|
-
body: zod_default.unknown().optional().describe("Request body for POST/PUT/PATCH methods"),
|
|
116226
|
-
headers: zod_default.record(zod_default.string(), zod_default.string()).optional().describe("Additional headers to include").default({})
|
|
116227
|
-
});
|
|
116228
116652
|
var registerCheckEndpointTool = ({
|
|
116229
116653
|
server,
|
|
116230
116654
|
account,
|
|
@@ -116234,8 +116658,24 @@ var registerCheckEndpointTool = ({
|
|
|
116234
116658
|
toolName3,
|
|
116235
116659
|
{
|
|
116236
116660
|
title: "Check Endpoint Schema",
|
|
116237
|
-
description: `
|
|
116238
|
-
|
|
116661
|
+
description: `Returns advisory data for an endpoint: auth mode, pricing, protocols, and input schema.
|
|
116662
|
+
|
|
116663
|
+
Two-phase workflow:
|
|
116664
|
+
1. Call without sample_input_body to get the input schema and advisory pricing from the OpenAPI spec (no live request to the endpoint).
|
|
116665
|
+
2. Once you know what body you intend to send, call again with sample_input_body set to that body. The endpoint will be probed live with that payload and exact paymentOptions (priced for your specific body) are returned in each advisory.
|
|
116666
|
+
|
|
116667
|
+
Checks the OpenAPI spec first, then falls back to a live 402 probe if no spec is found.
|
|
116668
|
+
Use before fetch to understand what an endpoint requires. No payment is made.`,
|
|
116669
|
+
inputSchema: zod_default.object({
|
|
116670
|
+
url: zod_default.string().describe("The endpoint URL"),
|
|
116671
|
+
method: zod_default.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional().describe(
|
|
116672
|
+
"HTTP method to check. If omitted, all methods declared in the spec are returned."
|
|
116673
|
+
),
|
|
116674
|
+
sample_input_body: zod_default.record(zod_default.string(), zod_default.unknown()).optional().describe(
|
|
116675
|
+
"A sample request body you plan to send. When provided, the endpoint is probed live with this payload and exact paymentOptions priced for that body are returned. Use this after phase 1 has given you the input schema."
|
|
116676
|
+
),
|
|
116677
|
+
headers: zod_default.record(zod_default.string(), zod_default.string()).optional().describe("Additional headers to include in the probe request").default({})
|
|
116678
|
+
}),
|
|
116239
116679
|
annotations: {
|
|
116240
116680
|
readOnlyHint: true,
|
|
116241
116681
|
destructiveHint: false,
|
|
@@ -116244,26 +116684,41 @@ var registerCheckEndpointTool = ({
|
|
|
116244
116684
|
}
|
|
116245
116685
|
},
|
|
116246
116686
|
safeHandler(async (input) => {
|
|
116247
|
-
log.info("Querying endpoint", input);
|
|
116248
|
-
const
|
|
116249
|
-
|
|
116250
|
-
|
|
116251
|
-
|
|
116252
|
-
|
|
116253
|
-
|
|
116687
|
+
log.info("Querying endpoint", { url: input.url, method: input.method, hasSampleInputBody: !!input.sample_input_body });
|
|
116688
|
+
const result = await checkEndpoint(
|
|
116689
|
+
toolName3,
|
|
116690
|
+
input.url,
|
|
116691
|
+
input.method ? [input.method] : void 0,
|
|
116692
|
+
input.sample_input_body,
|
|
116693
|
+
{
|
|
116254
116694
|
...input.headers,
|
|
116255
116695
|
"X-Wallet-Address": account.address,
|
|
116256
116696
|
...sessionId ? { "X-Session-ID": sessionId } : {}
|
|
116257
|
-
}
|
|
116258
|
-
|
|
116259
|
-
|
|
116260
|
-
|
|
116697
|
+
}
|
|
116698
|
+
);
|
|
116699
|
+
if (!result.found) {
|
|
116700
|
+
log.error("[checkEndpoint] failed", {
|
|
116701
|
+
surface: toolName3,
|
|
116702
|
+
url: input.url,
|
|
116703
|
+
cause: result.cause,
|
|
116704
|
+
message: result.message
|
|
116705
|
+
});
|
|
116261
116706
|
return mcpSuccessJson({
|
|
116262
|
-
message: "No
|
|
116263
|
-
url:
|
|
116707
|
+
message: "No endpoint schema found for this URL.",
|
|
116708
|
+
url: input.url
|
|
116264
116709
|
});
|
|
116265
116710
|
}
|
|
116266
|
-
|
|
116711
|
+
if (result.advisories.length === 0) {
|
|
116712
|
+
return mcpSuccessJson({
|
|
116713
|
+
message: "No endpoint schema found for this URL.",
|
|
116714
|
+
url: input.url
|
|
116715
|
+
});
|
|
116716
|
+
}
|
|
116717
|
+
const results = result.advisories.map((a) => ({
|
|
116718
|
+
...a,
|
|
116719
|
+
requiresPayment: a.authMode === "paid" || a.authMode === "apiKey+paid"
|
|
116720
|
+
}));
|
|
116721
|
+
return mcpSuccessJson(toJsonObject({ url: input.url, results }));
|
|
116267
116722
|
})
|
|
116268
116723
|
);
|
|
116269
116724
|
};
|
|
@@ -116532,69 +116987,23 @@ var ORIGINS = [
|
|
|
116532
116987
|
|
|
116533
116988
|
// src/shared/operations/discover.ts
|
|
116534
116989
|
init_cjs_shims();
|
|
116535
|
-
async function
|
|
116536
|
-
const
|
|
116537
|
-
|
|
116538
|
-
|
|
116539
|
-
|
|
116540
|
-
|
|
116541
|
-
|
|
116542
|
-
|
|
116543
|
-
|
|
116544
|
-
|
|
116545
|
-
|
|
116546
|
-
|
|
116547
|
-
return parseResult.value.data;
|
|
116548
|
-
}
|
|
116549
|
-
async function discoverResources(surface2, url3) {
|
|
116550
|
-
if (!/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(url3)) {
|
|
116551
|
-
url3 = `https://${url3}`;
|
|
116552
|
-
}
|
|
116553
|
-
const origin = URL.canParse(url3) ? new URL(url3).origin : url3;
|
|
116554
|
-
log.info(`Discovering resources for origin: ${origin}`);
|
|
116555
|
-
const [specResult, instructions] = await Promise.all([
|
|
116556
|
-
fetchOpenApiSpec(origin),
|
|
116557
|
-
fetchLlmsTxt(surface2, origin)
|
|
116558
|
-
]);
|
|
116559
|
-
if (!specResult.ok) {
|
|
116560
|
-
log.debug(`No OpenAPI spec found for ${origin}: ${specResult.cause}`);
|
|
116561
|
-
return {
|
|
116562
|
-
found: false,
|
|
116563
|
-
cause: specResult.cause,
|
|
116564
|
-
..."message" in specResult ? { message: specResult.message } : {}
|
|
116565
|
-
};
|
|
116566
|
-
}
|
|
116567
|
-
const spec = specResult.spec;
|
|
116568
|
-
const endpoints = await getOriginIndex(origin);
|
|
116569
|
-
if (!endpoints || endpoints.length === 0) {
|
|
116570
|
-
log.debug(`OpenAPI spec found for ${origin} but no endpoints extracted`);
|
|
116571
|
-
return { found: false, cause: "not_found" };
|
|
116572
|
-
}
|
|
116573
|
-
log.info(`Found ${endpoints.length} endpoints for: ${origin}`);
|
|
116574
|
-
const rawInfo = spec.info;
|
|
116575
|
-
const info = rawInfo && typeof rawInfo.title === "string" ? {
|
|
116576
|
-
title: rawInfo.title,
|
|
116577
|
-
...typeof rawInfo.version === "string" ? { version: rawInfo.version } : {},
|
|
116578
|
-
...typeof rawInfo.description === "string" ? { description: rawInfo.description } : {}
|
|
116579
|
-
} : void 0;
|
|
116580
|
-
return {
|
|
116581
|
-
found: true,
|
|
116582
|
-
origin,
|
|
116583
|
-
source: "openapi",
|
|
116584
|
-
...info ? { info } : {},
|
|
116585
|
-
endpoints: endpoints.map(({ path: path2, method, summary, price, protocols }) => ({
|
|
116586
|
-
path: path2,
|
|
116587
|
-
method,
|
|
116588
|
-
summary,
|
|
116589
|
-
...price ? { price } : {},
|
|
116590
|
-
...protocols ? { protocols } : {}
|
|
116591
|
-
})),
|
|
116592
|
-
...instructions ? { instructions } : {}
|
|
116593
|
-
};
|
|
116990
|
+
async function discoverResources(surface2, url3, options = {}) {
|
|
116991
|
+
const guidance = options.includeGuidance === true ? GuidanceMode.Always : options.includeGuidance === false ? GuidanceMode.Never : GuidanceMode.Auto;
|
|
116992
|
+
const result = await discoverOriginSchema({ target: url3, guidance });
|
|
116993
|
+
if (!result.found) {
|
|
116994
|
+
log.error(`[discoverResources failed`, {
|
|
116995
|
+
surface: surface2,
|
|
116996
|
+
url: url3,
|
|
116997
|
+
cause: result.cause,
|
|
116998
|
+
message: result.message
|
|
116999
|
+
});
|
|
117000
|
+
}
|
|
117001
|
+
return result;
|
|
116594
117002
|
}
|
|
116595
117003
|
|
|
116596
117004
|
// src/server/tools/discover-resources.ts
|
|
116597
117005
|
var toolName5 = "discover_api_endpoints";
|
|
117006
|
+
var OPENAPI_TRIED_PATHS = "/openapi.json, /.well-known/openapi.json";
|
|
116598
117007
|
function registerDiscoveryTools(server) {
|
|
116599
117008
|
server.registerTool(
|
|
116600
117009
|
toolName5,
|
|
@@ -116602,6 +117011,8 @@ function registerDiscoveryTools(server) {
|
|
|
116602
117011
|
title: "Discover API Endpoints",
|
|
116603
117012
|
description: `Find payment-protected resources on an origin. Returns a list of resource URLs.
|
|
116604
117013
|
Use check_endpoint_schema separately to get detailed pricing/schema info for specific resources.
|
|
117014
|
+
Guidance contract: responses always include guidanceAvailable. guidance is auto-included when compact.
|
|
117015
|
+
Use include_guidance=true to force-include larger guidance when needed.
|
|
116605
117016
|
Known default origins with resource packs. Discover if more needed:
|
|
116606
117017
|
- ${"https://stableenrich.dev" /* StableEnrich */} ->
|
|
116607
117018
|
People + Org search
|
|
@@ -116622,6 +117033,9 @@ function registerDiscoveryTools(server) {
|
|
|
116622
117033
|
inputSchema: external_exports3.object({
|
|
116623
117034
|
url: external_exports3.string().describe(
|
|
116624
117035
|
"The origin URL or any URL on the origin to discover resources from"
|
|
117036
|
+
),
|
|
117037
|
+
include_guidance: external_exports3.boolean().optional().describe(
|
|
117038
|
+
"Guidance override: true=always include llms.txt, false=never include, omitted=auto by threshold"
|
|
116625
117039
|
)
|
|
116626
117040
|
}),
|
|
116627
117041
|
annotations: {
|
|
@@ -116631,7 +117045,7 @@ function registerDiscoveryTools(server) {
|
|
|
116631
117045
|
openWorldHint: true
|
|
116632
117046
|
}
|
|
116633
117047
|
},
|
|
116634
|
-
safeHandler(async ({ url: url3 }) => {
|
|
117048
|
+
safeHandler(async ({ url: url3, include_guidance }) => {
|
|
116635
117049
|
if (!URL.canParse(url3)) {
|
|
116636
117050
|
return mcpErrorJson({
|
|
116637
117051
|
error: "Invalid URL",
|
|
@@ -116643,7 +117057,9 @@ function registerDiscoveryTools(server) {
|
|
|
116643
117057
|
const discoverResult = await resultFromPromise(
|
|
116644
117058
|
"discover",
|
|
116645
117059
|
toolName5,
|
|
116646
|
-
discoverResources(toolName5, url3
|
|
117060
|
+
discoverResources(toolName5, url3, {
|
|
117061
|
+
includeGuidance: include_guidance
|
|
117062
|
+
}),
|
|
116647
117063
|
(e) => ({
|
|
116648
117064
|
cause: "discover",
|
|
116649
117065
|
message: e instanceof Error ? e.message : String(e)
|
|
@@ -116658,19 +117074,20 @@ function registerDiscoveryTools(server) {
|
|
|
116658
117074
|
found: true,
|
|
116659
117075
|
origin: result.origin,
|
|
116660
117076
|
...result.info ? { info: result.info } : {},
|
|
117077
|
+
guidanceAvailable: result.guidanceAvailable,
|
|
117078
|
+
...result.guidanceTokens != null ? { guidanceTokens: result.guidanceTokens } : {},
|
|
117079
|
+
...result.guidance ? { guidance: result.guidance } : {},
|
|
116661
117080
|
endpoints: result.endpoints.map(
|
|
116662
117081
|
(e) => ({ ...e })
|
|
116663
|
-
)
|
|
116664
|
-
...result.instructions ? { instructions: result.instructions } : {}
|
|
117082
|
+
)
|
|
116665
117083
|
});
|
|
116666
117084
|
}
|
|
116667
117085
|
const origin = URL.canParse(url3) ? new URL(url3).origin : url3;
|
|
116668
|
-
const tried = OPENAPI_SPEC_PATHS.join(", ");
|
|
116669
117086
|
if (result.cause === "not_found") {
|
|
116670
117087
|
return mcpSuccessJson({
|
|
116671
117088
|
found: false,
|
|
116672
117089
|
origin,
|
|
116673
|
-
error: `No OpenAPI spec found. Tried: ${
|
|
117090
|
+
error: `No OpenAPI spec found. Tried: ${OPENAPI_TRIED_PATHS}`
|
|
116674
117091
|
});
|
|
116675
117092
|
}
|
|
116676
117093
|
return mcpSuccessJson({
|
|
@@ -116678,7 +117095,7 @@ function registerDiscoveryTools(server) {
|
|
|
116678
117095
|
origin,
|
|
116679
117096
|
cause: result.cause,
|
|
116680
117097
|
error: result.message ?? `Failed to fetch OpenAPI spec (${result.cause})`,
|
|
116681
|
-
hint: result.cause === "timeout" ? "The server may be slow or unreachable. Try again later." : result.cause === "network" ? "Could not reach the server. Check the network connection and try again." : `The server returned an unparseable response. Tried: ${
|
|
117098
|
+
hint: result.cause === "timeout" ? "The server may be slow or unreachable. Try again later." : result.cause === "network" ? "Could not reach the server. Check the network connection and try again." : `The server returned an unparseable response. Tried: ${OPENAPI_TRIED_PATHS}`
|
|
116682
117099
|
});
|
|
116683
117100
|
})
|
|
116684
117101
|
);
|
|
@@ -117166,7 +117583,7 @@ var import_path3 = require("path");
|
|
|
117166
117583
|
var import_url2 = require("url");
|
|
117167
117584
|
function getVersion3() {
|
|
117168
117585
|
if (true) {
|
|
117169
|
-
return "0.
|
|
117586
|
+
return "0.7.1";
|
|
117170
117587
|
}
|
|
117171
117588
|
const __dirname3 = (0, import_path3.dirname)((0, import_url2.fileURLToPath)(importMetaUrl));
|
|
117172
117589
|
const pkg = JSON.parse(
|