@agentcash/router 1.12.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 +91 -34
- package/dist/index.d.ts +91 -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;
|
|
@@ -419,6 +433,23 @@ interface DiscoveryConfig {
|
|
|
419
433
|
/** Override the OpenAPI `servers` URL. Defaults to `RouterConfig.baseUrl`. Use when the public API hostname differs from the payment realm URL. */
|
|
420
434
|
serverUrl?: string;
|
|
421
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
|
+
}
|
|
422
453
|
interface RouterConfig {
|
|
423
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()`. */
|
|
424
455
|
payeeAddress?: string;
|
|
@@ -454,19 +485,23 @@ interface RouterConfig {
|
|
|
454
485
|
rpcUrl?: string;
|
|
455
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. */
|
|
456
487
|
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. */
|
|
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. */
|
|
458
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;
|
|
459
492
|
/** Enables MPP payment-channel sessions for `.metered()` routes (registers both request and SSE session middleware). Also requires `mpp.operatorKey`. */
|
|
460
493
|
session?: {
|
|
461
494
|
/** Suggested deposit on the 402 challenge = `tickCost × depositMultiplier` USDC. Route `maxPrice` overrides. @default 10 */
|
|
462
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;
|
|
463
498
|
};
|
|
464
499
|
};
|
|
465
500
|
/** Payment protocols to accept on paid routes unless overridden per route. @default ['x402'] */
|
|
466
501
|
protocols?: ProtocolType[];
|
|
467
502
|
/** When true, `.route('key')` is rejected (use `.route({ path })`) and custom `key !== path` is rejected. Prevents discovery/openapi drift. */
|
|
468
503
|
strictRoutes?: boolean;
|
|
469
|
-
/** 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. */
|
|
470
505
|
discovery: DiscoveryConfig;
|
|
471
506
|
}
|
|
472
507
|
|
|
@@ -543,14 +578,27 @@ type InputTypeFor<TBody, TQuery> = [TBody] extends [undefined] ? [TQuery] extend
|
|
|
543
578
|
type RequestHandlerFn<TBody, TQuery> = (ctx: HandlerContext<TBody, TQuery>) => Promise<unknown>;
|
|
544
579
|
type UptoHandlerFn<TBody, TQuery> = (ctx: UptoHandlerContext<TBody, TQuery>) => Promise<unknown>;
|
|
545
580
|
type StreamingHandlerFn<TBody, TQuery> = (ctx: StreamingHandlerContext<TBody, TQuery>) => AsyncIterable<unknown>;
|
|
546
|
-
/**
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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'>;
|
|
550
598
|
interface RouteBuilderDefaults {
|
|
551
599
|
protocols?: ProtocolType[];
|
|
552
600
|
}
|
|
553
|
-
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'> {
|
|
554
602
|
#private;
|
|
555
603
|
constructor(key: string, registry: RouteRegistry, deps: RouterDeps, defaults?: RouteBuilderDefaults);
|
|
556
604
|
private fork;
|
|
@@ -562,7 +610,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
562
610
|
* router.route('search').paid('0.01').handler(handler);
|
|
563
611
|
* ```
|
|
564
612
|
*/
|
|
565
|
-
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'>;
|
|
566
614
|
/**
|
|
567
615
|
* Compute the price from the parsed body before issuing the 402 challenge.
|
|
568
616
|
* Throw an `HttpError` from the pricing function to reject the request
|
|
@@ -576,7 +624,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
576
624
|
* .handler(handler);
|
|
577
625
|
* ```
|
|
578
626
|
*/
|
|
579
|
-
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'>;
|
|
580
628
|
/**
|
|
581
629
|
* Options-object form of fixed or body-derived pricing. Pass exactly one of:
|
|
582
630
|
*
|
|
@@ -595,9 +643,9 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
595
643
|
* .body(schema).handler(handler);
|
|
596
644
|
* ```
|
|
597
645
|
*/
|
|
598
|
-
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 {
|
|
599
647
|
tiers: Record<string, TierConfig>;
|
|
600
|
-
} ? True : False, HasBody, '
|
|
648
|
+
} ? True : False, HasBody, 'exact'>;
|
|
601
649
|
/**
|
|
602
650
|
* x402-only handler-computed billing. The handler receives `charge(amount)`
|
|
603
651
|
* and the request settles once for the accumulated total, capped at
|
|
@@ -612,7 +660,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
612
660
|
* .handler(async ({ body, charge }) => { await charge('0.001'); ... });
|
|
613
661
|
* ```
|
|
614
662
|
*/
|
|
615
|
-
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'>;
|
|
616
664
|
/**
|
|
617
665
|
* MPP-only per-tick billing. `.handler()` bills exactly `tickCost`;
|
|
618
666
|
* `.stream()` calls `charge()` (no-arg) per yield, settling per tick up to
|
|
@@ -625,7 +673,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
625
673
|
* .stream(async function* ({ charge }) { await charge(); yield 'hi'; });
|
|
626
674
|
* ```
|
|
627
675
|
*/
|
|
628
|
-
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'>;
|
|
629
677
|
private applyPaid;
|
|
630
678
|
/**
|
|
631
679
|
* Require Sign-In-with-X wallet identity on this route — clients prove
|
|
@@ -641,7 +689,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
641
689
|
* router.route('inbox').paid('0.01').siwx().handler(async ({ wallet }) => getInbox(wallet));
|
|
642
690
|
* ```
|
|
643
691
|
*/
|
|
644
|
-
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>;
|
|
645
693
|
/**
|
|
646
694
|
* Require an `X-API-Key` header (or `Authorization: Bearer <key>`); the
|
|
647
695
|
* resolver returns the account record, or `null` for 401. Composes with
|
|
@@ -655,7 +703,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
655
703
|
* .handler(async ({ account }) => db.user.list(account.orgId));
|
|
656
704
|
* ```
|
|
657
705
|
*/
|
|
658
|
-
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>;
|
|
659
707
|
/**
|
|
660
708
|
* Mark the route as public — no auth, no payment, no SIWX. The handler
|
|
661
709
|
* receives `null` for `wallet`, `payment`, and `account`.
|
|
@@ -665,11 +713,11 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
665
713
|
* router.route('health').unprotected().handler(async () => ({ status: 'ok' }));
|
|
666
714
|
* ```
|
|
667
715
|
*/
|
|
668
|
-
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>;
|
|
669
717
|
/**
|
|
670
718
|
* Tag the route with an upstream provider for discovery and provider-side
|
|
671
|
-
* monitoring. The provider name and config surface in
|
|
672
|
-
*
|
|
719
|
+
* monitoring. The provider name and config surface in OpenAPI discovery
|
|
720
|
+
* output.
|
|
673
721
|
*
|
|
674
722
|
* @example
|
|
675
723
|
* ```ts
|
|
@@ -691,7 +739,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
691
739
|
* .handler(async ({ body }) => search(body.query));
|
|
692
740
|
* ```
|
|
693
741
|
*/
|
|
694
|
-
body<T>(schema: ZodType<T>): RouteBuilder<T, TQuery, TOutput,
|
|
742
|
+
body<T>(schema: ZodType<T>): RouteBuilder<T, TQuery, TOutput, Ident, NeedsBody, True, Bill>;
|
|
695
743
|
/**
|
|
696
744
|
* Declare a query-string Zod schema and switch the route to `GET`. Parsed
|
|
697
745
|
* query is typed as `ctx.query` in the handler. Use `.inputExample()` to
|
|
@@ -703,7 +751,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
703
751
|
* .handler(async ({ query }) => getById(query.id));
|
|
704
752
|
* ```
|
|
705
753
|
*/
|
|
706
|
-
query<T>(schema: ZodType<T>): RouteBuilder<TBody, T, TOutput,
|
|
754
|
+
query<T>(schema: ZodType<T>): RouteBuilder<TBody, T, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
707
755
|
/**
|
|
708
756
|
* Declare the response output's Zod schema for OpenAPI generation. The
|
|
709
757
|
* runtime does not validate handler return values — use Zod's `.parse()`
|
|
@@ -716,7 +764,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
716
764
|
* .handler(async () => ({ result: 'ok' }));
|
|
717
765
|
* ```
|
|
718
766
|
*/
|
|
719
|
-
output<T>(schema: ZodType<T>): RouteBuilder<TBody, TQuery, T,
|
|
767
|
+
output<T>(schema: ZodType<T>): RouteBuilder<TBody, TQuery, T, Ident, NeedsBody, HasBody, Bill>;
|
|
720
768
|
/**
|
|
721
769
|
* Attach an example of the request body or query for discovery output,
|
|
722
770
|
* validated against the registered schema at registration.
|
|
@@ -726,7 +774,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
726
774
|
* .body(searchSchema).inputExample({ query: 'cats' });
|
|
727
775
|
* ```
|
|
728
776
|
*/
|
|
729
|
-
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>;
|
|
730
778
|
/**
|
|
731
779
|
* Attach an example response for discovery output, validated against the
|
|
732
780
|
* registered output schema at registration.
|
|
@@ -736,10 +784,10 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
736
784
|
* .output(resultSchema).outputExample({ result: 'ok' });
|
|
737
785
|
* ```
|
|
738
786
|
*/
|
|
739
|
-
outputExample(example: TOutput & JsonValue): RouteBuilder<TBody, TQuery, TOutput,
|
|
787
|
+
outputExample(example: TOutput & JsonValue): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
740
788
|
/**
|
|
741
|
-
* Set a human-readable summary of the route. Surfaces in OpenAPI
|
|
742
|
-
* `
|
|
789
|
+
* Set a human-readable summary of the route. Surfaces in OpenAPI and
|
|
790
|
+
* `llms.txt` discovery output.
|
|
743
791
|
*
|
|
744
792
|
* @example
|
|
745
793
|
* ```ts
|
|
@@ -781,7 +829,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
781
829
|
* });
|
|
782
830
|
* ```
|
|
783
831
|
*/
|
|
784
|
-
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>;
|
|
785
833
|
/**
|
|
786
834
|
* Override MPP protocol metadata and per-route MPP settlement options.
|
|
787
835
|
* Merges with any `mpp` options passed to `.paid()`. Use on auto-priced routes
|
|
@@ -795,7 +843,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
795
843
|
* .handler(handler);
|
|
796
844
|
* ```
|
|
797
845
|
*/
|
|
798
|
-
mpp(info: MppProtocolInfo): RouteBuilder<TBody, TQuery, TOutput,
|
|
846
|
+
mpp(info: MppProtocolInfo): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
799
847
|
/**
|
|
800
848
|
* Hook into the settlement lifecycle. `beforeSettle` runs after the handler
|
|
801
849
|
* succeeds but before on-chain settlement and can cancel the charge;
|
|
@@ -809,7 +857,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
809
857
|
* });
|
|
810
858
|
* ```
|
|
811
859
|
*/
|
|
812
|
-
settlement(lifecycle: SettlementLifecycle<TBody>): RouteBuilder<TBody, TQuery, TOutput,
|
|
860
|
+
settlement(lifecycle: SettlementLifecycle<TBody>): RouteBuilder<TBody, TQuery, TOutput, Ident, NeedsBody, HasBody, Bill>;
|
|
813
861
|
/**
|
|
814
862
|
* Register the request handler and return the Next.js route function. The
|
|
815
863
|
* handler receives a typed context and may return a value (serialized to
|
|
@@ -824,7 +872,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
824
872
|
* .handler(async ({ body, wallet }) => searchService(body, wallet));
|
|
825
873
|
* ```
|
|
826
874
|
*/
|
|
827
|
-
handler(fn: HandlerArg<TBody, TQuery,
|
|
875
|
+
handler(fn: HandlerArg<TBody, TQuery, Ident, NeedsBody, HasBody, Bill>): (request: NextRequest) => Promise<Response>;
|
|
828
876
|
/**
|
|
829
877
|
* Register a streaming handler (`async function*`) and return the Next.js
|
|
830
878
|
* route function. Each `charge()` call bills one tick (`tickCost` USDC) up
|
|
@@ -844,7 +892,7 @@ declare class RouteBuilder<TBody = undefined, TQuery = undefined, TOutput = unde
|
|
|
844
892
|
* });
|
|
845
893
|
* ```
|
|
846
894
|
*/
|
|
847
|
-
stream(fn: StreamArg<TBody, TQuery,
|
|
895
|
+
stream(fn: StreamArg<TBody, TQuery, Ident, NeedsBody, HasBody, Bill>): (request: NextRequest) => Promise<Response>;
|
|
848
896
|
private register;
|
|
849
897
|
}
|
|
850
898
|
|
|
@@ -861,7 +909,7 @@ interface RouterConfigIssue {
|
|
|
861
909
|
interface CreateRouterFromEnvOptions<TPrices extends Record<string, string> = Record<never, string>> {
|
|
862
910
|
/** Defaults to `process.env`. Pass an explicit object in tests. */
|
|
863
911
|
env?: Record<string, string | undefined>;
|
|
864
|
-
/** Discovery title. Shown in
|
|
912
|
+
/** Discovery title. Shown in `/openapi.json` and `/llms.txt`. */
|
|
865
913
|
title: string;
|
|
866
914
|
/** Discovery description. */
|
|
867
915
|
description: string;
|
|
@@ -871,7 +919,7 @@ interface CreateRouterFromEnvOptions<TPrices extends Record<string, string> = Re
|
|
|
871
919
|
version?: string;
|
|
872
920
|
/** Optional contact metadata published in discovery. */
|
|
873
921
|
contact?: DiscoveryConfig['contact'];
|
|
874
|
-
/** Optional ownership proofs published in
|
|
922
|
+
/** Optional ownership proofs published in `/openapi.json` (and the deprecated `/.well-known/x402`). */
|
|
875
923
|
ownershipProofs?: string[];
|
|
876
924
|
/** Per-route HTTP method hint visibility. */
|
|
877
925
|
methodHints?: DiscoveryConfig['methodHints'];
|
|
@@ -937,10 +985,19 @@ interface MonitorEntry {
|
|
|
937
985
|
critical?: number;
|
|
938
986
|
}
|
|
939
987
|
interface ServiceRouter<TPriceKeys extends string = never> {
|
|
940
|
-
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
|
+
*/
|
|
941
995
|
wellKnown(): (request: NextRequest) => Promise<NextResponse>;
|
|
996
|
+
/** OpenAPI 3.1 discovery document. Mount at `GET /openapi.json`. */
|
|
942
997
|
openapi(): (request: NextRequest) => Promise<NextResponse>;
|
|
998
|
+
/** Plain-text agent guidance. Mount at `GET /llms.txt`. */
|
|
943
999
|
llmsTxt(): (request: NextRequest) => Promise<NextResponse>;
|
|
1000
|
+
/** JSON 404 fallback with rediscovery links. Mount in a catch-all route. */
|
|
944
1001
|
notFound(): (request: NextRequest) => Promise<NextResponse>;
|
|
945
1002
|
monitors(): MonitorEntry[];
|
|
946
1003
|
registry: RouteRegistry;
|
|
@@ -970,4 +1027,4 @@ declare function createRouter<const P extends Record<string, string> = Record<ne
|
|
|
970
1027
|
*/
|
|
971
1028
|
declare function createRouterFromEnv<const P extends Record<string, string> = Record<never, string>>(options: CreateRouterFromEnvOptions<P>): ServiceRouter<Extract<keyof P, string>>;
|
|
972
1029
|
|
|
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 };
|
|
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 };
|