@t2000/cli 0.20.43 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1453,67 +1453,50 @@ function isRetryable(code) {
|
|
|
1453
1453
|
// src/commands/pay.ts
|
|
1454
1454
|
import pc9 from "picocolors";
|
|
1455
1455
|
import { T2000 as T200019 } from "@t2000/sdk";
|
|
1456
|
-
import { x402Client } from "@t2000/x402";
|
|
1457
|
-
function createX402Wallet(agent) {
|
|
1458
|
-
return {
|
|
1459
|
-
client: agent.suiClient,
|
|
1460
|
-
keypair: agent.signer,
|
|
1461
|
-
address: () => agent.address(),
|
|
1462
|
-
signAndExecute: async (tx) => {
|
|
1463
|
-
const result = await agent.suiClient.signAndExecuteTransaction({
|
|
1464
|
-
signer: agent.signer,
|
|
1465
|
-
transaction: tx
|
|
1466
|
-
});
|
|
1467
|
-
return { digest: result.digest };
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
1456
|
function registerPay(program2) {
|
|
1472
|
-
program2.command("pay <url>").description("Pay for an
|
|
1457
|
+
program2.command("pay <url>").description("Pay for an MPP-protected API resource").option("--key <path>", "Key file path").option("--method <method>", "HTTP method (GET, POST, PUT)", "GET").option("--data <json>", "Request body for POST/PUT").option("--header <key=value>", "Additional HTTP header (repeatable)", collectHeaders, {}).option("--max-price <amount>", "Max USDC price to auto-approve", "1.00").action(async (url, opts) => {
|
|
1473
1458
|
try {
|
|
1474
1459
|
const pin = await resolvePin();
|
|
1475
1460
|
const agent = await T200019.create({ pin, keyPath: opts.key });
|
|
1476
|
-
agent.enforcer.check({ operation: "pay", amount: parseFloat(opts.maxPrice) });
|
|
1477
|
-
const wallet = createX402Wallet(agent);
|
|
1478
|
-
const client = new x402Client(wallet);
|
|
1479
1461
|
const startTime = Date.now();
|
|
1480
1462
|
if (!isJsonMode()) {
|
|
1481
1463
|
printBlank();
|
|
1482
1464
|
printInfo(`\u2192 ${opts.method} ${url}`);
|
|
1483
1465
|
}
|
|
1484
|
-
const
|
|
1466
|
+
const maxPrice = parseFloat(opts.maxPrice);
|
|
1467
|
+
if (isNaN(maxPrice) || maxPrice <= 0) {
|
|
1468
|
+
throw new Error(`Invalid --max-price: "${opts.maxPrice}". Must be a positive number.`);
|
|
1469
|
+
}
|
|
1470
|
+
const result = await agent.pay({
|
|
1471
|
+
url,
|
|
1485
1472
|
method: opts.method,
|
|
1486
1473
|
headers: opts.header,
|
|
1487
1474
|
body: opts.data,
|
|
1488
|
-
maxPrice
|
|
1489
|
-
timeout: parseInt(opts.timeout, 10) * 1e3,
|
|
1490
|
-
dryRun: opts.dryRun,
|
|
1491
|
-
onPayment: (details) => {
|
|
1492
|
-
if (!isJsonMode()) {
|
|
1493
|
-
printInfo(`\u2190 402 Payment Required: $${details.amount} USDC (Sui)`);
|
|
1494
|
-
printSuccess(`Paid $${details.amount} USDC (tx: ${details.txHash.slice(0, 10)}...)`);
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1475
|
+
maxPrice
|
|
1497
1476
|
});
|
|
1498
1477
|
const elapsed = Date.now() - startTime;
|
|
1499
1478
|
if (!isJsonMode()) {
|
|
1500
|
-
|
|
1479
|
+
if (result.paid && result.receipt) {
|
|
1480
|
+
printSuccess(`Paid via MPP (tx: ${result.receipt.reference.slice(0, 10)}...)`);
|
|
1481
|
+
}
|
|
1482
|
+
printInfo(`\u2190 ${result.status} OK ${pc9.dim(`[${elapsed}ms]`)}`);
|
|
1501
1483
|
}
|
|
1502
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
1503
|
-
const body = contentType.includes("application/json") ? await response.json() : await response.text();
|
|
1504
1484
|
if (isJsonMode()) {
|
|
1505
1485
|
printJson({
|
|
1506
|
-
status:
|
|
1486
|
+
status: result.status,
|
|
1507
1487
|
url,
|
|
1508
1488
|
elapsed,
|
|
1509
|
-
|
|
1489
|
+
paid: result.paid,
|
|
1490
|
+
cost: result.cost,
|
|
1491
|
+
receipt: result.receipt,
|
|
1492
|
+
body: result.body
|
|
1510
1493
|
});
|
|
1511
1494
|
} else {
|
|
1512
1495
|
printBlank();
|
|
1513
|
-
if (typeof body === "string") {
|
|
1514
|
-
console.log(body);
|
|
1496
|
+
if (typeof result.body === "string") {
|
|
1497
|
+
console.log(result.body);
|
|
1515
1498
|
} else {
|
|
1516
|
-
console.log(JSON.stringify(body, null, 2));
|
|
1499
|
+
console.log(JSON.stringify(result.body, null, 2));
|
|
1517
1500
|
}
|
|
1518
1501
|
printBlank();
|
|
1519
1502
|
}
|
|
@@ -2053,7 +2036,7 @@ function registerMcp(program2) {
|
|
|
2053
2036
|
mcp.command("start", { isDefault: true }).description("Start MCP server (stdio transport)").option("--key <path>", "Key file path").action(async (opts) => {
|
|
2054
2037
|
let mod;
|
|
2055
2038
|
try {
|
|
2056
|
-
mod = await import("./dist-
|
|
2039
|
+
mod = await import("./dist-7OOZ6NXP.js");
|
|
2057
2040
|
} catch {
|
|
2058
2041
|
console.error(
|
|
2059
2042
|
"MCP server not installed. Run:\n npm install -g @t2000/mcp"
|