@haven_ai/sdk 0.1.13-alpha.0 → 0.1.14-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 +55 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -903,6 +903,37 @@ declare class HavenClient {
|
|
|
903
903
|
*/
|
|
904
904
|
payMppChallenge(quote: MppQuote, options?: MppAuthorizationOptions): Promise<Response>;
|
|
905
905
|
private retryX402Request;
|
|
906
|
+
/**
|
|
907
|
+
* Deliver an already-signed x402 payment header to the merchant and return
|
|
908
|
+
* the merchant's response. Used by the hosted MCP server to complete the
|
|
909
|
+
* merchant leg of an MCP tool payment after the edge signer has built the
|
|
910
|
+
* `X-PAYMENT` header.
|
|
911
|
+
*
|
|
912
|
+
* Custody note: this never needs the delegate key. It relays a signed,
|
|
913
|
+
* amount/merchant/nonce-bound EIP-3009 authorization the edge signer already
|
|
914
|
+
* produced — the hosted server cannot mint or reuse signing authority.
|
|
915
|
+
*
|
|
916
|
+
* When the URL is MCP-shaped (`/mcp` path), runs a fresh `initialize`
|
|
917
|
+
* handshake (the quote-time session is gone once funding confirms; the x402
|
|
918
|
+
* challenge is stateless w.r.t. the MCP session, so a fresh session is
|
|
919
|
+
* accepted), threads the session + wallet headers, sets `X-PAYMENT`, and
|
|
920
|
+
* collapses an SSE JSON-RPC response to its `result`.
|
|
921
|
+
*
|
|
922
|
+
* Limitation: detects MCP only by the `/mcp` path convention, not the
|
|
923
|
+
* Coinbase Bazaar `extensions.bazaar` 402 signal that `fetch()` also honors.
|
|
924
|
+
* A Bazaar-discoverable merchant on a non-`/mcp` URL would need the standard
|
|
925
|
+
* `fetch()` path. All current MCP-tool merchants use the `/mcp` convention.
|
|
926
|
+
*/
|
|
927
|
+
completeX402MerchantCall(input: {
|
|
928
|
+
url: string;
|
|
929
|
+
init?: RequestInit;
|
|
930
|
+
paymentHeader: string;
|
|
931
|
+
}): Promise<{
|
|
932
|
+
status: number;
|
|
933
|
+
ok: boolean;
|
|
934
|
+
body: unknown;
|
|
935
|
+
settlementTxHash?: string;
|
|
936
|
+
}>;
|
|
906
937
|
authorizeMachinePayment(challenge: MachinePaymentChallenge, options?: MppAuthorizationOptions): Promise<MachinePaymentReceipt>;
|
|
907
938
|
private authorizeMppDemoPayment;
|
|
908
939
|
resumeAuthorizedMpp(input: ResumeAuthorizedMppInput): Promise<MachinePaymentReceipt>;
|
|
@@ -1188,7 +1219,7 @@ type SharedToolKey = keyof typeof toolDescriptions;
|
|
|
1188
1219
|
* this canonical string and asserts byte-for-byte equality, so the two copies
|
|
1189
1220
|
* cannot drift.
|
|
1190
1221
|
*/
|
|
1191
|
-
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\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 come from the tools \u2014 never assume them\n\nDo not guess the wallet address, network, or budget. Read them live:\n\n- `haven_get_agent` \u2014 agent identity, Haven wallet address, network.\n- `haven_get_allowances` \u2014 current per-token budgets and what remains.\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- **Direct transfer:** `haven_pay` with recipient, amount, and token.\n- **x402 paywall:** `haven_quote_x402` to get a quote, then\n `haven_pay_x402_quote`. In the hosted setup the signing step happens in\n the local Haven signer; follow the tool results \u2014 they tell you the next\n action at every step. Retry the original request only when the result says\n `retry_original_x402_request`.\n- **Status:** `haven_get_payment_status` with a `payment_id` to check on\n 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- Never ask the user for private keys and never try to sign anything\n yourself \u2014 Haven signs. If a tool reports a missing or invalid credential,\n tell the user to re-run the Haven setup command.\n\n## Failure handling\n\nHaven errors are shaped `{ error, status, details? }` and written for\nhumans \u2014 surface the message 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- Budget exceeded: tell the user how much remains (from\n `haven_get_allowances`) and that they can raise the budget in Haven.\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";
|
|
1222
|
+
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\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 come from the tools \u2014 never assume them\n\nDo not guess the wallet address, network, or budget. Read them live:\n\n- `haven_get_agent` \u2014 agent identity, Haven wallet address, network.\n- `haven_get_allowances` \u2014 current per-token budgets and what remains.\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- **Direct transfer:** `haven_pay` with recipient, amount, and token.\n- **x402 paywall:** `haven_quote_x402` to get a quote, then\n `haven_pay_x402_quote`. In the hosted setup the signing step happens in\n the local Haven signer; follow the tool results \u2014 they tell you the next\n action at every step. Retry the original request only when the result says\n `retry_original_x402_request`.\n- **Paid MCP tool call:** `haven_pay_mcp_tool` with the merchant URL, tool\n name, and arguments. Then follow the returned steps: `haven_sign` the\n funding hash, `haven_submit` the signature, `haven_x402_sign_header` to\n build the payment header, and finally `haven_complete_mcp_tool` to settle\n with the merchant and get the tool result. Pass `payment_required` and\n `arguments` through verbatim from the `haven_pay_mcp_tool` result. Do not\n call the merchant yourself \u2014 Haven completes the merchant leg for you.\n- **Status:** `haven_get_payment_status` with a `payment_id` to check on\n 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- Never ask the user for private keys and never try to sign anything\n yourself \u2014 Haven signs. If a tool reports a missing or invalid credential,\n tell the user to re-run the Haven setup command.\n\n## Failure handling\n\nHaven errors are shaped `{ error, status, details? }` and written for\nhumans \u2014 surface the message 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- Budget exceeded: tell the user how much remains (from\n `haven_get_allowances`) and that they can raise the budget in Haven.\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";
|
|
1192
1223
|
/** Directory name for the installed skill folder. */
|
|
1193
1224
|
declare const SKILL_FOLDER_NAME = "haven-pay";
|
|
1194
1225
|
|
package/dist/index.d.ts
CHANGED
|
@@ -903,6 +903,37 @@ declare class HavenClient {
|
|
|
903
903
|
*/
|
|
904
904
|
payMppChallenge(quote: MppQuote, options?: MppAuthorizationOptions): Promise<Response>;
|
|
905
905
|
private retryX402Request;
|
|
906
|
+
/**
|
|
907
|
+
* Deliver an already-signed x402 payment header to the merchant and return
|
|
908
|
+
* the merchant's response. Used by the hosted MCP server to complete the
|
|
909
|
+
* merchant leg of an MCP tool payment after the edge signer has built the
|
|
910
|
+
* `X-PAYMENT` header.
|
|
911
|
+
*
|
|
912
|
+
* Custody note: this never needs the delegate key. It relays a signed,
|
|
913
|
+
* amount/merchant/nonce-bound EIP-3009 authorization the edge signer already
|
|
914
|
+
* produced — the hosted server cannot mint or reuse signing authority.
|
|
915
|
+
*
|
|
916
|
+
* When the URL is MCP-shaped (`/mcp` path), runs a fresh `initialize`
|
|
917
|
+
* handshake (the quote-time session is gone once funding confirms; the x402
|
|
918
|
+
* challenge is stateless w.r.t. the MCP session, so a fresh session is
|
|
919
|
+
* accepted), threads the session + wallet headers, sets `X-PAYMENT`, and
|
|
920
|
+
* collapses an SSE JSON-RPC response to its `result`.
|
|
921
|
+
*
|
|
922
|
+
* Limitation: detects MCP only by the `/mcp` path convention, not the
|
|
923
|
+
* Coinbase Bazaar `extensions.bazaar` 402 signal that `fetch()` also honors.
|
|
924
|
+
* A Bazaar-discoverable merchant on a non-`/mcp` URL would need the standard
|
|
925
|
+
* `fetch()` path. All current MCP-tool merchants use the `/mcp` convention.
|
|
926
|
+
*/
|
|
927
|
+
completeX402MerchantCall(input: {
|
|
928
|
+
url: string;
|
|
929
|
+
init?: RequestInit;
|
|
930
|
+
paymentHeader: string;
|
|
931
|
+
}): Promise<{
|
|
932
|
+
status: number;
|
|
933
|
+
ok: boolean;
|
|
934
|
+
body: unknown;
|
|
935
|
+
settlementTxHash?: string;
|
|
936
|
+
}>;
|
|
906
937
|
authorizeMachinePayment(challenge: MachinePaymentChallenge, options?: MppAuthorizationOptions): Promise<MachinePaymentReceipt>;
|
|
907
938
|
private authorizeMppDemoPayment;
|
|
908
939
|
resumeAuthorizedMpp(input: ResumeAuthorizedMppInput): Promise<MachinePaymentReceipt>;
|
|
@@ -1188,7 +1219,7 @@ type SharedToolKey = keyof typeof toolDescriptions;
|
|
|
1188
1219
|
* this canonical string and asserts byte-for-byte equality, so the two copies
|
|
1189
1220
|
* cannot drift.
|
|
1190
1221
|
*/
|
|
1191
|
-
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\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 come from the tools \u2014 never assume them\n\nDo not guess the wallet address, network, or budget. Read them live:\n\n- `haven_get_agent` \u2014 agent identity, Haven wallet address, network.\n- `haven_get_allowances` \u2014 current per-token budgets and what remains.\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- **Direct transfer:** `haven_pay` with recipient, amount, and token.\n- **x402 paywall:** `haven_quote_x402` to get a quote, then\n `haven_pay_x402_quote`. In the hosted setup the signing step happens in\n the local Haven signer; follow the tool results \u2014 they tell you the next\n action at every step. Retry the original request only when the result says\n `retry_original_x402_request`.\n- **Status:** `haven_get_payment_status` with a `payment_id` to check on\n 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- Never ask the user for private keys and never try to sign anything\n yourself \u2014 Haven signs. If a tool reports a missing or invalid credential,\n tell the user to re-run the Haven setup command.\n\n## Failure handling\n\nHaven errors are shaped `{ error, status, details? }` and written for\nhumans \u2014 surface the message 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- Budget exceeded: tell the user how much remains (from\n `haven_get_allowances`) and that they can raise the budget in Haven.\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";
|
|
1222
|
+
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\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 come from the tools \u2014 never assume them\n\nDo not guess the wallet address, network, or budget. Read them live:\n\n- `haven_get_agent` \u2014 agent identity, Haven wallet address, network.\n- `haven_get_allowances` \u2014 current per-token budgets and what remains.\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- **Direct transfer:** `haven_pay` with recipient, amount, and token.\n- **x402 paywall:** `haven_quote_x402` to get a quote, then\n `haven_pay_x402_quote`. In the hosted setup the signing step happens in\n the local Haven signer; follow the tool results \u2014 they tell you the next\n action at every step. Retry the original request only when the result says\n `retry_original_x402_request`.\n- **Paid MCP tool call:** `haven_pay_mcp_tool` with the merchant URL, tool\n name, and arguments. Then follow the returned steps: `haven_sign` the\n funding hash, `haven_submit` the signature, `haven_x402_sign_header` to\n build the payment header, and finally `haven_complete_mcp_tool` to settle\n with the merchant and get the tool result. Pass `payment_required` and\n `arguments` through verbatim from the `haven_pay_mcp_tool` result. Do not\n call the merchant yourself \u2014 Haven completes the merchant leg for you.\n- **Status:** `haven_get_payment_status` with a `payment_id` to check on\n 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- Never ask the user for private keys and never try to sign anything\n yourself \u2014 Haven signs. If a tool reports a missing or invalid credential,\n tell the user to re-run the Haven setup command.\n\n## Failure handling\n\nHaven errors are shaped `{ error, status, details? }` and written for\nhumans \u2014 surface the message 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- Budget exceeded: tell the user how much remains (from\n `haven_get_allowances`) and that they can raise the budget in Haven.\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";
|
|
1192
1223
|
/** Directory name for the installed skill folder. */
|
|
1193
1224
|
declare const SKILL_FOLDER_NAME = "haven-pay";
|
|
1194
1225
|
|
package/dist/index.js
CHANGED
|
@@ -1612,6 +1612,54 @@ var HavenClient = class {
|
|
|
1612
1612
|
});
|
|
1613
1613
|
return retryResponse;
|
|
1614
1614
|
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Deliver an already-signed x402 payment header to the merchant and return
|
|
1617
|
+
* the merchant's response. Used by the hosted MCP server to complete the
|
|
1618
|
+
* merchant leg of an MCP tool payment after the edge signer has built the
|
|
1619
|
+
* `X-PAYMENT` header.
|
|
1620
|
+
*
|
|
1621
|
+
* Custody note: this never needs the delegate key. It relays a signed,
|
|
1622
|
+
* amount/merchant/nonce-bound EIP-3009 authorization the edge signer already
|
|
1623
|
+
* produced — the hosted server cannot mint or reuse signing authority.
|
|
1624
|
+
*
|
|
1625
|
+
* When the URL is MCP-shaped (`/mcp` path), runs a fresh `initialize`
|
|
1626
|
+
* handshake (the quote-time session is gone once funding confirms; the x402
|
|
1627
|
+
* challenge is stateless w.r.t. the MCP session, so a fresh session is
|
|
1628
|
+
* accepted), threads the session + wallet headers, sets `X-PAYMENT`, and
|
|
1629
|
+
* collapses an SSE JSON-RPC response to its `result`.
|
|
1630
|
+
*
|
|
1631
|
+
* Limitation: detects MCP only by the `/mcp` path convention, not the
|
|
1632
|
+
* Coinbase Bazaar `extensions.bazaar` 402 signal that `fetch()` also honors.
|
|
1633
|
+
* A Bazaar-discoverable merchant on a non-`/mcp` URL would need the standard
|
|
1634
|
+
* `fetch()` path. All current MCP-tool merchants use the `/mcp` convention.
|
|
1635
|
+
*/
|
|
1636
|
+
async completeX402MerchantCall(input) {
|
|
1637
|
+
let mcpSessionId;
|
|
1638
|
+
if (isMcpUrl(input.url)) {
|
|
1639
|
+
mcpSessionId = await this.mcpInitialize(input.url, input.init);
|
|
1640
|
+
}
|
|
1641
|
+
let requestInit = this.withX402Wallet(input.init, this.x402PayerAddress()) ?? {};
|
|
1642
|
+
if (mcpSessionId) requestInit = this.withMcpHeaders(requestInit, mcpSessionId);
|
|
1643
|
+
const headers = new Headers(requestInit.headers);
|
|
1644
|
+
headers.set("X-PAYMENT", input.paymentHeader);
|
|
1645
|
+
requestInit = { ...requestInit, headers };
|
|
1646
|
+
const response = await globalThis.fetch(input.url, requestInit);
|
|
1647
|
+
const surfaced = mcpSessionId ? await this.surfaceMcpResult(response) : response;
|
|
1648
|
+
const settlement = parseMerchantSettlement(surfaced.headers.get("PAYMENT-RESPONSE"));
|
|
1649
|
+
const text = await surfaced.text();
|
|
1650
|
+
let body;
|
|
1651
|
+
try {
|
|
1652
|
+
body = text ? JSON.parse(text) : null;
|
|
1653
|
+
} catch {
|
|
1654
|
+
body = text;
|
|
1655
|
+
}
|
|
1656
|
+
return {
|
|
1657
|
+
status: surfaced.status,
|
|
1658
|
+
ok: surfaced.ok,
|
|
1659
|
+
body,
|
|
1660
|
+
settlementTxHash: settlement.settlementTxHash ?? void 0
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1615
1663
|
async authorizeMachinePayment(challenge, options = {}) {
|
|
1616
1664
|
if (!this.delegateKey) {
|
|
1617
1665
|
throw new HavenSigningError(
|
|
@@ -3082,6 +3130,13 @@ normal, not an error.
|
|
|
3082
3130
|
the local Haven signer; follow the tool results \u2014 they tell you the next
|
|
3083
3131
|
action at every step. Retry the original request only when the result says
|
|
3084
3132
|
\`retry_original_x402_request\`.
|
|
3133
|
+
- **Paid MCP tool call:** \`haven_pay_mcp_tool\` with the merchant URL, tool
|
|
3134
|
+
name, and arguments. Then follow the returned steps: \`haven_sign\` the
|
|
3135
|
+
funding hash, \`haven_submit\` the signature, \`haven_x402_sign_header\` to
|
|
3136
|
+
build the payment header, and finally \`haven_complete_mcp_tool\` to settle
|
|
3137
|
+
with the merchant and get the tool result. Pass \`payment_required\` and
|
|
3138
|
+
\`arguments\` through verbatim from the \`haven_pay_mcp_tool\` result. Do not
|
|
3139
|
+
call the merchant yourself \u2014 Haven completes the merchant leg for you.
|
|
3085
3140
|
- **Status:** \`haven_get_payment_status\` with a \`payment_id\` to check on
|
|
3086
3141
|
queued or in-flight payments. Do not poll in a tight loop.
|
|
3087
3142
|
|