@mixrpay/agent-sdk 0.10.0 → 0.11.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.d.cts CHANGED
@@ -200,6 +200,7 @@ interface FetchPaymentInfo {
200
200
  amount_usd: string;
201
201
  tx_hash?: string;
202
202
  remaining_budget_usd: string | null;
203
+ charge_id?: string;
203
204
  }
204
205
  interface FetchPaidResponse {
205
206
  status: number;
@@ -212,6 +213,33 @@ interface FetchPaidOptions {
212
213
  headers?: Record<string, string>;
213
214
  body?: unknown;
214
215
  maxPaymentUsd?: number;
216
+ /** Idempotency key for exactly-once semantics. If provided with a duplicate key, returns cached result. */
217
+ idempotencyKey?: string;
218
+ }
219
+ /**
220
+ * Options for transfer operations with idempotency support.
221
+ */
222
+ interface TransferOptions {
223
+ /** Idempotency key for exactly-once semantics. If provided with a duplicate key, returns cached result. */
224
+ idempotencyKey?: string;
225
+ }
226
+ /**
227
+ * Options for swap operations with idempotency support.
228
+ */
229
+ interface SwapOptions {
230
+ /** Slippage tolerance in basis points (default: 100 = 1%) */
231
+ slippageBps?: number;
232
+ /** Idempotency key for exactly-once semantics. If provided with a duplicate key, returns cached result. */
233
+ idempotencyKey?: string;
234
+ }
235
+ /**
236
+ * Options for bridge operations with idempotency support.
237
+ */
238
+ interface BridgeOptions {
239
+ /** Destination address (defaults to same address) */
240
+ destAddress?: string;
241
+ /** Idempotency key for exactly-once semantics. If provided with a duplicate key, returns cached result. */
242
+ idempotencyKey?: string;
215
243
  }
216
244
  /**
217
245
  * Known charge types in the MixrPay system.
@@ -310,9 +338,166 @@ interface AnthropicToolkit {
310
338
  */
311
339
  execute: (name: string, input: Record<string, unknown>) => Promise<string>;
312
340
  }
