@heyamiko/amiko-cli 0.3.0 → 0.3.2
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 +67 -72
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -26413,6 +26413,11 @@ function saveCredentials(data) {
|
|
|
26413
26413
|
update.twinId = data.twinId;
|
|
26414
26414
|
if (data.twinToken)
|
|
26415
26415
|
update.twinToken = data.twinToken;
|
|
26416
|
+
if (data.apiKey) {
|
|
26417
|
+
update.apiKey = data.apiKey;
|
|
26418
|
+
} else if (data.cliToken) {
|
|
26419
|
+
update.apiKey = data.cliToken;
|
|
26420
|
+
}
|
|
26416
26421
|
if (data.privyToken)
|
|
26417
26422
|
update.privyToken = data.privyToken;
|
|
26418
26423
|
if (data.connectedKeyId)
|
|
@@ -26698,26 +26703,36 @@ function registerCreditsCommand(program2) {
|
|
|
26698
26703
|
{
|
|
26699
26704
|
const spinner2 = ora("Fetching credit balance...").start();
|
|
26700
26705
|
try {
|
|
26701
|
-
let
|
|
26702
|
-
|
|
26703
|
-
|
|
26704
|
-
|
|
26705
|
-
|
|
26706
|
-
|
|
26707
|
-
|
|
26708
|
-
|
|
26709
|
-
|
|
26710
|
-
|
|
26711
|
-
|
|
26712
|
-
|
|
26713
|
-
|
|
26714
|
-
|
|
26715
|
-
|
|
26706
|
+
let balance = null;
|
|
26707
|
+
const billingToken = auth.platformKey || auth.privyToken;
|
|
26708
|
+
if (auth.billingBase && billingToken) {
|
|
26709
|
+
try {
|
|
26710
|
+
const orRes = await fetch(`${auth.billingBase}/api/usage/openrouter`, {
|
|
26711
|
+
headers: { Authorization: `Bearer ${billingToken}` }
|
|
26712
|
+
});
|
|
26713
|
+
if (orRes.ok) {
|
|
26714
|
+
const orData = await orRes.json();
|
|
26715
|
+
const remaining = Number(orData.totalLimitRemaining);
|
|
26716
|
+
if (Number.isFinite(remaining)) {
|
|
26717
|
+
balance = remaining;
|
|
26718
|
+
}
|
|
26719
|
+
}
|
|
26720
|
+
} catch {}
|
|
26721
|
+
if (balance === null) {
|
|
26722
|
+
try {
|
|
26723
|
+
const res = await fetch(`${auth.billingBase}/api/credits`, {
|
|
26724
|
+
headers: { Authorization: `Bearer ${billingToken}` }
|
|
26725
|
+
});
|
|
26726
|
+
if (res.ok) {
|
|
26727
|
+
const raw = await res.json();
|
|
26728
|
+
balance = Number(raw.credits?.balance || 0);
|
|
26729
|
+
}
|
|
26730
|
+
} catch {}
|
|
26716
26731
|
}
|
|
26717
26732
|
}
|
|
26718
26733
|
spinner2.stop();
|
|
26719
|
-
if (
|
|
26720
|
-
console.log(label("Balance", source_default.bold(
|
|
26734
|
+
if (balance !== null) {
|
|
26735
|
+
console.log(label("Balance", source_default.bold(balance.toLocaleString()) + " credits"));
|
|
26721
26736
|
console.log("");
|
|
26722
26737
|
} else {
|
|
26723
26738
|
console.log(dim(" Could not fetch credit balance"));
|
|
@@ -26728,67 +26743,41 @@ function registerCreditsCommand(program2) {
|
|
|
26728
26743
|
console.error(error(err instanceof Error ? err.message : "Failed to fetch credit balance"));
|
|
26729
26744
|
}
|
|
26730
26745
|
}
|
|
26731
|
-
|
|
26746
|
+
const agentWallets = (auth.agentWallets || []).filter((w) => w.source === "agent");
|
|
26747
|
+
if (agentWallets.length > 0 && auth.billingBase) {
|
|
26732
26748
|
const spinner3 = ora("Fetching wallet balances...").start();
|
|
26749
|
+
const billingAuth = auth.platformKey || auth.privyToken;
|
|
26733
26750
|
try {
|
|
26734
|
-
|
|
26735
|
-
|
|
26736
|
-
|
|
26737
|
-
|
|
26738
|
-
|
|
26739
|
-
const
|
|
26740
|
-
|
|
26741
|
-
|
|
26742
|
-
|
|
26743
|
-
|
|
26744
|
-
|
|
26745
|
-
|
|
26746
|
-
|
|
26747
|
-
|
|
26748
|
-
|
|
26749
|
-
|
|
26750
|
-
const
|
|
26751
|
-
const
|
|
26752
|
-
|
|
26753
|
-
|
|
26754
|
-
|
|
26755
|
-
console.log(` ${source_default.bold(chainLabel)} ${dim(shortAddr)}`);
|
|
26756
|
-
let bals = w.balance && typeof w.balance === "object" ? w.balance : null;
|
|
26757
|
-
if (!bals) {
|
|
26758
|
-
try {
|
|
26759
|
-
const balRes = await fetch(`${auth.platformUrl}/api/agents/${auth.twinId}/wallets/${addr}/balance`, { headers: { Authorization: `Bearer ${auth.twinToken}` } });
|
|
26760
|
-
if (balRes.ok) {
|
|
26761
|
-
const balData = await balRes.json();
|
|
26762
|
-
if (balData.chains) {
|
|
26763
|
-
for (const [chainName, chainBals] of Object.entries(balData.chains)) {
|
|
26764
|
-
const chainLabel2 = chainName.charAt(0).toUpperCase() + chainName.slice(1);
|
|
26765
|
-
console.log(dim(` ${chainLabel2}:`));
|
|
26766
|
-
for (const [token, tData] of Object.entries(chainBals)) {
|
|
26767
|
-
const human = parseFloat(tData.amount) / Math.pow(10, tData.decimals);
|
|
26768
|
-
console.log(dim(` ${token.padEnd(8)} ${human.toFixed(6)}`));
|
|
26769
|
-
}
|
|
26770
|
-
}
|
|
26771
|
-
continue;
|
|
26772
|
-
}
|
|
26773
|
-
bals = balData.balances || {};
|
|
26774
|
-
}
|
|
26775
|
-
} catch {
|
|
26776
|
-
console.log(dim(" (balance unavailable)"));
|
|
26777
|
-
continue;
|
|
26778
|
-
}
|
|
26779
|
-
}
|
|
26780
|
-
if (bals) {
|
|
26781
|
-
for (const [token, data2] of Object.entries(bals)) {
|
|
26782
|
-
const human = parseFloat(data2.amount) / Math.pow(10, data2.decimals);
|
|
26783
|
-
if (human > 0 || ["sol", "eth", "usdc", "amiko"].includes(token.toLowerCase())) {
|
|
26784
|
-
console.log(dim(` ${token.padEnd(10)} ${human.toFixed(6)}`));
|
|
26785
|
-
}
|
|
26786
|
-
}
|
|
26751
|
+
spinner3.stop();
|
|
26752
|
+
console.log(label("Agent Wallets", ""));
|
|
26753
|
+
for (const w of agentWallets) {
|
|
26754
|
+
const addr = w.address || "";
|
|
26755
|
+
const chain = w.chain || "solana";
|
|
26756
|
+
const isEvm = ["base", "ethereum", "tempo"].includes(chain);
|
|
26757
|
+
const chainLabel = isEvm ? "EVM (Ethereum · Base · Tempo)" : chain.charAt(0).toUpperCase() + chain.slice(1);
|
|
26758
|
+
const shortAddr = addr ? `${addr.slice(0, 6)}...${addr.slice(-4)}` : "";
|
|
26759
|
+
console.log(` ${source_default.bold(chainLabel)} ${dim(shortAddr)}`);
|
|
26760
|
+
if (!billingAuth) {
|
|
26761
|
+
console.log(dim(" (no auth for balance fetch)"));
|
|
26762
|
+
continue;
|
|
26763
|
+
}
|
|
26764
|
+
try {
|
|
26765
|
+
const balRes = await fetch(`${auth.billingBase}/api/crossmint/wallets/${encodeURIComponent(addr)}/balance?chain=${chain}`, { headers: { Authorization: `Bearer ${billingAuth}` } });
|
|
26766
|
+
if (balRes.ok) {
|
|
26767
|
+
const balData = await balRes.json();
|
|
26768
|
+
const bals = balData.balances || {};
|
|
26769
|
+
for (const [token, tData] of Object.entries(bals)) {
|
|
26770
|
+
const human = parseFloat(tData.amount) / Math.pow(10, tData.decimals);
|
|
26771
|
+
console.log(dim(` ${token.padEnd(10)} ${human.toFixed(6)}`));
|
|
26787
26772
|
}
|
|
26773
|
+
} else {
|
|
26774
|
+
console.log(dim(" (balance unavailable)"));
|
|
26788
26775
|
}
|
|
26776
|
+
} catch {
|
|
26777
|
+
console.log(dim(" (balance fetch failed)"));
|
|
26789
26778
|
}
|
|
26790
|
-
console.log("");
|
|
26791
26779
|
}
|
|
26780
|
+
console.log("");
|
|
26792
26781
|
} catch (err) {
|
|
26793
26782
|
spinner3.stop();
|
|
26794
26783
|
console.error(error(err instanceof Error ? err.message : "Failed to fetch wallet balances"));
|
|
@@ -26899,6 +26888,10 @@ function registerCreditsCommand(program2) {
|
|
|
26899
26888
|
process.exit(1);
|
|
26900
26889
|
}
|
|
26901
26890
|
}
|
|
26891
|
+
if (["base", "ethereum", "tempo"].includes(walletChain)) {
|
|
26892
|
+
console.error(error("EVM topup not supported yet. Use a Solana wallet with --token AMIKO, USDC, USDT, or SOL."));
|
|
26893
|
+
process.exit(1);
|
|
26894
|
+
}
|
|
26902
26895
|
const TREASURY = "FPiZAf3jEnNfCwfvbv46jdPfHbmSepD4Q6iHiLJDQXvb";
|
|
26903
26896
|
const spinner3 = ora("Transferring tokens to treasury...").start();
|
|
26904
26897
|
const transferRes = await fetch(`${auth.billingBase}/api/crossmint/wallets/${encodeURIComponent(walletAddr)}/transfer`, {
|
|
@@ -26915,6 +26908,8 @@ function registerCreditsCommand(program2) {
|
|
|
26915
26908
|
spinner3.stop();
|
|
26916
26909
|
const err = await transferRes.json().catch(() => ({ error: "Transfer failed" }));
|
|
26917
26910
|
console.error(error(err.error || `Transfer failed: ${transferRes.status}`));
|
|
26911
|
+
if (err.details)
|
|
26912
|
+
console.error(dim(typeof err.details === "string" ? err.details : JSON.stringify(err.details)));
|
|
26918
26913
|
process.exit(1);
|
|
26919
26914
|
}
|
|
26920
26915
|
const transferData = await transferRes.json();
|