'use client' import type { FC } from 'react' import { Button } from '@langgenius/dify-ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@langgenius/dify-ui/dropdown-menu' import { toast } from '@langgenius/dify-ui/toast' import * as React from 'react' import { useState } from 'react' import { useTranslation } from 'react-i18next' import Input from '@/app/components/base/input' import { importSchemaFromURL } from '@/service/tools' import examples from './examples' type Props = Readonly<{ onChange: (value: string) => void }> const GetSchema: FC = ({ onChange }) => { const { t } = useTranslation() const [showImportFromUrl, setShowImportFromUrl] = useState(false) const [importUrl, setImportUrl] = useState('') const [isParsing, setIsParsing] = useState(false) const handleImportFromUrl = async () => { if (!importUrl.startsWith('http://') && !importUrl.startsWith('https://')) { toast.error(t(($) => $['createTool.urlError'], { ns: 'tools' })) return } setIsParsing(true) try { const { schema } = await importSchemaFromURL(importUrl) setImportUrl('') onChange(schema) } finally { setIsParsing(false) setShowImportFromUrl(false) } } const [showExamples, setShowExamples] = useState(false) return (
}> {t(($) => $['createTool.importFromUrl'], { ns: 'tools' })}
$['createTool.importFromUrlPlaceHolder'], { ns: 'tools' })!} value={importUrl} onChange={(e) => setImportUrl(e.target.value)} />
}> {t(($) => $['createTool.examples'], { ns: 'tools' })} {examples.map((item) => ( { onChange(item.content) setShowExamples(false) }} className="system-sm-regular whitespace-nowrap text-text-secondary" > {t(($) => $[`createTool.exampleOptions.${item.key}`], { ns: 'tools' })} ))}
) } export default React.memo(GetSchema)