/** * Codex Configuration Form Component * * Provides UI for configuring OpenAI Codex-specific execution settings. */ import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Switch } from '@/components/ui/switch' import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible' import { ChevronDown, Loader2 } from 'lucide-react' import { useState, useEffect } from 'react' import axios from 'axios' export interface CodexConfig { model?: string sandbox?: 'read-only' | 'workspace-write' | 'danger-full-access' askForApproval?: 'untrusted' | 'on-failure' | 'on-request' | 'never' fullAuto?: boolean search?: boolean json?: boolean color?: 'always' | 'never' | 'auto' } interface CodexConfigFormProps { config: CodexConfig onChange: (config: CodexConfig) => void } // Special value for "let agent decide" - will be converted to undefined when saving const DEFAULT_MODEL_VALUE = '__default__' // Default option shown while loading or if API fails const DEFAULT_MODEL_OPTION = { value: DEFAULT_MODEL_VALUE, label: 'Default (Agent Decides)' } /** * Format a model ID into a human-readable label */ function formatModelName(modelId: string): string { // Handle common patterns if (modelId.includes('gpt')) { return modelId.toUpperCase().replace(/-/g, ' ') } if (modelId.includes('o1') || modelId.includes('o3')) { return modelId.toUpperCase() } // Fallback: capitalize and clean up return modelId .replace(/[-_]/g, ' ') .replace(/\b\w/g, (c) => c.toUpperCase()) } interface ModelOption { value: string label: string } const SANDBOX_OPTIONS = [ { value: 'read-only', label: 'Read Only', description: 'Can only read files' }, { value: 'workspace-write', label: 'Workspace Write', description: 'Can write to workspace' }, { value: 'danger-full-access', label: 'Full Access', description: 'Unrestricted access' }, ] const APPROVAL_OPTIONS = [ { value: 'untrusted', label: 'Untrusted', description: 'Ask for every action' }, { value: 'on-failure', label: 'On Failure', description: 'Ask only when operations fail' }, { value: 'on-request', label: 'On Request', description: 'Ask when agent requests approval' }, { value: 'never', label: 'Never', description: 'Never ask for approval' }, ] export function CodexConfigForm({ config, onChange }: CodexConfigFormProps) { const [showAdvanced, setShowAdvanced] = useState(false) const [errors, setErrors] = useState>({}) const [models, setModels] = useState([DEFAULT_MODEL_OPTION]) const [modelsLoading, setModelsLoading] = useState(true) // Fetch available models from the agent useEffect(() => { let cancelled = false async function fetchModels() { try { // Use axios directly - /agents endpoints don't use ApiResponse wrapper const response = await axios.get<{ models: string[]; cached: boolean; fallback?: boolean }>( '/api/agents/codex/models' ) if (cancelled) return const data = response.data if (data.models && data.models.length > 0) { // Filter out "default" from API response (we add our own Default option) const apiModels = data.models .filter((model: string) => model.toLowerCase() !== 'default') .map((model: string) => ({ value: model, label: formatModelName(model), })) setModels([DEFAULT_MODEL_OPTION, ...apiModels]) } } catch (error) { // Keep just the default option on error console.warn('Failed to fetch Codex models:', error) } finally { if (!cancelled) { setModelsLoading(false) } } } fetchModels() return () => { cancelled = true } }, []) const validateConfig = (_newConfig: CodexConfig): Record => { // No validation errors - fullAuto simply overrides sandbox/approval settings // When fullAuto is enabled, sandbox and approval inputs are disabled in the UI return {} } const updateConfig = (updates: Partial) => { let newConfig = { ...config, ...updates } // When fullAuto is enabled, clear sandbox and approval settings // since fullAuto uses its own defaults (workspace-write, on-request) if (updates.fullAuto === true) { newConfig = { ...newConfig, sandbox: undefined, askForApproval: undefined, } } const validationErrors = validateConfig(newConfig) setErrors(validationErrors) onChange(newConfig) } return (
{/* Validation Errors */} {Object.keys(errors).length > 0 && (
{Object.values(errors).map((error, i) => (
{error}
))}
)} {/* Model Selection */}
{/* Full Auto Mode */}

Workspace write + auto-approve on failure

updateConfig({ fullAuto: checked })} />
{/* Web Search */}

Enable web browsing capability

updateConfig({ search: checked })} />
{/* JSON Output */}

Structured output format

updateConfig({ json: checked })} />
{/* Advanced Settings */} Advanced Settings {/* Sandbox Policy (disabled when fullAuto is enabled) */}
{config.fullAuto && (

Disabled when Full Auto Mode is enabled

)}
{/* Approval Policy (disabled when fullAuto is enabled) */}
{config.fullAuto && (

Disabled when Full Auto Mode is enabled

)}
{/* Color Output */}
) }