'use client' import type { FC } from 'react' import React, { useState } from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import { Settings01 } from '../../base/icons/src/vender/line/general' import ConfigCredentials from './config-credentials' import type { Credential, CustomCollectionBackend, CustomParamSchema } from '@/app/components/tools/types' import Button from '@/app/components/base/button' import Drawer from '@/app/components/base/drawer-plus' import I18n from '@/context/i18n' import { testAPIAvailable } from '@/service/tools' import { getModelRuntimeSupported } from '@/utils/language' type Props = { customCollection: CustomCollectionBackend tool: CustomParamSchema onHide: () => void } const keyClassNames = 'py-2 leading-5 text-sm font-medium text-gray-900' const TestApi: FC = ({ customCollection, tool, onHide, }) => { const { t } = useTranslation() const { locale } = useContext(I18n) const language = getModelRuntimeSupported(locale) const [credentialsModalShow, setCredentialsModalShow] = useState(false) const [tempCredential, setTempCredential] = React.useState(customCollection.credentials) const [result, setResult] = useState('') const { operation_id: toolName, parameters } = tool const [parametersValue, setParametersValue] = useState>({}) const handleTest = async () => { const data = { tool_name: toolName, credentials: tempCredential, schema_type: customCollection.schema_type, schema: customCollection.schema, parameters: parametersValue, } const res = await testAPIAvailable(data) as any setResult(res.error || res.result) } return ( <>
{t('tools.createTool.authMethod.title')}
setCredentialsModalShow(true)}>
{t(`tools.createTool.authMethod.types.${tempCredential.auth_type}`)}
{t('tools.test.parametersValue')}
{parameters.map((item, index) => ( ))}
{t('tools.test.parameters')} {t('tools.test.value')}
{item.label[language]} setParametersValue({ ...parametersValue, [item.name]: e.target.value })} type='text' className='px-3 h-[34px] w-full outline-none focus:bg-gray-100' >
{t('tools.test.testResult')}
{result || {t('tools.test.testResultPlaceholder')}}
} /> {credentialsModalShow && ( setCredentialsModalShow(false)} />) } ) } export default React.memo(TestApi)