2025-06-03 15:40:04 +08:00
|
|
|
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
|
|
|
|
import {
|
|
|
|
|
FormControl,
|
|
|
|
|
FormField,
|
|
|
|
|
FormItem,
|
|
|
|
|
FormLabel,
|
|
|
|
|
FormMessage,
|
|
|
|
|
} from '@/components/ui/form';
|
2025-06-10 10:49:41 +08:00
|
|
|
import { useFetchAgent } from '@/hooks/use-agent-request';
|
|
|
|
|
import { useContext, useMemo } from 'react';
|
2025-06-03 15:40:04 +08:00
|
|
|
import { useFormContext } from 'react-hook-form';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-06-10 10:49:41 +08:00
|
|
|
import { AgentFormContext } from '../../context';
|
|
|
|
|
import { useBuildComponentIdSelectOptions } from '../../hooks/use-get-begin-query';
|
2025-06-03 15:40:04 +08:00
|
|
|
|
|
|
|
|
export function QueryVariable() {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const form = useFormContext();
|
2025-06-10 10:49:41 +08:00
|
|
|
const { data } = useFetchAgent();
|
|
|
|
|
|
|
|
|
|
const node = useContext(AgentFormContext);
|
|
|
|
|
const options = useBuildComponentIdSelectOptions(node?.id, node?.parentId);
|
|
|
|
|
|
|
|
|
|
const nextOptions = useMemo(() => {
|
|
|
|
|
const globalOptions = Object.keys(data?.dsl?.globals ?? {}).map((x) => ({
|
|
|
|
|
label: x,
|
|
|
|
|
value: x,
|
|
|
|
|
}));
|
|
|
|
|
return [
|
|
|
|
|
{ ...options[0], options: [...options[0]?.options, ...globalOptions] },
|
|
|
|
|
...options.slice(1),
|
|
|
|
|
];
|
|
|
|
|
}, [data.dsl.globals, options]);
|
2025-06-03 15:40:04 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<FormField
|
|
|
|
|
control={form.control}
|
|
|
|
|
name="query"
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<FormItem>
|
|
|
|
|
<FormLabel tooltip={t('chat.modelTip')}>{t('flow.query')}</FormLabel>
|
|
|
|
|
<FormControl>
|
2025-06-10 10:49:41 +08:00
|
|
|
<SelectWithSearch
|
|
|
|
|
options={nextOptions}
|
|
|
|
|
{...field}
|
|
|
|
|
></SelectWithSearch>
|
2025-06-03 15:40:04 +08:00
|
|
|
</FormControl>
|
|
|
|
|
<FormMessage />
|
|
|
|
|
</FormItem>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|