@mixrpay/agent-sdk 0.8.5 → 0.8.7
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.
Potentially problematic release.
This version of @mixrpay/agent-sdk might be problematic. Click here for more details.
- package/README.md +58 -4
- package/dist/index.cjs +155 -8
- package/dist/index.d.cts +159 -7
- package/dist/index.d.ts +159 -7
- package/dist/index.js +155 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,71 @@
|
|
|
2
2
|
|
|
3
3
|
Enable AI agents to make payments to MixrPay-powered APIs.
|
|
4
4
|
|
|
5
|
+
## Getting Started: Claim an Access Code
|
|
6
|
+
|
|
7
|
+
Agents get spending authorization by claiming an **Access Code** from a human wallet owner.
|
|
8
|
+
|
|
9
|
+
### Step 1: Human Creates Access Code
|
|
10
|
+
|
|
11
|
+
The human logs in at [mixrpay.com/manage/invites](https://www.mixrpay.com/manage/invites), deposits funds, and creates an Access Code (e.g., `mixr-abc123`) with a budget.
|
|
12
|
+
|
|
13
|
+
### Step 2: Agent Claims the Access Code
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AgentWallet } from '@mixrpay/agent-sdk';
|
|
17
|
+
|
|
18
|
+
// Claim the Access Code to get your session key
|
|
19
|
+
const result = await AgentWallet.claimInvite({
|
|
20
|
+
inviteCode: 'mixr-abc123', // From the human
|
|
21
|
+
privateKey: process.env.AGENT_WALLET_KEY as `0x${string}`,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// IMPORTANT: Save this immediately — shown ONCE, cannot be recovered!
|
|
25
|
+
console.log('Session Key:', result.sessionKey); // sk_live_xxx
|
|
26
|
+
console.log('Budget:', result.limits.budgetUsd);
|
|
27
|
+
console.log('Invited by:', result.inviterName);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Step 3: Use the Session Key
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const wallet = new AgentWallet({
|
|
34
|
+
sessionKey: result.sessionKey, // or process.env.MIXRPAY_SESSION_KEY
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// All spending is authorized from the human's wallet
|
|
38
|
+
const response = await wallet.fetch('https://api.example.com/paid-endpoint');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Understanding Wallet Addresses
|
|
42
|
+
|
|
43
|
+
When you claim an Access Code, two addresses are involved:
|
|
44
|
+
|
|
45
|
+
| Address | What it is | Purpose |
|
|
46
|
+
|---------|-----------|---------|
|
|
47
|
+
| `info.address` | Session key's derived address | Used for signing requests |
|
|
48
|
+
| `info.walletAddress` | Human's funded wallet | Where funds are charged FROM |
|
|
49
|
+
|
|
50
|
+
**Verify which wallet you're spending from:**
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const info = await wallet.getSessionKeyInfo();
|
|
54
|
+
console.log('Session key:', info.address); // Your signing key
|
|
55
|
+
console.log('Spending from:', info.walletAddress); // Human's wallet (funding source)
|
|
56
|
+
console.log('Budget remaining:', info.limits.totalUsd);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This is important: your session key authorizes spending from the **human's wallet**, not your own external wallet. The human controls the budget and can revoke access at any time.
|
|
60
|
+
|
|
5
61
|
## Important: Session Key Security
|
|
6
62
|
|
|
7
63
|
Your session key (`sk_live_...`) is a **private key**. Treat it like a password:
|
|
8
64
|
|
|
9
|
-
- **Save it immediately** when you receive it (from `claimInvite()`
|
|
65
|
+
- **Save it immediately** when you receive it (from `claimInvite()`)
|
|
10
66
|
- **Store it securely** (environment variable, secrets manager)
|
|
11
67
|
- **Never commit it** to version control
|
|
12
68
|
- **Never log it** to console or files
|
|
13
|
-
- **It cannot be recovered** if lost - you will need a new
|
|
69
|
+
- **It cannot be recovered** if lost - you will need a new Access Code
|
|
14
70
|
|
|
15
71
|
The session key is shown **only once** when claimed. MixrPay does not store it.
|
|
16
72
|
|
|
@@ -39,8 +95,6 @@ const response = await wallet.callMerchantApi({
|
|
|
39
95
|
const data = await response.json();
|
|
40
96
|
```
|
|
41
97
|
|
|
42
|
-
Get session keys at [mixrpay.com/wallet/sessions](https://www.mixrpay.com/wallet/sessions).
|
|
43
|
-
|
|
44
98
|
## Core Methods
|
|
45
99
|
|
|
46
100
|
```typescript
|
package/dist/index.cjs
CHANGED
|
@@ -100,7 +100,7 @@ var InsufficientBalanceError = class extends MixrPayError {
|
|
|
100
100
|
this.name = "InsufficientBalanceError";
|
|
101
101
|
this.required = required;
|
|
102
102
|
this.available = available;
|
|
103
|
-
this.topUpUrl = "/wallet";
|
|
103
|
+
this.topUpUrl = "https://mixrpay.com/manage/wallet";
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
var SessionKeyExpiredError = class extends MixrPayError {
|
|
@@ -108,7 +108,7 @@ var SessionKeyExpiredError = class extends MixrPayError {
|
|
|
108
108
|
expiredAt;
|
|
109
109
|
constructor(expiredAt) {
|
|
110
110
|
super(
|
|
111
|
-
`Session key expired at ${expiredAt}. Request a new session key from the wallet owner
|
|
111
|
+
`Session key expired at ${expiredAt}. Request a new session key from the wallet owner at https://mixrpay.com/manage/invites`,
|
|
112
112
|
"SESSION_KEY_EXPIRED"
|
|
113
113
|
);
|
|
114
114
|
this.name = "SessionKeyExpiredError";
|
|
@@ -177,7 +177,7 @@ var InvalidSessionKeyError = class extends MixrPayError {
|
|
|
177
177
|
reason;
|
|
178
178
|
constructor(reason = "Invalid session key format") {
|
|
179
179
|
super(
|
|
180
|
-
`${reason}. Session keys should be in format: sk_live_<64 hex chars> or sk_test_<64 hex chars>. Get one from
|
|
180
|
+
`${reason}. Session keys should be in format: sk_live_<64 hex chars> or sk_test_<64 hex chars>. Get one from https://mixrpay.com/manage/invites`,
|
|
181
181
|
"INVALID_SESSION_KEY"
|
|
182
182
|
);
|
|
183
183
|
this.name = "InvalidSessionKeyError";
|
|
@@ -532,7 +532,7 @@ function getAmountUsd(requirements) {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
// src/agent-wallet.ts
|
|
535
|
-
var SDK_VERSION = "0.8.
|
|
535
|
+
var SDK_VERSION = "0.8.7";
|
|
536
536
|
var DEFAULT_BASE_URL = process.env.MIXRPAY_BASE_URL || "https://www.mixrpay.com";
|
|
537
537
|
var DEFAULT_TIMEOUT = 3e4;
|
|
538
538
|
var NETWORKS = {
|
|
@@ -648,7 +648,7 @@ var AgentWallet = class {
|
|
|
648
648
|
validateConfig(config) {
|
|
649
649
|
if (!config.sessionKey) {
|
|
650
650
|
throw new InvalidSessionKeyError(
|
|
651
|
-
"Session key is required. Get one from the wallet owner
|
|
651
|
+
"Session key is required. Get one from the wallet owner at https://mixrpay.com/manage/invites"
|
|
652
652
|
);
|
|
653
653
|
}
|
|
654
654
|
const key = config.sessionKey.trim();
|
|
@@ -1161,7 +1161,7 @@ var AgentWallet = class {
|
|
|
1161
1161
|
*
|
|
1162
1162
|
* @example
|
|
1163
1163
|
* ```typescript
|
|
1164
|
-
* // Human creates invite at
|
|
1164
|
+
* // Human creates invite at https://mixrpay.com/manage/invites, shares code "mixr-abc123"
|
|
1165
1165
|
*
|
|
1166
1166
|
* const result = await AgentWallet.claimInvite({
|
|
1167
1167
|
* inviteCode: 'mixr-abc123',
|
|
@@ -1387,6 +1387,16 @@ var AgentWallet = class {
|
|
|
1387
1387
|
const data = await response.json();
|
|
1388
1388
|
return data.children || [];
|
|
1389
1389
|
}
|
|
1390
|
+
/**
|
|
1391
|
+
* List child sessions spawned by this agent.
|
|
1392
|
+
*
|
|
1393
|
+
* Alias for `getChildSessions()` for naming consistency.
|
|
1394
|
+
*
|
|
1395
|
+
* @returns Array of child session info
|
|
1396
|
+
*/
|
|
1397
|
+
async listChildSessions() {
|
|
1398
|
+
return this.getChildSessions();
|
|
1399
|
+
}
|
|
1390
1400
|
// ===========================================================================
|
|
1391
1401
|
// Core Methods
|
|
1392
1402
|
// ===========================================================================
|
|
@@ -1697,6 +1707,7 @@ var AgentWallet = class {
|
|
|
1697
1707
|
const data = await response.json();
|
|
1698
1708
|
this.sessionKeyInfo = {
|
|
1699
1709
|
address: this.sessionKey.address,
|
|
1710
|
+
walletAddress: data.wallet_address ?? data.walletAddress ?? null,
|
|
1700
1711
|
isValid: data.is_valid ?? data.isValid ?? true,
|
|
1701
1712
|
limits: {
|
|
1702
1713
|
perTxUsd: data.per_tx_limit_usd ?? data.perTxLimitUsd ?? null,
|
|
@@ -1721,6 +1732,7 @@ var AgentWallet = class {
|
|
|
1721
1732
|
}
|
|
1722
1733
|
return {
|
|
1723
1734
|
address: this.sessionKey.address,
|
|
1735
|
+
walletAddress: null,
|
|
1724
1736
|
isValid: true,
|
|
1725
1737
|
limits: { perTxUsd: null, dailyUsd: null, totalUsd: null },
|
|
1726
1738
|
usage: { todayUsd: this.totalSpentUsd, totalUsd: this.totalSpentUsd, txCount: this.payments.length },
|
|
@@ -1840,7 +1852,7 @@ var AgentWallet = class {
|
|
|
1840
1852
|
checks.sessionKeyValid = info.isValid;
|
|
1841
1853
|
if (!info.isValid) {
|
|
1842
1854
|
issues.push("Session key is invalid or has been revoked.");
|
|
1843
|
-
recommendations.push("Request a new session key from the wallet owner
|
|
1855
|
+
recommendations.push("Request a new session key from the wallet owner at https://mixrpay.com/manage/invites");
|
|
1844
1856
|
}
|
|
1845
1857
|
const now = /* @__PURE__ */ new Date();
|
|
1846
1858
|
let expiresInHours = null;
|
|
@@ -1880,7 +1892,7 @@ var AgentWallet = class {
|
|
|
1880
1892
|
balance = await this.getBalance();
|
|
1881
1893
|
checks.hasBalance = balance > 0;
|
|
1882
1894
|
if (balance <= 0) {
|
|
1883
|
-
issues.push("Wallet has no USDC balance. Top up at
|
|
1895
|
+
issues.push("Wallet has no USDC balance. Top up at https://mixrpay.com/manage/wallet");
|
|
1884
1896
|
recommendations.push("Deposit USDC to your wallet address to enable payments.");
|
|
1885
1897
|
} else if (balance < 1) {
|
|
1886
1898
|
issues.push(`Low balance: $${balance.toFixed(2)}. Consider topping up.`);
|
|
@@ -2683,6 +2695,141 @@ Timestamp: ${timestamp}`;
|
|
|
2683
2695
|
createdAt: new Date(data.created_at)
|
|
2684
2696
|
};
|
|
2685
2697
|
}
|
|
2698
|
+
/**
|
|
2699
|
+
* Get details of a specific JIT MCP server instance.
|
|
2700
|
+
*
|
|
2701
|
+
* @param instanceId - The instance ID to retrieve
|
|
2702
|
+
* @returns Full instance details including endpoint URL
|
|
2703
|
+
*
|
|
2704
|
+
* @example
|
|
2705
|
+
* ```typescript
|
|
2706
|
+
* const instance = await wallet.getJitInstance('inst_abc123');
|
|
2707
|
+
* console.log('Endpoint:', instance.endpointUrl);
|
|
2708
|
+
* console.log('Expires:', instance.expiresAt);
|
|
2709
|
+
* ```
|
|
2710
|
+
*/
|
|
2711
|
+
async getJitInstance(instanceId) {
|
|
2712
|
+
this.logger.debug("getJitInstance", { instanceId });
|
|
2713
|
+
const authHeaders = await this.getSessionAuthHeaders();
|
|
2714
|
+
const response = await fetch(
|
|
2715
|
+
`${this.baseUrl}/api/v2/jit/instances/${instanceId}`,
|
|
2716
|
+
{ headers: authHeaders }
|
|
2717
|
+
);
|
|
2718
|
+
if (!response.ok) {
|
|
2719
|
+
const error = await response.json().catch(() => ({}));
|
|
2720
|
+
throw new MixrPayError(error.error || `Failed to get JIT instance: ${response.status}`);
|
|
2721
|
+
}
|
|
2722
|
+
const data = await response.json();
|
|
2723
|
+
return this.parseJitInstance(data.instance);
|
|
2724
|
+
}
|
|
2725
|
+
// ===========================================================================
|
|
2726
|
+
// Glama MCP Directory Methods
|
|
2727
|
+
// ===========================================================================
|
|
2728
|
+
/**
|
|
2729
|
+
* Search the Glama MCP server directory.
|
|
2730
|
+
*
|
|
2731
|
+
* Glama indexes 15,000+ MCP servers. Use this to discover tools
|
|
2732
|
+
* that can be deployed as JIT servers.
|
|
2733
|
+
*
|
|
2734
|
+
* Note: This is a public API and does not require authentication.
|
|
2735
|
+
*
|
|
2736
|
+
* @param query - Search query (e.g., "notion", "github", "database")
|
|
2737
|
+
* @returns Array of matching servers with hosting info
|
|
2738
|
+
*
|
|
2739
|
+
* @example
|
|
2740
|
+
* ```typescript
|
|
2741
|
+
* const results = await wallet.searchGlamaDirectory('notion');
|
|
2742
|
+
*
|
|
2743
|
+
* // Filter to only hostable servers
|
|
2744
|
+
* const hostable = results.servers.filter(s => s.canHost);
|
|
2745
|
+
* console.log(`Found ${hostable.length} deployable servers`);
|
|
2746
|
+
*
|
|
2747
|
+
* // Deploy one
|
|
2748
|
+
* if (hostable.length > 0) {
|
|
2749
|
+
* const server = hostable[0];
|
|
2750
|
+
* await wallet.deployJitMcp({
|
|
2751
|
+
* glamaId: server.id,
|
|
2752
|
+
* glamaNamespace: server.namespace,
|
|
2753
|
+
* glamaSlug: server.slug,
|
|
2754
|
+
* toolName: server.name,
|
|
2755
|
+
* envVars: { API_KEY: '...' },
|
|
2756
|
+
* });
|
|
2757
|
+
* }
|
|
2758
|
+
* ```
|
|
2759
|
+
*/
|
|
2760
|
+
async searchGlamaDirectory(query) {
|
|
2761
|
+
this.logger.debug("searchGlamaDirectory", { query });
|
|
2762
|
+
const params = new URLSearchParams({ q: query });
|
|
2763
|
+
const response = await fetch(`${this.baseUrl}/api/mcp/glama?${params}`);
|
|
2764
|
+
if (!response.ok) {
|
|
2765
|
+
const error = await response.json().catch(() => ({}));
|
|
2766
|
+
throw new MixrPayError(error.error || `Glama search failed: ${response.status}`);
|
|
2767
|
+
}
|
|
2768
|
+
const data = await response.json();
|
|
2769
|
+
return {
|
|
2770
|
+
servers: (data.servers || []).map((s) => this.parseGlamaServer(s)),
|
|
2771
|
+
pageInfo: data.pageInfo,
|
|
2772
|
+
query: data.query
|
|
2773
|
+
};
|
|
2774
|
+
}
|
|
2775
|
+
/**
|
|
2776
|
+
* Get featured/popular MCP servers from the Glama directory.
|
|
2777
|
+
*
|
|
2778
|
+
* Returns curated list of popular servers when you don't have
|
|
2779
|
+
* a specific search query.
|
|
2780
|
+
*
|
|
2781
|
+
* Note: This is a public API and does not require authentication.
|
|
2782
|
+
*
|
|
2783
|
+
* @returns Array of featured servers with hosting info
|
|
2784
|
+
*
|
|
2785
|
+
* @example
|
|
2786
|
+
* ```typescript
|
|
2787
|
+
* const { servers } = await wallet.getFeaturedGlamaServers();
|
|
2788
|
+
* console.log('Featured servers:', servers.map(s => s.name));
|
|
2789
|
+
* ```
|
|
2790
|
+
*/
|
|
2791
|
+
async getFeaturedGlamaServers() {
|
|
2792
|
+
this.logger.debug("getFeaturedGlamaServers");
|
|
2793
|
+
const response = await fetch(`${this.baseUrl}/api/mcp/glama`);
|
|
2794
|
+
if (!response.ok) {
|
|
2795
|
+
const error = await response.json().catch(() => ({}));
|
|
2796
|
+
throw new MixrPayError(error.error || `Failed to get featured servers: ${response.status}`);
|
|
2797
|
+
}
|
|
2798
|
+
const data = await response.json();
|
|
2799
|
+
return {
|
|
2800
|
+
servers: (data.servers || []).map((s) => this.parseGlamaServer(s)),
|
|
2801
|
+
featured: data.featured
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
/**
|
|
2805
|
+
* Parse Glama server response data.
|
|
2806
|
+
*/
|
|
2807
|
+
parseGlamaServer(data) {
|
|
2808
|
+
const importData = data.importData;
|
|
2809
|
+
return {
|
|
2810
|
+
id: data.id,
|
|
2811
|
+
name: data.name,
|
|
2812
|
+
namespace: data.namespace,
|
|
2813
|
+
slug: data.slug,
|
|
2814
|
+
description: data.description,
|
|
2815
|
+
url: data.url,
|
|
2816
|
+
attributes: data.attributes,
|
|
2817
|
+
canHost: data.canHost,
|
|
2818
|
+
tools: data.tools || [],
|
|
2819
|
+
repository: data.repository,
|
|
2820
|
+
license: data.spdxLicense?.name,
|
|
2821
|
+
importData: importData ? {
|
|
2822
|
+
glamaId: importData.glamaId,
|
|
2823
|
+
glamaNamespace: importData.glamaNamespace,
|
|
2824
|
+
glamaSlug: importData.glamaSlug,
|
|
2825
|
+
suggestedName: importData.suggestedName,
|
|
2826
|
+
suggestedDescription: importData.suggestedDescription,
|
|
2827
|
+
hostingType: importData.hostingType,
|
|
2828
|
+
requiredEnvVars: importData.requiredEnvVars,
|
|
2829
|
+
optionalEnvVars: importData.optionalEnvVars
|
|
2830
|
+
} : void 0
|
|
2831
|
+
};
|
|
2832
|
+
}
|
|
2686
2833
|
// ===========================================================================
|
|
2687
2834
|
// LLM Completion Methods
|
|
2688
2835
|
// ===========================================================================
|
package/dist/index.d.cts
CHANGED
|
@@ -31,9 +31,8 @@ interface AgentWalletConfig {
|
|
|
31
31
|
* Format: `sk_live_` (mainnet) or `sk_test_` (testnet) followed by 64 hex characters.
|
|
32
32
|
*
|
|
33
33
|
* Get session keys from:
|
|
34
|
-
* - The wallet owner
|
|
34
|
+
* - The wallet owner at https://mixrpay.com/manage/invites
|
|
35
35
|
* - Programmatically via the MixrPay API
|
|
36
|
-
* - The MixrPay widget session key management
|
|
37
36
|
*
|
|
38
37
|
* @example 'sk_live_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
39
38
|
*/
|
|
@@ -130,8 +129,14 @@ interface PaymentEvent {
|
|
|
130
129
|
* Information about a session key.
|
|
131
130
|
*/
|
|
132
131
|
interface SessionKeyInfo {
|
|
133
|
-
/** The session key's address (
|
|
132
|
+
/** The session key's derived address (used for signing requests) */
|
|
134
133
|
address: string;
|
|
134
|
+
/**
|
|
135
|
+
* The wallet address this session key is authorized to spend from.
|
|
136
|
+
* This is the human's funded wallet, NOT your agent's external wallet.
|
|
137
|
+
* All charges are deducted from this wallet.
|
|
138
|
+
*/
|
|
139
|
+
walletAddress: string | null;
|
|
135
140
|
/** Whether the session key is currently valid */
|
|
136
141
|
isValid: boolean;
|
|
137
142
|
/** Spending limits configured for this session key */
|
|
@@ -380,7 +385,7 @@ interface SessionStats {
|
|
|
380
385
|
*/
|
|
381
386
|
|
|
382
387
|
/** Current SDK version */
|
|
383
|
-
declare const SDK_VERSION = "0.8.
|
|
388
|
+
declare const SDK_VERSION = "0.8.7";
|
|
384
389
|
/** Supported networks */
|
|
385
390
|
declare const NETWORKS: {
|
|
386
391
|
readonly BASE_MAINNET: {
|
|
@@ -890,7 +895,7 @@ declare class AgentWallet {
|
|
|
890
895
|
*
|
|
891
896
|
* @example
|
|
892
897
|
* ```typescript
|
|
893
|
-
* // Human creates invite at
|
|
898
|
+
* // Human creates invite at https://mixrpay.com/manage/invites, shares code "mixr-abc123"
|
|
894
899
|
*
|
|
895
900
|
* const result = await AgentWallet.claimInvite({
|
|
896
901
|
* inviteCode: 'mixr-abc123',
|
|
@@ -983,6 +988,14 @@ declare class AgentWallet {
|
|
|
983
988
|
* ```
|
|
984
989
|
*/
|
|
985
990
|
getChildSessions(): Promise<ChildSession[]>;
|
|
991
|
+
/**
|
|
992
|
+
* List child sessions spawned by this agent.
|
|
993
|
+
*
|
|
994
|
+
* Alias for `getChildSessions()` for naming consistency.
|
|
995
|
+
*
|
|
996
|
+
* @returns Array of child session info
|
|
997
|
+
*/
|
|
998
|
+
listChildSessions(): Promise<ChildSession[]>;
|
|
986
999
|
/**
|
|
987
1000
|
* Make an HTTP request, automatically handling x402 payment if required.
|
|
988
1001
|
*
|
|
@@ -1432,6 +1445,74 @@ declare class AgentWallet {
|
|
|
1432
1445
|
* Parse JIT instance response data.
|
|
1433
1446
|
*/
|
|
1434
1447
|
private parseJitInstance;
|
|
1448
|
+
/**
|
|
1449
|
+
* Get details of a specific JIT MCP server instance.
|
|
1450
|
+
*
|
|
1451
|
+
* @param instanceId - The instance ID to retrieve
|
|
1452
|
+
* @returns Full instance details including endpoint URL
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* const instance = await wallet.getJitInstance('inst_abc123');
|
|
1457
|
+
* console.log('Endpoint:', instance.endpointUrl);
|
|
1458
|
+
* console.log('Expires:', instance.expiresAt);
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
getJitInstance(instanceId: string): Promise<JitInstance>;
|
|
1462
|
+
/**
|
|
1463
|
+
* Search the Glama MCP server directory.
|
|
1464
|
+
*
|
|
1465
|
+
* Glama indexes 15,000+ MCP servers. Use this to discover tools
|
|
1466
|
+
* that can be deployed as JIT servers.
|
|
1467
|
+
*
|
|
1468
|
+
* Note: This is a public API and does not require authentication.
|
|
1469
|
+
*
|
|
1470
|
+
* @param query - Search query (e.g., "notion", "github", "database")
|
|
1471
|
+
* @returns Array of matching servers with hosting info
|
|
1472
|
+
*
|
|
1473
|
+
* @example
|
|
1474
|
+
* ```typescript
|
|
1475
|
+
* const results = await wallet.searchGlamaDirectory('notion');
|
|
1476
|
+
*
|
|
1477
|
+
* // Filter to only hostable servers
|
|
1478
|
+
* const hostable = results.servers.filter(s => s.canHost);
|
|
1479
|
+
* console.log(`Found ${hostable.length} deployable servers`);
|
|
1480
|
+
*
|
|
1481
|
+
* // Deploy one
|
|
1482
|
+
* if (hostable.length > 0) {
|
|
1483
|
+
* const server = hostable[0];
|
|
1484
|
+
* await wallet.deployJitMcp({
|
|
1485
|
+
* glamaId: server.id,
|
|
1486
|
+
* glamaNamespace: server.namespace,
|
|
1487
|
+
* glamaSlug: server.slug,
|
|
1488
|
+
* toolName: server.name,
|
|
1489
|
+
* envVars: { API_KEY: '...' },
|
|
1490
|
+
* });
|
|
1491
|
+
* }
|
|
1492
|
+
* ```
|
|
1493
|
+
*/
|
|
1494
|
+
searchGlamaDirectory(query: string): Promise<GlamaSearchResult>;
|
|
1495
|
+
/**
|
|
1496
|
+
* Get featured/popular MCP servers from the Glama directory.
|
|
1497
|
+
*
|
|
1498
|
+
* Returns curated list of popular servers when you don't have
|
|
1499
|
+
* a specific search query.
|
|
1500
|
+
*
|
|
1501
|
+
* Note: This is a public API and does not require authentication.
|
|
1502
|
+
*
|
|
1503
|
+
* @returns Array of featured servers with hosting info
|
|
1504
|
+
*
|
|
1505
|
+
* @example
|
|
1506
|
+
* ```typescript
|
|
1507
|
+
* const { servers } = await wallet.getFeaturedGlamaServers();
|
|
1508
|
+
* console.log('Featured servers:', servers.map(s => s.name));
|
|
1509
|
+
* ```
|
|
1510
|
+
*/
|
|
1511
|
+
getFeaturedGlamaServers(): Promise<GlamaSearchResult>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Parse Glama server response data.
|
|
1514
|
+
*/
|
|
1515
|
+
private parseGlamaServer;
|
|
1435
1516
|
/**
|
|
1436
1517
|
* Simple LLM completion - single-turn, no tools.
|
|
1437
1518
|
*
|
|
@@ -2228,6 +2309,77 @@ interface JitInstance {
|
|
|
2228
2309
|
/** Creation time */
|
|
2229
2310
|
createdAt: Date;
|
|
2230
2311
|
}
|
|
2312
|
+
/**
|
|
2313
|
+
* MCP server from the Glama directory
|
|
2314
|
+
*/
|
|
2315
|
+
interface GlamaServer {
|
|
2316
|
+
/** Glama server ID */
|
|
2317
|
+
id: string;
|
|
2318
|
+
/** Server name */
|
|
2319
|
+
name: string;
|
|
2320
|
+
/** Namespace (e.g., "anthropics", "notion") */
|
|
2321
|
+
namespace: string;
|
|
2322
|
+
/** URL slug */
|
|
2323
|
+
slug: string;
|
|
2324
|
+
/** Server description */
|
|
2325
|
+
description: string;
|
|
2326
|
+
/** Glama URL */
|
|
2327
|
+
url: string;
|
|
2328
|
+
/** Server attributes (e.g., ["hosting:remote-capable", "author:official"]) */
|
|
2329
|
+
attributes: string[];
|
|
2330
|
+
/** Whether this server can be hosted as a JIT instance */
|
|
2331
|
+
canHost: boolean;
|
|
2332
|
+
/** Available tools */
|
|
2333
|
+
tools: Array<{
|
|
2334
|
+
name: string;
|
|
2335
|
+
description?: string;
|
|
2336
|
+
}>;
|
|
2337
|
+
/** Repository info */
|
|
2338
|
+
repository?: {
|
|
2339
|
+
url: string;
|
|
2340
|
+
};
|
|
2341
|
+
/** License name */
|
|
2342
|
+
license?: string;
|
|
2343
|
+
/** Import data for deploying as JIT server */
|
|
2344
|
+
importData?: GlamaImportData;
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* Import data for deploying a Glama server as JIT
|
|
2348
|
+
*/
|
|
2349
|
+
interface GlamaImportData {
|
|
2350
|
+
/** Glama server ID */
|
|
2351
|
+
glamaId: string;
|
|
2352
|
+
/** Namespace */
|
|
2353
|
+
glamaNamespace: string;
|
|
2354
|
+
/** Slug */
|
|
2355
|
+
glamaSlug: string;
|
|
2356
|
+
/** Suggested display name */
|
|
2357
|
+
suggestedName: string;
|
|
2358
|
+
/** Suggested description */
|
|
2359
|
+
suggestedDescription: string;
|
|
2360
|
+
/** Hosting type */
|
|
2361
|
+
hostingType: 'local' | 'remote' | 'hybrid';
|
|
2362
|
+
/** Required environment variables (API keys) */
|
|
2363
|
+
requiredEnvVars: string[];
|
|
2364
|
+
/** Optional environment variables */
|
|
2365
|
+
optionalEnvVars: string[];
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Result from searching the Glama directory
|
|
2369
|
+
*/
|
|
2370
|
+
interface GlamaSearchResult {
|
|
2371
|
+
/** Matching servers */
|
|
2372
|
+
servers: GlamaServer[];
|
|
2373
|
+
/** Pagination info */
|
|
2374
|
+
pageInfo?: {
|
|
2375
|
+
hasNextPage: boolean;
|
|
2376
|
+
endCursor?: string;
|
|
2377
|
+
};
|
|
2378
|
+
/** Original query (for search results) */
|
|
2379
|
+
query?: string;
|
|
2380
|
+
/** Whether these are featured servers */
|
|
2381
|
+
featured?: boolean;
|
|
2382
|
+
}
|
|
2231
2383
|
/**
|
|
2232
2384
|
* Options for simple LLM completion
|
|
2233
2385
|
*/
|
|
@@ -2618,7 +2770,7 @@ declare class PaymentFailedError extends MixrPayError {
|
|
|
2618
2770
|
* catch (error) {
|
|
2619
2771
|
* if (error instanceof InvalidSessionKeyError) {
|
|
2620
2772
|
* console.log(`Invalid key: ${error.reason}`);
|
|
2621
|
-
* console.log('Get a valid session key from
|
|
2773
|
+
* console.log('Get a valid session key from https://mixrpay.com/manage/invites');
|
|
2622
2774
|
* }
|
|
2623
2775
|
* }
|
|
2624
2776
|
* ```
|
|
@@ -2836,4 +2988,4 @@ declare function isMixrPayError(error: unknown): error is MixrPayError;
|
|
|
2836
2988
|
*/
|
|
2837
2989
|
declare function getErrorMessage(error: unknown): string;
|
|
2838
2990
|
|
|
2839
|
-
export { type AgentClaimInviteOptions, type AgentClaimInviteResult, type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type AvailableBudget, type CallMerchantApiOptions, type ChargeResult, type ChildSession, type CompleteOptions, type CompleteResult, type DeployJitMcpOptions, type DeployJitMcpResult, type DiagnosticsResult, InsufficientBalanceError, InvalidSessionKeyError, type JitInstance, MerchantNotAllowedError, MixrPayError, type PaymentEvent, PaymentFailedError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, type SessionKeyInfo, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, type SpawnChildOptions, type SpawnChildResult, SpendingLimitExceededError, type SpendingStats, X402ProtocolError, getErrorMessage, isMixrPayError };
|
|
2991
|
+
export { type AgentClaimInviteOptions, type AgentClaimInviteResult, type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type AvailableBudget, type CallMerchantApiOptions, type ChargeResult, type ChildSession, type CompleteOptions, type CompleteResult, type DeployJitMcpOptions, type DeployJitMcpResult, type DiagnosticsResult, type GlamaImportData, type GlamaSearchResult, type GlamaServer, InsufficientBalanceError, InvalidSessionKeyError, type JitInstance, MerchantNotAllowedError, MixrPayError, type PaymentEvent, PaymentFailedError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, type SessionKeyInfo, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, type SpawnChildOptions, type SpawnChildResult, SpendingLimitExceededError, type SpendingStats, X402ProtocolError, getErrorMessage, isMixrPayError };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,9 +31,8 @@ interface AgentWalletConfig {
|
|
|
31
31
|
* Format: `sk_live_` (mainnet) or `sk_test_` (testnet) followed by 64 hex characters.
|
|
32
32
|
*
|
|
33
33
|
* Get session keys from:
|
|
34
|
-
* - The wallet owner
|
|
34
|
+
* - The wallet owner at https://mixrpay.com/manage/invites
|
|
35
35
|
* - Programmatically via the MixrPay API
|
|
36
|
-
* - The MixrPay widget session key management
|
|
37
36
|
*
|
|
38
37
|
* @example 'sk_live_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
39
38
|
*/
|
|
@@ -130,8 +129,14 @@ interface PaymentEvent {
|
|
|
130
129
|
* Information about a session key.
|
|
131
130
|
*/
|
|
132
131
|
interface SessionKeyInfo {
|
|
133
|
-
/** The session key's address (
|
|
132
|
+
/** The session key's derived address (used for signing requests) */
|
|
134
133
|
address: string;
|
|
134
|
+
/**
|
|
135
|
+
* The wallet address this session key is authorized to spend from.
|
|
136
|
+
* This is the human's funded wallet, NOT your agent's external wallet.
|
|
137
|
+
* All charges are deducted from this wallet.
|
|
138
|
+
*/
|
|
139
|
+
walletAddress: string | null;
|
|
135
140
|
/** Whether the session key is currently valid */
|
|
136
141
|
isValid: boolean;
|
|
137
142
|
/** Spending limits configured for this session key */
|
|
@@ -380,7 +385,7 @@ interface SessionStats {
|
|
|
380
385
|
*/
|
|
381
386
|
|
|
382
387
|
/** Current SDK version */
|
|
383
|
-
declare const SDK_VERSION = "0.8.
|
|
388
|
+
declare const SDK_VERSION = "0.8.7";
|
|
384
389
|
/** Supported networks */
|
|
385
390
|
declare const NETWORKS: {
|
|
386
391
|
readonly BASE_MAINNET: {
|
|
@@ -890,7 +895,7 @@ declare class AgentWallet {
|
|
|
890
895
|
*
|
|
891
896
|
* @example
|
|
892
897
|
* ```typescript
|
|
893
|
-
* // Human creates invite at
|
|
898
|
+
* // Human creates invite at https://mixrpay.com/manage/invites, shares code "mixr-abc123"
|
|
894
899
|
*
|
|
895
900
|
* const result = await AgentWallet.claimInvite({
|
|
896
901
|
* inviteCode: 'mixr-abc123',
|
|
@@ -983,6 +988,14 @@ declare class AgentWallet {
|
|
|
983
988
|
* ```
|
|
984
989
|
*/
|
|
985
990
|
getChildSessions(): Promise<ChildSession[]>;
|
|
991
|
+
/**
|
|
992
|
+
* List child sessions spawned by this agent.
|
|
993
|
+
*
|
|
994
|
+
* Alias for `getChildSessions()` for naming consistency.
|
|
995
|
+
*
|
|
996
|
+
* @returns Array of child session info
|
|
997
|
+
*/
|
|
998
|
+
listChildSessions(): Promise<ChildSession[]>;
|
|
986
999
|
/**
|
|
987
1000
|
* Make an HTTP request, automatically handling x402 payment if required.
|
|
988
1001
|
*
|
|
@@ -1432,6 +1445,74 @@ declare class AgentWallet {
|
|
|
1432
1445
|
* Parse JIT instance response data.
|
|
1433
1446
|
*/
|
|
1434
1447
|
private parseJitInstance;
|
|
1448
|
+
/**
|
|
1449
|
+
* Get details of a specific JIT MCP server instance.
|
|
1450
|
+
*
|
|
1451
|
+
* @param instanceId - The instance ID to retrieve
|
|
1452
|
+
* @returns Full instance details including endpoint URL
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* const instance = await wallet.getJitInstance('inst_abc123');
|
|
1457
|
+
* console.log('Endpoint:', instance.endpointUrl);
|
|
1458
|
+
* console.log('Expires:', instance.expiresAt);
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
getJitInstance(instanceId: string): Promise<JitInstance>;
|
|
1462
|
+
/**
|
|
1463
|
+
* Search the Glama MCP server directory.
|
|
1464
|
+
*
|
|
1465
|
+
* Glama indexes 15,000+ MCP servers. Use this to discover tools
|
|
1466
|
+
* that can be deployed as JIT servers.
|
|
1467
|
+
*
|
|
1468
|
+
* Note: This is a public API and does not require authentication.
|
|
1469
|
+
*
|
|
1470
|
+
* @param query - Search query (e.g., "notion", "github", "database")
|
|
1471
|
+
* @returns Array of matching servers with hosting info
|
|
1472
|
+
*
|
|
1473
|
+
* @example
|
|
1474
|
+
* ```typescript
|
|
1475
|
+
* const results = await wallet.searchGlamaDirectory('notion');
|
|
1476
|
+
*
|
|
1477
|
+
* // Filter to only hostable servers
|
|
1478
|
+
* const hostable = results.servers.filter(s => s.canHost);
|
|
1479
|
+
* console.log(`Found ${hostable.length} deployable servers`);
|
|
1480
|
+
*
|
|
1481
|
+
* // Deploy one
|
|
1482
|
+
* if (hostable.length > 0) {
|
|
1483
|
+
* const server = hostable[0];
|
|
1484
|
+
* await wallet.deployJitMcp({
|
|
1485
|
+
* glamaId: server.id,
|
|
1486
|
+
* glamaNamespace: server.namespace,
|
|
1487
|
+
* glamaSlug: server.slug,
|
|
1488
|
+
* toolName: server.name,
|
|
1489
|
+
* envVars: { API_KEY: '...' },
|
|
1490
|
+
* });
|
|
1491
|
+
* }
|
|
1492
|
+
* ```
|
|
1493
|
+
*/
|
|
1494
|
+
searchGlamaDirectory(query: string): Promise<GlamaSearchResult>;
|
|
1495
|
+
/**
|
|
1496
|
+
* Get featured/popular MCP servers from the Glama directory.
|
|
1497
|
+
*
|
|
1498
|
+
* Returns curated list of popular servers when you don't have
|
|
1499
|
+
* a specific search query.
|
|
1500
|
+
*
|
|
1501
|
+
* Note: This is a public API and does not require authentication.
|
|
1502
|
+
*
|
|
1503
|
+
* @returns Array of featured servers with hosting info
|
|
1504
|
+
*
|
|
1505
|
+
* @example
|
|
1506
|
+
* ```typescript
|
|
1507
|
+
* const { servers } = await wallet.getFeaturedGlamaServers();
|
|
1508
|
+
* console.log('Featured servers:', servers.map(s => s.name));
|
|
1509
|
+
* ```
|
|
1510
|
+
*/
|
|
1511
|
+
getFeaturedGlamaServers(): Promise<GlamaSearchResult>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Parse Glama server response data.
|
|
1514
|
+
*/
|
|
1515
|
+
private parseGlamaServer;
|
|
1435
1516
|
/**
|
|
1436
1517
|
* Simple LLM completion - single-turn, no tools.
|
|
1437
1518
|
*
|
|
@@ -2228,6 +2309,77 @@ interface JitInstance {
|
|
|
2228
2309
|
/** Creation time */
|
|
2229
2310
|
createdAt: Date;
|
|
2230
2311
|
}
|
|
2312
|
+
/**
|
|
2313
|
+
* MCP server from the Glama directory
|
|
2314
|
+
*/
|
|
2315
|
+
interface GlamaServer {
|
|
2316
|
+
/** Glama server ID */
|
|
2317
|
+
id: string;
|
|
2318
|
+
/** Server name */
|
|
2319
|
+
name: string;
|
|
2320
|
+
/** Namespace (e.g., "anthropics", "notion") */
|
|
2321
|
+
namespace: string;
|
|
2322
|
+
/** URL slug */
|
|
2323
|
+
slug: string;
|
|
2324
|
+
/** Server description */
|
|
2325
|
+
description: string;
|
|
2326
|
+
/** Glama URL */
|
|
2327
|
+
url: string;
|
|
2328
|
+
/** Server attributes (e.g., ["hosting:remote-capable", "author:official"]) */
|
|
2329
|
+
attributes: string[];
|
|
2330
|
+
/** Whether this server can be hosted as a JIT instance */
|
|
2331
|
+
canHost: boolean;
|
|
2332
|
+
/** Available tools */
|
|
2333
|
+
tools: Array<{
|
|
2334
|
+
name: string;
|
|
2335
|
+
description?: string;
|
|
2336
|
+
}>;
|
|
2337
|
+
/** Repository info */
|
|
2338
|
+
repository?: {
|
|
2339
|
+
url: string;
|
|
2340
|
+
};
|
|
2341
|
+
/** License name */
|
|
2342
|
+
license?: string;
|
|
2343
|
+
/** Import data for deploying as JIT server */
|
|
2344
|
+
importData?: GlamaImportData;
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* Import data for deploying a Glama server as JIT
|
|
2348
|
+
*/
|
|
2349
|
+
interface GlamaImportData {
|
|
2350
|
+
/** Glama server ID */
|
|
2351
|
+
glamaId: string;
|
|
2352
|
+
/** Namespace */
|
|
2353
|
+
glamaNamespace: string;
|
|
2354
|
+
/** Slug */
|
|
2355
|
+
glamaSlug: string;
|
|
2356
|
+
/** Suggested display name */
|
|
2357
|
+
suggestedName: string;
|
|
2358
|
+
/** Suggested description */
|
|
2359
|
+
suggestedDescription: string;
|
|
2360
|
+
/** Hosting type */
|
|
2361
|
+
hostingType: 'local' | 'remote' | 'hybrid';
|
|
2362
|
+
/** Required environment variables (API keys) */
|
|
2363
|
+
requiredEnvVars: string[];
|
|
2364
|
+
/** Optional environment variables */
|
|
2365
|
+
optionalEnvVars: string[];
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Result from searching the Glama directory
|
|
2369
|
+
*/
|
|
2370
|
+
interface GlamaSearchResult {
|
|
2371
|
+
/** Matching servers */
|
|
2372
|
+
servers: GlamaServer[];
|
|
2373
|
+
/** Pagination info */
|
|
2374
|
+
pageInfo?: {
|
|
2375
|
+
hasNextPage: boolean;
|
|
2376
|
+
endCursor?: string;
|
|
2377
|
+
};
|
|
2378
|
+
/** Original query (for search results) */
|
|
2379
|
+
query?: string;
|
|
2380
|
+
/** Whether these are featured servers */
|
|
2381
|
+
featured?: boolean;
|
|
2382
|
+
}
|
|
2231
2383
|
/**
|
|
2232
2384
|
* Options for simple LLM completion
|
|
2233
2385
|
*/
|
|
@@ -2618,7 +2770,7 @@ declare class PaymentFailedError extends MixrPayError {
|
|
|
2618
2770
|
* catch (error) {
|
|
2619
2771
|
* if (error instanceof InvalidSessionKeyError) {
|
|
2620
2772
|
* console.log(`Invalid key: ${error.reason}`);
|
|
2621
|
-
* console.log('Get a valid session key from
|
|
2773
|
+
* console.log('Get a valid session key from https://mixrpay.com/manage/invites');
|
|
2622
2774
|
* }
|
|
2623
2775
|
* }
|
|
2624
2776
|
* ```
|
|
@@ -2836,4 +2988,4 @@ declare function isMixrPayError(error: unknown): error is MixrPayError;
|
|
|
2836
2988
|
*/
|
|
2837
2989
|
declare function getErrorMessage(error: unknown): string;
|
|
2838
2990
|
|
|
2839
|
-
export { type AgentClaimInviteOptions, type AgentClaimInviteResult, type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type AvailableBudget, type CallMerchantApiOptions, type ChargeResult, type ChildSession, type CompleteOptions, type CompleteResult, type DeployJitMcpOptions, type DeployJitMcpResult, type DiagnosticsResult, InsufficientBalanceError, InvalidSessionKeyError, type JitInstance, MerchantNotAllowedError, MixrPayError, type PaymentEvent, PaymentFailedError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, type SessionKeyInfo, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, type SpawnChildOptions, type SpawnChildResult, SpendingLimitExceededError, type SpendingStats, X402ProtocolError, getErrorMessage, isMixrPayError };
|
|
2991
|
+
export { type AgentClaimInviteOptions, type AgentClaimInviteResult, type AgentMessage, type AgentRunConfig, type AgentRunEvent, type AgentRunOptions, type AgentRunResult, type AgentRunStatusResult, AgentWallet, type AgentWalletConfig, type AvailableBudget, type CallMerchantApiOptions, type ChargeResult, type ChildSession, type CompleteOptions, type CompleteResult, type DeployJitMcpOptions, type DeployJitMcpResult, type DiagnosticsResult, type GlamaImportData, type GlamaSearchResult, type GlamaServer, InsufficientBalanceError, InvalidSessionKeyError, type JitInstance, MerchantNotAllowedError, MixrPayError, type PaymentEvent, PaymentFailedError, SDK_VERSION, type SessionAuthorization, SessionExpiredError, SessionKeyExpiredError, type SessionKeyInfo, SessionLimitExceededError, SessionNotFoundError, SessionRevokedError, type SessionStats, type SpawnChildOptions, type SpawnChildResult, SpendingLimitExceededError, type SpendingStats, X402ProtocolError, getErrorMessage, isMixrPayError };
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,7 @@ var InsufficientBalanceError = class extends MixrPayError {
|
|
|
63
63
|
this.name = "InsufficientBalanceError";
|
|
64
64
|
this.required = required;
|
|
65
65
|
this.available = available;
|
|
66
|
-
this.topUpUrl = "/wallet";
|
|
66
|
+
this.topUpUrl = "https://mixrpay.com/manage/wallet";
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
var SessionKeyExpiredError = class extends MixrPayError {
|
|
@@ -71,7 +71,7 @@ var SessionKeyExpiredError = class extends MixrPayError {
|
|
|
71
71
|
expiredAt;
|
|
72
72
|
constructor(expiredAt) {
|
|
73
73
|
super(
|
|
74
|
-
`Session key expired at ${expiredAt}. Request a new session key from the wallet owner
|
|
74
|
+
`Session key expired at ${expiredAt}. Request a new session key from the wallet owner at https://mixrpay.com/manage/invites`,
|
|
75
75
|
"SESSION_KEY_EXPIRED"
|
|
76
76
|
);
|
|
77
77
|
this.name = "SessionKeyExpiredError";
|
|
@@ -140,7 +140,7 @@ var InvalidSessionKeyError = class extends MixrPayError {
|
|
|
140
140
|
reason;
|
|
141
141
|
constructor(reason = "Invalid session key format") {
|
|
142
142
|
super(
|
|
143
|
-
`${reason}. Session keys should be in format: sk_live_<64 hex chars> or sk_test_<64 hex chars>. Get one from
|
|
143
|
+
`${reason}. Session keys should be in format: sk_live_<64 hex chars> or sk_test_<64 hex chars>. Get one from https://mixrpay.com/manage/invites`,
|
|
144
144
|
"INVALID_SESSION_KEY"
|
|
145
145
|
);
|
|
146
146
|
this.name = "InvalidSessionKeyError";
|
|
@@ -495,7 +495,7 @@ function getAmountUsd(requirements) {
|
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
// src/agent-wallet.ts
|
|
498
|
-
var SDK_VERSION = "0.8.
|
|
498
|
+
var SDK_VERSION = "0.8.7";
|
|
499
499
|
var DEFAULT_BASE_URL = process.env.MIXRPAY_BASE_URL || "https://www.mixrpay.com";
|
|
500
500
|
var DEFAULT_TIMEOUT = 3e4;
|
|
501
501
|
var NETWORKS = {
|
|
@@ -611,7 +611,7 @@ var AgentWallet = class {
|
|
|
611
611
|
validateConfig(config) {
|
|
612
612
|
if (!config.sessionKey) {
|
|
613
613
|
throw new InvalidSessionKeyError(
|
|
614
|
-
"Session key is required. Get one from the wallet owner
|
|
614
|
+
"Session key is required. Get one from the wallet owner at https://mixrpay.com/manage/invites"
|
|
615
615
|
);
|
|
616
616
|
}
|
|
617
617
|
const key = config.sessionKey.trim();
|
|
@@ -1124,7 +1124,7 @@ var AgentWallet = class {
|
|
|
1124
1124
|
*
|
|
1125
1125
|
* @example
|
|
1126
1126
|
* ```typescript
|
|
1127
|
-
* // Human creates invite at
|
|
1127
|
+
* // Human creates invite at https://mixrpay.com/manage/invites, shares code "mixr-abc123"
|
|
1128
1128
|
*
|
|
1129
1129
|
* const result = await AgentWallet.claimInvite({
|
|
1130
1130
|
* inviteCode: 'mixr-abc123',
|
|
@@ -1350,6 +1350,16 @@ var AgentWallet = class {
|
|
|
1350
1350
|
const data = await response.json();
|
|
1351
1351
|
return data.children || [];
|
|
1352
1352
|
}
|
|
1353
|
+
/**
|
|
1354
|
+
* List child sessions spawned by this agent.
|
|
1355
|
+
*
|
|
1356
|
+
* Alias for `getChildSessions()` for naming consistency.
|
|
1357
|
+
*
|
|
1358
|
+
* @returns Array of child session info
|
|
1359
|
+
*/
|
|
1360
|
+
async listChildSessions() {
|
|
1361
|
+
return this.getChildSessions();
|
|
1362
|
+
}
|
|
1353
1363
|
// ===========================================================================
|
|
1354
1364
|
// Core Methods
|
|
1355
1365
|
// ===========================================================================
|
|
@@ -1660,6 +1670,7 @@ var AgentWallet = class {
|
|
|
1660
1670
|
const data = await response.json();
|
|
1661
1671
|
this.sessionKeyInfo = {
|
|
1662
1672
|
address: this.sessionKey.address,
|
|
1673
|
+
walletAddress: data.wallet_address ?? data.walletAddress ?? null,
|
|
1663
1674
|
isValid: data.is_valid ?? data.isValid ?? true,
|
|
1664
1675
|
limits: {
|
|
1665
1676
|
perTxUsd: data.per_tx_limit_usd ?? data.perTxLimitUsd ?? null,
|
|
@@ -1684,6 +1695,7 @@ var AgentWallet = class {
|
|
|
1684
1695
|
}
|
|
1685
1696
|
return {
|
|
1686
1697
|
address: this.sessionKey.address,
|
|
1698
|
+
walletAddress: null,
|
|
1687
1699
|
isValid: true,
|
|
1688
1700
|
limits: { perTxUsd: null, dailyUsd: null, totalUsd: null },
|
|
1689
1701
|
usage: { todayUsd: this.totalSpentUsd, totalUsd: this.totalSpentUsd, txCount: this.payments.length },
|
|
@@ -1803,7 +1815,7 @@ var AgentWallet = class {
|
|
|
1803
1815
|
checks.sessionKeyValid = info.isValid;
|
|
1804
1816
|
if (!info.isValid) {
|
|
1805
1817
|
issues.push("Session key is invalid or has been revoked.");
|
|
1806
|
-
recommendations.push("Request a new session key from the wallet owner
|
|
1818
|
+
recommendations.push("Request a new session key from the wallet owner at https://mixrpay.com/manage/invites");
|
|
1807
1819
|
}
|
|
1808
1820
|
const now = /* @__PURE__ */ new Date();
|
|
1809
1821
|
let expiresInHours = null;
|
|
@@ -1843,7 +1855,7 @@ var AgentWallet = class {
|
|
|
1843
1855
|
balance = await this.getBalance();
|
|
1844
1856
|
checks.hasBalance = balance > 0;
|
|
1845
1857
|
if (balance <= 0) {
|
|
1846
|
-
issues.push("Wallet has no USDC balance. Top up at
|
|
1858
|
+
issues.push("Wallet has no USDC balance. Top up at https://mixrpay.com/manage/wallet");
|
|
1847
1859
|
recommendations.push("Deposit USDC to your wallet address to enable payments.");
|
|
1848
1860
|
} else if (balance < 1) {
|
|
1849
1861
|
issues.push(`Low balance: $${balance.toFixed(2)}. Consider topping up.`);
|
|
@@ -2646,6 +2658,141 @@ Timestamp: ${timestamp}`;
|
|
|
2646
2658
|
createdAt: new Date(data.created_at)
|
|
2647
2659
|
};
|
|
2648
2660
|
}
|
|
2661
|
+
/**
|
|
2662
|
+
* Get details of a specific JIT MCP server instance.
|
|
2663
|
+
*
|
|
2664
|
+
* @param instanceId - The instance ID to retrieve
|
|
2665
|
+
* @returns Full instance details including endpoint URL
|
|
2666
|
+
*
|
|
2667
|
+
* @example
|
|
2668
|
+
* ```typescript
|
|
2669
|
+
* const instance = await wallet.getJitInstance('inst_abc123');
|
|
2670
|
+
* console.log('Endpoint:', instance.endpointUrl);
|
|
2671
|
+
* console.log('Expires:', instance.expiresAt);
|
|
2672
|
+
* ```
|
|
2673
|
+
*/
|
|
2674
|
+
async getJitInstance(instanceId) {
|
|
2675
|
+
this.logger.debug("getJitInstance", { instanceId });
|
|
2676
|
+
const authHeaders = await this.getSessionAuthHeaders();
|
|
2677
|
+
const response = await fetch(
|
|
2678
|
+
`${this.baseUrl}/api/v2/jit/instances/${instanceId}`,
|
|
2679
|
+
{ headers: authHeaders }
|
|
2680
|
+
);
|
|
2681
|
+
if (!response.ok) {
|
|
2682
|
+
const error = await response.json().catch(() => ({}));
|
|
2683
|
+
throw new MixrPayError(error.error || `Failed to get JIT instance: ${response.status}`);
|
|
2684
|
+
}
|
|
2685
|
+
const data = await response.json();
|
|
2686
|
+
return this.parseJitInstance(data.instance);
|
|
2687
|
+
}
|
|
2688
|
+
// ===========================================================================
|
|
2689
|
+
// Glama MCP Directory Methods
|
|
2690
|
+
// ===========================================================================
|
|
2691
|
+
/**
|
|
2692
|
+
* Search the Glama MCP server directory.
|
|
2693
|
+
*
|
|
2694
|
+
* Glama indexes 15,000+ MCP servers. Use this to discover tools
|
|
2695
|
+
* that can be deployed as JIT servers.
|
|
2696
|
+
*
|
|
2697
|
+
* Note: This is a public API and does not require authentication.
|
|
2698
|
+
*
|
|
2699
|
+
* @param query - Search query (e.g., "notion", "github", "database")
|
|
2700
|
+
* @returns Array of matching servers with hosting info
|
|
2701
|
+
*
|
|
2702
|
+
* @example
|
|
2703
|
+
* ```typescript
|
|
2704
|
+
* const results = await wallet.searchGlamaDirectory('notion');
|
|
2705
|
+
*
|
|
2706
|
+
* // Filter to only hostable servers
|
|
2707
|
+
* const hostable = results.servers.filter(s => s.canHost);
|
|
2708
|
+
* console.log(`Found ${hostable.length} deployable servers`);
|
|
2709
|
+
*
|
|
2710
|
+
* // Deploy one
|
|
2711
|
+
* if (hostable.length > 0) {
|
|
2712
|
+
* const server = hostable[0];
|
|
2713
|
+
* await wallet.deployJitMcp({
|
|
2714
|
+
* glamaId: server.id,
|
|
2715
|
+
* glamaNamespace: server.namespace,
|
|
2716
|
+
* glamaSlug: server.slug,
|
|
2717
|
+
* toolName: server.name,
|
|
2718
|
+
* envVars: { API_KEY: '...' },
|
|
2719
|
+
* });
|
|
2720
|
+
* }
|
|
2721
|
+
* ```
|
|
2722
|
+
*/
|
|
2723
|
+
async searchGlamaDirectory(query) {
|
|
2724
|
+
this.logger.debug("searchGlamaDirectory", { query });
|
|
2725
|
+
const params = new URLSearchParams({ q: query });
|
|
2726
|
+
const response = await fetch(`${this.baseUrl}/api/mcp/glama?${params}`);
|
|
2727
|
+
if (!response.ok) {
|
|
2728
|
+
const error = await response.json().catch(() => ({}));
|
|
2729
|
+
throw new MixrPayError(error.error || `Glama search failed: ${response.status}`);
|
|
2730
|
+
}
|
|
2731
|
+
const data = await response.json();
|
|
2732
|
+
return {
|
|
2733
|
+
servers: (data.servers || []).map((s) => this.parseGlamaServer(s)),
|
|
2734
|
+
pageInfo: data.pageInfo,
|
|
2735
|
+
query: data.query
|
|
2736
|
+
};
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Get featured/popular MCP servers from the Glama directory.
|
|
2740
|
+
*
|
|
2741
|
+
* Returns curated list of popular servers when you don't have
|
|
2742
|
+
* a specific search query.
|
|
2743
|
+
*
|
|
2744
|
+
* Note: This is a public API and does not require authentication.
|
|
2745
|
+
*
|
|
2746
|
+
* @returns Array of featured servers with hosting info
|
|
2747
|
+
*
|
|
2748
|
+
* @example
|
|
2749
|
+
* ```typescript
|
|
2750
|
+
* const { servers } = await wallet.getFeaturedGlamaServers();
|
|
2751
|
+
* console.log('Featured servers:', servers.map(s => s.name));
|
|
2752
|
+
* ```
|
|
2753
|
+
*/
|
|
2754
|
+
async getFeaturedGlamaServers() {
|
|
2755
|
+
this.logger.debug("getFeaturedGlamaServers");
|
|
2756
|
+
const response = await fetch(`${this.baseUrl}/api/mcp/glama`);
|
|
2757
|
+
if (!response.ok) {
|
|
2758
|
+
const error = await response.json().catch(() => ({}));
|
|
2759
|
+
throw new MixrPayError(error.error || `Failed to get featured servers: ${response.status}`);
|
|
2760
|
+
}
|
|
2761
|
+
const data = await response.json();
|
|
2762
|
+
return {
|
|
2763
|
+
servers: (data.servers || []).map((s) => this.parseGlamaServer(s)),
|
|
2764
|
+
featured: data.featured
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
/**
|
|
2768
|
+
* Parse Glama server response data.
|
|
2769
|
+
*/
|
|
2770
|
+
parseGlamaServer(data) {
|
|
2771
|
+
const importData = data.importData;
|
|
2772
|
+
return {
|
|
2773
|
+
id: data.id,
|
|
2774
|
+
name: data.name,
|
|
2775
|
+
namespace: data.namespace,
|
|
2776
|
+
slug: data.slug,
|
|
2777
|
+
description: data.description,
|
|
2778
|
+
url: data.url,
|
|
2779
|
+
attributes: data.attributes,
|
|
2780
|
+
canHost: data.canHost,
|
|
2781
|
+
tools: data.tools || [],
|
|
2782
|
+
repository: data.repository,
|
|
2783
|
+
license: data.spdxLicense?.name,
|
|
2784
|
+
importData: importData ? {
|
|
2785
|
+
glamaId: importData.glamaId,
|
|
2786
|
+
glamaNamespace: importData.glamaNamespace,
|
|
2787
|
+
glamaSlug: importData.glamaSlug,
|
|
2788
|
+
suggestedName: importData.suggestedName,
|
|
2789
|
+
suggestedDescription: importData.suggestedDescription,
|
|
2790
|
+
hostingType: importData.hostingType,
|
|
2791
|
+
requiredEnvVars: importData.requiredEnvVars,
|
|
2792
|
+
optionalEnvVars: importData.optionalEnvVars
|
|
2793
|
+
} : void 0
|
|
2794
|
+
};
|
|
2795
|
+
}
|
|
2649
2796
|
// ===========================================================================
|
|
2650
2797
|
// LLM Completion Methods
|
|
2651
2798
|
// ===========================================================================
|