pi-antigravity-rotator 2.2.2 → 2.3.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/CHANGELOG.md +11 -0
- package/README.md +9 -1
- package/package.json +1 -1
- package/src/account-store.ts +109 -168
- package/src/admin-auth.ts +74 -83
- package/src/cli.ts +62 -46
- package/src/config-defaults.ts +64 -0
- package/src/config-storage.ts +21 -0
- package/src/dashboard.ts +310 -3193
- package/src/db-store.ts +155 -0
- package/src/doctor.ts +96 -78
- package/src/index.ts +200 -149
- package/src/onboarding.ts +352 -113
- package/src/paths.ts +34 -31
- package/src/proxy.ts +1751 -1270
- package/src/responses-store.ts +150 -178
- package/src/rotator.ts +3041 -2310
- package/src/settings-repository.ts +314 -0
- package/src/static/dashboard.css +1224 -0
- package/src/static/dashboard.js +1834 -0
- package/src/types.ts +501 -397
package/src/cli.ts
CHANGED
|
@@ -8,56 +8,72 @@
|
|
|
8
8
|
|
|
9
9
|
import { getConfigDir } from "./paths.js";
|
|
10
10
|
|
|
11
|
-
const args = process.argv
|
|
11
|
+
const args = process.argv
|
|
12
|
+
.slice(2)
|
|
13
|
+
.filter(
|
|
14
|
+
(a) =>
|
|
15
|
+
!a.startsWith("--config-dir") &&
|
|
16
|
+
a !== process.argv[process.argv.indexOf("--config-dir") + 1],
|
|
17
|
+
);
|
|
12
18
|
const command = args[0] || "start";
|
|
13
19
|
|
|
14
20
|
console.log(`Config dir: ${getConfigDir()}`);
|
|
15
21
|
console.log();
|
|
16
22
|
|
|
17
23
|
switch (command) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
24
|
+
case "start": {
|
|
25
|
+
// Dynamic import to avoid loading everything for help
|
|
26
|
+
const { main } = await import("./index.js");
|
|
27
|
+
await main();
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case "login": {
|
|
31
|
+
const { initDb } = await import("./db-store.js");
|
|
32
|
+
await initDb();
|
|
33
|
+
const { runLogin } = await import("./login.js");
|
|
34
|
+
await runLogin();
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "status": {
|
|
38
|
+
try {
|
|
39
|
+
const port = 51200;
|
|
40
|
+
const res = await fetch(`http://localhost:${port}/api/status`);
|
|
41
|
+
const data = await res.json();
|
|
42
|
+
console.log(JSON.stringify(data, null, 2));
|
|
43
|
+
} catch {
|
|
44
|
+
console.error("Rotator is not running or unreachable on port 51200");
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case "doctor": {
|
|
50
|
+
const { initDb } = await import("./db-store.js");
|
|
51
|
+
await initDb();
|
|
52
|
+
const { printDoctorReport, runDoctor } = await import("./doctor.js");
|
|
53
|
+
const result = await runDoctor();
|
|
54
|
+
printDoctorReport(result);
|
|
55
|
+
process.exit(result.ok ? 0 : 1);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
console.log("Pi Antigravity Rotator");
|
|
60
|
+
console.log();
|
|
61
|
+
console.log("Usage:");
|
|
62
|
+
console.log(" pi-antigravity-rotator start Start the proxy (default)");
|
|
63
|
+
console.log(" pi-antigravity-rotator login Add a new Google account");
|
|
64
|
+
console.log(
|
|
65
|
+
" pi-antigravity-rotator status Show account status (JSON)",
|
|
66
|
+
);
|
|
67
|
+
console.log(
|
|
68
|
+
" pi-antigravity-rotator doctor Validate config and local state",
|
|
69
|
+
);
|
|
70
|
+
console.log();
|
|
71
|
+
console.log("Options:");
|
|
72
|
+
console.log(
|
|
73
|
+
" --config-dir <path> Config directory (default: ~/.pi-antigravity-rotator/)",
|
|
74
|
+
);
|
|
75
|
+
console.log();
|
|
76
|
+
console.log("Environment:");
|
|
77
|
+
console.log(" PI_ROTATOR_DIR Config directory override");
|
|
78
|
+
process.exit(command === "help" || command === "--help" ? 0 : 1);
|
|
63
79
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Config } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export function applyConfigDefaults(config: Config): Config {
|
|
4
|
+
return {
|
|
5
|
+
proxyPort: config.proxyPort || 51200,
|
|
6
|
+
bindHost: config.bindHost || process.env.PI_ROTATOR_BIND_HOST || "0.0.0.0",
|
|
7
|
+
routingPolicy: config.routingPolicy || "timer-first",
|
|
8
|
+
requestsPerRotation: config.requestsPerRotation || 5,
|
|
9
|
+
rotateOnQuotaDrop: config.rotateOnQuotaDrop ?? 20,
|
|
10
|
+
quotaPollIntervalMs: config.quotaPollIntervalMs || 300000,
|
|
11
|
+
maxConcurrentRequestsPerAccount: config.maxConcurrentRequestsPerAccount ?? 1,
|
|
12
|
+
maxConcurrentRequestsPerProjectModel: config.maxConcurrentRequestsPerProjectModel ?? 1,
|
|
13
|
+
projectCircuitBreaker429Threshold: config.projectCircuitBreaker429Threshold ?? 3,
|
|
14
|
+
projectCircuitBreakerWindowMs: config.projectCircuitBreakerWindowMs ?? 10 * 60 * 1000,
|
|
15
|
+
projectCircuitBreakerCooldownMs: config.projectCircuitBreakerCooldownMs ?? 60 * 60 * 1000,
|
|
16
|
+
modelCircuitBreaker429Threshold: config.modelCircuitBreaker429Threshold ?? 3,
|
|
17
|
+
modelCircuitBreakerCooldownMs: config.modelCircuitBreakerCooldownMs ?? 6 * 60 * 60 * 1000,
|
|
18
|
+
dailyAccountSlowRequests: config.dailyAccountSlowRequests ?? 250,
|
|
19
|
+
dailyAccountStopRequests: config.dailyAccountStopRequests ?? 350,
|
|
20
|
+
dailyProjectSlowRequests: config.dailyProjectSlowRequests ?? 900,
|
|
21
|
+
dailyProjectStopRequests: config.dailyProjectStopRequests ?? 1200,
|
|
22
|
+
slowModeJitterMinMs: config.slowModeJitterMinMs ?? 8_000,
|
|
23
|
+
slowModeJitterMaxMs: config.slowModeJitterMaxMs ?? 25_000,
|
|
24
|
+
protectivePauseMs: config.protectivePauseMs ?? 21600000,
|
|
25
|
+
useRequestCountRotationWhenQuotaUnknownOnly: config.useRequestCountRotationWhenQuotaUnknownOnly ?? true,
|
|
26
|
+
tokenBucketEnabled: config.tokenBucketEnabled ?? false,
|
|
27
|
+
tokenBucketMaxTokens: config.tokenBucketMaxTokens ?? 50,
|
|
28
|
+
tokenBucketRefillPerMinute: config.tokenBucketRefillPerMinute ?? 6,
|
|
29
|
+
tokenBucketInitialTokens: config.tokenBucketInitialTokens ?? (config.tokenBucketMaxTokens ?? 50),
|
|
30
|
+
accounts: config.accounts ? config.accounts.map((account) => ({
|
|
31
|
+
...account,
|
|
32
|
+
tier: account.tier || "unknown",
|
|
33
|
+
})) : [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getDefaultConfig(): Config {
|
|
38
|
+
return applyConfigDefaults({
|
|
39
|
+
proxyPort: 51200,
|
|
40
|
+
accounts: [],
|
|
41
|
+
requestsPerRotation: 5,
|
|
42
|
+
rotateOnQuotaDrop: 20,
|
|
43
|
+
quotaPollIntervalMs: 300000,
|
|
44
|
+
maxConcurrentRequestsPerAccount: 1,
|
|
45
|
+
maxConcurrentRequestsPerProjectModel: 1,
|
|
46
|
+
projectCircuitBreaker429Threshold: 3,
|
|
47
|
+
projectCircuitBreakerWindowMs: 10 * 60 * 1000,
|
|
48
|
+
projectCircuitBreakerCooldownMs: 60 * 60 * 1000,
|
|
49
|
+
modelCircuitBreaker429Threshold: 3,
|
|
50
|
+
modelCircuitBreakerCooldownMs: 6 * 60 * 60 * 1000,
|
|
51
|
+
dailyAccountSlowRequests: 250,
|
|
52
|
+
dailyAccountStopRequests: 350,
|
|
53
|
+
dailyProjectSlowRequests: 900,
|
|
54
|
+
dailyProjectStopRequests: 1200,
|
|
55
|
+
slowModeJitterMinMs: 8_000,
|
|
56
|
+
slowModeJitterMaxMs: 25_000,
|
|
57
|
+
protectivePauseMs: 21600000,
|
|
58
|
+
useRequestCountRotationWhenQuotaUnknownOnly: true,
|
|
59
|
+
tokenBucketEnabled: false,
|
|
60
|
+
tokenBucketMaxTokens: 50,
|
|
61
|
+
tokenBucketRefillPerMinute: 6,
|
|
62
|
+
tokenBucketInitialTokens: 50,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Config } from "./types.js";
|
|
2
|
+
import { getCachedConfig, setCachedConfig } from "./db-store.js";
|
|
3
|
+
import { getDefaultConfig } from "./config-defaults.js";
|
|
4
|
+
|
|
5
|
+
export function loadConfig(): Config {
|
|
6
|
+
const cached = getCachedConfig();
|
|
7
|
+
if (cached) return cached;
|
|
8
|
+
return getDefaultConfig();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function loadOrCreateAccountsConfig(): Config {
|
|
12
|
+
try {
|
|
13
|
+
return loadConfig();
|
|
14
|
+
} catch {
|
|
15
|
+
return getDefaultConfig();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function saveAccountsConfig(config: Config): void {
|
|
20
|
+
setCachedConfig(config);
|
|
21
|
+
}
|