@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/dist/index.d.cts CHANGED
@@ -48,7 +48,7 @@ interface PaymentIntent {
48
48
  /** Data needed to sign the payment */
49
49
  signData: SignData;
50
50
  }
51
- type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'expired' | 'failed';
51
+ type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'pending_approval' | 'approved' | 'proposed' | 'executed' | 'rejected' | 'expired' | 'failed';
52
52
  interface PaymentResult {
53
53
  /** Unique payment ID */
54
54
  paymentId: string;
@@ -114,6 +114,72 @@ interface X402Receipt {
114
114
  payer?: string;
115
115
  chainId?: number;
116
116
  }
117
+ type MachinePaymentRail = 'x402' | 'mpp_demo' | 'mpp_crypto' | 'stripe_deposit' | 'spt';
118
+ interface MachinePaymentChallenge {
119
+ rail: MachinePaymentRail;
120
+ version: string;
121
+ challengeId: string;
122
+ resource: string;
123
+ description: string;
124
+ network: {
125
+ chainId: number;
126
+ name: 'base';
127
+ };
128
+ asset: {
129
+ symbol: 'USDC';
130
+ address: string;
131
+ decimals: 6;
132
+ };
133
+ amount: {
134
+ display: string;
135
+ atomic: string;
136
+ };
137
+ recipient: string;
138
+ expiresAt: string;
139
+ metadata?: Record<string, unknown>;
140
+ }
141
+ interface MachinePaymentReceipt {
142
+ success: boolean;
143
+ rail: MachinePaymentRail;
144
+ paymentId: string;
145
+ challengeId: string;
146
+ txHash: string;
147
+ token: string;
148
+ amount: string;
149
+ to: string;
150
+ resourceUrl: string;
151
+ explorerUrl: string;
152
+ payer?: string;
153
+ chainId?: number;
154
+ proofHeader: string;
155
+ }
156
+ type PaymentStateKind = 'payment_intent' | 'approval_request';
157
+ type PaymentPhase = 'agent_signature_required' | 'payment_submitted' | 'payment_confirmed' | 'user_approval_required' | 'user_execution_required' | 'waiting_for_additional_approvals' | 'funding_sent' | 'rejected' | 'expired' | 'failed';
158
+ type PaymentNextAction = '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';
159
+ interface PaymentStatusResult {
160
+ paymentId: string;
161
+ kind: PaymentStateKind;
162
+ rail: string;
163
+ status: PaymentStatus | string;
164
+ phase: PaymentPhase;
165
+ nextAction: PaymentNextAction;
166
+ amount: string;
167
+ token: string;
168
+ resourceUrl: string | null;
169
+ merchantAddress: string | null;
170
+ txHash: string | null;
171
+ expiresAt: string;
172
+ chainId: number;
173
+ message: string;
174
+ }
175
+ interface PendingApproval extends PaymentStatusResult {
176
+ kind: 'approval_request';
177
+ status: 'pending_approval' | 'pending' | string;
178
+ phase: 'user_approval_required';
179
+ nextAction: 'wait_for_user_approval';
180
+ requested?: string;
181
+ remaining?: string | null;
182
+ }
117
183
  declare class HavenError extends Error {
118
184
  readonly code: string;
119
185
  readonly statusCode?: number | undefined;
@@ -122,7 +188,14 @@ declare class HavenError extends Error {
122
188
  }
123
189
  declare class HavenApiError extends HavenError {
124
190
  readonly body?: unknown | undefined;
125
- constructor(message: string, statusCode: number, body?: unknown | undefined);
191
+ constructor(message: string, statusCode: number, body?: unknown | undefined, paymentId?: string);
192
+ }
193
+ declare class HavenPaymentStateError extends HavenApiError {
194
+ readonly state: PaymentStatusResult;
195
+ constructor(message: string, statusCode: number, state: PaymentStatusResult, body?: unknown);
196
+ get status(): string;
197
+ get phase(): PaymentPhase;
198
+ get nextAction(): PaymentNextAction;
126
199
  }
127
200
  declare class HavenSigningError extends HavenError {
128
201
  constructor(message: string);
@@ -141,6 +214,7 @@ declare class HavenClient {
141
214
  private readonly pollingInterval;
142
215
  private readonly inFlightX402;
143
216
  private readonly x402ReceiptCache;
217
+ private readonly inFlightMachinePayments;
144
218
  /** Delegate address derived from the private key (if provided) */
145
219
  readonly delegateAddress: string | undefined;
146
220
  constructor(config: HavenClientConfig);
@@ -179,6 +253,13 @@ declare class HavenClient {
179
253
  * Get the current status of a payment.
180
254
  */
181
255
  getPayment(paymentId: string): Promise<PaymentResult>;
256
+ /**
257
+ * Get agent-actionable status for a payment intent or approval request.
258
+ *
259
+ * Use this for IDs returned by agent tools and machine-payment/x402 flows.
260
+ * `getPayment()` remains available for payment-intent-only integrations.
261
+ */
262
+ getPaymentStatus(paymentId: string): Promise<PaymentStatusResult>;
182
263
  /**
183
264
  * Poll until a payment reaches a terminal status (confirmed, failed, expired).
184
265
  */
@@ -208,8 +289,17 @@ declare class HavenClient {
208
289
  * Requires `delegateKey` to be set in the client config.
209
290
  */
210
291
  fetch(url: string, init?: RequestInit): Promise<Response>;
292
+ authorizeMachinePayment(challenge: MachinePaymentChallenge): Promise<MachinePaymentReceipt>;
293
+ private authorizeMppDemoPayment;
294
+ private fetchWithMachinePayment;
211
295
  private createStandardX402Header;
212
296
  private cacheX402Receipt;
297
+ private mapMachinePaymentReceipt;
298
+ private recordMerchantRetryRejected;
299
+ private reportMachinePaymentEvidence;
300
+ private throwIfNonSignableAuthorizationState;
301
+ private throwPaymentStateError;
302
+ private paymentStateFromRaw;
213
303
  private x402PayerAddress;
214
304
  private withX402Wallet;
215
305
  /**
@@ -225,10 +315,12 @@ declare class HavenClient {
225
315
  * ```
226
316
  */
227
317
  executeTool(toolName: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
318
+ private toolError;
228
319
  private post;
229
320
  private get;
230
321
  private request;
231
322
  private mapPaymentResult;
323
+ private mapPaymentStatusResult;
232
324
  }
233
325
 
234
326
  /**
@@ -353,4 +445,9 @@ declare function encodePaymentProof(receipt: {
353
445
  chainId?: number;
354
446
  }): string;
355
447
 
356
- export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenSigningError, HavenTimeoutError, type OpenAITool, type PaymentIntent, type PaymentRequest, type PaymentResult, type PaymentStatus, type SignData, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, encodePaymentProof, havenTools, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
448
+ declare function parseMachinePaymentChallenge(response: Response): MachinePaymentChallenge;
449
+ declare function parseMachinePaymentChallengeResponse(response: Response): Promise<MachinePaymentChallenge>;
450
+ declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
451
+ declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
452
+
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 };
package/dist/index.d.ts CHANGED
@@ -48,7 +48,7 @@ interface PaymentIntent {
48
48
  /** Data needed to sign the payment */
49
49
  signData: SignData;
50
50
  }
51
- type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'expired' | 'failed';
51
+ type PaymentStatus = 'pending_signature' | 'submitted' | 'confirmed' | 'pending_approval' | 'approved' | 'proposed' | 'executed' | 'rejected' | 'expired' | 'failed';
52
52
  interface PaymentResult {
53
53
  /** Unique payment ID */
54
54
  paymentId: string;
@@ -114,6 +114,72 @@ interface X402Receipt {
114
114
  payer?: string;
115
115
  chainId?: number;
116
116
  }
117
+ type MachinePaymentRail = 'x402' | 'mpp_demo' | 'mpp_crypto' | 'stripe_deposit' | 'spt';
118
+ interface MachinePaymentChallenge {
119
+ rail: MachinePaymentRail;
120
+ version: string;
121
+ challengeId: string;
122
+ resource: string;
123
+ description: string;
124
+ network: {
125
+ chainId: number;
126
+ name: 'base';
127
+ };
128
+ asset: {
129
+ symbol: 'USDC';
130
+ address: string;
131
+ decimals: 6;
132
+ };
133
+ amount: {
134
+ display: string;
135
+ atomic: string;
136
+ };
137
+ recipient: string;
138
+ expiresAt: string;
139
+ metadata?: Record<string, unknown>;
140
+ }
141
+ interface MachinePaymentReceipt {
142
+ success: boolean;
143
+ rail: MachinePaymentRail;
144
+ paymentId: string;
145
+ challengeId: string;
146
+ txHash: string;
147
+ token: string;
148
+ amount: string;
149
+ to: string;
150
+ resourceUrl: string;
151
+ explorerUrl: string;
152
+ payer?: string;
153
+ chainId?: number;
154
+ proofHeader: string;
155
+ }
156
+ type PaymentStateKind = 'payment_intent' | 'approval_request';
157
+ type PaymentPhase = 'agent_signature_required' | 'payment_submitted' | 'payment_confirmed' | 'user_approval_required' | 'user_execution_required' | 'waiting_for_additional_approvals' | 'funding_sent' | 'rejected' | 'expired' | 'failed';
158
+ type PaymentNextAction = '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';
159
+ interface PaymentStatusResult {
160
+ paymentId: string;
161
+ kind: PaymentStateKind;
162
+ rail: string;
163
+ status: PaymentStatus | string;
164
+ phase: PaymentPhase;
165
+ nextAction: PaymentNextAction;
166
+ amount: string;
167
+ token: string;
168
+ resourceUrl: string | null;
169
+ merchantAddress: string | null;
170
+ txHash: string | null;
171
+ expiresAt: string;
172
+ chainId: number;
173
+ message: string;
174
+ }
175
+ interface PendingApproval extends PaymentStatusResult {
176
+ kind: 'approval_request';
177
+ status: 'pending_approval' | 'pending' | string;
178
+ phase: 'user_approval_required';
179
+ nextAction: 'wait_for_user_approval';
180
+ requested?: string;
181
+ remaining?: string | null;
182
+ }
117
183
  declare class HavenError extends Error {
118
184
  readonly code: string;
119
185
  readonly statusCode?: number | undefined;
@@ -122,7 +188,14 @@ declare class HavenError extends Error {
122
188
  }
123
189
  declare class HavenApiError extends HavenError {
124
190
  readonly body?: unknown | undefined;
125
- constructor(message: string, statusCode: number, body?: unknown | undefined);
191
+ constructor(message: string, statusCode: number, body?: unknown | undefined, paymentId?: string);
192
+ }
193
+ declare class HavenPaymentStateError extends HavenApiError {
194
+ readonly state: PaymentStatusResult;
195
+ constructor(message: string, statusCode: number, state: PaymentStatusResult, body?: unknown);
196
+ get status(): string;
197
+ get phase(): PaymentPhase;
198
+ get nextAction(): PaymentNextAction;
126
199
  }
127
200
  declare class HavenSigningError extends HavenError {
128
201
  constructor(message: string);
@@ -141,6 +214,7 @@ declare class HavenClient {
141
214
  private readonly pollingInterval;
142
215
  private readonly inFlightX402;
143
216
  private readonly x402ReceiptCache;
217
+ private readonly inFlightMachinePayments;
144
218
  /** Delegate address derived from the private key (if provided) */
145
219
  readonly delegateAddress: string | undefined;
146
220
  constructor(config: HavenClientConfig);
@@ -179,6 +253,13 @@ declare class HavenClient {
179
253
  * Get the current status of a payment.
180
254
  */
181
255
  getPayment(paymentId: string): Promise<PaymentResult>;
256
+ /**
257
+ * Get agent-actionable status for a payment intent or approval request.
258
+ *
259
+ * Use this for IDs returned by agent tools and machine-payment/x402 flows.
260
+ * `getPayment()` remains available for payment-intent-only integrations.
261
+ */
262
+ getPaymentStatus(paymentId: string): Promise<PaymentStatusResult>;
182
263
  /**
183
264
  * Poll until a payment reaches a terminal status (confirmed, failed, expired).
184
265
  */
@@ -208,8 +289,17 @@ declare class HavenClient {
208
289
  * Requires `delegateKey` to be set in the client config.
209
290
  */
210
291
  fetch(url: string, init?: RequestInit): Promise<Response>;
292
+ authorizeMachinePayment(challenge: MachinePaymentChallenge): Promise<MachinePaymentReceipt>;
293
+ private authorizeMppDemoPayment;
294
+ private fetchWithMachinePayment;
211
295
  private createStandardX402Header;
212
296
  private cacheX402Receipt;
297
+ private mapMachinePaymentReceipt;
298
+ private recordMerchantRetryRejected;
299
+ private reportMachinePaymentEvidence;
300
+ private throwIfNonSignableAuthorizationState;
301
+ private throwPaymentStateError;
302
+ private paymentStateFromRaw;
213
303
  private x402PayerAddress;
214
304
  private withX402Wallet;
215
305
  /**
@@ -225,10 +315,12 @@ declare class HavenClient {
225
315
  * ```
226
316
  */
227
317
  executeTool(toolName: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
318
+ private toolError;
228
319
  private post;
229
320
  private get;
230
321
  private request;
231
322
  private mapPaymentResult;
323
+ private mapPaymentStatusResult;
232
324
  }
233
325
 
234
326
  /**
@@ -353,4 +445,9 @@ declare function encodePaymentProof(receipt: {
353
445
  chainId?: number;
354
446
  }): string;
355
447
 
356
- export { type ClaudeTool, HavenApiError, HavenClient, type HavenClientConfig, HavenError, HavenSigningError, HavenTimeoutError, type OpenAITool, type PaymentIntent, type PaymentRequest, type PaymentResult, type PaymentStatus, type SignData, type X402PaymentOption, type X402PaymentRequired, type X402Receipt, addressFromKey, encodePaymentProof, havenTools, parsePaymentRequired, parsePaymentRequiredResponse, selectPaymentOption, signHash, verifySignature };
448
+ declare function parseMachinePaymentChallenge(response: Response): MachinePaymentChallenge;
449
+ declare function parseMachinePaymentChallengeResponse(response: Response): Promise<MachinePaymentChallenge>;
450
+ declare function buildMachinePaymentIdempotencyKey(challenge: MachinePaymentChallenge): string;
451
+ declare function encodeMachinePaymentProof(receipt: Omit<MachinePaymentReceipt, 'proofHeader'>): string;
452
+
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 };