@aluvia/sdk 1.4.1 → 2.0.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/CHANGELOG.md +194 -0
- package/README.md +162 -477
- package/dist/cjs/api/apiUtils.js +4 -1
- package/dist/cjs/client/AluviaClient.js +30 -32
- package/dist/cjs/client/BlockDetection.js +69 -87
- package/dist/cjs/client/rules.js +12 -2
- package/dist/cjs/connect.js +2 -2
- package/dist/cjs/index.js +12 -1
- package/dist/cjs/session/lock.js +40 -4
- package/dist/esm/api/apiUtils.js +4 -1
- package/dist/esm/client/AluviaClient.js +38 -40
- package/dist/esm/client/BlockDetection.js +69 -87
- package/dist/esm/client/rules.js +12 -2
- package/dist/esm/connect.js +2 -2
- package/dist/esm/index.js +6 -4
- package/dist/esm/session/lock.js +40 -4
- package/dist/types/client/AluviaClient.d.ts +2 -2
- package/dist/types/client/BlockDetection.d.ts +4 -4
- package/dist/types/client/types.d.ts +11 -11
- package/dist/types/index.d.ts +9 -7
- package/package.json +15 -23
- package/dist/cjs/bin/account.js +0 -31
- package/dist/cjs/bin/api-helpers.js +0 -58
- package/dist/cjs/bin/cli-adapter.js +0 -16
- package/dist/cjs/bin/cli.js +0 -245
- package/dist/cjs/bin/close.js +0 -120
- package/dist/cjs/bin/geos.js +0 -10
- package/dist/cjs/bin/mcp-helpers.js +0 -57
- package/dist/cjs/bin/open.js +0 -317
- package/dist/cjs/bin/session.js +0 -259
- package/dist/esm/bin/account.js +0 -28
- package/dist/esm/bin/api-helpers.js +0 -53
- package/dist/esm/bin/cli-adapter.js +0 -8
- package/dist/esm/bin/cli.js +0 -242
- package/dist/esm/bin/close.js +0 -117
- package/dist/esm/bin/geos.js +0 -7
- package/dist/esm/bin/mcp-helpers.js +0 -51
- package/dist/esm/bin/open.js +0 -280
- package/dist/esm/bin/session.js +0 -252
- package/dist/types/bin/account.d.ts +0 -1
- package/dist/types/bin/api-helpers.d.ts +0 -20
- package/dist/types/bin/cli-adapter.d.ts +0 -8
- package/dist/types/bin/cli.d.ts +0 -2
- package/dist/types/bin/close.d.ts +0 -1
- package/dist/types/bin/geos.d.ts +0 -1
- package/dist/types/bin/mcp-helpers.d.ts +0 -28
- package/dist/types/bin/open.d.ts +0 -21
- package/dist/types/bin/session.d.ts +0 -11
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Aluvia Client Node
|
|
2
2
|
// Main entry point
|
|
3
3
|
// Public class
|
|
4
|
-
export { AluviaClient } from
|
|
5
|
-
export { AluviaApi } from
|
|
4
|
+
export { AluviaClient } from './client/AluviaClient.js';
|
|
5
|
+
export { AluviaApi } from './api/AluviaApi.js';
|
|
6
6
|
// Connect helper
|
|
7
|
-
export { connect } from
|
|
7
|
+
export { connect } from './connect.js';
|
|
8
8
|
// Public error classes
|
|
9
|
-
export { MissingApiKeyError, InvalidApiKeyError, ApiError, ProxyStartError, ConnectError
|
|
9
|
+
export { MissingApiKeyError, InvalidApiKeyError, ApiError, ProxyStartError, ConnectError } from './errors.js';
|
|
10
|
+
// Session lock utilities (used by CLI)
|
|
11
|
+
export { writeLock, readLock, removeLock, isProcessAlive, getLogFilePath, validateSessionName, generateSessionName, listSessions, toLockData, } from './session/lock.js';
|
package/dist/esm/session/lock.js
CHANGED
|
@@ -3,12 +3,48 @@ import * as path from 'node:path';
|
|
|
3
3
|
import * as os from 'node:os';
|
|
4
4
|
const LOCK_DIR = path.join(os.tmpdir(), 'aluvia-sdk');
|
|
5
5
|
const ADJECTIVES = [
|
|
6
|
-
'swift',
|
|
7
|
-
'
|
|
6
|
+
'swift',
|
|
7
|
+
'bold',
|
|
8
|
+
'calm',
|
|
9
|
+
'keen',
|
|
10
|
+
'warm',
|
|
11
|
+
'bright',
|
|
12
|
+
'silent',
|
|
13
|
+
'rapid',
|
|
14
|
+
'steady',
|
|
15
|
+
'clever',
|
|
16
|
+
'vivid',
|
|
17
|
+
'agile',
|
|
18
|
+
'noble',
|
|
19
|
+
'lucid',
|
|
20
|
+
'crisp',
|
|
21
|
+
'gentle',
|
|
22
|
+
'fierce',
|
|
23
|
+
'nimble',
|
|
24
|
+
'sturdy',
|
|
25
|
+
'witty',
|
|
8
26
|
];
|
|
9
27
|
const NOUNS = [
|
|
10
|
-
'falcon',
|
|
11
|
-
'
|
|
28
|
+
'falcon',
|
|
29
|
+
'tiger',
|
|
30
|
+
'river',
|
|
31
|
+
'maple',
|
|
32
|
+
'coral',
|
|
33
|
+
'cedar',
|
|
34
|
+
'orbit',
|
|
35
|
+
'prism',
|
|
36
|
+
'flint',
|
|
37
|
+
'spark',
|
|
38
|
+
'ridge',
|
|
39
|
+
'ember',
|
|
40
|
+
'crane',
|
|
41
|
+
'grove',
|
|
42
|
+
'stone',
|
|
43
|
+
'brook',
|
|
44
|
+
'drift',
|
|
45
|
+
'crest',
|
|
46
|
+
'sage',
|
|
47
|
+
'lynx',
|
|
12
48
|
];
|
|
13
49
|
function lockFileName(sessionName) {
|
|
14
50
|
return `cli-${sessionName ?? 'default'}.lock`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AluviaClientConnection, AluviaClientOptions } from
|
|
2
|
-
import { AluviaApi } from
|
|
1
|
+
import type { AluviaClientConnection, AluviaClientOptions } from './types.js';
|
|
2
|
+
import { AluviaApi } from '../api/AluviaApi.js';
|
|
3
3
|
/**
|
|
4
4
|
* AluviaClient is the main entry point for the Aluvia Client.
|
|
5
5
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Logger } from
|
|
1
|
+
import type { Logger } from './logger.js';
|
|
2
2
|
/**
|
|
3
3
|
* Detection block status based on scoring
|
|
4
4
|
*/
|
|
5
|
-
export type DetectionBlockStatus =
|
|
5
|
+
export type DetectionBlockStatus = 'blocked' | 'suspected' | 'clear';
|
|
6
6
|
/**
|
|
7
7
|
* A single detection signal with weight
|
|
8
8
|
*/
|
|
@@ -10,7 +10,7 @@ export type DetectionSignal = {
|
|
|
10
10
|
name: string;
|
|
11
11
|
weight: number;
|
|
12
12
|
details: string;
|
|
13
|
-
source:
|
|
13
|
+
source: 'fast' | 'full';
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* A single hop in a redirect chain
|
|
@@ -28,7 +28,7 @@ export type BlockDetectionResult = {
|
|
|
28
28
|
blockStatus: DetectionBlockStatus;
|
|
29
29
|
score: number;
|
|
30
30
|
signals: DetectionSignal[];
|
|
31
|
-
pass:
|
|
31
|
+
pass: 'fast' | 'full';
|
|
32
32
|
persistentBlock: boolean;
|
|
33
33
|
redirectChain: RedirectHop[];
|
|
34
34
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { BlockDetectionConfig } from
|
|
1
|
+
import type { BlockDetectionConfig } from './BlockDetection.js';
|
|
2
2
|
/**
|
|
3
3
|
* Protocol used to connect to the Aluvia gateway.
|
|
4
4
|
*/
|
|
5
|
-
export type GatewayProtocol =
|
|
5
|
+
export type GatewayProtocol = 'http' | 'https';
|
|
6
6
|
/**
|
|
7
7
|
* Log level for the client.
|
|
8
8
|
*/
|
|
9
|
-
export type LogLevel =
|
|
9
|
+
export type LogLevel = 'silent' | 'info' | 'debug';
|
|
10
10
|
export type PlaywrightProxySettings = {
|
|
11
11
|
server: string;
|
|
12
12
|
username?: string;
|
|
@@ -148,8 +148,8 @@ export type AluviaClientConnection = {
|
|
|
148
148
|
* Useful for: Axios, got, node-fetch (legacy).
|
|
149
149
|
*/
|
|
150
150
|
asNodeAgents(): {
|
|
151
|
-
http: import(
|
|
152
|
-
https: import(
|
|
151
|
+
http: import('node:http').Agent;
|
|
152
|
+
https: import('node:http').Agent;
|
|
153
153
|
};
|
|
154
154
|
/**
|
|
155
155
|
* Axios adapter config.
|
|
@@ -159,8 +159,8 @@ export type AluviaClientConnection = {
|
|
|
159
159
|
*/
|
|
160
160
|
asAxiosConfig(): {
|
|
161
161
|
proxy: false;
|
|
162
|
-
httpAgent: import(
|
|
163
|
-
httpsAgent: import(
|
|
162
|
+
httpAgent: import('node:http').Agent;
|
|
163
|
+
httpsAgent: import('node:http').Agent;
|
|
164
164
|
};
|
|
165
165
|
/**
|
|
166
166
|
* got adapter options.
|
|
@@ -169,14 +169,14 @@ export type AluviaClientConnection = {
|
|
|
169
169
|
*/
|
|
170
170
|
asGotOptions(): {
|
|
171
171
|
agent: {
|
|
172
|
-
http: import(
|
|
173
|
-
https: import(
|
|
172
|
+
http: import('node:http').Agent;
|
|
173
|
+
https: import('node:http').Agent;
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
176
|
/**
|
|
177
177
|
* undici proxy dispatcher (for undici fetch / undici clients).
|
|
178
178
|
*/
|
|
179
|
-
asUndiciDispatcher(): import(
|
|
179
|
+
asUndiciDispatcher(): import('undici').Dispatcher;
|
|
180
180
|
/**
|
|
181
181
|
* Returns a `fetch` function powered by undici that uses the proxy dispatcher per request.
|
|
182
182
|
*
|
|
@@ -214,4 +214,4 @@ export type AluviaClientConnection = {
|
|
|
214
214
|
/** @deprecated Use `close()` instead. */
|
|
215
215
|
stop(): Promise<void>;
|
|
216
216
|
};
|
|
217
|
-
export type { BlockDetectionConfig, BlockDetectionResult, DetectionBlockStatus, DetectionSignal, RedirectHop, } from
|
|
217
|
+
export type { BlockDetectionConfig, BlockDetectionResult, DetectionBlockStatus, DetectionSignal, RedirectHop, } from './BlockDetection.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { AluviaClient } from
|
|
2
|
-
export { AluviaApi } from
|
|
3
|
-
export { connect } from
|
|
4
|
-
export type { ConnectResult } from
|
|
5
|
-
export { MissingApiKeyError, InvalidApiKeyError, ApiError, ProxyStartError, ConnectError
|
|
6
|
-
export
|
|
7
|
-
export type {
|
|
1
|
+
export { AluviaClient } from './client/AluviaClient.js';
|
|
2
|
+
export { AluviaApi } from './api/AluviaApi.js';
|
|
3
|
+
export { connect } from './connect.js';
|
|
4
|
+
export type { ConnectResult } from './connect.js';
|
|
5
|
+
export { MissingApiKeyError, InvalidApiKeyError, ApiError, ProxyStartError, ConnectError } from './errors.js';
|
|
6
|
+
export { writeLock, readLock, removeLock, isProcessAlive, getLogFilePath, validateSessionName, generateSessionName, listSessions, toLockData, } from './session/lock.js';
|
|
7
|
+
export type { LockData, LockDetection, SessionInfo } from './session/lock.js';
|
|
8
|
+
export type { GatewayProtocol, LogLevel, AluviaClientOptions, AluviaClientConnection, PlaywrightProxySettings, BlockDetectionConfig, BlockDetectionResult, DetectionBlockStatus, DetectionSignal, RedirectHop, } from './client/types.js';
|
|
9
|
+
export type { Account, AccountUsage, AccountPayment, AccountConnection, AccountConnectionDeleteResult, Geo, SuccessEnvelope, ErrorEnvelope, Envelope, } from './api/types.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aluvia/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Aluvia SDK for Node.js - local smart proxy for automation workloads and AI agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Aluvia",
|
|
@@ -22,31 +22,17 @@
|
|
|
22
22
|
"import": "./dist/esm/index.js",
|
|
23
23
|
"require": "./dist/cjs/index.js"
|
|
24
24
|
},
|
|
25
|
-
"./cli": {
|
|
26
|
-
"types": "./dist/types/bin/cli-adapter.d.ts",
|
|
27
|
-
"import": "./dist/esm/bin/cli-adapter.js",
|
|
28
|
-
"require": "./dist/cjs/bin/cli-adapter.js"
|
|
29
|
-
},
|
|
30
25
|
"./package.json": "./package.json"
|
|
31
26
|
},
|
|
32
|
-
"bin": {
|
|
33
|
-
"aluvia": "./dist/esm/bin/cli.js",
|
|
34
|
-
"aluvia-sdk": "./dist/esm/bin/cli.js"
|
|
35
|
-
},
|
|
36
|
-
"workspaces": [
|
|
37
|
-
"mcp"
|
|
38
|
-
],
|
|
39
27
|
"files": [
|
|
40
28
|
"dist/**/*",
|
|
41
29
|
"README.md",
|
|
42
|
-
"LICENSE"
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"CHANGELOG.md"
|
|
43
32
|
],
|
|
44
33
|
"scripts": {
|
|
45
34
|
"build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').mkdirSync('dist/cjs',{recursive:true});require('fs').writeFileSync('dist/cjs/package.json','{\\\"type\\\":\\\"commonjs\\\"}')\"",
|
|
46
|
-
"
|
|
47
|
-
"prepare": "npm run build",
|
|
48
|
-
"test": "node --import tsx --test test/integration.test.ts test/mcp-smoke.test.ts",
|
|
49
|
-
"test:mcp": "node mcp/test-stdio.mjs",
|
|
35
|
+
"test": "node --import tsx --test test/*.test.ts",
|
|
50
36
|
"lint": "prettier --check src test",
|
|
51
37
|
"lint:fix": "prettier --write src test"
|
|
52
38
|
},
|
|
@@ -61,13 +47,12 @@
|
|
|
61
47
|
"ai-agent",
|
|
62
48
|
"playwright",
|
|
63
49
|
"puppeteer",
|
|
64
|
-
"aluvia"
|
|
65
|
-
"mcp",
|
|
66
|
-
"model-context-protocol"
|
|
50
|
+
"aluvia"
|
|
67
51
|
],
|
|
68
52
|
"devDependencies": {
|
|
69
53
|
"@types/node": "^24.10.2",
|
|
70
54
|
"axios": "^1.13.2",
|
|
55
|
+
"playwright": "^1.58.2",
|
|
71
56
|
"prettier": "^3.4.2",
|
|
72
57
|
"tsx": "^4.21.0",
|
|
73
58
|
"typescript": "^5.9.3"
|
|
@@ -75,8 +60,15 @@
|
|
|
75
60
|
"dependencies": {
|
|
76
61
|
"http-proxy-agent": "^7.0.2",
|
|
77
62
|
"https-proxy-agent": "^7.0.6",
|
|
78
|
-
"playwright": "^1.58.2",
|
|
79
63
|
"proxy-chain": "^2.6.1",
|
|
80
64
|
"undici": "^6.22.0"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"playwright": "^1.0.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"playwright": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
81
73
|
}
|
|
82
|
-
}
|
|
74
|
+
}
|
package/dist/cjs/bin/account.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleAccount = handleAccount;
|
|
4
|
-
const api_helpers_js_1 = require("./api-helpers.js");
|
|
5
|
-
const cli_js_1 = require("./cli.js");
|
|
6
|
-
async function handleAccount(args) {
|
|
7
|
-
const subcommand = args[0];
|
|
8
|
-
if (!subcommand) {
|
|
9
|
-
const api = (0, api_helpers_js_1.requireApi)();
|
|
10
|
-
const account = await api.account.get();
|
|
11
|
-
return (0, cli_js_1.output)({ account });
|
|
12
|
-
}
|
|
13
|
-
if (subcommand === 'usage') {
|
|
14
|
-
let start;
|
|
15
|
-
let end;
|
|
16
|
-
for (let i = 1; i < args.length; i++) {
|
|
17
|
-
if (args[i] === '--start' && args[i + 1]) {
|
|
18
|
-
start = args[i + 1];
|
|
19
|
-
i++;
|
|
20
|
-
}
|
|
21
|
-
else if (args[i] === '--end' && args[i + 1]) {
|
|
22
|
-
end = args[i + 1];
|
|
23
|
-
i++;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const api = (0, api_helpers_js_1.requireApi)();
|
|
27
|
-
const usage = await api.account.usage.get({ start, end });
|
|
28
|
-
return (0, cli_js_1.output)({ usage });
|
|
29
|
-
}
|
|
30
|
-
return (0, cli_js_1.output)({ error: `Unknown account subcommand: '${subcommand}'.` }, 1);
|
|
31
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireApi = requireApi;
|
|
4
|
-
exports.resolveSession = resolveSession;
|
|
5
|
-
exports.requireConnectionId = requireConnectionId;
|
|
6
|
-
const AluviaApi_js_1 = require("../api/AluviaApi.js");
|
|
7
|
-
const lock_js_1 = require("../session/lock.js");
|
|
8
|
-
const cli_js_1 = require("./cli.js");
|
|
9
|
-
/**
|
|
10
|
-
* Create an AluviaApi instance from ALUVIA_API_KEY env var.
|
|
11
|
-
* Calls output() and exits if the key is missing.
|
|
12
|
-
*/
|
|
13
|
-
function requireApi() {
|
|
14
|
-
const apiKey = (process.env.ALUVIA_API_KEY ?? '').trim();
|
|
15
|
-
if (!apiKey) {
|
|
16
|
-
return (0, cli_js_1.output)({ error: 'ALUVIA_API_KEY environment variable is required.' }, 1);
|
|
17
|
-
}
|
|
18
|
-
return new AluviaApi_js_1.AluviaApi({ apiKey });
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Resolve a session by name or auto-select when only one is running.
|
|
22
|
-
* Calls output() and exits on error (no sessions, ambiguous sessions, stale lock).
|
|
23
|
-
*/
|
|
24
|
-
function resolveSession(sessionName) {
|
|
25
|
-
if (sessionName) {
|
|
26
|
-
const lock = (0, lock_js_1.readLock)(sessionName);
|
|
27
|
-
if (!lock) {
|
|
28
|
-
return (0, cli_js_1.output)({ error: `No session found with name '${sessionName}'.` }, 1);
|
|
29
|
-
}
|
|
30
|
-
if (!(0, lock_js_1.isProcessAlive)(lock.pid)) {
|
|
31
|
-
(0, lock_js_1.removeLock)(sessionName);
|
|
32
|
-
return (0, cli_js_1.output)({ error: `Session '${sessionName}' is no longer running (stale lock cleaned up).` }, 1);
|
|
33
|
-
}
|
|
34
|
-
return { session: sessionName, lock };
|
|
35
|
-
}
|
|
36
|
-
const sessions = (0, lock_js_1.listSessions)();
|
|
37
|
-
if (sessions.length === 0) {
|
|
38
|
-
return (0, cli_js_1.output)({ error: 'No running browser sessions found.' }, 1);
|
|
39
|
-
}
|
|
40
|
-
if (sessions.length > 1) {
|
|
41
|
-
return (0, cli_js_1.output)({
|
|
42
|
-
error: 'Multiple sessions running. Specify --browser-session <name>.',
|
|
43
|
-
browserSessions: sessions.map((s) => s.session),
|
|
44
|
-
}, 1);
|
|
45
|
-
}
|
|
46
|
-
const s = sessions[0];
|
|
47
|
-
return { session: s.session, lock: (0, lock_js_1.toLockData)(s) };
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Require a connection ID from lock data.
|
|
51
|
-
* Calls output() and exits if connectionId is missing.
|
|
52
|
-
*/
|
|
53
|
-
function requireConnectionId(lock, session) {
|
|
54
|
-
if (lock.connectionId == null) {
|
|
55
|
-
return (0, cli_js_1.output)({ error: `Session '${session}' has no connection ID. It may have been started without API access.` }, 1);
|
|
56
|
-
}
|
|
57
|
-
return lock.connectionId;
|
|
58
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Re-exports for @aluvia/mcp. MCP package imports from @aluvia/sdk/cli.
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.captureOutput = exports.handleOpen = exports.handleGeos = exports.handleAccount = exports.handleSession = void 0;
|
|
7
|
-
var session_js_1 = require("./session.js");
|
|
8
|
-
Object.defineProperty(exports, "handleSession", { enumerable: true, get: function () { return session_js_1.handleSession; } });
|
|
9
|
-
var account_js_1 = require("./account.js");
|
|
10
|
-
Object.defineProperty(exports, "handleAccount", { enumerable: true, get: function () { return account_js_1.handleAccount; } });
|
|
11
|
-
var geos_js_1 = require("./geos.js");
|
|
12
|
-
Object.defineProperty(exports, "handleGeos", { enumerable: true, get: function () { return geos_js_1.handleGeos; } });
|
|
13
|
-
var open_js_1 = require("./open.js");
|
|
14
|
-
Object.defineProperty(exports, "handleOpen", { enumerable: true, get: function () { return open_js_1.handleOpen; } });
|
|
15
|
-
var mcp_helpers_js_1 = require("./mcp-helpers.js");
|
|
16
|
-
Object.defineProperty(exports, "captureOutput", { enumerable: true, get: function () { return mcp_helpers_js_1.captureOutput; } });
|
package/dist/cjs/bin/cli.js
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.output = output;
|
|
5
|
-
const open_js_1 = require("./open.js");
|
|
6
|
-
const session_js_1 = require("./session.js");
|
|
7
|
-
const account_js_1 = require("./account.js");
|
|
8
|
-
const geos_js_1 = require("./geos.js");
|
|
9
|
-
const lock_js_1 = require("../session/lock.js");
|
|
10
|
-
const mcp_helpers_js_1 = require("./mcp-helpers.js");
|
|
11
|
-
function output(data, exitCode = 0) {
|
|
12
|
-
if ((0, mcp_helpers_js_1.isCapturing)()) {
|
|
13
|
-
throw new mcp_helpers_js_1.MCPOutputCapture(data, exitCode);
|
|
14
|
-
}
|
|
15
|
-
console.log(JSON.stringify(data));
|
|
16
|
-
process.exit(exitCode);
|
|
17
|
-
}
|
|
18
|
-
function printHelp(toStderr = false) {
|
|
19
|
-
const log = toStderr ? console.error : console.log;
|
|
20
|
-
log("Aluvia CLI\n");
|
|
21
|
-
log("Usage:");
|
|
22
|
-
log(" aluvia session start <url> [options] Start a browser session");
|
|
23
|
-
log(" aluvia session close [options] Stop a browser session");
|
|
24
|
-
log(" aluvia session list List active browser sessions");
|
|
25
|
-
log(" aluvia session get [options] Get session details and proxy URLs");
|
|
26
|
-
log(" aluvia session rotate-ip [options] Rotate IP on a running session");
|
|
27
|
-
log(" aluvia session set-geo <geo> [options] Set target geo on a running session");
|
|
28
|
-
log(" aluvia session set-rules <rules> [options] Set routing rules on a running session\n");
|
|
29
|
-
log(" aluvia account Show account info");
|
|
30
|
-
log(" aluvia account usage [options] Show usage stats");
|
|
31
|
-
log(" aluvia geos List available geos");
|
|
32
|
-
log(" aluvia help [--json] Show this help\n");
|
|
33
|
-
log("Session start options:");
|
|
34
|
-
log(" --connection-id <id> Use a specific connection ID");
|
|
35
|
-
log(" --headful Run browser in headful mode");
|
|
36
|
-
log(" --browser-session <name> Name for this session (auto-generated if omitted)");
|
|
37
|
-
log(" --auto-unblock Auto-detect blocks and reload through Aluvia");
|
|
38
|
-
log(" --disable-block-detection Disable block detection entirely");
|
|
39
|
-
log(" --run <script> Run a script with page, browser, context injected\n");
|
|
40
|
-
log("Session close options:");
|
|
41
|
-
log(" --browser-session <name> Close a specific session");
|
|
42
|
-
log(" --all Close all sessions\n");
|
|
43
|
-
log("Session targeting (get, rotate-ip, set-geo, set-rules):");
|
|
44
|
-
log(" --browser-session <name> Target a specific session (auto-selects if only one)\n");
|
|
45
|
-
log("Session set-rules:");
|
|
46
|
-
log(' <rules> Comma-separated rules to append (e.g. "a.com,b.com")');
|
|
47
|
-
log(" --remove <rules> Remove specific rules instead of appending\n");
|
|
48
|
-
log("Session set-geo:");
|
|
49
|
-
log(' <geo> Geo code to set (e.g. "US")');
|
|
50
|
-
log(" --clear Clear target geo\n");
|
|
51
|
-
log("Account usage options:");
|
|
52
|
-
log(" --start <ISO8601> Start date filter");
|
|
53
|
-
log(" --end <ISO8601> End date filter\n");
|
|
54
|
-
log("Environment:");
|
|
55
|
-
log(" ALUVIA_API_KEY Required. Your Aluvia API key.\n");
|
|
56
|
-
log("Output:");
|
|
57
|
-
log(" All commands output JSON to stdout.");
|
|
58
|
-
}
|
|
59
|
-
function printHelpJson() {
|
|
60
|
-
return output({
|
|
61
|
-
commands: [
|
|
62
|
-
{
|
|
63
|
-
command: "session start <url>",
|
|
64
|
-
description: "Start a browser session",
|
|
65
|
-
options: [
|
|
66
|
-
{
|
|
67
|
-
flag: "--connection-id <id>",
|
|
68
|
-
description: "Use a specific connection ID",
|
|
69
|
-
},
|
|
70
|
-
{ flag: "--headful", description: "Run browser in headful mode" },
|
|
71
|
-
{
|
|
72
|
-
flag: "--browser-session <name>",
|
|
73
|
-
description: "Name for this session (auto-generated if omitted)",
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
flag: "--auto-unblock",
|
|
77
|
-
description: "Auto-detect blocks and reload through Aluvia",
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
flag: "--disable-block-detection",
|
|
81
|
-
description: "Disable block detection entirely",
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
flag: "--run <script>",
|
|
85
|
-
description: "Run a script with page, browser, context injected",
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
command: "session close",
|
|
91
|
-
description: "Stop a browser session",
|
|
92
|
-
options: [
|
|
93
|
-
{
|
|
94
|
-
flag: "--browser-session <name>",
|
|
95
|
-
description: "Close a specific session",
|
|
96
|
-
},
|
|
97
|
-
{ flag: "--all", description: "Close all sessions" },
|
|
98
|
-
],
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
command: "session list",
|
|
102
|
-
description: "List active browser sessions",
|
|
103
|
-
options: [],
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
command: "session get",
|
|
107
|
-
description: "Get session details and proxy URLs",
|
|
108
|
-
options: [
|
|
109
|
-
{
|
|
110
|
-
flag: "--browser-session <name>",
|
|
111
|
-
description: "Target a specific session (auto-selects if only one)",
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
command: "session rotate-ip",
|
|
117
|
-
description: "Rotate IP on a running session",
|
|
118
|
-
options: [
|
|
119
|
-
{
|
|
120
|
-
flag: "--browser-session <name>",
|
|
121
|
-
description: "Target a specific session (auto-selects if only one)",
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
command: "session set-geo <geo>",
|
|
127
|
-
description: "Set target geo on a running session",
|
|
128
|
-
options: [
|
|
129
|
-
{
|
|
130
|
-
flag: "--browser-session <name>",
|
|
131
|
-
description: "Target a specific session (auto-selects if only one)",
|
|
132
|
-
},
|
|
133
|
-
{ flag: "--clear", description: "Clear target geo" },
|
|
134
|
-
],
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
command: "session set-rules <rules>",
|
|
138
|
-
description: "Set routing rules on a running session",
|
|
139
|
-
options: [
|
|
140
|
-
{
|
|
141
|
-
flag: "--browser-session <name>",
|
|
142
|
-
description: "Target a specific session (auto-selects if only one)",
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
flag: "--remove <rules>",
|
|
146
|
-
description: "Remove specific rules instead of appending",
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
command: "account",
|
|
152
|
-
description: "Show account info",
|
|
153
|
-
options: [],
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
command: "account usage",
|
|
157
|
-
description: "Show usage stats",
|
|
158
|
-
options: [
|
|
159
|
-
{ flag: "--start <ISO8601>", description: "Start date filter" },
|
|
160
|
-
{ flag: "--end <ISO8601>", description: "End date filter" },
|
|
161
|
-
],
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
command: "geos",
|
|
165
|
-
description: "List available geos",
|
|
166
|
-
options: [],
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
command: "help",
|
|
170
|
-
description: "Show this help",
|
|
171
|
-
options: [{ flag: "--json", description: "Output help as JSON" }],
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
function printHelpAndExit(args) {
|
|
177
|
-
if (args.includes("--json")) {
|
|
178
|
-
return printHelpJson();
|
|
179
|
-
}
|
|
180
|
-
printHelp();
|
|
181
|
-
process.exit(0);
|
|
182
|
-
}
|
|
183
|
-
function parseDaemonArgs(args) {
|
|
184
|
-
return (0, session_js_1.parseSessionArgs)(args);
|
|
185
|
-
}
|
|
186
|
-
async function main() {
|
|
187
|
-
const args = process.argv.slice(2);
|
|
188
|
-
const command = args[0] ?? "";
|
|
189
|
-
// Internal: --daemon mode (spawned by `session start` in detached child)
|
|
190
|
-
if (command === "--daemon") {
|
|
191
|
-
const parsed = parseDaemonArgs(args.slice(1));
|
|
192
|
-
if (parsed.sessionName && !(0, lock_js_1.validateSessionName)(parsed.sessionName)) {
|
|
193
|
-
output({
|
|
194
|
-
error: "Invalid session name. Use only letters, numbers, hyphens, and underscores.",
|
|
195
|
-
}, 1);
|
|
196
|
-
}
|
|
197
|
-
if (!parsed.url) {
|
|
198
|
-
return output({ error: "URL is required for daemon mode." }, 1);
|
|
199
|
-
}
|
|
200
|
-
await (0, open_js_1.handleOpenDaemon)({
|
|
201
|
-
url: parsed.url,
|
|
202
|
-
connectionId: parsed.connectionId,
|
|
203
|
-
headless: !parsed.headed,
|
|
204
|
-
sessionName: parsed.sessionName,
|
|
205
|
-
autoUnblock: parsed.autoUnblock,
|
|
206
|
-
disableBlockDetection: parsed.disableBlockDetection,
|
|
207
|
-
run: parsed.run,
|
|
208
|
-
});
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
// Check for --help / -h anywhere in args (subcommand help)
|
|
212
|
-
const wantsHelp = args.includes("--help") || args.includes("-h");
|
|
213
|
-
if (command === "session") {
|
|
214
|
-
if (wantsHelp)
|
|
215
|
-
printHelpAndExit(args);
|
|
216
|
-
await (0, session_js_1.handleSession)(args.slice(1));
|
|
217
|
-
}
|
|
218
|
-
else if (command === "account") {
|
|
219
|
-
if (wantsHelp)
|
|
220
|
-
printHelpAndExit(args);
|
|
221
|
-
await (0, account_js_1.handleAccount)(args.slice(1));
|
|
222
|
-
}
|
|
223
|
-
else if (command === "geos") {
|
|
224
|
-
if (wantsHelp)
|
|
225
|
-
printHelpAndExit(args);
|
|
226
|
-
await (0, geos_js_1.handleGeos)();
|
|
227
|
-
}
|
|
228
|
-
else if (command === "help" ||
|
|
229
|
-
command === "--help" ||
|
|
230
|
-
command === "-h" ||
|
|
231
|
-
command === "") {
|
|
232
|
-
printHelpAndExit(args);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
output({ error: `Unknown command: '${command}'. Run "aluvia help" for usage.` }, 1);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
// Only run CLI when this file is the direct entry point (not when imported by MCP server).
|
|
239
|
-
// Check if process.argv[1] resolves to this CLI file rather than another entry point.
|
|
240
|
-
const isCli = process.argv[1]?.match(/(?:cli)\.[jt]s$/);
|
|
241
|
-
if (isCli) {
|
|
242
|
-
main().catch((err) => {
|
|
243
|
-
output({ error: err.message }, 1);
|
|
244
|
-
});
|
|
245
|
-
}
|