@agent-commons/cli 0.1.5 → 0.1.6
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/bin.js +226 -23
- package/package.json +2 -2
package/dist/bin.js
CHANGED
|
@@ -25,10 +25,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
|
|
26
26
|
// src/bin.ts
|
|
27
27
|
var import_commander16 = require("commander");
|
|
28
|
+
var import_path3 = require("path");
|
|
29
|
+
var import_os3 = require("os");
|
|
30
|
+
var import_child_process2 = require("child_process");
|
|
28
31
|
|
|
29
32
|
// src/commands/login.ts
|
|
30
33
|
var import_commander = require("commander");
|
|
31
34
|
var readline = __toESM(require("readline"));
|
|
35
|
+
var import_fs2 = require("fs");
|
|
36
|
+
var import_path2 = require("path");
|
|
37
|
+
var import_os2 = require("os");
|
|
32
38
|
|
|
33
39
|
// src/config.ts
|
|
34
40
|
var import_fs = require("fs");
|
|
@@ -37,7 +43,8 @@ var import_path = require("path");
|
|
|
37
43
|
var import_sdk = require("@agent-commons/sdk");
|
|
38
44
|
var CONFIG_DIR = (0, import_path.join)((0, import_os.homedir)(), ".agc");
|
|
39
45
|
var CONFIG_FILE = (0, import_path.join)(CONFIG_DIR, "config.json");
|
|
40
|
-
var DEFAULT_API_URL = process.env.AGC_API_URL ?? "
|
|
46
|
+
var DEFAULT_API_URL = process.env.AGC_API_URL ?? "https://api.agentcommons.io";
|
|
47
|
+
var DEFAULT_APP_URL = "https://www.agentcommons.io";
|
|
41
48
|
function loadConfig() {
|
|
42
49
|
const fromEnv = {
|
|
43
50
|
...process.env.AGC_API_URL && { apiUrl: process.env.AGC_API_URL },
|
|
@@ -81,6 +88,7 @@ function makeClient(overrides) {
|
|
|
81
88
|
// src/ui.ts
|
|
82
89
|
var import_chalk = __toESM(require("chalk"));
|
|
83
90
|
var import_ora = __toESM(require("ora"));
|
|
91
|
+
var import_child_process = require("child_process");
|
|
84
92
|
var c = {
|
|
85
93
|
primary: (s) => import_chalk.default.cyan(s),
|
|
86
94
|
success: (s) => import_chalk.default.green(s),
|
|
@@ -98,6 +106,80 @@ var sym = {
|
|
|
98
106
|
bullet: import_chalk.default.dim("\u2022"),
|
|
99
107
|
dot: import_chalk.default.dim("\xB7")
|
|
100
108
|
};
|
|
109
|
+
function banner(version = "0.1.4") {
|
|
110
|
+
const line = import_chalk.default.cyan(" \u2500".padEnd(2) + "\u2500".repeat(44));
|
|
111
|
+
console.log("");
|
|
112
|
+
console.log(line);
|
|
113
|
+
console.log(
|
|
114
|
+
import_chalk.default.cyan(" \u2502 ") + import_chalk.default.bold.white(" \u25C8 Agent Commons") + import_chalk.default.dim(" \xB7 CLI") + " " + import_chalk.default.cyan(`v${version}`)
|
|
115
|
+
);
|
|
116
|
+
console.log(import_chalk.default.cyan(" \u2502 ") + import_chalk.default.dim(" The Open AI Agent Network \xB7 agentcommons.io"));
|
|
117
|
+
console.log(line);
|
|
118
|
+
console.log("");
|
|
119
|
+
}
|
|
120
|
+
function step(n, total, title) {
|
|
121
|
+
const fraction = import_chalk.default.dim(`${n}/${total}`);
|
|
122
|
+
console.log(`
|
|
123
|
+
${import_chalk.default.cyan.bold(" Step " + n)} ${fraction} ${import_chalk.default.bold(title)}`);
|
|
124
|
+
console.log(import_chalk.default.dim(" " + "\u2500".repeat(38)));
|
|
125
|
+
}
|
|
126
|
+
async function select(prompt2, choices) {
|
|
127
|
+
if (!process.stdin.isTTY) {
|
|
128
|
+
return choices[0].value;
|
|
129
|
+
}
|
|
130
|
+
let idx = 0;
|
|
131
|
+
const total = choices.length;
|
|
132
|
+
const render = (first = false) => {
|
|
133
|
+
if (!first) {
|
|
134
|
+
process.stdout.write(`\x1B[${total + 2}A\x1B[0J`);
|
|
135
|
+
}
|
|
136
|
+
console.log("\n" + import_chalk.default.bold(" " + prompt2));
|
|
137
|
+
for (let i = 0; i < total; i++) {
|
|
138
|
+
const { label, hint } = choices[i];
|
|
139
|
+
if (i === idx) {
|
|
140
|
+
const hintStr = hint ? import_chalk.default.dim(" " + hint) : "";
|
|
141
|
+
process.stdout.write(import_chalk.default.cyan(" \u203A ") + import_chalk.default.bold.white(label) + hintStr + "\n");
|
|
142
|
+
} else {
|
|
143
|
+
process.stdout.write(import_chalk.default.dim(" " + label) + "\n");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
render(true);
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
process.stdin.setRawMode(true);
|
|
150
|
+
process.stdin.resume();
|
|
151
|
+
process.stdin.setEncoding("utf8");
|
|
152
|
+
const handler = (data) => {
|
|
153
|
+
const key = String(data);
|
|
154
|
+
if (key === "\x1B[A" || key === "k") {
|
|
155
|
+
idx = (idx - 1 + total) % total;
|
|
156
|
+
render();
|
|
157
|
+
} else if (key === "\x1B[B" || key === "j") {
|
|
158
|
+
idx = (idx + 1) % total;
|
|
159
|
+
render();
|
|
160
|
+
} else if (key === "\r" || key === "\n" || key === " ") {
|
|
161
|
+
cleanup();
|
|
162
|
+
process.stdout.write("\n");
|
|
163
|
+
resolve(choices[idx].value);
|
|
164
|
+
} else if (key === "") {
|
|
165
|
+
cleanup();
|
|
166
|
+
process.stdout.write("\n");
|
|
167
|
+
process.exit(130);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const cleanup = () => {
|
|
171
|
+
process.stdin.removeListener("data", handler);
|
|
172
|
+
process.stdin.setRawMode(false);
|
|
173
|
+
process.stdin.pause();
|
|
174
|
+
};
|
|
175
|
+
process.stdin.on("data", handler);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function openBrowser(url) {
|
|
179
|
+
const cmd = process.platform === "darwin" ? `open "${url}"` : process.platform === "win32" ? `start "" "${url}"` : `xdg-open "${url}"`;
|
|
180
|
+
(0, import_child_process.exec)(cmd, () => {
|
|
181
|
+
});
|
|
182
|
+
}
|
|
101
183
|
function spin(text) {
|
|
102
184
|
return (0, import_ora.default)({ text, color: "cyan" }).start();
|
|
103
185
|
}
|
|
@@ -174,6 +256,7 @@ function statusBadge(status) {
|
|
|
174
256
|
}
|
|
175
257
|
|
|
176
258
|
// src/commands/login.ts
|
|
259
|
+
var CONFIG_FILE2 = (0, import_path2.join)((0, import_os2.homedir)(), ".agc", "config.json");
|
|
177
260
|
function prompt(question, hidden = false) {
|
|
178
261
|
return new Promise((resolve) => {
|
|
179
262
|
const rl = readline.createInterface({
|
|
@@ -202,26 +285,70 @@ function loginCommand() {
|
|
|
202
285
|
cmd.option("--api-url <url>", "API base URL", DEFAULT_API_URL).option("--api-key <key>", "API key (or set AGC_API_KEY env var)").option("--initiator <id>", "Default initiator ID (wallet address or user ID)").action(async (opts) => {
|
|
203
286
|
try {
|
|
204
287
|
const current = loadConfig();
|
|
205
|
-
const
|
|
206
|
-
|
|
288
|
+
const isFirstRun = !(0, import_fs2.existsSync)(CONFIG_FILE2);
|
|
289
|
+
banner();
|
|
290
|
+
if (isFirstRun) {
|
|
291
|
+
console.log(c.bold(" Welcome to Agent Commons CLI!"));
|
|
292
|
+
console.log(c.dim(" Let's get you set up in three quick steps.\n"));
|
|
293
|
+
} else {
|
|
294
|
+
console.log(c.bold(" Update your credentials"));
|
|
295
|
+
console.log(c.dim(" Press Enter to keep existing values.\n"));
|
|
296
|
+
}
|
|
297
|
+
step(1, 3, "API Endpoint");
|
|
298
|
+
const defaultUrl = current.apiUrl ?? DEFAULT_API_URL;
|
|
299
|
+
let apiUrl;
|
|
300
|
+
if (opts.apiUrl !== DEFAULT_API_URL) {
|
|
301
|
+
apiUrl = opts.apiUrl;
|
|
302
|
+
console.log(` ${c.dim("Using:")} ${apiUrl}`);
|
|
303
|
+
} else {
|
|
304
|
+
const answer = await prompt(
|
|
305
|
+
` ${c.dim("URL")} [${c.dim(defaultUrl)}]: `
|
|
306
|
+
);
|
|
307
|
+
apiUrl = answer || defaultUrl;
|
|
308
|
+
}
|
|
309
|
+
console.log(` ${sym.ok} ${c.dim("Endpoint:")} ${c.primary(apiUrl)}`);
|
|
310
|
+
const appUrl = apiUrl.includes("localhost") ? "http://localhost:3000" : DEFAULT_APP_URL;
|
|
311
|
+
const settingsUrl = `${appUrl}/settings`;
|
|
312
|
+
step(2, 3, "API Key");
|
|
207
313
|
let apiKey = opts.apiKey;
|
|
208
314
|
if (!apiKey) {
|
|
209
|
-
console.log(`
|
|
210
|
-
|
|
211
|
-
${c.bold(`${appUrl}/settings/api-keys`)}
|
|
315
|
+
console.log(` ${sym.arrow} Opening your browser to generate an API key\u2026`);
|
|
316
|
+
console.log(` ${c.dim(settingsUrl)}
|
|
212
317
|
`);
|
|
213
|
-
|
|
318
|
+
openBrowser(settingsUrl);
|
|
319
|
+
console.log(c.dim(" Once you have your key, paste it below."));
|
|
320
|
+
console.log(c.dim(" (Keys look like: sk-ac-xxxxxxxxxxxxxxxx)\n"));
|
|
321
|
+
apiKey = await prompt(` ${c.dim("API Key:")} `);
|
|
214
322
|
if (!apiKey) apiKey = current.apiKey;
|
|
215
323
|
}
|
|
324
|
+
if (!apiKey) {
|
|
325
|
+
console.log(`
|
|
326
|
+
${c.warn("\u26A0")} No API key provided \u2014 you can set one later with ${c.bold("agc config set apiKey <key>")}`);
|
|
327
|
+
} else {
|
|
328
|
+
console.log(` ${sym.ok} ${c.dim("Key saved:")} ****${apiKey.slice(-4)}`);
|
|
329
|
+
}
|
|
330
|
+
step(3, 3, "Your Identity");
|
|
216
331
|
let initiator = opts.initiator;
|
|
217
332
|
if (!initiator) {
|
|
218
|
-
|
|
333
|
+
const defaultInitiator = current.initiator ?? "";
|
|
334
|
+
const hint = defaultInitiator ? `[${c.dim(defaultInitiator.slice(0, 8) + "\u2026")}] ` : "";
|
|
335
|
+
initiator = await prompt(` ${c.dim("Wallet address (0x\u2026):")} ${hint}`);
|
|
219
336
|
if (!initiator) initiator = current.initiator;
|
|
220
337
|
}
|
|
338
|
+
if (!initiator) {
|
|
339
|
+
console.log(` ${c.warn("\u26A0")} No wallet address \u2014 set one later with ${c.bold("agc config set initiator <address>")}`);
|
|
340
|
+
} else {
|
|
341
|
+
console.log(` ${sym.ok} ${c.dim("Address:")} ${c.id(initiator.slice(0, 10) + "\u2026" + initiator.slice(-6))}`);
|
|
342
|
+
}
|
|
221
343
|
saveConfig({ apiUrl, apiKey, initiator });
|
|
222
344
|
console.log(`
|
|
223
|
-
${sym.ok} Credentials saved to ~/.agc/config.json`);
|
|
224
|
-
console.log(
|
|
345
|
+
${sym.ok} ${c.success("All set!")} Credentials saved to ${c.dim("~/.agc/config.json")}`);
|
|
346
|
+
console.log(`
|
|
347
|
+
${c.dim("Next steps:")}`);
|
|
348
|
+
console.log(` ${sym.arrow} ${c.dim("Run")} ${c.bold("agc")} ${c.dim("for an interactive menu")}`);
|
|
349
|
+
console.log(` ${sym.arrow} ${c.dim("Run")} ${c.bold("agc whoami")} ${c.dim("to verify your connection")}`);
|
|
350
|
+
console.log(` ${sym.arrow} ${c.dim("Run")} ${c.bold("agc chat --agent <id>")} ${c.dim("to start chatting")}
|
|
351
|
+
`);
|
|
225
352
|
} catch (err) {
|
|
226
353
|
printError(err);
|
|
227
354
|
process.exit(1);
|
|
@@ -739,12 +866,12 @@ ${sym.ok} Execution started: ${c.id(execution.executionId)}`);
|
|
|
739
866
|
const steps = execution.stepResults ?? execution.nodeResults;
|
|
740
867
|
if (steps && Object.keys(steps).length > 0) {
|
|
741
868
|
console.log("\n" + c.label("Step Results"));
|
|
742
|
-
for (const [nodeId,
|
|
743
|
-
const icon =
|
|
744
|
-
const dur =
|
|
869
|
+
for (const [nodeId, step2] of Object.entries(steps)) {
|
|
870
|
+
const icon = step2.status === "success" ? sym.ok : step2.status === "error" ? sym.fail : "\xB7";
|
|
871
|
+
const dur = step2.duration != null ? c.dim(` (${(step2.duration / 1e3).toFixed(2)}s)`) : "";
|
|
745
872
|
console.log(` ${icon} ${c.id(nodeId)}${dur}`);
|
|
746
|
-
if (
|
|
747
|
-
else if (
|
|
873
|
+
if (step2.error) console.log(` ${c.error(step2.error)}`);
|
|
874
|
+
else if (step2.output !== void 0) console.log(` ${JSON.stringify(step2.output, null, 2).replace(/\n/g, "\n ")}`);
|
|
748
875
|
}
|
|
749
876
|
}
|
|
750
877
|
} else {
|
|
@@ -769,12 +896,12 @@ ${sym.ok} ${c.success("Completed")}`);
|
|
|
769
896
|
}
|
|
770
897
|
if (e.nodeResults && Object.keys(e.nodeResults).length > 0) {
|
|
771
898
|
console.log("\n" + c.label("Step Results"));
|
|
772
|
-
for (const [nodeId,
|
|
773
|
-
const icon =
|
|
774
|
-
const dur =
|
|
899
|
+
for (const [nodeId, step2] of Object.entries(e.nodeResults)) {
|
|
900
|
+
const icon = step2.status === "success" ? sym.ok : step2.status === "error" ? sym.fail : "\xB7";
|
|
901
|
+
const dur = step2.duration != null ? c.dim(` (${(step2.duration / 1e3).toFixed(2)}s)`) : "";
|
|
775
902
|
console.log(` ${icon} ${c.id(nodeId)}${dur}`);
|
|
776
|
-
if (
|
|
777
|
-
else if (
|
|
903
|
+
if (step2.error) console.log(` ${c.error(step2.error)}`);
|
|
904
|
+
else if (step2.output !== void 0) console.log(` ${JSON.stringify(step2.output, null, 2).replace(/\n/g, "\n ")}`);
|
|
778
905
|
}
|
|
779
906
|
}
|
|
780
907
|
break;
|
|
@@ -2468,8 +2595,80 @@ function logsCommand() {
|
|
|
2468
2595
|
}
|
|
2469
2596
|
|
|
2470
2597
|
// src/bin.ts
|
|
2598
|
+
var CONFIG_FILE3 = (0, import_path3.join)((0, import_os3.homedir)(), ".agc", "config.json");
|
|
2599
|
+
async function interactiveMenu() {
|
|
2600
|
+
banner();
|
|
2601
|
+
const cfg = loadConfig();
|
|
2602
|
+
const isSetup = !!(cfg.apiKey && cfg.initiator);
|
|
2603
|
+
if (!isSetup) {
|
|
2604
|
+
console.log(c.bold(" Welcome to Agent Commons CLI!"));
|
|
2605
|
+
console.log(c.dim(" Looks like this is your first time here \u2014 let's get you set up.\n"));
|
|
2606
|
+
console.log(` ${sym.arrow} Running ${c.bold("agc login")} to configure your credentials\u2026
|
|
2607
|
+
`);
|
|
2608
|
+
runSubcommand(["login"]);
|
|
2609
|
+
return;
|
|
2610
|
+
}
|
|
2611
|
+
console.log(
|
|
2612
|
+
` ${c.dim("Connected to")} ${c.primary(cfg.apiUrl)} ${c.dim("\xB7")} ${c.dim("Wallet")} ${c.id(cfg.initiator.slice(0, 8) + "\u2026" + cfg.initiator.slice(-4))}
|
|
2613
|
+
`
|
|
2614
|
+
);
|
|
2615
|
+
const action = await select("What would you like to do?", [
|
|
2616
|
+
{ label: "Chat with an agent", value: "chat", hint: "agc chat" },
|
|
2617
|
+
{ label: "Run an agent (one-shot)", value: "run", hint: "agc run" },
|
|
2618
|
+
{ label: "View sessions", value: "sessions", hint: "agc sessions list" },
|
|
2619
|
+
{ label: "Manage agents", value: "agents", hint: "agc agents list" },
|
|
2620
|
+
{ label: "Tasks", value: "tasks", hint: "agc task list" },
|
|
2621
|
+
{ label: "Workflows", value: "workflows", hint: "agc workflow list" },
|
|
2622
|
+
{ label: "MCP servers", value: "mcp", hint: "agc mcp list" },
|
|
2623
|
+
{ label: "Skills", value: "skills", hint: "agc skills list" },
|
|
2624
|
+
{ label: "Wallet & balance", value: "wallet", hint: "agc wallet balance" },
|
|
2625
|
+
{ label: "Usage & cost", value: "usage", hint: "agc usage" },
|
|
2626
|
+
{ label: "Logs", value: "logs", hint: "agc logs" },
|
|
2627
|
+
{ label: "Config & credentials", value: "config", hint: "agc config get" },
|
|
2628
|
+
{ label: "Exit", value: "exit" }
|
|
2629
|
+
]);
|
|
2630
|
+
if (action === "exit") {
|
|
2631
|
+
process.exit(0);
|
|
2632
|
+
}
|
|
2633
|
+
const commandMap = {
|
|
2634
|
+
chat: cfg.defaultAgentId ? ["chat", "--agent", cfg.defaultAgentId] : ["chat", "--agent"],
|
|
2635
|
+
run: cfg.defaultAgentId ? ["run", "--agent", cfg.defaultAgentId, "--message"] : ["run", "--agent"],
|
|
2636
|
+
sessions: ["sessions", "list"],
|
|
2637
|
+
agents: ["agents", "list"],
|
|
2638
|
+
tasks: ["task", "list"],
|
|
2639
|
+
workflows: ["workflow", "list"],
|
|
2640
|
+
mcp: ["mcp", "list"],
|
|
2641
|
+
skills: ["skills", "list"],
|
|
2642
|
+
wallet: ["wallet", "balance"],
|
|
2643
|
+
usage: ["usage"],
|
|
2644
|
+
logs: ["logs"],
|
|
2645
|
+
config: ["config", "get"],
|
|
2646
|
+
exit: []
|
|
2647
|
+
};
|
|
2648
|
+
if ((action === "chat" || action === "run") && !cfg.defaultAgentId) {
|
|
2649
|
+
console.log(
|
|
2650
|
+
`
|
|
2651
|
+
${c.warn("\u26A0")} No default agent configured.
|
|
2652
|
+
${sym.arrow} ${c.dim("Run")} ${c.bold("agc agents list")} ${c.dim("to find an agent ID, then")}
|
|
2653
|
+
${sym.arrow} ${c.dim("Run")} ${c.bold("agc config set defaultAgentId <id>")} ${c.dim("to set a default.")}
|
|
2654
|
+
`
|
|
2655
|
+
);
|
|
2656
|
+
console.log(` ${c.dim("Or pass it directly: ")}${c.bold(`agc ${action} --agent <id>`)}
|
|
2657
|
+
`);
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
runSubcommand(commandMap[action]);
|
|
2661
|
+
}
|
|
2662
|
+
function runSubcommand(args) {
|
|
2663
|
+
const child = (0, import_child_process2.spawn)(process.argv[0], [process.argv[1], ...args], {
|
|
2664
|
+
stdio: "inherit"
|
|
2665
|
+
});
|
|
2666
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
2667
|
+
}
|
|
2471
2668
|
var program = new import_commander16.Command();
|
|
2472
|
-
program.name("agc").description("Agent Commons CLI \u2014 interact with the Agent Commons platform").version("0.1.
|
|
2669
|
+
program.name("agc").description("Agent Commons CLI \u2014 interact with the Agent Commons platform").version("0.1.4", "-v, --version").action(async () => {
|
|
2670
|
+
await interactiveMenu();
|
|
2671
|
+
});
|
|
2473
2672
|
program.addCommand(loginCommand());
|
|
2474
2673
|
program.addCommand(logoutCommand());
|
|
2475
2674
|
program.addCommand(whoamiCommand());
|
|
@@ -2489,8 +2688,12 @@ program.addCommand(memoryCommand());
|
|
|
2489
2688
|
program.addCommand(usageCommand());
|
|
2490
2689
|
program.addCommand(logsCommand());
|
|
2491
2690
|
program.on("command:*", () => {
|
|
2492
|
-
console.error(
|
|
2493
|
-
|
|
2691
|
+
console.error(
|
|
2692
|
+
`
|
|
2693
|
+
${c.error("Unknown command:")} ${program.args.join(" ")}
|
|
2694
|
+
Run ${c.bold("agc --help")} to see available commands, or just ${c.bold("agc")} for the interactive menu.
|
|
2695
|
+
`
|
|
2696
|
+
);
|
|
2494
2697
|
process.exit(1);
|
|
2495
2698
|
});
|
|
2496
2699
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-commons/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Agent Commons CLI — chat, run, and manage agents from your terminal",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"commander": "^12.1.0",
|
|
15
15
|
"chalk": "^5.3.0",
|
|
16
16
|
"ora": "^8.1.1",
|
|
17
|
-
"@agent-commons/sdk": "0.1.
|
|
17
|
+
"@agent-commons/sdk": "0.1.6"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"tsup": "^8.3.5",
|