@haven_ai/sdk 0.2.1-alpha.0 → 0.3.0-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 +29 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -128
- package/dist/index.d.ts +37 -128
- package/dist/index.js +30 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -114,12 +114,12 @@ var AgentPaymentNextAction = {
|
|
|
114
114
|
* the agent's per-token allowance needs to be raised before the payment
|
|
115
115
|
* can succeed. A user approval will not fix this state on its own.
|
|
116
116
|
*
|
|
117
|
-
* #
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
117
|
+
* #2914: the account-vocabulary spelling, and the only one — the
|
|
118
|
+
* pre-#2907 `fund_safe_or_raise_allowance` wire value (and the
|
|
119
|
+
* `AgentPaymentNextActionAccountAlias` seam #2908 added to bridge it) are
|
|
120
|
+
* retired along with the rest of the #2908 compatibility window.
|
|
121
121
|
*/
|
|
122
|
-
|
|
122
|
+
FundAccountOrRaiseAllowance: "fund_account_or_raise_allowance",
|
|
123
123
|
/**
|
|
124
124
|
* The delegate wallet may hold funds that were sent from the Safe but never
|
|
125
125
|
* settled to the merchant. The wallet owner should initiate a sweep to
|
|
@@ -146,19 +146,6 @@ var AgentPaymentNextAction = {
|
|
|
146
146
|
*/
|
|
147
147
|
AwaitingSettlementEvidence: "awaiting_settlement_evidence"
|
|
148
148
|
};
|
|
149
|
-
var AgentPaymentNextActionAccountAlias = {
|
|
150
|
-
/** Account-vocabulary twin of `fund_safe_or_raise_allowance`; same meaning. */
|
|
151
|
-
FundAccountOrRaiseAllowance: "fund_account_or_raise_allowance"
|
|
152
|
-
};
|
|
153
|
-
function canonicalAgentPaymentNextAction(value) {
|
|
154
|
-
if (value === AgentPaymentNextActionAccountAlias.FundAccountOrRaiseAllowance) {
|
|
155
|
-
return AgentPaymentNextAction.FundSafeOrRaiseAllowance;
|
|
156
|
-
}
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
|
-
function isFundAccountOrRaiseAllowance(value) {
|
|
160
|
-
return value === AgentPaymentNextAction.FundSafeOrRaiseAllowance || value === AgentPaymentNextActionAccountAlias.FundAccountOrRaiseAllowance;
|
|
161
|
-
}
|
|
162
149
|
var AgentPaymentFailureCode = {
|
|
163
150
|
/** A merchant-authoritative x402 price exceeds the caller's pre-funding max_amount cap. */
|
|
164
151
|
PriceExceedsMax: "PRICE_EXCEEDS_MAX",
|
|
@@ -253,7 +240,7 @@ var AgentPaymentNextActionDescriptions = {
|
|
|
253
240
|
[AgentPaymentNextAction.StopAndTellUser]: "Stop retrying this payment and tell the user what happened.",
|
|
254
241
|
[AgentPaymentNextAction.RequestAgainIfUserStillWantsIt]: "Ask again only if the user still wants the payment after expiry.",
|
|
255
242
|
[AgentPaymentNextAction.PaymentWindowExpired]: "The x402 funding/quote window expired. Re-quote with the same idempotency key before asking the signer to build a merchant payment header again.",
|
|
256
|
-
[AgentPaymentNextAction.
|
|
243
|
+
[AgentPaymentNextAction.FundAccountOrRaiseAllowance]: "Stop and tell the user that the account needs to be funded or the agent budget raised before the payment can succeed.",
|
|
257
244
|
[AgentPaymentNextAction.RetryWithExplicitContext]: "Retry the same tool call, this time passing merchant_url, tool_name, arguments, and mcp_transport explicitly \u2014 the server had no stored context to rehydrate for this payment id.",
|
|
258
245
|
[AgentPaymentNextAction.SweepStrandedFunds]: "Tell the user that funds may be stranded in the delegate wallet and prompt them to initiate a sweep in Haven to return them to the originating account.",
|
|
259
246
|
[AgentPaymentNextAction.AwaitingSettlementEvidence]: "The settlement window passed with no verified on-chain evidence yet. If you hold the merchant's real settlement transaction hash, report it with haven_report_settlement_evidence. Otherwise, Haven's settlement sweep may still attribute it within about two minutes \u2014 poll getPaymentStatus once more, then tell the user the goods were delivered but unverified if it still shows nothing."
|
|
@@ -1226,10 +1213,7 @@ function mapPaymentStatusResult(raw) {
|
|
|
1226
1213
|
rail: raw.rail,
|
|
1227
1214
|
status: raw.status,
|
|
1228
1215
|
phase: raw.phase,
|
|
1229
|
-
|
|
1230
|
-
// so every `=== AgentPaymentNextAction.X` downstream keeps working when
|
|
1231
|
-
// the server flips its emit at #2914.
|
|
1232
|
-
nextAction: canonicalAgentPaymentNextAction(raw.next_action),
|
|
1216
|
+
nextAction: raw.next_action,
|
|
1233
1217
|
amount: raw.amount,
|
|
1234
1218
|
token: raw.token,
|
|
1235
1219
|
resourceUrl: raw.resource_url,
|
|
@@ -1365,7 +1349,7 @@ function messageForState(label, status, paymentId, nextAction) {
|
|
|
1365
1349
|
function paymentStateFromRaw(label, raw) {
|
|
1366
1350
|
if (!raw.payment_id || !raw.status) return null;
|
|
1367
1351
|
const phase = raw.phase ?? phaseForStatus(raw.status);
|
|
1368
|
-
const nextAction =
|
|
1352
|
+
const nextAction = raw.next_action ?? nextActionForStatus(raw.status);
|
|
1369
1353
|
if (!phase || !nextAction) return null;
|
|
1370
1354
|
const amount = raw.amount ?? raw.requested ?? "";
|
|
1371
1355
|
const token = raw.token ?? "";
|
|
@@ -1688,20 +1672,6 @@ function verifyPaymentReceipt(receipt, recover = defaultRecover) {
|
|
|
1688
1672
|
return { verified: true, recoveredSigner: recovered };
|
|
1689
1673
|
}
|
|
1690
1674
|
|
|
1691
|
-
// src/account-naming.ts
|
|
1692
|
-
function readAccountAddress(raw) {
|
|
1693
|
-
return raw.account_address ?? raw.safe_address ?? void 0;
|
|
1694
|
-
}
|
|
1695
|
-
function readAccountId(raw) {
|
|
1696
|
-
return raw.account_id ?? raw.safe_id ?? void 0;
|
|
1697
|
-
}
|
|
1698
|
-
function accountAddressTwins(address) {
|
|
1699
|
-
return { accountAddress: address, safeAddress: address };
|
|
1700
|
-
}
|
|
1701
|
-
function readX402ReceiptPayer(raw) {
|
|
1702
|
-
return raw.payer ?? raw.account_address ?? raw.sign_data?.components?.payer_account ?? raw.safe_address ?? raw.sign_data?.components?.safe;
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
1675
|
// src/account-reads.ts
|
|
1706
1676
|
function safeBigInt(value) {
|
|
1707
1677
|
try {
|
|
@@ -1760,10 +1730,13 @@ var AccountReads = class {
|
|
|
1760
1730
|
const raw = await this.transport.get("/machine-payments/allowances");
|
|
1761
1731
|
return {
|
|
1762
1732
|
agentId: raw.agent_id,
|
|
1763
|
-
//
|
|
1764
|
-
//
|
|
1765
|
-
//
|
|
1766
|
-
|
|
1733
|
+
// `account_address` is required on the wire contract, so the declared
|
|
1734
|
+
// type stays `string`; a server that omits it is off-contract and the
|
|
1735
|
+
// cast is the one place that case is allowed through as `undefined`
|
|
1736
|
+
// rather than a fabricated `''` (a present-but-blank address downstream
|
|
1737
|
+
// — the hosted MCP output spreads this object, and the sweep uses it as
|
|
1738
|
+
// a destination).
|
|
1739
|
+
accountAddress: raw.account_address,
|
|
1767
1740
|
delegateAddress: raw.delegate_address,
|
|
1768
1741
|
chainId: raw.chain_id,
|
|
1769
1742
|
allowances: raw.allowances.map((allowance) => ({
|
|
@@ -1852,10 +1825,10 @@ var AccountReads = class {
|
|
|
1852
1825
|
id: raw.id,
|
|
1853
1826
|
name: raw.name,
|
|
1854
1827
|
status: raw.status,
|
|
1855
|
-
//
|
|
1856
|
-
//
|
|
1857
|
-
//
|
|
1858
|
-
|
|
1828
|
+
// See the comment on `getAllowances` above: `account_address` is
|
|
1829
|
+
// required on the wire contract, so an omission here is off-contract
|
|
1830
|
+
// and comes through as `undefined` rather than a fabricated `''`.
|
|
1831
|
+
accountAddress: raw.account_address,
|
|
1859
1832
|
delegateAddress: raw.delegate_address,
|
|
1860
1833
|
chainId: raw.chain_id,
|
|
1861
1834
|
executionRail: raw.execution_rail === "delegation" ? "delegation" : "legacy"
|
|
@@ -2187,6 +2160,13 @@ function assertCanResumeX402(status, paymentRequired, option) {
|
|
|
2187
2160
|
);
|
|
2188
2161
|
}
|
|
2189
2162
|
}
|
|
2163
|
+
|
|
2164
|
+
// src/account-naming.ts
|
|
2165
|
+
function readX402ReceiptPayer(raw) {
|
|
2166
|
+
return raw.payer ?? raw.account_address ?? raw.sign_data?.components?.payer_account;
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
// src/x402-funding-leg.ts
|
|
2190
2170
|
var X402FundingLeg = class {
|
|
2191
2171
|
delegateKey;
|
|
2192
2172
|
delegateAddress;
|
|
@@ -4212,13 +4192,13 @@ var toolDescriptions = {
|
|
|
4212
4192
|
summary: "Pay an inspected x402 quote. The delegate key signs locally; Haven only validates and relays signed, on-chain-constrained payment transactions.",
|
|
4213
4193
|
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.",
|
|
4214
4194
|
behavior: "Signs the payment locally and returns the merchant response. Settlement is either direct account-to-merchant with no funding leg, or a bridge that first redeems the agent's budget delegation to fund the delegate wallet for an EIP-3009 authorization. A payment outside the on-chain budget is declined before any money moves; nothing is queued for a human to approve later.",
|
|
4215
|
-
nextActionGuidance: "Preserve the returned resume_state \u2014 it identifies this payment if you need to ask about it later. This tool performs the merchant retry itself, so do not wait on a signal while the call is in flight. If the process crashes after this call and a later haven_get_payment_status reports nextAction=retry_original_x402_request, Haven's funding leg confirmed but no merchant response was ever recorded \u2014 call the resume tool with the preserved resume_state or payment_id instead of paying again. If the response carries phase=insufficient_funds and nextAction=
|
|
4195
|
+
nextActionGuidance: "Preserve the returned resume_state \u2014 it identifies this payment if you need to ask about it later. This tool performs the merchant retry itself, so do not wait on a signal while the call is in flight. If the process crashes after this call and a later haven_get_payment_status reports nextAction=retry_original_x402_request, Haven's funding leg confirmed but no merchant response was ever recorded \u2014 call the resume tool with the preserved resume_state or payment_id instead of paying again. If the response carries phase=insufficient_funds and nextAction=fund_account_or_raise_allowance, the payment cannot be retried until the account is funded or the agent budget raised \u2014 stop and tell the user the shortfall reported on the response."
|
|
4216
4196
|
},
|
|
4217
4197
|
payX402OneShot: {
|
|
4218
4198
|
summary: "Fetch an x402 paid HTTP resource in a single call. Handles the full probe -> pay -> retry round trip and returns the merchant response.",
|
|
4219
4199
|
selectionGuidance: "Prefer this over the quote+pay split when the agent just wants the paid resource and does not need to inspect the price first. If you already have a quote from haven_quote_x402, use haven_pay_x402_quote instead. Do not use for read-only allowance, budget, spend-limit, remaining-amount, reset-period, or what-can-I-spend questions; use the allowance lookup tool instead.",
|
|
4220
4200
|
behavior: "Calls the URL, parses any HTTP 402 x402 challenge, signs the payment locally, then retries the original request with the signed payment header (sent under PAYMENT-SIGNATURE, plus the legacy X-PAYMENT on the EIP-3009 path only) and returns the merchant response. Settlement is either direct account-to-merchant with no funding leg, or a bridge that first redeems the agent's budget delegation to fund the delegate wallet for an EIP-3009 authorization. A payment outside the on-chain budget is declined before any money moves; nothing is queued for a human to approve later. If the resource returns a non-402 status, returns it unchanged without contacting Haven.",
|
|
4221
|
-
nextActionGuidance: "Preserve the returned resume_state or paymentId \u2014 either identifies this payment if you need to ask about it later. This tool performs the merchant retry itself, so do not wait on a signal while the call is in flight. If the process crashes after this call and a later haven_get_payment_status reports nextAction=retry_original_x402_request, Haven's funding leg confirmed but no merchant response was ever recorded \u2014 call the resume tool with the preserved resume_state or payment_id instead of paying again. If the response carries phase=insufficient_funds and nextAction=
|
|
4201
|
+
nextActionGuidance: "Preserve the returned resume_state or paymentId \u2014 either identifies this payment if you need to ask about it later. This tool performs the merchant retry itself, so do not wait on a signal while the call is in flight. If the process crashes after this call and a later haven_get_payment_status reports nextAction=retry_original_x402_request, Haven's funding leg confirmed but no merchant response was ever recorded \u2014 call the resume tool with the preserved resume_state or payment_id instead of paying again. If the response carries phase=insufficient_funds and nextAction=fund_account_or_raise_allowance, the payment cannot be retried until the account is funded or the agent budget raised \u2014 stop and tell the user the shortfall reported on the response."
|
|
4222
4202
|
},
|
|
4223
4203
|
resumeX402: {
|
|
4224
4204
|
summary: "Resume an x402 payment whose Haven-side authorization already succeeded but whose merchant retry did not complete.",
|
|
@@ -4242,7 +4222,7 @@ var toolDescriptions = {
|
|
|
4242
4222
|
getAgent: {
|
|
4243
4223
|
summary: "Return the authenticated agent identity AND its live spend authority in one call: Haven wallet, delegate, chain, raw status, spend_authority_readiness, and per-token remaining allowance (atomic + human-readable). The recommended first call in a new session to confirm who you are and whether Haven will let you spend right now.",
|
|
4244
4224
|
selectionGuidance: "Use this as the one-shot orientation/bootstrap at the start of a session, or whenever you need to confirm identity together with whether the agent can spend right now. For a detailed per-token breakdown (configured vs spent vs reset window) use haven_get_allowances.",
|
|
4245
|
-
behavior: `Reads identity plus the live spend-authority snapshot in one shot \u2014 the agent's active on-chain budget delegation. spend_authority_readiness (readiness is a deprecated alias, same value) is "ready" when at least one token has remaining spend authority, "needs_approval" when the agent is active but has none, and "revoked" when the credential is not active. It covers hosted identity + on-chain spend authority ONLY \u2014 the hosted server cannot see the LOCAL signer, so "ready" does not mean the signer can start; verify the signer with a signer tool call or connect --doctor. An over-budget payment is declined before any money moves: there is no approval queue, so ask the owner to grant or raise the budget in Haven rather than waiting for an approval. allowances[] carries remainingAtomic and remainingDisplay per token. Identity fields: id, name, status, accountAddress
|
|
4225
|
+
behavior: `Reads identity plus the live spend-authority snapshot in one shot \u2014 the agent's active on-chain budget delegation. spend_authority_readiness (readiness is a deprecated alias, same value) is "ready" when at least one token has remaining spend authority, "needs_approval" when the agent is active but has none, and "revoked" when the credential is not active. It covers hosted identity + on-chain spend authority ONLY \u2014 the hosted server cannot see the LOCAL signer, so "ready" does not mean the signer can start; verify the signer with a signer tool call or connect --doctor. An over-budget payment is declined before any money moves: there is no approval queue, so ask the owner to grant or raise the budget in Haven rather than waiting for an approval. allowances[] carries remainingAtomic and remainingDisplay per token. Identity fields: id, name, status, accountAddress, delegateAddress, chainId.`,
|
|
4246
4226
|
nextActionGuidance: ""
|
|
4247
4227
|
},
|
|
4248
4228
|
getAllowances: {
|
|
@@ -5047,7 +5027,6 @@ exports.AgentPaymentFailureCode = AgentPaymentFailureCode;
|
|
|
5047
5027
|
exports.AgentPaymentFailureCodeDescriptions = AgentPaymentFailureCodeDescriptions;
|
|
5048
5028
|
exports.AgentPaymentFailureCodeSchema = AgentPaymentFailureCodeSchema;
|
|
5049
5029
|
exports.AgentPaymentNextAction = AgentPaymentNextAction;
|
|
5050
|
-
exports.AgentPaymentNextActionAccountAlias = AgentPaymentNextActionAccountAlias;
|
|
5051
5030
|
exports.AgentPaymentNextActionDescriptions = AgentPaymentNextActionDescriptions;
|
|
5052
5031
|
exports.AgentPaymentNextActionSchema = AgentPaymentNextActionSchema;
|
|
5053
5032
|
exports.AgentPaymentPhase = AgentPaymentPhase;
|
|
@@ -5095,12 +5074,10 @@ exports.X402_PAYMENT_HEADER_NAMES_SENT = X402_PAYMENT_HEADER_NAMES_SENT;
|
|
|
5095
5074
|
exports.X402_PAYMENT_REQUIRED_HEADER_NAME = X402_PAYMENT_REQUIRED_HEADER_NAME;
|
|
5096
5075
|
exports.X402_PAYMENT_RESPONSE_HEADER_NAME = X402_PAYMENT_RESPONSE_HEADER_NAME;
|
|
5097
5076
|
exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_SECONDS;
|
|
5098
|
-
exports.accountAddressTwins = accountAddressTwins;
|
|
5099
5077
|
exports.addressFromKey = addressFromKey;
|
|
5100
5078
|
exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
|
|
5101
5079
|
exports.buildSweepTypedData = buildSweepTypedData;
|
|
5102
5080
|
exports.buildX402ExpectedMessage = buildX402ExpectedMessage;
|
|
5103
|
-
exports.canonicalAgentPaymentNextAction = canonicalAgentPaymentNextAction;
|
|
5104
5081
|
exports.compareNodeVersions = compareNodeVersions;
|
|
5105
5082
|
exports.composeDescription = composeDescription;
|
|
5106
5083
|
exports.connectorRerunCommand = connectorRerunCommand;
|
|
@@ -5114,15 +5091,12 @@ exports.encodePaymentProof = encodePaymentProof;
|
|
|
5114
5091
|
exports.havenTools = havenTools;
|
|
5115
5092
|
exports.isConnectorChannel = isConnectorChannel;
|
|
5116
5093
|
exports.isErc7710Option = isErc7710Option;
|
|
5117
|
-
exports.isFundAccountOrRaiseAllowance = isFundAccountOrRaiseAllowance;
|
|
5118
5094
|
exports.isSupportedNodeVersion = isSupportedNodeVersion;
|
|
5119
5095
|
exports.isSweepableChain = isSweepableChain;
|
|
5120
5096
|
exports.isZeroSettlementTxHash = isZeroSettlementTxHash;
|
|
5121
5097
|
exports.normalizePaymentRequired = normalizePaymentRequired;
|
|
5122
5098
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
5123
5099
|
exports.parsePaymentRequiredResponse = parsePaymentRequiredResponse;
|
|
5124
|
-
exports.readAccountAddress = readAccountAddress;
|
|
5125
|
-
exports.readAccountId = readAccountId;
|
|
5126
5100
|
exports.readX402ReceiptPayer = readX402ReceiptPayer;
|
|
5127
5101
|
exports.resolveConnectorChannel = resolveConnectorChannel;
|
|
5128
5102
|
exports.resolveTokenFromAddress = resolveTokenFromAddress;
|