@haven_ai/sdk 0.1.1 → 0.1.2
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/README.md +31 -13
- package/dist/index.cjs +532 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -3
- package/dist/index.d.ts +100 -3
- package/dist/index.js +528 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
TypeScript SDK for [Haven](https://github.com/d-hinders/Haven-AI) — agent wallet infrastructure for the autonomous economy.
|
|
4
4
|
|
|
5
|
-
Haven
|
|
5
|
+
Haven lets AI agents request and sign payments within strict, user-approved on-chain guardrails. This SDK makes it straightforward to integrate Haven payment requests into any agent without giving Haven custody of user or agent keys.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -92,7 +92,9 @@ const result = await haven.waitForConfirmation(intent.paymentId)
|
|
|
92
92
|
|
|
93
93
|
## x402 Protocol Support
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
Production merchant acceptance, facilitator, settlement, fiat, or acquiring functionality needs separate product and legal review under the repo's [CASP / MiCA guardrails](../../docs/regulatory/casp-risk-guardrails.md). The hosted x402 endpoint is an internal technical demo, not a merchant settlement product.
|
|
96
|
+
|
|
97
|
+
Haven natively supports the [x402](https://x402.org) payment protocol. When an API returns HTTP 402, the SDK evaluates the challenge against the agent's approved limits, uses the configured delegate key for the required signature, and retries automatically:
|
|
96
98
|
|
|
97
99
|
```typescript
|
|
98
100
|
// Automatic — fetch() intercepts 402, pays, and retries
|
|
@@ -147,9 +149,9 @@ for (const block of response.content) {
|
|
|
147
149
|
|
|
148
150
|
| Tool | Description |
|
|
149
151
|
|------|-------------|
|
|
150
|
-
| `make_payment` |
|
|
151
|
-
| `get_payment_status` | Check the status of a
|
|
152
|
-
| `authorize_x402_payment` |
|
|
152
|
+
| `make_payment` | Request and sign a payment from the user-controlled Safe within approved limits |
|
|
153
|
+
| `get_payment_status` | Check the status of a payment intent or approval request |
|
|
154
|
+
| `authorize_x402_payment` | Authorize a policy-limited x402 payment and return a payment header for an HTTP 402 resource |
|
|
153
155
|
|
|
154
156
|
## Configuration
|
|
155
157
|
|
|
@@ -167,33 +169,49 @@ const haven = new HavenClient({
|
|
|
167
169
|
|
|
168
170
|
## Payments above the on-chain allowance
|
|
169
171
|
|
|
170
|
-
Haven's policy lives
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
and queues it for the wallet owner
|
|
172
|
+
Haven's policy lives on the Safe AllowanceModule (token, amount, reset period).
|
|
173
|
+
If an agent requests a payment above the remaining allowance, Haven does **not**
|
|
174
|
+
reject it — it returns HTTP 202 with `status: 'pending_approval'`, a
|
|
175
|
+
`payment_id`, `phase`, and `next_action`, then queues it for the wallet owner
|
|
176
|
+
to approve in the dashboard.
|
|
174
177
|
|
|
175
178
|
Surface that to the user: the payment isn't dead, it's waiting for a human to
|
|
176
|
-
sign off.
|
|
179
|
+
sign off. Check `getPaymentStatus(payment_id)` or the `get_payment_status`
|
|
180
|
+
tool later instead of retrying in a tight loop.
|
|
181
|
+
|
|
182
|
+
For x402, the manual approval path has two steps. First, the user approves the
|
|
183
|
+
funding movement from the Haven wallet to the agent's delegate wallet. Once
|
|
184
|
+
Haven reports `next_action: 'retry_original_x402_request'`, retry the original
|
|
185
|
+
paid API request so the SDK can attach the merchant x402 payment header. Do not
|
|
186
|
+
rewrite the SDK while waiting for approval.
|
|
177
187
|
|
|
178
188
|
```typescript
|
|
179
189
|
try {
|
|
180
190
|
await haven.pay({ token: 'USDC', amount: '500', to: '0xabc...' })
|
|
181
191
|
} catch (err) {
|
|
182
|
-
if (err instanceof
|
|
183
|
-
|
|
192
|
+
if (err instanceof HavenPaymentStateError && err.nextAction === 'wait_for_user_approval') {
|
|
193
|
+
console.log(err.paymentId, err.phase, err.nextAction)
|
|
184
194
|
console.log('Queued for owner approval — visible in the Haven dashboard.')
|
|
185
195
|
}
|
|
186
196
|
}
|
|
197
|
+
|
|
198
|
+
const status = await haven.getPaymentStatus('approval-or-payment-id')
|
|
199
|
+
if (status.nextAction === 'retry_original_x402_request') {
|
|
200
|
+
// Retry the original paid API request.
|
|
201
|
+
}
|
|
187
202
|
```
|
|
188
203
|
|
|
189
204
|
## Error Handling
|
|
190
205
|
|
|
191
206
|
```typescript
|
|
192
|
-
import { HavenApiError, HavenSigningError, HavenTimeoutError } from '@haven_ai/sdk'
|
|
207
|
+
import { HavenApiError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError } from '@haven_ai/sdk'
|
|
193
208
|
|
|
194
209
|
try {
|
|
195
210
|
await haven.pay({ token: 'EURe', amount: '5.00', to: '0xabc...' })
|
|
196
211
|
} catch (err) {
|
|
212
|
+
if (err instanceof HavenPaymentStateError) {
|
|
213
|
+
console.log(err.paymentId, err.phase, err.nextAction)
|
|
214
|
+
}
|
|
197
215
|
if (err instanceof HavenApiError) {
|
|
198
216
|
console.log(err.statusCode, err.message) // API returned an error
|
|
199
217
|
}
|