@heyamiko/amiko-cli 0.5.16 → 0.5.18

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.
Files changed (2) hide show
  1. package/dist/index.js +48 -81
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -75831,92 +75831,70 @@ function registerUpdateCommand(program2) {
75831
75831
  }
75832
75832
 
75833
75833
  // src/commands/search.ts
75834
- var AMIKO_MINT = "AY1Ww6MxwC3cCiyrandHqLrp4FXvzgcwQTZpJ2FEpump";
75835
75834
  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
- }
75871
75835
  function registerSearchCommand(program2) {
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
+ program2.command("search <query>").description("Search X/Twitter — pays 1 AMIKO token per search").option("--raw", "Output raw JSON").action(async (query, opts) => {
75873
75837
  const spinner = ora("Searching X...").start();
75874
75838
  try {
75875
75839
  const config2 = loadConfig();
75876
75840
  const auth = resolveAuth(config2);
75877
75841
  const mppBase2 = (config2.apiBase || "https://mpp.amikomarkets.com").replace(/\/$/, "");
75878
- if (auth.mode === "none") {
75842
+ const billingBase2 = auth.billingBase || "https://billing.heyamiko.com";
75843
+ const billingToken = auth.platformKey || auth.twinToken || auth.privyToken;
75844
+ if (auth.mode === "none" || !billingToken) {
75879
75845
  spinner.stop();
75880
- console.error(error("Not connected. Set up .amiko.json or run: amiko connect"));
75846
+ console.error(error("Not connected."));
75881
75847
  process.exit(1);
75882
75848
  }
75883
- const headers = { "Content-Type": "application/json" };
75884
- const apiKey = config2.apiKey || auth.platformKey;
75885
- if (apiKey) {
75886
- headers["X-Amiko-Key"] = apiKey;
75849
+ const allWallets = auth.agentWallets || config2.agentWallets || [];
75850
+ const solanaWallet = allWallets.find((w5) => w5.chain === "solana")?.address;
75851
+ if (!solanaWallet) {
75852
+ spinner.stop();
75853
+ console.error(error("No Solana wallet found for AMIKO payment."));
75854
+ process.exit(1);
75887
75855
  }
75888
- const params = new URLSearchParams({ q: query });
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
- }
75856
+ spinner.text = "Paying 1 AMIKO...";
75857
+ const transferRes = await fetch(`${billingBase2}/api/crossmint/wallets/${encodeURIComponent(solanaWallet)}/transfer`, {
75858
+ method: "POST",
75859
+ headers: {
75860
+ "Content-Type": "application/json",
75861
+ Authorization: `Bearer ${billingToken}`
75862
+ },
75863
+ body: JSON.stringify({
75864
+ to: TREASURY,
75865
+ amount: "1",
75866
+ token: "AMIKO",
75867
+ chain: "solana"
75868
+ })
75869
+ });
75870
+ if (!transferRes.ok) {
75871
+ spinner.stop();
75872
+ const err = await transferRes.json().catch(() => ({ error: "Transfer failed" }));
75873
+ console.error(error(err.error || `AMIKO payment failed: ${transferRes.status}`));
75874
+ process.exit(1);
75909
75875
  }
75910
- spinner.stop();
75911
- if (res.status === 402) {
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"));
75876
+ const transferData = await transferRes.json();
75877
+ const txHash = transferData.txHash;
75878
+ if (!txHash) {
75879
+ spinner.stop();
75880
+ console.error(error("Payment sent but no tx hash returned."));
75915
75881
  process.exit(1);
75916
75882
  }
75883
+ spinner.text = `Paid 1 AMIKO — searching X...`;
75884
+ const params = new URLSearchParams({ q: query });
75885
+ const res = await fetch(`${mppBase2}/v1/x/search?${params}`, {
75886
+ headers: {
75887
+ "Content-Type": "application/json",
75888
+ "X-Payment-Tx": txHash,
75889
+ "X-Payment-Amount": "1",
75890
+ "X-Payment-Token": "AMIKO"
75891
+ }
75892
+ });
75893
+ spinner.stop();
75917
75894
  if (!res.ok) {
75918
75895
  const text = await res.text().catch(() => "");
75919
75896
  console.error(error(`Search failed: ${res.status} ${text.slice(0, 200)}`));
75897
+ console.log(dim(`Payment tx: https://solscan.io/tx/${txHash}`));
75920
75898
  process.exit(1);
75921
75899
  }
75922
75900
  const data = await res.json();
@@ -75924,9 +75902,6 @@ function registerSearchCommand(program2) {
75924
75902
  console.log(JSON.stringify(data, null, 2));
75925
75903
  return;
75926
75904
  }
75927
- const paymentMethod = res.headers.get("x-payment-method");
75928
- const paymentBalance = res.headers.get("x-payment-balance");
75929
- const paymentTx = res.headers.get("x-payment-tx");
75930
75905
  console.log(heading(`X Search: "${query}"
75931
75906
  `));
75932
75907
  const tweets = data.data || [];
@@ -75945,15 +75920,7 @@ function registerSearchCommand(program2) {
75945
75920
  console.log("");
75946
75921
  }
75947
75922
  }
75948
- if (paymentMethod) {
75949
- let footer = success("Paid");
75950
- footer += dim(` via ${paymentMethod}`);
75951
- if (paymentBalance)
75952
- footer += dim(` (balance: $${paymentBalance})`);
75953
- console.log(footer);
75954
- }
75955
- if (paymentTx)
75956
- console.log(dim(`tx: ${paymentTx}`));
75923
+ console.log(success("Paid 1 AMIKO") + dim(` tx: ${txHash.slice(0, 16)}...`));
75957
75924
  } catch (err) {
75958
75925
  spinner.stop();
75959
75926
  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.16",
3
+ "version": "0.5.18",
4
4
  "description": "Amiko CLI — swap tokens, manage credits, bridge cross-chain, and call marketplace agents",
5
5
  "type": "module",
6
6
  "bin": {