fix: tools value not update caused data outdated

This commit is contained in:
Joel 2025-08-28 14:06:20 +08:00
parent 9a13cb5bdf
commit 740f1c5f2c
3 changed files with 16 additions and 9 deletions

View File

@ -10,6 +10,7 @@ import type {
} from '@/app/components/workflow/types' } from '@/app/components/workflow/types'
import { useIsChatMode } from './use-workflow' import { useIsChatMode } from './use-workflow'
import { useStoreApi } from 'reactflow' import { useStoreApi } from 'reactflow'
import { useStore } from '@/app/components/workflow/store'
import type { Type } from '../nodes/llm/types' import type { Type } from '../nodes/llm/types'
import useMatchSchemaType from '../nodes/_base/components/variable/use-match-schema-type' import useMatchSchemaType from '../nodes/_base/components/variable/use-match-schema-type'
@ -18,6 +19,11 @@ export const useWorkflowVariables = () => {
const workflowStore = useWorkflowStore() const workflowStore = useWorkflowStore()
const { getMatchedSchemaType } = useMatchSchemaType() 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(({ const getNodeAvailableVars = useCallback(({
parentNode, parentNode,
beforeNodes, beforeNodes,
@ -37,11 +43,6 @@ export const useWorkflowVariables = () => {
conversationVariables, conversationVariables,
environmentVariables, environmentVariables,
ragPipelineVariables, ragPipelineVariables,
buildInTools,
customTools,
workflowTools,
mcpTools,
dataSourceList,
} = workflowStore.getState() } = workflowStore.getState()
return toNodeAvailableVars({ return toNodeAvailableVars({
parentNode, parentNode,
@ -61,7 +62,7 @@ export const useWorkflowVariables = () => {
}, },
getMatchedSchemaType, getMatchedSchemaType,
}) })
}, [t, workflowStore, getMatchedSchemaType]) }, [t, workflowStore, getMatchedSchemaType, buildInTools])
const getCurrentVariableType = useCallback(({ const getCurrentVariableType = useCallback(({
parentNode, parentNode,
@ -71,6 +72,7 @@ export const useWorkflowVariables = () => {
availableNodes, availableNodes,
isChatMode, isChatMode,
isConstant, isConstant,
preferSchemaType,
}: { }: {
valueSelector: ValueSelector valueSelector: ValueSelector
parentNode?: Node | null parentNode?: Node | null
@ -79,6 +81,7 @@ export const useWorkflowVariables = () => {
availableNodes: any[] availableNodes: any[]
isChatMode: boolean isChatMode: boolean
isConstant?: boolean isConstant?: boolean
preferSchemaType?: boolean
}) => { }) => {
const { const {
conversationVariables, conversationVariables,
@ -109,8 +112,9 @@ export const useWorkflowVariables = () => {
dataSourceList: dataSourceList ?? [], dataSourceList: dataSourceList ?? [],
}, },
getMatchedSchemaType, getMatchedSchemaType,
preferSchemaType,
}) })
}, [workflowStore]) }, [workflowStore, getVarType, getMatchedSchemaType])
return { return {
getNodeAvailableVars, getNodeAvailableVars,

View File

@ -825,6 +825,7 @@ export const getVarType = ({
ragVariables = [], ragVariables = [],
allPluginInfoList, allPluginInfoList,
getMatchedSchemaType, getMatchedSchemaType,
preferSchemaType,
}: { }: {
valueSelector: ValueSelector valueSelector: ValueSelector
parentNode?: Node | null parentNode?: Node | null
@ -838,6 +839,7 @@ export const getVarType = ({
ragVariables?: RAGPipelineVariable[] ragVariables?: RAGPipelineVariable[]
allPluginInfoList: Record<string, ToolWithProvider[]> allPluginInfoList: Record<string, ToolWithProvider[]>
getMatchedSchemaType: (obj: any) => string getMatchedSchemaType: (obj: any) => string
preferSchemaType?: boolean
}): VarType => { }): VarType => {
if (isConstant) if (isConstant)
return VarType.string return VarType.string
@ -934,7 +936,7 @@ export const getVarType = ({
const isStructuredOutputVar = !!targetVar.children?.schema?.properties const isStructuredOutputVar = !!targetVar.children?.schema?.properties
if (isStructuredOutputVar) { if (isStructuredOutputVar) {
if (valueSelector.length === 2) { // root if (valueSelector.length === 2) { // root
return targetVar.alias || VarType.object return (preferSchemaType && targetVar.schemaType) ? targetVar.schemaType : VarType.object
} }
let currProperties = targetVar.children.schema; let currProperties = targetVar.children.schema;
(valueSelector as ValueSelector).slice(2).forEach((key, i) => { (valueSelector as ValueSelector).slice(2).forEach((key, i) => {
@ -955,7 +957,7 @@ export const getVarType = ({
curr = curr?.find((v: any) => v.variable === key) curr = curr?.find((v: any) => v.variable === key)
if (isLast) { if (isLast) {
type = curr?.type type = (preferSchemaType && curr?.schemaType) ? curr?.schemaType : curr?.type
} }
else { else {
if (curr?.type === VarType.object || curr?.type === VarType.file) if (curr?.type === VarType.object || curr?.type === VarType.file)

View File

@ -288,6 +288,7 @@ const VarReferencePicker: FC<Props> = ({
availableNodes, availableNodes,
isChatMode, isChatMode,
isConstant: !!isConstant, isConstant: !!isConstant,
preferSchemaType,
}) })
const { isEnv, isChatVar, isRagVar, isValidVar, isException } = useMemo(() => { const { isEnv, isChatVar, isRagVar, isValidVar, isException } = useMemo(() => {