tmpa-cli 1.0.6 → 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 +16 -28
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -8,13 +8,12 @@ const { execSync } = require('child_process');
|
|
|
8
8
|
|
|
9
9
|
const CONFIG_FILE = path.join(os.homedir(), '.tmpa_config.json');
|
|
10
10
|
|
|
11
|
-
// Exact RGB Gradient Colors (Cyan -> Light Blue -> Deep Blue -> Purple)
|
|
12
11
|
const C = {
|
|
13
12
|
reset: '\x1b[0m',
|
|
14
|
-
c1: '\x1b[38;2;0;210;255m',
|
|
15
|
-
c2: '\x1b[38;2;30;144;255m',
|
|
16
|
-
c3: '\x1b[38;2;99;102;241m',
|
|
17
|
-
c4: '\x1b[38;2;168;85;247m',
|
|
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',
|
|
18
17
|
green: '\x1b[38;2;34;197;94m',
|
|
19
18
|
cyan: '\x1b[38;2;6x;182;212m',
|
|
20
19
|
yellow: '\x1b[38;2;234;179;8m',
|
|
@@ -26,11 +25,7 @@ const C = {
|
|
|
26
25
|
function loadConfig() {
|
|
27
26
|
if (fs.existsSync(CONFIG_FILE)) {
|
|
28
27
|
try {
|
|
29
|
-
|
|
30
|
-
if (!data.endpoint) {
|
|
31
|
-
data.endpoint = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent';
|
|
32
|
-
}
|
|
33
|
-
return data;
|
|
28
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
34
29
|
} catch (e) {
|
|
35
30
|
return {};
|
|
36
31
|
}
|
|
@@ -44,8 +39,6 @@ function saveConfig(config) {
|
|
|
44
39
|
|
|
45
40
|
function showBanner() {
|
|
46
41
|
console.clear();
|
|
47
|
-
|
|
48
|
-
// Exact Banner matching the image structure
|
|
49
42
|
console.log(`
|
|
50
43
|
${C.c1}████████╗███╗ ███╗██████╗ █████╗ ${C.reset}
|
|
51
44
|
${C.c2}╚══██╔══╝████╗ ████║██╔══██╗██╔══██╗${C.reset}
|
|
@@ -85,18 +78,16 @@ async function handleChat(prompt) {
|
|
|
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
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,19 +98,16 @@ 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${C.c1}TMPA CLI :${C.reset} ${reply}\n`);
|
|
121
109
|
} catch (error) {
|
|
122
|
-
console.log(`\n${C.red}[x] Error: ${error.message}${C.reset}\n`);
|
|
110
|
+
console.log(`\n${C.red}[x] Fetch Error: ${error.message}${C.reset}\n`);
|
|
123
111
|
}
|
|
124
112
|
|
|
125
113
|
startPrompt();
|