import React, { useMemo, useState } from 'react'; import { MessageCircleQuestion } from 'lucide-react'; import { useI18n } from '../../application/i18n/I18nProvider'; import { Button } from '../ui/button'; import type { CodexAppServerInteraction } from '../../infrastructure/ai/shared/codexAppServerInteractions'; type UserInputInteraction = Extract; export const CodexUserInputCard: React.FC<{ interaction: UserInputInteraction; onSubmit: (answers: Record) => void; onSkip: () => void; }> = ({ interaction, onSubmit, onSkip }) => { const { t } = useI18n(); const [values, setValues] = useState>({}); const questions = useMemo(() => interaction.questions || [], [interaction.questions]); const complete = useMemo( () => questions.every((question) => String(values[question.id] || '').trim().length > 0), [questions, values], ); const submit = () => { if (!complete) return; const answers: Record = {}; for (const question of questions) { const value = String(values[question.id] || ''); answers[question.id] = { answers: [question.isSecret ? value : value.trim()] }; } onSubmit(answers); }; return (
{t('ai.codex.appServer.userInput.title')}
{t('ai.codex.appServer.userInput.description')}
{questions.map((question) => (
{question.header ? `${question.header}: ` : ''}{question.question} {question.options?.length ? (
{question.options.map((option) => ( ))} {question.isOther ? ( option.label === values[question.id]) ? '' : (values[question.id] || '')} onChange={(event) => setValues((current) => ({ ...current, [question.id]: event.target.value }))} placeholder={t('ai.codex.appServer.userInput.other')} className="h-8 w-full rounded-md border border-input bg-background px-2.5 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring" /> ) : null}
) : ( setValues((current) => ({ ...current, [question.id]: event.target.value }))} className="h-8 w-full rounded-md border border-input bg-background px-2.5 text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring" /> )}
))} {interaction.autoResolutionMs ? (

{t('ai.codex.appServer.userInput.autoResolve')}

) : null}
); };