'use client'; import { FormContainer } from '@/components/form-container'; import { SelectWithSearch } from '@/components/originui/select-with-search'; import { BlockButton, Button } from '@/components/ui/button'; import { FormControl, FormField, FormItem, FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { Separator } from '@/components/ui/separator'; import { RAGFlowNodeType } from '@/interfaces/database/flow'; import { t } from 'i18next'; import { X } from 'lucide-react'; import { ReactNode, useCallback, useMemo } from 'react'; import { useFieldArray, useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { useBuildSubNodeOutputOptions } from './use-build-options'; interface IProps { node?: RAGFlowNodeType; } export function DynamicOutputForm({ node }: IProps) { const { t } = useTranslation(); const form = useFormContext(); const options = useBuildSubNodeOutputOptions(node?.id); const name = 'outputs'; const flatOptions = useMemo(() => { return options.reduce<{ label: string; value: string; type: string }[]>( (pre, cur) => { pre.push(...cur.options); return pre; }, [], ); }, [options]); const findType = useCallback( (val: string) => { const type = flatOptions.find((x) => x.value === val)?.type; if (type) { return `Array<${type}>`; } }, [flatOptions], ); const { fields, remove, append } = useFieldArray({ name: name, control: form.control, }); return (