@agentcash/router 1.12.0 → 1.14.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 +328 -289
- package/dist/index.d.cts +92 -37
- package/dist/index.d.ts +92 -37
- package/dist/index.js +327 -289
- 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;
|
|
@@ -208,8 +222,6 @@ interface X402AcceptConfig extends X402AcceptBase {
|
|
|
208
222
|
payTo?: PayToConfig;
|
|
209
223
|
}
|
|
210
224
|
interface X402RouterFacilitatorConfig extends FacilitatorConfig {
|
|
211
|
-
/** Async header builder invoked per facilitator call. Use for short-lived auth tokens (e.g. CDP signed headers). */
|
|
212
|
-
createAcceptsHeaders?: () => Promise<Record<string, string>>;
|
|
213
225
|
}
|
|
214
226
|
/** A facilitator URL or a full `FacilitatorConfig` (URL + auth header builders). */
|
|
215
227
|
type X402FacilitatorTarget = string | X402RouterFacilitatorConfig;
|
|
@@ -419,6 +431,23 @@ interface DiscoveryConfig {
|
|
|
419
431
|
/** Override the OpenAPI `servers` URL. Defaults to `RouterConfig.baseUrl`. Use when the public API hostname differs from the payment realm URL. */
|
|
420
432
|
serverUrl?: string;
|
|
421
433
|
}
|
|
434
|
+
/** Sponsor fee-budget ceilings for fee-sponsored Tempo transactions. Structural mirror of mppx's `FeePayer.Policy`, all fields optional. */
|
|
435
|
+
interface MppFeePayerPolicy {
|
|
436
|
+
maxGas?: bigint;
|
|
437
|
+
maxFeePerGas?: bigint;
|
|
438
|
+
maxPriorityFeePerGas?: bigint;
|
|
439
|
+
maxTotalFee?: bigint;
|
|
440
|
+
maxValidityWindowSeconds?: number;
|
|
441
|
+
}
|
|
442
|
+
/** Server-owned automatic settlement cadence for MPP session channels. Structural mirror of mppx's `SettlementSchedule`. */
|
|
443
|
+
interface MppSettlementSchedule {
|
|
444
|
+
/** Settle after this many additional paid units since the previous settlement. */
|
|
445
|
+
units?: number;
|
|
446
|
+
/** Settle after this much additional billed amount (decimal-dollar string) since the previous settlement. */
|
|
447
|
+
amount?: string;
|
|
448
|
+
/** Settle after this many milliseconds since the previous settlement. */
|
|
449
|
+
intervalMs?: number;
|
|
450
|
+
}
|
|
422
451
|
interface RouterConfig {
|
|
423
452
|
/** 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()`. */
|
|
424
453
|
payeeAddress?: string;
|
|
@@ -454,19 +483,23 @@ interface RouterConfig {
|
|
|
454
483
|
rpcUrl?: string;
|
|
455
484
|
/** Hex private key. Signs channel close/settle; required for `session`. Address MUST equal `recipient`/payee — mppx asserts sender===payee on settle. Validated at init. */
|
|
456
485
|
operatorKey?: string;
|
|
457
|
-
/** 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. */
|
|
486
|
+
/** 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. */
|
|
458
487
|
feePayerKey?: string;
|
|
488
|
+
/** 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. */
|
|
489
|
+
feePayerPolicy?: MppFeePayerPolicy;
|
|
459
490
|
/** Enables MPP payment-channel sessions for `.metered()` routes (registers both request and SSE session middleware). Also requires `mpp.operatorKey`. */
|
|
460
491
|
session?: {
|
|
461
492
|
/** Suggested deposit on the 402 challenge = `tickCost × depositMultiplier` USDC. Route `maxPrice` overrides. @default 10 */
|
|
462
493
|
depositMultiplier?: number;
|
|
494
|
+
/** Server-owned automatic settlement cadence for session channels. Omitted: channels settle only on client close. Thresholds compose (whichever trips first). */
|
|
495
|
+
settlementSchedule?: MppSettlementSchedule;
|
|
463
496
|
};
|
|
464
497
|
};
|
|
465
498
|
/** Payment protocols to accept on paid routes unless overridden per route. @default ['x402'] */
|
|
466
499
|
protocols?: ProtocolType[];
|
|
467
500
|
/** When true, `.route('key')` is rejected (use `.route({ path })`) and custom `key !== path` is rejected. Prevents discovery/openapi drift. */
|
|
468
501
|
strictRoutes?: boolean;
|
|
469
|
-
/** Static metadata for auto-generated discovery surfaces —
|
|
502
|
+
/** Static metadata for auto-generated discovery surfaces — `/openapi.json` (`.openapi()`) and `/llms.txt` (`.llmsTxt()`). Also feeds the deprecated `.wellKnown()` handler. */
|
|
470
503
|
discovery: DiscoveryConfig;
|
|
471
504
|
}
|
|
472
505
|
|
|
@@ -543,14 +576,27 @@ type InputTypeFor<TBody, TQuery> = [TBody] extends [undefined] ? [TQuery] extend
|
|
|
543
576
|
type RequestHandlerFn<TBody, TQuery> = (ctx: HandlerContext<TBody, TQuery>) => Promise<unknown>;
|
|
544
577
|
type UptoHandlerFn<TBody, TQuery> = (ctx: UptoHandlerContext<TBody, TQuery>) => Promise<unknown>;
|
|
545
578
|
type StreamingHandlerFn<TBody, TQuery> = (ctx: StreamingHandlerContext<TBody, TQuery>) => AsyncIterable<unknown>;
|
|
546
|
-
/**
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
579
|
+
/**
|
|
580
|
+
* Pricing-mode discriminator threaded through the builder. `'none'` until a
|
|
581
|
+
* pricing method is chained; then `'exact'` (`.paid()`), `'upto'`, or
|
|
582
|
+
* `'metered'`. Gates repeat pricing calls and picks the handler shape.
|
|
583
|
+
*/
|
|
584
|
+
type BillingMode = 'none' | 'exact' | 'upto' | 'metered';
|
|
585
|
+
/**
|
|
586
|
+
* Identity-mode discriminator threaded through the builder. `'none'` until an
|
|
587
|
+
* identity method is chained; then `'siwx'`, `'apiKey'`, or `'open'`
|
|
588
|
+
* (`.unprotected()`). Gates the mutually-exclusive combinations at compile
|
|
589
|
+
* time, mirroring the registration-time throws.
|
|
590
|
+
*/
|
|
591
|
+
type IdentMode = 'none' | 'siwx' | 'apiKey' | 'open';
|
|
592
|
+
/** Resolves to `TSelf` when a pricing method may be chained, else a `RouteError`. Mirrors the runtime guards in `applyPaid`. */
|
|
593
|
+
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'>;
|
|
594
|
+
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>;
|
|
595
|
+
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'>;
|
|
550
596
|
interface RouteBuilderDefaults {
|
|
551
597
|
protocols?: ProtocolType[];
|
|
552
598
|
}
|
|
553
|
-
declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = undefined,
|
|
599
|
+
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'> {
|
|
554
600
|
#private;
|
|
555
601
|
constructor(key: string, registry: RouteRegistry, deps: RouterDeps, defaults?: RouteBuilderDefaults);
|
|
556
602
|
private fork;
|
|
@@ -562,7 +608,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
562
608
|
* router.route('search').paid('0.01').handler(handler);
|
|
563
609
|
* ```
|
|
564
610
|
*/
|
|
565
|
-
paid(price: string, options?: PaidOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
611
|
+
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'>;
|
|
566
612
|
/**
|
|
567
613
|
* Compute the price from the parsed body before issuing the 402 challenge.
|
|
568
614
|
* Throw an `HttpError` from the pricing function to reject the request
|
|
@@ -576,7 +622,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
576
622
|
* .handler(handler);
|
|
577
623
|
* ```
|
|
578
624
|
*/
|
|
579
|
-
paid<TBodyIn>(fn: (body: TBodyIn) => string | Promise<string>, options?: PaidOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
625
|
+
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'>;
|
|
580
626
|
/**
|
|
581
627
|
* Options-object form of fixed or body-derived pricing. Pass exactly one of:
|
|
582
628
|
*
|
|
@@ -595,9 +641,9 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
595
641
|
* .body(schema).handler(handler);
|
|
596
642
|
* ```
|
|
597
643
|
*/
|
|
598
|
-
paid<T extends PaidArg>(arg: T): RouteBuilder<TBody, TQuery, TOutput,
|
|
644
|
+
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 {
|
|
599
645
|
tiers: Record<string, TierConfig>;
|
|
600
|
-
} ? True : False, HasBody, '
|
|
646
|
+
} ? True : False, HasBody, 'exact'>;
|
|
601
647
|
/**
|
|
602
648
|
* x402-only handler-computed billing. The handler receives `charge(amount)`
|
|
603
649
|
* and the request settles once for the accumulated total, capped at
|
|
@@ -612,7 +658,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
612
658
|
* .handler(async ({ body, charge }) => { await charge('0.001'); ... });
|
|
613
659
|
* ```
|
|
614
660
|
*/
|
|
615
|
-
upTo(arg: string | UpToOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
661
|
+
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'>;
|
|
616
662
|
/**
|
|
617
663
|
* MPP-only per-tick billing. `.handler()` bills exactly `tickCost`;
|
|
618
664
|
* `.stream()` calls `charge()` (no-arg) per yield, settling per tick up to
|
|
@@ -625,7 +671,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
625
671
|
* .stream(async function* ({ charge }) { await charge(); yield 'hi'; });
|
|
626
672
|
* ```
|
|
627
673
|
*/
|
|
628
|
-
metered(options: MeteredOptions): RouteBuilder<TBody, TQuery, TOutput,
|
|
674
|
+
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'>;
|
|
629
675
|
private applyPaid;
|
|
630
676
|
/**
|
|
631
677
|
* Require Sign-In-with-X wallet identity on this route — clients prove
|
|
@@ -641,7 +687,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
641
687
|
* router.route('inbox').paid('0.01').siwx().handler(async ({ wallet }) => getInbox(wallet));
|
|
642
688
|
* ```
|
|
643
689
|
*/
|
|
644
|
-
siwx(): RouteBuilder<TBody, TQuery, TOutput,
|
|
690
|
+
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>;
|
|
645
691
|
/**
|
|
646
692
|
* Require an `X-API-Key` header (or `Authorization: Bearer <key>`); the
|
|
647
693
|
* resolver returns the account record, or `null` for 401. Composes with
|
|
@@ -655,7 +701,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
655
701
|
* .handler(async ({ account }) => db.user.list(account.orgId));
|
|
656
702
|
* ```
|
|
657
703
|
*/
|
|
658
|
-
apiKey(resolver: (key: string) => unknown | Promise<unknown>): RouteBuilder<TBody, TQuery, TOutput,
|
|
704
|
+
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>;
|
|
659
705
|
/**
|
|
660
706
|
* Mark the route as public — no auth, no payment, no SIWX. The handler
|
|
661
707
|
* receives `null` for `wallet`, `payment`, and `account`.
|
|
@@ -665,11 +711,11 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
665
711
|
* router.route('health').unprotected().handler(async () => ({ status: 'ok' }));
|
|
666
712
|
* ```
|
|
667
713
|
*/
|
|
668
|
-
unprotected(): RouteBuilder<TBody, TQuery, TOutput,
|
|
714
|
+
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>;
|
|
669
715
|
/**
|
|
670
716
|
* Tag the route with an upstream provider for discovery and provider-side
|
|
671
|
-
* monitoring. The provider name and config surface in
|
|
672
|
-
*
|
|
717
|
+
* monitoring. The provider name and config surface in OpenAPI discovery
|
|
718
|
+
* output.
|
|
673
719
|
*
|
|
674
720
|
* @example
|
|
675
721
|
* ```ts
|
|
@@ -691,7 +737,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
691
737
|
* .handler(async ({ body }) => search(body.query));
|
|
692
738
|
* ```
|
|
693
739
|
*/
|
|
694
|
-
body<T>(schema: ZodType<T>): RouteBuilder<T, TQuery, TOutput,
|
|
740
|
+
body<T>(schema: ZodType<T>): RouteBuilder<T, TQuery, TOutput, Ident, NeedsBody, True, Bill>;
|
|
695
741
|
/**
|
|
696
742
|
* Declare a query-string Zod schema and switch the route to `GET`. Parsed
|
|
697
743
|
* query is typed as `ctx.query` in the handler. Use `.inputExample()` to
|
|
@@ -703,7 +749,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
703
749
|
* .handler(async ({ query }) => getById(query.id));
|
|
704
750
|
* ```
|
|
705
751
|
*/
|
|
706
|
-
query<T>(schema: ZodType<T>): RouteBuilder<TBody, T, TOutput,
|
|
752
|
+
query<T>(schema: ZodType<T>): RouteBuilder<TBody, T, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
707
753
|
/**
|
|
708
754
|
* Declare the response output's Zod schema for OpenAPI generation. The
|
|
709
755
|
* runtime does not validate handler return values — use Zod's `.parse()`
|
|
@@ -716,7 +762,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
716
762
|
* .handler(async () => ({ result: 'ok' }));
|
|
717
763
|
* ```
|
|
718
764
|
*/
|
|
719
|
-
output<T>(schema: ZodType<T>): RouteBuilder<TBody, TQuery, T,
|
|
765
|
+
output<T>(schema: ZodType<T>): RouteBuilder<TBody, TQuery, T, Ident, NeedsBody, HasBody, Bill>;
|
|
720
766
|
/**
|
|
721
767
|
* Attach an example of the request body or query for discovery output,
|
|
722
768
|
* validated against the registered schema at registration.
|
|
@@ -726,7 +772,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
726
772
|
* .body(searchSchema).inputExample({ query: 'cats' });
|
|
727
773
|
* ```
|
|
728
774
|
*/
|
|
729
|
-
inputExample(example: InputTypeFor<TBody, TQuery> & JsonObject): RouteBuilder<TBody, TQuery, TOutput,
|
|
775
|
+
inputExample(example: InputTypeFor<TBody, TQuery> & JsonObject): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
730
776
|
/**
|
|
731
777
|
* Attach an example response for discovery output, validated against the
|
|
732
778
|
* registered output schema at registration.
|
|
@@ -736,10 +782,10 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
736
782
|
* .output(resultSchema).outputExample({ result: 'ok' });
|
|
737
783
|
* ```
|
|
738
784
|
*/
|
|
739
|
-
outputExample(example: TOutput & JsonValue): RouteBuilder<TBody, TQuery, TOutput,
|
|
785
|
+
outputExample(example: TOutput & JsonValue): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
740
786
|
/**
|
|
741
|
-
* Set a human-readable summary of the route. Surfaces in OpenAPI
|
|
742
|
-
* `
|
|
787
|
+
* Set a human-readable summary of the route. Surfaces in OpenAPI and
|
|
788
|
+
* `llms.txt` discovery output.
|
|
743
789
|
*
|
|
744
790
|
* @example
|
|
745
791
|
* ```ts
|
|
@@ -781,7 +827,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
781
827
|
* });
|
|
782
828
|
* ```
|
|
783
829
|
*/
|
|
784
|
-
validate(fn: (body: TBody) => void | Promise<void>): RouteBuilder<TBody, TQuery, TOutput,
|
|
830
|
+
validate(fn: (body: TBody) => void | Promise<void>): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
785
831
|
/**
|
|
786
832
|
* Override MPP protocol metadata and per-route MPP settlement options.
|
|
787
833
|
* Merges with any `mpp` options passed to `.paid()`. Use on auto-priced routes
|
|
@@ -795,7 +841,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
795
841
|
* .handler(handler);
|
|
796
842
|
* ```
|
|
797
843
|
*/
|
|
798
|
-
mpp(info: MppProtocolInfo): RouteBuilder<TBody, TQuery, TOutput,
|
|
844
|
+
mpp(info: MppProtocolInfo): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
799
845
|
/**
|
|
800
846
|
* Hook into the settlement lifecycle. `beforeSettle` runs after the handler
|
|
801
847
|
* succeeds but before on-chain settlement and can cancel the charge;
|
|
@@ -809,7 +855,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
809
855
|
* });
|
|
810
856
|
* ```
|
|
811
857
|
*/
|
|
812
|
-
settlement(lifecycle: SettlementLifecycle<TBody>): RouteBuilder<TBody, TQuery, TOutput,
|
|
858
|
+
settlement(lifecycle: SettlementLifecycle<TBody>): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
813
859
|
/**
|
|
814
860
|
* Register the request handler and return the Next.js route function. The
|
|
815
861
|
* handler receives a typed context and may return a value (serialized to
|
|
@@ -824,7 +870,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
824
870
|
* .handler(async ({ body, wallet }) => searchService(body, wallet));
|
|
825
871
|
* ```
|
|
826
872
|
*/
|
|
827
|
-
handler(fn: HandlerArg<TBody, TQuery,
|
|
873
|
+
handler(fn: HandlerArg<TBody, TQuery, Ident, NeedsBody, HasBody, Bill>): (request: NextRequest) => Promise<Response>;
|
|
828
874
|
/**
|
|
829
875
|
* Register a streaming handler (`async function*`) and return the Next.js
|
|
830
876
|
* route function. Each `charge()` call bills one tick (`tickCost` USDC) up
|
|
@@ -844,7 +890,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
844
890
|
* });
|
|
845
891
|
* ```
|
|
846
892
|
*/
|
|
847
|
-
stream(fn: StreamArg<TBody, TQuery,
|
|
893
|
+
stream(fn: StreamArg<TBody, TQuery, Ident, NeedsBody, HasBody, Bill>): (request: NextRequest) => Promise<Response>;
|
|
848
894
|
private register;
|
|
849
895
|
}
|
|
850
896
|
|
|
@@ -861,7 +907,7 @@ interface RouterConfigIssue {
|
|
|
861
907
|
interface CreateRouterFromEnvOptions<TPrices extends Record<string, string> = Record<never, string>> {
|
|
862
908
|
/** Defaults to `process.env`. Pass an explicit object in tests. */
|
|
863
909
|
env?: Record<string, string | undefined>;
|
|
864
|
-
/** Discovery title. Shown in
|
|
910
|
+
/** Discovery title. Shown in `/openapi.json` and `/llms.txt`. */
|
|
865
911
|
title: string;
|
|
866
912
|
/** Discovery description. */
|
|
867
913
|
description: string;
|
|
@@ -871,7 +917,7 @@ interface CreateRouterFromEnvOptions<TPrices extends Record<string, string> = Re
|
|
|
871
917
|
version?: string;
|
|
872
918
|
/** Optional contact metadata published in discovery. */
|
|
873
919
|
contact?: DiscoveryConfig['contact'];
|
|
874
|
-
/** Optional ownership proofs published in
|
|
920
|
+
/** Optional ownership proofs published in `/openapi.json` (and the deprecated `/.well-known/x402`). */
|
|
875
921
|
ownershipProofs?: string[];
|
|
876
922
|
/** Per-route HTTP method hint visibility. */
|
|
877
923
|
methodHints?: DiscoveryConfig['methodHints'];
|
|
@@ -924,7 +970,7 @@ declare const BASE_USDC_DECIMALS = 6;
|
|
|
924
970
|
/** All-zeros EVM address. Used as a placeholder/sentinel; not a valid payee. */
|
|
925
971
|
declare const ZERO_EVM_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
926
972
|
/** Public Solana x402 facilitator. Override per-deployment via `SOLANA_FACILITATOR_URL`. */
|
|
927
|
-
declare const DEFAULT_SOLANA_FACILITATOR_URL = "https://facilitator.
|
|
973
|
+
declare const DEFAULT_SOLANA_FACILITATOR_URL = "https://facilitator.payai.network";
|
|
928
974
|
/** Public Tempo JSON-RPC endpoint used for MPP on-chain verification. Override per-deployment via `TEMPO_RPC_URL`. */
|
|
929
975
|
declare const DEFAULT_TEMPO_RPC_URL = "https://rpc.tempo.xyz";
|
|
930
976
|
|
|
@@ -937,10 +983,19 @@ interface MonitorEntry {
|
|
|
937
983
|
critical?: number;
|
|
938
984
|
}
|
|
939
985
|
interface ServiceRouter<TPriceKeys extends string = never> {
|
|
940
|
-
route<K extends string>(keyOrDefinition: K | RouteDefinition<K>): [K] extends [TPriceKeys] ? RouteBuilder<undefined, undefined, undefined,
|
|
986
|
+
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'>;
|
|
987
|
+
/**
|
|
988
|
+
* @deprecated The `/.well-known/x402` surface is no longer a recommended
|
|
989
|
+
* discovery location. The handler keeps working for legacy x402 clients,
|
|
990
|
+
* but new integrations should mount `.openapi()` (at `/openapi.json`) and
|
|
991
|
+
* `.llmsTxt()` (at `/llms.txt`) instead.
|
|
992
|
+
*/
|
|
941
993
|
wellKnown(): (request: NextRequest) => Promise<NextResponse>;
|
|
994
|
+
/** OpenAPI 3.1 discovery document. Mount at `GET /openapi.json`. */
|
|
942
995
|
openapi(): (request: NextRequest) => Promise<NextResponse>;
|
|
996
|
+
/** Plain-text agent guidance. Mount at `GET /llms.txt`. */
|
|
943
997
|
llmsTxt(): (request: NextRequest) => Promise<NextResponse>;
|
|
998
|
+
/** JSON 404 fallback with rediscovery links. Mount in a catch-all route. */
|
|
944
999
|
notFound(): (request: NextRequest) => Promise<NextResponse>;
|
|
945
1000
|
monitors(): MonitorEntry[];
|
|
946
1001
|
registry: RouteRegistry;
|
|
@@ -970,4 +1025,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
|
|
|
970
1025
|
*/
|
|
971
1026
|
declare function createRouterFromEnv<const P extends Record<string, string> = Record<never, string>>(options: CreateRouterFromEnvOptions<P>): ServiceRouter<Extract<keyof P, string>>;
|
|
972
1027
|
|
|
973
|
-
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 };
|
|
1028
|
+
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 };
|