pi-antigravity-rotator 2.2.1 → 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 +23 -4
- package/README.md +14 -5
- package/package.json +3 -1
- package/src/account-store.ts +109 -168
- package/src/admin-auth.ts +74 -83
- package/src/cli.ts +62 -46
- package/src/compat/cache.ts +42 -0
- package/src/compat/model-specs.ts +78 -0
- package/src/compat/schema-sanitizer.ts +277 -0
- package/src/compat/translators.ts +1538 -0
- package/src/compat.ts +1535 -2444
- 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/notification-poller.ts +1 -1
- 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/telemetry.ts +1 -1
- package/src/types.ts +501 -397
|
@@ -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
|
+
}
|