mirror of https://github.com/langgenius/dify.git
feat: knowledge node var init value and limit
This commit is contained in:
parent
4835358f24
commit
aff5ab933b
|
|
@ -16,7 +16,7 @@ export const useNodesInitialData = () => {
|
|||
return useMemo(() => produce(NODES_INITIAL_DATA, (draft) => {
|
||||
Object.keys(draft).forEach((key) => {
|
||||
draft[key as BlockEnum].title = t(`workflow.blocks.${key}`)
|
||||
|
||||
draft[key as BlockEnum]._isReady = true
|
||||
if (nodesDefaultConfigs[key as BlockEnum]) {
|
||||
draft[key as BlockEnum] = {
|
||||
...draft[key as BlockEnum],
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ const Panel: FC<NodePanelProps<KnowledgeRetrievalNodeType>> = ({
|
|||
const {
|
||||
inputs,
|
||||
handleQueryVarChange,
|
||||
filterVar,
|
||||
handleRetrievalModeChange,
|
||||
handleMultipleRetrievalConfigChange,
|
||||
selectedDatasets,
|
||||
|
|
@ -52,6 +53,8 @@ const Panel: FC<NodePanelProps<KnowledgeRetrievalNodeType>> = ({
|
|||
isShowNodeName
|
||||
value={inputs.query_variable_selector}
|
||||
onChange={handleQueryVarChange}
|
||||
filterVar={filterVar}
|
||||
width={370}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { useCallback, useEffect, useState } from 'react'
|
||||
import produce from 'immer'
|
||||
import type { ValueSelector } from '../../types'
|
||||
import type { ValueSelector, Var } from '../../types'
|
||||
import { BlockEnum, VarType } from '../../types'
|
||||
import { useIsChatMode, useWorkflow } from '../../hooks'
|
||||
import type { KnowledgeRetrievalNodeType, MultipleRetrievalConfig } from './types'
|
||||
import type { RETRIEVE_TYPE } from '@/types/app'
|
||||
import type { DataSet } from '@/models/datasets'
|
||||
|
|
@ -9,10 +11,14 @@ import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-cr
|
|||
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
|
||||
|
||||
const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
||||
const isChatMode = useIsChatMode()
|
||||
const { getBeforeNodesInSameBranch } = useWorkflow()
|
||||
const startNode = getBeforeNodesInSameBranch(id).find(node => node.data.type === BlockEnum.Start)
|
||||
const startNodeId = startNode?.id
|
||||
const { inputs, setInputs } = useNodeCrud<KnowledgeRetrievalNodeType>(id, payload)
|
||||
const handleQueryVarChange = useCallback((newVar: ValueSelector) => {
|
||||
const handleQueryVarChange = useCallback((newVar: ValueSelector | string) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.query_variable_selector = newVar
|
||||
draft.query_variable_selector = newVar as ValueSelector
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs])
|
||||
|
|
@ -45,8 +51,19 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
|||
})
|
||||
setInputs(newInputs)
|
||||
})()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (inputs._isReady) {
|
||||
if (isChatMode && inputs.query_variable_selector.length === 0 && startNodeId) {
|
||||
handleQueryVarChange(
|
||||
[startNodeId, 'sys.query'],
|
||||
)
|
||||
}
|
||||
}
|
||||
}, [inputs._isReady])
|
||||
|
||||
const handleOnDatasetsChange = useCallback((newDatasets: DataSet[]) => {
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
draft.dataset_ids = newDatasets.map(d => d.id)
|
||||
|
|
@ -55,6 +72,10 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
|||
setSelectedDatasets(newDatasets)
|
||||
}, [inputs, setInputs])
|
||||
|
||||
const filterVar = useCallback((varPayload: Var) => {
|
||||
return varPayload.type === VarType.string
|
||||
}, [])
|
||||
|
||||
// single run
|
||||
const {
|
||||
isShowSingleRun,
|
||||
|
|
@ -84,6 +105,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
|||
return {
|
||||
inputs,
|
||||
handleQueryVarChange,
|
||||
filterVar,
|
||||
handleRetrievalModeChange,
|
||||
handleMultipleRetrievalConfigChange,
|
||||
selectedDatasets,
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export type CommonNodeType<T = {}> = {
|
|||
_isSingleRun?: boolean
|
||||
_runningStatus?: NodeRunningStatus
|
||||
_singleRunningStatus?: NodeRunningStatus
|
||||
_isReady?: boolean
|
||||
selected?: boolean
|
||||
title: string
|
||||
desc: string
|
||||
|
|
|
|||
Loading…
Reference in New Issue