@haven_ai/sdk 0.1.2 → 0.1.4
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 +154 -13
- package/dist/index.cjs +1111 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +405 -8
- package/dist/index.d.ts +405 -8
- package/dist/index.js +1100 -93
- package/dist/index.js.map +1 -1
- package/examples/mcp-x402-sse.ts +149 -0
- package/examples/x402_openapi_python.py +114 -0
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -13,6 +13,15 @@ interface HavenClientConfig {
|
|
|
13
13
|
confirmationTimeout?: number;
|
|
14
14
|
/** Polling interval in ms when waiting for confirmation (default: 3000) */
|
|
15
15
|
pollingInterval?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Extra headers to attach to every request to the Haven API.
|
|
18
|
+
*
|
|
19
|
+
* Used by the MCP server to tag requests with `X-Haven-MCP-Tool: <name>`
|
|
20
|
+
* so the backend can record an audit-log entry per tool invocation. Has
|
|
21
|
+
* no effect on outbound merchant requests (x402 / MPP) — those are
|
|
22
|
+
* standard HTTP and never carry Haven-internal headers.
|
|
23
|
+
*/
|
|
24
|
+
defaultHeaders?: Record<string, string>;
|
|
16
25
|
}
|
|
17
26
|
interface PaymentRequest {
|
|
18
27
|
/** Token symbol: "EURe", "USDC.e", or "xDAI" */
|
|
@@ -113,6 +122,151 @@ interface X402Receipt {
|
|
|
113
122
|
merchantTo?: string | null;
|
|
114
123
|
payer?: string;
|
|
115
124
|
chainId?: number;
|
|
125
|
+
haven?: {
|
|
126
|
+
paymentId: string;
|
|
127
|
+
fundingTxHash: string;
|
|
128
|
+
fundingExplorerUrl: string;
|
|
129
|
+
};
|
|
130
|
+
merchant?: {
|
|
131
|
+
payTo: string | null;
|
|
132
|
+
settlementTxHash?: string | null;
|
|
133
|
+
settlementExplorerUrl?: string | null;
|
|
134
|
+
};
|
|
135
|
+
x402?: {
|
|
136
|
+
amount: string;
|
|
137
|
+
token: string;
|
|
138
|
+
network: string;
|
|
139
|
+
asset: string;
|
|
140
|
+
resource: string;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
interface X402AuthorizationOptions {
|
|
144
|
+
/** Stable caller-supplied key for this user intent. Prevents duplicate approvals across fresh 402 quotes. */
|
|
145
|
+
idempotencyKey?: string;
|
|
146
|
+
}
|
|
147
|
+
/** Serializable HTTP request state for retrying the same x402 merchant request. */
|
|
148
|
+
interface X402RequestSnapshot {
|
|
149
|
+
url: string;
|
|
150
|
+
method: string;
|
|
151
|
+
headers: [string, string][];
|
|
152
|
+
body?: string;
|
|
153
|
+
}
|
|
154
|
+
/** Quote parsed from an HTTP 402 response without creating a Haven payment. */
|
|
155
|
+
interface X402Quote {
|
|
156
|
+
rail: 'x402';
|
|
157
|
+
idempotencyKey: string;
|
|
158
|
+
paymentRequired: X402PaymentRequired;
|
|
159
|
+
accepted: X402PaymentOption;
|
|
160
|
+
request: X402RequestSnapshot;
|
|
161
|
+
resourceUrl: string;
|
|
162
|
+
description: string | null;
|
|
163
|
+
mimeType: string | null;
|
|
164
|
+
amountAtomic: string;
|
|
165
|
+
amount: string;
|
|
166
|
+
token: string;
|
|
167
|
+
asset: string;
|
|
168
|
+
network: string;
|
|
169
|
+
chainId: number | null;
|
|
170
|
+
merchantAddress: string;
|
|
171
|
+
maxTimeoutSeconds: number;
|
|
172
|
+
}
|
|
173
|
+
/** State bundle an agent can persist while waiting for manual x402 approval. */
|
|
174
|
+
interface X402ResumeState {
|
|
175
|
+
rail: 'x402';
|
|
176
|
+
paymentId: string;
|
|
177
|
+
idempotencyKey: string;
|
|
178
|
+
paymentRequired: X402PaymentRequired;
|
|
179
|
+
accepted: X402PaymentOption;
|
|
180
|
+
url: string;
|
|
181
|
+
request?: X402RequestSnapshot;
|
|
182
|
+
resourceUrl: string;
|
|
183
|
+
description: string | null;
|
|
184
|
+
amountAtomic: string;
|
|
185
|
+
amount: string;
|
|
186
|
+
token: string;
|
|
187
|
+
asset: string;
|
|
188
|
+
network: string;
|
|
189
|
+
chainId: number | null;
|
|
190
|
+
merchantAddress: string;
|
|
191
|
+
}
|
|
192
|
+
interface MppAuthorizationOptions {
|
|
193
|
+
/** Stable caller-supplied key for this user intent. Prevents duplicate approvals across retries. */
|
|
194
|
+
idempotencyKey?: string;
|
|
195
|
+
}
|
|
196
|
+
/** Quote parsed from an MPP challenge without creating a Haven payment. */
|
|
197
|
+
interface MppQuote {
|
|
198
|
+
rail: 'mpp';
|
|
199
|
+
paymentRail: MachinePaymentRail;
|
|
200
|
+
idempotencyKey: string;
|
|
201
|
+
challenge: MachinePaymentChallenge;
|
|
202
|
+
request: X402RequestSnapshot;
|
|
203
|
+
resourceUrl: string;
|
|
204
|
+
description: string | null;
|
|
205
|
+
amountAtomic: string;
|
|
206
|
+
amount: string;
|
|
207
|
+
token: string;
|
|
208
|
+
asset: string;
|
|
209
|
+
network: string;
|
|
210
|
+
chainId: number;
|
|
211
|
+
merchantAddress: string;
|
|
212
|
+
expiresAt: string;
|
|
213
|
+
}
|
|
214
|
+
/** State bundle an agent can persist while waiting for manual MPP approval. */
|
|
215
|
+
interface MppResumeState {
|
|
216
|
+
rail: 'mpp';
|
|
217
|
+
paymentRail: MachinePaymentRail;
|
|
218
|
+
paymentId: string;
|
|
219
|
+
idempotencyKey: string;
|
|
220
|
+
challenge: MachinePaymentChallenge;
|
|
221
|
+
url: string;
|
|
222
|
+
request?: X402RequestSnapshot;
|
|
223
|
+
resourceUrl: string;
|
|
224
|
+
description: string | null;
|
|
225
|
+
amountAtomic: string;
|
|
226
|
+
amount: string;
|
|
227
|
+
token: string;
|
|
228
|
+
asset: string;
|
|
229
|
+
network: string;
|
|
230
|
+
chainId: number;
|
|
231
|
+
merchantAddress: string;
|
|
232
|
+
expiresAt: string;
|
|
233
|
+
}
|
|
234
|
+
type PaymentResumeState = X402ResumeState | MppResumeState;
|
|
235
|
+
interface ResumeAuthorizedX402Input extends X402AuthorizationOptions {
|
|
236
|
+
/** Payment or approval request ID returned by authorizeX402 / haven.fetch. */
|
|
237
|
+
paymentId: string;
|
|
238
|
+
/** Original or freshly parsed x402 requirements for the merchant retry. */
|
|
239
|
+
paymentRequired: X402PaymentRequired;
|
|
240
|
+
}
|
|
241
|
+
interface ResumeX402PaymentInput extends X402AuthorizationOptions {
|
|
242
|
+
/** Payment or approval request ID returned by authorizeX402 / haven.fetch. */
|
|
243
|
+
paymentId: string;
|
|
244
|
+
/** Original paid URL. If paymentRequired is omitted, Haven will call it once to re-read the 402 challenge. */
|
|
245
|
+
url: string;
|
|
246
|
+
/** Original fetch options. Reused for the 402 probe and final merchant retry. */
|
|
247
|
+
init?: RequestInit;
|
|
248
|
+
/** Serializable original request captured by quoteX402() / pending approval errors. */
|
|
249
|
+
request?: X402RequestSnapshot;
|
|
250
|
+
/** Original or freshly parsed x402 requirements. Supplying this avoids an extra merchant 402 probe. */
|
|
251
|
+
paymentRequired?: X402PaymentRequired;
|
|
252
|
+
}
|
|
253
|
+
interface ResumeAuthorizedMppInput extends MppAuthorizationOptions {
|
|
254
|
+
/** Payment or approval request ID returned by authorizeMachinePayment / haven.fetch. */
|
|
255
|
+
paymentId: string;
|
|
256
|
+
/** Original MPP challenge returned by the paid resource. */
|
|
257
|
+
challenge: MachinePaymentChallenge;
|
|
258
|
+
}
|
|
259
|
+
interface ResumeMppPaymentInput extends MppAuthorizationOptions {
|
|
260
|
+
/** Payment or approval request ID returned by authorizeMachinePayment / haven.fetch. */
|
|
261
|
+
paymentId: string;
|
|
262
|
+
/** Original paid URL. If challenge is omitted, Haven will call it once to re-read the MPP challenge. */
|
|
263
|
+
url: string;
|
|
264
|
+
/** Original fetch options. Reused for the 402 probe and final merchant retry. */
|
|
265
|
+
init?: RequestInit;
|
|
266
|
+
/** Serializable original request captured by quoteMpp() / pending approval errors. */
|
|
267
|
+
request?: X402RequestSnapshot;
|
|
268
|
+
/** Original MPP challenge. Supplying this avoids an extra paid-resource 402 probe. */
|
|
269
|
+
challenge?: MachinePaymentChallenge;
|
|
116
270
|
}
|
|
117
271
|
type MachinePaymentRail = 'x402' | 'mpp_demo' | 'mpp_crypto' | 'stripe_deposit' | 'spt';
|
|
118
272
|
interface MachinePaymentChallenge {
|
|
@@ -153,9 +307,134 @@ interface MachinePaymentReceipt {
|
|
|
153
307
|
chainId?: number;
|
|
154
308
|
proofHeader: string;
|
|
155
309
|
}
|
|
310
|
+
interface HavenAgent {
|
|
311
|
+
id: string;
|
|
312
|
+
name: string;
|
|
313
|
+
status: string;
|
|
314
|
+
safeAddress: string;
|
|
315
|
+
delegateAddress: string;
|
|
316
|
+
chainId: number;
|
|
317
|
+
}
|
|
318
|
+
interface HavenAllowance {
|
|
319
|
+
id: string;
|
|
320
|
+
tokenAddress: string;
|
|
321
|
+
tokenSymbol: string;
|
|
322
|
+
configuredAmount: string;
|
|
323
|
+
resetPeriodMin: number;
|
|
324
|
+
onchain: {
|
|
325
|
+
amount: string;
|
|
326
|
+
spent: string;
|
|
327
|
+
remaining: string;
|
|
328
|
+
effectiveSpent: string;
|
|
329
|
+
resetTimeMin: number;
|
|
330
|
+
lastResetMin: number;
|
|
331
|
+
nonce: number;
|
|
332
|
+
isResetPending: boolean;
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
interface HavenAllowanceSummary {
|
|
336
|
+
agentId: string;
|
|
337
|
+
safeAddress: string;
|
|
338
|
+
delegateAddress: string;
|
|
339
|
+
chainId: number;
|
|
340
|
+
allowances: HavenAllowance[];
|
|
341
|
+
}
|
|
342
|
+
interface HavenPaymentReceipt {
|
|
343
|
+
id: string;
|
|
344
|
+
paymentId: string;
|
|
345
|
+
rail: string;
|
|
346
|
+
proofStatus: string;
|
|
347
|
+
txHash: string;
|
|
348
|
+
chainId: number;
|
|
349
|
+
resourceUrl: string;
|
|
350
|
+
merchantAddress: string | null;
|
|
351
|
+
payerAddress: string;
|
|
352
|
+
settlementAddress: string;
|
|
353
|
+
tokenSymbol: string;
|
|
354
|
+
tokenAddress: string;
|
|
355
|
+
amountRaw: string;
|
|
356
|
+
amount: string;
|
|
357
|
+
challengeId: string | null;
|
|
358
|
+
idempotencyKey: string | null;
|
|
359
|
+
challengePayload?: Record<string, unknown> | null;
|
|
360
|
+
selectedPayment?: Record<string, unknown> | null;
|
|
361
|
+
paymentProofHeaderName: string | null;
|
|
362
|
+
protocolReceiptHeaderName: string | null;
|
|
363
|
+
protocolReceiptPayload?: Record<string, unknown> | null;
|
|
364
|
+
merchantStatus: number | null;
|
|
365
|
+
confirmedAt: string | null;
|
|
366
|
+
createdAt: string;
|
|
367
|
+
updatedAt: string;
|
|
368
|
+
}
|
|
156
369
|
type PaymentStateKind = 'payment_intent' | 'approval_request';
|
|
157
|
-
|
|
158
|
-
type
|
|
370
|
+
interface AgentPaymentEnumSchema {
|
|
371
|
+
type: 'string';
|
|
372
|
+
enum: readonly string[];
|
|
373
|
+
description: string;
|
|
374
|
+
'x-enumDescriptions': Record<string, string>;
|
|
375
|
+
}
|
|
376
|
+
declare const AgentPaymentPhase: {
|
|
377
|
+
/** The agent must sign and submit the prepared payment before Haven can relay it. */
|
|
378
|
+
readonly AgentSignatureRequired: "agent_signature_required";
|
|
379
|
+
/** Haven has received the signed payment and the agent should poll for confirmation. */
|
|
380
|
+
readonly PaymentSubmitted: "payment_submitted";
|
|
381
|
+
/** The direct payment is confirmed; the agent does not need to do more for this payment id. */
|
|
382
|
+
readonly PaymentConfirmed: "payment_confirmed";
|
|
383
|
+
/** The payment needs wallet owner approval in Haven before it can continue. */
|
|
384
|
+
readonly UserApprovalRequired: "user_approval_required";
|
|
385
|
+
/** The wallet owner approved the request and still needs to complete the funding payment. */
|
|
386
|
+
readonly UserExecutionRequired: "user_execution_required";
|
|
387
|
+
/** The funding payment was proposed and is waiting for the remaining account approvals. */
|
|
388
|
+
readonly WaitingForAdditionalApprovals: "waiting_for_additional_approvals";
|
|
389
|
+
/** The Haven funding leg was sent; the agent can continue the merchant/protocol leg. */
|
|
390
|
+
readonly FundingSent: "funding_sent";
|
|
391
|
+
/** The wallet owner rejected the request; the agent should stop and tell the user. */
|
|
392
|
+
readonly Rejected: "rejected";
|
|
393
|
+
/** The payment or approval request expired before completion. */
|
|
394
|
+
readonly Expired: "expired";
|
|
395
|
+
/** Haven could not complete the payment; the agent should stop and surface the failure. */
|
|
396
|
+
readonly Failed: "failed";
|
|
397
|
+
};
|
|
398
|
+
type AgentPaymentPhase = (typeof AgentPaymentPhase)[keyof typeof AgentPaymentPhase];
|
|
399
|
+
declare const AgentPaymentNextAction: {
|
|
400
|
+
/** Sign with the delegate key and submit the payment to Haven. */
|
|
401
|
+
readonly SignAndSubmitPayment: "sign_and_submit_payment";
|
|
402
|
+
/** Poll getPaymentStatus later using this payment id. */
|
|
403
|
+
readonly CheckStatusLater: "check_status_later";
|
|
404
|
+
/** No further agent action is required for this payment id. */
|
|
405
|
+
readonly None: "none";
|
|
406
|
+
/** Wait for the wallet owner to approve or reject the request in Haven. */
|
|
407
|
+
readonly WaitForUserApproval: "wait_for_user_approval";
|
|
408
|
+
/** Wait for the wallet owner to finish sending the approved funding payment. */
|
|
409
|
+
readonly WaitForUserToCompletePayment: "wait_for_user_to_complete_payment";
|
|
410
|
+
/** Resume this payment id and retry the original x402 request with the merchant payment header. */
|
|
411
|
+
readonly RetryOriginalX402Request: "retry_original_x402_request";
|
|
412
|
+
/** Stop retrying this payment and tell the user what happened. */
|
|
413
|
+
readonly StopAndTellUser: "stop_and_tell_user";
|
|
414
|
+
/** Ask again only if the user still wants the payment after expiry. */
|
|
415
|
+
readonly RequestAgainIfUserStillWantsIt: "request_again_if_user_still_wants_it";
|
|
416
|
+
};
|
|
417
|
+
type AgentPaymentNextAction = (typeof AgentPaymentNextAction)[keyof typeof AgentPaymentNextAction];
|
|
418
|
+
declare const AgentPaymentRail: {
|
|
419
|
+
/** Standard Haven payment from the user's Safe through an approved delegate allowance. */
|
|
420
|
+
readonly Direct: "direct";
|
|
421
|
+
/** x402 HTTP 402 payment flow with a Haven funding leg and merchant retry leg. */
|
|
422
|
+
readonly X402: "x402";
|
|
423
|
+
/** Machine Payment Protocol flow. */
|
|
424
|
+
readonly Mpp: "mpp";
|
|
425
|
+
};
|
|
426
|
+
type AgentPaymentRail = (typeof AgentPaymentRail)[keyof typeof AgentPaymentRail];
|
|
427
|
+
type PaymentPhase = AgentPaymentPhase;
|
|
428
|
+
type PaymentNextAction = AgentPaymentNextAction;
|
|
429
|
+
declare const AGENT_PAYMENT_PHASE_VALUES: ("rejected" | "expired" | "failed" | "agent_signature_required" | "payment_submitted" | "payment_confirmed" | "user_approval_required" | "user_execution_required" | "waiting_for_additional_approvals" | "funding_sent")[];
|
|
430
|
+
declare const AGENT_PAYMENT_NEXT_ACTION_VALUES: ("sign_and_submit_payment" | "check_status_later" | "none" | "wait_for_user_approval" | "wait_for_user_to_complete_payment" | "retry_original_x402_request" | "stop_and_tell_user" | "request_again_if_user_still_wants_it")[];
|
|
431
|
+
declare const AGENT_PAYMENT_RAIL_VALUES: ("x402" | "mpp" | "direct")[];
|
|
432
|
+
declare const AgentPaymentPhaseDescriptions: Record<AgentPaymentPhase, string>;
|
|
433
|
+
declare const AgentPaymentNextActionDescriptions: Record<AgentPaymentNextAction, string>;
|
|
434
|
+
declare const AgentPaymentRailDescriptions: Record<AgentPaymentRail, string>;
|
|
435
|
+
declare const AgentPaymentPhaseSchema: AgentPaymentEnumSchema;
|
|
436
|
+
declare const AgentPaymentNextActionSchema: AgentPaymentEnumSchema;
|
|
437
|
+
declare const AgentPaymentRailSchema: AgentPaymentEnumSchema;
|
|
159
438
|
interface PaymentStatusResult {
|
|
160
439
|
paymentId: string;
|
|
161
440
|
kind: PaymentStateKind;
|
|
@@ -171,12 +450,36 @@ interface PaymentStatusResult {
|
|
|
171
450
|
expiresAt: string;
|
|
172
451
|
chainId: number;
|
|
173
452
|
message: string;
|
|
453
|
+
amountAtomic?: string | null;
|
|
454
|
+
asset?: string | null;
|
|
455
|
+
network?: string | null;
|
|
456
|
+
description?: string | null;
|
|
457
|
+
idempotencyKey?: string | null;
|
|
458
|
+
x402?: {
|
|
459
|
+
amountAtomic: string | null;
|
|
460
|
+
asset: string | null;
|
|
461
|
+
network: string | null;
|
|
462
|
+
resourceUrl: string | null;
|
|
463
|
+
merchantAddress: string | null;
|
|
464
|
+
description: string | null;
|
|
465
|
+
idempotencyKey: string | null;
|
|
466
|
+
};
|
|
467
|
+
mpp?: {
|
|
468
|
+
amountAtomic: string | null;
|
|
469
|
+
asset: string | null;
|
|
470
|
+
network: string | null;
|
|
471
|
+
resourceUrl: string | null;
|
|
472
|
+
merchantAddress: string | null;
|
|
473
|
+
description: string | null;
|
|
474
|
+
idempotencyKey: string | null;
|
|
475
|
+
challengeId: string | null;
|
|
476
|
+
};
|
|
174
477
|
}
|
|
175
478
|
interface PendingApproval extends PaymentStatusResult {
|
|
176
479
|
kind: 'approval_request';
|
|
177
480
|
status: 'pending_approval' | 'pending' | string;
|
|
178
|
-
phase:
|
|
179
|
-
nextAction:
|
|
481
|
+
phase: typeof AgentPaymentPhase.UserApprovalRequired;
|
|
482
|
+
nextAction: typeof AgentPaymentNextAction.WaitForUserApproval;
|
|
180
483
|
requested?: string;
|
|
181
484
|
remaining?: string | null;
|
|
182
485
|
}
|
|
@@ -192,6 +495,7 @@ declare class HavenApiError extends HavenError {
|
|
|
192
495
|
}
|
|
193
496
|
declare class HavenPaymentStateError extends HavenApiError {
|
|
194
497
|
readonly state: PaymentStatusResult;
|
|
498
|
+
resumeState?: X402ResumeState | MppResumeState;
|
|
195
499
|
constructor(message: string, statusCode: number, state: PaymentStatusResult, body?: unknown);
|
|
196
500
|
get status(): string;
|
|
197
501
|
get phase(): PaymentPhase;
|
|
@@ -215,9 +519,38 @@ declare class HavenClient {
|
|
|
215
519
|
private readonly inFlightX402;
|
|
216
520
|
private readonly x402ReceiptCache;
|
|
217
521
|
private readonly inFlightMachinePayments;
|
|
522
|
+
/**
|
|
523
|
+
* Setup-time headers configured via `HavenClientConfig.defaultHeaders`.
|
|
524
|
+
* Read-only after construction — use `withRequestContext` for per-call
|
|
525
|
+
* scoping so concurrent requests don't race on shared mutable state.
|
|
526
|
+
*/
|
|
527
|
+
private readonly defaultHeaders;
|
|
528
|
+
/**
|
|
529
|
+
* Async-local store for per-request context (currently: extra headers).
|
|
530
|
+
* Each `withRequestContext` invocation produces an isolated store, so
|
|
531
|
+
* overlapping async work — like two MCP tool dispatches in flight at
|
|
532
|
+
* the same time — see their own headers without stepping on each other.
|
|
533
|
+
*/
|
|
534
|
+
private readonly requestContext;
|
|
218
535
|
/** Delegate address derived from the private key (if provided) */
|
|
219
536
|
readonly delegateAddress: string | undefined;
|
|
220
537
|
constructor(config: HavenClientConfig);
|
|
538
|
+
/**
|
|
539
|
+
* Run `fn` with extra Haven-API headers scoped to the async work it
|
|
540
|
+
* performs. Used by the MCP server to tag every Haven API request that
|
|
541
|
+
* a single tool dispatch makes with `X-Haven-MCP-Tool: <name>` so the
|
|
542
|
+
* backend can write an audit-log row attributing the call.
|
|
543
|
+
*
|
|
544
|
+
* The headers are held in an `AsyncLocalStorage` so overlapping
|
|
545
|
+
* dispatches do not leak headers into each other's requests. The store
|
|
546
|
+
* inherits across `await` boundaries, so any Haven API call made while
|
|
547
|
+
* `fn` is awaiting will pick up the right headers.
|
|
548
|
+
*
|
|
549
|
+
* Has no effect on outbound merchant requests (x402 / MPP) — those
|
|
550
|
+
* never go through the internal `request<T>` path that reads the
|
|
551
|
+
* context.
|
|
552
|
+
*/
|
|
553
|
+
withRequestContext<T>(headers: Record<string, string>, fn: () => Promise<T>): Promise<T>;
|
|
221
554
|
/**
|
|
222
555
|
* Send a payment in one call.
|
|
223
556
|
*
|
|
@@ -260,6 +593,27 @@ declare class HavenClient {
|
|
|
260
593
|
* `getPayment()` remains available for payment-intent-only integrations.
|
|
261
594
|
*/
|
|
262
595
|
getPaymentStatus(paymentId: string): Promise<PaymentStatusResult>;
|
|
596
|
+
/**
|
|
597
|
+
* Get the agent identity tied to this API key.
|
|
598
|
+
*/
|
|
599
|
+
getAgent(): Promise<HavenAgent>;
|
|
600
|
+
/**
|
|
601
|
+
* Get configured and on-chain allowances for the authenticated agent.
|
|
602
|
+
*/
|
|
603
|
+
getAllowances(): Promise<HavenAllowanceSummary>;
|
|
604
|
+
/**
|
|
605
|
+
* List recent machine-payment receipts/evidence for bookkeeping.
|
|
606
|
+
*/
|
|
607
|
+
listReceipts(options?: {
|
|
608
|
+
limit?: number;
|
|
609
|
+
}): Promise<HavenPaymentReceipt[]>;
|
|
610
|
+
/**
|
|
611
|
+
* Rehydrate the x402/MPP resume-state bundle for a payment id.
|
|
612
|
+
*
|
|
613
|
+
* The server returns stored protocol context only. The client still signs the
|
|
614
|
+
* merchant proof locally when resumeX402Payment() or resumeMppPayment() runs.
|
|
615
|
+
*/
|
|
616
|
+
getResumeState(paymentId: string): Promise<PaymentResumeState>;
|
|
263
617
|
/**
|
|
264
618
|
* Poll until a payment reaches a terminal status (confirmed, failed, expired).
|
|
265
619
|
*/
|
|
@@ -273,8 +627,19 @@ declare class HavenClient {
|
|
|
273
627
|
*
|
|
274
628
|
* Requires `delegateKey` to be set in the client config.
|
|
275
629
|
*/
|
|
276
|
-
authorizeX402(paymentRequired: X402PaymentRequired): Promise<X402Receipt>;
|
|
630
|
+
authorizeX402(paymentRequired: X402PaymentRequired, options?: X402AuthorizationOptions): Promise<X402Receipt>;
|
|
631
|
+
/**
|
|
632
|
+
* Probe a paid endpoint and return its x402 quote without creating a Haven
|
|
633
|
+
* payment or approval request.
|
|
634
|
+
*/
|
|
635
|
+
quoteX402(url: string, init?: RequestInit, options?: X402AuthorizationOptions): Promise<X402Quote>;
|
|
636
|
+
/**
|
|
637
|
+
* Pay a previously inspected x402 quote and retry the exact captured request.
|
|
638
|
+
*/
|
|
639
|
+
payX402Quote(quote: X402Quote, options?: X402AuthorizationOptions): Promise<Response>;
|
|
277
640
|
private authorizeStandardX402;
|
|
641
|
+
resumeAuthorizedX402(input: ResumeAuthorizedX402Input): Promise<X402Receipt>;
|
|
642
|
+
resumeX402Payment(input: ResumeX402PaymentInput | X402ResumeState): Promise<Response>;
|
|
278
643
|
/**
|
|
279
644
|
* Fetch wrapper that automatically handles HTTP 402 responses.
|
|
280
645
|
*
|
|
@@ -288,20 +653,49 @@ declare class HavenClient {
|
|
|
288
653
|
*
|
|
289
654
|
* Requires `delegateKey` to be set in the client config.
|
|
290
655
|
*/
|
|
291
|
-
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
292
|
-
|
|
656
|
+
fetch(url: string, init?: RequestInit, options?: X402AuthorizationOptions): Promise<Response>;
|
|
657
|
+
/**
|
|
658
|
+
* Probe a paid MPP endpoint or inspect an existing challenge without creating
|
|
659
|
+
* a Haven payment or approval request.
|
|
660
|
+
*/
|
|
661
|
+
quoteMpp(challengeOrUrl: MachinePaymentChallenge | string, init?: RequestInit, options?: MppAuthorizationOptions): Promise<MppQuote>;
|
|
662
|
+
/**
|
|
663
|
+
* Pay a previously inspected MPP quote and retry the exact captured request.
|
|
664
|
+
*/
|
|
665
|
+
payMppChallenge(quote: MppQuote, options?: MppAuthorizationOptions): Promise<Response>;
|
|
666
|
+
private retryX402Request;
|
|
667
|
+
authorizeMachinePayment(challenge: MachinePaymentChallenge, options?: MppAuthorizationOptions): Promise<MachinePaymentReceipt>;
|
|
293
668
|
private authorizeMppDemoPayment;
|
|
669
|
+
resumeAuthorizedMpp(input: ResumeAuthorizedMppInput): Promise<MachinePaymentReceipt>;
|
|
670
|
+
resumeMppPayment(input: ResumeMppPaymentInput | MppResumeState): Promise<Response>;
|
|
294
671
|
private fetchWithMachinePayment;
|
|
672
|
+
private retryMppRequest;
|
|
673
|
+
private assertCanResumeX402;
|
|
674
|
+
private assertCanResumeMpp;
|
|
675
|
+
private mapX402ReceiptFromAuthorization;
|
|
676
|
+
private mapX402ReceiptFromStatus;
|
|
677
|
+
private buildX402Receipt;
|
|
295
678
|
private createStandardX402Header;
|
|
296
679
|
private cacheX402Receipt;
|
|
297
680
|
private mapMachinePaymentReceipt;
|
|
681
|
+
private mapMachinePaymentReceiptFromStatus;
|
|
298
682
|
private recordMerchantRetryRejected;
|
|
299
683
|
private reportMachinePaymentEvidence;
|
|
300
684
|
private throwIfNonSignableAuthorizationState;
|
|
301
685
|
private throwPaymentStateError;
|
|
302
686
|
private paymentStateFromRaw;
|
|
303
687
|
private x402PayerAddress;
|
|
688
|
+
private snapshotX402Request;
|
|
689
|
+
private snapshotRequestBody;
|
|
690
|
+
private requestInitFromSnapshot;
|
|
304
691
|
private withX402Wallet;
|
|
692
|
+
private buildX402Quote;
|
|
693
|
+
private buildX402ResumeState;
|
|
694
|
+
private buildMppQuote;
|
|
695
|
+
private buildMppResumeState;
|
|
696
|
+
private attachResumeState;
|
|
697
|
+
private attachX402ResumeState;
|
|
698
|
+
private attachMppResumeState;
|
|
305
699
|
/**
|
|
306
700
|
* Execute a tool call by name and input.
|
|
307
701
|
*
|
|
@@ -315,12 +709,15 @@ declare class HavenClient {
|
|
|
315
709
|
* ```
|
|
316
710
|
*/
|
|
317
711
|
executeTool(toolName: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
712
|
+
private toolX402PaymentRequired;
|
|
713
|
+
private x402ToolReceipt;
|
|
318
714
|
private toolError;
|
|
319
715
|
private post;
|
|
320
716
|
private get;
|
|
321
717
|
private request;
|
|
322
718
|
private mapPaymentResult;
|
|
323
719
|
private mapPaymentStatusResult;
|
|
720
|
+
private mapPaymentReceipt;
|
|
324
721
|
}
|
|
325
722
|
|
|
326
723
|
/**
|
|
@@ -450,4 +847,4 @@ declare function parseMachinePaymentChallengeResponse(response: Response): Promi
|
|
|
450
847
|
declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
|
|
451
848
|
declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
|
|
452
849
|
|
|
453
|
-
export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type SignData, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|
|
850
|
+
export { AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, type AgentPaymentEnumSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, type ClaudeTool, type HavenAgent, type HavenAllowance, type HavenAllowanceSummary, HavenApiError, HavenClient, type HavenClientConfig, HavenError, type HavenPaymentReceipt, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, type MachinePaymentChallenge, type MachinePaymentRail, type MachinePaymentReceipt, type MppAuthorizationOptions, type MppQuote, type MppResumeState, type OpenAITool, type PaymentIntent, type PaymentNextAction, type PaymentPhase, type PaymentRequest, type PaymentResult, type PaymentResumeState, type PaymentStatus, type PaymentStatusResult, type PendingApproval, type ResumeAuthorizedMppInput, type ResumeAuthorizedX402Input, type ResumeMppPaymentInput, type ResumeX402PaymentInput, type SignData, type X402AuthorizationOptions, type X402PaymentOption, type X402PaymentRequired, type X402Quote, type X402Receipt, type X402RequestSnapshot, type X402ResumeState, addressFromKey, buildMachinePaymentIdempotencyKey, encodeMachinePaymentProof, encodePaymentProof, havenTools, parseMachinePaymentChallenge, parseMachinePaymentChallengeResponse, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
|