diff --git a/web/src/pages/agent/canvas/node/tool-node.tsx b/web/src/pages/agent/canvas/node/tool-node.tsx index 9f9733537..e3da77f32 100644 --- a/web/src/pages/agent/canvas/node/tool-node.tsx +++ b/web/src/pages/agent/canvas/node/tool-node.tsx @@ -58,6 +58,7 @@ function InnerToolNode({ const mcp = x as unknown as IAgentForm['mcp'][number]; return ( @@ -174,6 +176,7 @@ function AgentForm({ node }: INextOperatorForm) { diff --git a/web/src/pages/agent/form/components/prompt-editor/index.tsx b/web/src/pages/agent/form/components/prompt-editor/index.tsx index afff80e29..c9644249d 100644 --- a/web/src/pages/agent/form/components/prompt-editor/index.tsx +++ b/web/src/pages/agent/form/components/prompt-editor/index.tsx @@ -21,6 +21,7 @@ import { TooltipTrigger, } from '@/components/ui/tooltip'; import { cn } from '@/lib/utils'; +import { JsonSchemaDataType } from '@/pages/agent/constant'; import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; import { Variable } from 'lucide-react'; import { ReactNode, useCallback, useState } from 'react'; @@ -54,6 +55,7 @@ type IProps = { value?: string; onChange?: (value?: string) => void; placeholder?: ReactNode; + types?: JsonSchemaDataType[]; } & PromptContentProps & Pick; @@ -127,6 +129,7 @@ export function PromptEditor({ multiLine = true, extraOptions, baseOptions, + types, }: IProps) { const { t } = useTranslation(); const initialConfig: InitialConfigType = { @@ -179,6 +182,7 @@ export function PromptEditor({ value={value} extraOptions={extraOptions} baseOptions={baseOptions} + types={types} > void; @@ -108,6 +111,7 @@ function VariablePickerMenuItem({ selectOptionAndCleanUp({ ...x, @@ -149,11 +153,13 @@ export type VariablePickerMenuPluginProps = { value?: string; extraOptions?: VariablePickerMenuOptionType[]; baseOptions?: VariablePickerMenuOptionType[]; + types?: JsonSchemaDataType[]; }; export default function VariablePickerMenuPlugin({ value, extraOptions, baseOptions, + types, }: VariablePickerMenuPluginProps): JSX.Element { const [editor] = useLexicalComposerContext(); @@ -180,7 +186,7 @@ export default function VariablePickerMenuPlugin({ const [queryString, setQueryString] = React.useState(''); - let options = useBuildQueryVariableOptions(); + let options = useFilterQueryVariableOptionsByTypes(types); if (baseOptions) { options = baseOptions as typeof options; @@ -379,6 +385,7 @@ export default function VariablePickerMenuPlugin({ index={i} key={option.key} option={option} + types={types} selectOptionAndCleanUp={selectOptionAndCleanUp} /> ))} diff --git a/web/src/pages/agent/form/components/query-variable.tsx b/web/src/pages/agent/form/components/query-variable.tsx index 08efb94ca..88faeec8b 100644 --- a/web/src/pages/agent/form/components/query-variable.tsx +++ b/web/src/pages/agent/form/components/query-variable.tsx @@ -5,12 +5,11 @@ import { FormLabel, FormMessage, } from '@/components/ui/form'; -import { isEmpty, toLower } from 'lodash'; -import { ReactNode, useMemo } from 'react'; +import { ReactNode } from 'react'; import { useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { JsonSchemaDataType } from '../../constant'; -import { useBuildQueryVariableOptions } from '../../hooks/use-get-begin-query'; +import { useFilterQueryVariableOptionsByTypes } from '../../hooks/use-get-begin-query'; import { GroupedSelectWithSecondaryMenu } from './select-with-secondary-menu'; type QueryVariableProps = { @@ -31,22 +30,7 @@ export function QueryVariable({ const { t } = useTranslation(); const form = useFormContext(); - const nextOptions = useBuildQueryVariableOptions(); - - const finalOptions = useMemo(() => { - return !isEmpty(types) - ? nextOptions.map((x) => { - return { - ...x, - options: x.options.filter( - (y) => - types?.some((x) => toLower(y.type).includes(x)) || - y.type === undefined, // agent structured output - ), - }; - }) - : nextOptions; - }, [nextOptions, types]); + const finalOptions = useFilterQueryVariableOptionsByTypes(types); return ( diff --git a/web/src/pages/agent/hooks/use-get-begin-query.tsx b/web/src/pages/agent/hooks/use-get-begin-query.tsx index 7978321a6..06f6d343f 100644 --- a/web/src/pages/agent/hooks/use-get-begin-query.tsx +++ b/web/src/pages/agent/hooks/use-get-begin-query.tsx @@ -4,12 +4,14 @@ import { RAGFlowNodeType } from '@/interfaces/database/flow'; import { buildNodeOutputOptions } from '@/utils/canvas-util'; import { DefaultOptionType } from 'antd/es/select'; import { t } from 'i18next'; +import { isEmpty, toLower } from 'lodash'; import get from 'lodash/get'; import { useCallback, useContext, useEffect, useMemo, useState } from 'react'; import { AgentDialogueMode, BeginId, BeginQueryType, + JsonSchemaDataType, Operator, VariableType, } from '../constant'; @@ -171,6 +173,29 @@ export function useBuildQueryVariableOptions(n?: RAGFlowNodeType) { return nextOptions; } +export function useFilterQueryVariableOptionsByTypes( + types?: JsonSchemaDataType[], +) { + const nextOptions = useBuildQueryVariableOptions(); + + const filteredOptions = useMemo(() => { + return !isEmpty(types) + ? nextOptions.map((x) => { + return { + ...x, + options: x.options.filter( + (y) => + types?.some((x) => toLower(y.type).includes(x)) || + y.type === undefined, // agent structured output + ), + }; + }) + : nextOptions; + }, [nextOptions, types]); + + return filteredOptions; +} + export function useBuildComponentIdOptions(nodeId?: string, parentId?: string) { const nodes = useGraphStore((state) => state.nodes);