diff --git a/web/app/components/workflow/hooks/use-workflow-variables.ts b/web/app/components/workflow/hooks/use-workflow-variables.ts index d5eebfde77..b42a41bab5 100644 --- a/web/app/components/workflow/hooks/use-workflow-variables.ts +++ b/web/app/components/workflow/hooks/use-workflow-variables.ts @@ -10,6 +10,7 @@ import type { } from '@/app/components/workflow/types' import { useIsChatMode } from './use-workflow' import { useStoreApi } from 'reactflow' +import { useStore } from '@/app/components/workflow/store' import type { Type } from '../nodes/llm/types' import useMatchSchemaType from '../nodes/_base/components/variable/use-match-schema-type' @@ -18,6 +19,11 @@ export const useWorkflowVariables = () => { const workflowStore = useWorkflowStore() const { getMatchedSchemaType } = useMatchSchemaType() + const buildInTools = useStore(s => s.buildInTools) + const customTools = useStore(s => s.customTools) + const workflowTools = useStore(s => s.workflowTools) + const mcpTools = useStore(s => s.mcpTools) + const dataSourceList = useStore(s => s.dataSourceList) const getNodeAvailableVars = useCallback(({ parentNode, beforeNodes, @@ -37,11 +43,6 @@ export const useWorkflowVariables = () => { conversationVariables, environmentVariables, ragPipelineVariables, - buildInTools, - customTools, - workflowTools, - mcpTools, - dataSourceList, } = workflowStore.getState() return toNodeAvailableVars({ parentNode, @@ -61,7 +62,7 @@ export const useWorkflowVariables = () => { }, getMatchedSchemaType, }) - }, [t, workflowStore, getMatchedSchemaType]) + }, [t, workflowStore, getMatchedSchemaType, buildInTools]) const getCurrentVariableType = useCallback(({ parentNode, @@ -71,6 +72,7 @@ export const useWorkflowVariables = () => { availableNodes, isChatMode, isConstant, + preferSchemaType, }: { valueSelector: ValueSelector parentNode?: Node | null @@ -79,6 +81,7 @@ export const useWorkflowVariables = () => { availableNodes: any[] isChatMode: boolean isConstant?: boolean + preferSchemaType?: boolean }) => { const { conversationVariables, @@ -109,8 +112,9 @@ export const useWorkflowVariables = () => { dataSourceList: dataSourceList ?? [], }, getMatchedSchemaType, + preferSchemaType, }) - }, [workflowStore]) + }, [workflowStore, getVarType, getMatchedSchemaType]) return { getNodeAvailableVars, diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 52e18ef10e..1df833d95f 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -825,6 +825,7 @@ export const getVarType = ({ ragVariables = [], allPluginInfoList, getMatchedSchemaType, + preferSchemaType, }: { valueSelector: ValueSelector parentNode?: Node | null @@ -838,6 +839,7 @@ export const getVarType = ({ ragVariables?: RAGPipelineVariable[] allPluginInfoList: Record getMatchedSchemaType: (obj: any) => string + preferSchemaType?: boolean }): VarType => { if (isConstant) return VarType.string @@ -934,7 +936,7 @@ export const getVarType = ({ const isStructuredOutputVar = !!targetVar.children?.schema?.properties if (isStructuredOutputVar) { if (valueSelector.length === 2) { // root - return targetVar.alias || VarType.object + return (preferSchemaType && targetVar.schemaType) ? targetVar.schemaType : VarType.object } let currProperties = targetVar.children.schema; (valueSelector as ValueSelector).slice(2).forEach((key, i) => { @@ -955,7 +957,7 @@ export const getVarType = ({ curr = curr?.find((v: any) => v.variable === key) if (isLast) { - type = curr?.type + type = (preferSchemaType && curr?.schemaType) ? curr?.schemaType : curr?.type } else { if (curr?.type === VarType.object || curr?.type === VarType.file) diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx index b90fd53125..e493b7b6b9 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx @@ -288,6 +288,7 @@ const VarReferencePicker: FC = ({ availableNodes, isChatMode, isConstant: !!isConstant, + preferSchemaType, }) const { isEnv, isChatVar, isRagVar, isValidVar, isException } = useMemo(() => {