341
+ /**
342
+ * Supported plan step actions.
343
+ */
344
+ type PlanStepAction = 'transfer' | 'swap' | 'bridge' | 'tool_call' | 'fetch' | 'custom';
345
+ /**
346
+ * A single step in a plan.
347
+ */
348
+ interface PlanStep {
349
+ /** Action type for this step */
350
+ action: PlanStepAction;
351
+ /** Parameters for the action */
352
+ params: Record<string, unknown>;
353
+ /** Estimated cost in USD */
354
+ estimatedCostUsd?: number;
355
+ /** Human-readable description */
356
+ description: string;
357
+ }
358
+ /**
359
+ * Plan submission request.
360
+ */
361
+ interface PlanSubmission {
362
+ /** Plan title */
363
+ title: string;
364
+ /** Optional description */
365
+ description?: string;
366
+ /** Steps to execute */
367
+ steps: PlanStep[];
368
+ /** Total estimated cost in USD */
369
+ totalEstimatedCostUsd: number;
370
+ /** Whether to require human approval (default: false) */
371
+ requiresApproval?: boolean;
372
+ /** Idempotency key for exactly-once submission */
373
+ idempotencyKey?: string;
374
+ }
375
+ /**
376
+ * Result from submitting a plan.
377
+ */
378
+ interface PlanSubmitResult {
379
+ /** Unique plan ID */
380
+ planId: string;
381
+ /** Plan status after submission */
382
+ status: 'pending_approval' | 'auto_approved';
383
+ /** URL for human approval (if pending) */
384
+ approvalUrl?: string;
385
+ }
386
+ /**
387
+ * Status values for plan steps.
388
+ */
389
+ type PlanStepStatusValue = 'pending' | 'executing' | 'completed' | 'failed' | 'skipped' | 'awaiting_confirmation';
390
+ /**
391
+ * Status of a single plan step.
392
+ */
393
+ interface PlanStepStatus {
394
+ /** Step index */
395
+ index: number;
396
+ /** Action type */
397
+ action: PlanStepAction;
398
+ /** Step description */
399
+ description: string;
400
+ /** Current status */
401
+ status: PlanStepStatusValue;
402
+ /** Estimated cost in USD */
403
+ estimatedCostUsd?: number;
404
+ /** Transaction hash (if completed) */
405
+ txHash?: string;
406
+ /** Charge ID (if completed) */
407
+ chargeId?: string;
408
+ /** Bridge order ID (if bridge action) */
409
+ bridgeOrderId?: string;
410
+ /** Error message (if failed) */
411
+ error?: string;
412
+ /** When execution started */
413
+ submittedAt?: string;
414
+ /** When execution completed */
415
+ completedAt?: string;
416
+ }
417
+ /**
418
+ * Overall plan status values.
419
+ */
420
+ type PlanStatusValue = 'pending_approval' | 'approved' | 'auto_approved' | 'rejected' | 'expired' | 'executing' | 'completed' | 'partial_failure' | 'failed';
421
+ /**
422
+ * Full plan status including step details.
423
+ */
424
+ interface PlanStatus {
425
+ /** Unique plan ID */
426
+ planId: string;
427
+ /** Plan title */
428
+ title: string;
429
+ /** Plan description */
430
+ description?: string;
431
+ /** Overall plan status */
432
+ status: PlanStatusValue;
433
+ /** Per-step status */
434
+ steps: PlanStepStatus[];
435
+ /** Total estimated cost in USD */
436
+ totalEstimatedCostUsd: number;
437
+ /** Approval info (if responded) */
438
+ approval?: {
439
+ status: string;
440
+ respondedAt?: string;
441
+ responseNote?: string;
442
+ };
443
+ /** When the plan was created */
444
+ createdAt: string;
445
+ /** When the plan expires */
446
+ expiresAt?: string;
447
+ }
448
+ /**
449
+ * Summary item for plan listing.
450
+ */
451
+ interface PlanListItem {
452
+ /** Unique plan ID */
453
+ planId: string;
454
+ /** Plan title */
455
+ title: string;
456
+ /** Overall status */
457
+ status: string;
458
+ /** Total estimated cost in USD */
459
+ totalEstimatedCostUsd: number;
460
+ /** Number of completed steps */
461
+ stepsCompleted: number;
462
+ /** Total number of steps */
463
+ stepsTotal: number;
464
+ /** When the plan was created */
465
+ createdAt: string;
466
+ }
467
+ /**
468
+ * Response from listing plans.
469
+ */
470
+ interface PlansListResponse {
471
+ /** List of plans */
472
+ plans: PlanListItem[];
473
+ /** Total number of matching plans */
474
+ total: number;
475
+ /** Whether more plans exist */
476
+ hasMore: boolean;
477
+ }
478
+ /**
479
+ * Options for listing plans.
480
+ */
481
+ interface ListPlansOptions {
482
+ /** Maximum number of plans to return */
483
+ limit?: number;
484
+ /** Offset for pagination */
485
+ offset?: number;
486
+ /** Filter by status */
487
+ status?: string;
488
+ }
489
+ /**
490
+ * Options for waiting on plan completion.
491
+ */
492
+ interface WaitForPlanOptions {
493
+ /** Poll interval in milliseconds (default: 15000) */
494
+ pollIntervalMs?: number;
495
+ /** Timeout in milliseconds (default: 1800000 = 30 min) */
496
+ timeoutMs?: number;
497
+ }
313
498
 
314
499
  /** Current SDK version */
315
- declare const SDK_VERSION = "0.10.0";
500
+ declare const SDK_VERSION = "0.11.0";
316
501
  /** Supported networks */
