@agentcash/router 1.11.0 → 1.13.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/AGENTS.md +15 -4
- package/README.md +40 -6
- package/dist/index.cjs +269 -259
- package/dist/index.d.cts +92 -34
- package/dist/index.d.ts +92 -34
- package/dist/index.js +268 -259
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -128,6 +128,20 @@ declare class HttpError extends Error {
|
|
|
128
128
|
readonly status: number;
|
|
129
129
|
constructor(message: string, status: number);
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Thrown when a route definition is invalid — an impossible builder
|
|
133
|
+
* combination, a malformed price, or a route that needs config the router
|
|
134
|
+
* wasn't given. Fires at module-import time (when the route file is first
|
|
135
|
+
* loaded), so Next.js surfaces it as a build/dev error, never as a response.
|
|
136
|
+
* The registration-time sibling of {@link RouterConfigError}.
|
|
137
|
+
*/
|
|
138
|
+
declare class RouteDefinitionError extends Error {
|
|
139
|
+
/** Registry key of the offending route. */
|
|
140
|
+
readonly route: string;
|
|
141
|
+
constructor(
|
|
142
|
+
/** Registry key of the offending route. */
|
|
143
|
+
route: string, detail: string);
|
|
144
|
+
}
|
|
131
145
|
type AlertLevel = 'info' | 'warn' | 'error' | 'critical';
|
|
132
146
|
interface AlertEvent {
|
|
133
147
|
level: AlertLevel;
|
|
@@ -410,6 +424,7 @@ interface DiscoveryConfig {
|
|
|
410
424
|
contact?: {
|
|
411
425
|
name?: string;
|
|
412
426
|
url?: string;
|
|
427
|
+
email?: string;
|
|
413
428
|
};
|
|
414
429
|
ownershipProofs?: string[];
|
|
415
430
|
methodHints?: 'off' | 'non-default' | 'always';
|
|
@@ -418,6 +433,23 @@ interface DiscoveryConfig {
|
|
|
418
433
|
/** Override the OpenAPI `servers` URL. Defaults to `RouterConfig.baseUrl`. Use when the public API hostname differs from the payment realm URL. */
|
|
419
434
|
serverUrl?: string;
|
|
420
435
|
}
|
|
436
|
+
/** Sponsor fee-budget ceilings for fee-sponsored Tempo transactions. Structural mirror of mppx's `FeePayer.Policy`, all fields optional. */
|
|
437
|
+
interface MppFeePayerPolicy {
|
|
438
|
+
maxGas?: bigint;
|
|
439
|
+
maxFeePerGas?: bigint;
|
|
440
|
+
maxPriorityFeePerGas?: bigint;
|
|
441
|
+
maxTotalFee?: bigint;
|
|
442
|
+
maxValidityWindowSeconds?: number;
|
|
443
|
+
}
|
|
444
|
+
/** Server-owned automatic settlement cadence for MPP session channels. Structural mirror of mppx's `SettlementSchedule`. */
|
|
445
|
+
interface MppSettlementSchedule {
|
|
446
|
+
/** Settle after this many additional paid units since the previous settlement. */
|
|
447
|
+
units?: number;
|
|
448
|
+
/** Settle after this much additional billed amount (decimal-dollar string) since the previous settlement. */
|
|
449
|
+
amount?: string;
|
|
450
|
+
/** Settle after this many milliseconds since the previous settlement. */
|
|
451
|
+
intervalMs?: number;
|
|
452
|
+
}
|
|
421
453
|
interface RouterConfig {
|
|
422
454
|
/** Default payee for paid routes — populates `payTo` on the auto-generated x402 `exact` accept and acts as the MPP `recipient` fallback. Override per-protocol via `x402.accepts[i].payTo` / `mpp.recipient`, or per-route via the `payTo` option on `.paid()` / `.upTo()` / `.metered()`. */
|
|
423
455
|
payeeAddress?: string;
|
|
@@ -453,19 +485,23 @@ interface RouterConfig {
|
|
|
453
485
|
rpcUrl?: string;
|
|
454
486
|
/** Hex private key. Signs channel close/settle; required for `session`. Address MUST equal `recipient`/payee — mppx asserts sender===payee on settle. Validated at init. */
|
|
455
487
|
operatorKey?: string;
|
|
456
|
-
/** Hex private key. Sponsors gas for client channel open/topUp. MUST resolve to a different address than `operatorKey` — Tempo rejects sender===feePayer. Validated at init. Omit to make clients pay their own gas. */
|
|
488
|
+
/** Hex private key. Sponsors gas for client channel open/topUp. MUST resolve to a different address than `operatorKey` — Tempo rejects sender===feePayer. Validated at init. Omit to make clients pay their own gas. The account must hold the Tempo fee token (pathUSD) to pay sponsored gas. */
|
|
457
489
|
feePayerKey?: string;
|
|
490
|
+
/** Partial override of mppx's sponsor fee-budget ceilings for fee-sponsored Tempo transactions (charge co-signs and session open/topUp/close). Raise `maxTotalFee` alongside `maxGas`/`maxFeePerGas`. Omit for mppx's per-chain defaults. */
|
|
491
|
+
feePayerPolicy?: MppFeePayerPolicy;
|
|
458
492
|
/** Enables MPP payment-channel sessions for `.metered()` routes (registers both request and SSE session middleware). Also requires `mpp.operatorKey`. */
|
|
459
493
|
session?: {
|
|
460
494
|
/** Suggested deposit on the 402 challenge = `tickCost × depositMultiplier` USDC. Route `maxPrice` overrides. @default 10 */
|
|
461
495
|
depositMultiplier?: number;
|
|
496
|
+
/** Server-owned automatic settlement cadence for session channels. Omitted: channels settle only on client close. Thresholds compose (whichever trips first). */
|
|
497
|
+
settlementSchedule?: MppSettlementSchedule;
|
|
462
498
|
};
|
|
463
499
|
};
|
|
464
500
|
/** Payment protocols to accept on paid routes unless overridden per route. @default ['x402'] */
|
|
465
501
|
protocols?: ProtocolType[];
|
|
466
502
|
/** When true, `.route('key')` is rejected (use `.route({ path })`) and custom `key !== path` is rejected. Prevents discovery/openapi drift. */
|
|
467
503
|
strictRoutes?: boolean;
|
|
468
|
-
/** Static metadata for auto-generated discovery surfaces —
|
|
504
|
+
/** Static metadata for auto-generated discovery surfaces — `/openapi.json` (`.openapi()`) and `/llms.txt` (`.llmsTxt()`). Also feeds the deprecated `.wellKnown()` handler. */
|
|
469
505
|
discovery: DiscoveryConfig;
|
|
470
506
|
}
|
|
471
507
|
|
|
@@ -542,14 +578,27 @@ type InputTypeFor<TBody, TQuery> = [TBody] extends [undefined] ? [TQuery] extend
|
|
|
542
578
|
type RequestHandlerFn<TBody, TQuery> = (ctx: HandlerContext<TBody, TQuery>) => Promise<unknown>;
|
|
543
579
|
type UptoHandlerFn<TBody, TQuery> = (ctx: UptoHandlerContext<TBody, TQuery>) => Promise<unknown>;
|
|
544
580
|
type StreamingHandlerFn<TBody, TQuery> = (ctx: StreamingHandlerContext<TBody, TQuery>) => AsyncIterable<unknown>;
|
|
545
|
-
/**
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
581
|
+
/**
|
|
582
|
+
* Pricing-mode discriminator threaded through the builder. `'none'` until a
|
|
583
|
+
* pricing method is chained; then `'exact'` (`.paid()`), `'upto'`, or
|
|
584
|
+
* `'metered'`. Gates repeat pricing calls and picks the handler shape.
|
|
585
|
+
*/
|
|
586
|
+
type BillingMode = 'none' | 'exact' | 'upto' | 'metered';
|
|
587
|
+
/**
|
|
588
|
+
* Identity-mode discriminator threaded through the builder. `'none'` until an
|
|
589
|
+
* identity method is chained; then `'siwx'`, `'apiKey'`, or `'open'`
|
|
590
|
+
* (`.unprotected()`). Gates the mutually-exclusive combinations at compile
|
|
591
|
+
* time, mirroring the registration-time throws.
|
|
592
|
+
*/
|
|
593
|
+
type IdentMode = 'none' | 'siwx' | 'apiKey' | 'open';
|
|
594
|
+
/** Resolves to `TSelf` when a pricing method may be chained, else a `RouteError`. Mirrors the runtime guards in `applyPaid`. */
|
|
595
|
+
type PricingGate<TSelf, Ident extends IdentMode, Bill extends BillingMode, M extends string> = Ident extends 'open' ? RouteError<`Cannot combine .unprotected() and .${M}() on the same route`> : Bill extends 'none' ? TSelf : RouteError<'Cannot combine .paid(), .upTo(), and .metered() — pick one pricing mode'>;
|
|
596
|
+
type HandlerArg<TBody, TQuery, Ident extends IdentMode, NeedsBody extends boolean, HasBody extends boolean, Bill extends BillingMode> = [Ident, Bill] extends ['none', 'none'] ? RouteError<'Pick an auth mode first: .paid(...), .upTo(...), .metered(...), .siwx(), .apiKey(...), or .unprotected()'> : [NeedsBody, HasBody] extends [true, false] ? RouteError<'Call .body(schema) — body-derived/tiered pricing reads the parsed body'> : Bill extends 'upto' ? UptoHandlerFn<TBody, TQuery> : RequestHandlerFn<TBody, TQuery>;
|
|
597
|
+
type StreamArg<TBody, TQuery, Ident extends IdentMode, NeedsBody extends boolean, HasBody extends boolean, Bill extends BillingMode> = [Ident, Bill] extends ['none', 'none'] ? RouteError<'Pick an auth mode first: .metered({ ... }) — streaming requires metered pricing'> : Bill extends 'metered' ? [NeedsBody, HasBody] extends [true, false] ? RouteError<'Call .body(schema) — metered pricing reads the parsed body'> : StreamingHandlerFn<TBody, TQuery> : Bill extends 'upto' ? RouteError<'Streaming is not supported on .upTo() — use .metered() on MPP for per-yield billing'> : RouteError<'Streaming requires .metered({ tickCost, maxPrice }) — static/free routes cannot meter per-chunk billing'>;
|
|
549
598
|
interface RouteBuilderDefaults {
|
|
550
599
|
protocols?: ProtocolType[];
|
|
551
600
|
}
|
|
552
|
-
declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = undefined,
|
|
601
|
+
declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = undefined, Ident extends IdentMode = 'none', NeedsBody extends boolean = false, HasBody extends boolean = false, Bill extends BillingMode = 'none'> {
|
|
553
602
|
#private;
|
|
554
603
|
constructor(key: string, registry: RouteRegistry, deps: RouterDeps, defaults?: RouteBuilderDefaults);
|
|
555
604
|
private fork;
|
|
@@ -561,7 +610,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
561
610
|
* router.route('search').paid('0.01').handler(handler);
|
|
562
611
|
* ```
|
|
563
612
|
*/
|
|
564
|
-
paid(price: string, options?: PaidOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
613
|
+
paid(this: PricingGate<RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>, Ident, Bill, 'paid'>, price: string, options?: PaidOptions): RouteBuilder<TBody, TQuery, TOutput, Ident, False, HasBody, 'exact'>;
|
|
565
614
|
/**
|
|
566
615
|
* Compute the price from the parsed body before issuing the 402 challenge.
|
|
567
616
|
* Throw an `HttpError` from the pricing function to reject the request
|
|
@@ -575,7 +624,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
575
624
|
* .handler(handler);
|
|
576
625
|
* ```
|
|
577
626
|
*/
|
|
578
|
-
paid<TBodyIn>(fn: (body: TBodyIn) => string | Promise<string>, options?: PaidOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
627
|
+
paid<TBodyIn>(this: PricingGate<RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>, Ident, Bill, 'paid'>, fn: (body: TBodyIn) => string | Promise<string>, options?: PaidOptions): RouteBuilder<TBody, TQuery, TOutput, Ident, True, HasBody, 'exact'>;
|
|
579
628
|
/**
|
|
580
629
|
* Options-object form of fixed or body-derived pricing. Pass exactly one of:
|
|
581
630
|
*
|
|
@@ -594,9 +643,9 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
594
643
|
* .body(schema).handler(handler);
|
|
595
644
|
* ```
|
|
596
645
|
*/
|
|
597
|
-
paid<T extends PaidArg>(arg: T): RouteBuilder<TBody, TQuery, TOutput,
|
|
646
|
+
paid<T extends PaidArg>(this: PricingGate<RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>, Ident, Bill, 'paid'>, arg: T): RouteBuilder<TBody, TQuery, TOutput, Ident, T extends {
|
|
598
647
|
tiers: Record<string, TierConfig>;
|
|
599
|
-
} ? True : False, HasBody, '
|
|
648
|
+
} ? True : False, HasBody, 'exact'>;
|
|
600
649
|
/**
|
|
601
650
|
* x402-only handler-computed billing. The handler receives `charge(amount)`
|
|
602
651
|
* and the request settles once for the accumulated total, capped at
|
|
@@ -611,7 +660,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
611
660
|
* .handler(async ({ body, charge }) => { await charge('0.001'); ... });
|
|
612
661
|
* ```
|
|
613
662
|
*/
|
|
614
|
-
upTo(arg: string | UpToOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
663
|
+
upTo(this: PricingGate<RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>, Ident, Bill, 'upTo'>, arg: string | UpToOptions): RouteBuilder<TBody, TQuery, TOutput, Ident, False, HasBody, 'upto'>;
|
|
615
664
|
/**
|
|
616
665
|
* MPP-only per-tick billing. `.handler()` bills exactly `tickCost`;
|
|
617
666
|
* `.stream()` calls `charge()` (no-arg) per yield, settling per tick up to
|
|
@@ -624,7 +673,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
624
673
|
* .stream(async function* ({ charge }) { await charge(); yield 'hi'; });
|
|
625
674
|
* ```
|
|
626
675
|
*/
|
|
627
|
-
metered(options: MeteredOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
676
|
+
metered(this: Ident extends 'siwx' ? RouteError<'Cannot combine .siwx() and .metered() — per-tick MPP billing has no entitlement model'> : PricingGate<RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>, Ident, Bill, 'metered'>, options: MeteredOptions): RouteBuilder<TBody, TQuery, TOutput, Ident, False, HasBody, 'metered'>;
|
|
628
677
|
private applyPaid;
|
|
629
678
|
/**
|
|
630
679
|
* Require Sign-In-with-X wallet identity on this route — clients prove
|
|
@@ -640,7 +689,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
640
689
|
* router.route('inbox').paid('0.01').siwx().handler(async ({ wallet }) => getInbox(wallet));
|
|
641
690
|
* ```
|
|
642
691
|
*/
|
|
643
|
-
siwx(): RouteBuilder<TBody, TQuery, TOutput,
|
|
692
|
+
siwx(this: Ident extends 'open' ? RouteError<'Cannot combine .unprotected() and .siwx() on the same route'> : Ident extends 'apiKey' ? RouteError<'Combining .siwx() and .apiKey() is not supported on the same route'> : Bill extends 'metered' ? RouteError<'Cannot combine .metered() and .siwx() — per-tick MPP billing has no entitlement model'> : RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>): RouteBuilder<TBody, TQuery, TOutput, 'siwx', NeedsBody, HasBody, Bill>;
|
|
644
693
|
/**
|
|
645
694
|
* Require an `X-API-Key` header (or `Authorization: Bearer <key>`); the
|
|
646
695
|
* resolver returns the account record, or `null` for 401. Composes with
|
|
@@ -654,7 +703,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
654
703
|
* .handler(async ({ account }) => db.user.list(account.orgId));
|
|
655
704
|
* ```
|
|
656
705
|
*/
|
|
657
|
-
apiKey(resolver: (key: string) => unknown | Promise<unknown>): RouteBuilder<TBody, TQuery, TOutput,
|
|
706
|
+
apiKey(this: Ident extends 'open' ? RouteError<'Cannot combine .unprotected() and .apiKey() on the same route'> : Ident extends 'siwx' ? RouteError<'Combining .apiKey() and .siwx() is not supported on the same route'> : RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>, resolver: (key: string) => unknown | Promise<unknown>): RouteBuilder<TBody, TQuery, TOutput, 'apiKey', NeedsBody, HasBody, Bill>;
|
|
658
707
|
/**
|
|
659
708
|
* Mark the route as public — no auth, no payment, no SIWX. The handler
|
|
660
709
|
* receives `null` for `wallet`, `payment`, and `account`.
|
|
@@ -664,11 +713,11 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
664
713
|
* router.route('health').unprotected().handler(async () => ({ status: 'ok' }));
|
|
665
714
|
* ```
|
|
666
715
|
*/
|
|
667
|
-
unprotected(): RouteBuilder<TBody, TQuery, TOutput,
|
|
716
|
+
unprotected(this: Bill extends 'none' ? Ident extends 'siwx' ? RouteError<'Cannot combine .unprotected() and .siwx() on the same route'> : Ident extends 'apiKey' ? RouteError<'Cannot combine .unprotected() and .apiKey() on the same route'> : RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill> : RouteError<'Cannot combine .unprotected() and a pricing mode on the same route'>): RouteBuilder<TBody, TQuery, TOutput, 'open', NeedsBody, HasBody, Bill>;
|
|
668
717
|
/**
|
|
669
718
|
* Tag the route with an upstream provider for discovery and provider-side
|
|
670
|
-
* monitoring. The provider name and config surface in
|
|
671
|
-
*
|
|
719
|
+
* monitoring. The provider name and config surface in OpenAPI discovery
|
|
720
|
+
* output.
|
|
672
721
|
*
|
|
673
722
|
* @example
|
|
674
723
|
* ```ts
|
|
@@ -690,7 +739,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
690
739
|
* .handler(async ({ body }) => search(body.query));
|
|
691
740
|
* ```
|
|
692
741
|
*/
|
|
693
|
-
body<T>(schema: ZodType<T>): RouteBuilder<T, TQuery, TOutput,
|
|
742
|
+
body<T>(schema: ZodType<T>): RouteBuilder<T, TQuery, TOutput, Ident, NeedsBody, True, Bill>;
|
|
694
743
|
/**
|
|
695
744
|
* Declare a query-string Zod schema and switch the route to `GET`. Parsed
|
|
696
745
|
* query is typed as `ctx.query` in the handler. Use `.inputExample()` to
|
|
@@ -702,7 +751,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
702
751
|
* .handler(async ({ query }) => getById(query.id));
|
|
703
752
|
* ```
|
|
704
753
|
*/
|
|
705
|
-
query<T>(schema: ZodType<T>): RouteBuilder<TBody, T, TOutput,
|
|
754
|
+
query<T>(schema: ZodType<T>): RouteBuilder<TBody, T, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
706
755
|
/**
|
|
707
756
|
* Declare the response output's Zod schema for OpenAPI generation. The
|
|
708
757
|
* runtime does not validate handler return values — use Zod's `.parse()`
|
|
@@ -715,7 +764,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
715
764
|
* .handler(async () => ({ result: 'ok' }));
|
|
716
765
|
* ```
|
|
717
766
|
*/
|
|
718
|
-
output<T>(schema: ZodType<T>): RouteBuilder<TBody, TQuery, T,
|
|
767
|
+
output<T>(schema: ZodType<T>): RouteBuilder<TBody, TQuery, T, Ident, NeedsBody, HasBody, Bill>;
|
|
719
768
|
/**
|
|
720
769
|
* Attach an example of the request body or query for discovery output,
|
|
721
770
|
* validated against the registered schema at registration.
|
|
@@ -725,7 +774,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
725
774
|
* .body(searchSchema).inputExample({ query: 'cats' });
|
|
726
775
|
* ```
|
|
727
776
|
*/
|
|
728
|
-
inputExample(example: InputTypeFor<TBody, TQuery> & JsonObject): RouteBuilder<TBody, TQuery, TOutput,
|
|
777
|
+
inputExample(example: InputTypeFor<TBody, TQuery> & JsonObject): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
729
778
|
/**
|
|
730
779
|
* Attach an example response for discovery output, validated against the
|
|
731
780
|
* registered output schema at registration.
|
|
@@ -735,10 +784,10 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
735
784
|
* .output(resultSchema).outputExample({ result: 'ok' });
|
|
736
785
|
* ```
|
|
737
786
|
*/
|
|
738
|
-
outputExample(example: TOutput & JsonValue): RouteBuilder<TBody, TQuery, TOutput,
|
|
787
|
+
outputExample(example: TOutput & JsonValue): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
739
788
|
/**
|
|
740
|
-
* Set a human-readable summary of the route. Surfaces in OpenAPI
|
|
741
|
-
* `
|
|
789
|
+
* Set a human-readable summary of the route. Surfaces in OpenAPI and
|
|
790
|
+
* `llms.txt` discovery output.
|
|
742
791
|
*
|
|
743
792
|
* @example
|
|
744
793
|
* ```ts
|
|
@@ -780,7 +829,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
780
829
|
* });
|
|
781
830
|
* ```
|
|
782
831
|
*/
|
|
783
|
-
validate(fn: (body: TBody) => void | Promise<void>): RouteBuilder<TBody, TQuery, TOutput,
|
|
832
|
+
validate(fn: (body: TBody) => void | Promise<void>): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
784
833
|
/**
|
|
785
834
|
* Override MPP protocol metadata and per-route MPP settlement options.
|
|
786
835
|
* Merges with any `mpp` options passed to `.paid()`. Use on auto-priced routes
|
|
@@ -794,7 +843,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
794
843
|
* .handler(handler);
|
|
795
844
|
* ```
|
|
796
845
|
*/
|
|
797
|
-
mpp(info: MppProtocolInfo): RouteBuilder<TBody, TQuery, TOutput,
|
|
846
|
+
mpp(info: MppProtocolInfo): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
798
847
|
/**
|
|
799
848
|
* Hook into the settlement lifecycle. `beforeSettle` runs after the handler
|
|
800
849
|
* succeeds but before on-chain settlement and can cancel the charge;
|
|
@@ -808,7 +857,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
808
857
|
* });
|
|
809
858
|
* ```
|
|
810
859
|
*/
|
|
811
|
-
settlement(lifecycle: SettlementLifecycle<TBody>): RouteBuilder<TBody, TQuery, TOutput,
|
|
860
|
+
settlement(lifecycle: SettlementLifecycle<TBody>): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
812
861
|
/**
|
|
813
862
|
* Register the request handler and return the Next.js route function. The
|
|
814
863
|
* handler receives a typed context and may return a value (serialized to
|
|
@@ -823,7 +872,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
823
872
|
* .handler(async ({ body, wallet }) => searchService(body, wallet));
|
|
824
873
|
* ```
|
|
825
874
|
*/
|
|
826
|
-
handler(fn: HandlerArg<TBody, TQuery,
|
|
875
|
+
handler(fn: HandlerArg<TBody, TQuery, Ident, NeedsBody, HasBody, Bill>): (request: NextRequest) => Promise<Response>;
|
|
827
876
|
/**
|
|
828
877
|
* Register a streaming handler (`async function*`) and return the Next.js
|
|
829
878
|
* route function. Each `charge()` call bills one tick (`tickCost` USDC) up
|
|
@@ -843,7 +892,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
843
892
|
* });
|
|
844
893
|
* ```
|
|
845
894
|
*/
|
|
846
|
-
stream(fn: StreamArg<TBody, TQuery,
|
|
895
|
+
stream(fn: StreamArg<TBody, TQuery, Ident, NeedsBody, HasBody, Bill>): (request: NextRequest) => Promise<Response>;
|
|
847
896
|
private register;
|
|
848
897
|
}
|
|
849
898
|
|
|
@@ -860,7 +909,7 @@ interface RouterConfigIssue {
|
|
|
860
909
|
interface CreateRouterFromEnvOptions<TPrices extends Record<string, string> = Record<never, string>> {
|
|
861
910
|
/** Defaults to `process.env`. Pass an explicit object in tests. */
|
|
862
911
|
env?: Record<string, string | undefined>;
|
|
863
|
-
/** Discovery title. Shown in
|
|
912
|
+
/** Discovery title. Shown in `/openapi.json` and `/llms.txt`. */
|
|
864
913
|
title: string;
|
|
865
914
|
/** Discovery description. */
|
|
866
915
|
description: string;
|
|
@@ -870,7 +919,7 @@ interface CreateRouterFromEnvOptions<TPrices extends Record<string, string> = Re
|
|
|
870
919
|
version?: string;
|
|
871
920
|
/** Optional contact metadata published in discovery. */
|
|
872
921
|
contact?: DiscoveryConfig['contact'];
|
|
873
|
-
/** Optional ownership proofs published in
|
|
922
|
+
/** Optional ownership proofs published in `/openapi.json` (and the deprecated `/.well-known/x402`). */
|
|
874
923
|
ownershipProofs?: string[];
|
|
875
924
|
/** Per-route HTTP method hint visibility. */
|
|
876
925
|
methodHints?: DiscoveryConfig['methodHints'];
|
|
@@ -936,10 +985,19 @@ interface MonitorEntry {
|
|
|
936
985
|
critical?: number;
|
|
937
986
|
}
|
|
938
987
|
interface ServiceRouter<TPriceKeys extends string = never> {
|
|
939
|
-
route<K extends string>(keyOrDefinition: K | RouteDefinition<K>): [K] extends [TPriceKeys] ? RouteBuilder<undefined, undefined, undefined,
|
|
988
|
+
route<K extends string>(keyOrDefinition: K | RouteDefinition<K>): [K] extends [TPriceKeys] ? RouteBuilder<undefined, undefined, undefined, 'none', false, false, 'exact'> : RouteBuilder<undefined, undefined, undefined, 'none', false, false, 'none'>;
|
|
989
|
+
/**
|
|
990
|
+
* @deprecated The `/.well-known/x402` surface is no longer a recommended
|
|
991
|
+
* discovery location. The handler keeps working for legacy x402 clients,
|
|
992
|
+
* but new integrations should mount `.openapi()` (at `/openapi.json`) and
|
|
993
|
+
* `.llmsTxt()` (at `/llms.txt`) instead.
|
|
994
|
+
*/
|
|
940
995
|
wellKnown(): (request: NextRequest) => Promise<NextResponse>;
|
|
996
|
+
/** OpenAPI 3.1 discovery document. Mount at `GET /openapi.json`. */
|
|
941
997
|
openapi(): (request: NextRequest) => Promise<NextResponse>;
|
|
998
|
+
/** Plain-text agent guidance. Mount at `GET /llms.txt`. */
|
|
942
999
|
llmsTxt(): (request: NextRequest) => Promise<NextResponse>;
|
|
1000
|
+
/** JSON 404 fallback with rediscovery links. Mount in a catch-all route. */
|
|
943
1001
|
notFound(): (request: NextRequest) => Promise<NextResponse>;
|
|
944
1002
|
monitors(): MonitorEntry[];
|
|
945
1003
|
registry: RouteRegistry;
|
|
@@ -969,4 +1027,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
|
|
|
969
1027
|
*/
|
|
970
1028
|
declare function createRouterFromEnv<const P extends Record<string, string> = Record<never, string>>(options: CreateRouterFromEnvOptions<P>): ServiceRouter<Extract<keyof P, string>>;
|
|
971
1029
|
|
|
972
|
-
export { BASE_MAINNET_NETWORK, BASE_USDC_ADDRESS, BASE_USDC_DECIMALS, type CheckoutSessionContext, type CheckoutSessionFn, type CheckoutSessionResponse, type CreateRouterFromEnvOptions, DEFAULT_SOLANA_FACILITATOR_URL, DEFAULT_TEMPO_RPC_URL, type DiscoveryConfig, type HandlerContext, HttpError, type KvStore, type MppProtocolInfo, type PaidOptions, type ProtocolType, type RouterConfig, RouterConfigError, type RouterConfigIssue, type RouterConfigIssueCode, type RouterConfigIssueSeverity, type RouterPlugin, SOLANA_MAINNET_NETWORK, type ServiceRouter, type SettlementErrorContext, type SettlementLifecycleContext, type SettlementSettledContext, TEMPO_USDC_ADDRESS, TEMPO_USDC_DECIMALS, type X402FacilitatorsConfig, ZERO_EVM_ADDRESS, createRouter, createRouterFromEnv, routerConfigFromEnv };
|
|
1030
|
+
export { BASE_MAINNET_NETWORK, BASE_USDC_ADDRESS, BASE_USDC_DECIMALS, type CheckoutSessionContext, type CheckoutSessionFn, type CheckoutSessionResponse, type CreateRouterFromEnvOptions, DEFAULT_SOLANA_FACILITATOR_URL, DEFAULT_TEMPO_RPC_URL, type DiscoveryConfig, type HandlerContext, HttpError, type KvStore, type MppProtocolInfo, type PaidOptions, type ProtocolType, RouteDefinitionError, type RouterConfig, RouterConfigError, type RouterConfigIssue, type RouterConfigIssueCode, type RouterConfigIssueSeverity, type RouterPlugin, SOLANA_MAINNET_NETWORK, type ServiceRouter, type SettlementErrorContext, type SettlementLifecycleContext, type SettlementSettledContext, TEMPO_USDC_ADDRESS, TEMPO_USDC_DECIMALS, type X402FacilitatorsConfig, ZERO_EVM_ADDRESS, createRouter, createRouterFromEnv, routerConfigFromEnv };
|