mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 10:28:10 +08:00
chore: direct answer to answer
This commit is contained in:
@ -12,9 +12,9 @@ function useVarList<T>({
|
||||
setInputs,
|
||||
varKey = 'variables',
|
||||
}: Params<T>) {
|
||||
const handleVarListChange = useCallback((newList: Variable[]) => {
|
||||
const handleVarListChange = useCallback((newList: Variable[] | string) => {
|
||||
const newInputs = produce(inputs, (draft: any) => {
|
||||
draft[varKey] = newList
|
||||
draft[varKey] = newList as Variable[]
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs, varKey])
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { NodeDefault } from '../../types'
|
||||
import type { DirectAnswerNodeType } from './types'
|
||||
import type { AnswerNodeType } from './types'
|
||||
|
||||
const nodeDefault: NodeDefault<DirectAnswerNodeType> = {
|
||||
const nodeDefault: NodeDefault<AnswerNodeType> = {
|
||||
defaultValue: {
|
||||
variables: [],
|
||||
answer: '',
|
||||
@ -2,17 +2,17 @@ import type { FC } from 'react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import InfoPanel from '../_base/components/info-panel'
|
||||
import type { DirectAnswerNodeType } from './types'
|
||||
import type { AnswerNodeType } from './types'
|
||||
import type { NodeProps } from '@/app/components/workflow/types'
|
||||
|
||||
const Node: FC<NodeProps<DirectAnswerNodeType>> = ({
|
||||
const Node: FC<NodeProps<AnswerNodeType>> = ({
|
||||
data,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className='px-3'>
|
||||
<InfoPanel title={t('workflow.nodes.directAnswer.answer')} content={data.answer} />
|
||||
<InfoPanel title={t('workflow.nodes.answer.answer')} content={data.answer} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -2,7 +2,7 @@ import type { FC } from 'react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import useConfig from './use-config'
|
||||
import type { DirectAnswerNodeType } from './types'
|
||||
import type { AnswerNodeType } from './types'
|
||||
import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
|
||||
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
||||
import AddButton from '@/app/components/base/button/add-button'
|
||||
@ -10,9 +10,9 @@ import Split from '@/app/components/workflow/nodes/_base/components/split'
|
||||
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
||||
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||
|
||||
const i18nPrefix = 'workflow.nodes.directAnswer'
|
||||
const i18nPrefix = 'workflow.nodes.answer'
|
||||
|
||||
const Panel: FC<NodePanelProps<DirectAnswerNodeType>> = ({
|
||||
const Panel: FC<NodePanelProps<AnswerNodeType>> = ({
|
||||
id,
|
||||
data,
|
||||
}) => {
|
||||
@ -29,12 +29,13 @@ const Panel: FC<NodePanelProps<DirectAnswerNodeType>> = ({
|
||||
return (
|
||||
<div className='mt-2 px-4 space-y-4'>
|
||||
<Field
|
||||
title={t(`${i18nPrefix}.inputVars`)}
|
||||
title={t(`${i18nPrefix}.outputVars`)}
|
||||
operations={
|
||||
<AddButton onClick={handleAddVariable} />
|
||||
}
|
||||
>
|
||||
<VarList
|
||||
nodeId={id}
|
||||
readonly={readOnly}
|
||||
list={inputs.variables}
|
||||
onChange={handleVarListChange}
|
||||
@ -1,6 +1,6 @@
|
||||
import type { CommonNodeType, Variable } from '@/app/components/workflow/types'
|
||||
|
||||
export type DirectAnswerNodeType = CommonNodeType & {
|
||||
export type AnswerNodeType = CommonNodeType & {
|
||||
variables: Variable[]
|
||||
answer: string
|
||||
}
|
||||
@ -1,13 +1,13 @@
|
||||
import { useCallback } from 'react'
|
||||
import produce from 'immer'
|
||||
import useVarList from '../_base/hooks/use-var-list'
|
||||
import type { DirectAnswerNodeType } from './types'
|
||||
import type { AnswerNodeType } from './types'
|
||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||
|
||||
const useConfig = (id: string, payload: DirectAnswerNodeType) => {
|
||||
const { inputs, setInputs } = useNodeCrud<DirectAnswerNodeType>(id, payload)
|
||||
const useConfig = (id: string, payload: AnswerNodeType) => {
|
||||
const { inputs, setInputs } = useNodeCrud<AnswerNodeType>(id, payload)
|
||||
// variables
|
||||
const { handleVarListChange, handleAddVariable } = useVarList<DirectAnswerNodeType>({
|
||||
const { handleVarListChange, handleAddVariable } = useVarList<AnswerNodeType>({
|
||||
inputs,
|
||||
setInputs,
|
||||
})
|
||||
5
web/app/components/workflow/nodes/answer/utils.ts
Normal file
5
web/app/components/workflow/nodes/answer/utils.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import type { AnswerNodeType } from './types'
|
||||
|
||||
export const checkNodeValid = (payload: AnswerNodeType) => {
|
||||
return true
|
||||
}
|
||||
@ -4,8 +4,8 @@ import StartNode from './start/node'
|
||||
import StartPanel from './start/panel'
|
||||
import EndNode from './end/node'
|
||||
import EndPanel from './end/panel'
|
||||
import DirectAnswerNode from './direct-answer/node'
|
||||
import DirectAnswerPanel from './direct-answer/panel'
|
||||
import AnswerNode from './answer/node'
|
||||
import AnswerPanel from './answer/panel'
|
||||
import LLMNode from './llm/node'
|
||||
import LLMPanel from './llm/panel'
|
||||
import KnowledgeRetrievalNode from './knowledge-retrieval/node'
|
||||
@ -28,7 +28,7 @@ import VariableAssignerPanel from './variable-assigner/panel'
|
||||
export const NodeComponentMap: Record<string, ComponentType<any>> = {
|
||||
[BlockEnum.Start]: StartNode,
|
||||
[BlockEnum.End]: EndNode,
|
||||
[BlockEnum.DirectAnswer]: DirectAnswerNode,
|
||||
[BlockEnum.Answer]: AnswerNode,
|
||||
[BlockEnum.LLM]: LLMNode,
|
||||
[BlockEnum.KnowledgeRetrieval]: KnowledgeRetrievalNode,
|
||||
[BlockEnum.QuestionClassifier]: QuestionClassifierNode,
|
||||
@ -43,7 +43,7 @@ export const NodeComponentMap: Record<string, ComponentType<any>> = {
|
||||
export const PanelComponentMap: Record<string, ComponentType> = {
|
||||
[BlockEnum.Start]: StartPanel,
|
||||
[BlockEnum.End]: EndPanel,
|
||||
[BlockEnum.DirectAnswer]: DirectAnswerPanel,
|
||||
[BlockEnum.Answer]: AnswerPanel,
|
||||
[BlockEnum.LLM]: LLMPanel,
|
||||
[BlockEnum.KnowledgeRetrieval]: KnowledgeRetrievalPanel,
|
||||
[BlockEnum.QuestionClassifier]: QuestionClassifierPanel,
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
import type { DirectAnswerNodeType } from './types'
|
||||
|
||||
export const checkNodeValid = (payload: DirectAnswerNodeType) => {
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user