@haven_ai/sdk 0.1.12-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.cjs
CHANGED
|
@@ -1614,6 +1614,54 @@ var HavenClient = class {
|
|
|
1614
1614
|
});
|
|
1615
1615
|
return retryResponse;
|
|
1616
1616
|
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Deliver an already-signed x402 payment header to the merchant and return
|
|
1619
|
+
* the merchant's response. Used by the hosted MCP server to complete the
|
|
1620
|
+
* merchant leg of an MCP tool payment after the edge signer has built the
|
|
1621
|
+
* `X-PAYMENT` header.
|
|
1622
|
+
*
|
|
1623
|
+
* Custody note: this never needs the delegate key. It relays a signed,
|
|
1624
|
+
* amount/merchant/nonce-bound EIP-3009 authorization the edge signer already
|
|
1625
|
+
* produced — the hosted server cannot mint or reuse signing authority.
|
|
1626
|
+
*
|
|
1627
|
+
* When the URL is MCP-shaped (`/mcp` path), runs a fresh `initialize`
|
|
1628
|
+
* handshake (the quote-time session is gone once funding confirms; the x402
|
|
1629
|
+
* challenge is stateless w.r.t. the MCP session, so a fresh session is
|
|
1630
|
+
* accepted), threads the session + wallet headers, sets `X-PAYMENT`, and
|
|
1631
|
+
* collapses an SSE JSON-RPC response to its `result`.
|
|
1632
|
+
*
|
|
1633
|
+
* Limitation: detects MCP only by the `/mcp` path convention, not the
|
|
1634
|
+
* Coinbase Bazaar `extensions.bazaar` 402 signal that `fetch()` also honors.
|
|
1635
|
+
* A Bazaar-discoverable merchant on a non-`/mcp` URL would need the standard
|
|
1636
|
+
* `fetch()` path. All current MCP-tool merchants use the `/mcp` convention.
|
|
1637
|
+
*/
|
|
1638
|
+
async completeX402MerchantCall(input) {
|
|
1639
|
+
let mcpSessionId;
|
|
1640
|
+
if (isMcpUrl(input.url)) {
|
|
1641
|
+
mcpSessionId = await this.mcpInitialize(input.url, input.init);
|
|
1642
|
+
}
|
|
1643
|
+
let requestInit = this.withX402Wallet(input.init, this.x402PayerAddress()) ?? {};
|
|
1644
|
+
if (mcpSessionId) requestInit = this.withMcpHeaders(requestInit, mcpSessionId);
|
|
1645
|
+
const headers = new Headers(requestInit.headers);
|
|
1646
|
+
headers.set("X-PAYMENT", input.paymentHeader);
|
|
1647
|
+
requestInit = { ...requestInit, headers };
|
|
1648
|
+
const response = await globalThis.fetch(input.url, requestInit);
|
|
1649
|
+
const surfaced = mcpSessionId ? await this.surfaceMcpResult(response) : response;
|
|
1650
|
+
const settlement = parseMerchantSettlement(surfaced.headers.get("PAYMENT-RESPONSE"));
|
|
1651
|
+
const text = await surfaced.text();
|
|
1652
|
+
let body;
|
|
1653
|
+
try {
|
|
1654
|
+
body = text ? JSON.parse(text) : null;
|
|
1655
|
+
} catch {
|
|
1656
|
+
body = text;
|
|
1657
|
+
}
|
|
1658
|
+
return {
|
|
1659
|
+
status: surfaced.status,
|
|
1660
|
+
ok: surfaced.ok,
|
|
1661
|
+
body,
|
|
1662
|
+
settlementTxHash: settlement.settlementTxHash ?? void 0
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1617
1665
|
async authorizeMachinePayment(challenge, options = {}) {
|
|
1618
1666
|
if (!this.delegateKey) {
|
|
1619
1667
|
throw new HavenSigningError(
|
|
@@ -3084,6 +3132,13 @@ normal, not an error.
|
|
|
3084
3132
|
the local Haven signer; follow the tool results \u2014 they tell you the next
|
|
3085
3133
|
action at every step. Retry the original request only when the result says
|
|
3086
3134
|
\`retry_original_x402_request\`.
|
|
3135
|
+
- **Paid MCP tool call:** \`haven_pay_mcp_tool\` with the merchant URL, tool
|
|
3136
|
+
name, and arguments. Then follow the returned steps: \`haven_sign\` the
|
|
3137
|
+
funding hash, \`haven_submit\` the signature, \`haven_x402_sign_header\` to
|
|
3138
|
+
build the payment header, and finally \`haven_complete_mcp_tool\` to settle
|
|
3139
|
+
with the merchant and get the tool result. Pass \`payment_required\` and
|
|
3140
|
+
\`arguments\` through verbatim from the \`haven_pay_mcp_tool\` result. Do not
|
|
3141
|
+
call the merchant yourself \u2014 Haven completes the merchant leg for you.
|
|
3087
3142
|
- **Status:** \`haven_get_payment_status\` with a \`payment_id\` to check on
|
|
3088
3143
|
queued or in-flight payments. Do not poll in a tight loop.
|
|
3089
3144
|
|