@haven_ai/sdk 0.1.20-alpha.0 → 0.1.22-alpha.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 +479 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +370 -7
- package/dist/index.d.ts +370 -7
- package/dist/index.js +470 -87
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -65,6 +65,11 @@ interface HavenClientConfig {
|
|
|
65
65
|
x402Wallet?: string;
|
|
66
66
|
/** Timeout in ms for individual HTTP requests (default: 30000) */
|
|
67
67
|
requestTimeout?: number;
|
|
68
|
+
/** Timeout (ms) for MERCHANT-facing requests — x402/MPP probes, MCP
|
|
69
|
+
* handshakes, paid retries. Separate from requestTimeout (Haven API):
|
|
70
|
+
* merchants may settle on-chain synchronously, so the default is
|
|
71
|
+
* deliberately generous. #1300. */
|
|
72
|
+
merchantTimeout?: number;
|
|
68
73
|
/** Timeout in ms when polling for tx confirmation (default: 90000) */
|
|
69
74
|
confirmationTimeout?: number;
|
|
70
75
|
/** Polling interval in ms when waiting for confirmation (default: 3000) */
|
|
@@ -101,6 +106,12 @@ interface PaymentRequest {
|
|
|
101
106
|
amount: string;
|
|
102
107
|
/** Recipient Ethereum address (0x...) */
|
|
103
108
|
to: string;
|
|
109
|
+
/**
|
|
110
|
+
* Optional dedupe key (#1207): a retried request with the same key returns
|
|
111
|
+
* the FIRST request's result instead of minting a second transfer or a
|
|
112
|
+
* second approval. Same contract as /machine-payments/send. Max 128 chars.
|
|
113
|
+
*/
|
|
114
|
+
idempotencyKey?: string;
|
|
104
115
|
}
|
|
105
116
|
interface SignData {
|
|
106
117
|
/** The hash to sign (keccak256, 0x-prefixed) */
|
|
@@ -251,6 +262,14 @@ interface X402Receipt {
|
|
|
251
262
|
interface X402AuthorizationOptions {
|
|
252
263
|
/** Stable caller-supplied key for this user intent. Prevents duplicate approvals across fresh 402 quotes. */
|
|
253
264
|
idempotencyKey?: string;
|
|
265
|
+
/**
|
|
266
|
+
* #1307: the merchant MCP-tool call context this quote was made against
|
|
267
|
+
* (merchant_url, tool_name, arguments, mcp_transport). Persisted on the
|
|
268
|
+
* intent so `getX402MerchantCallContext` can rehydrate it by payment_id at
|
|
269
|
+
* settle/complete time instead of the caller re-threading it. Optional —
|
|
270
|
+
* omit for a non-MCP-tool x402 merchant (plain HTTP resource).
|
|
271
|
+
*/
|
|
272
|
+
mcpCallContext?: X402McpCallContext;
|
|
254
273
|
}
|
|
255
274
|
/**
|
|
256
275
|
* Keyless x402 construct result.
|
|
@@ -346,6 +365,30 @@ interface X402McpTransport {
|
|
|
346
365
|
handshakeRequired: boolean;
|
|
347
366
|
source: 'path' | 'bazaar';
|
|
348
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* #1307: the merchant MCP-tool call an x402 quote was made against — carried
|
|
370
|
+
* through `createX402Intent`'s options so Haven can persist it for the
|
|
371
|
+
* settle-leg rehydration handoff (`getX402MerchantCallContext`). Convenience
|
|
372
|
+
* metadata for retrying the merchant's OWN JSON-RPC call, never payment
|
|
373
|
+
* authority.
|
|
374
|
+
*/
|
|
375
|
+
interface X402McpCallContext {
|
|
376
|
+
merchantUrl: string;
|
|
377
|
+
toolName: string;
|
|
378
|
+
arguments?: Record<string, unknown>;
|
|
379
|
+
mcpTransport?: X402McpTransport;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Response shape of `getX402MerchantCallContext` — the stored merchant call
|
|
383
|
+
* context for a payment_id, rehydrated instead of re-threaded (#1307).
|
|
384
|
+
*/
|
|
385
|
+
interface X402MerchantCallContext {
|
|
386
|
+
paymentId: string;
|
|
387
|
+
merchantUrl: string;
|
|
388
|
+
toolName: string;
|
|
389
|
+
arguments: Record<string, unknown>;
|
|
390
|
+
mcpTransport?: X402McpTransport;
|
|
391
|
+
}
|
|
349
392
|
/** Quote parsed from an HTTP 402 response without creating a Haven payment. */
|
|
350
393
|
interface X402Quote {
|
|
351
394
|
rail: 'x402';
|
|
@@ -510,6 +553,14 @@ interface HavenAgent {
|
|
|
510
553
|
safeAddress: string;
|
|
511
554
|
delegateAddress: string;
|
|
512
555
|
chainId: number;
|
|
556
|
+
/**
|
|
557
|
+
* Which on-chain policy primitive gates this agent's spend (#1306): the
|
|
558
|
+
* legacy Safe AllowanceModule (import-only accounts) or the delegation
|
|
559
|
+
* rail's active budget delegations (#1090). Read-only reporting — the
|
|
560
|
+
* on-chain state is the actual gate either way, this only says which
|
|
561
|
+
* mechanism a caller should read/derive from.
|
|
562
|
+
*/
|
|
563
|
+
executionRail: 'legacy' | 'delegation';
|
|
513
564
|
}
|
|
514
565
|
interface HavenAllowance {
|
|
515
566
|
id: string;
|
|
@@ -526,6 +577,15 @@ interface HavenAllowance {
|
|
|
526
577
|
lastResetMin: number;
|
|
527
578
|
nonce: number;
|
|
528
579
|
isResetPending: boolean;
|
|
580
|
+
/**
|
|
581
|
+
* Delegation rail only (#1319, provenance for #1145's fallback): true
|
|
582
|
+
* when `remaining` came from a live on-chain enforcer read, false when
|
|
583
|
+
* the read failed and `remaining` is the fallback full configured
|
|
584
|
+
* budget. Undefined on the legacy AllowanceModule rail, which has no
|
|
585
|
+
* fallback concept. Reporting only — the on-chain policy remains the
|
|
586
|
+
* actual spend gate either way.
|
|
587
|
+
*/
|
|
588
|
+
remainingIsFromChain?: boolean;
|
|
529
589
|
};
|
|
530
590
|
}
|
|
531
591
|
interface HavenAllowanceSummary {
|
|
@@ -535,6 +595,34 @@ interface HavenAllowanceSummary {
|
|
|
535
595
|
chainId: number;
|
|
536
596
|
allowances: HavenAllowance[];
|
|
537
597
|
}
|
|
598
|
+
/**
|
|
599
|
+
* Post-purchase allowance/budget summary attached to a settled x402 payment
|
|
600
|
+
* (#1310). Read-only reporting — the on-chain policy remains the actual
|
|
601
|
+
* spend gate either way, this only says what is left after the purchase.
|
|
602
|
+
*
|
|
603
|
+
* Deliberately the SAME rail-labeled field spelling as #1306's
|
|
604
|
+
* catalog-purchase preflight `allowance` block (never a new spelling),
|
|
605
|
+
* minus the preflight-only `sufficient` field: post-purchase reporting
|
|
606
|
+
* answers "what is left", not "was this purchase covered". Read through the
|
|
607
|
+
* exact same source as {@link HavenAllowanceSummary} / `haven_get_allowances`
|
|
608
|
+
* (`GET /machine-payments/allowances`; delegation-rail values are the #1090
|
|
609
|
+
* `deriveDelegationBudgets`-backed enforcer read, never `agent_allowances`),
|
|
610
|
+
* so this can never disagree with `haven_get_allowances` for the same
|
|
611
|
+
* fixture.
|
|
612
|
+
*/
|
|
613
|
+
interface PostPurchaseAllowanceSummary {
|
|
614
|
+
/** Which on-chain policy primitive gates this agent's spend (#1306 labeling). */
|
|
615
|
+
rail: 'legacy' | 'delegation';
|
|
616
|
+
/** Remaining atomic units, read through the same source as {@link HavenAllowance.onchain.remaining}. */
|
|
617
|
+
remaining_atomic: string;
|
|
618
|
+
/** Human-readable remaining, e.g. "4.96 USDC". Omitted when the token's decimals are unknown. */
|
|
619
|
+
remaining_display?: string;
|
|
620
|
+
token_symbol?: string;
|
|
621
|
+
token_address?: string;
|
|
622
|
+
/** Minutes — mirrors {@link HavenAllowance.resetPeriodMin} / the delegation's period. */
|
|
623
|
+
reset_period?: number;
|
|
624
|
+
source: 'allowance_module' | 'active_delegations';
|
|
625
|
+
}
|
|
538
626
|
/**
|
|
539
627
|
* Affirmative spend-readiness for the authenticated agent, derived from the raw
|
|
540
628
|
* agent status plus the remaining spend authority the backend reports per rail
|
|
@@ -695,6 +783,8 @@ declare const AgentPaymentNextAction: {
|
|
|
695
783
|
readonly StopAndTellUser: "stop_and_tell_user";
|
|
696
784
|
/** Ask again only if the user still wants the payment after expiry. */
|
|
697
785
|
readonly RequestAgainIfUserStillWantsIt: "request_again_if_user_still_wants_it";
|
|
786
|
+
/** #1307: retry the SAME tool call, supplying the explicit context fields the server could not rehydrate. */
|
|
787
|
+
readonly RetryWithExplicitContext: "retry_with_explicit_context";
|
|
698
788
|
/**
|
|
699
789
|
* The x402 funding/quote window expired. Re-quote the same logical merchant
|
|
700
790
|
* operation with the same idempotency key to stay double-charge-safe.
|
|
@@ -721,6 +811,20 @@ declare const AgentPaymentFailureCode: {
|
|
|
721
811
|
readonly PaymentWindowExpired: "PAYMENT_WINDOW_EXPIRED";
|
|
722
812
|
/** The Haven funding leg succeeded, but the merchant rejected the paid retry. */
|
|
723
813
|
readonly MerchantRejectedAfterFunding: "MERCHANT_REJECTED_AFTER_FUNDING";
|
|
814
|
+
/** #1300 review: funding is on-chain but the merchant never ANSWERED the
|
|
815
|
+
* paid retry within the timeout. NOT proof of rejection — the merchant
|
|
816
|
+
* holds a valid EIP-3009 authorization and may still settle late, so the
|
|
817
|
+
* guidance is verify-then-sweep, never blind sweep. */
|
|
818
|
+
readonly MerchantUnresponsiveAfterFunding: "MERCHANT_UNRESPONSIVE_AFTER_FUNDING";
|
|
819
|
+
/**
|
|
820
|
+
* #1307: the caller omitted merchant_url/tool_name (asking Haven to
|
|
821
|
+
* rehydrate the stored MCP merchant-call context by payment_id), but no
|
|
822
|
+
* usable context was stored for this intent — either it was never an
|
|
823
|
+
* MCP-tool quote, or the stored context is incomplete. The fallback is
|
|
824
|
+
* mechanical: re-send merchant_url, tool_name, arguments, and
|
|
825
|
+
* mcp_transport explicitly (the version-skew path).
|
|
826
|
+
*/
|
|
827
|
+
readonly MerchantCallContextUnavailable: "MERCHANT_CALL_CONTEXT_UNAVAILABLE";
|
|
724
828
|
};
|
|
725
829
|
type AgentPaymentFailureCode = (typeof AgentPaymentFailureCode)[keyof typeof AgentPaymentFailureCode];
|
|
726
830
|
/**
|
|
@@ -761,12 +865,83 @@ type AgentPaymentRail = (typeof AgentPaymentRail)[keyof typeof AgentPaymentRail]
|
|
|
761
865
|
type PaymentPhase = AgentPaymentPhase;
|
|
762
866
|
type PaymentNextAction = AgentPaymentNextAction;
|
|
763
867
|
declare const AGENT_PAYMENT_PHASE_VALUES: ("rejected" | "expired" | "failed" | "agent_signature_required" | "payment_submitted" | "payment_confirmed" | "user_approval_required" | "user_execution_required" | "waiting_for_additional_approvals" | "funding_sent" | "insufficient_funds" | "funded_but_unsettled")[];
|
|
764
|
-
declare const AGENT_PAYMENT_NEXT_ACTION_VALUES: ("sign_and_submit_payment" | "check_status_later" | "none" | "wait_for_user_approval" | "wait_for_user_to_complete_payment" | "retry_original_x402_request" | "stop_and_tell_user" | "request_again_if_user_still_wants_it" | "payment_window_expired" | "fund_safe_or_raise_allowance" | "sweep_stranded_funds")[];
|
|
765
|
-
declare const AGENT_PAYMENT_FAILURE_CODE_VALUES: ("PRICE_EXCEEDS_MAX" | "PAYMENT_WINDOW_EXPIRED" | "MERCHANT_REJECTED_AFTER_FUNDING")[];
|
|
868
|
+
declare const AGENT_PAYMENT_NEXT_ACTION_VALUES: ("sign_and_submit_payment" | "check_status_later" | "none" | "wait_for_user_approval" | "wait_for_user_to_complete_payment" | "retry_original_x402_request" | "stop_and_tell_user" | "request_again_if_user_still_wants_it" | "retry_with_explicit_context" | "payment_window_expired" | "fund_safe_or_raise_allowance" | "sweep_stranded_funds")[];
|
|
869
|
+
declare const AGENT_PAYMENT_FAILURE_CODE_VALUES: ("PRICE_EXCEEDS_MAX" | "PAYMENT_WINDOW_EXPIRED" | "MERCHANT_REJECTED_AFTER_FUNDING" | "MERCHANT_UNRESPONSIVE_AFTER_FUNDING" | "MERCHANT_CALL_CONTEXT_UNAVAILABLE")[];
|
|
766
870
|
declare const AGENT_PAYMENT_RAIL_VALUES: ("x402" | "mpp" | "mpp_demo" | "mpp_crypto" | "stripe_deposit" | "spt" | "direct")[];
|
|
767
871
|
declare const AgentPaymentPhaseDescriptions: Record<AgentPaymentPhase, string>;
|
|
768
872
|
declare const AgentPaymentNextActionDescriptions: Record<AgentPaymentNextAction, string>;
|
|
769
873
|
declare const AgentPaymentFailureCodeDescriptions: Record<AgentPaymentFailureCode, string>;
|
|
874
|
+
/**
|
|
875
|
+
* #1308: machine-readable warning codes carried in the `warnings` array on
|
|
876
|
+
* x402 MCP tool responses. Warnings are ADVISORY — they never replace a
|
|
877
|
+
* refusal, and existing failure codes stay authoritative for errors. The
|
|
878
|
+
* legacy `cap_warning` string field is kept for compatibility; the structured
|
|
879
|
+
* entry carries the same message under MISSING_MAX_AMOUNT.
|
|
880
|
+
*/
|
|
881
|
+
declare const AgentPaymentWarningCode: {
|
|
882
|
+
/** No max_amount cap was supplied — the live quoted price was accepted as-is. */
|
|
883
|
+
readonly MissingMaxAmount: "MISSING_MAX_AMOUNT";
|
|
884
|
+
/** The signing window closes soon; sign promptly or re-quote with the same idempotency key. */
|
|
885
|
+
readonly QuoteExpiresSoon: "QUOTE_EXPIRES_SOON";
|
|
886
|
+
/** The merchant URL was resolved via discovery — pass the RESOLVED url forward. */
|
|
887
|
+
readonly MerchantUrlDiscovered: "MERCHANT_URL_DISCOVERED";
|
|
888
|
+
/**
|
|
889
|
+
* #1306: the catalog's last-verified price_atomic differs from the LIVE
|
|
890
|
+
* merchant quote for a guided catalog purchase. The catalog price is only
|
|
891
|
+
* ever indicative; the live quote in the same response is authoritative.
|
|
892
|
+
*/
|
|
893
|
+
readonly CatalogPriceDiffers: "CATALOG_PRICE_DIFFERS";
|
|
894
|
+
/**
|
|
895
|
+
* #1306: the rail-aware allowance/budget pre-check could not be read (RPC
|
|
896
|
+
* failure, etc). `sufficient` is reported as null rather than a fabricated
|
|
897
|
+
* true/false — the on-chain policy remains the actual gate either way.
|
|
898
|
+
*/
|
|
899
|
+
readonly AllowanceCheckUnavailable: "ALLOWANCE_CHECK_UNAVAILABLE";
|
|
900
|
+
/**
|
|
901
|
+
* #1319: the delegation-rail read itself SUCCEEDED, but the remaining
|
|
902
|
+
* figure it returned is the #1145 fallback (the full configured budget)
|
|
903
|
+
* rather than a live ERC20PeriodTransferEnforcer read — `sufficient` is a
|
|
904
|
+
* real true/false, just computed from an optimistic number. Distinct from
|
|
905
|
+
* {@link AgentPaymentWarningCode.AllowanceCheckUnavailable}, which fires
|
|
906
|
+
* when the read failed outright and `sufficient` degrades to null. The
|
|
907
|
+
* on-chain policy re-checks at redemption either way; this only says the
|
|
908
|
+
* guidance shown here may be optimistic.
|
|
909
|
+
*/
|
|
910
|
+
readonly AllowanceReadOptimistic: "ALLOWANCE_READ_OPTIMISTIC";
|
|
911
|
+
};
|
|
912
|
+
type AgentPaymentWarningCode = (typeof AgentPaymentWarningCode)[keyof typeof AgentPaymentWarningCode];
|
|
913
|
+
interface AgentPaymentWarning {
|
|
914
|
+
code: AgentPaymentWarningCode;
|
|
915
|
+
message: string;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* #1308: the structured next-step contract on x402 MCP tool responses. It
|
|
919
|
+
* EXTENDS the existing taxonomy — `next_action` values come from
|
|
920
|
+
* AgentPaymentNextAction, never a parallel vocabulary. `next_arguments`
|
|
921
|
+
* carries the small, literally-usable arguments; bulky pass-through fields
|
|
922
|
+
* (payment_required) are named in `reason` and taken from the SAME response.
|
|
923
|
+
*/
|
|
924
|
+
interface AgentNextStep {
|
|
925
|
+
next_action: AgentPaymentNextAction;
|
|
926
|
+
/** Fully-qualified tool name for the next call, when one exists. */
|
|
927
|
+
next_tool?: string;
|
|
928
|
+
/** Small literal arguments for next_tool. Bulky fields are referenced by reason. */
|
|
929
|
+
next_arguments?: Record<string, unknown>;
|
|
930
|
+
/** False when the agent should stop and involve the user before continuing. */
|
|
931
|
+
safe_to_continue: boolean;
|
|
932
|
+
reason: string;
|
|
933
|
+
}
|
|
934
|
+
/** #1308: compact reporting summary — what the agent tells the user. */
|
|
935
|
+
interface AgentPaymentSummary {
|
|
936
|
+
payment_id: string;
|
|
937
|
+
status: string;
|
|
938
|
+
amount?: string;
|
|
939
|
+
amount_atomic?: string;
|
|
940
|
+
token?: string;
|
|
941
|
+
network?: string;
|
|
942
|
+
expires_at?: string;
|
|
943
|
+
product?: string;
|
|
944
|
+
}
|
|
770
945
|
declare const AgentPaymentRailDescriptions: Record<AgentPaymentRail, string>;
|
|
771
946
|
declare const AgentPaymentPhaseSchema: AgentPaymentEnumSchema;
|
|
772
947
|
declare const AgentPaymentNextActionSchema: AgentPaymentEnumSchema;
|
|
@@ -833,6 +1008,7 @@ interface HavenCatalogEntry {
|
|
|
833
1008
|
rail: 'x402' | 'mpp';
|
|
834
1009
|
protocol: 'http' | 'mcp';
|
|
835
1010
|
toolName: string | null;
|
|
1011
|
+
toolArguments: Record<string, unknown> | null;
|
|
836
1012
|
priceDisplay: string | null;
|
|
837
1013
|
priceAtomic: string | null;
|
|
838
1014
|
asset: string | null;
|
|
@@ -850,6 +1026,26 @@ declare class HavenApiError extends HavenError {
|
|
|
850
1026
|
readonly body?: unknown | undefined;
|
|
851
1027
|
constructor(message: string, statusCode: number, body?: unknown | undefined, paymentId?: string);
|
|
852
1028
|
}
|
|
1029
|
+
/**
|
|
1030
|
+
* #1300: quoteX402 hit a URL that answered something other than 402 — the
|
|
1031
|
+
* typed form of "this is not the x402 endpoint". Exists so consumers (the
|
|
1032
|
+
* hosted MCP's #1271 discovery trigger) can key on a class instead of
|
|
1033
|
+
* message text.
|
|
1034
|
+
*/
|
|
1035
|
+
/**
|
|
1036
|
+
* #1300: a merchant-facing fetch hit the client-side merchantTimeout. Typed
|
|
1037
|
+
* so consumers can distinguish "merchant never answered" from a real HTTP
|
|
1038
|
+
* error response — the funded-retry path routes this to verify-then-sweep
|
|
1039
|
+
* guidance instead of a bare 504.
|
|
1040
|
+
*/
|
|
1041
|
+
declare class MerchantTimeoutError extends HavenApiError {
|
|
1042
|
+
readonly merchantErrorCode: "merchant_timeout";
|
|
1043
|
+
constructor(message: string);
|
|
1044
|
+
}
|
|
1045
|
+
declare class X402UnexpectedStatusError extends HavenApiError {
|
|
1046
|
+
readonly x402ErrorCode: "unexpected_non_402_status";
|
|
1047
|
+
constructor(message: string, statusCode: number);
|
|
1048
|
+
}
|
|
853
1049
|
declare class HavenPaymentStateError extends HavenApiError {
|
|
854
1050
|
readonly state: PaymentStatusResult;
|
|
855
1051
|
resumeState?: X402ResumeState | MppResumeState;
|
|
@@ -861,6 +1057,53 @@ declare class HavenPaymentStateError extends HavenApiError {
|
|
|
861
1057
|
declare class HavenSigningError extends HavenError {
|
|
862
1058
|
constructor(message: string);
|
|
863
1059
|
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Refusal codes the local signer returns when it does not recognise the
|
|
1062
|
+
* VERSION of a Haven-signed binding it was asked to sign (#1309). Distinct
|
|
1063
|
+
* from `AgentPaymentFailureCode`: these describe a **signer capability**
|
|
1064
|
+
* problem (this install cannot evaluate what Haven sent), not a payment-domain
|
|
1065
|
+
* outcome, and they never reach the backend's REST/OpenAPI surface — only the
|
|
1066
|
+
* local signer's own MCP tool responses (`haven_sign` / `haven_sign_x402` /
|
|
1067
|
+
* `haven_sign_sweep_delegate`). That is also why this pair does not go through
|
|
1068
|
+
* the `AgentPaymentFailureCode` four-gate (sdk → backend mirror → spec →
|
|
1069
|
+
* api-types): there is no backend mirror to keep in sync with.
|
|
1070
|
+
*/
|
|
1071
|
+
declare const SignerRefusalCode: {
|
|
1072
|
+
/** `SUPPORTED_X402_EXPECTED_VERSIONS` in `@haven_ai/signer` does not include the received version. */
|
|
1073
|
+
readonly UnsupportedExpectedContextVersion: "UNSUPPORTED_EXPECTED_CONTEXT_VERSION";
|
|
1074
|
+
/** `SUPPORTED_SWEEP_BINDING_VERSIONS` in `@haven_ai/signer` does not include the received version. */
|
|
1075
|
+
readonly UnsupportedSweepBindingVersion: "UNSUPPORTED_SWEEP_BINDING_VERSION";
|
|
1076
|
+
};
|
|
1077
|
+
type SignerRefusalCode = (typeof SignerRefusalCode)[keyof typeof SignerRefusalCode];
|
|
1078
|
+
/**
|
|
1079
|
+
* Canonical recovery guidance for a stale local signer (#1309) — the ONE
|
|
1080
|
+
* string both the signer's structured refusal (`fallback` field, carried by
|
|
1081
|
+
* `HavenUnsupportedSignerVersionError`) and the hosted quote's advisory
|
|
1082
|
+
* `signer_compatibility.fallback` (#1155) render, so an agent that meets
|
|
1083
|
+
* either surface is told the identical fix. A second hand-maintained copy of
|
|
1084
|
+
* this sentence is exactly how the two surfaces could start disagreeing about
|
|
1085
|
+
* what to do.
|
|
1086
|
+
*/
|
|
1087
|
+
declare const SIGNER_UPDATE_FALLBACK: string;
|
|
1088
|
+
/**
|
|
1089
|
+
* Thrown by the local signer when a Haven-signed binding (x402 expected
|
|
1090
|
+
* context or sweep authorization) carries a version outside what this signer
|
|
1091
|
+
* install enforces (#1143, structured as #1309). Machine-readable: `code`,
|
|
1092
|
+
* `supportedVersions`, and `receivedVersion` are DERIVED from the signer's own
|
|
1093
|
+
* `SUPPORTED_X402_EXPECTED_VERSIONS` / `SUPPORTED_SWEEP_BINDING_VERSIONS`
|
|
1094
|
+
* constants at the throw site, never a second literal — see
|
|
1095
|
+
* `assertSupportedBindingVersion` in `@haven_ai/signer`.
|
|
1096
|
+
*
|
|
1097
|
+
* This narrows HOW the refusal is reported. It does not weaken it: nothing is
|
|
1098
|
+
* signed either way, and the version stays inside the Haven-signed binding
|
|
1099
|
+
* message (callers must not "fix" a mismatch by rewriting it).
|
|
1100
|
+
*/
|
|
1101
|
+
declare class HavenUnsupportedSignerVersionError extends HavenError {
|
|
1102
|
+
readonly supportedVersions: readonly number[];
|
|
1103
|
+
readonly receivedVersion: number;
|
|
1104
|
+
readonly fallback: string;
|
|
1105
|
+
constructor(message: string, code: SignerRefusalCode, supportedVersions: readonly number[], receivedVersion: number, fallback: string);
|
|
1106
|
+
}
|
|
864
1107
|
declare class HavenTimeoutError extends HavenError {
|
|
865
1108
|
constructor(paymentId: string);
|
|
866
1109
|
}
|
|
@@ -1051,6 +1294,7 @@ declare class HavenClient {
|
|
|
1051
1294
|
private readonly baseUrl;
|
|
1052
1295
|
private readonly x402Wallet;
|
|
1053
1296
|
private readonly requestTimeout;
|
|
1297
|
+
private readonly merchantTimeout;
|
|
1054
1298
|
private readonly confirmationTimeout;
|
|
1055
1299
|
private readonly pollingInterval;
|
|
1056
1300
|
private readonly chainRpcs;
|
|
@@ -1203,6 +1447,56 @@ declare class HavenClient {
|
|
|
1203
1447
|
* Get configured and on-chain allowances for the authenticated agent.
|
|
1204
1448
|
*/
|
|
1205
1449
|
getAllowances(): Promise<HavenAllowanceSummary>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Post-purchase allowance/budget summary for a settled payment (#1310).
|
|
1452
|
+
*
|
|
1453
|
+
* Reuses the EXACT rail-aware read path {@link getAllowances} / #1306's
|
|
1454
|
+
* catalog-purchase preflight `allowance` block use — `GET
|
|
1455
|
+
* /machine-payments/allowances`, with delegation-rail values coming from
|
|
1456
|
+
* the #1090 `deriveDelegationBudgets`-backed enforcer read, never
|
|
1457
|
+
* `agent_allowances` — so this can never disagree with
|
|
1458
|
+
* {@link getAllowances} for the same fixture. The settled token is
|
|
1459
|
+
* resolved from {@link getPaymentStatus} so callers pass only
|
|
1460
|
+
* `paymentId`, never a second haven_get_agent-style round trip.
|
|
1461
|
+
*
|
|
1462
|
+
* NEVER throws: any failed read (status lookup, agent lookup, or the
|
|
1463
|
+
* allowance/budget lookup itself) degrades to `{ allowance: null,
|
|
1464
|
+
* warnings: [ALLOWANCE_CHECK_UNAVAILABLE] }` rather than converting a
|
|
1465
|
+
* successful settlement into a failure — the on-chain policy remains the
|
|
1466
|
+
* actual spend gate regardless of whether this report can be produced.
|
|
1467
|
+
*
|
|
1468
|
+
* Freshness caveat (#1319): the delegation rail's on-chain enforcer read
|
|
1469
|
+
* can silently fall back to the optimistic full period budget without
|
|
1470
|
+
* throwing when the RPC read itself fails (#1145's fund-safe design,
|
|
1471
|
+
* unchanged here). {@link getAllowances}'s `onchain.remainingIsFromChain`
|
|
1472
|
+
* now carries that provenance on the wire, and the #1306 catalog-purchase
|
|
1473
|
+
* preflight (`haven_prepare_catalog_purchase`) surfaces it as a warning —
|
|
1474
|
+
* this summary does not (yet). `remaining_atomic` here reflects the last
|
|
1475
|
+
* successful chain read, not a guaranteed-live one, and callers should not
|
|
1476
|
+
* phrase it as guaranteed-fresh.
|
|
1477
|
+
*/
|
|
1478
|
+
getPostPurchaseAllowanceSummary(paymentId: string): Promise<{
|
|
1479
|
+
allowance: PostPurchaseAllowanceSummary | null;
|
|
1480
|
+
warnings: AgentPaymentWarning[];
|
|
1481
|
+
}>;
|
|
1482
|
+
/**
|
|
1483
|
+
* `haven_get_payment_status` convenience: fetch status and, for a
|
|
1484
|
+
* genuinely SETTLED x402 payment, attach the same post-purchase
|
|
1485
|
+
* allowance/budget summary a settle response carries.
|
|
1486
|
+
*
|
|
1487
|
+
* #1310/#1311 parity: this is the ONE home for logic that was duplicated
|
|
1488
|
+
* verbatim in `packages/mcp-server/src/tools.ts` and `packages/mcp/src/tools.ts`
|
|
1489
|
+
* (both hosted and local `haven_get_payment_status` handlers) — extracted
|
|
1490
|
+
* here because both packages already depend on `@haven_ai/sdk` and call
|
|
1491
|
+
* methods on a `HavenClient` instance, so this needed no new dependency
|
|
1492
|
+
* edge. `funded_but_unsettled` is deliberately excluded: that phase means
|
|
1493
|
+
* the merchant did NOT accept the retry. Every other phase/rail returns
|
|
1494
|
+
* the status untouched.
|
|
1495
|
+
*/
|
|
1496
|
+
getPaymentStatusWithPostPurchaseAllowance(paymentId: string): Promise<PaymentStatusResult & {
|
|
1497
|
+
allowance?: PostPurchaseAllowanceSummary | null;
|
|
1498
|
+
warnings?: AgentPaymentWarning[];
|
|
1499
|
+
}>;
|
|
1206
1500
|
/**
|
|
1207
1501
|
* Discover payable services from Haven's curated merchant catalog.
|
|
1208
1502
|
*
|
|
@@ -1214,6 +1508,16 @@ declare class HavenClient {
|
|
|
1214
1508
|
category?: string;
|
|
1215
1509
|
rail?: 'x402' | 'mpp';
|
|
1216
1510
|
}): Promise<HavenCatalogEntry[]>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Fetch one curated catalog entry by id (#1306).
|
|
1513
|
+
*
|
|
1514
|
+
* Chain-scoped for free by the backend's SQL when the client is
|
|
1515
|
+
* agent-authenticated (#1299): an unknown id and an id curated for a
|
|
1516
|
+
* DIFFERENT chain than this agent's both 404 identically — this method does
|
|
1517
|
+
* not (and must not) re-filter by chain in JS. Read-only, like
|
|
1518
|
+
* {@link discoverTools}.
|
|
1519
|
+
*/
|
|
1520
|
+
getCatalogEntry(id: string): Promise<HavenCatalogEntry>;
|
|
1217
1521
|
/**
|
|
1218
1522
|
* List recent machine-payment receipts/evidence for bookkeeping.
|
|
1219
1523
|
*/
|
|
@@ -1256,6 +1560,17 @@ declare class HavenClient {
|
|
|
1256
1560
|
* payment or approval request.
|
|
1257
1561
|
*/
|
|
1258
1562
|
quoteX402(url: string, init?: RequestInit, options?: X402AuthorizationOptions): Promise<X402Quote>;
|
|
1563
|
+
/**
|
|
1564
|
+
* Probe an MCP tool for its x402 quote without creating a payment.
|
|
1565
|
+
*
|
|
1566
|
+
* Unlike the generic {@link quoteX402} helper, this completes the
|
|
1567
|
+
* Streamable-HTTP MCP lifecycle before sending the unpaid `tools/call`.
|
|
1568
|
+
* Hosted MCP uses this path while remaining keyless: it resolves only the
|
|
1569
|
+
* agent's public delegate address for `x402-wallet`; signing remains local.
|
|
1570
|
+
* It refuses before the quote when the merchant does not establish a session;
|
|
1571
|
+
* callers that need a plain x402 endpoint must use {@link quoteX402}.
|
|
1572
|
+
*/
|
|
1573
|
+
quoteMcpX402(url: string, init?: RequestInit, options?: X402AuthorizationOptions): Promise<X402Quote>;
|
|
1259
1574
|
/**
|
|
1260
1575
|
* Pay a previously inspected x402 quote and retry the exact captured request.
|
|
1261
1576
|
*/
|
|
@@ -1376,6 +1691,17 @@ declare class HavenClient {
|
|
|
1376
1691
|
body: unknown;
|
|
1377
1692
|
settlementTxHash?: string;
|
|
1378
1693
|
}>;
|
|
1694
|
+
/**
|
|
1695
|
+
* GET /x402/:id/merchant-call-context — the settle-leg twin of #1263's
|
|
1696
|
+
* sign-context fetch (#1307). Re-serves the stored merchant MCP-tool call
|
|
1697
|
+
* context (merchant_url, tool_name, arguments, mcp_transport) recorded at
|
|
1698
|
+
* quote time, so `haven_settle_mcp_tool` / `haven_complete_mcp_tool` can
|
|
1699
|
+
* omit those fields and let Haven rehydrate them by payment_id instead of
|
|
1700
|
+
* the caller re-threading them. Throws `HavenApiError` (404 unknown/foreign
|
|
1701
|
+
* payment_id, 409 no stored context, 410 expired) — the caller decides the
|
|
1702
|
+
* fallback (re-send the full context explicitly).
|
|
1703
|
+
*/
|
|
1704
|
+
getX402MerchantCallContext(paymentId: string): Promise<X402MerchantCallContext>;
|
|
1379
1705
|
private resolveX402MerchantCompletionContext;
|
|
1380
1706
|
private resolveX402WalletForMerchantCall;
|
|
1381
1707
|
authorizeMachinePayment(challenge: MachinePaymentChallenge, options?: MppAuthorizationOptions): Promise<MachinePaymentReceipt>;
|
|
@@ -1439,6 +1765,15 @@ declare class HavenClient {
|
|
|
1439
1765
|
private toolError;
|
|
1440
1766
|
private post;
|
|
1441
1767
|
private get;
|
|
1768
|
+
/**
|
|
1769
|
+
* #1300: every MERCHANT-facing fetch goes through here. Haven API calls
|
|
1770
|
+
* have always been bounded (request() below); the merchant probes/retries
|
|
1771
|
+
* called globalThis.fetch bare, so a slow-loris merchant could hold a tool
|
|
1772
|
+
* call open forever. A caller-supplied signal still applies (combined via
|
|
1773
|
+
* AbortSignal.any); a timeout abort surfaces as a clear HavenApiError 504
|
|
1774
|
+
* naming the URL rather than a bare AbortError.
|
|
1775
|
+
*/
|
|
1776
|
+
private merchantFetch;
|
|
1442
1777
|
private request;
|
|
1443
1778
|
private mapPaymentResult;
|
|
1444
1779
|
private mapPaymentStatusResult;
|
|
@@ -1643,16 +1978,16 @@ declare const toolDescriptions: {
|
|
|
1643
1978
|
readonly nextActionGuidance: "";
|
|
1644
1979
|
};
|
|
1645
1980
|
readonly payMcpTool: {
|
|
1646
|
-
readonly summary: "Call a named tool on an MCP merchant that requires an x402 payment, handling the full initialize → pay → retry round trip.";
|
|
1981
|
+
readonly summary: "Call a named tool on an MCP merchant that requires an x402 payment, handling the full initialize → pay → retry round trip in one call.";
|
|
1647
1982
|
readonly selectionGuidance: string;
|
|
1648
1983
|
readonly behavior: string;
|
|
1649
1984
|
readonly nextActionGuidance: string;
|
|
1650
1985
|
};
|
|
1651
1986
|
readonly discoverTools: {
|
|
1652
|
-
readonly summary: "
|
|
1987
|
+
readonly summary: "Step 1 of a purchase: discover payable services from Haven's curated merchant catalog — names, prices, and which pay tool to use next.";
|
|
1653
1988
|
readonly selectionGuidance: string;
|
|
1654
1989
|
readonly behavior: string;
|
|
1655
|
-
readonly nextActionGuidance: "Pick an entry and pay it with the tool named in suggested_tool, passing the entry's resource_url
|
|
1990
|
+
readonly nextActionGuidance: "Pick an entry and pay it with the tool named in suggested_tool, passing the entry's resource_url, tool_name, and tool_arguments for MCP merchants. Confirm the price from the live pay-tool result (not the catalog), and pass max_amount when the user has a cap.";
|
|
1656
1991
|
};
|
|
1657
1992
|
readonly sweep_delegate: {
|
|
1658
1993
|
readonly summary: "Sweep stranded USDC and/or ETH from the delegate wallet back to the originating Safe.";
|
|
@@ -1688,7 +2023,7 @@ type SharedToolKey = keyof typeof toolDescriptions;
|
|
|
1688
2023
|
* this canonical string and asserts byte-for-byte equality, so the two copies
|
|
1689
2024
|
* cannot drift.
|
|
1690
2025
|
*/
|
|
1691
|
-
declare const HAVEN_SKILL_MD = "---\nname: haven-pay\ndescription: Pay for things from the user's Haven wallet within their agent rules. Use when the user asks to send, pay, tip, or transfer crypto \u2014 or when a request hits an HTTP 402 (x402) paywall.\n---\n\n# Haven: pay from a Haven wallet\n\nThis skill lets the agent make payments from the user's Haven wallet through\nthe Haven MCP tools. Every payment is checked against the agent's on-chain\nbudget before money moves; payments above the remaining budget wait for the\nuser's approval in Haven.\n\nHosted tools run in the `mcp__haven__` namespace. Local signing tools run in\nthe `mcp__haven-signer__` namespace and keep the delegate key on this machine.\n\n## When to use this skill\n\n- The user asks to send money, pay someone, tip, donate, or transfer tokens.\n- A request returns HTTP 402 (x402): use the Haven pay tools to settle it,\n then retry the original request.\n\n## Identity and budget\n\nDo not guess the wallet address, network, or budget.\n\nFor instant orientation at the start of a session, read the non-secret\n`agent.json` the connector wrote to your Haven credential directory (typically\n`~/.haven/agents/<agent-id>/agent.json` \u2014 if you don't know the agent id, list\n`~/.haven/agents/` to find the folder). It\nholds your agent id, Haven wallet address, network, and *configured* per-token\nbudget, and contains no keys \u2014 the fastest way to answer \"who am I and what may\nI spend\" with no round trip. If that file is absent (some setups don't write\nit), use the tools below instead.\n\nBefore any payment, confirm the *live remaining* budget with the tools \u2014\n`agent.json` shows the configured budget, not what is left after recent\nspending:\n\n- `
|
|
2026
|
+
declare const HAVEN_SKILL_MD = "---\nname: haven-pay\ndescription: Pay for things from the user's Haven wallet within their agent rules. Use when the user asks to send, pay, tip, or transfer crypto \u2014 or when a request hits an HTTP 402 (x402) paywall.\n---\n\n# Haven: pay from a Haven wallet\n\nThis skill lets the agent make payments from the user's Haven wallet through\nthe Haven MCP tools. Every payment is checked against the agent's on-chain\nbudget before money moves; payments above the remaining budget wait for the\nuser's approval in Haven.\n\nHosted tools run in the `mcp__haven__` namespace. Local signing tools run in\nthe `mcp__haven-signer__` namespace and keep the delegate key on this machine.\nTool results carry the exact next step (`next_action`, `next_tool`,\n`next_arguments`) \u2014 follow those fields first; the prose below is fallback\nand orientation, not the source of truth.\n\n## When to use this skill\n\n- The user asks to send money, pay someone, tip, donate, or transfer tokens.\n- A request returns HTTP 402 (x402): use the Haven pay tools to settle it,\n then retry the original request.\n\n## Identity and budget\n\nDo not guess the wallet address, network, or budget.\n\nFor instant orientation at the start of a session, read the non-secret\n`agent.json` the connector wrote to your Haven credential directory (typically\n`~/.haven/agents/<agent-id>/agent.json` \u2014 if you don't know the agent id, list\n`~/.haven/agents/` to find the folder). It\nholds your agent id, Haven wallet address, network, and *configured* per-token\nbudget, and contains no keys \u2014 the fastest way to answer \"who am I and what may\nI spend\" with no round trip. If that file is absent (some setups don't write\nit), use the tools below instead.\n\nBefore any payment, confirm the *live remaining* budget with the tools \u2014\n`agent.json` shows the configured budget, not what is left after recent\nspending:\n\n- `mcp__haven__haven_get_agent` \u2014 the recommended first call: identity\n (wallet, network) plus a readiness signal (`ready` / `needs_approval` /\n `revoked`) and live remaining per-token allowance, in one shot.\n- `mcp__haven__haven_get_allowances` \u2014 detailed per-token breakdown\n (configured, spent, reset window) when you need more than the summary.\n\nBudgets reset on a period the user chose. If a payment exceeds the remaining\nbudget it is queued for the user to approve in the Haven dashboard \u2014 this is\nnormal, not an error.\n\n## Paying\n\n**Catalog purchases \u2014 the primary path for MCP merchants:**\n\n1. `mcp__haven__haven_discover_tools` to find a payable service and its\n `catalog_id`.\n2. `mcp__haven__haven_prepare_catalog_purchase` with `catalog_id` and\n `max_amount`. `max_amount` (atomic units) is REQUIRED on this tool, and\n is best practice on every paid call below too \u2014 it caps what the LIVE\n merchant quote may charge, checked before any funding intent is created.\n3. Then FOLLOW THE RESPONSE'S GUIDANCE FIELDS: `next_action`, `next_tool`,\n and `next_arguments` name the exact next call \u2014 act on those first; the\n prose in this section is fallback and debugging detail. If the catalog\n entry is missing or degraded, the response instead names\n `mcp__haven__haven_pay_mcp_tool` (merchant URL, tool name, arguments) as\n the manual fallback.\n\n**Signing:** `mcp__haven-signer__haven_sign_x402` with `payment_id` and\n`payment_required` ONLY \u2014 the local signer fetches the exact signing bytes\nitself, so never relay `typed_data` yourself. Fallback for an older signer\nor backend: re-run the quote/prepare tool with the SAME `idempotency_key`\nplus `include_signing_payload=true`, then pass `payload_hash`,\n`x402_expected` (the nested `x402.expected` object), and\n`typed_data`/`typed_data_b64` through unchanged.\n\n**Settle:** `mcp__haven__haven_settle_mcp_tool` with `payment_id`,\n`signature`, and `payment_header` ONLY \u2014 Haven rehydrates the merchant call\ncontext (`merchant_url`, `tool_name`, `arguments`, `mcp_transport`)\nserver-side from `payment_id`. Pass those four fields explicitly only as a\nversion-skew fallback when Haven has no stored context for the id \u2014 both or\nnone together, never just one. If the settle result carries `settled: false`,\nfunding is queued for the user's approval \u2014 tell them and check status later,\ndo not re-pay.\n\nStep-by-step alternative (also key-safe; for an older signer or backend, or\nwhen you already have a merchant URL and tool name instead of a\n`catalog_id`): `mcp__haven__haven_pay_mcp_tool` then\n`mcp__haven-signer__haven_sign` \u2192 `mcp__haven__haven_submit` \u2192\n`mcp__haven-signer__haven_x402_sign_header` \u2192\n`mcp__haven__haven_complete_mcp_tool`. Pass `payment_required`,\n`arguments`, and `mcp_transport` verbatim from the quote/prepare result.\nThe returned `expires_at` is the signing window; if a tool returns\n`PAYMENT_WINDOW_EXPIRED`, re-run the same quote/prepare tool with the same\n`idempotency_key`. Do not call the merchant yourself \u2014 Haven completes the\nmerchant leg for you.\n\n**Direct transfer / non-MCP paywall:** `mcp__haven__haven_pay` with\nrecipient, amount, and token for a plain transfer. For an arbitrary,\nnon-MCP x402 paywall: `mcp__haven__haven_quote_x402` to get a quote, then\n`mcp__haven__haven_pay_x402_quote` \u2014 follow the result's guidance fields\nfirst, sign in the local Haven signer, and retry the original request only\nwhen the result says `retry_original_x402_request`.\n\n**Catalog tool arguments:** when `haven_discover_tools` returns\n`tool_arguments`, pass that object unchanged as the pay tool's\n`arguments` field (for example\n`tool_arguments: { \"tier\": \"50gb\" }` -> `arguments: { \"tier\": \"50gb\" }`).\n\n**Prices:** show the user the live price from the pay-tool result, never a\ncatalog price. `haven_discover_tools` prices are indicative\n(`price_is_indicative`) and can be stale. The pay-tool result's `amount` /\n`amount_atomic` is the amount Haven authorizes for the call \u2014 a ceiling the\nmerchant settles at or below \u2014 so present it as the most the user will pay.\n\n**Status:** `mcp__haven__haven_get_payment_status` with a `payment_id` to\ncheck on queued or in-flight payments. Do not poll in a tight loop.\n\n## Approval semantics\n\n- A result with `pending_approval` means the payment exceeded the remaining\n budget and is waiting for the user in Haven. Tell the user, then check\n status later.\n- `safe_to_continue: false` on a guidance block is the same signal in\n machine-readable form: stop and involve the user before calling anything\n else for this payment.\n- Never ask the user for private keys. Signing happens only in the local Haven\n signer; the hosted Haven tools never receive the signing key. If a tool\n reports a missing or invalid credential, tell the user to re-run the Haven\n setup command.\n\n## Failure handling\n\nHaven tool failures are shaped like `{ success: false, code, message, ... }`\nor older `{ error, status, details? }` responses. Branch on `code` when\npresent and surface `message` or `error` verbatim. Common cases:\n\n- `pending_approval`: queued for the user's approval (see above).\n- `insufficient_funds`: the Haven wallet doesn't hold enough of that token.\n Suggest the user add funds in the Haven dashboard.\n- `PRICE_EXCEEDS_MAX`: the live merchant price exceeded your `max_amount`.\n No funds moved; ask the user before retrying with a higher cap.\n- `PAYMENT_WINDOW_EXPIRED`: re-run the quote/prepare tool with the same\n `idempotency_key`, then sign the fresh payload.\n- `MERCHANT_REJECTED_AFTER_FUNDING`: the merchant refused the paid retry.\n Stop-and-sweep \u2014 stop retrying the merchant and use\n `mcp__haven__haven_sweep_delegate` to recover stranded delegate funds.\n- `MERCHANT_UNRESPONSIVE_AFTER_FUNDING`: funding confirmed on-chain, but the\n merchant never answered the paid retry. This is NOT proof of rejection \u2014 the\n merchant may still settle late. Verify-then-sweep, never a blind sweep:\n check `mcp__haven__haven_get_payment_status`, retry\n `mcp__haven__haven_complete_mcp_tool` ONCE, and only sweep with\n `mcp__haven__haven_sweep_delegate` if no settlement appears.\n- Budget exceeded: tell the user how much remains (from\n `mcp__haven__haven_get_allowances`) and that they can raise the budget in\n Haven.\n\n## Reporting after a purchase\n\nA settled `mcp__haven__haven_settle_mcp_tool` response carries\n`agent_summary` and the remaining post-purchase allowance in `allowance` \u2014\nreport the amount paid and what is left from those fields directly. Do not\ncall `haven_get_agent` or `haven_get_allowances` again just to report a\npurchase you already made.\n\n## Revoke\n\nIf this agent's credential may have leaked, tell the user to pause or revoke\nthe agent in the Haven dashboard under Agents. New requests stop immediately\nfor that credential.\n";
|
|
1692
2027
|
/** Directory name for the installed skill folder. */
|
|
1693
2028
|
declare const SKILL_FOLDER_NAME = "haven-pay";
|
|
1694
2029
|
|
|
@@ -1915,4 +2250,32 @@ declare function encodeBase64Json(value: unknown): string;
|
|
|
1915
2250
|
*/
|
|
1916
2251
|
declare function decodeBase64Json<T>(value: string, label?: string): T;
|
|
1917
2252
|
|
|
1918
|
-
|
|
2253
|
+
/**
|
|
2254
|
+
* #1271 / #1301: bounded same-origin merchant MCP endpoint discovery.
|
|
2255
|
+
*
|
|
2256
|
+
* An agent handed a BASE merchant URL previously had to hand-probe /, /mcp,
|
|
2257
|
+
* /sse, … until something answered 402. The demo merchant (and the #1266
|
|
2258
|
+
* contract) serves a machine-readable discovery document at
|
|
2259
|
+
* `/.well-known/haven-demo-merchant` (also at `/`) naming `mcp_url`. This
|
|
2260
|
+
* helper fetches ONLY those two fixed same-origin paths — no redirects
|
|
2261
|
+
* (`redirect: 'error'`), a 5 s timeout, a 64 KB read cap — and accepts the
|
|
2262
|
+
* document's `mcp_url` ONLY when it stays on the same origin as the input.
|
|
2263
|
+
* Anything else returns null and the caller reports the original probe
|
|
2264
|
+
* failure. Discovery finds endpoints; it carries no payment authority and an
|
|
2265
|
+
* off-origin `mcp_url` is never even fetched — this must not grow into a
|
|
2266
|
+
* general network scanner (SSRF bound, per the issue).
|
|
2267
|
+
*
|
|
2268
|
+
* Originally hosted-only (mcp-server, #1271). Moved here in #1301 so the
|
|
2269
|
+
* local/self-signed MCP package (`@haven_ai/mcp`) can share the EXACT same
|
|
2270
|
+
* bounded implementation instead of re-deriving discovery semantics —
|
|
2271
|
+
* behavior is byte-identical to the pre-move mcp-server copy; the #1271
|
|
2272
|
+
* contract tests in packages/mcp-server/src/tools.test.ts pass unmodified
|
|
2273
|
+
* against this moved implementation.
|
|
2274
|
+
*/
|
|
2275
|
+
declare const MERCHANT_DISCOVERY_PATHS: readonly ["/.well-known/haven-demo-merchant", "/"];
|
|
2276
|
+
declare const DISCOVERY_MAX_BYTES: number;
|
|
2277
|
+
declare function discoverMerchantMcpUrl(inputUrl: string): Promise<string | null>;
|
|
2278
|
+
/** Trailing-slash/percent-case echoes compare equal; unparseable never does. */
|
|
2279
|
+
declare function sameUrl(a: string, b: string): boolean;
|
|
2280
|
+
|
|
2281
|
+
export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentNextStep, type AgentPaymentEnumSchema, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type AgentPaymentSummary, type AgentPaymentWarning, AgentPaymentWarningCode, type ClaudeTool, DISCOVERY_MAX_BYTES, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_MD, type HavenAgent, type HavenAgentAllowanceSummary, type HavenAgentReadiness, type HavenAgentSummary, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, type HavenCatalogEntry, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, MERCHANT_DISCOVERY_PATHS, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, MerchantTimeoutError, type MppAuthorizationOptions, type MppQuote, type MppResumeState, type OpenAITool, type PaymentFee, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentReceipt, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type PostPurchaseAllowanceSummary, RECEIPT_VERSION, type ReceiptVerification, type ResumeAuthorizedMppInput, type ResumeAuthorizedX402Input, type ResumeMppPaymentInput, type ResumeX402PaymentInput, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, type SharedToolKey, type SignData, SignerRefusalCode, type SweepAuthorization, type SweepEip712Domain, type SweepEntry, type SweepExpectedAuth, type SweepPreparation, type SweepPrepareResponse, type SweepResult, type SweepSubmitResponse, type SweepSubmitResult, type SweepTypedData, TRANSFER_WITH_AUTHORIZATION_TYPES, type ToolDescription, type UnsupportedNodeVersionMessageOptions, type X402AuthorizationOptions, type X402ExpectedAuth, type X402ExpectedContext, type X402Intent, type X402McpCallContext, type X402McpTransport, type X402MerchantCallContext, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, X402UnexpectedStatusError, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildMachinePaymentIdempotencyKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodeMachinePaymentProof, encodePaymentProof, havenTools, isSupportedNodeVersion, isSweepableChain, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, sameUrl, selectPaymentOption, selectStandardPaymentOption, signHash, signUserOpTypedDataForDelegation, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, verifyPaymentReceipt, verifySignature, x402AuthorizationAmount };
|