@agentcash/router 0.7.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +46 -27
- package/dist/index.d.cts +20 -31
- package/dist/index.d.ts +20 -31
- package/dist/index.js +46 -27
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1456,7 +1456,15 @@ function createRedisEntitlementStore(client, options) {
|
|
|
1456
1456
|
|
|
1457
1457
|
// src/discovery/well-known.ts
|
|
1458
1458
|
var import_server3 = require("next/server");
|
|
1459
|
-
|
|
1459
|
+
|
|
1460
|
+
// src/discovery/utils/guidance.ts
|
|
1461
|
+
async function resolveGuidance(discovery) {
|
|
1462
|
+
if (typeof discovery.guidance === "function") return discovery.guidance();
|
|
1463
|
+
return discovery.guidance;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// src/discovery/well-known.ts
|
|
1467
|
+
function createWellKnownHandler(registry, baseUrl, pricesKeys, discovery) {
|
|
1460
1468
|
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
1461
1469
|
let validated = false;
|
|
1462
1470
|
return async (_request) => {
|
|
@@ -1466,19 +1474,14 @@ function createWellKnownHandler(registry, baseUrl, pricesKeys, options = {}) {
|
|
|
1466
1474
|
}
|
|
1467
1475
|
const x402Set = /* @__PURE__ */ new Set();
|
|
1468
1476
|
const mppSet = /* @__PURE__ */ new Set();
|
|
1469
|
-
const methodHints =
|
|
1477
|
+
const methodHints = discovery.methodHints ?? "non-default";
|
|
1470
1478
|
for (const [key, entry] of registry.entries()) {
|
|
1471
1479
|
const url = `${normalizedBase}/api/${entry.path ?? key}`;
|
|
1472
1480
|
const resource = toDiscoveryResource(entry.method, url, methodHints);
|
|
1473
1481
|
if (entry.authMode !== "unprotected") x402Set.add(resource);
|
|
1474
1482
|
if (entry.protocols.includes("mpp")) mppSet.add(resource);
|
|
1475
1483
|
}
|
|
1476
|
-
|
|
1477
|
-
if (typeof options.instructions === "function") {
|
|
1478
|
-
instructions = await options.instructions();
|
|
1479
|
-
} else if (typeof options.instructions === "string") {
|
|
1480
|
-
instructions = options.instructions;
|
|
1481
|
-
}
|
|
1484
|
+
const instructions = await resolveGuidance(discovery);
|
|
1482
1485
|
const body = {
|
|
1483
1486
|
version: 1,
|
|
1484
1487
|
resources: Array.from(x402Set)
|
|
@@ -1487,11 +1490,11 @@ function createWellKnownHandler(registry, baseUrl, pricesKeys, options = {}) {
|
|
|
1487
1490
|
if (mppResources.length > 0) {
|
|
1488
1491
|
body.mppResources = mppResources;
|
|
1489
1492
|
}
|
|
1490
|
-
if (
|
|
1491
|
-
body.description =
|
|
1493
|
+
if (discovery.description) {
|
|
1494
|
+
body.description = discovery.description;
|
|
1492
1495
|
}
|
|
1493
|
-
if (
|
|
1494
|
-
body.ownershipProofs =
|
|
1496
|
+
if (discovery.ownershipProofs) {
|
|
1497
|
+
body.ownershipProofs = discovery.ownershipProofs;
|
|
1495
1498
|
}
|
|
1496
1499
|
if (instructions) {
|
|
1497
1500
|
body.instructions = instructions;
|
|
@@ -1514,7 +1517,7 @@ function toDiscoveryResource(method, url, mode) {
|
|
|
1514
1517
|
|
|
1515
1518
|
// src/discovery/openapi.ts
|
|
1516
1519
|
var import_server4 = require("next/server");
|
|
1517
|
-
function createOpenAPIHandler(registry, baseUrl, pricesKeys,
|
|
1520
|
+
function createOpenAPIHandler(registry, baseUrl, pricesKeys, discovery) {
|
|
1518
1521
|
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
1519
1522
|
let cached = null;
|
|
1520
1523
|
let validated = false;
|
|
@@ -1555,21 +1558,20 @@ function createOpenAPIHandler(registry, baseUrl, pricesKeys, options) {
|
|
|
1555
1558
|
};
|
|
1556
1559
|
}
|
|
1557
1560
|
const discoveryMetadata = {};
|
|
1558
|
-
if (
|
|
1559
|
-
discoveryMetadata.ownershipProofs =
|
|
1560
|
-
}
|
|
1561
|
-
if (options.llmsTxtUrl) {
|
|
1562
|
-
discoveryMetadata.llmsTxtUrl = options.llmsTxtUrl;
|
|
1561
|
+
if (discovery.ownershipProofs && discovery.ownershipProofs.length > 0) {
|
|
1562
|
+
discoveryMetadata.ownershipProofs = discovery.ownershipProofs;
|
|
1563
1563
|
}
|
|
1564
|
+
const guidance = await resolveGuidance(discovery);
|
|
1564
1565
|
const openApiDocument = {
|
|
1565
1566
|
openapi: "3.1.0",
|
|
1566
1567
|
info: {
|
|
1567
|
-
title:
|
|
1568
|
-
description:
|
|
1569
|
-
version:
|
|
1570
|
-
|
|
1568
|
+
title: discovery.title,
|
|
1569
|
+
description: discovery.description,
|
|
1570
|
+
version: discovery.version,
|
|
1571
|
+
guidance,
|
|
1572
|
+
...discovery.contact && { contact: discovery.contact }
|
|
1571
1573
|
},
|
|
1572
|
-
servers: [{ url: (
|
|
1574
|
+
servers: [{ url: (discovery.serverUrl ?? normalizedBase).replace(/\/+$/, "") }],
|
|
1573
1575
|
tags: Array.from(tagSet).sort().map((name) => ({ name })),
|
|
1574
1576
|
...Object.keys(securitySchemes).length > 0 ? {
|
|
1575
1577
|
components: {
|
|
@@ -1689,6 +1691,20 @@ function buildPricingInfo(entry) {
|
|
|
1689
1691
|
return void 0;
|
|
1690
1692
|
}
|
|
1691
1693
|
|
|
1694
|
+
// src/discovery/llms-txt.ts
|
|
1695
|
+
var import_server5 = require("next/server");
|
|
1696
|
+
function createLlmsTxtHandler(discovery) {
|
|
1697
|
+
return async (_request) => {
|
|
1698
|
+
const guidance = await resolveGuidance(discovery) ?? "";
|
|
1699
|
+
return new import_server5.NextResponse(guidance, {
|
|
1700
|
+
headers: {
|
|
1701
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
1702
|
+
"Access-Control-Allow-Origin": "*"
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1692
1708
|
// src/index.ts
|
|
1693
1709
|
function createRouter(config) {
|
|
1694
1710
|
const registry = new RouteRegistry();
|
|
@@ -1817,11 +1833,14 @@ function createRouter(config) {
|
|
|
1817
1833
|
}
|
|
1818
1834
|
return builder;
|
|
1819
1835
|
},
|
|
1820
|
-
wellKnown(
|
|
1821
|
-
return createWellKnownHandler(registry, resolvedBaseUrl, pricesKeys,
|
|
1836
|
+
wellKnown() {
|
|
1837
|
+
return createWellKnownHandler(registry, resolvedBaseUrl, pricesKeys, config.discovery);
|
|
1838
|
+
},
|
|
1839
|
+
openapi() {
|
|
1840
|
+
return createOpenAPIHandler(registry, resolvedBaseUrl, pricesKeys, config.discovery);
|
|
1822
1841
|
},
|
|
1823
|
-
|
|
1824
|
-
return
|
|
1842
|
+
llmsTxt() {
|
|
1843
|
+
return createLlmsTxtHandler(config.discovery);
|
|
1825
1844
|
},
|
|
1826
1845
|
monitors() {
|
|
1827
1846
|
const result = [];
|
package/dist/index.d.cts
CHANGED
|
@@ -280,6 +280,21 @@ interface RouteEntry {
|
|
|
280
280
|
providerConfig?: ProviderConfig;
|
|
281
281
|
validateFn?: (body: unknown) => void | Promise<void>;
|
|
282
282
|
}
|
|
283
|
+
interface DiscoveryConfig {
|
|
284
|
+
title: string;
|
|
285
|
+
version: string;
|
|
286
|
+
description?: string;
|
|
287
|
+
contact?: {
|
|
288
|
+
name?: string;
|
|
289
|
+
url?: string;
|
|
290
|
+
};
|
|
291
|
+
ownershipProofs?: string[];
|
|
292
|
+
methodHints?: 'off' | 'non-default' | 'always';
|
|
293
|
+
/** Natural language guidance for agents. Served as wellknown `instructions` and `/llms.txt`. */
|
|
294
|
+
guidance?: string | (() => string | Promise<string>);
|
|
295
|
+
/** Override the OpenAPI `servers` URL. Defaults to `RouterConfig.baseUrl`. Use when the public API hostname differs from the payment realm URL. */
|
|
296
|
+
serverUrl?: string;
|
|
297
|
+
}
|
|
283
298
|
interface RouterConfig {
|
|
284
299
|
payeeAddress: string;
|
|
285
300
|
/**
|
|
@@ -329,6 +344,7 @@ interface RouterConfig {
|
|
|
329
344
|
* This prevents discovery/openapi drift caused by shorthand internal keys.
|
|
330
345
|
*/
|
|
331
346
|
strictRoutes?: boolean;
|
|
347
|
+
discovery: DiscoveryConfig;
|
|
332
348
|
}
|
|
333
349
|
|
|
334
350
|
declare class RouteRegistry {
|
|
@@ -341,34 +357,6 @@ declare class RouteRegistry {
|
|
|
341
357
|
validate(expectedKeys?: string[]): void;
|
|
342
358
|
}
|
|
343
359
|
|
|
344
|
-
interface WellKnownOptions {
|
|
345
|
-
description?: string;
|
|
346
|
-
instructions?: string | (() => string | Promise<string>);
|
|
347
|
-
ownershipProofs?: string[];
|
|
348
|
-
/**
|
|
349
|
-
* Whether to include explicit HTTP method prefixes in `resources`.
|
|
350
|
-
* - `off`: always emit plain URLs.
|
|
351
|
-
* - `non-default`: emit `METHOD url` for PUT/PATCH/DELETE routes.
|
|
352
|
-
* - `always`: emit `METHOD url` for all routes.
|
|
353
|
-
*
|
|
354
|
-
* @default 'non-default'
|
|
355
|
-
*/
|
|
356
|
-
methodHints?: 'off' | 'non-default' | 'always';
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
interface OpenAPIOptions {
|
|
360
|
-
title: string;
|
|
361
|
-
version: string;
|
|
362
|
-
description?: string;
|
|
363
|
-
baseUrl?: string;
|
|
364
|
-
contact?: {
|
|
365
|
-
name?: string;
|
|
366
|
-
url?: string;
|
|
367
|
-
};
|
|
368
|
-
llmsTxtUrl?: string;
|
|
369
|
-
ownershipProofs?: string[];
|
|
370
|
-
}
|
|
371
|
-
|
|
372
360
|
interface OrchestrateDeps {
|
|
373
361
|
x402Server: X402Server | null;
|
|
374
362
|
initPromise: Promise<void>;
|
|
@@ -477,8 +465,9 @@ interface MonitorEntry {
|
|
|
477
465
|
}
|
|
478
466
|
interface ServiceRouter<TPriceKeys extends string = never> {
|
|
479
467
|
route<K extends string>(keyOrDefinition: K | RouteDefinition<K>): [K] extends [TPriceKeys] ? RouteBuilder<undefined, undefined, true, false, false> : RouteBuilder<undefined, undefined, false, false, false>;
|
|
480
|
-
wellKnown(
|
|
481
|
-
openapi(
|
|
468
|
+
wellKnown(): (request: NextRequest) => Promise<NextResponse>;
|
|
469
|
+
openapi(): (request: NextRequest) => Promise<NextResponse>;
|
|
470
|
+
llmsTxt(): (request: NextRequest) => Promise<NextResponse>;
|
|
482
471
|
monitors(): MonitorEntry[];
|
|
483
472
|
registry: RouteRegistry;
|
|
484
473
|
}
|
|
@@ -486,4 +475,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
|
|
|
486
475
|
prices?: P;
|
|
487
476
|
}): ServiceRouter<Extract<keyof P, string>>;
|
|
488
477
|
|
|
489
|
-
export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type NonceStore, type OveragePolicy, type PaidOptions, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
|
|
478
|
+
export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type DiscoveryConfig, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type NonceStore, type OveragePolicy, type PaidOptions, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
|
package/dist/index.d.ts
CHANGED
|
@@ -280,6 +280,21 @@ interface RouteEntry {
|
|
|
280
280
|
providerConfig?: ProviderConfig;
|
|
281
281
|
validateFn?: (body: unknown) => void | Promise<void>;
|
|
282
282
|
}
|
|
283
|
+
interface DiscoveryConfig {
|
|
284
|
+
title: string;
|
|
285
|
+
version: string;
|
|
286
|
+
description?: string;
|
|
287
|
+
contact?: {
|
|
288
|
+
name?: string;
|
|
289
|
+
url?: string;
|
|
290
|
+
};
|
|
291
|
+
ownershipProofs?: string[];
|
|
292
|
+
methodHints?: 'off' | 'non-default' | 'always';
|
|
293
|
+
/** Natural language guidance for agents. Served as wellknown `instructions` and `/llms.txt`. */
|
|
294
|
+
guidance?: string | (() => string | Promise<string>);
|
|
295
|
+
/** Override the OpenAPI `servers` URL. Defaults to `RouterConfig.baseUrl`. Use when the public API hostname differs from the payment realm URL. */
|
|
296
|
+
serverUrl?: string;
|
|
297
|
+
}
|
|
283
298
|
interface RouterConfig {
|
|
284
299
|
payeeAddress: string;
|
|
285
300
|
/**
|
|
@@ -329,6 +344,7 @@ interface RouterConfig {
|
|
|
329
344
|
* This prevents discovery/openapi drift caused by shorthand internal keys.
|
|
330
345
|
*/
|
|
331
346
|
strictRoutes?: boolean;
|
|
347
|
+
discovery: DiscoveryConfig;
|
|
332
348
|
}
|
|
333
349
|
|
|
334
350
|
declare class RouteRegistry {
|
|
@@ -341,34 +357,6 @@ declare class RouteRegistry {
|
|
|
341
357
|
validate(expectedKeys?: string[]): void;
|
|
342
358
|
}
|
|
343
359
|
|
|
344
|
-
interface WellKnownOptions {
|
|
345
|
-
description?: string;
|
|
346
|
-
instructions?: string | (() => string | Promise<string>);
|
|
347
|
-
ownershipProofs?: string[];
|
|
348
|
-
/**
|
|
349
|
-
* Whether to include explicit HTTP method prefixes in `resources`.
|
|
350
|
-
* - `off`: always emit plain URLs.
|
|
351
|
-
* - `non-default`: emit `METHOD url` for PUT/PATCH/DELETE routes.
|
|
352
|
-
* - `always`: emit `METHOD url` for all routes.
|
|
353
|
-
*
|
|
354
|
-
* @default 'non-default'
|
|
355
|
-
*/
|
|
356
|
-
methodHints?: 'off' | 'non-default' | 'always';
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
interface OpenAPIOptions {
|
|
360
|
-
title: string;
|
|
361
|
-
version: string;
|
|
362
|
-
description?: string;
|
|
363
|
-
baseUrl?: string;
|
|
364
|
-
contact?: {
|
|
365
|
-
name?: string;
|
|
366
|
-
url?: string;
|
|
367
|
-
};
|
|
368
|
-
llmsTxtUrl?: string;
|
|
369
|
-
ownershipProofs?: string[];
|
|
370
|
-
}
|
|
371
|
-
|
|
372
360
|
interface OrchestrateDeps {
|
|
373
361
|
x402Server: X402Server | null;
|
|
374
362
|
initPromise: Promise<void>;
|
|
@@ -477,8 +465,9 @@ interface MonitorEntry {
|
|
|
477
465
|
}
|
|
478
466
|
interface ServiceRouter<TPriceKeys extends string = never> {
|
|
479
467
|
route<K extends string>(keyOrDefinition: K | RouteDefinition<K>): [K] extends [TPriceKeys] ? RouteBuilder<undefined, undefined, true, false, false> : RouteBuilder<undefined, undefined, false, false, false>;
|
|
480
|
-
wellKnown(
|
|
481
|
-
openapi(
|
|
468
|
+
wellKnown(): (request: NextRequest) => Promise<NextResponse>;
|
|
469
|
+
openapi(): (request: NextRequest) => Promise<NextResponse>;
|
|
470
|
+
llmsTxt(): (request: NextRequest) => Promise<NextResponse>;
|
|
482
471
|
monitors(): MonitorEntry[];
|
|
483
472
|
registry: RouteRegistry;
|
|
484
473
|
}
|
|
@@ -486,4 +475,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
|
|
|
486
475
|
prices?: P;
|
|
487
476
|
}): ServiceRouter<Extract<keyof P, string>>;
|
|
488
477
|
|
|
489
|
-
export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type NonceStore, type OveragePolicy, type PaidOptions, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
|
|
478
|
+
export { type AlertEvent, type AlertFn, type AlertLevel, type AuthEvent, type AuthMode, type DiscoveryConfig, type EntitlementStore, type ErrorEvent, type HandlerContext, HttpError, MemoryEntitlementStore, MemoryNonceStore, type MonitorEntry, type NonceStore, type OveragePolicy, type PaidOptions, type PaymentEvent, type PluginContext, type PricingConfig, type ProtocolType, type ProviderConfig, type ProviderQuotaEvent, type QuotaInfo, type QuotaLevel, type RedisEntitlementStoreOptions, type RedisNonceStoreOptions, type RequestMeta, type ResponseMeta, RouteBuilder, type RouteEntry, RouteRegistry, type RouterConfig, type RouterPlugin, SIWX_CHALLENGE_EXPIRY_MS, type ServiceRouter, type SettlementEvent, type TierConfig, type X402Server, consolePlugin, createRedisEntitlementStore, createRedisNonceStore, createRouter };
|
package/dist/index.js
CHANGED
|
@@ -1417,7 +1417,15 @@ function createRedisEntitlementStore(client, options) {
|
|
|
1417
1417
|
|
|
1418
1418
|
// src/discovery/well-known.ts
|
|
1419
1419
|
import { NextResponse as NextResponse3 } from "next/server";
|
|
1420
|
-
|
|
1420
|
+
|
|
1421
|
+
// src/discovery/utils/guidance.ts
|
|
1422
|
+
async function resolveGuidance(discovery) {
|
|
1423
|
+
if (typeof discovery.guidance === "function") return discovery.guidance();
|
|
1424
|
+
return discovery.guidance;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// src/discovery/well-known.ts
|
|
1428
|
+
function createWellKnownHandler(registry, baseUrl, pricesKeys, discovery) {
|
|
1421
1429
|
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
1422
1430
|
let validated = false;
|
|
1423
1431
|
return async (_request) => {
|
|
@@ -1427,19 +1435,14 @@ function createWellKnownHandler(registry, baseUrl, pricesKeys, options = {}) {
|
|
|
1427
1435
|
}
|
|
1428
1436
|
const x402Set = /* @__PURE__ */ new Set();
|
|
1429
1437
|
const mppSet = /* @__PURE__ */ new Set();
|
|
1430
|
-
const methodHints =
|
|
1438
|
+
const methodHints = discovery.methodHints ?? "non-default";
|
|
1431
1439
|
for (const [key, entry] of registry.entries()) {
|
|
1432
1440
|
const url = `${normalizedBase}/api/${entry.path ?? key}`;
|
|
1433
1441
|
const resource = toDiscoveryResource(entry.method, url, methodHints);
|
|
1434
1442
|
if (entry.authMode !== "unprotected") x402Set.add(resource);
|
|
1435
1443
|
if (entry.protocols.includes("mpp")) mppSet.add(resource);
|
|
1436
1444
|
}
|
|
1437
|
-
|
|
1438
|
-
if (typeof options.instructions === "function") {
|
|
1439
|
-
instructions = await options.instructions();
|
|
1440
|
-
} else if (typeof options.instructions === "string") {
|
|
1441
|
-
instructions = options.instructions;
|
|
1442
|
-
}
|
|
1445
|
+
const instructions = await resolveGuidance(discovery);
|
|
1443
1446
|
const body = {
|
|
1444
1447
|
version: 1,
|
|
1445
1448
|
resources: Array.from(x402Set)
|
|
@@ -1448,11 +1451,11 @@ function createWellKnownHandler(registry, baseUrl, pricesKeys, options = {}) {
|
|
|
1448
1451
|
if (mppResources.length > 0) {
|
|
1449
1452
|
body.mppResources = mppResources;
|
|
1450
1453
|
}
|
|
1451
|
-
if (
|
|
1452
|
-
body.description =
|
|
1454
|
+
if (discovery.description) {
|
|
1455
|
+
body.description = discovery.description;
|
|
1453
1456
|
}
|
|
1454
|
-
if (
|
|
1455
|
-
body.ownershipProofs =
|
|
1457
|
+
if (discovery.ownershipProofs) {
|
|
1458
|
+
body.ownershipProofs = discovery.ownershipProofs;
|
|
1456
1459
|
}
|
|
1457
1460
|
if (instructions) {
|
|
1458
1461
|
body.instructions = instructions;
|
|
@@ -1475,7 +1478,7 @@ function toDiscoveryResource(method, url, mode) {
|
|
|
1475
1478
|
|
|
1476
1479
|
// src/discovery/openapi.ts
|
|
1477
1480
|
import { NextResponse as NextResponse4 } from "next/server";
|
|
1478
|
-
function createOpenAPIHandler(registry, baseUrl, pricesKeys,
|
|
1481
|
+
function createOpenAPIHandler(registry, baseUrl, pricesKeys, discovery) {
|
|
1479
1482
|
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
1480
1483
|
let cached = null;
|
|
1481
1484
|
let validated = false;
|
|
@@ -1516,21 +1519,20 @@ function createOpenAPIHandler(registry, baseUrl, pricesKeys, options) {
|
|
|
1516
1519
|
};
|
|
1517
1520
|
}
|
|
1518
1521
|
const discoveryMetadata = {};
|
|
1519
|
-
if (
|
|
1520
|
-
discoveryMetadata.ownershipProofs =
|
|
1521
|
-
}
|
|
1522
|
-
if (options.llmsTxtUrl) {
|
|
1523
|
-
discoveryMetadata.llmsTxtUrl = options.llmsTxtUrl;
|
|
1522
|
+
if (discovery.ownershipProofs && discovery.ownershipProofs.length > 0) {
|
|
1523
|
+
discoveryMetadata.ownershipProofs = discovery.ownershipProofs;
|
|
1524
1524
|
}
|
|
1525
|
+
const guidance = await resolveGuidance(discovery);
|
|
1525
1526
|
const openApiDocument = {
|
|
1526
1527
|
openapi: "3.1.0",
|
|
1527
1528
|
info: {
|
|
1528
|
-
title:
|
|
1529
|
-
description:
|
|
1530
|
-
version:
|
|
1531
|
-
|
|
1529
|
+
title: discovery.title,
|
|
1530
|
+
description: discovery.description,
|
|
1531
|
+
version: discovery.version,
|
|
1532
|
+
guidance,
|
|
1533
|
+
...discovery.contact && { contact: discovery.contact }
|
|
1532
1534
|
},
|
|
1533
|
-
servers: [{ url: (
|
|
1535
|
+
servers: [{ url: (discovery.serverUrl ?? normalizedBase).replace(/\/+$/, "") }],
|
|
1534
1536
|
tags: Array.from(tagSet).sort().map((name) => ({ name })),
|
|
1535
1537
|
...Object.keys(securitySchemes).length > 0 ? {
|
|
1536
1538
|
components: {
|
|
@@ -1650,6 +1652,20 @@ function buildPricingInfo(entry) {
|
|
|
1650
1652
|
return void 0;
|
|
1651
1653
|
}
|
|
1652
1654
|
|
|
1655
|
+
// src/discovery/llms-txt.ts
|
|
1656
|
+
import { NextResponse as NextResponse5 } from "next/server";
|
|
1657
|
+
function createLlmsTxtHandler(discovery) {
|
|
1658
|
+
return async (_request) => {
|
|
1659
|
+
const guidance = await resolveGuidance(discovery) ?? "";
|
|
1660
|
+
return new NextResponse5(guidance, {
|
|
1661
|
+
headers: {
|
|
1662
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
1663
|
+
"Access-Control-Allow-Origin": "*"
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1653
1669
|
// src/index.ts
|
|
1654
1670
|
function createRouter(config) {
|
|
1655
1671
|
const registry = new RouteRegistry();
|
|
@@ -1778,11 +1794,14 @@ function createRouter(config) {
|
|
|
1778
1794
|
}
|
|
1779
1795
|
return builder;
|
|
1780
1796
|
},
|
|
1781
|
-
wellKnown(
|
|
1782
|
-
return createWellKnownHandler(registry, resolvedBaseUrl, pricesKeys,
|
|
1797
|
+
wellKnown() {
|
|
1798
|
+
return createWellKnownHandler(registry, resolvedBaseUrl, pricesKeys, config.discovery);
|
|
1799
|
+
},
|
|
1800
|
+
openapi() {
|
|
1801
|
+
return createOpenAPIHandler(registry, resolvedBaseUrl, pricesKeys, config.discovery);
|
|
1783
1802
|
},
|
|
1784
|
-
|
|
1785
|
-
return
|
|
1803
|
+
llmsTxt() {
|
|
1804
|
+
return createLlmsTxtHandler(config.discovery);
|
|
1786
1805
|
},
|
|
1787
1806
|
monitors() {
|
|
1788
1807
|
const result = [];
|