refactor: extract shared error detection and token rotation utilities (SSOT)
- Create agent-error-detection.ts: single source for error classification (isClaudeUsageExhaustedMessage, isClaudeAuthExpiredMessage, classifyAgentError, etc.) - Create token-rotation-base.ts: shared rotation algorithm (parseRetryAfterFromError, computeCooldownUntil, findNextAvailable) - Remove 6 duplicated functions from message-agent-executor and task-scheduler - Delegate detectFallbackTrigger/detectCodexRotationTrigger to shared classifiers - Split canFallback into isClaudeAgent/canRotateToken/canFallback (3-way separation) - Cache env.ts with getEnv() to eliminate repeated disk I/O - Migrate config, discord, provider-fallback, token-rotation, memento-client to getEnv() Net: -146 lines, 0 new dependencies, 354/354 tests passing
This commit is contained in:
@@ -204,7 +204,6 @@ function loadCodexState(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Get the auth.json path for the current active account. */
|
/** Get the auth.json path for the current active account. */
|
||||||
export function getActiveCodexAuthPath(): string | null {
|
export function getActiveCodexAuthPath(): string | null {
|
||||||
if (accounts.length === 0) return null;
|
if (accounts.length === 0) return null;
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ export const STATUS_UPDATE_INTERVAL = 10000; // 10s
|
|||||||
export const USAGE_UPDATE_INTERVAL = 300000; // 5 minutes
|
export const USAGE_UPDATE_INTERVAL = 300000; // 5 minutes
|
||||||
export const STATUS_SHOW_ROOMS =
|
export const STATUS_SHOW_ROOMS =
|
||||||
(getEnv('STATUS_SHOW_ROOMS') || 'true') !== 'false';
|
(getEnv('STATUS_SHOW_ROOMS') || 'true') !== 'false';
|
||||||
export const USAGE_DASHBOARD_ENABLED =
|
export const USAGE_DASHBOARD_ENABLED = getEnv('USAGE_DASHBOARD') === 'true';
|
||||||
getEnv('USAGE_DASHBOARD') === 'true';
|
|
||||||
|
|
||||||
// Timezone for scheduled tasks (cron expressions, etc.)
|
// Timezone for scheduled tasks (cron expressions, etc.)
|
||||||
// Uses system timezone by default
|
// Uses system timezone by default
|
||||||
|
|||||||
@@ -82,10 +82,7 @@ function loadConfig(): FallbackConfig {
|
|||||||
authToken,
|
authToken,
|
||||||
model,
|
model,
|
||||||
smallModel: getEnv('FALLBACK_SMALL_MODEL') || model,
|
smallModel: getEnv('FALLBACK_SMALL_MODEL') || model,
|
||||||
defaultCooldownMs: parseInt(
|
defaultCooldownMs: parseInt(getEnv('FALLBACK_COOLDOWN_MS') || '600000', 10),
|
||||||
getEnv('FALLBACK_COOLDOWN_MS') || '600000',
|
|
||||||
10,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_config.enabled) {
|
if (_config.enabled) {
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ export {
|
|||||||
shouldUseTaskScopedSession,
|
shouldUseTaskScopedSession,
|
||||||
} from './task-watch-status.js';
|
} from './task-watch-status.js';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the next run time for a recurring task, anchored to the
|
* Compute the next run time for a recurring task, anchored to the
|
||||||
* task's scheduled time rather than Date.now() to prevent cumulative
|
* task's scheduled time rather than Date.now() to prevent cumulative
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ function loadState(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Get the current active token. */
|
/** Get the current active token. */
|
||||||
export function getCurrentToken(): string | undefined {
|
export function getCurrentToken(): string | undefined {
|
||||||
if (tokens.length === 0) return process.env.CLAUDE_CODE_OAUTH_TOKEN;
|
if (tokens.length === 0) return process.env.CLAUDE_CODE_OAUTH_TOKEN;
|
||||||
|
|||||||
Reference in New Issue
Block a user