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.
Files changed (2) hide show
  1. package/bin/index.js +50 -62
  2. 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
- // Color Palette (TrueColor / ANSI Escape Codes)
12
- const COLOR = {
11
+ const C = {
13
12
  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
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
- const data = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
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
- // 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`);
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(`${COLOR.yellow}[>] Enter API Key:${COLOR.reset} `, (apiKey) => {
72
- rl.question(`${COLOR.yellow}[>] Enter Endpoint URL (Press Enter for Default Gemini):${COLOR.reset} `, (endpoint) => {
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(`${COLOR.green}[+] Configuration saved successfully!${COLOR.reset}\n`);
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(`${COLOR.yellow}[!] API Key is not set.${COLOR.reset}`);
77
+ console.log(`${C.yellow}[!] API Key is not set.${C.reset}`);
85
78
  return askConfig(() => startPrompt());
86
79
  }
87
80
 
88
- if (!config.endpoint) {
89
- config.endpoint = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent';
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(`${COLOR.yellow}TMPA CLI processing...${COLOR.reset}`);
84
+ console.log(`${C.yellow}TMPA CLI processing...${C.reset}`);
93
85
 
94
86
  try {
95
- const url = config.endpoint.includes('googleapis.com')
96
- ? `${config.endpoint}?key=${config.apiKey}`
97
- : config.endpoint;
87
+ const isGoogle = targetEndpoint.includes('googleapis.com');
88
+ const url = isGoogle ? `${targetEndpoint}?key=${config.apiKey}` : targetEndpoint;
98
89
 
99
- const bodyData = config.endpoint.includes('googleapis.com')
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
- reply = data.candidates[0].content.parts[0].text;
114
- } else if (data.reply) {
115
- reply = data.reply;
116
- } else if (data.message) {
117
- reply = data.message;
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${COLOR.red}[x] Error: ${error.message}${COLOR.reset}\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(`${COLOR.red}[!] Are you sure you want to uninstall TMPA CLI? (y/N):${COLOR.reset} `, (answer) => {
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${COLOR.yellow}[...] Removing TMPA CLI and cleaning configuration...${COLOR.reset}`);
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(`${COLOR.green}[+] Local configuration cleared.${COLOR.reset}`);
124
+ console.log(`${C.green}[+] Local configuration cleared.${C.reset}`);
137
125
  execSync('npm uninstall -g tmpa-cli', { stdio: 'inherit' });
138
- console.log(`\n${COLOR.green}[+] TMPA CLI uninstalled successfully. Goodbye!${COLOR.reset}\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${COLOR.red}[x] Failed to uninstall automatically. Run: npm uninstall -g tmpa-cli manually.${COLOR.reset}\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(`${COLOR.gray}Uninstall process cancelled.${COLOR.reset}\n`);
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(`${COLOR.cyan}TMPA >${COLOR.reset} `, (input) => {
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(`${COLOR.gray}Goodbye!${COLOR.reset}`);
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${COLOR.purple}[!] [COMING SOON] Web integration & auth login features will be available in the next release.${COLOR.reset}\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 Entry Point
164
+ // Program Execution
177
165
  showBanner();
178
166
  if (!config.apiKey) {
179
167
  askConfig(() => startPrompt());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmpa-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "bin": {