@heyamiko/amiko-cli 0.5.15 → 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 +70 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75831,13 +75831,55 @@ 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) {
|
|
@@ -75845,16 +75887,31 @@ function registerSearchCommand(program2) {
|
|
|
75845
75887
|
}
|
|
75846
75888
|
const params = new URLSearchParams({ q: query });
|
|
75847
75889
|
let res = await fetch(`${mppBase2}/v1/x/search?${params}`, { headers });
|
|
75848
|
-
if (res.status === 402
|
|
75849
|
-
|
|
75850
|
-
|
|
75851
|
-
|
|
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
|
+
}
|
|
75852
75909
|
}
|
|
75853
75910
|
spinner.stop();
|
|
75854
75911
|
if (res.status === 402) {
|
|
75855
|
-
console.error(error("Payment
|
|
75856
|
-
console.log(dim("
|
|
75857
|
-
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"));
|
|
75858
75915
|
process.exit(1);
|
|
75859
75916
|
}
|
|
75860
75917
|
if (!res.ok) {
|
|
@@ -75869,6 +75926,7 @@ function registerSearchCommand(program2) {
|
|
|
75869
75926
|
}
|
|
75870
75927
|
const paymentMethod = res.headers.get("x-payment-method");
|
|
75871
75928
|
const paymentBalance = res.headers.get("x-payment-balance");
|
|
75929
|
+
const paymentTx = res.headers.get("x-payment-tx");
|
|
75872
75930
|
console.log(heading(`X Search: "${query}"
|
|
75873
75931
|
`));
|
|
75874
75932
|
const tweets = data.data || [];
|
|
@@ -75888,11 +75946,14 @@ function registerSearchCommand(program2) {
|
|
|
75888
75946
|
}
|
|
75889
75947
|
}
|
|
75890
75948
|
if (paymentMethod) {
|
|
75891
|
-
let footer =
|
|
75949
|
+
let footer = success("Paid");
|
|
75950
|
+
footer += dim(` via ${paymentMethod}`);
|
|
75892
75951
|
if (paymentBalance)
|
|
75893
75952
|
footer += dim(` (balance: $${paymentBalance})`);
|
|
75894
75953
|
console.log(footer);
|
|
75895
75954
|
}
|
|
75955
|
+
if (paymentTx)
|
|
75956
|
+
console.log(dim(`tx: ${paymentTx}`));
|
|
75896
75957
|
} catch (err) {
|
|
75897
75958
|
spinner.stop();
|
|
75898
75959
|
console.error(error(err instanceof Error ? err.message : "Search failed"));
|