/* * @Author: ZhaoYing * @Date: 2026-02-03 16:27:56 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-04-07 16:13:44 */ /** * Copy Application Modal * Allows users to duplicate an existing application with a new name */ import { forwardRef, useImperativeHandle, useState, useRef } from 'react'; import { Form, Button, Flex } from 'antd'; import { useTranslation } from 'react-i18next'; import clsx from 'clsx' import type { FeaturesConfigModalRef, FeaturesConfigForm } from '../../types' import RbModal from '@/components/RbModal' import SwitchFormItem from '@/components/FormItem/SwitchFormItem' import FileUploadSettingModal from './FileUploadSettingModal' import type { Application } from '@/views/ApplicationManagement/types'; import type { Capability } from '@/views/ModelManagement/types' import OpenStatementSettingModal, { type OpenStatementSettingModalRef } from './OpenStatementSettingModal' import type { Variable } from '../VariableList/types' interface FeaturesConfigModalProps { refresh: (value: FeaturesConfigForm) => void; source?: Application['type']; capability?: Capability[]; chatVariables: Variable[]; } const max_file_count = 1; /** * Modal for copying applications */ const FeaturesConfigModal = forwardRef(({ refresh, source, capability, chatVariables }, ref) => { const { t } = useTranslation(); const [visible, setVisible] = useState(false); const [form] = Form.useForm(); const values = Form.useWatch([], form) const fileUploadSettingModalRef = useRef(null) const openStatementSettingModalRef = useRef(null) /** Close modal and reset form */ const handleClose = () => { setVisible(false); form.resetFields(); }; /** Open modal */ const handleOpen = (initValue: FeaturesConfigForm) => { setVisible(true); form.setFieldsValue(initValue) }; /** Copy application with new name */ const handleSave = () => { form.validateFields().then((values) => { setVisible(false); refresh(values) }) } const handleOpenSettings = () => { fileUploadSettingModalRef.current?.handleOpen(values?.file_upload) } const handleSaveSettings = (settings: FeaturesConfigForm['file_upload']) => { form.setFieldValue('file_upload', { ...settings, enabled: values?.file_upload?.enabled ?? false }) } const formatFileTypeOptions = (fu: FeaturesConfigForm['file_upload']) => { let options = fu.document_enabled ? [{ type: 'document', enabled: fu.document_enabled, maxSize: fu.document_max_size_mb }] : [] if (!capability && source !== 'workflow') return options if ((capability?.includes('vision') || source === 'workflow') && fu.image_enabled) { options.push({ type: 'image', enabled: fu.image_enabled, maxSize: fu.image_max_size_mb }) } if ((capability?.includes('audio') || source === 'workflow') && fu.audio_enabled) { options.push({ type: 'audio', enabled: fu.audio_enabled, maxSize: fu.audio_max_size_mb }) } if ((capability?.includes('video') || source === 'workflow') && fu.video_enabled) { options.push({ type: 'video', enabled: fu.video_enabled, maxSize: fu.video_max_size_mb }) } return options.filter(item => item.enabled) } const handleOpenStatementSettings = () => { openStatementSettingModalRef.current?.handleOpen(values?.opening_statement) } const handleSaveStatement = (settings: FeaturesConfigForm['opening_statement']) => { form.setFieldValue('opening_statement', settings) } /** Expose methods to parent component */ useImperativeHandle(ref, () => ({ handleOpen, handleClose })); return ( <>
{values?.opening_statement?.enabled && (() => { const statement = values.opening_statement?.statement return statement && statement.trim() !== '' ? <>
{statement}
: })()}
{source !== 'workflow' && <>
}
{values?.file_upload?.enabled && (() => { const fu = values.file_upload // 'vision' | 'audio' | 'video' const filterTypes = formatFileTypeOptions(fu) return filterTypes.length > 0 ? <>
{t(`application.supportedTypes`)}
{t('application.singleMaxSize')}
{filterTypes.map((item, index) => (
{t(`application.${item.type}`)}
{item.maxSize} MB
))}
{t('application.maxCount')}
{max_file_count} {t('application.unix')}
: })()}
); }); export default FeaturesConfigModal;