@mixrpay/agent-sdk 0.8.9 → 0.10.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/LICENSE +21 -0
- package/README.md +49 -113
- package/dist/agent-wallet-FDRSEXLB.js +2 -0
- package/dist/chunk-IBXQMJ7G.js +1 -0
- package/dist/chunk-RAJSYN5T.js +32 -0
- package/dist/chunk-SWK4Q2A3.js +2 -0
- package/dist/cli.js +147 -0
- package/dist/credentials-QUSJGKLZ.js +2 -0
- package/dist/credentials-XJV2ESBQ.js +2 -0
- package/dist/credentials-Z4HQDXFU.js +1 -0
- package/dist/index.cjs +28 -4642
- package/dist/index.d.cts +1327 -303
- package/dist/index.d.ts +1327 -303
- package/dist/index.js +28 -4604
- package/dist/mcp-server.js +35 -0
- package/package.json +25 -10
package/dist/cli.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {b,a as a$1,e,d,c as c$1}from'./chunk-SWK4Q2A3.js';import {c,g,a}from'./chunk-RAJSYN5T.js';function x(e){let i={command:"",flags:{},positionals:[]},o=0;for(;o<e.length;){let r=e[o];if(r.startsWith("--")){let[n,t]=r.slice(2).split("=");t!==void 0?i.flags[n]=t:o+1<e.length&&!e[o+1].startsWith("-")?i.flags[n]=e[++o]:i.flags[n]=true;}else if(r.startsWith("-")){let n=r.slice(1);o+1<e.length&&!e[o+1].startsWith("-")?i.flags[n]=e[++o]:i.flags[n]=true;}else i.command?i.positionals.push(r):i.command=r;o++;}return i}async function v(e$1){if(e$1.help||e$1.h){console.log(`
|
|
3
|
+
mixrpay login - Authenticate via browser
|
|
4
|
+
|
|
5
|
+
USAGE
|
|
6
|
+
mixrpay login [options]
|
|
7
|
+
|
|
8
|
+
OPTIONS
|
|
9
|
+
--baseUrl, --url Override MixrPay API URL
|
|
10
|
+
--help, -h Show this help message
|
|
11
|
+
|
|
12
|
+
DESCRIPTION
|
|
13
|
+
Opens a browser window for you to authenticate with your MixrPay account.
|
|
14
|
+
After successful authentication, your session key is saved locally.
|
|
15
|
+
|
|
16
|
+
EXAMPLES
|
|
17
|
+
mixrpay login
|
|
18
|
+
mixrpay login --baseUrl https://staging.mixrpay.com
|
|
19
|
+
`);return}let i=e$1.baseUrl||e$1.url||c;console.log(`Starting MixrPay authentication...
|
|
20
|
+
`);try{let o=await g.deviceFlowLogin({baseUrl:i}),r=await o.getSessionKeyInfo();console.log("Logged in successfully!"),console.log(` Wallet: ${o.getWalletAddress()}`),console.log(` Network: ${o.getNetwork().name}`),r.expiresAt&&console.log(` Expires: ${r.expiresAt.toLocaleDateString()}`),console.log(`
|
|
21
|
+
Credentials saved to: ${e()}`);}catch(o){o instanceof a?console.error(`Login failed: ${o.message}`):console.error("Login failed:",o),process.exit(1);}}async function A(){if(!d()){console.log("No credentials found. Already logged out.");return}c$1()?(console.log("Logged out successfully."),console.log(`Credentials removed from: ${e()}`)):(console.error("Failed to remove credentials."),process.exit(1));}async function w(e$1){if(e$1.help||e$1.h){console.log(`
|
|
22
|
+
mixrpay whoami - Show current authentication status
|
|
23
|
+
|
|
24
|
+
USAGE
|
|
25
|
+
mixrpay whoami [options]
|
|
26
|
+
|
|
27
|
+
OPTIONS
|
|
28
|
+
--help, -h Show this help message
|
|
29
|
+
|
|
30
|
+
DESCRIPTION
|
|
31
|
+
Shows information about your current authentication status including
|
|
32
|
+
session key, wallet address, and remaining budget.
|
|
33
|
+
|
|
34
|
+
EXAMPLES
|
|
35
|
+
mixrpay whoami
|
|
36
|
+
`);return}let i=b();i.success||(console.error("Error loading credentials:",i.error),process.exit(1));let{credentials:o}=i;if(!o.sessionKey&&!o.apiToken&&!o.masterKey){console.log("Not logged in."),console.log("\nRun `mixrpay login` to authenticate.");return}if(console.log(`MixrPay Authentication Status
|
|
37
|
+
`),console.log(`Credentials file: ${e()}`),o.sessionKey){let r=o.sessionKey.startsWith("sk_test_")?"testnet":"mainnet";console.log(`Session key: ${o.sessionKey.slice(0,16)}...${o.sessionKey.slice(-8)} (${r})`);try{let n=o.baseUrl||c,t=new g({sessionKey:o.sessionKey,baseUrl:n}),s=await t.getSessionKeyInfo();if(console.log(`
|
|
38
|
+
Wallet: ${t.getWalletAddress()}`),console.log(`Network: ${t.getNetwork().name}`),s.expiresAt){let d=new Date,m=(s.expiresAt.getTime()-d.getTime())/(1e3*60*60);m<0?console.log(`Status: EXPIRED (${s.expiresAt.toLocaleDateString()})`):m<24?console.log(`Status: Active (expires in ${m.toFixed(1)} hours)`):console.log(`Status: Active (expires ${s.expiresAt.toLocaleDateString()})`);}if(s.limits.totalUsd){let d=s.limits.totalUsd-(s.usage?.totalUsd||0);console.log(`Budget: $${d.toFixed(2)} remaining of $${s.limits.totalUsd.toFixed(2)}`);}}catch{console.log(`
|
|
39
|
+
Note: Could not fetch additional info from server.`);}}o.apiToken&&console.log(`API token: ${o.apiToken.slice(0,16)}...`),o.masterKey&&(console.log(`Master key: ${o.masterKey.slice(0,16)}...`),o.defaultAgentName&&console.log(`Default agent: ${o.defaultAgentName}`)),o.baseUrl&&console.log(`Base URL: ${o.baseUrl}`),o.updatedAt&&console.log(`Last updated: ${new Date(o.updatedAt).toLocaleString()}`);}async function S(e){if(e.help||e.h){console.log(`
|
|
40
|
+
mixrpay register - Register a new agent with MixrPay
|
|
41
|
+
|
|
42
|
+
USAGE
|
|
43
|
+
mixrpay register [options]
|
|
44
|
+
|
|
45
|
+
OPTIONS
|
|
46
|
+
--key, --privateKey Agent's wallet private key (0x...)
|
|
47
|
+
--name, -n Agent display name
|
|
48
|
+
--mode Registration mode: wallet, invite, or self (default: wallet)
|
|
49
|
+
--invite-code Invite code for 'invite' mode
|
|
50
|
+
--baseUrl, --url Override MixrPay API URL
|
|
51
|
+
--help, -h Show this help message
|
|
52
|
+
|
|
53
|
+
EXAMPLES
|
|
54
|
+
# Register with wallet (default)
|
|
55
|
+
mixrpay register --key 0x... --name "My Agent"
|
|
56
|
+
|
|
57
|
+
# Register via invite code (no wallet needed)
|
|
58
|
+
mixrpay register --mode invite --invite-code mixr-abc123 --name "My Agent"
|
|
59
|
+
|
|
60
|
+
# Self-registration (gets claim code for human to fund)
|
|
61
|
+
mixrpay register --mode self --name "My Agent"
|
|
62
|
+
|
|
63
|
+
ENVIRONMENT VARIABLES
|
|
64
|
+
AGENT_WALLET_KEY Agent's wallet private key
|
|
65
|
+
`);return}let i=e.mode||"wallet",o=e.name||e.n,r=e.baseUrl||e.url||c,n=e["invite-code"]||e.inviteCode;if(["wallet","invite","self"].includes(i)||(console.error(`Error: Invalid mode '${i}'. Must be 'wallet', 'invite', or 'self'.`),process.exit(1)),i==="wallet"){let t=e.key||e.privateKey||process.env.AGENT_WALLET_KEY;t||(console.error("Error: Private key required for wallet mode."),console.error(`
|
|
66
|
+
Usage: mixrpay register --key 0x... [--name "Agent Name"]`),console.error(`
|
|
67
|
+
Alternatively, set the AGENT_WALLET_KEY environment variable.`),console.error(`
|
|
68
|
+
Or use --mode invite or --mode self for keyless registration.`),process.exit(1)),(!t.startsWith("0x")||t.length!==66)&&(console.error("Error: Invalid private key format."),console.error("Expected: 0x followed by 64 hex characters."),process.exit(1)),console.log(`Registering agent with wallet...
|
|
69
|
+
`);try{let s=await g.register({privateKey:t,name:o,baseUrl:r});console.log(`Agent registered successfully!
|
|
70
|
+
`),console.log(` User ID: ${s.userId}`),console.log(` Deposit Address: ${s.depositAddress}`),console.log(`
|
|
71
|
+
Next steps:`),console.log(" 1. Fund the deposit address with USDC on Base"),console.log(" 2. Run `mixrpay login` to authenticate via browser");}catch(s){s instanceof a?console.error(`Registration failed: ${s.message}`):console.error("Registration failed:",s),process.exit(1);}}else if(i==="invite"){n||(console.error("Error: Invite code required for invite mode."),console.error(`
|
|
72
|
+
Usage: mixrpay register --mode invite --invite-code mixr-... --name "Agent Name"`),process.exit(1)),o||(console.error("Error: Agent name required."),console.error(`
|
|
73
|
+
Usage: mixrpay register --mode invite --invite-code mixr-... --name "Agent Name"`),process.exit(1)),console.log(`Registering agent via invite code...
|
|
74
|
+
`);try{let t=await fetch(`${r}/api/v2/agent/register`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:"invite",name:o,invite_code:n})}),s=await t.json();if(!t.ok)throw new Error(s.error||"Registration failed");console.log(`Agent registered successfully!
|
|
75
|
+
`),console.log(` Agent ID: ${s.agent_id}`),s.instance_id&&console.log(` Instance ID: ${s.instance_id}`),console.log(` Status: ${s.status}`),console.log(` Budget: $${s.budget_usd}`),console.log(` Inviter: ${s.inviter_name}`),s.session?.session_key||s.token?(a$1({sessionKey:s.session?.session_key,apiToken:s.token,baseUrl:r}),s.session?.session_key&&console.log(` Session Key: ${s.session.session_key.slice(0,16)}...`),s.token&&console.log(` Token: ${s.token.slice(0,16)}...`),console.log("\nCredentials saved. Run `mixrpay status` to check your agent.")):console.log(`
|
|
76
|
+
Your agent is now active and ready to make payments!`);}catch(t){console.error(`Registration failed: ${t instanceof Error?t.message:t}`),process.exit(1);}}else if(i==="self"){o||(console.error("Error: Agent name required."),console.error(`
|
|
77
|
+
Usage: mixrpay register --mode self --name "Agent Name"`),process.exit(1)),console.log(`Self-registering agent...
|
|
78
|
+
`);try{let t=await fetch(`${r}/api/v2/agent/register`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:"self",name:o})}),s=await t.json();if(!t.ok)throw new Error(s.error||"Registration failed");console.log(`Agent created successfully!
|
|
79
|
+
`),console.log(` Agent ID: ${s.agent_id}`),console.log(` Status: ${s.status}`),console.log(` Claim Code: ${s.claim_code}`),console.log(`
|
|
80
|
+
Next steps:`),console.log(" Share this URL with a human to fund and activate this agent:"),console.log(` ${s.claim_url}`),console.log(`
|
|
81
|
+
The claim code expires in ${s.expires_in_days} days.`);}catch(t){console.error(`Registration failed: ${t instanceof Error?t.message:t}`),process.exit(1);}}}async function $(e){if(e.help||e.h){console.log(`
|
|
82
|
+
mixrpay status - Show agent balance and session info
|
|
83
|
+
|
|
84
|
+
USAGE
|
|
85
|
+
mixrpay status [options]
|
|
86
|
+
|
|
87
|
+
OPTIONS
|
|
88
|
+
--key, --privateKey Agent's wallet private key (optional if logged in)
|
|
89
|
+
--baseUrl, --url Override MixrPay API URL
|
|
90
|
+
--help, -h Show this help message
|
|
91
|
+
|
|
92
|
+
DESCRIPTION
|
|
93
|
+
Shows your agent's current status including balance, spending stats,
|
|
94
|
+
and active sessions. If you've run 'mixrpay login', it will use your
|
|
95
|
+
cached session key. Otherwise, provide a private key.
|
|
96
|
+
|
|
97
|
+
EXAMPLES
|
|
98
|
+
mixrpay status # Uses cached session key
|
|
99
|
+
mixrpay status --key 0x... # Uses wallet private key
|
|
100
|
+
`);return}let i=e.key||e.privateKey||process.env.AGENT_WALLET_KEY,o=e.baseUrl||e.url||c,r=b();if(!i&&r.success&&r.credentials.sessionKey)try{let n=new g({sessionKey:r.credentials.sessionKey,baseUrl:r.credentials.baseUrl||o}),t=await n.getSpendingStats(),s=await n.getSessionKeyInfo();console.log(`Agent Status (via session key)
|
|
101
|
+
`),console.log(`Wallet: ${n.getWalletAddress()}`),console.log(`Network: ${n.getNetwork().name}`),console.log(`
|
|
102
|
+
Spending:`),console.log(` Total spent: $${t.totalSpentUsd.toFixed(2)}`),console.log(` Transaction count: ${t.txCount}`),t.remainingDailyUsd!==null&&console.log(` Daily remaining: $${t.remainingDailyUsd.toFixed(2)}`),t.remainingTotalUsd!==null&&console.log(` Total remaining: $${t.remainingTotalUsd.toFixed(2)}`),s.expiresAt&&console.log(`
|
|
103
|
+
Session expires: ${s.expiresAt.toLocaleString()}`);return}catch{console.error("Failed to get status via session key."),i||(console.error("Provide --key to use wallet signature auth instead."),process.exit(1));}i||(console.error("Error: Private key required (no cached session key found)."),console.error(`
|
|
104
|
+
Usage: mixrpay status --key 0x...`),console.error(`
|
|
105
|
+
Alternatively:`),console.error(" - Run `mixrpay login` to cache credentials"),console.error(" - Set the AGENT_WALLET_KEY environment variable"),process.exit(1)),console.log(`Fetching agent status...
|
|
106
|
+
`);try{let n=await g.getStatus({privateKey:i,baseUrl:o});console.log(`Agent Status
|
|
107
|
+
`),console.log(`Deposit Address: ${n.depositAddress}`),console.log(`Balance: $${n.balanceUsd.toFixed(2)} USDC`),console.log(`Total Spent: $${n.totalSpentUsd.toFixed(2)}`),console.log(`
|
|
108
|
+
Active Sessions: ${n.activeSessions.length}`);for(let t of n.activeSessions){let s=t.remainingUsd!==null?`$${t.remainingUsd.toFixed(2)} remaining`:"unlimited";console.log(` - ${t.id.slice(0,8)}... ${s}, expires ${t.expiresAt.toLocaleDateString()}`);}}catch(n){n instanceof a?console.error(`Failed to get status: ${n.message}`):console.error("Failed to get status:",n),process.exit(1);}}function h(){console.log(`
|
|
109
|
+
MixrPay CLI - Manage AI agent payments
|
|
110
|
+
|
|
111
|
+
USAGE
|
|
112
|
+
mixrpay <command> [options]
|
|
113
|
+
|
|
114
|
+
COMMANDS
|
|
115
|
+
login Authenticate via browser and save credentials
|
|
116
|
+
logout Clear saved credentials
|
|
117
|
+
whoami Show current authentication status
|
|
118
|
+
register Register a new agent with MixrPay
|
|
119
|
+
status Show agent balance and session info
|
|
120
|
+
|
|
121
|
+
OPTIONS
|
|
122
|
+
--help, -h Show this help message
|
|
123
|
+
--version, -v Show version number
|
|
124
|
+
--baseUrl Override MixrPay API URL (default: https://www.mixrpay.com)
|
|
125
|
+
|
|
126
|
+
EXAMPLES
|
|
127
|
+
# Interactive login (opens browser)
|
|
128
|
+
mixrpay login
|
|
129
|
+
|
|
130
|
+
# Check current auth status
|
|
131
|
+
mixrpay whoami
|
|
132
|
+
|
|
133
|
+
# Register new agent
|
|
134
|
+
mixrpay register --key 0x... --name "My Agent"
|
|
135
|
+
|
|
136
|
+
# Check agent status
|
|
137
|
+
mixrpay status --key 0x...
|
|
138
|
+
|
|
139
|
+
ENVIRONMENT VARIABLES
|
|
140
|
+
MIXRPAY_SESSION_KEY Session key for authentication
|
|
141
|
+
MIXRPAY_API_KEY API key for authentication
|
|
142
|
+
MIXRPAY_MASTER_KEY Master key for multi-agent deployments
|
|
143
|
+
MIXRPAY_BASE_URL Custom API base URL
|
|
144
|
+
AGENT_WALLET_KEY Agent's wallet private key
|
|
145
|
+
|
|
146
|
+
For more info, visit: https://docs.mixrpay.com/cli
|
|
147
|
+
`);}function k(){import('./agent-wallet-FDRSEXLB.js').then(({SDK_VERSION:e})=>{console.log(`mixrpay v${e}`);});}async function E(){let e=x(process.argv.slice(2));if(e.flags.help||e.flags.h){h();return}if(e.flags.version||e.flags.v){k();return}switch(e.command){case "login":await v(e.flags);break;case "logout":await A();break;case "whoami":await w(e.flags);break;case "register":await S(e.flags);break;case "status":await $(e.flags);break;case "":case "help":h();break;default:console.error(`Unknown command: ${e.command}`),console.error("\nRun `mixrpay --help` for usage information."),process.exit(1);}}E().catch(e=>{console.error("Fatal error:",e),process.exit(1);});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import*as r from'fs';import*as s from'path';import*as o from'os';function d(){if(o.platform()==="win32"){let n=process.env.APPDATA||s.join(o.homedir(),"AppData","Roaming");return s.join(n,"mixrpay")}let e=process.env.XDG_CONFIG_HOME||s.join(o.homedir(),".config");return s.join(e,"mixrpay")}function a(){return s.join(d(),"credentials.json")}function g(){let t=d();r.existsSync(t)||r.mkdirSync(t,{recursive:true,mode:448});}function f(t){try{r.chmodSync(t,384);}catch{}}function y(t){try{g();let e=a(),n={};if(r.existsSync(e))try{let l=r.readFileSync(e,"utf-8");n=JSON.parse(l);}catch{n={};}let i={...n,...t,updatedAt:new Date().toISOString()},c=Object.fromEntries(Object.entries(i).filter(([l,p])=>p!==void 0));return r.writeFileSync(e,JSON.stringify(c,null,2),{mode:384}),f(e),!0}catch(e){return console.error("[MixrPay] Failed to save credentials:",e),false}}function u(){try{let t=a();if(!r.existsSync(t))return {success:!0,credentials:{}};let e=r.readFileSync(t,"utf-8");return {success:!0,credentials:JSON.parse(e)}}catch(t){return {success:false,error:t instanceof Error?t.message:"Failed to load credentials"}}}function S(t){try{let e=a();if(!r.existsSync(e))return !0;if(!t)return r.unlinkSync(e),!0;let n=u();if(!n.success)return !1;let i={...n.credentials};for(let c of t)delete i[c];return Object.keys(i).length===0?r.unlinkSync(e):(r.writeFileSync(e,JSON.stringify(i,null,2),{mode:384}),f(e)),!0}catch(e){return console.error("[MixrPay] Failed to delete credentials:",e),false}}function m(){let t=u();if(!t.success)return false;let{credentials:e}=t;return !!(e.sessionKey||e.apiToken||e.masterKey)}function h(){return a()}export{S as deleteCredentials,h as getCredentialsFilePath,m as hasCredentials,u as loadCredentials,y as saveCredentials};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{c as deleteCredentials,e as getCredentialsFilePath,d as hasCredentials,b as loadCredentials,a as saveCredentials}from'./chunk-IBXQMJ7G.js';
|