enton-cli 0.1.0 ā 0.1.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.
- package/dist/commands/interactive.js +109 -10
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ exports.interactiveMode = interactiveMode;
|
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
11
|
const ora_1 = __importDefault(require("ora"));
|
|
12
12
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
13
|
+
const open_1 = __importDefault(require("open"));
|
|
13
14
|
const client_1 = require("../api/client");
|
|
14
15
|
const manager_1 = require("../config/manager");
|
|
15
16
|
async function interactiveMode(options) {
|
|
@@ -104,6 +105,16 @@ async function handleCommand(command, client) {
|
|
|
104
105
|
case 'clear':
|
|
105
106
|
console.clear();
|
|
106
107
|
break;
|
|
108
|
+
case 'login':
|
|
109
|
+
await handleLogin();
|
|
110
|
+
break;
|
|
111
|
+
case 'logout':
|
|
112
|
+
await handleLogout();
|
|
113
|
+
break;
|
|
114
|
+
case 'key':
|
|
115
|
+
case 'apikey':
|
|
116
|
+
await showApiKeyHelp();
|
|
117
|
+
break;
|
|
107
118
|
case 'history':
|
|
108
119
|
console.log(chalk_1.default.dim('Command history not yet implemented'));
|
|
109
120
|
break;
|
|
@@ -118,26 +129,114 @@ async function handleCommand(command, client) {
|
|
|
118
129
|
function showHelp() {
|
|
119
130
|
console.log(`
|
|
120
131
|
${chalk_1.default.bold('Available Commands:')}
|
|
121
|
-
${chalk_1.default.cyan('/
|
|
122
|
-
${chalk_1.default.cyan('/
|
|
132
|
+
${chalk_1.default.cyan('/login')} - Login to ENTON (opens browser)
|
|
133
|
+
${chalk_1.default.cyan('/logout')} - Logout and clear API key
|
|
134
|
+
${chalk_1.default.cyan('/key')} - Show API key setup help
|
|
123
135
|
${chalk_1.default.cyan('/status')} - Show connection status
|
|
124
|
-
${chalk_1.default.cyan('/
|
|
136
|
+
${chalk_1.default.cyan('/clear')} - Clear the screen
|
|
137
|
+
${chalk_1.default.cyan('/help')} - Show this help message
|
|
125
138
|
|
|
126
139
|
${chalk_1.default.bold('Query Examples:')}
|
|
127
|
-
${chalk_1.default.dim('
|
|
128
|
-
${chalk_1.default.dim('
|
|
129
|
-
${chalk_1.default.dim('
|
|
130
|
-
${chalk_1.default.dim('
|
|
131
|
-
${chalk_1.default.dim('
|
|
140
|
+
${chalk_1.default.dim('price of AAPL')}
|
|
141
|
+
${chalk_1.default.dim('news about Tesla')}
|
|
142
|
+
${chalk_1.default.dim('analyze NVDA')}
|
|
143
|
+
${chalk_1.default.dim('show my portfolio')}
|
|
144
|
+
${chalk_1.default.dim('buy 10 shares of MSFT')}
|
|
132
145
|
|
|
133
146
|
${chalk_1.default.bold('Exit:')}
|
|
134
147
|
Type ${chalk_1.default.cyan('exit')}, ${chalk_1.default.cyan('quit')}, or ${chalk_1.default.cyan('q')}
|
|
135
148
|
`);
|
|
136
149
|
}
|
|
150
|
+
async function handleLogin() {
|
|
151
|
+
console.log(chalk_1.default.bold('\nš Login to ENTON\n'));
|
|
152
|
+
const config = (0, manager_1.getConfig)();
|
|
153
|
+
const developerUrl = `${config.apiUrl}/developer`;
|
|
154
|
+
console.log(chalk_1.default.dim('Opening browser to get your API key...\n'));
|
|
155
|
+
try {
|
|
156
|
+
await (0, open_1.default)(developerUrl);
|
|
157
|
+
console.log(chalk_1.default.cyan(`If browser doesn't open, visit:\n${developerUrl}\n`));
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
console.log(chalk_1.default.cyan(`Open this URL in your browser:\n${developerUrl}\n`));
|
|
161
|
+
}
|
|
162
|
+
console.log(chalk_1.default.bold('Steps:'));
|
|
163
|
+
console.log(' 1. Sign in if prompted');
|
|
164
|
+
console.log(' 2. Click "Create API Key"');
|
|
165
|
+
console.log(' 3. Copy your key (starts with ent_live_ or ent_test_)\n');
|
|
166
|
+
const { apiKey } = await inquirer_1.default.prompt([
|
|
167
|
+
{
|
|
168
|
+
type: 'password',
|
|
169
|
+
name: 'apiKey',
|
|
170
|
+
message: 'Paste your API key:',
|
|
171
|
+
mask: '*',
|
|
172
|
+
validate: (input) => {
|
|
173
|
+
if (!input)
|
|
174
|
+
return 'API key is required';
|
|
175
|
+
if (!input.startsWith('ent_'))
|
|
176
|
+
return 'API key should start with ent_live_ or ent_test_';
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
]);
|
|
181
|
+
const spinner = (0, ora_1.default)('Verifying API key...').start();
|
|
182
|
+
try {
|
|
183
|
+
// Save the key
|
|
184
|
+
await (0, manager_1.saveApiKey)(apiKey);
|
|
185
|
+
// Test it
|
|
186
|
+
const client = new client_1.EntonAPIClient(config.apiUrl, apiKey);
|
|
187
|
+
await client.query('hello', { stream: false });
|
|
188
|
+
spinner.succeed(chalk_1.default.green('Successfully logged in!'));
|
|
189
|
+
console.log(chalk_1.default.dim('\nYour API key is saved. You can now use ENTON.\n'));
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
spinner.fail(chalk_1.default.red('Login failed'));
|
|
193
|
+
console.log(chalk_1.default.dim(` ${error.message}\n`));
|
|
194
|
+
console.log(chalk_1.default.dim('Make sure you copied the full API key from enton.ai/developer\n'));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function handleLogout() {
|
|
198
|
+
const { confirm } = await inquirer_1.default.prompt([
|
|
199
|
+
{
|
|
200
|
+
type: 'confirm',
|
|
201
|
+
name: 'confirm',
|
|
202
|
+
message: 'Are you sure you want to logout?',
|
|
203
|
+
default: false
|
|
204
|
+
}
|
|
205
|
+
]);
|
|
206
|
+
if (confirm) {
|
|
207
|
+
await (0, manager_1.deleteApiKey)();
|
|
208
|
+
console.log(chalk_1.default.green('\nā
Logged out successfully\n'));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function showApiKeyHelp() {
|
|
212
|
+
const config = (0, manager_1.getConfig)();
|
|
213
|
+
console.log(`
|
|
214
|
+
${chalk_1.default.bold('š API Key Setup')}
|
|
215
|
+
|
|
216
|
+
${chalk_1.default.bold('Option 1: Interactive login')}
|
|
217
|
+
Type ${chalk_1.default.cyan('/login')} to open browser and authenticate
|
|
218
|
+
|
|
219
|
+
${chalk_1.default.bold('Option 2: Environment variable')}
|
|
220
|
+
${chalk_1.default.dim('export ENTON_API_KEY=ent_live_xxxxxxxxxxxxx')}
|
|
221
|
+
|
|
222
|
+
${chalk_1.default.bold('Option 3: Config file')}
|
|
223
|
+
Your config is stored at: ${chalk_1.default.cyan('~/.enton/config.json')}
|
|
224
|
+
|
|
225
|
+
${chalk_1.default.bold('Get your API key:')}
|
|
226
|
+
Visit ${chalk_1.default.cyan(`${config.apiUrl}/developer`)} to create API keys
|
|
227
|
+
|
|
228
|
+
${chalk_1.default.bold('Current status:')}
|
|
229
|
+
${config.apiKey ? chalk_1.default.green('ā
API key configured') : chalk_1.default.yellow('ā ļø No API key set')}
|
|
230
|
+
`);
|
|
231
|
+
}
|
|
137
232
|
async function showStatus(client) {
|
|
233
|
+
const config = (0, manager_1.getConfig)();
|
|
138
234
|
console.log(`
|
|
139
235
|
${chalk_1.default.bold('Connection Status:')}
|
|
140
|
-
API URL:
|
|
141
|
-
|
|
236
|
+
API URL: ${chalk_1.default.cyan(client.baseUrl)}
|
|
237
|
+
API Key: ${config.apiKey ? chalk_1.default.green('ā
' + config.apiKey.substring(0, 12) + '...') : chalk_1.default.yellow('ā ļø Not set')}
|
|
238
|
+
Auth: ${client.isAuthenticated() ? chalk_1.default.green('ā
Authenticated') : chalk_1.default.yellow('ā ļø Not authenticated')}
|
|
239
|
+
|
|
240
|
+
${chalk_1.default.dim('Use /login to authenticate or /key for help')}
|
|
142
241
|
`);
|
|
143
242
|
}
|