@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.js
CHANGED
|
@@ -112,12 +112,12 @@ var AgentPaymentNextAction = {
|
|
|
112
112
|
* the agent's per-token allowance needs to be raised before the payment
|
|
113
113
|
* can succeed. A user approval will not fix this state on its own.
|
|
114
114
|
*
|
|
115
|
-
* #
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
115
|
+
* #2914: the account-vocabulary spelling, and the only one — the
|
|
116
|
+
* pre-#2907 `fund_safe_or_raise_allowance` wire value (and the
|
|
117
|
+
* `AgentPaymentNextActionAccountAlias` seam #2908 added to bridge it) are
|
|
118
|
+
* retired along with the rest of the #2908 compatibility window.
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
FundAccountOrRaiseAllowance: "fund_account_or_raise_allowance",
|
|
121
121
|
/**
|
|
122
122
|
* The delegate wallet may hold funds that were sent from the Safe but never
|
|
123
123
|
* settled to the merchant. The wallet owner should initiate a sweep to
|
|
@@ -144,19 +144,6 @@ var AgentPaymentNextAction = {
|
|
|
144
144
|
*/
|
|
145
145
|
AwaitingSettlementEvidence: "awaiting_settlement_evidence"
|
|
146
146
|
};
|
|
147
|
-
var AgentPaymentNextActionAccountAlias = {
|
|
148
|
-
/** Account-vocabulary twin of `fund_safe_or_raise_allowance`; same meaning. */
|
|
149
|
-
FundAccountOrRaiseAllowance: "fund_account_or_raise_allowance"
|
|
150
|
-
};
|
|
151
|
-
function canonicalAgentPaymentNextAction(value) {
|
|
152
|
-
if (value === AgentPaymentNextActionAccountAlias.FundAccountOrRaiseAllowance) {
|
|
153
|
-
return AgentPaymentNextAction.FundSafeOrRaiseAllowance;
|
|
154
|
-
}
|
|
155
|
-
return value;
|
|
156
|
-
}
|
|
157
|
-
function isFundAccountOrRaiseAllowance(value) {
|
|
158
|
-
return value === AgentPaymentNextAction.FundSafeOrRaiseAllowance || value === AgentPaymentNextActionAccountAlias.FundAccountOrRaiseAllowance;
|
|
159
|
-
}
|
|
160
147
|
var AgentPaymentFailureCode = {
|
|
161
148
|
/** A merchant-authoritative x402 price exceeds the caller's pre-funding max_amount cap. */
|
|
162
149
|
PriceExceedsMax: "PRICE_EXCEEDS_MAX",
|
|
@@ -251,7 +238,7 @@ var AgentPaymentNextActionDescriptions = {
|
|
|
251
238
|
[AgentPaymentNextAction.StopAndTellUser]: "Stop retrying this payment and tell the user what happened.",
|
|
252
239
|
[AgentPaymentNextAction.RequestAgainIfUserStillWantsIt]: "Ask again only if the user still wants the payment after expiry.",
|
|
253
240
|
[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.",
|
|
254
|
-
[AgentPaymentNextAction.
|
|
241
|
+
[AgentPaymentNextAction.FundAccountOrRaiseAllowance]: "Stop and tell the user that the account needs to be funded or the agent budget raised before the payment can succeed.",
|
|
255
242
|
[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.",
|
|
256
243
|
[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.",
|
|
257
244
|
[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."
|
|
@@ -1224,10 +1211,7 @@ function mapPaymentStatusResult(raw) {
|
|
|
1224
1211
|
rail: raw.rail,
|
|
1225
1212
|
status: raw.status,
|
|
1226
1213
|
phase: raw.phase,
|
|
1227
|
-
|
|
1228
|
-
// so every `=== AgentPaymentNextAction.X` downstream keeps working when
|
|
1229
|
-
// the server flips its emit at #2914.
|
|
1230
|
-
nextAction: canonicalAgentPaymentNextAction(raw.next_action),
|
|
1214
|
+
nextAction: raw.next_action,
|
|
1231
1215
|
amount: raw.amount,
|
|
1232
1216
|
token: raw.token,
|
|
1233
1217
|
resourceUrl: raw.resource_url,
|
|
@@ -1363,7 +1347,7 @@ function messageForState(label, status, paymentId, nextAction) {
|
|
|
1363
1347
|
function paymentStateFromRaw(label, raw) {
|
|
1364
1348
|
if (!raw.payment_id || !raw.status) return null;
|
|
1365
1349
|
const phase = raw.phase ?? phaseForStatus(raw.status);
|
|
1366
|
-
const nextAction =
|
|
1350
|
+
const nextAction = raw.next_action ?? nextActionForStatus(raw.status);
|
|
1367
1351
|
if (!phase || !nextAction) return null;
|
|
1368
1352
|
const amount = raw.amount ?? raw.requested ?? "";
|
|
1369
1353
|
const token = raw.token ?? "";
|
|
@@ -1686,20 +1670,6 @@ function verifyPaymentReceipt(receipt, recover = defaultRecover) {
|
|
|
1686
1670
|
return { verified: true, recoveredSigner: recovered };
|
|
1687
1671
|
}
|
|
1688
1672
|
|
|
1689
|
-
// src/account-naming.ts
|
|
1690
|
-
function readAccountAddress(raw) {
|
|
1691
|
-
return raw.account_address ?? raw.safe_address ?? void 0;
|
|
1692
|
-
}
|
|
1693
|
-
function readAccountId(raw) {
|
|
1694
|
-
return raw.account_id ?? raw.safe_id ?? void 0;
|
|
1695
|
-
}
|
|
1696
|
-
function accountAddressTwins(address) {
|
|
1697
|
-
return { accountAddress: address, safeAddress: address };
|
|
1698
|
-
}
|
|
1699
|
-
function readX402ReceiptPayer(raw) {
|
|
1700
|
-
return raw.payer ?? raw.account_address ?? raw.sign_data?.components?.payer_account ?? raw.safe_address ?? raw.sign_data?.components?.safe;
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
1673
|
// src/account-reads.ts
|
|
1704
1674
|
function safeBigInt(value) {
|
|
1705
1675
|
try {
|
|
@@ -1758,10 +1728,13 @@ var AccountReads = class {
|
|
|
1758
1728
|
const raw = await this.transport.get("/machine-payments/allowances");
|
|
1759
1729
|
return {
|
|
1760
1730
|
agentId: raw.agent_id,
|
|
1761
|
-
//
|
|
1762
|
-
//
|
|
1763
|
-
//
|
|
1764
|
-
|
|
1731
|
+
// `account_address` is required on the wire contract, so the declared
|
|
1732
|
+
// type stays `string`; a server that omits it is off-contract and the
|
|
1733
|
+
// cast is the one place that case is allowed through as `undefined`
|
|
1734
|
+
// rather than a fabricated `''` (a present-but-blank address downstream
|
|
1735
|
+
// — the hosted MCP output spreads this object, and the sweep uses it as
|
|
1736
|
+
// a destination).
|
|
1737
|
+
accountAddress: raw.account_address,
|
|
1765
1738
|
delegateAddress: raw.delegate_address,
|
|
1766
1739
|
chainId: raw.chain_id,
|
|
1767
1740
|
allowances: raw.allowances.map((allowance) => ({
|
|
@@ -1850,10 +1823,10 @@ var AccountReads = class {
|
|
|
1850
1823
|
id: raw.id,
|
|
1851
1824
|
name: raw.name,
|
|
1852
1825
|
status: raw.status,
|
|
1853
|
-
//
|
|
1854
|
-
//
|
|
1855
|
-
//
|
|
1856
|
-
|
|
1826
|
+
// See the comment on `getAllowances` above: `account_address` is
|
|
1827
|
+
// required on the wire contract, so an omission here is off-contract
|
|
1828
|
+
// and comes through as `undefined` rather than a fabricated `''`.
|
|
1829
|
+
accountAddress: raw.account_address,
|
|
1857
1830
|
delegateAddress: raw.delegate_address,
|
|
1858
1831
|
chainId: raw.chain_id,
|
|
1859
1832
|
executionRail: raw.execution_rail === "delegation" ? "delegation" : "legacy"
|
|
@@ -2185,6 +2158,13 @@ function assertCanResumeX402(status, paymentRequired, option) {
|
|
|
2185
2158
|
);
|
|
2186
2159
|
}
|
|
2187
2160
|
}
|
|
2161
|
+
|
|
2162
|
+
// src/account-naming.ts
|
|
2163
|
+
function readX402ReceiptPayer(raw) {
|
|
2164
|
+
return raw.payer ?? raw.account_address ?? raw.sign_data?.components?.payer_account;
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// src/x402-funding-leg.ts
|
|
2188
2168
|
var X402FundingLeg = class {
|
|
2189
2169
|
delegateKey;
|
|
2190
2170
|
delegateAddress;
|
|
@@ -4210,13 +4190,13 @@ var toolDescriptions = {
|
|
|
4210
4190
|
summary: "Pay an inspected x402 quote. The delegate key signs locally; Haven only validates and relays signed, on-chain-constrained payment transactions.",
|
|
4211
4191
|
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.",
|
|
4212
4192
|
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.",
|
|
4213
|
-
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=
|
|
4193
|
+
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."
|
|
4214
4194
|
},
|
|
4215
4195
|
payX402OneShot: {
|
|
4216
4196
|
summary: "Fetch an x402 paid HTTP resource in a single call. Handles the full probe -> pay -> retry round trip and returns the merchant response.",
|
|
4217
4197
|
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.",
|
|
4218
4198
|
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.",
|
|
4219
|
-
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=
|
|
4199
|
+
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."
|
|
4220
4200
|
},
|
|
4221
4201
|
resumeX402: {
|
|
4222
4202
|
summary: "Resume an x402 payment whose Haven-side authorization already succeeded but whose merchant retry did not complete.",
|
|
@@ -4240,7 +4220,7 @@ var toolDescriptions = {
|
|
|
4240
4220
|
getAgent: {
|
|
4241
4221
|
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.",
|
|
4242
4222
|
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.",
|
|
4243
|
-
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
|
|
4223
|
+
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.`,
|
|
4244
4224
|
nextActionGuidance: ""
|
|
4245
4225
|
},
|
|
4246
4226
|
getAllowances: {
|
|
@@ -5027,6 +5007,6 @@ function sameUrl(a, b) {
|
|
|
5027
5007
|
}
|
|
5028
5008
|
}
|
|
5029
5009
|
|
|
5030
|
-
export { AGENT_APPROVAL_RELAY_JSON_SENTENCE, AGENT_APPROVAL_RELAY_PROSE_SENTENCE, AGENT_COMMAND_MODIFICATION_SENTENCE, AGENT_JSON_MODE_SENTENCE, AGENT_LOCAL_KEY_SENTENCE, AGENT_NETWORK_ACCESS_SENTENCE, AGENT_ONBOARDING_PROMPT, AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AGENT_README_SECTION_MD, AGENT_SECRET_HYGIENE_SENTENCE, AGENT_WIRING_COLLISION_RELAY_SENTENCE, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction,
|
|
5010
|
+
export { AGENT_APPROVAL_RELAY_JSON_SENTENCE, AGENT_APPROVAL_RELAY_PROSE_SENTENCE, AGENT_COMMAND_MODIFICATION_SENTENCE, AGENT_JSON_MODE_SENTENCE, AGENT_LOCAL_KEY_SENTENCE, AGENT_NETWORK_ACCESS_SENTENCE, AGENT_ONBOARDING_PROMPT, AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AGENT_README_SECTION_MD, AGENT_SECRET_HYGIENE_SENTENCE, AGENT_WIRING_COLLISION_RELAY_SENTENCE, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, AgentPaymentWarningCode, CONNECTOR_PACKAGE_NAME, DEFAULT_CONFIRMATION_TIMEOUT_MS, DISCOVERY_MAX_BYTES, ERC7710_ASSET_TRANSFER_METHOD, HAVEN_AGENT_RUNBOOK_MD, HAVEN_CONNECTOR_CHANNEL, HAVEN_MINIMUM_NODE_VERSION, HAVEN_SKILL_BODY_MD, HAVEN_SKILL_MD, HavenApiError, HavenClient, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, HavenZeroSettlementHashError, MERCHANT_DISCOVERY_PATHS, MerchantTimeoutError, RECEIPT_VERSION, SIGNER_UPDATE_FALLBACK, SKILL_FOLDER_NAME, SWEEP_BASE_CHAIN_ID, SWEEP_BASE_SEPOLIA_CHAIN_ID, SWEEP_BASE_SEPOLIA_USDC_ADDRESS, SWEEP_BASE_USDC_ADDRESS, SignerRefusalCode, TRANSFER_WITH_AUTHORIZATION_TYPES, X402AlreadySettledError, X402PaymentHeaderValidationError, X402UnexpectedStatusError, X402_LEGACY_PAYMENT_HEADER_NAME, X402_MAX_AUTHORIZATION_WINDOW_SECONDS, X402_PAYMENT_HEADER_NAME, X402_PAYMENT_HEADER_NAMES_SENT, X402_PAYMENT_REQUIRED_HEADER_NAME, X402_PAYMENT_RESPONSE_HEADER_NAME, X402_SETTLEMENT_FORWARD_MARGIN_SECONDS, addressFromKey, buildSweepAuthorizationMessage, buildSweepTypedData, buildX402ExpectedMessage, compareNodeVersions, composeDescription, connectorRerunCommand, connectorSpec, decodeBase64Json, decodeBase64Utf8, discoverMerchantMcpUrl, encodeBase64Json, encodeBase64Utf8, encodePaymentProof, havenTools, isConnectorChannel, isErc7710Option, isSupportedNodeVersion, isSweepableChain, isZeroSettlementTxHash, normalizePaymentRequired, parsePaymentRequired, parsePaymentRequiredResponse, readX402ReceiptPayer, resolveConnectorChannel, resolveTokenFromAddress, sameUrl, selectErc7710PaymentOption, selectPaymentOption, selectStandardPaymentOption, selectX402SettlementScheme, signHash, signUserOpTypedDataForDelegation, signerUpdateFallback, sweepUsdcAddress, sweepUsdcDomain, toStandardPaymentRequirements, toolDescriptions, unsupportedNodeVersionMessage, validateStandardX402PaymentHeader, verifyPaymentReceipt, verifySignature, x402AssetTransferMethod, x402AuthorizationAmount, x402FacilitatorAddresses, x402V2PaymentEnvelope };
|
|
5031
5011
|
//# sourceMappingURL=index.js.map
|
|
5032
5012
|
//# sourceMappingURL=index.js.map
|