'use client' import type { FC } from 'react' import React, { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import { PortalToFollowElem, PortalToFollowElemContent, } from '@/app/components/base/portal-to-follow-elem' import { Lock01 } from '@/app/components/base/icons/src/vender/solid/security' import Button from '@/app/components/base/button' import type { FirecrawlConfig } from '@/models/common' import Field from '@/app/components/datasets/create/website/base/field' import Toast from '@/app/components/base/toast' import { createDataSourceApiKeyBinding } from '@/service/datasets' import { LinkExternal02 } from '@/app/components/base/icons/src/vender/line/general' type Props = { onCancel: () => void onSaved: () => void } const I18N_PREFIX = 'datasetCreation.firecrawl' const DEFAULT_BASE_URL = 'https://api.firecrawl.dev' const ConfigFirecrawlModal: FC = ({ onCancel, onSaved, }) => { const { t } = useTranslation() const [isSaving, setIsSaving] = useState(false) const [config, setConfig] = useState({ api_key: '', base_url: '', }) const handleConfigChange = useCallback((key: string) => { return (value: string | number) => { setConfig(prev => ({ ...prev, [key]: value as string })) } }, []) const handleSave = useCallback(async () => { if (isSaving) return let errorMsg = '' if (config.base_url && !((config.base_url.startsWith('http://') || config.base_url.startsWith('https://')))) errorMsg = t('common.errorMsg.urlError') if (!errorMsg) { if (!config.api_key) { errorMsg = t('common.errorMsg.fieldRequired', { field: 'API Key', }) } } if (errorMsg) { Toast.notify({ type: 'error', message: errorMsg, }) return } const postData = { category: 'website', provider: 'firecrawl', credentials: { auth_type: 'bearer', config: { api_key: config.api_key, base_url: config.base_url || DEFAULT_BASE_URL, }, }, } try { setIsSaving(true) await createDataSourceApiKeyBinding(postData) Toast.notify({ type: 'success', message: t('common.api.success'), }) } finally { setIsSaving(false) } onSaved() }, [config.api_key, config.base_url, onSaved, t, isSaving]) return (
{t(`${I18N_PREFIX}.configFirecrawl`)}
{t(`${I18N_PREFIX}.getApiKeyLinkText`)}
{t('common.modelProvider.encrypted.front')} PKCS1_OAEP {t('common.modelProvider.encrypted.back')}
) } export default React.memo(ConfigFirecrawlModal)