'use client' import React, { useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine } from '@remixicon/react' import AppIconPicker from '@/app/components/base/app-icon-picker' import type { AppIconSelection } from '@/app/components/base/app-icon-picker' import AppIcon from '@/app/components/base/app-icon' import Modal from '@/app/components/base/modal' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import type { AppIconType } from '@/types/app' import type { ToolWithProvider } from '@/app/components/workflow/types' import { noop } from 'lodash-es' import cn from '@/utils/classnames' export type DuplicateAppModalProps = { data?: ToolWithProvider show: boolean onConfirm: (info: { name: string server_url: string icon_type: AppIconType icon: string icon_background?: string | null }) => void onHide: () => void } const DEFAULT_ICON = { type: 'emoji', icon: '🧿', background: '#EFF1F5' } const extractFileId = (url: string) => { const match = url.match(/files\/(.+?)\/file-preview/) return match ? match[1] : null } const getIcon = (data?: ToolWithProvider) => { if (!data) return DEFAULT_ICON as AppIconSelection if (typeof data.icon === 'string') return { type: 'image', url: data.icon, fileId: extractFileId(data.icon) } as AppIconSelection return { ...data.icon, icon: data.icon.content, type: 'emoji', } as unknown as AppIconSelection } const MCPModal = ({ data, show, onConfirm, onHide, }: DuplicateAppModalProps) => { const { t } = useTranslation() const [name, setName] = React.useState(data?.name || '') const [appIcon, setAppIcon] = useState(getIcon(data)) const [url, setUrl] = React.useState(data?.server_url || '') const [showAppIconPicker, setShowAppIconPicker] = useState(false) const submit = async () => { await onConfirm({ name, server_url: url, icon_type: appIcon.type, icon: appIcon.type === 'emoji' ? appIcon.icon : appIcon.fileId, icon_background: appIcon.type === 'emoji' ? appIcon.background : undefined, }) onHide() } return ( <>
{t('tools.mcp.modal.title')}
{t('tools.mcp.modal.name')}
setName(e.target.value)} placeholder={t('tools.mcp.modal.namePlaceholder')} />
{ setShowAppIconPicker(true) }} />
{t('tools.mcp.modal.serverUrl')}
setUrl(e.target.value)} placeholder={t('tools.mcp.modal.serverUrlPlaceholder')} />
{showAppIconPicker && { setAppIcon(payload) setShowAppIconPicker(false) }} onClose={() => { setAppIcon(getIcon(data)) setShowAppIconPicker(false) }} />} ) } export default MCPModal