@agent-pay/mcp 2.0.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/README.md +91 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +689 -0
- package/dist/cli.js.map +1 -0
- package/dist/gateway-client.d.ts +26 -0
- package/dist/gateway-client.js +91 -0
- package/dist/gateway-client.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/check-deployment.d.ts +3 -0
- package/dist/tools/check-deployment.js +73 -0
- package/dist/tools/check-deployment.js.map +1 -0
- package/dist/tools/get-compute-quote.d.ts +4 -0
- package/dist/tools/get-compute-quote.js +90 -0
- package/dist/tools/get-compute-quote.js.map +1 -0
- package/dist/tools/list-deployments.d.ts +3 -0
- package/dist/tools/list-deployments.js +65 -0
- package/dist/tools/list-deployments.js.map +1 -0
- package/dist/tools/provision-compute.d.ts +4 -0
- package/dist/tools/provision-compute.js +251 -0
- package/dist/tools/provision-compute.js.map +1 -0
- package/dist/tools/stop-deployment.d.ts +3 -0
- package/dist/tools/stop-deployment.js +42 -0
- package/dist/tools/stop-deployment.js.map +1 -0
- package/dist/types.d.ts +227 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/wallet.d.ts +27 -0
- package/dist/wallet.js +119 -0
- package/dist/wallet.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GatewayRequestError } from "../gateway-client.js";
|
|
3
|
+
export function registerProvisionCompute(server, gateway, _wallet) {
|
|
4
|
+
server.registerTool("provision_compute", {
|
|
5
|
+
title: "Provision Compute",
|
|
6
|
+
description: "Provision cloud compute on Akash Network. Analyzes your task, gets pricing from multiple providers, pays with USDC, and deploys — all in one step. Returns deployment ID, endpoints, and SSH credentials.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
task: z
|
|
9
|
+
.string()
|
|
10
|
+
.describe("Description of what the compute will be used for (e.g. 'run a PyTorch training job', 'host a Node.js API server')"),
|
|
11
|
+
cpu: z
|
|
12
|
+
.number()
|
|
13
|
+
.min(1)
|
|
14
|
+
.max(256)
|
|
15
|
+
.optional()
|
|
16
|
+
.describe("CPU cores (1-256). If omitted, auto-detected from task."),
|
|
17
|
+
memory: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('RAM size (e.g. "4GB", "16GB"). If omitted, auto-detected from task.'),
|
|
21
|
+
storage: z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('Storage size (e.g. "20GB", "100GB"). If omitted, auto-detected from task.'),
|
|
25
|
+
image: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Docker image to deploy. If omitted, auto-detected from task."),
|
|
29
|
+
hours: z
|
|
30
|
+
.number()
|
|
31
|
+
.min(1)
|
|
32
|
+
.max(720)
|
|
33
|
+
.optional()
|
|
34
|
+
.describe("Lease duration in hours (1-720). If omitted, auto-detected from task."),
|
|
35
|
+
maxBudget: z
|
|
36
|
+
.number()
|
|
37
|
+
.optional()
|
|
38
|
+
.describe("Maximum budget in USD. Defaults to $10."),
|
|
39
|
+
gpu: z
|
|
40
|
+
.object({
|
|
41
|
+
count: z.number().min(1).describe("Number of GPUs"),
|
|
42
|
+
model: z
|
|
43
|
+
.string()
|
|
44
|
+
.optional()
|
|
45
|
+
.describe('GPU model (e.g. "nvidia-a100")'),
|
|
46
|
+
})
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("GPU requirements, if any."),
|
|
49
|
+
env: z
|
|
50
|
+
.record(z.string(), z.string())
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Environment variables to set in the container."),
|
|
53
|
+
command: z
|
|
54
|
+
.array(z.string())
|
|
55
|
+
.optional()
|
|
56
|
+
.describe("Override container command."),
|
|
57
|
+
ports: z
|
|
58
|
+
.array(z.object({
|
|
59
|
+
port: z.number().describe("Port number"),
|
|
60
|
+
protocol: z
|
|
61
|
+
.enum(["tcp", "udp"])
|
|
62
|
+
.default("tcp")
|
|
63
|
+
.describe("Protocol"),
|
|
64
|
+
expose: z
|
|
65
|
+
.boolean()
|
|
66
|
+
.default(true)
|
|
67
|
+
.describe("Expose to the internet"),
|
|
68
|
+
}))
|
|
69
|
+
.optional()
|
|
70
|
+
.describe("Ports to expose from the container."),
|
|
71
|
+
},
|
|
72
|
+
annotations: {
|
|
73
|
+
destructiveHint: false,
|
|
74
|
+
idempotentHint: false,
|
|
75
|
+
openWorldHint: true,
|
|
76
|
+
},
|
|
77
|
+
}, async (args) => {
|
|
78
|
+
try {
|
|
79
|
+
const maxBudget = args.maxBudget ?? 10;
|
|
80
|
+
// Step 1: If specs are incomplete, ask the LLM to analyze the task
|
|
81
|
+
let cpu = args.cpu;
|
|
82
|
+
let memory = args.memory;
|
|
83
|
+
let storage = args.storage;
|
|
84
|
+
let image = args.image;
|
|
85
|
+
let hours = args.hours;
|
|
86
|
+
if (!cpu || !memory || !storage || !image || !hours) {
|
|
87
|
+
const analysis = await gateway.analyzeTask({
|
|
88
|
+
task: args.task,
|
|
89
|
+
maxBudget,
|
|
90
|
+
});
|
|
91
|
+
cpu = cpu ?? analysis.recommendedCpu;
|
|
92
|
+
memory = memory ?? analysis.recommendedRam;
|
|
93
|
+
storage = storage ?? analysis.recommendedStorage;
|
|
94
|
+
image = image ?? analysis.recommendedImage;
|
|
95
|
+
hours = hours ?? analysis.estimatedDurationHours;
|
|
96
|
+
}
|
|
97
|
+
// Step 2: Get quotes from multiple providers
|
|
98
|
+
const quoteReq = {
|
|
99
|
+
cpu,
|
|
100
|
+
memory,
|
|
101
|
+
storage,
|
|
102
|
+
image,
|
|
103
|
+
hours,
|
|
104
|
+
gpu: args.gpu,
|
|
105
|
+
};
|
|
106
|
+
const { quotes } = await gateway.getMultiQuotes(quoteReq);
|
|
107
|
+
if (quotes.length === 0) {
|
|
108
|
+
return {
|
|
109
|
+
content: [
|
|
110
|
+
{
|
|
111
|
+
type: "text",
|
|
112
|
+
text: "No providers returned quotes for the requested specs. Try adjusting CPU, memory, or GPU requirements.",
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
isError: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// Step 3: Select best provider
|
|
119
|
+
const selection = await gateway.selectProvider({
|
|
120
|
+
task: args.task,
|
|
121
|
+
budget: maxBudget,
|
|
122
|
+
quotes,
|
|
123
|
+
});
|
|
124
|
+
const chosenQuoteId = selection.selectedQuoteId ?? quotes[0].quoteId;
|
|
125
|
+
const chosenQuote = quotes.find((q) => q.quoteId === chosenQuoteId) ?? quotes[0];
|
|
126
|
+
// Check if escrow is available
|
|
127
|
+
const escrowInfo = chosenQuote.escrow;
|
|
128
|
+
if (escrowInfo) {
|
|
129
|
+
// ESCROW FLOW: Return quote with deposit instructions
|
|
130
|
+
const quotedUsd = (parseInt(escrowInfo.quotedAmount) / 1_000_000).toFixed(2);
|
|
131
|
+
const depositUsd = (parseInt(escrowInfo.suggestedDeposit) / 1_000_000).toFixed(2);
|
|
132
|
+
const refundEstimate = (parseFloat(depositUsd) - parseFloat(quotedUsd)).toFixed(2);
|
|
133
|
+
const text = [
|
|
134
|
+
`## Deployment Quote Ready`,
|
|
135
|
+
"",
|
|
136
|
+
`**Specs:** ${cpu} CPU, ${memory} RAM, ${storage} storage`,
|
|
137
|
+
`**Image:** ${image}`,
|
|
138
|
+
`**Duration:** ${hours} hours`,
|
|
139
|
+
`**Provider:** ${chosenQuote.providerName} (${chosenQuote.region})`,
|
|
140
|
+
"",
|
|
141
|
+
`**Cost:** $${quotedUsd} USDC`,
|
|
142
|
+
`**Deposit:** $${depositUsd} USDC (includes buffer)`,
|
|
143
|
+
`**Estimated Refund:** ~$${refundEstimate} USDC`,
|
|
144
|
+
"",
|
|
145
|
+
`### To deploy, run this command:`,
|
|
146
|
+
"",
|
|
147
|
+
"```",
|
|
148
|
+
`npx @agent-pay/mcp deposit ${chosenQuoteId}`,
|
|
149
|
+
"```",
|
|
150
|
+
"",
|
|
151
|
+
"This will:",
|
|
152
|
+
"1. Open your wallet to approve the deposit",
|
|
153
|
+
"2. Deposit funds into the escrow contract",
|
|
154
|
+
"3. Gateway will deploy your compute automatically",
|
|
155
|
+
"4. You'll get any unused funds back",
|
|
156
|
+
"",
|
|
157
|
+
"**Your Protections:**",
|
|
158
|
+
"- Funds held in escrow until deployment succeeds",
|
|
159
|
+
"- Full refund if deployment fails",
|
|
160
|
+
"- Excess funds automatically returned",
|
|
161
|
+
"- All transactions recorded on-chain",
|
|
162
|
+
"",
|
|
163
|
+
`Quote expires in 5 minutes.`,
|
|
164
|
+
].join("\n");
|
|
165
|
+
return { content: [{ type: "text", text }] };
|
|
166
|
+
}
|
|
167
|
+
// LEGACY FLOW: Direct provision (for backwards compatibility)
|
|
168
|
+
const deployment = await gateway.provision({
|
|
169
|
+
quoteId: chosenQuoteId,
|
|
170
|
+
env: args.env,
|
|
171
|
+
command: args.command,
|
|
172
|
+
ports: args.ports,
|
|
173
|
+
});
|
|
174
|
+
// Get payment info from response
|
|
175
|
+
const paymentInfo = deployment.payment || {};
|
|
176
|
+
const paymentTxHash = paymentInfo.txHash || "pending";
|
|
177
|
+
// Poll for running status (up to 90s)
|
|
178
|
+
let status = await gateway.getDeploymentStatus(deployment.deploymentId);
|
|
179
|
+
const deadline = Date.now() + 90_000;
|
|
180
|
+
while (status.status !== "running" &&
|
|
181
|
+
status.status !== "failed" &&
|
|
182
|
+
Date.now() < deadline) {
|
|
183
|
+
await sleep(3000);
|
|
184
|
+
status = await gateway.getDeploymentStatus(deployment.deploymentId);
|
|
185
|
+
}
|
|
186
|
+
const endpointLines = status.endpoints && status.endpoints.length > 0
|
|
187
|
+
? status.endpoints
|
|
188
|
+
.map((ep) => ` ${ep.protocol}://${ep.host}:${ep.port}`)
|
|
189
|
+
.join("\n")
|
|
190
|
+
: " (endpoints not yet available — check status again shortly)";
|
|
191
|
+
const text = [
|
|
192
|
+
`Deployment **${deployment.deploymentId}** is **${status.status}**.`,
|
|
193
|
+
"",
|
|
194
|
+
`Provider: ${chosenQuote.providerName} (${chosenQuote.region})`,
|
|
195
|
+
`Image: ${image}`,
|
|
196
|
+
`Specs: ${cpu} CPU, ${memory} RAM, ${storage} storage, ${hours}h`,
|
|
197
|
+
`Cost: ${chosenQuote.priceUsdc} USDC`,
|
|
198
|
+
`Payment tx: ${paymentTxHash}`,
|
|
199
|
+
"",
|
|
200
|
+
"Endpoints:",
|
|
201
|
+
endpointLines,
|
|
202
|
+
"",
|
|
203
|
+
`SSH: ssh ${deployment.credentials.sshUser}@${deployment.credentials.sshHost} -p ${deployment.credentials.sshPort}`,
|
|
204
|
+
`Access token: ${deployment.credentials.accessToken}`,
|
|
205
|
+
"",
|
|
206
|
+
`Expires: ${new Date(status.expiresAt).toISOString()}`,
|
|
207
|
+
].join("\n");
|
|
208
|
+
return { content: [{ type: "text", text }] };
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
if (err instanceof GatewayRequestError) {
|
|
212
|
+
// Handle payment failures with helpful message
|
|
213
|
+
if (err.status === 402) {
|
|
214
|
+
const body = err.body;
|
|
215
|
+
const lines = [
|
|
216
|
+
"## Insufficient Spending Allowance",
|
|
217
|
+
"",
|
|
218
|
+
`This deployment costs **${body.details?.required || "unknown"}** but your current spending limit is **${body.details?.allowance || "$0.00"}**.`,
|
|
219
|
+
"",
|
|
220
|
+
"### To approve spending:",
|
|
221
|
+
"",
|
|
222
|
+
`\`\`\``,
|
|
223
|
+
body.action || "npx @agent-pay/mcp approve 50",
|
|
224
|
+
`\`\`\``,
|
|
225
|
+
"",
|
|
226
|
+
body.hint || "This will open your wallet to set a spending limit. No funds are charged until you provision compute.",
|
|
227
|
+
"",
|
|
228
|
+
"After approving, come back here and try again!",
|
|
229
|
+
];
|
|
230
|
+
return {
|
|
231
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
232
|
+
isError: true,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
content: [{ type: "text", text: `Gateway error (${err.status}): ${err.message}` }],
|
|
237
|
+
isError: true,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
241
|
+
return {
|
|
242
|
+
content: [{ type: "text", text: msg }],
|
|
243
|
+
isError: true,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
function sleep(ms) {
|
|
249
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=provision-compute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-compute.js","sourceRoot":"","sources":["../../src/tools/provision-compute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAG3D,MAAM,UAAU,wBAAwB,CACtC,MAAiB,EACjB,OAAsB,EACtB,OAA0B;IAE1B,MAAM,CAAC,YAAY,CACjB,mBAAmB,EACnB;QACE,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EACT,2MAA2M;QAC7M,WAAW,EAAE;YACX,IAAI,EAAE,CAAC;iBACJ,MAAM,EAAE;iBACR,QAAQ,CACP,mHAAmH,CACpH;YACH,GAAG,EAAE,CAAC;iBACH,MAAM,EAAE;iBACR,GAAG,CAAC,CAAC,CAAC;iBACN,GAAG,CAAC,GAAG,CAAC;iBACR,QAAQ,EAAE;iBACV,QAAQ,CAAC,yDAAyD,CAAC;YACtE,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CACP,qEAAqE,CACtE;YACH,OAAO,EAAE,CAAC;iBACP,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ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GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;gBAC/C,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GatewayRequestError } from "../gateway-client.js";
|
|
3
|
+
export function registerStopDeployment(server, gateway) {
|
|
4
|
+
server.registerTool("stop_deployment", {
|
|
5
|
+
title: "Stop Deployment",
|
|
6
|
+
description: "Stop a running Akash compute deployment. This closes the lease and frees the resources. Cannot be undone.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
deploymentId: z
|
|
9
|
+
.string()
|
|
10
|
+
.describe('The deployment ID to stop (e.g. "deploy_abc123")'),
|
|
11
|
+
},
|
|
12
|
+
annotations: {
|
|
13
|
+
destructiveHint: true,
|
|
14
|
+
idempotentHint: true,
|
|
15
|
+
openWorldHint: true,
|
|
16
|
+
},
|
|
17
|
+
}, async (args) => {
|
|
18
|
+
try {
|
|
19
|
+
const result = await gateway.closeDeployment(args.deploymentId);
|
|
20
|
+
return {
|
|
21
|
+
content: [
|
|
22
|
+
{
|
|
23
|
+
type: "text",
|
|
24
|
+
text: `Deployment **${result.deploymentId}** has been **stopped**. ${result.message}`,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
const msg = err instanceof GatewayRequestError
|
|
31
|
+
? `Gateway error (${err.status}): ${err.message}`
|
|
32
|
+
: err instanceof Error
|
|
33
|
+
? err.message
|
|
34
|
+
: String(err);
|
|
35
|
+
return {
|
|
36
|
+
content: [{ type: "text", text: msg }],
|
|
37
|
+
isError: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=stop-deployment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-deployment.js","sourceRoot":"","sources":["../../src/tools/stop-deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,UAAU,sBAAsB,CACpC,MAAiB,EACjB,OAAsB;IAEtB,MAAM,CAAC,YAAY,CACjB,iBAAiB,EACjB;QACE,KAAK,EAAE,iBAAiB;QACxB,WAAW,EACT,2GAA2G;QAC7G,WAAW,EAAE;YACX,YAAY,EAAE,CAAC;iBACZ,MAAM,EAAE;iBACR,QAAQ,CAAC,kDAAkD,CAAC;SAChE;QACD,WAAW,EAAE;YACX,eAAe,EAAE,IAAI;YACrB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,IAAI;SACpB;KACF,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAEhE,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,gBAAgB,MAAM,CAAC,YAAY,4BAA4B,MAAM,CAAC,OAAO,EAAE;qBACtF;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GACP,GAAG,YAAY,mBAAmB;gBAChC,CAAC,CAAC,kBAAkB,GAAG,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE;gBACjD,CAAC,CAAC,GAAG,YAAY,KAAK;oBACpB,CAAC,CAAC,GAAG,CAAC,OAAO;oBACb,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;gBAC/C,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
export interface ComputeSpecs {
|
|
2
|
+
cpu: number;
|
|
3
|
+
memory: string;
|
|
4
|
+
storage: string;
|
|
5
|
+
image: string;
|
|
6
|
+
hours: number;
|
|
7
|
+
region?: string;
|
|
8
|
+
gpu?: {
|
|
9
|
+
count: number;
|
|
10
|
+
model?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface QuoteRequest {
|
|
14
|
+
cpu: number;
|
|
15
|
+
memory: string;
|
|
16
|
+
storage: string;
|
|
17
|
+
image: string;
|
|
18
|
+
hours: number;
|
|
19
|
+
region?: string;
|
|
20
|
+
gpu?: {
|
|
21
|
+
count: number;
|
|
22
|
+
model?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface QuotePricing {
|
|
26
|
+
akashCostUakt: string;
|
|
27
|
+
akashCostUsd: string;
|
|
28
|
+
markupUsd: string;
|
|
29
|
+
totalUsd: string;
|
|
30
|
+
totalUsdc: string;
|
|
31
|
+
}
|
|
32
|
+
export interface PaymentDetails {
|
|
33
|
+
network: string;
|
|
34
|
+
token: string;
|
|
35
|
+
recipient: string;
|
|
36
|
+
amount: string;
|
|
37
|
+
}
|
|
38
|
+
export interface QuoteResponse {
|
|
39
|
+
quoteId: string;
|
|
40
|
+
specs: ComputeSpecs;
|
|
41
|
+
pricing: QuotePricing;
|
|
42
|
+
paymentDetails: PaymentDetails;
|
|
43
|
+
validUntil: number;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
}
|
|
46
|
+
export interface ProviderQuote {
|
|
47
|
+
quoteId: string;
|
|
48
|
+
provider: string;
|
|
49
|
+
providerName: string;
|
|
50
|
+
region: string;
|
|
51
|
+
priceUsdc: string;
|
|
52
|
+
currency: string;
|
|
53
|
+
validUntil: number;
|
|
54
|
+
capabilities: string;
|
|
55
|
+
specs: ComputeSpecs;
|
|
56
|
+
}
|
|
57
|
+
export interface MultiQuoteResponse {
|
|
58
|
+
quotes: ProviderQuote[];
|
|
59
|
+
}
|
|
60
|
+
export interface ProvisionRequest {
|
|
61
|
+
quoteId: string;
|
|
62
|
+
paymentTx?: string;
|
|
63
|
+
image?: string;
|
|
64
|
+
provider?: string;
|
|
65
|
+
specs?: {
|
|
66
|
+
cpu?: number;
|
|
67
|
+
ram?: string;
|
|
68
|
+
memory?: string;
|
|
69
|
+
storage?: string;
|
|
70
|
+
};
|
|
71
|
+
env?: Record<string, string>;
|
|
72
|
+
command?: string[];
|
|
73
|
+
ports?: Array<{
|
|
74
|
+
port: number;
|
|
75
|
+
protocol: "tcp" | "udp";
|
|
76
|
+
expose: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
79
|
+
export interface ProvisionResponse {
|
|
80
|
+
deploymentId: string;
|
|
81
|
+
provider: string;
|
|
82
|
+
providerName: string;
|
|
83
|
+
host: string;
|
|
84
|
+
ports: {
|
|
85
|
+
http: number;
|
|
86
|
+
https: number;
|
|
87
|
+
ssh: number;
|
|
88
|
+
};
|
|
89
|
+
status: string;
|
|
90
|
+
expiresAt: number;
|
|
91
|
+
credentials: {
|
|
92
|
+
sshHost: string;
|
|
93
|
+
sshPort: number;
|
|
94
|
+
sshUser: string;
|
|
95
|
+
accessToken: string;
|
|
96
|
+
};
|
|
97
|
+
message: string;
|
|
98
|
+
}
|
|
99
|
+
export interface AkashInfo {
|
|
100
|
+
dseq?: string;
|
|
101
|
+
gseq?: number;
|
|
102
|
+
oseq?: number;
|
|
103
|
+
provider?: string;
|
|
104
|
+
leaseId?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface DeploymentEndpoint {
|
|
107
|
+
host: string;
|
|
108
|
+
port: number;
|
|
109
|
+
protocol: string;
|
|
110
|
+
}
|
|
111
|
+
export interface DeploymentStatus {
|
|
112
|
+
deploymentId: string;
|
|
113
|
+
status: "pending" | "deploying" | "running" | "stopped" | "failed";
|
|
114
|
+
quoteId: string;
|
|
115
|
+
paymentTxHash?: string;
|
|
116
|
+
akash: AkashInfo;
|
|
117
|
+
endpoints?: DeploymentEndpoint[];
|
|
118
|
+
specs: ComputeSpecs;
|
|
119
|
+
expiresAt: number;
|
|
120
|
+
createdAt: number;
|
|
121
|
+
updatedAt: number;
|
|
122
|
+
}
|
|
123
|
+
export interface ListDeploymentsResponse {
|
|
124
|
+
deployments: DeploymentStatus[];
|
|
125
|
+
total: number;
|
|
126
|
+
}
|
|
127
|
+
export interface CloseDeploymentResponse {
|
|
128
|
+
deploymentId: string;
|
|
129
|
+
status: "stopped";
|
|
130
|
+
message: string;
|
|
131
|
+
}
|
|
132
|
+
export interface AnalyzeRequest {
|
|
133
|
+
task: string;
|
|
134
|
+
maxBudget?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface AnalyzeResponse {
|
|
137
|
+
recommendedCpu: number;
|
|
138
|
+
recommendedRam: string;
|
|
139
|
+
recommendedStorage: string;
|
|
140
|
+
recommendedImage: string;
|
|
141
|
+
estimatedDurationHours: number;
|
|
142
|
+
reasoning: string;
|
|
143
|
+
confidence: "high" | "medium" | "low";
|
|
144
|
+
}
|
|
145
|
+
export interface SelectProviderRequest {
|
|
146
|
+
task: string;
|
|
147
|
+
budget: number | string;
|
|
148
|
+
quotes: ProviderQuote[];
|
|
149
|
+
}
|
|
150
|
+
export interface SelectProviderResponse {
|
|
151
|
+
selectedProvider: string | null;
|
|
152
|
+
selectedQuoteId: string | null;
|
|
153
|
+
selectionReason: string;
|
|
154
|
+
confidence: "high" | "medium" | "low";
|
|
155
|
+
}
|
|
156
|
+
export interface PayRequest {
|
|
157
|
+
quoteId?: string;
|
|
158
|
+
amount?: string;
|
|
159
|
+
recipient?: string;
|
|
160
|
+
memo?: string;
|
|
161
|
+
currency?: string;
|
|
162
|
+
network?: string;
|
|
163
|
+
}
|
|
164
|
+
export interface PayResponse {
|
|
165
|
+
txHash: string;
|
|
166
|
+
amount: string;
|
|
167
|
+
recipient: string;
|
|
168
|
+
memo: string;
|
|
169
|
+
currency: string;
|
|
170
|
+
network: string;
|
|
171
|
+
timestamp: number;
|
|
172
|
+
status: "confirmed";
|
|
173
|
+
blockNumber: number;
|
|
174
|
+
}
|
|
175
|
+
export interface GatewayError {
|
|
176
|
+
error: string;
|
|
177
|
+
details?: unknown[];
|
|
178
|
+
reason?: string;
|
|
179
|
+
required?: {
|
|
180
|
+
amount: string;
|
|
181
|
+
token: string;
|
|
182
|
+
recipient: string;
|
|
183
|
+
network: string;
|
|
184
|
+
};
|
|
185
|
+
setup?: string;
|
|
186
|
+
action?: string;
|
|
187
|
+
}
|
|
188
|
+
export interface AuthRegisterResponse {
|
|
189
|
+
token: string;
|
|
190
|
+
walletAddress: string;
|
|
191
|
+
balance: {
|
|
192
|
+
usdc: string;
|
|
193
|
+
raw: string;
|
|
194
|
+
};
|
|
195
|
+
allowance: {
|
|
196
|
+
usdc: string;
|
|
197
|
+
raw: string;
|
|
198
|
+
};
|
|
199
|
+
message: string;
|
|
200
|
+
}
|
|
201
|
+
export interface AuthVerifyResponse {
|
|
202
|
+
valid: boolean;
|
|
203
|
+
walletAddress?: string;
|
|
204
|
+
error?: string;
|
|
205
|
+
balance?: {
|
|
206
|
+
usdc: string;
|
|
207
|
+
raw: string;
|
|
208
|
+
};
|
|
209
|
+
allowance?: {
|
|
210
|
+
usdc: string;
|
|
211
|
+
raw: string;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export interface AuthInfoResponse {
|
|
215
|
+
walletAddress: string;
|
|
216
|
+
balance: {
|
|
217
|
+
usdc: string;
|
|
218
|
+
raw: string;
|
|
219
|
+
};
|
|
220
|
+
allowance: {
|
|
221
|
+
usdc: string;
|
|
222
|
+
raw: string;
|
|
223
|
+
sufficient: boolean;
|
|
224
|
+
};
|
|
225
|
+
network: string;
|
|
226
|
+
gatewayAddress: string;
|
|
227
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,0BAA0B"}
|
package/dist/wallet.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Address, type Hash, type PublicClient, type WalletClient } from "viem";
|
|
2
|
+
export interface TransferResult {
|
|
3
|
+
txHash: Hash;
|
|
4
|
+
}
|
|
5
|
+
export declare class UsdcWallet {
|
|
6
|
+
readonly address: Address;
|
|
7
|
+
readonly network: string;
|
|
8
|
+
private publicClient;
|
|
9
|
+
private walletClient;
|
|
10
|
+
private usdcAddress;
|
|
11
|
+
constructor(publicClient: PublicClient, walletClient: WalletClient, address: Address, usdcAddress: Address, network: string);
|
|
12
|
+
/**
|
|
13
|
+
* Transfer USDC to a recipient.
|
|
14
|
+
* @param to - recipient address
|
|
15
|
+
* @param amount - raw amount in USDC smallest unit (6 decimals, e.g. "32200" = 0.0322 USDC)
|
|
16
|
+
*/
|
|
17
|
+
transferUsdc(to: Address, amount: bigint): Promise<TransferResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Get USDC balance formatted as a human-readable string (e.g. "12.50").
|
|
20
|
+
*/
|
|
21
|
+
getBalance(): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a USDC wallet from environment variables.
|
|
25
|
+
* Returns null if AGENT_PAY_WALLET_KEY is not set (simulated mode).
|
|
26
|
+
*/
|
|
27
|
+
export declare function createWallet(): UsdcWallet | null;
|