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/src/cli.ts CHANGED
@@ -8,56 +8,72 @@
8
8
 
9
9
  import { getConfigDir } from "./paths.js";
10
10
 
11
- const args = process.argv.slice(2).filter((a) => !a.startsWith("--config-dir") && a !== process.argv[process.argv.indexOf("--config-dir") + 1]);
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
- case "start": {
19
- // Dynamic import to avoid loading everything for help
20
- const { main } = await import("./index.js");
21
- main();
22
- break;
23
- }
24
- case "login": {
25
- const { runLogin } = await import("./login.js");
26
- runLogin();
27
- break;
28
- }
29
- case "status": {
30
- try {
31
- const port = 51200;
32
- const res = await fetch(`http://localhost:${port}/api/status`);
33
- const data = await res.json();
34
- console.log(JSON.stringify(data, null, 2));
35
- } catch {
36
- console.error("Rotator is not running or unreachable on port 51200");
37
- process.exit(1);
38
- }
39
- break;
40
- }
41
- case "doctor": {
42
- const { printDoctorReport, runDoctor } = await import("./doctor.js");
43
- const result = runDoctor();
44
- printDoctorReport(result);
45
- process.exit(result.ok ? 0 : 1);
46
- break;
47
- }
48
- default:
49
- console.log("Pi Antigravity Rotator");
50
- console.log();
51
- console.log("Usage:");
52
- console.log(" pi-antigravity-rotator start Start the proxy (default)");
53
- console.log(" pi-antigravity-rotator login Add a new Google account");
54
- console.log(" pi-antigravity-rotator status Show account status (JSON)");
55
- console.log(" pi-antigravity-rotator doctor Validate config and local state");
56
- console.log();
57
- console.log("Options:");
58
- console.log(" --config-dir <path> Config directory (default: ~/.pi-antigravity-rotator/)");
59
- console.log();
60
- console.log("Environment:");
61
- console.log(" PI_ROTATOR_DIR Config directory override");
62
- process.exit(command === "help" || command === "--help" ? 0 : 1);
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
+ }