'use client' import { useState } from 'react' import { useTranslation } from 'react-i18next' import Modal from '@/app/components/base/modal' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Textarea from '@/app/components/base/textarea' import Switch from '@/app/components/base/switch' import Toast from '@/app/components/base/toast' import Select from '@/app/components/base/select' import { createRedBlueChallenge } from '@/service/console/challenges' import { useAppFullList } from '@/service/use-apps' import { useAppWorkflow } from '@/service/use-workflow' type Props = { show: boolean onHide: () => void onSuccess: () => void } export default function CreateRedBlueModal({ show, onHide, onSuccess }: Props) { const { t } = useTranslation() const [form, setForm] = useState({ app_id: '', workflow_id: '', name: '', description: '', judge_suite: ['CBRNE', 'SA', 'SH', 'RWH', 'V', 'M'], defense_selection_policy: 'latest_best', attack_selection_policy: 'latest_best', scoring_strategy: 'red_blue_ratio', is_active: true, }) const [loading, setLoading] = useState(false) const { data: appsData } = useAppFullList() const apps = appsData?.data || [] const { data: workflowData } = useAppWorkflow(form.app_id) const hasWorkflow = !!workflowData?.graph const handleSubmit = async () => { if (!form.app_id || !form.name) { Toast.notify({ type: 'error', message: 'App ID and Name are required' }) return } setLoading(true) try { await createRedBlueChallenge(form) Toast.notify({ type: 'success', message: 'Red/Blue challenge created successfully' }) onSuccess() } catch (e: any) { Toast.notify({ type: 'error', message: e.message || 'Failed to create challenge' }) } finally { setLoading(false) } } return (
{workflowData?.id ? `Workflow ID: ${workflowData.id}` : 'No workflow published'}
)}
setForm({ ...form, name: e.target.value })} placeholder={t('challenges.console.form.namePlaceholder')} />