tmpa-cli 1.0.3 → 1.0.5
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/bin/index.js +48 -32
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -8,11 +8,24 @@ const { execSync } = require('child_process');
|
|
|
8
8
|
|
|
9
9
|
const CONFIG_FILE = path.join(os.homedir(), '.tmpa_config.json');
|
|
10
10
|
|
|
11
|
+
// Color Palette (TrueColor / ANSI Escape Codes)
|
|
12
|
+
const COLOR = {
|
|
13
|
+
reset: '\x1b[0m',
|
|
14
|
+
dim: '\x1b[2m',
|
|
15
|
+
bold: '\x1b[1m',
|
|
16
|
+
cyan: '\x1b[36m',
|
|
17
|
+
blue: '\x1b[38;2;59;130;246m', // #3B82F6
|
|
18
|
+
purple: '\x1b[38;2;168;85;247m', // #A855F7
|
|
19
|
+
green: '\x1b[38;2;34;197;94m', // #22C55E
|
|
20
|
+
yellow: '\x1b[38;2;234;179;8m', // #EAB308
|
|
21
|
+
red: '\x1b[38;2;239;68;68m', // #EF4444
|
|
22
|
+
gray: '\x1b[38;2;100;116;139m' // #64748B
|
|
23
|
+
};
|
|
24
|
+
|
|
11
25
|
function loadConfig() {
|
|
12
26
|
if (fs.existsSync(CONFIG_FILE)) {
|
|
13
27
|
try {
|
|
14
28
|
const data = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
15
|
-
// Pastikan endpoint selalu ada nilainya agar tidak undefined
|
|
16
29
|
if (!data.endpoint) {
|
|
17
30
|
data.endpoint = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent';
|
|
18
31
|
}
|
|
@@ -30,17 +43,21 @@ function saveConfig(config) {
|
|
|
30
43
|
|
|
31
44
|
function showBanner() {
|
|
32
45
|
console.clear();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
██║
|
|
38
|
-
██║
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
|
|
47
|
+
// ASCII Art Banner with Blue-to-Purple Gradient Effect
|
|
48
|
+
const line1 = `${COLOR.blue} ████████╗███╗ ███╗██████╗ █████╗ ${COLOR.reset}`;
|
|
49
|
+
const line2 = `${COLOR.blue} ╚══██╔══╝████╗ ████║██╔══██╗██╔══██╗${COLOR.reset}`;
|
|
50
|
+
const line3 = `${COLOR.blue} ██║ ██╔████╔██║██████╔╝███████║${COLOR.reset}`;
|
|
51
|
+
const line4 = `${COLOR.purple} ██║ ██║╚██╔╝██║██╔═══╝ ██╔══██║${COLOR.reset}`;
|
|
52
|
+
const line5 = `${COLOR.purple} ██║ ██║ ╚═╝ ██║██║ ██║ ██║${COLOR.reset}`;
|
|
53
|
+
const line6 = `${COLOR.purple} ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝${COLOR.reset}`;
|
|
54
|
+
|
|
55
|
+
console.log(`\n${line1}\n${line2}\n${line3}\n${line4}\n${line5}\n${line6}`);
|
|
56
|
+
console.log(`${COLOR.gray}───────────────────────────────────────────────────${COLOR.reset}`);
|
|
57
|
+
console.log(` ${COLOR.green}The Multi Platform AI [Interactive Mode]${COLOR.reset}`);
|
|
58
|
+
console.log(` ${COLOR.gray}/config${COLOR.reset} : Set API Key | ${COLOR.gray}/connect${COLOR.reset} : Connect Web`);
|
|
59
|
+
console.log(` ${COLOR.gray}/uninstall${COLOR.reset} : Remove CLI | ${COLOR.gray}/exit${COLOR.reset} : Exit Session`);
|
|
60
|
+
console.log(`${COLOR.gray}───────────────────────────────────────────────────${COLOR.reset}\n`);
|
|
44
61
|
}
|
|
45
62
|
|
|
46
63
|
const rl = readline.createInterface({
|
|
@@ -51,12 +68,12 @@ const rl = readline.createInterface({
|
|
|
51
68
|
let config = loadConfig();
|
|
52
69
|
|
|
53
70
|
function askConfig(callback) {
|
|
54
|
-
rl.question(
|
|
55
|
-
rl.question(
|
|
71
|
+
rl.question(`${COLOR.yellow}[>] Enter API Key:${COLOR.reset} `, (apiKey) => {
|
|
72
|
+
rl.question(`${COLOR.yellow}[>] Enter Endpoint URL (Press Enter for Default Gemini):${COLOR.reset} `, (endpoint) => {
|
|
56
73
|
config.apiKey = apiKey.trim();
|
|
57
74
|
config.endpoint = endpoint.trim() || 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent';
|
|
58
75
|
saveConfig(config);
|
|
59
|
-
console.log(
|
|
76
|
+
console.log(`${COLOR.green}[+] Configuration saved successfully!${COLOR.reset}\n`);
|
|
60
77
|
if (callback) callback();
|
|
61
78
|
});
|
|
62
79
|
});
|
|
@@ -64,16 +81,15 @@ function askConfig(callback) {
|
|
|
64
81
|
|
|
65
82
|
async function handleChat(prompt) {
|
|
66
83
|
if (!config.apiKey) {
|
|
67
|
-
console.log(
|
|
84
|
+
console.log(`${COLOR.yellow}[!] API Key is not set.${COLOR.reset}`);
|
|
68
85
|
return askConfig(() => startPrompt());
|
|
69
86
|
}
|
|
70
87
|
|
|
71
|
-
// Pastikan endpoint aman dari undefined
|
|
72
88
|
if (!config.endpoint) {
|
|
73
89
|
config.endpoint = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent';
|
|
74
90
|
}
|
|
75
91
|
|
|
76
|
-
console.log(
|
|
92
|
+
console.log(`${COLOR.yellow}TMPA CLI processing...${COLOR.reset}`);
|
|
77
93
|
|
|
78
94
|
try {
|
|
79
95
|
const url = config.endpoint.includes('googleapis.com')
|
|
@@ -91,7 +107,7 @@ async function handleChat(prompt) {
|
|
|
91
107
|
});
|
|
92
108
|
|
|
93
109
|
const data = await response.json();
|
|
94
|
-
let reply = '
|
|
110
|
+
let reply = 'No response from server.';
|
|
95
111
|
|
|
96
112
|
if (data.candidates && data.candidates[0]?.content?.parts[0]?.text) {
|
|
97
113
|
reply = data.candidates[0].content.parts[0].text;
|
|
@@ -101,43 +117,43 @@ async function handleChat(prompt) {
|
|
|
101
117
|
reply = data.message;
|
|
102
118
|
}
|
|
103
119
|
|
|
104
|
-
console.log(`\n
|
|
120
|
+
console.log(`\n${COLOR.blue}TMPA CLI :${COLOR.reset} ${reply}\n`);
|
|
105
121
|
} catch (error) {
|
|
106
|
-
console.log(`\n
|
|
122
|
+
console.log(`\n${COLOR.red}[x] Error: ${error.message}${COLOR.reset}\n`);
|
|
107
123
|
}
|
|
108
124
|
|
|
109
125
|
startPrompt();
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
function handleUninstall() {
|
|
113
|
-
rl.question(
|
|
114
|
-
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === '
|
|
115
|
-
console.log(
|
|
129
|
+
rl.question(`${COLOR.red}[!] Are you sure you want to uninstall TMPA CLI? (y/N):${COLOR.reset} `, (answer) => {
|
|
130
|
+
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
|
|
131
|
+
console.log(`\n${COLOR.yellow}[...] Removing TMPA CLI and cleaning configuration...${COLOR.reset}`);
|
|
116
132
|
try {
|
|
117
133
|
if (fs.existsSync(CONFIG_FILE)) {
|
|
118
134
|
fs.unlinkSync(CONFIG_FILE);
|
|
119
135
|
}
|
|
120
|
-
console.log(
|
|
136
|
+
console.log(`${COLOR.green}[+] Local configuration cleared.${COLOR.reset}`);
|
|
121
137
|
execSync('npm uninstall -g tmpa-cli', { stdio: 'inherit' });
|
|
122
|
-
console.log(
|
|
138
|
+
console.log(`\n${COLOR.green}[+] TMPA CLI uninstalled successfully. Goodbye!${COLOR.reset}\n`);
|
|
123
139
|
process.exit(0);
|
|
124
140
|
} catch (err) {
|
|
125
|
-
console.log(
|
|
141
|
+
console.log(`\n${COLOR.red}[x] Failed to uninstall automatically. Run: npm uninstall -g tmpa-cli manually.${COLOR.reset}\n`);
|
|
126
142
|
process.exit(0);
|
|
127
143
|
}
|
|
128
144
|
} else {
|
|
129
|
-
console.log(
|
|
145
|
+
console.log(`${COLOR.gray}Uninstall process cancelled.${COLOR.reset}\n`);
|
|
130
146
|
startPrompt();
|
|
131
147
|
}
|
|
132
148
|
});
|
|
133
149
|
}
|
|
134
150
|
|
|
135
151
|
function startPrompt() {
|
|
136
|
-
rl.question(
|
|
152
|
+
rl.question(`${COLOR.cyan}TMPA >${COLOR.reset} `, (input) => {
|
|
137
153
|
const cmd = input.trim();
|
|
138
154
|
|
|
139
155
|
if (cmd === '/exit') {
|
|
140
|
-
console.log(
|
|
156
|
+
console.log(`${COLOR.gray}Goodbye!${COLOR.reset}`);
|
|
141
157
|
process.exit(0);
|
|
142
158
|
} else if (cmd === '/clear') {
|
|
143
159
|
showBanner();
|
|
@@ -145,7 +161,7 @@ function startPrompt() {
|
|
|
145
161
|
} else if (cmd === '/config') {
|
|
146
162
|
askConfig(() => startPrompt());
|
|
147
163
|
} else if (cmd === '/connect') {
|
|
148
|
-
console.log(
|
|
164
|
+
console.log(`\n${COLOR.purple}[!] [COMING SOON] Web integration & auth login features will be available in the next release.${COLOR.reset}\n`);
|
|
149
165
|
startPrompt();
|
|
150
166
|
} else if (cmd === '/uninstall') {
|
|
151
167
|
handleUninstall();
|
|
@@ -157,7 +173,7 @@ function startPrompt() {
|
|
|
157
173
|
});
|
|
158
174
|
}
|
|
159
175
|
|
|
160
|
-
//
|
|
176
|
+
// Program Entry Point
|
|
161
177
|
showBanner();
|
|
162
178
|
if (!config.apiKey) {
|
|
163
179
|
askConfig(() => startPrompt());
|