@torqon/mcp 0.1.4 → 0.1.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.
Files changed (2) hide show
  1. package/dist/cli.js +47 -20
  2. package/package.json +3 -2
package/dist/cli.js CHANGED
@@ -13,7 +13,6 @@
13
13
  import { readFileSync, writeFileSync, existsSync } from 'fs';
14
14
  import { homedir } from 'os';
15
15
  import { join } from 'path';
16
- import * as readline from 'readline';
17
16
  // ── Config ────────────────────────────────────────────────────────────────────
18
17
  const CONFIG_PATH = join(homedir(), '.torqon', 'config.json');
19
18
  function loadConfig() {
@@ -234,27 +233,55 @@ function cmdConfig() {
234
233
  console.log(` ${Y('Run')} ${P('torqon login')} ${Y('to set your API key.')}\n`);
235
234
  }
236
235
  }
237
- async function cmdLogin() {
238
- printLogo();
239
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
240
- rl.question(` ${B('Enter your Torqon API key:')} `, (key) => {
241
- rl.close();
242
- if (!key.trim()) {
243
- console.log(R('\n ✗ No key entered.\n'));
244
- return;
245
- }
246
- const trimmed = key.trim();
247
- // Save to ~/.torqon/config.json
248
- const dir = join(homedir(), '.torqon');
236
+ function openBrowser(url) {
237
+ const { platform } = process;
238
+ const { exec } = require('child_process');
239
+ if (platform === 'win32')
240
+ exec(`start "" "${url}"`);
241
+ else if (platform === 'darwin')
242
+ exec(`open "${url}"`);
243
+ else
244
+ exec(`xdg-open "${url}"`);
245
+ }
246
+ async function pollForToken(state, timeoutMs = 120_000) {
247
+ const deadline = Date.now() + timeoutMs;
248
+ while (Date.now() < deadline) {
249
+ await new Promise(r => setTimeout(r, 2000));
249
250
  try {
250
- const { mkdirSync } = require('fs');
251
- mkdirSync(dir, { recursive: true });
251
+ const res = await fetch(`${API_URL}/api/auth/cli/token?state=${state}`);
252
+ if (res.ok) {
253
+ const data = await res.json();
254
+ if (data?.apiKey)
255
+ return data.apiKey;
256
+ }
252
257
  }
253
- catch { /* ignore */ }
254
- saveConfig({ ...cfg, apiKey: trimmed, apiUrl: API_URL });
255
- console.log(`\n ${G('✓ API key saved to')} ${Cy(CONFIG_PATH)}`);
256
- console.log(` ${Gr('Run')} ${P('torqon status')} ${Gr('to verify.')}\n`);
257
- });
258
+ catch { /* keep polling */ }
259
+ process.stdout.write('.');
260
+ }
261
+ return null;
262
+ }
263
+ async function cmdLogin() {
264
+ printLogo();
265
+ // Generate a random one-time state token
266
+ const state = Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2);
267
+ const loginUrl = `${API_URL.includes('localhost') ? 'http://localhost:3002' : 'https://torqon.ai'}/auth/cli?state=${state}`;
268
+ console.log(` ${B('Opening browser to complete login...')}\n`);
269
+ console.log(` ${Gr('URL:')} ${Cy(loginUrl)}\n`);
270
+ console.log(` ${Gr("If the browser didn't open, copy the URL above and paste it manually.")}\n`);
271
+ openBrowser(loginUrl);
272
+ console.log(` ${Gr('Waiting for authentication')}`, '');
273
+ const apiKey = await pollForToken(state);
274
+ if (!apiKey) {
275
+ console.log(`\n\n ${R('✗ Login timed out (2 minutes).')}`);
276
+ console.log(` ${Gr('Run')} ${P('torqon login')} ${Gr('to try again.\n')}`);
277
+ return;
278
+ }
279
+ // Save key
280
+ const { mkdirSync } = await import('fs');
281
+ mkdirSync(join(homedir(), '.torqon'), { recursive: true });
282
+ saveConfig({ ...cfg, apiKey, apiUrl: API_URL });
283
+ console.log(`\n\n ${G('✓ Authenticated!')} ${Gr('Key saved to')} ${Cy(CONFIG_PATH)}`);
284
+ console.log(` ${Gr('Run')} ${P('torqon status')} ${Gr('to verify.\n')}`);
258
285
  }
259
286
  // ── Router ────────────────────────────────────────────────────────────────────
260
287
  const args = process.argv.slice(2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
- {
1
+ {
2
2
  "name": "@torqon/mcp",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -26,3 +26,4 @@
26
26
  "typescript": "^5.0.0"
27
27
  }
28
28
  }
29
+