317
502
  declare const NETWORKS: {
318
503
  readonly BASE_MAINNET: {
@@ -2865,6 +3050,7 @@ declare class AgentWallet {
2865
3050
  * @param to - Recipient address
2866
3051
  * @param amount - Amount in USD (e.g., "10.50")
2867
3052
  * @param currency - Currency to transfer (default: "USDC")
3053
+ * @param options - Optional transfer options (idempotencyKey)
2868
3054
  * @returns Transfer result with transaction hash
2869
3055
  * @throws {MixrPayError} If the transfer fails
2870
3056
  *
@@ -2875,8 +3061,16 @@ declare class AgentWallet {
2875
3061
  * console.log(`TX: ${result.tx_hash}`);
2876
3062
  * console.log(`Remaining budget: $${result.remaining_budget_usd}`);
2877
3063
  * ```
3064
+ *
3065
+ * @example With idempotency key
3066
+ * ```typescript
3067
+ * const result = await wallet.transfer('0x1234...', '10.00', 'USDC', {
3068
+ * idempotencyKey: 'payment-123',
3069
+ * });
3070
+ * // If called again with same key, returns cached result
3071
+ * ```
2878
3072
  */
2879
- transfer(to: string, amount: string, currency?: string): Promise<TransferResponse>;
3073
+ transfer(to: string, amount: string, currency?: string, options?: TransferOptions): Promise<TransferResponse>;
2880
3074
  /**
2881
3075
  * Swap tokens using 0x Protocol on Base.
2882
3076
  *
@@ -2886,7 +3080,7 @@ declare class AgentWallet {
2886
3080
  * @param sellToken - Token to sell (symbol or address, e.g., "USDC", "ETH")
2887
3081
  * @param buyToken - Token to buy (symbol or address, e.g., "WETH", "USDC")
2888
3082
  * @param sellAmount - Amount to sell in human-readable format (e.g., "100" for 100 USDC)
2889
- * @param slippageBps - Slippage tolerance in basis points (default: 100 = 1%)
3083
+ * @param options - Optional swap options (slippageBps, idempotencyKey)
2890
3084
  * @returns Swap result with transaction hash and amounts
2891
3085
  * @throws {MixrPayError} If the swap fails
2892
3086
  *
@@ -2898,8 +3092,16 @@ declare class AgentWallet {
2898
3092
  * console.log(`Received ${result.buy_amount} ${result.buy_token}`);
2899
3093
  * console.log(`Price: ${result.price}`);
2900
3094
  * ```
3095
+ *
3096
+ * @example With options
3097
+ * ```typescript
3098
+ * const result = await wallet.swap('USDC', 'ETH', '100', {
3099
+ * slippageBps: 50,
3100
+ * idempotencyKey: 'swap-abc123',
3101
+ * });
3102
+ * ```
2901
3103
  */
2902
- swap(sellToken: string, buyToken: string, sellAmount: string, slippageBps?: number): Promise<SwapResponse>;
3104
+ swap(sellToken: string, buyToken: string, sellAmount: string, options?: SwapOptions | number): Promise<SwapResponse>;
2903
3105
  /**
2904
3106
  * Bridge tokens to another chain using deBridge.
2905
3107
  *
@@ -2910,7 +3112,7 @@ declare class AgentWallet {
2910
3112
  * @param token - Token to bridge (symbol, e.g., "USDC")
2911
3113
  * @param amount - Amount in human-readable format (e.g., "100")
2912
3114
  * @param destChain - Destination chain ID or name (e.g., "1" for Ethereum, "arbitrum")
2913
- * @param destAddress - Destination address (defaults to same address)
3115
+ * @param options - Optional bridge options (destAddress, idempotencyKey)
2914
3116
  * @returns Bridge result with order ID for tracking
2915
3117
  * @throws {MixrPayError} If the bridge fails
2916
3118
  *
@@ -2927,8 +3129,16 @@ declare class AgentWallet {
2927
3129
  * console.log(`Completed! Dest TX: ${status.dest_tx_hash}`);
2928
3130
  * }
2929
3131
  * ```
3132
+ *
3133
+ * @example With options
3134
+ * ```typescript
3135
+ * const result = await wallet.bridge('USDC', '100', 'arbitrum', {
3136
+ * destAddress: '0xabc...',
3137
+ * idempotencyKey: 'bridge-xyz789',
3138
+ * });
3139
+ * ```
2930
3140
  */
2931
- bridge(token: string, amount: string, destChain: string, destAddress?: string): Promise<BridgeResponse>;
3141
+ bridge(token: string, amount: string, destChain: string, options?: BridgeOptions | string): Promise<BridgeResponse>;
2932
3142
  /**
2933
3143
  * Check the status of a bridge order.
2934
3144
  *
@@ -2964,7 +3174,7 @@ declare class AgentWallet {
2964
3174
  * fetch() that uses session key auth for x402, see the standard fetch() method.
2965
3175
  *
2966
3176
  * @param url - URL to fetch
2967
- * @param options - Fetch options (method, headers, body, maxPaymentUsd)
3177
+ * @param options - Fetch options (method, headers, body, maxPaymentUsd, idempotencyKey)
2968
3178
  * @returns Response with status, headers, body, and optional payment info
2969
3179
  * @throws {MixrPayError} If the fetch fails
2970
3180
  *
@@ -2984,8 +3194,126 @@ declare class AgentWallet {
2984
3194
  * console.log(`Paid $${result.payment.amount_usd}`);
2985
3195
  * }
2986
3196
  * ```
3197
+ *
3198
+ * @example With idempotency key
3199
+ * ```typescript
3200
+ * const result = await wallet.fetchPaid('https://api.example.com/data', {
3201
+ * idempotencyKey: 'request-123',
3202
+ * });
3203
+ * // If called again with same key, returns cached result
3204
+ * ```
2987
3205
  */
2988
3206
  fetchPaid(url: string, options?: FetchPaidOptions): Promise<FetchPaidResponse>;
3207
+ /**
3208
+ * Submit a multi-step plan for approval or auto-approval.
3209
+ *
3210
+ * Plans allow agents to propose complex workflows (swap, bridge, transfer, etc.)
3211
+ * that can be reviewed by humans before execution.
3212
+ *
3213
+ * @param plan - Plan submission details
3214
+ * @returns Plan submission result with ID and status
3215
+ * @throws {MixrPayError} If submission fails
3216
+ *
3217
+ * @example
3218
+ * ```typescript
3219
+ * const result = await wallet.submitPlan({
3220
+ * title: 'Swap and Bridge to Arbitrum',
3221
+ * steps: [
3222
+ * { action: 'swap', params: { sellToken: 'USDC', buyToken: 'ETH', sellAmount: '100' }, description: 'Swap USDC for ETH' },
3223
+ * { action: 'bridge', params: { token: 'ETH', amount: '0.03', destChain: 'arbitrum' }, description: 'Bridge ETH to Arbitrum' },
3224
+ * ],
3225
+ * totalEstimatedCostUsd: 105,
3226
+ * });
3227
+ *
3228
+ * if (result.status === 'pending_approval') {
3229
+ * console.log(`Waiting for approval: ${result.approvalUrl}`);
3230
+ * } else {
3231
+ * await wallet.executePlan(result.planId);
3232
+ * }
3233
+ * ```
3234
+ */
3235
+ submitPlan(plan: PlanSubmission): Promise<PlanSubmitResult>;
3236
+ /**
3237
+ * Get the current status of a plan.
3238
+ *
3239
+ * @param planId - Plan ID
3240
+ * @returns Full plan status including step details
3241
+ * @throws {MixrPayError} If status check fails
3242
+ */
3243
+ getPlanStatus(planId: string): Promise<PlanStatus>;
3244
+ /**
3245
+ * List plans for this agent.
3246
+ *
3247
+ * @param options - Query options
3248
+ * @returns List of plans with summary info
3249
+ * @throws {MixrPayError} If listing fails
3250
+ */
3251
+ listPlans(options?: ListPlansOptions): Promise<PlansListResponse>;
3252
+ /**
3253
+ * Report progress on a plan step (internal use by executePlan).
3254
+ *
3255
+ * @param planId - Plan ID
3256
+ * @param stepIndex - Step index
3257
+ * @param status - New status
3258
+ * @param details - Optional details (txHash, chargeId, error)
3259
+ */
3260
+ private reportPlanProgress;
3261
+ /**
3262
+ * Wait for a bridge order to complete.
3263
+ *
3264
+ * Polls the bridge status endpoint until the bridge is fulfilled or fails.
3265
+ *
3266
+ * @param orderId - Bridge order ID
3267
+ * @param options - Polling options
3268
+ * @throws {MixrPayError} If bridge fails or times out
3269
+ */
3270
+ waitForBridgeCompletion(orderId: string, options?: WaitForPlanOptions): Promise<void>;
3271
+ /**
3272
+ * Wait for a plan to complete execution.
3273
+ *
3274
+ * Polls the plan status until it reaches a terminal state.
3275
+ *
3276
+ * @param planId - Plan ID
3277
+ * @param options - Polling options
3278
+ * @returns Final plan status
3279
+ */
3280
+ waitForPlanCompletion(planId: string, options?: WaitForPlanOptions): Promise<PlanStatus>;
3281
+ /**
3282
+ * Execute an approved plan.
3283
+ *
3284
+ * Orchestrates step-by-step execution of an approved plan, handling:
3285
+ * - Sequential execution of steps
3286
+ * - Idempotency (safe to retry on restart)
3287
+ * - Bridge wait times
3288
+ * - Partial failure tracking
3289
+ *
3290
+ * This method runs in the agent's container (not serverless), so it can
3291
+ * wait for long-running operations like bridge confirmations.
3292
+ *
3293
+ * @param planId - Plan ID to execute
3294
+ * @returns Final plan status
3295
+ * @throws {MixrPayError} If plan is not executable
3296
+ *
3297
+ * @example
3298
+ * ```typescript
3299
+ * // Submit and execute a plan
3300
+ * const { planId, status } = await wallet.submitPlan({
3301
+ * title: 'DeFi workflow',
3302
+ * steps: [...],
3303
+ * totalEstimatedCostUsd: 50,
3304
+ * });
3305
+ *
3306
+ * if (status === 'pending_approval') {
3307
+ * // Wait for human approval
3308
+ * await wallet.waitForPlanCompletion(planId);
3309
+ * }
3310
+ *
3311
+ * // Execute once approved
3312
+ * const result = await wallet.executePlan(planId);
3313
+ * console.log(`Plan ${result.status}: ${result.steps.filter(s => s.status === 'completed').length} steps completed`);
3314
+ * ```
3315
+ */
3316
+ executePlan(planId: string): Promise<PlanStatus>;
2989
3317
  /**
2990
3318
  * Call the API with agent token auth (agt_live_xxx bearer token).
2991
3319
  * Used by DeFi methods that require delegation auth.
@@ -4673,4 +5001,4 @@ declare function getWalletStoragePath(): string;
4673
5001
  */
4674
5002
  declare function deleteWalletKey(): Promise<boolean>;
4675
5003
 
4676
- export { type AgentClaimInviteOptions, type AgentClaimInviteResult, type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type AnthropicToolDefinition, type AnthropicToolkit, AuthenticationError, type AvailableBudget, type BalancesResponse, type BridgeResponse, type BridgeStatusResponse, type CallMerchantApiOptions, type ChargeResult, type ChargeType, type ChildSession, type CompleteOptions, type CompleteResult, type ConnectOptions, type CredentialLoadResult, type DelegationBudget, type DeployJitMcpOptions, type DeployJitMcpResult, type DiagnosticsResult, type FetchPaidOptions, type FetchPaidResponse, type FetchPaymentInfo, type GetTransactionsOptions, type GlamaImportData, type GlamaSearchResult, type GlamaServer, InsufficientBalanceError, InvalidSessionKeyError, type JitInstance, type KnownChargeType, type MCPTool, type MCPToolResult, type McpServerConfig, MerchantNotAllowedError, MixrPayError, NetworkError, type PaymentEvent, PaymentFailedError, RateLimitError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, type SessionKeyInfo, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, type SiweOptions, type SiweResult, type SkillInfo, type SkillStatus, type SpawnChildOptions, type SpawnChildResult, SpendingLimitExceededError, type SpendingStats, type StoredCredentials, type StoredWallet, type SwapResponse, type TokenBalance, type Tool, type ToolResult, type TransactionRecord, type TransactionsResponse, type TransferResponse, type UseSkillOptions, type UseSkillResult, X402ProtocolError, deleteCredentials, deleteWalletKey, getCredentialsFilePath, getErrorMessage, getWalletStoragePath, hasCredentials, hasWalletKey, isMixrPayError, loadCredentials, loadWalletData, loadWalletKey, saveCredentials, saveWalletKey };
5004
+ export { type AgentClaimInviteOptions, type AgentClaimInviteResult, type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type AnthropicToolDefinition, type AnthropicToolkit, AuthenticationError, type AvailableBudget, type BalancesResponse, type BridgeOptions, type BridgeResponse, type BridgeStatusResponse, type CallMerchantApiOptions, type ChargeResult, type ChargeType, type ChildSession, type CompleteOptions, type CompleteResult, type ConnectOptions, type CredentialLoadResult, type DelegationBudget, type DeployJitMcpOptions, type DeployJitMcpResult, type DiagnosticsResult, type FetchPaidOptions, type FetchPaidResponse, type FetchPaymentInfo, type GetTransactionsOptions, type GlamaImportData, type GlamaSearchResult, type GlamaServer, InsufficientBalanceError, InvalidSessionKeyError, type JitInstance, type KnownChargeType, type ListPlansOptions, type MCPTool, type MCPToolResult, type McpServerConfig, MerchantNotAllowedError, MixrPayError, NetworkError, type PaymentEvent, PaymentFailedError, type PlanListItem, type PlanStatus, type PlanStatusValue, type PlanStep, type PlanStepAction, type PlanStepStatus, type PlanStepStatusValue, type PlanSubmission, type PlanSubmitResult, type PlansListResponse, RateLimitError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, type SessionKeyInfo, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, type SiweOptions, type SiweResult, type SkillInfo, type SkillStatus, type SpawnChildOptions, type SpawnChildResult, SpendingLimitExceededError, type SpendingStats, type StoredCredentials, type StoredWallet, type SwapOptions, type SwapResponse, type TokenBalance, type Tool, type ToolResult, type TransactionRecord, type TransactionsResponse, type TransferOptions, type TransferResponse, type UseSkillOptions, type UseSkillResult, type WaitForPlanOptions, X402ProtocolError, deleteCredentials, deleteWalletKey, getCredentialsFilePath, getErrorMessage, getWalletStoragePath, hasCredentials, hasWalletKey, isMixrPayError, loadCredentials, loadWalletData, loadWalletKey, saveCredentials, saveWalletKey };