import { SelectWithSearch } from '@/components/originui/select-with-search'; import { FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { Radio } from '@/components/ui/radio'; import { Spin } from '@/components/ui/spin'; import { Switch } from '@/components/ui/switch'; import { useTranslate } from '@/hooks/common-hooks'; import { cn } from '@/lib/utils'; import { useMemo, useState } from 'react'; import { FieldValues, useFormContext } from 'react-hook-form'; import { useHandleKbEmbedding, useHasParsedDocument, useSelectChunkMethodList, useSelectEmbeddingModelOptions, } from '../hooks'; interface IProps { line?: 1 | 2; isEdit?: boolean; } export function ChunkMethodItem(props: IProps) { const { line } = props; const { t } = useTranslate('knowledgeConfiguration'); const form = useFormContext(); // const handleChunkMethodSelectChange = useHandleChunkMethodSelectChange(form); const parserList = useSelectChunkMethodList(); return ( (
{t('builtIn')}
)} /> ); } export const EmbeddingSelect = ({ isEdit, field, name, }: { isEdit: boolean; field: FieldValues; name?: string; }) => { const { t } = useTranslate('knowledgeConfiguration'); const form = useFormContext(); const embeddingModelOptions = useSelectEmbeddingModelOptions(); const { handleChange } = useHandleKbEmbedding(); const disabled = useHasParsedDocument(isEdit); const oldValue = useMemo(() => { const embdStr = form.getValues(name || 'embd_id'); return embdStr || ''; }, [form]); const [loading, setLoading] = useState(false); return ( { field.onChange(value); if (isEdit && disabled) { setLoading(true); const res = await handleChange({ embed_id: value, callback: field.onChange, }); if (res.code !== 0) { field.onChange(oldValue); } setLoading(false); } }} value={field.value} options={embeddingModelOptions} placeholder={t('embeddingModelPlaceholder')} /> ); }; export function EmbeddingModelItem({ line = 1, isEdit }: IProps) { const { t } = useTranslate('knowledgeConfiguration'); const form = useFormContext(); return ( <> (
{t('embeddingModel')}
)} /> ); } export function ParseTypeItem({ line = 2 }: { line?: number }) { const { t } = useTranslate('knowledgeConfiguration'); const form = useFormContext(); return ( (
{t('parseType')}
{t('builtIn')} {t('manualSetup')}
)} /> ); } export function EnableAutoGenerateItem() { const { t } = useTranslate('knowledgeConfiguration'); const form = useFormContext(); return ( (
{t('enableAutoGenerate')}
)} /> ); } export function EnableTocToggle() { const { t } = useTranslate('knowledgeConfiguration'); const form = useFormContext(); return ( (
{t('tocExtraction')}
)} /> ); }