@haven_ai/sdk 0.1.4 → 0.1.6

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.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import { PaymentRequirements } from 'x402/types';
2
+
1
3
  interface HavenClientConfig {
2
4
  /** Haven API key (sk_agent_xxx) */
3
5
  apiKey: string;
@@ -144,6 +146,55 @@ interface X402AuthorizationOptions {
144
146
  /** Stable caller-supplied key for this user intent. Prevents duplicate approvals across fresh 402 quotes. */
145
147
  idempotencyKey?: string;
146
148
  }
149
+ /**
150
+ * Keyless x402 construct result.
151
+ *
152
+ * Returned by `createX402Intent` — the non-custodial half of an x402 payment.
153
+ * It carries the unsigned funding hash (`signData.hash`, Safe → delegate EOA)
154
+ * plus everything the *edge* needs to build and sign the EIP-3009 merchant
155
+ * header itself. The construct path never signs; both delegate signatures
156
+ * (funding hash + merchant header) happen on the machine that holds the key.
157
+ */
158
+ interface X402Intent {
159
+ /** Haven payment id for the funding transfer. */
160
+ paymentId: string;
161
+ status: 'pending_signature';
162
+ /** ISO 8601 expiry of the funding intent, if returned. */
163
+ expiresAt?: string;
164
+ /** The unsigned funding hash to sign with the delegate key (Safe → delegate EOA). */
165
+ signData: SignData;
166
+ /** The selected x402 option — the edge needs this to build the EIP-3009 header. */
167
+ accepted: X402PaymentOption;
168
+ /** Resource URL the 402 came from. */
169
+ resourceUrl: string;
170
+ /** Merchant payTo address (the final recipient of the EIP-3009 transfer). */
171
+ merchantTo: string;
172
+ /** Atomic amount the edge signer must authorize in the merchant header. */
173
+ amountAtomic: string;
174
+ /** Token contract the merchant header must pay. */
175
+ asset: string;
176
+ /** x402 network the merchant header must use. */
177
+ network: string;
178
+ /** Haven-authenticated binding over the x402 expected context. */
179
+ expectedAuth: X402ExpectedAuth;
180
+ /** Delegate EOA the funding transfer tops up (the x402 payer). */
181
+ fundingTo: string;
182
+ }
183
+ interface X402ExpectedContext {
184
+ paymentId: string;
185
+ payloadHash: string;
186
+ resourceUrl: string;
187
+ merchantTo: string;
188
+ amount: string;
189
+ asset: string;
190
+ network: string;
191
+ }
192
+ interface X402ExpectedAuth {
193
+ version: 1;
194
+ message: string;
195
+ signature: string;
196
+ signer: string;
197
+ }
147
198
  /** Serializable HTTP request state for retrying the same x402 merchant request. */
148
199
  interface X402RequestSnapshot {
149
200
  url: string;
@@ -342,6 +393,8 @@ interface HavenAllowanceSummary {
342
393
  interface HavenPaymentReceipt {
343
394
  id: string;
344
395
  paymentId: string;
396
+ paymentIntentId?: string | null;
397
+ approvalRequestId?: string | null;
345
398
  rail: string;
346
399
  proofStatus: string;
347
400
  txHash: string;
@@ -415,20 +468,46 @@ declare const AgentPaymentNextAction: {
415
468
  readonly RequestAgainIfUserStillWantsIt: "request_again_if_user_still_wants_it";
416
469
  };
417
470
  type AgentPaymentNextAction = (typeof AgentPaymentNextAction)[keyof typeof AgentPaymentNextAction];
471
+ /**
472
+ * Stable rail identifier carried on Haven agent payment responses and resume
473
+ * state.
474
+ *
475
+ * Two layers of vocabulary share this enum because both reach the wire:
476
+ *
477
+ * - **Categorical rails** identify the rail family and are used as
478
+ * discriminators on `PaymentResumeState`: `direct`, `x402`, `mpp`.
479
+ * - **Granular rails** identify the specific protocol the backend persists
480
+ * and returns on response bodies: `mpp_demo`, `mpp_crypto`,
481
+ * `stripe_deposit`, `spt`. `x402` doubles as both categorical and
482
+ * granular.
483
+ *
484
+ * Consumers reading the top-level `rail` field on a payment status response
485
+ * should treat any `mpp*` value as the MPP family; consumers reading the
486
+ * `rail` field on a `MppResumeState` will always see the categorical `mpp`,
487
+ * with the granular value on `paymentRail`.
488
+ */
418
489
  declare const AgentPaymentRail: {
419
490
  /** Standard Haven payment from the user's Safe through an approved delegate allowance. */
420
491
  readonly Direct: "direct";
421
492
  /** x402 HTTP 402 payment flow with a Haven funding leg and merchant retry leg. */
422
493
  readonly X402: "x402";
423
- /** Machine Payment Protocol flow. */
494
+ /** Machine Payment Protocol family — categorical value used as a resume-state discriminator. */
424
495
  readonly Mpp: "mpp";
496
+ /** Haven internal MPP demo rail. Not for production traffic. */
497
+ readonly MppDemo: "mpp_demo";
498
+ /** Crypto-settled MPP rail. */
499
+ readonly MppCrypto: "mpp_crypto";
500
+ /** Stripe-deposit-backed MPP rail. */
501
+ readonly StripeDeposit: "stripe_deposit";
502
+ /** Stripe Payment Token MPP rail. */
503
+ readonly Spt: "spt";
425
504
  };
426
505
  type AgentPaymentRail = (typeof AgentPaymentRail)[keyof typeof AgentPaymentRail];
427
506
  type PaymentPhase = AgentPaymentPhase;
428
507
  type PaymentNextAction = AgentPaymentNextAction;
429
508
  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")[];
430
509
  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")[];
431
- declare const AGENT_PAYMENT_RAIL_VALUES: ("x402" | "mpp" | "direct")[];
510
+ declare const AGENT_PAYMENT_RAIL_VALUES: ("x402" | "mpp" | "mpp_demo" | "mpp_crypto" | "stripe_deposit" | "spt" | "direct")[];
432
511
  declare const AgentPaymentPhaseDescriptions: Record<AgentPaymentPhase, string>;
433
512
  declare const AgentPaymentNextActionDescriptions: Record<AgentPaymentNextAction, string>;
434
513
  declare const AgentPaymentRailDescriptions: Record<AgentPaymentRail, string>;
@@ -566,6 +645,23 @@ declare class HavenClient {
566
645
  * Returns the intent with the hash to sign.
567
646
  */
568
647
  createIntent(request: PaymentRequest): Promise<PaymentIntent>;
648
+ /**
649
+ * Keyless x402 construct.
650
+ *
651
+ * The non-custodial half of an x402 payment: posts the funding request to
652
+ * `/x402` and returns the unsigned funding hash plus the data the caller
653
+ * needs to build and sign the EIP-3009 merchant header itself. Crucially it
654
+ * does **not** sign — neither the funding hash nor the merchant header — so
655
+ * it works without a `delegateKey`. Both delegate signatures happen on the
656
+ * machine that holds the key (the edge); the hosted MCP server relays only.
657
+ *
658
+ * Use this from the hosted, keyless server. The all-in-one `authorizeX402`
659
+ * remains for local clients that hold the key.
660
+ *
661
+ * Throws (via the shared payment-state path) when the amount exceeds the
662
+ * on-chain allowance — there is nothing to sign until the user approves.
663
+ */
664
+ createX402Intent(paymentRequired: X402PaymentRequired, options?: X402AuthorizationOptions): Promise<X402Intent>;
569
665
  /**
570
666
  * Step 2: Sign a hash with the delegate key.
571
667
  *
@@ -723,8 +819,15 @@ declare class HavenClient {
723
819
  /**
724
820
  * Pre-built tool definitions for AI agent frameworks.
725
821
  *
726
- * These definitions describe the `make_payment` and `get_payment_status` tools
727
- * in the formats expected by Claude (Anthropic) and OpenAI.
822
+ * These definitions describe Haven's direct SDK tool-calling surface in the
823
+ * formats expected by Claude (Anthropic) and OpenAI.
824
+ *
825
+ * The agent payment surface used by these tools is shared with the
826
+ * `@haven_ai/mcp` server — both consume `toolDescriptions` from
827
+ * `./tool-descriptions.ts`. Each consumer composes its own user-visible string
828
+ * from the same semantic fragments, so guidance lands in both surfaces at
829
+ * once and a downstream test asserts the shared summary appears in every
830
+ * consumer description.
728
831
  *
729
832
  * Usage with Claude:
730
833
  * const response = await anthropic.messages.create({
@@ -786,6 +889,105 @@ declare function addressFromKey(privateKey: string): string;
786
889
  */
787
890
  declare function verifySignature(hash: string, signature: string, expectedAddress: string): boolean;
788
891
 
892
+ /**
893
+ * Shared semantic descriptions for Haven agent payment tools.
894
+ *
895
+ * Two surfaces in this repo expose Haven as a tool: the Claude / OpenAI
896
+ * function-calling tool definitions in `tools.ts` (used for direct SDK
897
+ * integrations) and the MCP server in `packages/mcp` (used by any MCP-speaking
898
+ * agent runtime). The two surfaces use different tool *names* — the SDK's
899
+ * tools are tuned for tool-calling conventions (`make_payment`,
900
+ * `authorize_x402_payment`); the MCP tools follow the MCP `haven_*` naming
901
+ * (`haven_pay_x402_quote`).
902
+ *
903
+ * The underlying *operations* are the same, so the descriptive prose should
904
+ * live in one place. Both surfaces import from this module and compose their
905
+ * own tool descriptions from these semantic fragments. Drift is caught by
906
+ * tests asserting each consumer's description string contains the shared
907
+ * `summary` from this module.
908
+ */
909
+ interface ToolDescription {
910
+ /** One-line summary of the operation. Used as the first sentence of every
911
+ * downstream description and as a stable substring for drift tests. */
912
+ summary: string;
913
+ /** Natural-language user intents that should make an agent prefer this
914
+ * tool over adjacent tools. Empty or omitted when the summary is enough. */
915
+ selectionGuidance?: string;
916
+ /** Concrete behaviour the tool performs end-to-end, including which
917
+ * non-custodial guarantee applies. */
918
+ behavior: string;
919
+ /** What the agent should do next on error / pending-approval states.
920
+ * Empty string if not applicable. */
921
+ nextActionGuidance: string;
922
+ }
923
+ /**
924
+ * Build a single description string from the three fragments. Joined with
925
+ * spaces so consumers can split on the summary substring if they need to.
926
+ */
927
+ declare function composeDescription(d: ToolDescription): string;
928
+ declare const toolDescriptions: {
929
+ readonly quoteX402: {
930
+ readonly summary: "Inspect an HTTP 402 x402 paid resource without creating a Haven payment, signature, approval, or on-chain transaction.";
931
+ readonly behavior: "Probes the merchant directly and parses the 402 response. Pure read-only client behavior — Haven is not contacted.";
932
+ readonly nextActionGuidance: "";
933
+ };
934
+ readonly payX402: {
935
+ readonly summary: "Pay an inspected x402 quote. The delegate key signs locally; Haven only validates and relays signed, on-chain-constrained payment transactions.";
936
+ readonly selectionGuidance: "Do not use this for read-only allowance, budget, spend-limit, remaining-amount, reset-period, or what-can-I-spend questions; use the allowance lookup tool instead.";
937
+ readonly behavior: "Signs the EIP-3009 payment from the delegate wallet, asks Haven for a Safe AllowanceModule top-up if needed, and returns the merchant response or a pending-approval state.";
938
+ readonly nextActionGuidance: "If approval is needed, preserve the returned resume_state and wait for nextAction=retry_original_x402_request before resuming.";
939
+ };
940
+ readonly resumeX402: {
941
+ readonly summary: "Resume an x402 payment after the Haven wallet owner approved the funding step.";
942
+ readonly behavior: "Accepts either resume_state or payment_id, validates the original x402 details against the approved Haven funding, and retries the merchant request with the X-PAYMENT header. No new Haven approval is created.";
943
+ readonly nextActionGuidance: "Only use when get_payment_status returns nextAction=retry_original_x402_request; do not start a new merchant session.";
944
+ };
945
+ readonly quoteMpp: {
946
+ readonly summary: "Inspect a Haven MPP challenge or paid MPP URL without creating a Haven payment, signature, approval, or on-chain transaction.";
947
+ readonly behavior: "Parses an MPP challenge envelope and returns a typed quote with rail tag, amount, asset, and merchant context. Pure read-only — Haven is not contacted.";
948
+ readonly nextActionGuidance: "";
949
+ };
950
+ readonly payMpp: {
951
+ readonly summary: "Pay an inspected MPP challenge. The delegate key signs locally; Haven only validates and relays signed, on-chain-constrained payment transactions.";
952
+ readonly selectionGuidance: "Do not use this for read-only allowance, budget, spend-limit, remaining-amount, reset-period, or what-can-I-spend questions; use the allowance lookup tool instead.";
953
+ readonly behavior: "Authorizes the payment through Haven within the on-chain allowance, signs the challenge proof, and returns the proof header for retrying the original paid resource.";
954
+ readonly nextActionGuidance: "If approval is needed, preserve resume_state or payment_id and wait for nextAction=retry_original_x402_request before resuming.";
955
+ };
956
+ readonly resumeMpp: {
957
+ readonly summary: "Resume an MPP payment after the Haven wallet owner approved the funding step.";
958
+ readonly behavior: "Accepts either resume_state or payment_id and retries the original paid resource with the MPP proof header. No new Haven approval is created.";
959
+ readonly nextActionGuidance: "";
960
+ };
961
+ readonly getPaymentStatus: {
962
+ readonly summary: "Fetch structured Haven payment status, including phase and nextAction taxonomy for agent recovery.";
963
+ readonly behavior: "Accepts a payment intent or approval request id and returns the full state taxonomy (phase, nextAction, rail, amount, merchant, resource url, idempotency key, message).";
964
+ readonly nextActionGuidance: "";
965
+ };
966
+ readonly getResumeState: {
967
+ readonly summary: "Rehydrate stored x402 or MPP resume_state by payment_id.";
968
+ readonly behavior: "Returns the context that the agent originally received in a pending-approval response, reconstructed from Haven's database. This is context only; signing still happens locally when a resume tool is called.";
969
+ readonly nextActionGuidance: "";
970
+ };
971
+ readonly getAgent: {
972
+ readonly summary: "Return the authenticated agent identity, Haven wallet, delegate address, chain, and status.";
973
+ readonly behavior: "Read-only identity lookup. Useful for verifying which on-chain Safe and delegate the credential is bound to.";
974
+ readonly nextActionGuidance: "";
975
+ };
976
+ readonly getAllowances: {
977
+ readonly summary: "Return configured and on-chain allowance state for the authenticated agent. On-chain allowance is the real spend gate.";
978
+ readonly selectionGuidance: "Use this when the user asks about allowance, budget, spend limit, remaining amount, remaining allowance, remaining budget, daily limit, reset period, what can I spend, or what the agent can still spend.";
979
+ readonly behavior: "Reads the Safe AllowanceModule snapshot per token (allowance, spent, remaining, reset window). Configured amounts from Haven are returned alongside the on-chain truth.";
980
+ readonly nextActionGuidance: "";
981
+ };
982
+ readonly listReceipts: {
983
+ readonly summary: "List recent machine-payment receipts and evidence for bookkeeping.";
984
+ readonly selectionGuidance: "Use this for transaction history, receipts, payment evidence, or bookkeeping; use the allowance tool instead for remaining allowance, budget, spend-limit, or what-can-I-spend questions.";
985
+ readonly behavior: "Returns the agent's recent machine-payment receipts ordered by recency. Proof header values are not returned.";
986
+ readonly nextActionGuidance: "";
987
+ };
988
+ };
989
+ type SharedToolKey = keyof typeof toolDescriptions;
990
+
789
991
  /**
790
992
  * x402 protocol support for the Haven SDK.
791
993
  *
@@ -824,6 +1026,15 @@ declare function parsePaymentRequiredResponse(response: Response): Promise<X402P
824
1026
  * 3. null — no compatible option
825
1027
  */
826
1028
  declare function selectPaymentOption(accepts: X402PaymentOption[]): X402PaymentOption | null;
1029
+ /**
1030
+ * Select an option that can be paid with the official x402 EIP-3009 exact
1031
+ * scheme. Haven's older tx-hash proof path can describe more networks; the
1032
+ * merchant-verified path currently needs Base USDC.
1033
+ */
1034
+ declare function selectStandardPaymentOption(accepts: X402PaymentOption[]): X402PaymentOption | null;
1035
+ declare function x402AuthorizationAmount(option: X402PaymentOption): string;
1036
+ declare function buildX402ExpectedMessage(context: X402ExpectedContext): string;
1037
+ declare function toStandardPaymentRequirements(paymentRequired: X402PaymentRequired, option: X402PaymentOption): PaymentRequirements;
827
1038
  /**
828
1039
  * Encode a payment receipt as a base64 PAYMENT-SIGNATURE header value.
829
1040
  *
@@ -847,4 +1058,4 @@ declare function parseMachinePaymentChallengeResponse(response: Response): Promi
847
1058
  declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
848
1059
  declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
849
1060
 
850
- export { AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentPaymentEnumSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type ClaudeTool, type HavenAgent, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type MppAuthorizationOptions, type MppQuote, type MppResumeState, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type ResumeAuthorizedMppInput, type ResumeAuthorizedX402Input, type ResumeMppPaymentInput, type ResumeX402PaymentInput, type SignData, type X402AuthorizationOptions, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
1061
+ export { AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentPaymentEnumSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type ClaudeTool, type HavenAgent, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type MppAuthorizationOptions, type MppQuote, type MppResumeState, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type ResumeAuthorizedMppInput, type ResumeAuthorizedX402Input, type ResumeMppPaymentInput, type ResumeX402PaymentInput, type SharedToolKey, type SignData, type ToolDescription, type X402AuthorizationOptions, type X402ExpectedAuth, type X402ExpectedContext, type X402Intent, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, addressFromKey, buildMachinePaymentIdempotencyKey, buildX402ExpectedMessage, composeDescription, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, selectStandardPaymentOption, signHash, toStandardPaymentRequirements, toolDescriptions, verifySignature, x402AuthorizationAmount };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { PaymentRequirements } from 'x402/types';
2
+
1
3
  interface HavenClientConfig {
2
4
  /** Haven API key (sk_agent_xxx) */
3
5
  apiKey: string;
@@ -144,6 +146,55 @@ interface X402AuthorizationOptions {
144
146
  /** Stable caller-supplied key for this user intent. Prevents duplicate approvals across fresh 402 quotes. */
145
147
  idempotencyKey?: string;
146
148
  }
149
+ /**
150
+ * Keyless x402 construct result.
151
+ *
152
+ * Returned by `createX402Intent` — the non-custodial half of an x402 payment.
153
+ * It carries the unsigned funding hash (`signData.hash`, Safe → delegate EOA)
154
+ * plus everything the *edge* needs to build and sign the EIP-3009 merchant
155
+ * header itself. The construct path never signs; both delegate signatures
156
+ * (funding hash + merchant header) happen on the machine that holds the key.
157
+ */
158
+ interface X402Intent {
159
+ /** Haven payment id for the funding transfer. */
160
+ paymentId: string;
161
+ status: 'pending_signature';
162
+ /** ISO 8601 expiry of the funding intent, if returned. */
163
+ expiresAt?: string;
164
+ /** The unsigned funding hash to sign with the delegate key (Safe → delegate EOA). */
165
+ signData: SignData;
166
+ /** The selected x402 option — the edge needs this to build the EIP-3009 header. */
167
+ accepted: X402PaymentOption;
168
+ /** Resource URL the 402 came from. */
169
+ resourceUrl: string;
170
+ /** Merchant payTo address (the final recipient of the EIP-3009 transfer). */
171
+ merchantTo: string;
172
+ /** Atomic amount the edge signer must authorize in the merchant header. */
173
+ amountAtomic: string;
174
+ /** Token contract the merchant header must pay. */
175
+ asset: string;
176
+ /** x402 network the merchant header must use. */
177
+ network: string;
178
+ /** Haven-authenticated binding over the x402 expected context. */
179
+ expectedAuth: X402ExpectedAuth;
180
+ /** Delegate EOA the funding transfer tops up (the x402 payer). */
181
+ fundingTo: string;
182
+ }
183
+ interface X402ExpectedContext {
184
+ paymentId: string;
185
+ payloadHash: string;
186
+ resourceUrl: string;
187
+ merchantTo: string;
188
+ amount: string;
189
+ asset: string;
190
+ network: string;
191
+ }
192
+ interface X402ExpectedAuth {
193
+ version: 1;
194
+ message: string;
195
+ signature: string;
196
+ signer: string;
197
+ }
147
198
  /** Serializable HTTP request state for retrying the same x402 merchant request. */
148
199
  interface X402RequestSnapshot {
149
200
  url: string;
@@ -342,6 +393,8 @@ interface HavenAllowanceSummary {
342
393
  interface HavenPaymentReceipt {
343
394
  id: string;
344
395
  paymentId: string;
396
+ paymentIntentId?: string | null;
397
+ approvalRequestId?: string | null;
345
398
  rail: string;
346
399
  proofStatus: string;
347
400
  txHash: string;
@@ -415,20 +468,46 @@ declare const AgentPaymentNextAction: {
415
468
  readonly RequestAgainIfUserStillWantsIt: "request_again_if_user_still_wants_it";
416
469
  };
417
470
  type AgentPaymentNextAction = (typeof AgentPaymentNextAction)[keyof typeof AgentPaymentNextAction];
471
+ /**
472
+ * Stable rail identifier carried on Haven agent payment responses and resume
473
+ * state.
474
+ *
475
+ * Two layers of vocabulary share this enum because both reach the wire:
476
+ *
477
+ * - **Categorical rails** identify the rail family and are used as
478
+ * discriminators on `PaymentResumeState`: `direct`, `x402`, `mpp`.
479
+ * - **Granular rails** identify the specific protocol the backend persists
480
+ * and returns on response bodies: `mpp_demo`, `mpp_crypto`,
481
+ * `stripe_deposit`, `spt`. `x402` doubles as both categorical and
482
+ * granular.
483
+ *
484
+ * Consumers reading the top-level `rail` field on a payment status response
485
+ * should treat any `mpp*` value as the MPP family; consumers reading the
486
+ * `rail` field on a `MppResumeState` will always see the categorical `mpp`,
487
+ * with the granular value on `paymentRail`.
488
+ */
418
489
  declare const AgentPaymentRail: {
419
490
  /** Standard Haven payment from the user's Safe through an approved delegate allowance. */
420
491
  readonly Direct: "direct";
421
492
  /** x402 HTTP 402 payment flow with a Haven funding leg and merchant retry leg. */
422
493
  readonly X402: "x402";
423
- /** Machine Payment Protocol flow. */
494
+ /** Machine Payment Protocol family — categorical value used as a resume-state discriminator. */
424
495
  readonly Mpp: "mpp";
496
+ /** Haven internal MPP demo rail. Not for production traffic. */
497
+ readonly MppDemo: "mpp_demo";
498
+ /** Crypto-settled MPP rail. */
499
+ readonly MppCrypto: "mpp_crypto";
500
+ /** Stripe-deposit-backed MPP rail. */
501
+ readonly StripeDeposit: "stripe_deposit";
502
+ /** Stripe Payment Token MPP rail. */
503
+ readonly Spt: "spt";
425
504
  };
426
505
  type AgentPaymentRail = (typeof AgentPaymentRail)[keyof typeof AgentPaymentRail];
427
506
  type PaymentPhase = AgentPaymentPhase;
428
507
  type PaymentNextAction = AgentPaymentNextAction;
429
508
  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")[];
430
509
  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")[];
431
- declare const AGENT_PAYMENT_RAIL_VALUES: ("x402" | "mpp" | "direct")[];
510
+ declare const AGENT_PAYMENT_RAIL_VALUES: ("x402" | "mpp" | "mpp_demo" | "mpp_crypto" | "stripe_deposit" | "spt" | "direct")[];
432
511
  declare const AgentPaymentPhaseDescriptions: Record<AgentPaymentPhase, string>;
433
512
  declare const AgentPaymentNextActionDescriptions: Record<AgentPaymentNextAction, string>;
434
513
  declare const AgentPaymentRailDescriptions: Record<AgentPaymentRail, string>;
@@ -566,6 +645,23 @@ declare class HavenClient {
566
645
  * Returns the intent with the hash to sign.
567
646
  */
568
647
  createIntent(request: PaymentRequest): Promise<PaymentIntent>;
648
+ /**
649
+ * Keyless x402 construct.
650
+ *
651
+ * The non-custodial half of an x402 payment: posts the funding request to
652
+ * `/x402` and returns the unsigned funding hash plus the data the caller
653
+ * needs to build and sign the EIP-3009 merchant header itself. Crucially it
654
+ * does **not** sign — neither the funding hash nor the merchant header — so
655
+ * it works without a `delegateKey`. Both delegate signatures happen on the
656
+ * machine that holds the key (the edge); the hosted MCP server relays only.
657
+ *
658
+ * Use this from the hosted, keyless server. The all-in-one `authorizeX402`
659
+ * remains for local clients that hold the key.
660
+ *
661
+ * Throws (via the shared payment-state path) when the amount exceeds the
662
+ * on-chain allowance — there is nothing to sign until the user approves.
663
+ */
664
+ createX402Intent(paymentRequired: X402PaymentRequired, options?: X402AuthorizationOptions): Promise<X402Intent>;
569
665
  /**
570
666
  * Step 2: Sign a hash with the delegate key.
571
667
  *
@@ -723,8 +819,15 @@ declare class HavenClient {
723
819
  /**
724
820
  * Pre-built tool definitions for AI agent frameworks.
725
821
  *
726
- * These definitions describe the `make_payment` and `get_payment_status` tools
727
- * in the formats expected by Claude (Anthropic) and OpenAI.
822
+ * These definitions describe Haven's direct SDK tool-calling surface in the
823
+ * formats expected by Claude (Anthropic) and OpenAI.
824
+ *
825
+ * The agent payment surface used by these tools is shared with the
826
+ * `@haven_ai/mcp` server — both consume `toolDescriptions` from
827
+ * `./tool-descriptions.ts`. Each consumer composes its own user-visible string
828
+ * from the same semantic fragments, so guidance lands in both surfaces at
829
+ * once and a downstream test asserts the shared summary appears in every
830
+ * consumer description.
728
831
  *
729
832
  * Usage with Claude:
730
833
  * const response = await anthropic.messages.create({
@@ -786,6 +889,105 @@ declare function addressFromKey(privateKey: string): string;
786
889
  */
787
890
  declare function verifySignature(hash: string, signature: string, expectedAddress: string): boolean;
788
891
 
892
+ /**
893
+ * Shared semantic descriptions for Haven agent payment tools.
894
+ *
895
+ * Two surfaces in this repo expose Haven as a tool: the Claude / OpenAI
896
+ * function-calling tool definitions in `tools.ts` (used for direct SDK
897
+ * integrations) and the MCP server in `packages/mcp` (used by any MCP-speaking
898
+ * agent runtime). The two surfaces use different tool *names* — the SDK's
899
+ * tools are tuned for tool-calling conventions (`make_payment`,
900
+ * `authorize_x402_payment`); the MCP tools follow the MCP `haven_*` naming
901
+ * (`haven_pay_x402_quote`).
902
+ *
903
+ * The underlying *operations* are the same, so the descriptive prose should
904
+ * live in one place. Both surfaces import from this module and compose their
905
+ * own tool descriptions from these semantic fragments. Drift is caught by
906
+ * tests asserting each consumer's description string contains the shared
907
+ * `summary` from this module.
908
+ */
909
+ interface ToolDescription {
910
+ /** One-line summary of the operation. Used as the first sentence of every
911
+ * downstream description and as a stable substring for drift tests. */
912
+ summary: string;
913
+ /** Natural-language user intents that should make an agent prefer this
914
+ * tool over adjacent tools. Empty or omitted when the summary is enough. */
915
+ selectionGuidance?: string;
916
+ /** Concrete behaviour the tool performs end-to-end, including which
917
+ * non-custodial guarantee applies. */
918
+ behavior: string;
919
+ /** What the agent should do next on error / pending-approval states.
920
+ * Empty string if not applicable. */
921
+ nextActionGuidance: string;
922
+ }
923
+ /**
924
+ * Build a single description string from the three fragments. Joined with
925
+ * spaces so consumers can split on the summary substring if they need to.
926
+ */
927
+ declare function composeDescription(d: ToolDescription): string;
928
+ declare const toolDescriptions: {
929
+ readonly quoteX402: {
930
+ readonly summary: "Inspect an HTTP 402 x402 paid resource without creating a Haven payment, signature, approval, or on-chain transaction.";
931
+ readonly behavior: "Probes the merchant directly and parses the 402 response. Pure read-only client behavior — Haven is not contacted.";
932
+ readonly nextActionGuidance: "";
933
+ };
934
+ readonly payX402: {
935
+ readonly summary: "Pay an inspected x402 quote. The delegate key signs locally; Haven only validates and relays signed, on-chain-constrained payment transactions.";
936
+ readonly selectionGuidance: "Do not use this for read-only allowance, budget, spend-limit, remaining-amount, reset-period, or what-can-I-spend questions; use the allowance lookup tool instead.";
937
+ readonly behavior: "Signs the EIP-3009 payment from the delegate wallet, asks Haven for a Safe AllowanceModule top-up if needed, and returns the merchant response or a pending-approval state.";
938
+ readonly nextActionGuidance: "If approval is needed, preserve the returned resume_state and wait for nextAction=retry_original_x402_request before resuming.";
939
+ };
940
+ readonly resumeX402: {
941
+ readonly summary: "Resume an x402 payment after the Haven wallet owner approved the funding step.";
942
+ readonly behavior: "Accepts either resume_state or payment_id, validates the original x402 details against the approved Haven funding, and retries the merchant request with the X-PAYMENT header. No new Haven approval is created.";
943
+ readonly nextActionGuidance: "Only use when get_payment_status returns nextAction=retry_original_x402_request; do not start a new merchant session.";
944
+ };
945
+ readonly quoteMpp: {
946
+ readonly summary: "Inspect a Haven MPP challenge or paid MPP URL without creating a Haven payment, signature, approval, or on-chain transaction.";
947
+ readonly behavior: "Parses an MPP challenge envelope and returns a typed quote with rail tag, amount, asset, and merchant context. Pure read-only — Haven is not contacted.";
948
+ readonly nextActionGuidance: "";
949
+ };
950
+ readonly payMpp: {
951
+ readonly summary: "Pay an inspected MPP challenge. The delegate key signs locally; Haven only validates and relays signed, on-chain-constrained payment transactions.";
952
+ readonly selectionGuidance: "Do not use this for read-only allowance, budget, spend-limit, remaining-amount, reset-period, or what-can-I-spend questions; use the allowance lookup tool instead.";
953
+ readonly behavior: "Authorizes the payment through Haven within the on-chain allowance, signs the challenge proof, and returns the proof header for retrying the original paid resource.";
954
+ readonly nextActionGuidance: "If approval is needed, preserve resume_state or payment_id and wait for nextAction=retry_original_x402_request before resuming.";
955
+ };
956
+ readonly resumeMpp: {
957
+ readonly summary: "Resume an MPP payment after the Haven wallet owner approved the funding step.";
958
+ readonly behavior: "Accepts either resume_state or payment_id and retries the original paid resource with the MPP proof header. No new Haven approval is created.";
959
+ readonly nextActionGuidance: "";
960
+ };
961
+ readonly getPaymentStatus: {
962
+ readonly summary: "Fetch structured Haven payment status, including phase and nextAction taxonomy for agent recovery.";
963
+ readonly behavior: "Accepts a payment intent or approval request id and returns the full state taxonomy (phase, nextAction, rail, amount, merchant, resource url, idempotency key, message).";
964
+ readonly nextActionGuidance: "";
965
+ };
966
+ readonly getResumeState: {
967
+ readonly summary: "Rehydrate stored x402 or MPP resume_state by payment_id.";
968
+ readonly behavior: "Returns the context that the agent originally received in a pending-approval response, reconstructed from Haven's database. This is context only; signing still happens locally when a resume tool is called.";
969
+ readonly nextActionGuidance: "";
970
+ };
971
+ readonly getAgent: {
972
+ readonly summary: "Return the authenticated agent identity, Haven wallet, delegate address, chain, and status.";
973
+ readonly behavior: "Read-only identity lookup. Useful for verifying which on-chain Safe and delegate the credential is bound to.";
974
+ readonly nextActionGuidance: "";
975
+ };
976
+ readonly getAllowances: {
977
+ readonly summary: "Return configured and on-chain allowance state for the authenticated agent. On-chain allowance is the real spend gate.";
978
+ readonly selectionGuidance: "Use this when the user asks about allowance, budget, spend limit, remaining amount, remaining allowance, remaining budget, daily limit, reset period, what can I spend, or what the agent can still spend.";
979
+ readonly behavior: "Reads the Safe AllowanceModule snapshot per token (allowance, spent, remaining, reset window). Configured amounts from Haven are returned alongside the on-chain truth.";
980
+ readonly nextActionGuidance: "";
981
+ };
982
+ readonly listReceipts: {
983
+ readonly summary: "List recent machine-payment receipts and evidence for bookkeeping.";
984
+ readonly selectionGuidance: "Use this for transaction history, receipts, payment evidence, or bookkeeping; use the allowance tool instead for remaining allowance, budget, spend-limit, or what-can-I-spend questions.";
985
+ readonly behavior: "Returns the agent's recent machine-payment receipts ordered by recency. Proof header values are not returned.";
986
+ readonly nextActionGuidance: "";
987
+ };
988
+ };
989
+ type SharedToolKey = keyof typeof toolDescriptions;
990
+
789
991
  /**
790
992
  * x402 protocol support for the Haven SDK.
791
993
  *
@@ -824,6 +1026,15 @@ declare function parsePaymentRequiredResponse(response: Response): Promise<X402P
824
1026
  * 3. null — no compatible option
825
1027
  */
826
1028
  declare function selectPaymentOption(accepts: X402PaymentOption[]): X402PaymentOption | null;
1029
+ /**
1030
+ * Select an option that can be paid with the official x402 EIP-3009 exact
1031
+ * scheme. Haven's older tx-hash proof path can describe more networks; the
1032
+ * merchant-verified path currently needs Base USDC.
1033
+ */
1034
+ declare function selectStandardPaymentOption(accepts: X402PaymentOption[]): X402PaymentOption | null;
1035
+ declare function x402AuthorizationAmount(option: X402PaymentOption): string;
1036
+ declare function buildX402ExpectedMessage(context: X402ExpectedContext): string;
1037
+ declare function toStandardPaymentRequirements(paymentRequired: X402PaymentRequired, option: X402PaymentOption): PaymentRequirements;
827
1038
  /**
828
1039
  * Encode a payment receipt as a base64 PAYMENT-SIGNATURE header value.
829
1040
  *
@@ -847,4 +1058,4 @@ declare function parseMachinePaymentChallengeResponse(response: Response): Promi
847
1058
  declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
848
1059
  declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
849
1060
 
850
- export { AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentPaymentEnumSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type ClaudeTool, type HavenAgent, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type MppAuthorizationOptions, type MppQuote, type MppResumeState, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type ResumeAuthorizedMppInput, type ResumeAuthorizedX402Input, type ResumeMppPaymentInput, type ResumeX402PaymentInput, type SignData, type X402AuthorizationOptions, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
1061
+ export { AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentPaymentEnumSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type ClaudeTool, type HavenAgent, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type MppAuthorizationOptions, type MppQuote, type MppResumeState, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type ResumeAuthorizedMppInput, type ResumeAuthorizedX402Input, type ResumeMppPaymentInput, type ResumeX402PaymentInput, type SharedToolKey, type SignData, type ToolDescription, type X402AuthorizationOptions, type X402ExpectedAuth, type X402ExpectedContext, type X402Intent, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, addressFromKey, buildMachinePaymentIdempotencyKey, buildX402ExpectedMessage, composeDescription, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, selectStandardPaymentOption, signHash, toStandardPaymentRequirements, toolDescriptions, verifySignature, x402AuthorizationAmount };