@mixrpay/agent-sdk 0.3.2 → 0.3.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/dist/index.d.ts CHANGED
@@ -745,6 +745,359 @@ declare class AgentWallet {
745
745
  * Parse session response data into SessionAuthorization object.
746
746
  */
747
747
  private parseSessionResponse;
748
+ /**
749
+ * Get authentication headers for MCP wallet-based authentication.
750
+ *
751
+ * These headers prove wallet ownership without transmitting the private key.
752
+ * Use for direct pay-per-call mode (no session needed).
753
+ *
754
+ * @returns Headers object with X-Mixr-Wallet, X-Mixr-Signature, X-Mixr-Timestamp
755
+ *
756
+ * @example
757
+ * ```typescript
758
+ * const headers = await wallet.getMCPAuthHeaders();
759
+ * const response = await fetch('https://mixrpay.com/api/mcp', {
760
+ * method: 'POST',
761
+ * headers: {
762
+ * 'Content-Type': 'application/json',
763
+ * ...headers,
764
+ * },
765
+ * body: JSON.stringify({
766
+ * jsonrpc: '2.0',
767
+ * method: 'tools/list',
768
+ * id: 1,
769
+ * }),
770
+ * });
771
+ * ```
772
+ */
773
+ getMCPAuthHeaders(): Promise<Record<string, string>>;
774
+ /**
775
+ * List available MCP tools from the MixrPay gateway.
776
+ *
777
+ * Returns all tools exposed by MCP providers on the MixrPay marketplace.
778
+ * Each tool includes pricing information.
779
+ *
780
+ * @returns Array of MCP tools with pricing and metadata
781
+ *
782
+ * @example
783
+ * ```typescript
784
+ * const tools = await wallet.listMCPTools();
785
+ * for (const tool of tools) {
786
+ * console.log(`${tool.name}: $${tool.priceUsd} - ${tool.description}`);
787
+ * }
788
+ * ```
789
+ */
790
+ listMCPTools(): Promise<MCPTool[]>;
791
+ /**
792
+ * Call an MCP tool with wallet authentication (direct pay per call).
793
+ *
794
+ * This method signs a fresh auth message for each call, charging
795
+ * directly from your wallet balance without needing a session.
796
+ *
797
+ * @param toolName - The tool name in format "merchant/tool"
798
+ * @param args - Arguments to pass to the tool
799
+ * @returns Tool execution result
800
+ *
801
+ * @example
802
+ * ```typescript
803
+ * const result = await wallet.callMCPTool('firecrawl/scrape', {
804
+ * url: 'https://example.com',
805
+ * });
806
+ * console.log(result.data);
807
+ * console.log(`Charged: $${result.chargedUsd}`);
808
+ * ```
809
+ */
810
+ callMCPTool(toolName: string, args?: Record<string, unknown>): Promise<MCPToolResult>;
811
+ /**
812
+ * Run an AI agent with LLM and tool execution.
813
+ *
814
+ * This method orchestrates a full agentic loop:
815
+ * - Multi-turn reasoning with LLM
816
+ * - Automatic tool execution
817
+ * - Bundled billing (single charge at end)
818
+ * - Optional streaming via SSE
819
+ *
820
+ * @param options - Agent run options
821
+ * @returns Agent run result with response and cost breakdown
822
+ *
823
+ * @example Basic usage
824
+ * ```typescript
825
+ * const result = await wallet.runAgent({
826
+ * sessionId: 'sess_abc123',
827
+ * messages: [{ role: 'user', content: 'Find AI startups in SF' }],
828
+ * });
829
+ *
830
+ * console.log(result.response);
831
+ * console.log(`Cost: $${result.cost.totalUsd.toFixed(4)}`);
832
+ * ```
833
+ *
834
+ * @example With custom config
835
+ * ```typescript
836
+ * const result = await wallet.runAgent({
837
+ * sessionId: 'sess_abc123',
838
+ * messages: [{ role: 'user', content: 'Research quantum computing' }],
839
+ * config: {
840
+ * model: 'gpt-4o',
841
+ * maxIterations: 15,
842
+ * tools: ['platform/exa-search', 'platform/firecrawl-scrape'],
843
+ * systemPrompt: 'You are a research assistant.',
844
+ * },
845
+ * });
846
+ * ```
847
+ *
848
+ * @example With streaming
849
+ * ```typescript
850
+ * await wallet.runAgent({
851
+ * sessionId: 'sess_abc123',
852
+ * messages: [{ role: 'user', content: 'Analyze this company' }],
853
+ * stream: true,
854
+ * onEvent: (event) => {
855
+ * if (event.type === 'llm_chunk') {
856
+ * process.stdout.write(event.delta);
857
+ * } else if (event.type === 'tool_call') {
858
+ * console.log(`Calling tool: ${event.tool}`);
859
+ * }
860
+ * },
861
+ * });
862
+ * ```
863
+ */
864
+ runAgent(options: AgentRunOptions): Promise<AgentRunResult>;
865
+ /**
866
+ * Internal: Handle streaming agent run via SSE
867
+ */
868
+ private runAgentStreaming;
869
+ /**
870
+ * Internal: Parse SSE event into typed event object
871
+ */
872
+ private parseSSEEvent;
873
+ /**
874
+ * Get the status of an agent run by ID.
875
+ *
876
+ * @param runId - The agent run ID
877
+ * @param sessionId - The session ID (for authentication)
878
+ * @returns Agent run status and results
879
+ *
880
+ * @example
881
+ * ```typescript
882
+ * const status = await wallet.getAgentRunStatus('run_abc123', 'sess_xyz789');
883
+ * console.log(`Status: ${status.status}`);
884
+ * if (status.status === 'completed') {
885
+ * console.log(status.response);
886
+ * }
887
+ * ```
888
+ */
889
+ getAgentRunStatus(runId: string, sessionId: string): Promise<AgentRunStatusResult>;
890
+ /**
891
+ * Call an MCP tool using session authorization (pre-authorized spending limit).
892
+ *
893
+ * Use this when you've already created a session with the tool provider
894
+ * and want to use that spending limit instead of direct wallet charges.
895
+ *
896
+ * @param sessionId - The session ID for the tool provider
897
+ * @param toolName - The tool name in format "merchant/tool"
898
+ * @param args - Arguments to pass to the tool
899
+ * @returns Tool execution result
900
+ *
901
+ * @example
902
+ * ```typescript
903
+ * // Create session with provider first
904
+ * const session = await wallet.getOrCreateSession({
905
+ * merchantPublicKey: 'pk_live_firecrawl_...',
906
+ * spendingLimitUsd: 50,
907
+ * });
908
+ *
909
+ * // Use session for multiple calls
910
+ * const result = await wallet.callMCPToolWithSession(
911
+ * session.id,
912
+ * 'firecrawl/scrape',
913
+ * { url: 'https://example.com' }
914
+ * );
915
+ * ```
916
+ */
917
+ callMCPToolWithSession(sessionId: string, toolName: string, args?: Record<string, unknown>): Promise<MCPToolResult>;
918
+ }
919
+ /**
920
+ * MCP Tool definition returned by listMCPTools()
921
+ */
922
+ interface MCPTool {
923
+ /** Tool name in format "merchant/tool" */
924
+ name: string;
925
+ /** Human-readable description with price */
926
+ description: string;
927
+ /** JSON Schema for tool input parameters */
928
+ inputSchema: Record<string, unknown>;
929
+ /** Price per call in USD */
930
+ priceUsd: number;
931
+ /** Merchant/provider name */
932
+ merchantName: string;
933
+ /** Merchant slug for session creation */
934
+ merchantSlug: string;
935
+ /** Whether the provider is domain-verified */
936
+ verified: boolean;
937
+ }
938
+ /**
939
+ * Result from calling an MCP tool
940
+ */
941
+ interface MCPToolResult {
942
+ /** The tool's response data */
943
+ data: unknown;
944
+ /** Amount charged in USD */
945
+ chargedUsd: number;
946
+ /** On-chain transaction hash (if available) */
947
+ txHash?: string;
948
+ /** Execution latency in milliseconds */
949
+ latencyMs?: number;
950
+ }
951
+ /**
952
+ * Message in an agent conversation
953
+ */
954
+ interface AgentMessage {
955
+ /** Message role */
956
+ role: 'user' | 'assistant' | 'system' | 'tool';
957
+ /** Message content */
958
+ content: string;
959
+ }
960
+ /**
961
+ * Configuration for an agent run
962
+ */
963
+ interface AgentRunConfig {
964
+ /** LLM model to use (default: gpt-4o-mini) */
965
+ model?: string;
966
+ /** Maximum iterations before stopping (default: 10, max: 25) */
967
+ maxIterations?: number;
968
+ /** Specific tools to enable (e.g., ['platform/exa-search', 'platform/firecrawl-scrape']) */
969
+ tools?: string[];
970
+ /** Custom system prompt for the agent */
971
+ systemPrompt?: string;
972
+ }
973
+ /**
974
+ * Options for running an agent
975
+ */
976
+ interface AgentRunOptions {
977
+ /** Session ID for authentication and billing */
978
+ sessionId: string;
979
+ /** Conversation messages */
980
+ messages: AgentMessage[];
981
+ /** Agent configuration */
982
+ config?: AgentRunConfig;
983
+ /** Enable SSE streaming (default: false) */
984
+ stream?: boolean;
985
+ /** Unique key for idempotency */
986
+ idempotencyKey?: string;
987
+ /** Callback for streaming events */
988
+ onEvent?: (event: AgentRunEvent) => void;
989
+ }
990
+ /**
991
+ * Result from an agent run
992
+ */
993
+ interface AgentRunResult {
994
+ /** Unique run ID */
995
+ runId: string;
996
+ /** Run status */
997
+ status: 'completed' | 'failed';
998
+ /** Final response from the agent */
999
+ response: string;
1000
+ /** Number of iterations performed */
1001
+ iterations: number;
1002
+ /** Tools used during the run */
1003
+ toolsUsed: string[];
1004
+ /** Cost breakdown */
1005
+ cost: {
1006
+ /** LLM cost in USD */
1007
+ llmUsd: number;
1008
+ /** Tool execution cost in USD */
1009
+ toolsUsd: number;
1010
+ /** Total cost in USD */
1011
+ totalUsd: number;
1012
+ };
1013
+ /** Token usage */
1014
+ tokens: {
1015
+ /** Prompt tokens used */
1016
+ prompt: number;
1017
+ /** Completion tokens used */
1018
+ completion: number;
1019
+ };
1020
+ /** Remaining session balance in USD */
1021
+ sessionRemainingUsd: number;
1022
+ /** On-chain transaction hash for payment */
1023
+ txHash?: string;
1024
+ }
1025
+ /**
1026
+ * Streaming events from an agent run
1027
+ */
1028
+ type AgentRunEvent = {
1029
+ type: 'run_start';
1030
+ runId: string;
1031
+ } | {
1032
+ type: 'iteration_start';
1033
+ iteration: number;
1034
+ } | {
1035
+ type: 'llm_chunk';
1036
+ delta: string;
1037
+ } | {
1038
+ type: 'tool_call';
1039
+ tool: string;
1040
+ arguments: unknown;
1041
+ } | {
1042
+ type: 'tool_result';
1043
+ tool: string;
1044
+ success: boolean;
1045
+ costUsd: number;
1046
+ error?: string;
1047
+ } | {
1048
+ type: 'iteration_complete';
1049
+ iteration: number;
1050
+ tokens?: {
1051
+ prompt?: number;
1052
+ completion?: number;
1053
+ };
1054
+ costUsd?: number;
1055
+ } | {
1056
+ type: 'complete';
1057
+ runId: string;
1058
+ response: string;
1059
+ totalCostUsd: number;
1060
+ txHash?: string;
1061
+ iterations: number;
1062
+ toolsUsed: string[];
1063
+ } | {
1064
+ type: 'error';
1065
+ error: string;
1066
+ partialCostUsd?: number;
1067
+ };
1068
+ /**
1069
+ * Result from getting agent run status
1070
+ */
1071
+ interface AgentRunStatusResult {
1072
+ /** Unique run ID */
1073
+ runId: string;
1074
+ /** Run status */
1075
+ status: 'running' | 'completed' | 'failed' | 'interrupted';
1076
+ /** Final response (if completed) */
1077
+ response?: string;
1078
+ /** Number of iterations performed */
1079
+ iterations: number;
1080
+ /** Tools used during the run */
1081
+ toolsUsed: string[];
1082
+ /** Cost breakdown */
1083
+ cost: {
1084
+ llmUsd: number;
1085
+ toolsUsd: number;
1086
+ totalUsd: number;
1087
+ };
1088
+ /** Token usage */
1089
+ tokens: {
1090
+ prompt: number;
1091
+ completion: number;
1092
+ };
1093
+ /** On-chain transaction hash */
1094
+ txHash?: string;
1095
+ /** Error message (if failed) */
1096
+ error?: string;
1097
+ /** When the run started */
1098
+ startedAt: Date;
1099
+ /** When the run completed */
1100
+ completedAt?: Date;
748
1101
  }
749
1102
 
750
1103
  /**
@@ -1075,4 +1428,4 @@ declare class SessionRevokedError extends MixrPayError {
1075
1428
  */
1076
1429
  declare function isMixrPayError(error: unknown): error is MixrPayError;
1077
1430
 
1078
- export { AgentWallet, type AgentWalletConfig, type CallMerchantApiOptions, type ChargeResult, InsufficientBalanceError, InvalidSessionKeyError, MixrPayError, type PaymentEvent, PaymentFailedError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, SpendingLimitExceededError, type SpendingStats, isMixrPayError };
1431
+ export { type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type CallMerchantApiOptions, type ChargeResult, InsufficientBalanceError, InvalidSessionKeyError, MixrPayError, type PaymentEvent, PaymentFailedError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, SpendingLimitExceededError, type SpendingStats, isMixrPayError };