@astrive-ai/cli 1.0.1

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.
Files changed (67) hide show
  1. package/dist/bin.d.ts +3 -0
  2. package/dist/bin.d.ts.map +1 -0
  3. package/dist/bin.js +4 -0
  4. package/dist/bin.js.map +1 -0
  5. package/dist/cli.d.ts +20 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +74 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/commands/chat.d.ts +8 -0
  10. package/dist/commands/chat.d.ts.map +1 -0
  11. package/dist/commands/chat.js +84 -0
  12. package/dist/commands/chat.js.map +1 -0
  13. package/dist/commands/dev.d.ts +7 -0
  14. package/dist/commands/dev.d.ts.map +1 -0
  15. package/dist/commands/dev.js +51 -0
  16. package/dist/commands/dev.js.map +1 -0
  17. package/dist/commands/doctor.d.ts +7 -0
  18. package/dist/commands/doctor.d.ts.map +1 -0
  19. package/dist/commands/doctor.js +46 -0
  20. package/dist/commands/doctor.js.map +1 -0
  21. package/dist/commands/init.d.ts +7 -0
  22. package/dist/commands/init.d.ts.map +1 -0
  23. package/dist/commands/init.js +56 -0
  24. package/dist/commands/init.js.map +1 -0
  25. package/dist/commands/inspect.d.ts +7 -0
  26. package/dist/commands/inspect.d.ts.map +1 -0
  27. package/dist/commands/inspect.js +24 -0
  28. package/dist/commands/inspect.js.map +1 -0
  29. package/dist/commands/plugins.d.ts +7 -0
  30. package/dist/commands/plugins.d.ts.map +1 -0
  31. package/dist/commands/plugins.js +32 -0
  32. package/dist/commands/plugins.js.map +1 -0
  33. package/dist/commands/tools.d.ts +7 -0
  34. package/dist/commands/tools.d.ts.map +1 -0
  35. package/dist/commands/tools.js +42 -0
  36. package/dist/commands/tools.js.map +1 -0
  37. package/dist/commands/version.d.ts +8 -0
  38. package/dist/commands/version.d.ts.map +1 -0
  39. package/dist/commands/version.js +23 -0
  40. package/dist/commands/version.js.map +1 -0
  41. package/dist/index.d.ts +4 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +7 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/parser.d.ts +6 -0
  46. package/dist/parser.d.ts.map +1 -0
  47. package/dist/parser.js +43 -0
  48. package/dist/parser.js.map +1 -0
  49. package/dist/ui.d.ts +32 -0
  50. package/dist/ui.d.ts.map +1 -0
  51. package/dist/ui.js +95 -0
  52. package/dist/ui.js.map +1 -0
  53. package/package.json +29 -0
  54. package/src/bin.ts +3 -0
  55. package/src/cli.ts +97 -0
  56. package/src/commands/chat.ts +94 -0
  57. package/src/commands/dev.ts +61 -0
  58. package/src/commands/doctor.ts +50 -0
  59. package/src/commands/init.ts +64 -0
  60. package/src/commands/inspect.ts +28 -0
  61. package/src/commands/plugins.ts +35 -0
  62. package/src/commands/tools.ts +47 -0
  63. package/src/commands/version.ts +25 -0
  64. package/src/index.ts +8 -0
  65. package/src/parser.ts +41 -0
  66. package/src/ui.ts +109 -0
  67. package/tsconfig.json +8 -0
