@heyamiko/amiko-cli 0.2.1 → 0.2.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 +114 -48
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -23419,6 +23419,7 @@ var SKIP_COMMANDS = new Set([
|
|
|
23419
23419
|
"login",
|
|
23420
23420
|
"logout",
|
|
23421
23421
|
"connect",
|
|
23422
|
+
"credits",
|
|
23422
23423
|
"update"
|
|
23423
23424
|
]);
|
|
23424
23425
|
function prompt(question) {
|
|
@@ -26351,52 +26352,117 @@ function registerBridgeCommand(program2) {
|
|
|
26351
26352
|
}
|
|
26352
26353
|
|
|
26353
26354
|
// src/commands/connect.ts
|
|
26355
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
26356
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
26357
|
+
function openBrowser2(url) {
|
|
26358
|
+
try {
|
|
26359
|
+
const platform = process.platform;
|
|
26360
|
+
if (platform === "darwin") {
|
|
26361
|
+
execFileSync2("open", [url]);
|
|
26362
|
+
} else if (platform === "win32") {
|
|
26363
|
+
execFileSync2("cmd", ["/c", "start", "", url]);
|
|
26364
|
+
} else {
|
|
26365
|
+
try {
|
|
26366
|
+
execFileSync2("xdg-open", [url], { stdio: "ignore" });
|
|
26367
|
+
} catch {}
|
|
26368
|
+
}
|
|
26369
|
+
} catch {}
|
|
26370
|
+
}
|
|
26371
|
+
function printSuccess(data) {
|
|
26372
|
+
console.log(heading("Connected"));
|
|
26373
|
+
console.log("");
|
|
26374
|
+
if (data.userId)
|
|
26375
|
+
console.log(label("User", String(data.userId)));
|
|
26376
|
+
if (data.platformUrl)
|
|
26377
|
+
console.log(label("Platform", String(data.platformUrl)));
|
|
26378
|
+
const wallets = data.wallets;
|
|
26379
|
+
console.log(label("Wallets", `${wallets?.length || 0} found`));
|
|
26380
|
+
if (wallets?.length) {
|
|
26381
|
+
for (const w of wallets) {
|
|
26382
|
+
console.log(dim(` ${w.chain}: ${w.address.slice(0, 8)}...${w.address.slice(-6)}`));
|
|
26383
|
+
}
|
|
26384
|
+
}
|
|
26385
|
+
console.log("");
|
|
26386
|
+
console.log(success("Account connected. You can now run: amiko credits topup <amount>"));
|
|
26387
|
+
}
|
|
26388
|
+
function saveCredentials(data) {
|
|
26389
|
+
saveConfig({
|
|
26390
|
+
userId: data.userId,
|
|
26391
|
+
platformUrl: data.platformUrl,
|
|
26392
|
+
billingBase: data.billingBase,
|
|
26393
|
+
agentWallets: data.wallets
|
|
26394
|
+
});
|
|
26395
|
+
}
|
|
26354
26396
|
function registerConnectCommand(program2) {
|
|
26355
|
-
program2.command("connect").description("Connect to an Amiko account
|
|
26356
|
-
|
|
26357
|
-
|
|
26358
|
-
|
|
26359
|
-
|
|
26360
|
-
|
|
26361
|
-
|
|
26362
|
-
|
|
26363
|
-
|
|
26364
|
-
|
|
26365
|
-
const redeemUrl = `${url.origin}/api/cli/connect/redeem`;
|
|
26366
|
-
const res = await fetch(redeemUrl, {
|
|
26367
|
-
method: "POST",
|
|
26368
|
-
headers: { "Content-Type": "application/json" },
|
|
26369
|
-
body: JSON.stringify({ code })
|
|
26370
|
-
});
|
|
26371
|
-
if (!res.ok) {
|
|
26372
|
-
spinner.stop();
|
|
26373
|
-
const err = await res.json().catch(() => ({ error: "Failed to connect" }));
|
|
26374
|
-
console.error(error(err.error || `Connection failed: ${res.status}`));
|
|
26375
|
-
process.exit(1);
|
|
26376
|
-
}
|
|
26377
|
-
const data = await res.json();
|
|
26378
|
-
spinner.stop();
|
|
26379
|
-
saveConfig({
|
|
26380
|
-
userId: data.userId,
|
|
26381
|
-
platformUrl: data.platformUrl,
|
|
26382
|
-
billingBase: data.billingBase,
|
|
26383
|
-
agentWallets: data.wallets
|
|
26384
|
-
});
|
|
26385
|
-
console.log(heading("Connected"));
|
|
26386
|
-
console.log("");
|
|
26387
|
-
console.log(label("User", data.userId));
|
|
26388
|
-
console.log(label("Platform", data.platformUrl));
|
|
26389
|
-
console.log(label("Wallets", `${data.wallets?.length || 0} found`));
|
|
26390
|
-
if (data.wallets?.length > 0) {
|
|
26391
|
-
for (const w of data.wallets) {
|
|
26392
|
-
console.log(dim(` ${w.chain}: ${w.address.slice(0, 8)}...${w.address.slice(-6)}`));
|
|
26397
|
+
program2.command("connect").description("Connect to an Amiko account (opens browser, or pass a connect URL)").argument("[url]", "Connect URL from Amiko settings (optional — opens browser if omitted)").option("--no-browser", "Print the connect URL instead of opening a browser").action(async (urlStr, opts) => {
|
|
26398
|
+
if (urlStr) {
|
|
26399
|
+
const spinner2 = ora("Connecting...").start();
|
|
26400
|
+
try {
|
|
26401
|
+
const url = new URL(urlStr);
|
|
26402
|
+
const code = url.searchParams.get("code");
|
|
26403
|
+
if (!code) {
|
|
26404
|
+
spinner2.stop();
|
|
26405
|
+
console.error(error("Invalid connect URL — missing code parameter."));
|
|
26406
|
+
process.exit(1);
|
|
26393
26407
|
}
|
|
26408
|
+
const redeemUrl = `${url.origin}/api/cli/connect/redeem`;
|
|
26409
|
+
const res = await fetch(redeemUrl, {
|
|
26410
|
+
method: "POST",
|
|
26411
|
+
headers: { "Content-Type": "application/json" },
|
|
26412
|
+
body: JSON.stringify({ code })
|
|
26413
|
+
});
|
|
26414
|
+
if (!res.ok) {
|
|
26415
|
+
spinner2.stop();
|
|
26416
|
+
const err = await res.json().catch(() => ({ error: "Failed to connect" }));
|
|
26417
|
+
console.error(error(err.error || `Connection failed: ${res.status}`));
|
|
26418
|
+
process.exit(1);
|
|
26419
|
+
}
|
|
26420
|
+
const data = await res.json();
|
|
26421
|
+
spinner2.stop();
|
|
26422
|
+
saveCredentials(data);
|
|
26423
|
+
printSuccess(data);
|
|
26424
|
+
} catch (err) {
|
|
26425
|
+
spinner2.stop();
|
|
26426
|
+
console.error(error(err instanceof Error ? err.message : "Failed to connect"));
|
|
26427
|
+
process.exit(1);
|
|
26394
26428
|
}
|
|
26395
|
-
|
|
26396
|
-
|
|
26429
|
+
return;
|
|
26430
|
+
}
|
|
26431
|
+
const config = loadConfig();
|
|
26432
|
+
const state = randomBytes2(16).toString("hex");
|
|
26433
|
+
const platformUrl = config.platformUrl || process.env.AMIKO_PLATFORM_URL || "https://app.heyamiko.com";
|
|
26434
|
+
console.log(heading("Amiko Connect"));
|
|
26435
|
+
console.log(dim(`Connect your CLI to your Amiko account.
|
|
26436
|
+
`));
|
|
26437
|
+
const spinner = ora("Starting connection server...").start();
|
|
26438
|
+
const { port, token: callbackPromise } = await startCallbackServer(state);
|
|
26439
|
+
spinner.stop();
|
|
26440
|
+
const connectUrl = `${platformUrl}/cli-connect?port=${port}&state=${state}`;
|
|
26441
|
+
if (opts.browser !== false) {
|
|
26442
|
+
console.log(dim(`Opening browser...
|
|
26443
|
+
`));
|
|
26444
|
+
openBrowser2(connectUrl);
|
|
26445
|
+
}
|
|
26446
|
+
console.log(dim(`If your browser does not open, visit:
|
|
26447
|
+
`));
|
|
26448
|
+
console.log(source_default.cyan(connectUrl));
|
|
26449
|
+
console.log("");
|
|
26450
|
+
const waitSpinner = ora("Waiting for authorization...").start();
|
|
26451
|
+
try {
|
|
26452
|
+
const result = await callbackPromise;
|
|
26453
|
+
const data = JSON.parse(JSON.stringify(result));
|
|
26454
|
+
delete data.state;
|
|
26455
|
+
delete data.token;
|
|
26456
|
+
result.acknowledge({ ok: true });
|
|
26457
|
+
waitSpinner.stop();
|
|
26458
|
+
saveCredentials(data);
|
|
26459
|
+
printSuccess(data);
|
|
26397
26460
|
} catch (err) {
|
|
26398
|
-
|
|
26399
|
-
console.error(error(err instanceof Error ? err.message : "
|
|
26461
|
+
waitSpinner.stop();
|
|
26462
|
+
console.error(error(err instanceof Error ? err.message : "Connection timed out or failed"));
|
|
26463
|
+
console.log(dim(`
|
|
26464
|
+
Tip: you can also generate a connect link from your Amiko settings`));
|
|
26465
|
+
console.log(dim(" and run: amiko connect <url>"));
|
|
26400
26466
|
process.exit(1);
|
|
26401
26467
|
}
|
|
26402
26468
|
});
|
|
@@ -26711,10 +26777,10 @@ function registerCreditsCommand(program2) {
|
|
|
26711
26777
|
}
|
|
26712
26778
|
|
|
26713
26779
|
// src/commands/update.ts
|
|
26714
|
-
import { execFileSync as
|
|
26780
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
26715
26781
|
function detectPackageManager() {
|
|
26716
26782
|
try {
|
|
26717
|
-
|
|
26783
|
+
execFileSync3("bun", ["--version"], { stdio: "ignore" });
|
|
26718
26784
|
return "bun";
|
|
26719
26785
|
} catch {
|
|
26720
26786
|
return "npm";
|
|
@@ -26732,14 +26798,14 @@ function registerUpdateCommand(program2) {
|
|
|
26732
26798
|
const spinner = ora("Installing latest version...").start();
|
|
26733
26799
|
try {
|
|
26734
26800
|
if (pm === "bun") {
|
|
26735
|
-
|
|
26801
|
+
execFileSync3("bun", ["install", "-g", `${pkg}@latest`], { stdio: "pipe" });
|
|
26736
26802
|
} else {
|
|
26737
|
-
|
|
26803
|
+
execFileSync3("npm", ["install", "-g", `${pkg}@latest`], { stdio: "pipe" });
|
|
26738
26804
|
}
|
|
26739
26805
|
spinner.stop();
|
|
26740
26806
|
let newVersion = "latest";
|
|
26741
26807
|
try {
|
|
26742
|
-
newVersion =
|
|
26808
|
+
newVersion = execFileSync3("amiko", ["--version"], { encoding: "utf-8" }).trim();
|
|
26743
26809
|
} catch {}
|
|
26744
26810
|
if (newVersion !== currentVersion) {
|
|
26745
26811
|
console.log(success(`Updated to v${newVersion}`));
|
|
@@ -26762,7 +26828,7 @@ var didOnboard = await runOnboarding(process.argv);
|
|
|
26762
26828
|
if (didOnboard)
|
|
26763
26829
|
process.exit(0);
|
|
26764
26830
|
var program2 = new Command;
|
|
26765
|
-
program2.name("amiko").description("
|
|
26831
|
+
program2.name("amiko").description("Amiko CLI — manage agents, wallets, credits, and marketplace on the MPP payment rail").version("0.2.2");
|
|
26766
26832
|
registerBrowseCommand(program2);
|
|
26767
26833
|
registerCallCommand(program2);
|
|
26768
26834
|
registerWalletCommand(program2);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyamiko/amiko-cli",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Amiko CLI — manage agents, wallets, credits, and marketplace on the MPP payment rail",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"amiko": "./dist/index.js"
|