import React, { useState } from 'react' import { PRODUCT_NAME } from '../constants/product' import { Box, Newline, Text, useInput } from 'ink' import { getGlobalConfig, saveGlobalConfig, DEFAULT_GLOBAL_CONFIG, ProviderType, } from '../utils/config.js' import { OrderedList } from '@inkjs/ui' import { useExitOnCtrlCD } from '../hooks/useExitOnCtrlCD' import { MIN_LOGO_WIDTH } from './Logo' import { Select } from './CustomSelect/select' import { StructuredDiff } from './StructuredDiff' import { getTheme, type ThemeNames } from '../utils/theme' import { clearTerminal } from '../utils/terminal' import { PressEnterToContinue } from './PressEnterToContinue' import { ModelSelector } from './ModelSelector' type StepId = 'theme' | 'usage' | 'providers' | 'model' interface OnboardingStep { id: StepId component: React.ReactNode } type Props = { onDone(): void } export function Onboarding({ onDone }: Props): React.ReactNode { const [currentStepIndex, setCurrentStepIndex] = useState(0) const [showModelSelector, setShowModelSelector] = useState(false) const config = getGlobalConfig() const [selectedTheme, setSelectedTheme] = useState( DEFAULT_GLOBAL_CONFIG.theme, ) const theme = getTheme() function goToNextStep() { if (currentStepIndex < steps.length - 1) { const nextIndex = currentStepIndex + 1 setCurrentStepIndex(nextIndex) } } function handleThemeSelection(newTheme: string) { saveGlobalConfig({ ...config, theme: newTheme as ThemeNames, }) goToNextStep() } function handleThemePreview(newTheme: string) { setSelectedTheme(newTheme as ThemeNames) } function handleProviderSelectionDone() { // After model selection is done, go to the next step goToNextStep() } function handleModelSelectionDone() { // After final model selection is done, complete onboarding onDone() } const exitState = useExitOnCtrlCD(() => process.exit(0)) useInput(async (_, key) => { const currentStep = steps[currentStepIndex] if ( key.return && currentStep && ['usage', 'providers', 'model'].includes(currentStep.id) ) { if (currentStep.id === 'model') { // Navigate to ModelSelector component setShowModelSelector(true) } else if (currentStepIndex === steps.length - 1) { onDone() } else { // HACK: for some reason there's now a jump here otherwise :( await clearTerminal() goToNextStep() } } }) // Define all onboarding steps const themeStep = ( Let's get started. Choose the option that looks best when you select it: To change this later, run /config