@heyamiko/amiko-cli 0.2.0 → 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 +117 -49
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -23417,7 +23417,10 @@ var SKIP_COMMANDS = new Set([
|
|
|
23417
23417
|
"-V",
|
|
23418
23418
|
"config",
|
|
23419
23419
|
"login",
|
|
23420
|
-
"logout"
|
|
23420
|
+
"logout",
|
|
23421
|
+
"connect",
|
|
23422
|
+
"credits",
|
|
23423
|
+
"update"
|
|
23421
23424
|
]);
|
|
23422
23425
|
function prompt(question) {
|
|
23423
23426
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -26349,52 +26352,117 @@ function registerBridgeCommand(program2) {
|
|
|
26349
26352
|
}
|
|
26350
26353
|
|
|
26351
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
|
+
}
|
|
26352
26396
|
function registerConnectCommand(program2) {
|
|
26353
|
-
program2.command("connect").description("Connect to an Amiko account
|
|
26354
|
-
|
|
26355
|
-
|
|
26356
|
-
|
|
26357
|
-
|
|
26358
|
-
|
|
26359
|
-
|
|
26360
|
-
|
|
26361
|
-
|
|
26362
|
-
|
|
26363
|
-
const redeemUrl = `${url.origin}/api/cli/connect/redeem`;
|
|
26364
|
-
const res = await fetch(redeemUrl, {
|
|
26365
|
-
method: "POST",
|
|
26366
|
-
headers: { "Content-Type": "application/json" },
|
|
26367
|
-
body: JSON.stringify({ code })
|
|
26368
|
-
});
|
|
26369
|
-
if (!res.ok) {
|
|
26370
|
-
spinner.stop();
|
|
26371
|
-
const err = await res.json().catch(() => ({ error: "Failed to connect" }));
|
|
26372
|
-
console.error(error(err.error || `Connection failed: ${res.status}`));
|
|
26373
|
-
process.exit(1);
|
|
26374
|
-
}
|
|
26375
|
-
const data = await res.json();
|
|
26376
|
-
spinner.stop();
|
|
26377
|
-
saveConfig({
|
|
26378
|
-
userId: data.userId,
|
|
26379
|
-
platformUrl: data.platformUrl,
|
|
26380
|
-
billingBase: data.billingBase,
|
|
26381
|
-
agentWallets: data.wallets
|
|
26382
|
-
});
|
|
26383
|
-
console.log(heading("Connected"));
|
|
26384
|
-
console.log("");
|
|
26385
|
-
console.log(label("User", data.userId));
|
|
26386
|
-
console.log(label("Platform", data.platformUrl));
|
|
26387
|
-
console.log(label("Wallets", `${data.wallets?.length || 0} found`));
|
|
26388
|
-
if (data.wallets?.length > 0) {
|
|
26389
|
-
for (const w of data.wallets) {
|
|
26390
|
-
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);
|
|
26391
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);
|
|
26392
26428
|
}
|
|
26393
|
-
|
|
26394
|
-
|
|
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);
|
|
26395
26460
|
} catch (err) {
|
|
26396
|
-
|
|
26397
|
-
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>"));
|
|
26398
26466
|
process.exit(1);
|
|
26399
26467
|
}
|
|
26400
26468
|
});
|
|
@@ -26709,10 +26777,10 @@ function registerCreditsCommand(program2) {
|
|
|
26709
26777
|
}
|
|
26710
26778
|
|
|
26711
26779
|
// src/commands/update.ts
|
|
26712
|
-
import { execFileSync as
|
|
26780
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
26713
26781
|
function detectPackageManager() {
|
|
26714
26782
|
try {
|
|
26715
|
-
|
|
26783
|
+
execFileSync3("bun", ["--version"], { stdio: "ignore" });
|
|
26716
26784
|
return "bun";
|
|
26717
26785
|
} catch {
|
|
26718
26786
|
return "npm";
|
|
@@ -26730,14 +26798,14 @@ function registerUpdateCommand(program2) {
|
|
|
26730
26798
|
const spinner = ora("Installing latest version...").start();
|
|
26731
26799
|
try {
|
|
26732
26800
|
if (pm === "bun") {
|
|
26733
|
-
|
|
26801
|
+
execFileSync3("bun", ["install", "-g", `${pkg}@latest`], { stdio: "pipe" });
|
|
26734
26802
|
} else {
|
|
26735
|
-
|
|
26803
|
+
execFileSync3("npm", ["install", "-g", `${pkg}@latest`], { stdio: "pipe" });
|
|
26736
26804
|
}
|
|
26737
26805
|
spinner.stop();
|
|
26738
26806
|
let newVersion = "latest";
|
|
26739
26807
|
try {
|
|
26740
|
-
newVersion =
|
|
26808
|
+
newVersion = execFileSync3("amiko", ["--version"], { encoding: "utf-8" }).trim();
|
|
26741
26809
|
} catch {}
|
|
26742
26810
|
if (newVersion !== currentVersion) {
|
|
26743
26811
|
console.log(success(`Updated to v${newVersion}`));
|
|
@@ -26760,7 +26828,7 @@ var didOnboard = await runOnboarding(process.argv);
|
|
|
26760
26828
|
if (didOnboard)
|
|
26761
26829
|
process.exit(0);
|
|
26762
26830
|
var program2 = new Command;
|
|
26763
|
-
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");
|
|
26764
26832
|
registerBrowseCommand(program2);
|
|
26765
26833
|
registerCallCommand(program2);
|
|
26766
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"
|