/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ import type React from 'react'; import { useMemo, useCallback } from 'react'; import { Box, Text } from 'ink'; import { Colors } from '../../colors.js'; import { useKeypress } from '../../hooks/useKeypress.js'; import { RadioButtonSelect, type RadioSelectItem, } from '../shared/RadioButtonSelect.js'; import type { ModelInfo, ModelsLoadStatus, } from '../../hooks/useWelcomeOnboarding.js'; interface ModelSelectStepProps { provider: string; models: ModelInfo[]; modelsLoadStatus: ModelsLoadStatus; onSelect: (modelId: string) => void | Promise; onBack: () => void; isFocused?: boolean; } const ModelSelectHeader: React.FC<{ providerDisplay: string }> = ({ providerDisplay, }) => ( Step 2 of 5: Choose Your Model Select a model for {providerDisplay}: ); const ModelLoadingState: React.FC = () => ( Loading models... ); const ModelErrorState: React.FC = () => ( Failed to load models. Press Esc to go back and try again. ); const ModelEmptyState: React.FC = () => ( No models available for this provider. Press Esc to go back and select a different provider. ); const ModelFooterHint: React.FC<{ showNavHint: boolean }> = ({ showNavHint, }) => ( {showNavHint ? 'Use ↑↓ to navigate, Enter to select' : 'Press Esc to go back'} ); export const ModelSelectStep: React.FC = ({ provider, models, modelsLoadStatus, onSelect, onBack, isFocused = true, }) => { const providerDisplay = provider.charAt(0).toUpperCase() + provider.slice(1); const options: Array> = useMemo(() => { const modelOptions = models.map((model) => ({ label: model.name, value: model.id, key: model.id, })); modelOptions.push({ label: '← Back to provider selection', value: '__back__', key: '__back__', }); return modelOptions; }, [models]); const handleSelect = useCallback( (value: string) => { if (value === '__back__') { onBack(); } else { void onSelect(value); } }, [onBack, onSelect], ); useKeypress( (key) => { if (key.name === 'escape') { onBack(); } }, { isActive: isFocused }, ); const showNavHint = modelsLoadStatus === 'success' && models.length > 0; return ( {modelsLoadStatus === 'loading' && } {modelsLoadStatus === 'error' && } {modelsLoadStatus === 'success' && models.length > 0 && ( )} {modelsLoadStatus === 'success' && models.length === 0 && ( )} ); };