@useagentpay/sdk 0.1.0 → 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
@@ -1,3 +1,6 @@
1
+ import { Stagehand } from '@browserbasehq/stagehand';
2
+ import { createServer } from 'node:http';
3
+
1
4
  interface BillingCredentials {
2
5
  card: {
3
6
  number: string;
@@ -82,15 +85,27 @@ interface ProposeOptions {
82
85
  url: string;
83
86
  }
84
87
 
88
+ /**
89
+ * Abstraction over how a Stagehand browser instance is created.
90
+ * Implement this interface to plug in a custom browser backend
91
+ * (e.g. Browserbase, cloud Playwright, etc.).
92
+ */
93
+ interface BrowserProvider {
94
+ createStagehand(modelApiKey?: string): Stagehand;
95
+ close(): Promise<void>;
96
+ }
97
+
85
98
  interface CheckoutResult {
86
99
  success: boolean;
87
100
  confirmationId?: string;
88
101
  error?: string;
89
102
  }
90
103
  interface ExecutorConfig {
91
- browserbaseApiKey?: string;
92
- browserbaseProjectId?: string;
104
+ /** Custom browser provider. Defaults to LocalBrowserProvider (local Chromium). */
105
+ provider?: BrowserProvider;
106
+ /** LLM API key for Stagehand's AI-driven navigation (e.g. ANTHROPIC_API_KEY). */
93
107
  modelApiKey?: string;
108
+ proxyUrl?: string;
94
109
  }
95
110
 
96
111
  declare class NotSetupError extends Error {
@@ -220,8 +235,11 @@ interface DiscoverResult {
220
235
  productName: string;
221
236
  }
222
237
  declare class PurchaseExecutor {
223
- private config;
238
+ private provider;
239
+ private modelApiKey?;
224
240
  private stagehand;
241
+ private proxyUrl;
242
+ private originalBaseUrl;
225
243
  constructor(config?: ExecutorConfig);
226
244
  private createStagehand;
227
245
  /**
@@ -263,6 +281,52 @@ declare const PLACEHOLDER_MAP: {
263
281
  declare function getPlaceholderVariables(): Record<string, string>;
264
282
  declare function credentialsToSwapMap(creds: BillingCredentials): Record<string, string>;
265
283
 
284
+ interface ApprovalResult {
285
+ action: 'approved' | 'rejected';
286
+ passphrase?: string;
287
+ reason?: string;
288
+ }
289
+ /**
290
+ * Launch an ephemeral HTTP server on localhost, open a browser page
291
+ * where the human can approve or deny the transaction.
292
+ * On approve: server-side signing is performed, passphrase returned in result.
293
+ * On deny: transaction is rejected.
294
+ */
295
+ declare function requestBrowserApproval(tx: Transaction, tm: TransactionManager, audit: AuditLogger, home?: string): Promise<ApprovalResult>;
296
+
297
+ interface SetupResult {
298
+ completed: boolean;
299
+ }
300
+ /**
301
+ * Launch an ephemeral HTTP server on localhost, open a browser page
302
+ * where the human fills in credentials, passphrase, and budget.
303
+ * All sensitive data stays in the browser->server HTTP request on localhost.
304
+ * Never touches stdout/terminal.
305
+ */
306
+ declare function requestBrowserSetup(home?: string): Promise<SetupResult>;
307
+
308
+ declare function startServer(port: number): Promise<ReturnType<typeof createServer>>;
309
+
310
+ declare function openBrowser(url: string): void;
311
+
312
+ interface PassphraseContext {
313
+ action: 'buy' | 'approve';
314
+ merchant?: string;
315
+ amount?: number;
316
+ description?: string;
317
+ txId?: string;
318
+ }
319
+
320
+ declare function promptInput(question: string): Promise<string>;
321
+ declare function promptPassphrase(prompt?: string): Promise<string>;
322
+ declare function promptConfirm(question: string): Promise<boolean>;
323
+ /**
324
+ * Collect passphrase safely: uses terminal prompt when stdin is a TTY,
325
+ * otherwise opens a browser page so the human can enter it directly
326
+ * (keeping the passphrase out of the agent's context).
327
+ */
328
+ declare function promptPassphraseSafe(context?: PassphraseContext): Promise<string>;
329
+
266
330
  interface AgentPayOptions {
267
331
  home?: string;
268
332
  passphrase?: string;
@@ -289,13 +353,6 @@ declare class AgentPay {
289
353
  limitPerTx: number;
290
354
  remaining: number;
291
355
  };
292
- generateFundingQR: (options?: {
293
- suggestedBudget?: number;
294
- message?: string;
295
- }) => Promise<{
296
- url: string;
297
- qrDataUrl: string;
298
- }>;
299
356
  };
300
357
  get transactions(): {
301
358
  propose: (options: ProposeOptions) => Transaction;
@@ -307,6 +364,11 @@ declare class AgentPay {
307
364
  status: "approved" | "rejected";
308
365
  reason?: string;
309
366
  }>;
367
+ requestApproval: (txId: string) => Promise<{
368
+ action: "approved" | "rejected";
369
+ passphrase?: string;
370
+ reason?: string;
371
+ }>;
310
372
  execute: (txId: string) => Promise<Receipt>;
311
373
  getReceipt: (txId: string) => Receipt | undefined;
312
374
  };
@@ -323,6 +385,6 @@ declare class AgentPay {
323
385
  };
324
386
  }
325
387
 
326
- declare const VERSION = "0.1.0";
388
+ declare const VERSION: string;
327
389
 
328
- export { AgentPay, type AgentPayOptions, AlreadyExecutedError, AuditLogger, type BillingCredentials, BudgetManager, CheckoutFailedError, type CheckoutResult, DecryptError, type EncryptedVault, ExceedsTxLimitError, type ExecutorConfig, InsufficientBalanceError, InvalidMandateError, type KeyPair, NotApprovedError, NotSetupError, PLACEHOLDER_MAP, type ProposeOptions, PurchaseExecutor, type PurchaseMandate, type Receipt, TimeoutError, type Transaction, type TransactionDetails, TransactionManager, type TransactionStatus, VERSION, type Wallet, createMandate, credentialsToSwapMap, decrypt, encrypt, formatCurrency, formatStatus, formatTable, formatTimestamp, generateKeyPair, generateTxId, getAuditPath, getCredentialsPath, getHomePath, getKeysPath, getPlaceholderVariables, getTransactionsPath, getWalletPath, loadPrivateKey, loadPublicKey, loadVault, saveKeyPair, saveVault, verifyMandate, waitForApproval };
390
+ export { AgentPay, type AgentPayOptions, AlreadyExecutedError, type ApprovalResult, AuditLogger, type BillingCredentials, type BrowserProvider, BudgetManager, CheckoutFailedError, type CheckoutResult, DecryptError, type EncryptedVault, ExceedsTxLimitError, type ExecutorConfig, InsufficientBalanceError, InvalidMandateError, type KeyPair, NotApprovedError, NotSetupError, PLACEHOLDER_MAP, type ProposeOptions, PurchaseExecutor, type PurchaseMandate, type Receipt, type SetupResult, TimeoutError, type Transaction, type TransactionDetails, TransactionManager, type TransactionStatus, VERSION, type Wallet, createMandate, credentialsToSwapMap, decrypt, encrypt, formatCurrency, formatStatus, formatTable, formatTimestamp, generateKeyPair, generateTxId, getAuditPath, getCredentialsPath, getHomePath, getKeysPath, getPlaceholderVariables, getTransactionsPath, getWalletPath, loadPrivateKey, loadPublicKey, loadVault, openBrowser, promptConfirm, promptInput, promptPassphrase, promptPassphraseSafe, requestBrowserApproval, requestBrowserSetup, saveKeyPair, saveVault, startServer as startDashboardServer, verifyMandate, waitForApproval };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { Stagehand } from '@browserbasehq/stagehand';
2
+ import { createServer } from 'node:http';
3
+
1
4
  interface BillingCredentials {
2
5
  card: {
3
6
  number: string;
@@ -82,15 +85,27 @@ interface ProposeOptions {
82
85
  url: string;
83
86
  }
84
87
 
88
+ /**
89
+ * Abstraction over how a Stagehand browser instance is created.
90
+ * Implement this interface to plug in a custom browser backend
91
+ * (e.g. Browserbase, cloud Playwright, etc.).
92
+ */
93
+ interface BrowserProvider {
94
+ createStagehand(modelApiKey?: string): Stagehand;
95
+ close(): Promise<void>;
96
+ }
97
+
85
98
  interface CheckoutResult {
86
99
  success: boolean;
87
100
  confirmationId?: string;
88
101
  error?: string;
89
102
  }
90
103
  interface ExecutorConfig {
91
- browserbaseApiKey?: string;
92
- browserbaseProjectId?: string;
104
+ /** Custom browser provider. Defaults to LocalBrowserProvider (local Chromium). */
105
+ provider?: BrowserProvider;
106
+ /** LLM API key for Stagehand's AI-driven navigation (e.g. ANTHROPIC_API_KEY). */
93
107
  modelApiKey?: string;
108
+ proxyUrl?: string;
94
109
  }
95
110
 
96
111
  declare class NotSetupError extends Error {
@@ -220,8 +235,11 @@ interface DiscoverResult {
220
235
  productName: string;
221
236
  }
222
237
  declare class PurchaseExecutor {
223
- private config;
238
+ private provider;
239
+ private modelApiKey?;
224
240
  private stagehand;
241
+ private proxyUrl;
242
+ private originalBaseUrl;
225
243
  constructor(config?: ExecutorConfig);
226
244
  private createStagehand;
227
245
  /**
@@ -263,6 +281,52 @@ declare const PLACEHOLDER_MAP: {
263
281
  declare function getPlaceholderVariables(): Record<string, string>;
264
282
  declare function credentialsToSwapMap(creds: BillingCredentials): Record<string, string>;
265
283
 
284
+ interface ApprovalResult {
285
+ action: 'approved' | 'rejected';
286
+ passphrase?: string;
287
+ reason?: string;
288
+ }
289
+ /**
290
+ * Launch an ephemeral HTTP server on localhost, open a browser page
291
+ * where the human can approve or deny the transaction.
292
+ * On approve: server-side signing is performed, passphrase returned in result.
293
+ * On deny: transaction is rejected.
294
+ */
295
+ declare function requestBrowserApproval(tx: Transaction, tm: TransactionManager, audit: AuditLogger, home?: string): Promise<ApprovalResult>;
296
+
297
+ interface SetupResult {
298
+ completed: boolean;
299
+ }
300
+ /**
301
+ * Launch an ephemeral HTTP server on localhost, open a browser page
302
+ * where the human fills in credentials, passphrase, and budget.
303
+ * All sensitive data stays in the browser->server HTTP request on localhost.
304
+ * Never touches stdout/terminal.
305
+ */
306
+ declare function requestBrowserSetup(home?: string): Promise<SetupResult>;
307
+
308
+ declare function startServer(port: number): Promise<ReturnType<typeof createServer>>;
309
+
310
+ declare function openBrowser(url: string): void;
311
+
312
+ interface PassphraseContext {
313
+ action: 'buy' | 'approve';
314
+ merchant?: string;
315
+ amount?: number;
316
+ description?: string;
317
+ txId?: string;
318
+ }
319
+
320
+ declare function promptInput(question: string): Promise<string>;
321
+ declare function promptPassphrase(prompt?: string): Promise<string>;
322
+ declare function promptConfirm(question: string): Promise<boolean>;
323
+ /**
324
+ * Collect passphrase safely: uses terminal prompt when stdin is a TTY,
325
+ * otherwise opens a browser page so the human can enter it directly
326
+ * (keeping the passphrase out of the agent's context).
327
+ */
328
+ declare function promptPassphraseSafe(context?: PassphraseContext): Promise<string>;
329
+
266
330
  interface AgentPayOptions {
267
331
  home?: string;
268
332
  passphrase?: string;
@@ -289,13 +353,6 @@ declare class AgentPay {
289
353
  limitPerTx: number;
290
354
  remaining: number;
291
355
  };
292
- generateFundingQR: (options?: {
293
- suggestedBudget?: number;
294
- message?: string;
295
- }) => Promise<{
296
- url: string;
297
- qrDataUrl: string;
298
- }>;
299
356
  };
300
357
  get transactions(): {
301
358
  propose: (options: ProposeOptions) => Transaction;
@@ -307,6 +364,11 @@ declare class AgentPay {
307
364
  status: "approved" | "rejected";
308
365
  reason?: string;
309
366
  }>;
367
+ requestApproval: (txId: string) => Promise<{
368
+ action: "approved" | "rejected";
369
+ passphrase?: string;
370
+ reason?: string;
371
+ }>;
310
372
  execute: (txId: string) => Promise<Receipt>;
311
373
  getReceipt: (txId: string) => Receipt | undefined;
312
374
  };
@@ -323,6 +385,6 @@ declare class AgentPay {
323
385
  };
324
386
  }
325
387
 
326
- declare const VERSION = "0.1.0";
388
+ declare const VERSION: string;
327
389
 
328
- export { AgentPay, type AgentPayOptions, AlreadyExecutedError, AuditLogger, type BillingCredentials, BudgetManager, CheckoutFailedError, type CheckoutResult, DecryptError, type EncryptedVault, ExceedsTxLimitError, type ExecutorConfig, InsufficientBalanceError, InvalidMandateError, type KeyPair, NotApprovedError, NotSetupError, PLACEHOLDER_MAP, type ProposeOptions, PurchaseExecutor, type PurchaseMandate, type Receipt, TimeoutError, type Transaction, type TransactionDetails, TransactionManager, type TransactionStatus, VERSION, type Wallet, createMandate, credentialsToSwapMap, decrypt, encrypt, formatCurrency, formatStatus, formatTable, formatTimestamp, generateKeyPair, generateTxId, getAuditPath, getCredentialsPath, getHomePath, getKeysPath, getPlaceholderVariables, getTransactionsPath, getWalletPath, loadPrivateKey, loadPublicKey, loadVault, saveKeyPair, saveVault, verifyMandate, waitForApproval };
390
+ export { AgentPay, type AgentPayOptions, AlreadyExecutedError, type ApprovalResult, AuditLogger, type BillingCredentials, type BrowserProvider, BudgetManager, CheckoutFailedError, type CheckoutResult, DecryptError, type EncryptedVault, ExceedsTxLimitError, type ExecutorConfig, InsufficientBalanceError, InvalidMandateError, type KeyPair, NotApprovedError, NotSetupError, PLACEHOLDER_MAP, type ProposeOptions, PurchaseExecutor, type PurchaseMandate, type Receipt, type SetupResult, TimeoutError, type Transaction, type TransactionDetails, TransactionManager, type TransactionStatus, VERSION, type Wallet, createMandate, credentialsToSwapMap, decrypt, encrypt, formatCurrency, formatStatus, formatTable, formatTimestamp, generateKeyPair, generateTxId, getAuditPath, getCredentialsPath, getHomePath, getKeysPath, getPlaceholderVariables, getTransactionsPath, getWalletPath, loadPrivateKey, loadPublicKey, loadVault, openBrowser, promptConfirm, promptInput, promptPassphrase, promptPassphraseSafe, requestBrowserApproval, requestBrowserSetup, saveKeyPair, saveVault, startServer as startDashboardServer, verifyMandate, waitForApproval };