forked from zaber-dev/free-ai-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
100 lines (84 loc) · 3.36 KB
/
Copy pathcli.ts
File metadata and controls
100 lines (84 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { promptCommand, PromptOptions } from "./commands/prompt";
import { chatCommand, ChatOptions } from "./commands/chat";
import { listModelsCommand } from "./commands/models";
import { doctorCommand } from "./commands/doctor";
import { skillsCommand } from "./commands/skills";
export function printHelp(): void {
console.log(`
⚡ Free-AI Gateway CLI (free-ai / freeai)
Usage:
free-ai <command> [options]
free-ai "<prompt>" [options]
Commands:
prompt <query> Execute a one-off AI prompt with automatic capability routing
chat Launch an interactive terminal chat REPL session
models List all discovered models, providers, and supported capabilities
doctor / health Perform diagnostics and check configured API keys
skills <list|install> Manage and install agentic IDE skills (Antigravity, Cursor, Claude)
Options:
--capability=<cap> Required capability (e.g. text, reasoning, code, vision, tool_calling)
--provider=<id> Force preferred provider (e.g. groq, google, sambanova, openrouter)
--model=<id> Force preferred model identifier
--help, -h Show this help manual
--version, -v Display CLI version
Examples:
free-ai "Explain quantum computing in one sentence"
free-ai prompt "Write a quicksort in TypeScript" --capability=code
free-ai chat --capability=reasoning
free-ai models
free-ai doctor
free-ai skills install --target=antigravity
`);
}
export async function runCli(argv: string[] = process.argv.slice(2)): Promise<void> {
const command = argv[0];
if (!command || command === "--help" || command === "-h" || command === "help") {
printHelp();
return;
}
if (command === "--version" || command === "-v" || command === "version") {
console.log("free-ai-gateway/cli v1.0.0");
return;
}
if (command === "models") {
listModelsCommand();
return;
}
if (command === "doctor" || command === "health") {
doctorCommand();
return;
}
if (command === "skills") {
skillsCommand(argv.slice(1));
return;
}
if (command === "chat") {
const chatOpts: ChatOptions = {};
for (const arg of argv.slice(1)) {
if (arg.startsWith("--capability=")) chatOpts.capability = arg.replace("--capability=", "");
if (arg.startsWith("--provider=")) chatOpts.provider = arg.replace("--provider=", "");
if (arg.startsWith("--model=")) chatOpts.model = arg.replace("--model=", "");
}
await chatCommand(chatOpts);
return;
}
if (command === "prompt" || !command.startsWith("-")) {
const promptText = command === "prompt" ? argv[1] : command;
if (!promptText) {
console.error("❌ Error: Missing prompt text. Run 'free-ai --help' for usage.");
process.exitCode = 1;
return;
}
const promptOpts: PromptOptions = {};
const remainingArgs = command === "prompt" ? argv.slice(2) : argv.slice(1);
for (const arg of remainingArgs) {
if (arg.startsWith("--capability=")) promptOpts.capability = arg.replace("--capability=", "");
if (arg.startsWith("--provider=")) promptOpts.provider = arg.replace("--provider=", "");
if (arg.startsWith("--model=")) promptOpts.model = arg.replace("--model=", "");
}
await promptCommand(promptText, promptOpts);
return;
}
console.error(`❌ Unknown command: "${command}". Run "free-ai --help" for usage.`);
process.exitCode = 1;
}