diff --git a/web/src/components/ragflow-form.tsx b/web/src/components/ragflow-form.tsx index 0afe9a670..4151e6fef 100644 --- a/web/src/components/ragflow-form.tsx +++ b/web/src/components/ragflow-form.tsx @@ -15,6 +15,7 @@ type RAGFlowFormItemProps = { tooltip?: ReactNode; children: ReactNode | ((field: ControllerRenderProps) => ReactNode); horizontal?: boolean; + required?: boolean; }; export function RAGFlowFormItem({ @@ -23,6 +24,7 @@ export function RAGFlowFormItem({ tooltip, children, horizontal = false, + required = false, }: RAGFlowFormItemProps) { const form = useFormContext(); return ( @@ -35,7 +37,11 @@ export function RAGFlowFormItem({ 'flex items-center': horizontal, })} > - + {label} diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsx index f65644ee0..d091c1f03 100644 --- a/web/src/components/ui/dialog.tsx +++ b/web/src/components/ui/dialog.tsx @@ -38,7 +38,7 @@ const DialogContent = React.forwardRef< ( MenuItemKey.Recommended, ); + useEffect(() => { setTemplateList(list); }, [list]); + const { visible: creatingVisible, hideModal: hideCreatingModal, diff --git a/web/src/pages/agents/create-agent-dialog.tsx b/web/src/pages/agents/create-agent-dialog.tsx index 00815d0bc..c4b7fd467 100644 --- a/web/src/pages/agents/create-agent-dialog.tsx +++ b/web/src/pages/agents/create-agent-dialog.tsx @@ -6,16 +6,18 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; -import { IModalProps } from '@/interfaces/common'; import { TagRenameId } from '@/pages/add-knowledge/constant'; import { useTranslation } from 'react-i18next'; -import { CreateAgentForm } from './create-agent-form'; +import { CreateAgentForm, CreateAgentFormProps } from './create-agent-form'; + +type CreateAgentDialogProps = CreateAgentFormProps; export function CreateAgentDialog({ hideModal, onOk, loading, -}: IModalProps) { + shouldChooseAgent, +}: CreateAgentDialogProps) { const { t } = useTranslation(); return ( @@ -24,7 +26,11 @@ export function CreateAgentDialog({ {t('flow.createGraph')} - + {t('common.save')} diff --git a/web/src/pages/agents/create-agent-form.tsx b/web/src/pages/agents/create-agent-form.tsx index 43883b9ab..fac0cbb1e 100644 --- a/web/src/pages/agents/create-agent-form.tsx +++ b/web/src/pages/agents/create-agent-form.tsx @@ -4,6 +4,8 @@ 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, FormControl, @@ -14,10 +16,76 @@ import { } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { IModalProps } from '@/interfaces/common'; +import { cn } from '@/lib/utils'; import { TagRenameId } from '@/pages/add-knowledge/constant'; +import { BrainCircuit, Check, Route } from 'lucide-react'; +import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -export function CreateAgentForm({ hideModal, onOk }: IModalProps) { +export type CreateAgentFormProps = IModalProps & { + shouldChooseAgent?: boolean; +}; + +enum FlowType { + Agent = 'agent', + Flow = 'flow', +} + +type FlowTypeCardProps = { + value?: FlowType; + onChange?: (value: FlowType) => void; +}; +function FlowTypeCards({ value, onChange }: FlowTypeCardProps) { + const handleChange = useCallback( + (value: FlowType) => () => { + onChange?.(value); + }, + [onChange], + ); + + return ( +
+ {Object.values(FlowType).map((val) => { + const isActive = value === val; + return ( + + +
+ {val === FlowType.Agent ? ( + + ) : ( + + )} +

{val}

+
+ {isActive && } +
+
+ ); + })} +
+ ); +} + +export function CreateAgentForm({ + hideModal, + onOk, + shouldChooseAgent = false, +}: CreateAgentFormProps) { const { t } = useTranslation(); const FormSchema = z.object({ name: z @@ -28,11 +96,12 @@ export function CreateAgentForm({ hideModal, onOk }: IModalProps) { .trim(), tag: z.string().trim().optional(), description: z.string().trim().optional(), + type: z.nativeEnum(FlowType).optional(), }); const form = useForm>({ resolver: zodResolver(FormSchema), - defaultValues: { name: '' }, + defaultValues: { name: '', type: FlowType.Agent }, }); async function onSubmit(data: z.infer) { @@ -49,12 +118,17 @@ export function CreateAgentForm({ hideModal, onOk }: IModalProps) { className="space-y-6" id={TagRenameId} > + {shouldChooseAgent && ( + + + + )} ( - {t('common.name')} + {t('common.name')} ) { )} /> - {/* ( - - {t('flow.tag')} - - - - - - )} - /> - ( - - {t('flow.description')} - - - - - - )} - /> */} ); diff --git a/web/src/pages/agents/index.tsx b/web/src/pages/agents/index.tsx index d4d5c913a..95c6f1808 100644 --- a/web/src/pages/agents/index.tsx +++ b/web/src/pages/agents/index.tsx @@ -1,14 +1,22 @@ import ListFilterBar from '@/components/list-filter-bar'; import { RenameDialog } from '@/components/rename-dialog'; import { Button } from '@/components/ui/button'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '@/components/ui/dropdown-menu'; import { RAGFlowPagination } from '@/components/ui/ragflow-pagination'; +import { useSetModalState } from '@/hooks/common-hooks'; import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks'; import { useFetchAgentListByPage } from '@/hooks/use-agent-request'; import { t } from 'i18next'; import { pick } from 'lodash'; -import { Plus } from 'lucide-react'; +import { Clipboard, ClipboardPlus, FileInput, Plus } from 'lucide-react'; import { useCallback } from 'react'; import { AgentCard } from './agent-card'; +import { CreateAgentDialog } from './create-agent-dialog'; import { useRenameAgent } from './use-rename-agent'; export default function Agents() { @@ -25,6 +33,12 @@ export default function Agents() { showAgentRenameModal, } = useRenameAgent(); + const { + visible: creatingVisible, + hideModal: hideCreatingModal, + showModal: showCreatingModal, + } = useSetModalState(); + const handlePageChange = useCallback( (page: number, pageSize?: number) => { setPagination({ page, pageSize }); @@ -41,10 +55,34 @@ export default function Agents() { onSearchChange={handleInputChange} icon="agent" > - + + + + + + + + Create from Blank + + + + Create from Template + + + + Import json file + + +
@@ -75,6 +113,15 @@ export default function Agents() { loading={agentRenameLoading} > )} + {creatingVisible && ( + {}} + > + )} ); }