@agentcash/discovery 1.6.2 → 1.6.3

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/index.js CHANGED
@@ -13785,8 +13785,8 @@ var FixedPriceSchema = external_exports.object({
13785
13785
  var DynamicPriceSchema = external_exports.object({
13786
13786
  currency: Iso4217Schema,
13787
13787
  mode: external_exports.literal("dynamic"),
13788
- min: external_exports.string(),
13789
- max: external_exports.string()
13788
+ min: external_exports.string().optional(),
13789
+ max: external_exports.string().optional()
13790
13790
  });
13791
13791
  var PriceSchema = external_exports.union([FixedPriceSchema, DynamicPriceSchema]);
13792
13792
  var X402ProtocolSchema = external_exports.object({
@@ -13885,7 +13885,12 @@ function normalizeLegacy(raw) {
13885
13885
  function formatPrice(price) {
13886
13886
  const sym = price.currency ?? "USD";
13887
13887
  if (price.mode === "fixed") return `${price.amount} ${sym}`;
13888
- return `${price.min}-${price.max} ${sym}`;
13888
+ if (price.min !== void 0 && price.max !== void 0) {
13889
+ return `${price.min}-${price.max} ${sym}`;
13890
+ }
13891
+ if (price.min !== void 0) return `>=${price.min} ${sym}`;
13892
+ if (price.max !== void 0) return `<=${price.max} ${sym}`;
13893
+ return `dynamic ${sym}`;
13889
13894
  }
13890
13895
  function extractProtocolNames(protocols) {
13891
13896
  return protocols.map((p) => {
@@ -13937,10 +13942,13 @@ var OpenApiOperationSchema = external_exports.object({
13937
13942
  description: external_exports.string().optional(),
13938
13943
  tags: external_exports.array(external_exports.string()).optional(),
13939
13944
  security: external_exports.array(external_exports.record(external_exports.string(), external_exports.array(external_exports.string()))).optional(),
13945
+ // `in` / `name` are spec-required, but a single malformed parameter must not
13946
+ // abort the whole spec — keep them optional so discovery is resilient to
13947
+ // non-conformant OpenAPI documents in the wild.
13940
13948
  parameters: external_exports.array(
13941
13949
  external_exports.object({
13942
- in: external_exports.string(),
13943
- name: external_exports.string(),
13950
+ in: external_exports.string().optional(),
13951
+ name: external_exports.string().optional(),
13944
13952
  schema: external_exports.unknown().optional(),
13945
13953
  required: external_exports.boolean().optional()
13946
13954
  })
@@ -13950,7 +13958,8 @@ var OpenApiOperationSchema = external_exports.object({
13950
13958
  content: external_exports.record(external_exports.string(), external_exports.object({ schema: external_exports.unknown().optional() }))
13951
13959
  }).optional(),
13952
13960
  responses: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
13953
- "x-payment-info": OpenApiPaymentInfoSchema.optional()
13961
+ // Permissive: vendor extension shape is validated at runtime, never at parse time.
13962
+ "x-payment-info": external_exports.unknown().optional()
13954
13963
  });
13955
13964
  var OpenApiPathItemSchema = external_exports.object({
13956
13965
  get: OpenApiOperationSchema.optional(),
@@ -14094,20 +14103,27 @@ function fetchSafe(url2, init) {
14094
14103
  }
14095
14104
 
14096
14105
  // src/core/source/openapi/index.ts
14097
- function resolvePricingHint(p) {
14098
- const raw = p;
14099
- const info = resolvePaymentInfo(raw);
14106
+ function toRecord(raw) {
14107
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return void 0;
14108
+ return raw;
14109
+ }
14110
+ function resolvePricingHint(raw) {
14111
+ const record2 = toRecord(raw);
14112
+ if (!record2) return void 0;
14113
+ const info = resolvePaymentInfo(record2);
14100
14114
  if (!info) return void 0;
14101
14115
  return {
14102
14116
  pricingMode: info.price.mode,
14103
14117
  ...info.price.mode === "fixed" ? { price: info.price.amount } : {},
14104
- ...info.price.mode === "dynamic" ? { minPrice: info.price.min, maxPrice: info.price.max } : {},
14118
+ ...info.price.mode === "dynamic" && info.price.min !== void 0 ? { minPrice: info.price.min } : {},
14119
+ ...info.price.mode === "dynamic" && info.price.max !== void 0 ? { maxPrice: info.price.max } : {},
14105
14120
  ...info.price.currency ? { currency: info.price.currency } : {}
14106
14121
  };
14107
14122
  }
14108
- function resolveProtocols(p) {
14109
- const raw = p;
14110
- const info = resolvePaymentInfo(raw);
14123
+ function resolveProtocols(raw) {
14124
+ const record2 = toRecord(raw);
14125
+ if (!record2) return [];
14126
+ const info = resolvePaymentInfo(record2);
14111
14127
  if (!info) return [];
14112
14128
  return extractProtocolNames(info.protocols);
14113
14129
  }
@@ -14120,8 +14136,8 @@ var OpenApiParsedSchema = OpenApiDocSchema.transform((doc) => {
14120
14136
  if (!operation) continue;
14121
14137
  const authMode = inferAuthMode(operation, doc.security, doc.components?.securitySchemes) ?? void 0;
14122
14138
  const p = operation["x-payment-info"];
14123
- const protocols = resolveProtocols(p ?? {});
14124
- const pricing = (authMode === "paid" || authMode === "apiKey+paid") && p ? resolvePricingHint(p) : void 0;
14139
+ const protocols = resolveProtocols(p);
14140
+ const pricing = (authMode === "paid" || authMode === "apiKey+paid") && p !== void 0 ? resolvePricingHint(p) : void 0;
14125
14141
  const summary = operation.summary ?? operation.description;
14126
14142
  routes.push({
14127
14143
  path: normalizePath(serverBasePath + rawPath),
@@ -14362,28 +14378,29 @@ function getWellKnown(origin, headers, signal) {
14362
14378
  // src/core/layers/l2.ts
14363
14379
  function formatPrice2(pricing) {
14364
14380
  const sym = pricing.currency ?? "USD";
14365
- if (pricing.pricingMode === "fixed") return `${pricing.price} ${sym}`;
14381
+ if (pricing.pricingMode === "fixed" && pricing.price) return `${pricing.price} ${sym}`;
14366
14382
  if (pricing.pricingMode === "dynamic") {
14367
14383
  if (pricing.minPrice && pricing.maxPrice)
14368
14384
  return `${pricing.minPrice}-${pricing.maxPrice} ${sym}`;
14369
14385
  if (pricing.maxPrice) return `up to ${pricing.maxPrice} ${sym}`;
14370
- return "dynamic";
14386
+ if (pricing.minPrice) return `from ${pricing.minPrice} ${sym}`;
14371
14387
  }
14372
- return `unknown pricing mode: ${pricing.pricingMode}`;
14388
+ return void 0;
14373
14389
  }
14374
14390
  function checkL2ForOpenAPI(openApi) {
14375
- const routes = openApi.routes.map((route) => ({
14376
- path: route.path,
14377
- method: route.method,
14378
- summary: route.summary ?? `${route.method} ${route.path}`,
14379
- ...route.authMode ? { authMode: route.authMode } : {},
14380
- ...route.pricing ? {
14381
- price: formatPrice2(route.pricing),
14382
- pricingMode: route.pricing.pricingMode,
14383
- ...route.pricing.currency ? { currency: route.pricing.currency } : {}
14384
- } : {},
14385
- ...route.protocols?.length ? { protocols: route.protocols } : {}
14386
- }));
14391
+ const routes = openApi.routes.map((route) => {
14392
+ const priceHint = route.pricing ? formatPrice2(route.pricing) : void 0;
14393
+ return {
14394
+ path: route.path,
14395
+ method: route.method,
14396
+ summary: route.summary ?? `${route.method} ${route.path}`,
14397
+ ...route.authMode ? { authMode: route.authMode } : {},
14398
+ ...priceHint ? { price: priceHint } : {},
14399
+ ...route.pricing?.pricingMode ? { pricingMode: route.pricing.pricingMode } : {},
14400
+ ...route.pricing?.currency ? { currency: route.pricing.currency } : {},
14401
+ ...route.protocols?.length ? { protocols: route.protocols } : {}
14402
+ };
14403
+ });
14387
14404
  return {
14388
14405
  ...openApi.info.title ? { title: openApi.info.title } : {},
14389
14406
  ...openApi.info.description ? { description: openApi.info.description } : {},
@@ -15440,6 +15457,7 @@ var AUDIT_CODES = {
15440
15457
  L2_NO_PAID_ROUTES: "L2_NO_PAID_ROUTES",
15441
15458
  L2_PRICE_MISSING_ON_PAID: "L2_PRICE_MISSING_ON_PAID",
15442
15459
  L2_PRICING_MODE_UNKNOWN: "L2_PRICING_MODE_UNKNOWN",
15460
+ L2_DYNAMIC_PRICE_INCOMPLETE: "L2_DYNAMIC_PRICE_INCOMPLETE",
15443
15461
  L2_CURRENCY_INVALID: "L2_CURRENCY_INVALID",
15444
15462
  L2_PAYMENT_INFO_LEGACY: "L2_PAYMENT_INFO_LEGACY",
15445
15463
  L2_PROTOCOLS_MISSING_ON_PAID: "L2_PROTOCOLS_MISSING_ON_PAID",
@@ -16128,7 +16146,15 @@ function getWarningsForL2(l2) {
16128
16146
  });
16129
16147
  }
16130
16148
  if (route.authMode === "paid") {
16131
- if (!route.price) {
16149
+ if (route.pricingMode === "dynamic" && !route.price) {
16150
+ warnings.push({
16151
+ code: AUDIT_CODES.L2_DYNAMIC_PRICE_INCOMPLETE,
16152
+ severity: "warn",
16153
+ message: `Paid route ${loc} declares dynamic pricing but no min/max bounds.`,
16154
+ hint: "Add x-payment-info.price.min and .price.max so agents can budget before calling. Without bounds, agents have no safe upper limit to pre-authorize.",
16155
+ path: route.path
16156
+ });
16157
+ } else if (!route.price) {
16132
16158
  warnings.push({
16133
16159
  code: AUDIT_CODES.L2_PRICE_MISSING_ON_PAID,
16134
16160
  severity: "warn",
package/dist/schemas.cjs CHANGED
@@ -13809,8 +13809,8 @@ var FixedPriceSchema = external_exports.object({
13809
13809
  var DynamicPriceSchema = external_exports.object({
13810
13810
  currency: Iso4217Schema,
13811
13811
  mode: external_exports.literal("dynamic"),
13812
- min: external_exports.string(),
13813
- max: external_exports.string()
13812
+ min: external_exports.string().optional(),
13813
+ max: external_exports.string().optional()
13814
13814
  });
13815
13815
  var PriceSchema = external_exports.union([FixedPriceSchema, DynamicPriceSchema]);
13816
13816
  var X402ProtocolSchema = external_exports.object({
@@ -13857,10 +13857,13 @@ var OpenApiOperationSchema = external_exports.object({
13857
13857
  description: external_exports.string().optional(),
13858
13858
  tags: external_exports.array(external_exports.string()).optional(),
13859
13859
  security: external_exports.array(external_exports.record(external_exports.string(), external_exports.array(external_exports.string()))).optional(),
13860
+ // `in` / `name` are spec-required, but a single malformed parameter must not
13861
+ // abort the whole spec — keep them optional so discovery is resilient to
13862
+ // non-conformant OpenAPI documents in the wild.
13860
13863
  parameters: external_exports.array(
13861
13864
  external_exports.object({
13862
- in: external_exports.string(),
13863
- name: external_exports.string(),
13865
+ in: external_exports.string().optional(),
13866
+ name: external_exports.string().optional(),
13864
13867
  schema: external_exports.unknown().optional(),
13865
13868
  required: external_exports.boolean().optional()
13866
13869
  })
@@ -13870,7 +13873,8 @@ var OpenApiOperationSchema = external_exports.object({
13870
13873
  content: external_exports.record(external_exports.string(), external_exports.object({ schema: external_exports.unknown().optional() }))
13871
13874
  }).optional(),
13872
13875
  responses: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
13873
- "x-payment-info": OpenApiPaymentInfoSchema.optional()
13876
+ // Permissive: vendor extension shape is validated at runtime, never at parse time.
13877
+ "x-payment-info": external_exports.unknown().optional()
13874
13878
  });
13875
13879
  var OpenApiPathItemSchema = external_exports.object({
13876
13880
  get: OpenApiOperationSchema.optional(),