@heyamiko/amiko-cli 0.5.14 → 0.5.16
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 +72 -8
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -75831,27 +75831,87 @@ function registerUpdateCommand(program2) {
|
|
|
75831
75831
|
}
|
|
75832
75832
|
|
|
75833
75833
|
// src/commands/search.ts
|
|
75834
|
+
var AMIKO_MINT = "AY1Ww6MxwC3cCiyrandHqLrp4FXvzgcwQTZpJ2FEpump";
|
|
75835
|
+
var TREASURY = "FPiZAf3jEnNfCwfvbv46jdPfHbmSepD4Q6iHiLJDQXvb";
|
|
75836
|
+
async function payWithAmiko(auth, amountUsd) {
|
|
75837
|
+
const billingBase2 = auth.billingBase || "https://billing.heyamiko.com";
|
|
75838
|
+
const billingToken = auth.platformKey || auth.twinToken || auth.privyToken;
|
|
75839
|
+
if (!billingToken)
|
|
75840
|
+
return null;
|
|
75841
|
+
const allWallets = auth.agentWallets || [];
|
|
75842
|
+
const solanaWallet = allWallets.find((w5) => w5.chain === "solana")?.address;
|
|
75843
|
+
if (!solanaWallet)
|
|
75844
|
+
return null;
|
|
75845
|
+
const jupRes = await fetch(`https://lite-api.jup.ag/swap/v1/quote?inputMint=${AMIKO_MINT}&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=${Math.pow(10, 6)}&slippageBps=100`);
|
|
75846
|
+
if (!jupRes.ok)
|
|
75847
|
+
return null;
|
|
75848
|
+
const jupData = await jupRes.json();
|
|
75849
|
+
const pricePerToken = parseFloat(jupData.outAmount) / 1e6;
|
|
75850
|
+
if (!pricePerToken || pricePerToken <= 0)
|
|
75851
|
+
return null;
|
|
75852
|
+
const tokenAmount = (amountUsd / pricePerToken).toFixed(6);
|
|
75853
|
+
const transferRes = await fetch(`${billingBase2}/api/crossmint/wallets/${encodeURIComponent(solanaWallet)}/transfer`, {
|
|
75854
|
+
method: "POST",
|
|
75855
|
+
headers: {
|
|
75856
|
+
"Content-Type": "application/json",
|
|
75857
|
+
Authorization: `Bearer ${billingToken}`
|
|
75858
|
+
},
|
|
75859
|
+
body: JSON.stringify({
|
|
75860
|
+
to: TREASURY,
|
|
75861
|
+
amount: tokenAmount,
|
|
75862
|
+
token: "AMIKO",
|
|
75863
|
+
chain: "solana"
|
|
75864
|
+
})
|
|
75865
|
+
});
|
|
75866
|
+
if (!transferRes.ok)
|
|
75867
|
+
return null;
|
|
75868
|
+
const transferData = await transferRes.json();
|
|
75869
|
+
return transferData.txHash || null;
|
|
75870
|
+
}
|
|
75834
75871
|
function registerSearchCommand(program2) {
|
|
75835
|
-
program2.command("search <query>").description("Search X/Twitter via MPP (
|
|
75872
|
+
program2.command("search <query>").description("Search X/Twitter via MPP (pays with AMIKO tokens)").option("--limit <n>", "Number of results", "10").option("--raw", "Output raw JSON").action(async (query, opts) => {
|
|
75836
75873
|
const spinner = ora("Searching X...").start();
|
|
75837
75874
|
try {
|
|
75838
75875
|
const config2 = loadConfig();
|
|
75839
75876
|
const auth = resolveAuth(config2);
|
|
75840
75877
|
const mppBase2 = (config2.apiBase || "https://mpp.amikomarkets.com").replace(/\/$/, "");
|
|
75878
|
+
if (auth.mode === "none") {
|
|
75879
|
+
spinner.stop();
|
|
75880
|
+
console.error(error("Not connected. Set up .amiko.json or run: amiko connect"));
|
|
75881
|
+
process.exit(1);
|
|
75882
|
+
}
|
|
75841
75883
|
const headers = { "Content-Type": "application/json" };
|
|
75842
75884
|
const apiKey = config2.apiKey || auth.platformKey;
|
|
75843
75885
|
if (apiKey) {
|
|
75844
75886
|
headers["X-Amiko-Key"] = apiKey;
|
|
75845
|
-
} else if (auth.twinToken) {
|
|
75846
|
-
headers["Authorization"] = `Bearer ${auth.twinToken}`;
|
|
75847
75887
|
}
|
|
75848
75888
|
const params = new URLSearchParams({ q: query });
|
|
75849
|
-
|
|
75889
|
+
let res = await fetch(`${mppBase2}/v1/x/search?${params}`, { headers });
|
|
75890
|
+
if (res.status === 402) {
|
|
75891
|
+
spinner.text = "Paying with AMIKO tokens...";
|
|
75892
|
+
const challenge2 = await res.json().catch(() => null);
|
|
75893
|
+
const amountUsd = 0.01;
|
|
75894
|
+
const txHash = await payWithAmiko(auth, amountUsd);
|
|
75895
|
+
if (txHash) {
|
|
75896
|
+
spinner.text = `Paid (tx: ${txHash.slice(0, 12)}...) — retrying search...`;
|
|
75897
|
+
res = await fetch(`${mppBase2}/v1/x/search?${params}`, {
|
|
75898
|
+
headers: {
|
|
75899
|
+
...headers,
|
|
75900
|
+
"X-Payment-Tx": txHash,
|
|
75901
|
+
...apiKey ? { "X-Amiko-Key": apiKey } : {}
|
|
75902
|
+
}
|
|
75903
|
+
});
|
|
75904
|
+
if (res.status === 402) {
|
|
75905
|
+
await new Promise((r19) => setTimeout(r19, 3000));
|
|
75906
|
+
res = await fetch(`${mppBase2}/v1/x/search?${params}`, { headers });
|
|
75907
|
+
}
|
|
75908
|
+
}
|
|
75909
|
+
}
|
|
75850
75910
|
spinner.stop();
|
|
75851
75911
|
if (res.status === 402) {
|
|
75852
|
-
console.error(error("Payment
|
|
75853
|
-
console.log(dim("
|
|
75854
|
-
console.log(dim("
|
|
75912
|
+
console.error(error("Payment failed — insufficient AMIKO balance or no wallet."));
|
|
75913
|
+
console.log(dim("Check balance: amiko credits balance"));
|
|
75914
|
+
console.log(dim("Top up: amiko credits topup 10000 --token AMIKO --yes"));
|
|
75855
75915
|
process.exit(1);
|
|
75856
75916
|
}
|
|
75857
75917
|
if (!res.ok) {
|
|
@@ -75866,6 +75926,7 @@ function registerSearchCommand(program2) {
|
|
|
75866
75926
|
}
|
|
75867
75927
|
const paymentMethod = res.headers.get("x-payment-method");
|
|
75868
75928
|
const paymentBalance = res.headers.get("x-payment-balance");
|
|
75929
|
+
const paymentTx = res.headers.get("x-payment-tx");
|
|
75869
75930
|
console.log(heading(`X Search: "${query}"
|
|
75870
75931
|
`));
|
|
75871
75932
|
const tweets = data.data || [];
|
|
@@ -75885,11 +75946,14 @@ function registerSearchCommand(program2) {
|
|
|
75885
75946
|
}
|
|
75886
75947
|
}
|
|
75887
75948
|
if (paymentMethod) {
|
|
75888
|
-
let footer =
|
|
75949
|
+
let footer = success("Paid");
|
|
75950
|
+
footer += dim(` via ${paymentMethod}`);
|
|
75889
75951
|
if (paymentBalance)
|
|
75890
75952
|
footer += dim(` (balance: $${paymentBalance})`);
|
|
75891
75953
|
console.log(footer);
|
|
75892
75954
|
}
|
|
75955
|
+
if (paymentTx)
|
|
75956
|
+
console.log(dim(`tx: ${paymentTx}`));
|
|
75893
75957
|
} catch (err) {
|
|
75894
75958
|
spinner.stop();
|
|
75895
75959
|
console.error(error(err instanceof Error ? err.message : "Search failed"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyamiko/amiko-cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.16",
|
|
4
4
|
"description": "Amiko CLI — swap tokens, manage credits, bridge cross-chain, and call marketplace agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@crossmint/wallets-sdk": "^1.0.5",
|
|
28
|
-
"@solana/mpp": "^0.
|
|
28
|
+
"@solana/mpp": "^0.5.1",
|
|
29
29
|
"chalk": "^5.3.0",
|
|
30
30
|
"commander": "^12.1.0",
|
|
31
31
|
"ora": "^8.1.0"
|