qualiloop 0.0.0-stage → 0.2.0
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/LICENSE +202 -0
- package/README.md +258 -3
- package/dist/api.js +165 -0
- package/dist/auth.js +73 -0
- package/dist/catalog.js +24 -0
- package/dist/catalog.json +7943 -0
- package/dist/cli.js +2777 -0
- package/dist/config.js +76 -0
- package/dist/connect.js +357 -0
- package/dist/export.js +114 -0
- package/dist/mcp/install.js +142 -0
- package/dist/mcp/server.js +523 -0
- package/dist/output.js +43 -0
- package/dist/workflows.js +147 -0
- package/package.json +47 -4
package/dist/auth.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import { ApiError, EXIT } from './api.js';
|
|
4
|
+
import { saveCredentials } from './config.js';
|
|
5
|
+
export const openBrowser = (url) => {
|
|
6
|
+
if (process.env.QUALILOOP_NO_BROWSER || (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const [command, args] = process.platform === 'win32'
|
|
11
|
+
? ['rundll32', ['url.dll,FileProtocolHandler', url]]
|
|
12
|
+
: process.platform === 'darwin'
|
|
13
|
+
? ['open', [url]]
|
|
14
|
+
: ['xdg-open', [url]];
|
|
15
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
16
|
+
child.on('error', () => undefined);
|
|
17
|
+
child.unref();
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
25
|
+
export const login = async (client, options = {}) => {
|
|
26
|
+
const started = await client.request('POST', '/v1/cli/login', {
|
|
27
|
+
anonymous: true,
|
|
28
|
+
body: { client: options.client || 'cli', hostname: os.hostname() },
|
|
29
|
+
});
|
|
30
|
+
const opened = options.browser === false ? false : openBrowser(started.verification_url_complete);
|
|
31
|
+
options.onStarted?.({
|
|
32
|
+
url: started.verification_url_complete,
|
|
33
|
+
code: started.user_code,
|
|
34
|
+
opened,
|
|
35
|
+
expiresIn: started.expires_in,
|
|
36
|
+
});
|
|
37
|
+
let interval = Math.max(1, started.interval) * 1000;
|
|
38
|
+
const deadline = Date.now() + started.expires_in * 1000;
|
|
39
|
+
while (Date.now() < deadline) {
|
|
40
|
+
await sleep(interval);
|
|
41
|
+
let polled;
|
|
42
|
+
try {
|
|
43
|
+
polled = await client.request('POST', '/v1/cli/login/poll', {
|
|
44
|
+
anonymous: true,
|
|
45
|
+
body: { device_code: started.device_code },
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof ApiError && error.exitCode === EXIT.server)
|
|
50
|
+
continue;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
if (polled.status === 'slow_down') {
|
|
54
|
+
interval += 1000;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (polled.status === 'pending')
|
|
58
|
+
continue;
|
|
59
|
+
if (polled.status === 'approved' && polled.token) {
|
|
60
|
+
saveCredentials(client.url, {
|
|
61
|
+
token: polled.token,
|
|
62
|
+
expires_at: polled.expires_at ?? null,
|
|
63
|
+
user: polled.user ?? null,
|
|
64
|
+
});
|
|
65
|
+
return { url: client.url, user: polled.user ?? null, expires_at: polled.expires_at ?? null };
|
|
66
|
+
}
|
|
67
|
+
if (polled.status === 'denied') {
|
|
68
|
+
throw new ApiError('The sign-in was denied in the browser.', 403, EXIT.auth);
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
throw new ApiError(`The sign-in expired before it was approved. ${options.again ?? 'Run the same command again.'}`, 408, EXIT.timeout);
|
|
73
|
+
};
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
let bundled;
|
|
5
|
+
const readBundled = () => {
|
|
6
|
+
if (!bundled) {
|
|
7
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
bundled = JSON.parse(readFileSync(path.join(here, 'catalog.json'), 'utf8'));
|
|
9
|
+
}
|
|
10
|
+
return bundled;
|
|
11
|
+
};
|
|
12
|
+
export const bundledCatalog = () => readBundled().actions;
|
|
13
|
+
export const bundledGuide = () => readBundled().guide ?? '';
|
|
14
|
+
export const loadCatalog = async (client) => {
|
|
15
|
+
if (!client.isSignedIn())
|
|
16
|
+
return bundledCatalog();
|
|
17
|
+
try {
|
|
18
|
+
const body = await client.request('GET', '/v1/actions');
|
|
19
|
+
return body.actions?.length ? body.actions : bundledCatalog();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return bundledCatalog();
|
|
23
|
+
}
|
|
24
|
+
};
|