Pārlūkot izejas kodu

fix: tools value not update caused data outdated

tags/2.0.0-beta.1
Joel pirms 2 mēnešiem
vecāks
revīzija
740f1c5f2c

+ 11
- 7
web/app/components/workflow/hooks/use-workflow-variables.ts Parādīt failu

} 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'


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,
conversationVariables, conversationVariables,
environmentVariables, environmentVariables,
ragPipelineVariables, ragPipelineVariables,
buildInTools,
customTools,
workflowTools,
mcpTools,
dataSourceList,
} = workflowStore.getState() } = workflowStore.getState()
return toNodeAvailableVars({ return toNodeAvailableVars({
parentNode, parentNode,
}, },
getMatchedSchemaType, getMatchedSchemaType,
}) })
}, [t, workflowStore, getMatchedSchemaType])
}, [t, workflowStore, getMatchedSchemaType, buildInTools])


const getCurrentVariableType = useCallback(({ const getCurrentVariableType = useCallback(({
parentNode, parentNode,
availableNodes, availableNodes,
isChatMode, isChatMode,
isConstant, isConstant,
preferSchemaType,
}: { }: {
valueSelector: ValueSelector valueSelector: ValueSelector
parentNode?: Node | null parentNode?: Node | null
availableNodes: any[] availableNodes: any[]
isChatMode: boolean isChatMode: boolean
isConstant?: boolean isConstant?: boolean
preferSchemaType?: boolean
}) => { }) => {
const { const {
conversationVariables, conversationVariables,
dataSourceList: dataSourceList ?? [], dataSourceList: dataSourceList ?? [],
}, },
getMatchedSchemaType, getMatchedSchemaType,
preferSchemaType,
}) })
}, [workflowStore])
}, [workflowStore, getVarType, getMatchedSchemaType])


return { return {
getNodeAvailableVars, getNodeAvailableVars,

+ 4
- 2
web/app/components/workflow/nodes/_base/components/variable/utils.ts Parādīt failu

ragVariables = [], ragVariables = [],
allPluginInfoList, allPluginInfoList,
getMatchedSchemaType, getMatchedSchemaType,
preferSchemaType,
}: { }: {
valueSelector: ValueSelector valueSelector: ValueSelector
parentNode?: Node | null parentNode?: Node | null
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
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) => {
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)

+ 1
- 0
web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx Parādīt failu

availableNodes, availableNodes,
isChatMode, isChatMode,
isConstant: !!isConstant, isConstant: !!isConstant,
preferSchemaType,
}) })


const { isEnv, isChatVar, isRagVar, isValidVar, isException } = useMemo(() => { const { isEnv, isChatVar, isRagVar, isValidVar, isException } = useMemo(() => {

Notiek ielāde…
Atcelt
Saglabāt