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