mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 01:18:05 +08:00
rag pipeline initial template
This commit is contained in:
@ -3,15 +3,12 @@ import React from 'react'
|
||||
import type { ToolNodeType } from './types'
|
||||
import type { NodeProps } from '@/app/components/workflow/types'
|
||||
import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import { useInitial } from './use-initial'
|
||||
|
||||
const Node: FC<NodeProps<ToolNodeType>> = ({
|
||||
id,
|
||||
data,
|
||||
}) => {
|
||||
const { tool_configurations, paramSchemas } = data
|
||||
const toolConfigs = Object.keys(tool_configurations || {})
|
||||
useInitial(id)
|
||||
|
||||
if (!toolConfigs.length)
|
||||
return null
|
||||
|
||||
@ -12,7 +12,6 @@ import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/compo
|
||||
import StructureOutputItem from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show'
|
||||
import { useStore } from '@/app/components/workflow/store'
|
||||
import { wrapStructuredVarItem } from '@/app/components/workflow/utils/tool'
|
||||
import { useInitial } from './use-initial'
|
||||
import useMatchSchemaType from '../_base/components/variable/use-match-schema-type'
|
||||
|
||||
const i18nPrefix = 'workflow.nodes.tool'
|
||||
@ -22,7 +21,6 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
|
||||
data,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
useInitial(id)
|
||||
const {
|
||||
readOnly,
|
||||
inputs,
|
||||
|
||||
@ -26,5 +26,4 @@ export type ToolNodeType = CommonNodeType & {
|
||||
tool_description?: string
|
||||
is_team_authorization?: boolean
|
||||
params?: Record<string, any>
|
||||
_notInitialized?: boolean
|
||||
}
|
||||
|
||||
@ -1,67 +0,0 @@
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
} from 'react'
|
||||
import { useStoreApi } from 'reactflow'
|
||||
import { useNodeDataUpdate } from '@/app/components/workflow/hooks/use-node-data-update'
|
||||
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||
import { useStore } from '../../store'
|
||||
import type { ToolNodeType } from './types'
|
||||
import { canFindTool } from '@/utils'
|
||||
|
||||
export const useInitial = (id: string) => {
|
||||
const store = useStoreApi()
|
||||
const buildInTools = useStore(s => s.buildInTools)
|
||||
const language = useLanguage()
|
||||
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
|
||||
|
||||
const getNodeData = useCallback(() => {
|
||||
const { getNodes } = store.getState()
|
||||
const nodes = getNodes()
|
||||
|
||||
return nodes.find(node => node.id === id)
|
||||
}, [store, id])
|
||||
|
||||
const handleNodeDataUpdate = useCallback((data: Partial<ToolNodeType>) => {
|
||||
handleNodeDataUpdateWithSyncDraft({
|
||||
id,
|
||||
data,
|
||||
})
|
||||
}, [id, handleNodeDataUpdateWithSyncDraft])
|
||||
|
||||
const handleInitial = useCallback(() => {
|
||||
const nodeData = getNodeData()
|
||||
const { provider_id, tool_name, _notInitialized } = nodeData?.data || {}
|
||||
const currCollection = buildInTools.find(item => canFindTool(item.id, provider_id))
|
||||
const currTool = currCollection?.tools.find(tool => tool.name === tool_name)
|
||||
|
||||
if (!currTool)
|
||||
return
|
||||
|
||||
if (_notInitialized && currCollection) {
|
||||
const params: Record<string, string> = {}
|
||||
if (currTool.parameters) {
|
||||
currTool.parameters.forEach((item) => {
|
||||
params[item.name] = ''
|
||||
})
|
||||
}
|
||||
handleNodeDataUpdate({
|
||||
provider_id: currCollection.id,
|
||||
provider_type: currCollection.type as any,
|
||||
provider_name: currCollection.name,
|
||||
tool_name: currTool.name,
|
||||
tool_label: currTool.label[language],
|
||||
tool_description: currTool.description[language],
|
||||
title: currTool.label[language],
|
||||
is_team_authorization: currCollection.is_team_authorization,
|
||||
paramSchemas: currTool.parameters,
|
||||
params,
|
||||
_notInitialized: false,
|
||||
})
|
||||
}
|
||||
}, [handleNodeDataUpdate, language, buildInTools, getNodeData])
|
||||
|
||||
useEffect(() => {
|
||||
handleInitial()
|
||||
}, [handleInitial])
|
||||
}
|
||||
Reference in New Issue
Block a user