@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.
- package/dist/cli.js +49 -21
- 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
|
|
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.
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
|
251
|
-
|
|
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 { /*
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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);
|