working companion prototype
This commit is contained in:
@@ -10,13 +10,61 @@
|
||||
* - NODE_ENV=test → MockBrowserAutomation → N/A → N/A
|
||||
*/
|
||||
|
||||
export type AutomationMode = 'production' | 'test';
|
||||
export type AutomationMode = 'production' | 'development' | 'test';
|
||||
|
||||
/**
|
||||
* @deprecated Use AutomationMode instead. Will be removed in future version.
|
||||
*/
|
||||
export type LegacyAutomationMode = 'dev' | 'production' | 'mock';
|
||||
|
||||
/**
|
||||
* Retry configuration for element finding operations.
|
||||
*/
|
||||
export interface RetryConfig {
|
||||
/** Maximum number of retry attempts (default: 3) */
|
||||
maxRetries: number;
|
||||
/** Initial delay in milliseconds before first retry (default: 500) */
|
||||
baseDelayMs: number;
|
||||
/** Maximum delay in milliseconds between retries (default: 5000) */
|
||||
maxDelayMs: number;
|
||||
/** Multiplier for exponential backoff (default: 2.0) */
|
||||
backoffMultiplier: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timing configuration for automation operations.
|
||||
*/
|
||||
export interface TimingConfig {
|
||||
/** Wait time for page to load after opening browser (default: 5000) */
|
||||
pageLoadWaitMs: number;
|
||||
/** Delay between sequential actions (default: 200) */
|
||||
interActionDelayMs: number;
|
||||
/** Delay after clicking an element (default: 300) */
|
||||
postClickDelayMs: number;
|
||||
/** Delay before starting step execution (default: 100) */
|
||||
preStepDelayMs: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default retry configuration values.
|
||||
*/
|
||||
export const DEFAULT_RETRY_CONFIG: RetryConfig = {
|
||||
maxRetries: 3,
|
||||
baseDelayMs: 500,
|
||||
maxDelayMs: 5000,
|
||||
backoffMultiplier: 2.0,
|
||||
};
|
||||
|
||||
/**
|
||||
* Default timing configuration values.
|
||||
*/
|
||||
export const DEFAULT_TIMING_CONFIG: TimingConfig = {
|
||||
pageLoadWaitMs: 5000,
|
||||
interActionDelayMs: 200,
|
||||
postClickDelayMs: 300,
|
||||
preStepDelayMs: 100,
|
||||
};
|
||||
|
||||
export interface AutomationEnvironmentConfig {
|
||||
mode: AutomationMode;
|
||||
|
||||
@@ -27,6 +75,10 @@ export interface AutomationEnvironmentConfig {
|
||||
windowTitle?: string;
|
||||
templatePath?: string;
|
||||
confidence?: number;
|
||||
/** Retry configuration for element finding */
|
||||
retry?: Partial<RetryConfig>;
|
||||
/** Timing configuration for waits */
|
||||
timing?: Partial<TimingConfig>;
|
||||
};
|
||||
|
||||
/** Default timeout for automation operations in milliseconds */
|
||||
@@ -60,8 +112,9 @@ export function getAutomationMode(): AutomationMode {
|
||||
}
|
||||
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
// Both production and development use real OS automation
|
||||
if (nodeEnv === 'production' || nodeEnv === 'development') return 'production';
|
||||
// Map NODE_ENV to AutomationMode
|
||||
if (nodeEnv === 'production') return 'production';
|
||||
if (nodeEnv === 'development') return 'development';
|
||||
return 'test';
|
||||
}
|
||||
|
||||
@@ -89,8 +142,20 @@ export function loadAutomationConfig(): AutomationEnvironmentConfig {
|
||||
mouseSpeed: parseIntSafe(process.env.NUTJS_MOUSE_SPEED, 1000),
|
||||
keyboardDelay: parseIntSafe(process.env.NUTJS_KEYBOARD_DELAY, 50),
|
||||
windowTitle: process.env.IRACING_WINDOW_TITLE || 'iRacing',
|
||||
templatePath: process.env.TEMPLATE_PATH || './resources/templates',
|
||||
templatePath: process.env.TEMPLATE_PATH || './resources/templates/iracing',
|
||||
confidence: parseFloatSafe(process.env.OCR_CONFIDENCE, 0.9),
|
||||
retry: {
|
||||
maxRetries: parseIntSafe(process.env.AUTOMATION_MAX_RETRIES, DEFAULT_RETRY_CONFIG.maxRetries),
|
||||
baseDelayMs: parseIntSafe(process.env.AUTOMATION_BASE_DELAY_MS, DEFAULT_RETRY_CONFIG.baseDelayMs),
|
||||
maxDelayMs: parseIntSafe(process.env.AUTOMATION_MAX_DELAY_MS, DEFAULT_RETRY_CONFIG.maxDelayMs),
|
||||
backoffMultiplier: parseFloatSafe(process.env.AUTOMATION_BACKOFF_MULTIPLIER, DEFAULT_RETRY_CONFIG.backoffMultiplier),
|
||||
},
|
||||
timing: {
|
||||
pageLoadWaitMs: parseIntSafe(process.env.AUTOMATION_PAGE_LOAD_WAIT_MS, DEFAULT_TIMING_CONFIG.pageLoadWaitMs),
|
||||
interActionDelayMs: parseIntSafe(process.env.AUTOMATION_INTER_ACTION_DELAY_MS, DEFAULT_TIMING_CONFIG.interActionDelayMs),
|
||||
postClickDelayMs: parseIntSafe(process.env.AUTOMATION_POST_CLICK_DELAY_MS, DEFAULT_TIMING_CONFIG.postClickDelayMs),
|
||||
preStepDelayMs: parseIntSafe(process.env.AUTOMATION_PRE_STEP_DELAY_MS, DEFAULT_TIMING_CONFIG.preStepDelayMs),
|
||||
},
|
||||
},
|
||||
defaultTimeout: parseIntSafe(process.env.AUTOMATION_TIMEOUT, 30000),
|
||||
retryAttempts: parseIntSafe(process.env.RETRY_ATTEMPTS, 3),
|
||||
@@ -102,7 +167,7 @@ export function loadAutomationConfig(): AutomationEnvironmentConfig {
|
||||
* Type guard to validate automation mode string.
|
||||
*/
|
||||
function isValidAutomationMode(value: string | undefined): value is AutomationMode {
|
||||
return value === 'production' || value === 'test';
|
||||
return value === 'production' || value === 'development' || value === 'test';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user