@torqon/mcp 0.1.4 → 0.1.6

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 +49 -21
  2. package/package.json +3 -2
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@
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';
16
+ import { exec } from 'child_process';
17
17
  // ── Config ────────────────────────────────────────────────────────────────────
18
18
  const CONFIG_PATH = join(homedir(), '.torqon', 'config.json');
19
19
  function loadConfig() {
@@ -86,7 +86,7 @@ function progressBar(value, max, width = 24, warn = false) {
86
86
  }
87
87
  // ── Commands ──────────────────────────────────────────────────────────────────
88
88
  function printLogo() {
89
- console.log(`\n ${P('t')}${B('orqon')} ${Gr('cli v0.1.4')}`);
89
+ console.log(`\n ${P('t')}${B('orqon')} ${Gr('cli v0.1.6')}`);
90
90
  console.log(` ${Gr('memory layer for LLMs')}\n`);
91
91
  }
92
92
  function printHelp() {
@@ -234,27 +234,55 @@ function cmdConfig() {
234
234
  console.log(` ${Y('Run')} ${P('torqon login')} ${Y('to set your API key.')}\n`);
235
235
  }
236
236
  }
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');
237
+ function openBrowser(url) {
238
+ const { platform } = 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, webUrl, 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(`${webUrl}/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 WEB_URL = API_URL.includes('localhost') ? 'http://localhost:3002' : 'https://torqon.vercel.app';
268
+ const loginUrl = `${WEB_URL}/auth/cli?state=${state}`;
269
+ console.log(` ${B('Opening browser to complete login...')}\n`);
270
+ console.log(` ${Gr('URL:')} ${Cy(loginUrl)}\n`);
271
+ console.log(` ${Gr("If the browser didn't open, copy the URL above and paste it manually.")}\n`);
272
+ openBrowser(loginUrl);
273
+ console.log(` ${Gr('Waiting for authentication')}`, '');
274
+ const apiKey = await pollForToken(state, WEB_URL);
275
+ if (!apiKey) {
276
+ console.log(`\n\n ${R('✗ Login timed out (2 minutes).')}`);
277
+ console.log(` ${Gr('Run')} ${P('torqon login')} ${Gr('to try again.\n')}`);
278
+ return;
279
+ }
280
+ // Save key
281
+ const { mkdirSync } = await import('fs');
282
+ mkdirSync(join(homedir(), '.torqon'), { recursive: true });
283
+ saveConfig({ ...cfg, apiKey, apiUrl: API_URL });
284
+ console.log(`\n\n ${G('✓ Authenticated!')} ${Gr('Key saved to')} ${Cy(CONFIG_PATH)}`);
285
+ console.log(` ${Gr('Run')} ${P('torqon status')} ${Gr('to verify.\n')}`);
258
286
  }
259
287
  // ── Router ────────────────────────────────────────────────────────────────────
260
288
  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.6",
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
+