@@ -0,0 +1,35 @@
1
+ import { Command } from '../cli.js';
2
+ import { table, info } from '../ui.js';
3
+ import * as BuiltInPlugins from '@astrive-ai/plugins';
4
+
5
+ export class PluginsCommand implements Command {
6
+ name = 'plugins';
7
+ description = 'Manage plugins';
8
+
9
+ async execute(args: string[], flags: Record<string, string>): Promise<void> {
10
+ info('Available Built-in AstriveAI Plugins:');
11
+
12
+ const pluginsData: string[][] = [];
13
+
14
+ // Assuming @astrive-ai/plugins exports plugin classes
15
+ for (const key of Object.keys(BuiltInPlugins)) {
16
+ const PluginClass = (BuiltInPlugins as any)[key];
17
+ if (typeof PluginClass === 'function' && PluginClass.prototype) {
18
+ try {
19
+ const instance = new PluginClass();
20
+ pluginsData.push([instance.name || key, instance.version || '1.0.0', 'Built-in plugin']);
21
+ } catch (e) {
22
+ // ignore instantiation errors
23
+ }
24
+ }
25
+ }
26
+
27
+ console.log();
28
+ if (pluginsData.length === 0) {
29
+ info('No built-in plugins found.');
30
+ } else {
31
+ table(['Name', 'Version', 'Description'], pluginsData);
32
+ }
33
+ console.log();
34
+ }
35
+ }
@@ -0,0 +1,47 @@
1
+ import { Command } from '../cli.js';
2
+ import { table, info } from '../ui.js';
3
+ import * as BuiltInTools from '@astrive-ai/tools';
4
+
5
+ export class ToolsCommand implements Command {
6
+ name = 'tools';
7
+ description = 'List available tools';
8
+
9
+ async execute(args: string[], flags: Record<string, string>): Promise<void> {
10
+ info('Registered AstriveAI Tools:');
11
+
12
+ const toolClasses = [
13
+ BuiltInTools.DownloaderTool,
14
+ BuiltInTools.VisionTool,
15
+ BuiltInTools.TextToImageTool,
16
+ BuiltInTools.RemoveBGTool,
17
+ BuiltInTools.UpscalerTool,
18
+ BuiltInTools.OCRTool,
19
+ BuiltInTools.FaceSwapTool,
20
+ BuiltInTools.Img2ImgTool,
21
+ BuiltInTools.TextToSpeechTool,
22
+ BuiltInTools.SpeechToTextTool,
23
+ BuiltInTools.WebSearchTool,
24
+ BuiltInTools.FilesystemTool,
25
+ BuiltInTools.TerminalTool,
26
+ BuiltInTools.GitTool,
27
+ ];
28
+
29
+ const toolsData: string[][] = [];
30
+
31
+ for (const ToolClass of toolClasses) {
32
+ if (ToolClass) {
33
+ try {
34
+ const instance = new ToolClass();
35
+ const def = instance.definition;
36
+ toolsData.push([def.function.name, def.function.description || 'No description', 'builtin']);
37
+ } catch (e) {
38
+ // ignore instantiation errors
39
+ }
40
+ }
41
+ }
42
+
43
+ console.log();
44
+ table(['Name', 'Description', 'Category'], toolsData);
45
+ console.log();
46
+ }
47
+ }
@@ -0,0 +1,25 @@
1
+ import { Command } from '../cli.js';
2
+ import { info, bold } from '../ui.js';
3
+ import * as fs from 'fs/promises';
4
+ import { fileURLToPath } from 'url';
5
+ import * as path from 'path';
6
+
7
+ export class VersionCommand implements Command {
8
+ name = 'version';
9
+ description = 'Show version information';
10
+ aliases = ['-v', '--version'];
11
+
12
+ async execute(args: string[], flags: Record<string, string>): Promise<void> {
13
+ try {
14
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
+ const pkgPath = path.resolve(__dirname, '../../package.json');
16
+ const pkgData = await fs.readFile(pkgPath, 'utf-8');
17
+ const pkg = JSON.parse(pkgData);
18
+
19
+ console.log(`${bold('AstriveAI CLI')} v${pkg.version}`);
20
+ console.log(`Node.js ${process.version}`);
21
+ } catch (err) {
22
+ info('AstriveAI CLI version unknown (could not read package.json)');
23
+ }
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { CLI } from './cli.js';
2
+ export type { Command, Flag } from './cli.js';
3
+ import { CLI } from './cli.js';
4
+
5
+ export async function run(args: string[]): Promise<void> {
6
+ const cli = new CLI();
7
+ await cli.run(args);
8
+ }
package/src/parser.ts ADDED
@@ -0,0 +1,41 @@
1
+ export function parseArgs(args: string[]): { command: string; positional: string[]; flags: Record<string, string> } {
2
+ const command = args.length > 0 && !args[0].startsWith('-') ? args[0] : '';
3
+ const remaining = command ? args.slice(1) : args;
4
+
5
+ const positional: string[] = [];
6
+ const flags: Record<string, string> = {};
7
+
8
+ for (let i = 0; i < remaining.length; i++) {
9
+ const arg = remaining[i];
10
+
11
+ if (arg.startsWith('--')) {
12
+ const eqIdx = arg.indexOf('=');
13
+ if (eqIdx !== -1) {
14
+ const key = arg.slice(2, eqIdx);
15
+ const value = arg.slice(eqIdx + 1);
16
+ flags[key] = value;
17
+ } else {
18
+ const key = arg.slice(2);
19
+ // Check if next arg is a value or another flag
20
+ if (i + 1 < remaining.length && !remaining[i + 1].startsWith('-')) {
21
+ flags[key] = remaining[i + 1];
22
+ i++; // Skip the value
23
+ } else {
24
+ flags[key] = 'true';
25
+ }
26
+ }
27
+ } else if (arg.startsWith('-')) {
28
+ const key = arg.slice(1);
29
+ if (i + 1 < remaining.length && !remaining[i + 1].startsWith('-')) {
30
+ flags[key] = remaining[i + 1];
31
+ i++;
32
+ } else {
33
+ flags[key] = 'true';
34
+ }
35
+ } else {
36
+ positional.push(arg);
37
+ }
38
+ }
39
+
40
+ return { command, positional, flags };
41
+ }
package/src/ui.ts ADDED
@@ -0,0 +1,109 @@
1
+ export const Colors = {
2
+ reset: "\x1b[0m",
3
+ bold: "\x1b[1m",
4
+ dim: "\x1b[2m",
5
+ red: "\x1b[31m",
6
+ green: "\x1b[32m",
7
+ yellow: "\x1b[33m",
8
+ blue: "\x1b[34m",
9
+ magenta: "\x1b[35m",
10
+ cyan: "\x1b[36m",
11
+ white: "\x1b[37m",
12
+ };
13
+
14
+ export function bold(text: string): string {
15
+ return `${Colors.bold}${text}${Colors.reset}`;
16
+ }
17
+
18
+ export function dim(text: string): string {
19
+ return `${Colors.dim}${text}${Colors.reset}`;
20
+ }
21
+
22
+ export function success(msg: string): void {
23
+ console.log(`${Colors.green}✔${Colors.reset} ${msg}`);
24
+ }
25
+
26
+ export function error(msg: string): void {
27
+ console.log(`${Colors.red}✖${Colors.reset} ${msg}`);
28
+ }
29
+
30
+ export function warning(msg: string): void {
31
+ console.log(`${Colors.yellow}⚠${Colors.reset} ${msg}`);
32
+ }
33
+
34
+ export function info(msg: string): void {
35
+ console.log(`${Colors.cyan}ℹ${Colors.reset} ${msg}`);
36
+ }
37
+
38
+ export function banner(): void {
39
+ console.log(`
40
+ ${Colors.cyan}${Colors.bold}
41
+ ___ __ _
42
+ / _ | ___ / /_ ____(_) _____
43
+ / __ |(_-</ __/ __/ / |/ / -_)
44
+ /_/ |_/___/\\__/_/ /_/|___/\\__/
45
+ ${Colors.reset}
46
+ `);
47
+ }
48
+
49
+ export function divider(): void {
50
+ console.log(dim('----------------------------------------'));
51
+ }
52
+
53
+ export function table(headers: string[], rows: string[][]): void {
54
+ const colWidths = headers.map(h => h.length);
55
+ rows.forEach(row => {
56
+ row.forEach((cell, i) => {
57
+ colWidths[i] = Math.max(colWidths[i], String(cell).length);
58
+ });
59
+ });
60
+
61
+ const printRow = (row: string[], isHeader = false) => {
62
+ const formatted = row.map((cell, i) => {
63
+ const padded = String(cell).padEnd(colWidths[i] + 2);
64
+ return isHeader ? bold(padded) : padded;
65
+ }).join('');
66
+ console.log(formatted);
67
+ };
68
+
69
+ printRow(headers, true);
70
+ divider();
71
+ rows.forEach(row => printRow(row));
72
+ }
73
+
74
+ export class Spinner {
75
+ private frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
76
+ private currentFrame = 0;
77
+ private timer: NodeJS.Timeout | null = null;
78
+ private message = '';
79
+
80
+ start(msg: string): void {
81
+ this.message = msg;
82
+ if (this.timer) clearInterval(this.timer);
83
+
84
+ this.timer = setInterval(() => {
85
+ process.stdout.write(`\r${Colors.cyan}${this.frames[this.currentFrame]}${Colors.reset} ${this.message}`);
86
+ this.currentFrame = (this.currentFrame + 1) % this.frames.length;
87
+ }, 80);
88
+ }
89
+
90
+ stop(msg?: string): void {
91
+ if (this.timer) {
92
+ clearInterval(this.timer);
93
+ this.timer = null;
94
+ }
95
+ if (msg) {
96
+ process.stdout.write(`\r${msg}\n`);
97
+ } else {
98
+ process.stdout.write('\r\x1b[K'); // clear line
99
+ }
100
+ }
101
+
102
+ succeed(msg: string): void {
103
+ this.stop(`${Colors.green}✔${Colors.reset} ${msg}`);
104
+ }
105
+
106
+ fail(msg: string): void {
107
+ this.stop(`${Colors.red}✖${Colors.reset} ${msg}`);
108
+ }
109
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"]
8
+ }