'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import { RAGFlowFormItem } from '@/components/ragflow-form'; import { Card, CardContent } from '@/components/ui/card'; import { Form } from '@/components/ui/form'; import { TagRenameId } from '@/constants/knowledge'; import { IModalProps } from '@/interfaces/common'; import { cn } from '@/lib/utils'; import { BrainCircuit, Check, Route } from 'lucide-react'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { FlowType } from './constant'; import { NameFormField, NameFormSchema } from './name-form-field'; export type CreateAgentFormProps = IModalProps & { shouldChooseAgent?: boolean; }; type FlowTypeCardProps = { value?: FlowType; onChange?: (value: FlowType) => void; }; function FlowTypeCards({ value, onChange }: FlowTypeCardProps) { const { t } = useTranslation(); const handleChange = useCallback( (value: FlowType) => () => { onChange?.(value); }, [onChange], ); return (
{Object.values(FlowType).map((val) => { const isActive = value === val; return (
{val === FlowType.Agent ? ( ) : ( )}

{t( `flow.${val === FlowType.Agent ? 'createAgent' : 'createPipeline'}`, )}

{isActive && }
); })}
); } export const FormSchema = z.object({ ...NameFormSchema, tag: z.string().trim().optional(), description: z.string().trim().optional(), type: z.nativeEnum(FlowType).optional(), }); export type FormSchemaType = z.infer; export function CreateAgentForm({ hideModal, onOk, shouldChooseAgent = false, }: CreateAgentFormProps) { const { t } = useTranslation(); const form = useForm({ resolver: zodResolver(FormSchema), defaultValues: { name: '', type: FlowType.Agent }, }); async function onSubmit(data: FormSchemaType) { const ret = await onOk?.(data); if (ret) { hideModal?.(); } } return (
{shouldChooseAgent && ( )}
); }