/**
* Agent Configuration
*
* Constants and model configurations for the agent module.
* Extracted from agent.ts for modularity.
*/
// ============================================
// Display Defaults
// ============================================
/** Default display width when actual size cannot be determined */
export const DEFAULT_DISPLAY_WIDTH = 1024;
/** Default display height when actual size cannot be determined */
export const DEFAULT_DISPLAY_HEIGHT = 768;
/** Anthropic recommends max width for optimal computer use accuracy */
export const RECOMMENDED_MAX_WIDTH = 1280;
/** Anthropic recommends max height for optimal computer use accuracy */
export const RECOMMENDED_MAX_HEIGHT = 800;
/** Width of zoom region for Opus 4.5 zoom action */
export const ZOOM_REGION_WIDTH = 400;
/** Height of zoom region for Opus 4.5 zoom action */
export const ZOOM_REGION_HEIGHT = 300;
// ============================================
// Task Limits (enforced server-side)
// ============================================
/** Default max steps if not specified by client */
export const DEFAULT_MAX_STEPS = 100;
// ============================================
// Context Management
// ============================================
/**
* Maximum number of message exchanges to keep in history.
* Each exchange = assistant response + user tool results.
* Older exchanges are trimmed to prevent context bloat from accumulated screenshots.
* With 20 exchanges, we keep ~40 messages which allows for sufficient context
* while limiting token usage from base64 images (~30KB each, ~400 tokens).
*/
export const MAX_MESSAGE_HISTORY = 20;
/** Hard maximum steps - client cannot exceed this */
export const MAX_STEPS_LIMIT = 100;
/** Default timeout in seconds if not specified */
export const DEFAULT_TIMEOUT_SECONDS = 750;
/** Hard maximum timeout - must be below Vercel's maxDuration (800s) */
export const MAX_TIMEOUT_SECONDS = 750;
// ============================================
// Validation Constants
// ============================================
/** Maximum length for sandbox names */
export const SANDBOX_NAME_MAX_LENGTH = 64;
/** Maximum length for task IDs */
export const TASK_ID_MAX_LENGTH = 64;
// ============================================
// Timing Constants
// ============================================
/** Delay before retrying failed operations (ms) */
export const RETRY_DELAY_MS = 500;
/** Base delay for retry backoff (ms) */
export const RETRY_BACKOFF_BASE_MS = 100;
/** Maximum wait time for wait action (ms) */
export const MAX_WAIT_MS = 5000;
/** Interval for progress heartbeat during API calls (ms) */
export const HEARTBEAT_INTERVAL_MS = 5000;
/** Delay for UI to settle after actions (ms) */
export const UI_SETTLE_DELAY_MS = 500;
/** Max retries for Anthropic API calls (default is 2) */
export const ANTHROPIC_MAX_RETRIES = 4;
// ============================================
// Model Configurations
// ============================================
/**
* Configuration for a specific Claude model
*/
export type ModelConfig = {
model: string;
toolType: "computer_20250124" | "computer_20251124";
betaFlag: string;
supportsZoom: boolean;
};
/**
* Available model configurations
* Keys match the CUA_MODEL environment variable values
*/
export const MODEL_CONFIGS: Record<string, ModelConfig> = {
"claude-sonnet-4-5": {
model: "claude-sonnet-4-5-20250929",
toolType: "computer_20250124",
betaFlag: "computer-use-2025-01-24",
supportsZoom: false,
},
"claude-opus-4-5": {
model: "claude-opus-4-5-20251101",
toolType: "computer_20251124",
betaFlag: "computer-use-2025-11-24",
supportsZoom: true,
},
};
/** Default model key (Opus 4.5 for better accuracy) */
export const DEFAULT_MODEL = "claude-opus-4-5";
/**
* Get the model configuration based on environment variable
* Falls back to Sonnet 4.5 if unknown model specified
*/
export function getModelConfig(): ModelConfig {
const modelKey = process.env.CUA_MODEL || DEFAULT_MODEL;
const config = MODEL_CONFIGS[modelKey];
if (!config) {
console.warn(
`[Agent] Unknown model ${modelKey}, falling back to claude-sonnet-4-5`
);
return MODEL_CONFIGS["claude-sonnet-4-5"];
}
return config;
}