datasource template

feat/rag-2
zxhlyh 10 months ago
parent 5401299e6e
commit 16603952a0

@ -10,7 +10,6 @@ import {
import { API_PREFIX } from '@/config' import { API_PREFIX } from '@/config'
import { syncWorkflowDraft } from '@/service/workflow' import { syncWorkflowDraft } from '@/service/workflow'
import { usePipelineRefreshDraft } from '.' import { usePipelineRefreshDraft } from '.'
import { CUSTOM_DATA_SOURCE_EMPTY_NODE } from '@/app/components/workflow/nodes/data-source-empty/constants'
export const useNodesSyncDraft = () => { export const useNodesSyncDraft = () => {
const store = useStoreApi() const store = useStoreApi()
@ -25,7 +24,7 @@ export const useNodesSyncDraft = () => {
transform, transform,
} = store.getState() } = store.getState()
const nodesOriginal = getNodes() const nodesOriginal = getNodes()
const nodes = nodesOriginal.filter(node => node.type !== CUSTOM_DATA_SOURCE_EMPTY_NODE) const nodes = nodesOriginal.filter(node => !node.data._isTempNode)
const [x, y, zoom] = transform const [x, y, zoom] = transform
const { const {
pipelineId, pipelineId,

@ -9,11 +9,8 @@ import { CUSTOM_NODE } from '@/app/components/workflow/constants'
export const processNodesWithoutDataSource = (nodes: Node[]) => { export const processNodesWithoutDataSource = (nodes: Node[]) => {
let leftNode let leftNode
let hasNoteBySystem
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
const node = nodes[i] const node = nodes[i]
if (node.type === CUSTOM_NOTE_NODE && node.data.noteBySystem)
hasNoteBySystem = true
if (node.data.type === BlockEnum.DataSource) if (node.data.type === BlockEnum.DataSource)
return nodes return nodes
@ -34,38 +31,36 @@ export const processNodesWithoutDataSource = (nodes: Node[]) => {
desc: '', desc: '',
type: BlockEnum.DataSourceEmpty, type: BlockEnum.DataSourceEmpty,
width: 240, width: 240,
_isTempNode: true,
}, },
position: { position: {
x: leftNode.position.x - 500, x: leftNode.position.x - 500,
y: leftNode.position.y, y: leftNode.position.y,
}, },
}) })
let newNoteNode const newNoteNode = generateNewNode({
if (!hasNoteBySystem) {
newNoteNode = generateNewNode({
id: 'note', id: 'note',
type: CUSTOM_NOTE_NODE, type: CUSTOM_NOTE_NODE,
data: { data: {
title: '', title: '',
desc: '', desc: '',
type: '' as any, type: '' as any,
text: '{"root":{"children":[{"children":[{"detail":0,"format":1,"mode":"normal","style":"font-size: 14px;","text":"Get started with a blank pipeline","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":1,"textStyle":"font-size: 14px;"},{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":1,"textStyle":""},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"A Knowledge Pipeline starts with Data Source as the starting node and ends with the knowledge base node. The general steps are: import documents from the data source → use extractor to extract document content → split and clean content into structured chunks → store in the knowledge base.","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":0,"textStyle":""},{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":0,"textStyle":""},{"children":[{"children":[{"detail":0,"format":2,"mode":"normal","style":"","text":"Link to documentation","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"link","version":1,"textFormat":2,"rel":"noreferrer","target":null,"title":null,"url":"https://dify.ai"}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":2,"textStyle":""},{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":0,"textStyle":""}],"direction":"ltr","format":"","indent":0,"type":"root","version":1,"textFormat":1,"textStyle":"font-size: 14px;"}}', text: '{"root":{"children":[{"children":[{"detail":0,"format":1,"mode":"normal","style":"font-size: 14px;","text":"Get started with a blank pipeline","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":1,"textStyle":"font-size: 14px;"},{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":1,"textStyle":""},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"A Knowledge Pipeline starts with Data Source as the starting node and ends with the knowledge base node. The general steps are: import documents from the data source → use extractor to extract document content → split and clean content into structured chunks → store in the knowledge base.","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":0,"textStyle":""},{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":0,"textStyle":""},{"children":[{"children":[{"detail":0,"format":2,"mode":"normal","style":"","text":"Link to documentation","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"link","version":1,"textFormat":2,"rel":"noreferrer","target":"_blank","title":null,"url":"https://dify.ai"}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":2,"textStyle":""},{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":0,"textStyle":""}],"direction":"ltr","format":"","indent":0,"type":"root","version":1,"textFormat":1,"textStyle":"font-size: 14px;"}}',
theme: NoteTheme.blue, theme: NoteTheme.blue,
author: '', author: '',
showAuthor: true, showAuthor: true,
width: 240, width: 240,
height: 300, height: 300,
noteBySystem: true, _isTempNode: true,
} as NoteNodeType, } as NoteNodeType,
position: { position: {
x: leftNode.position.x - 500, x: leftNode.position.x - 500,
y: leftNode.position.y + 100, y: leftNode.position.y + 100,
}, },
}).newNode }).newNode
}
return [ return [
newNode, newNode,
...(newNoteNode ? [newNoteNode] : []), newNoteNode,
...nodes, ...nodes,
] ]
} }

@ -38,7 +38,10 @@ export const useReplaceDataSourceNode = (id: string) => {
const newNodes = produce(nodes, (draft) => { const newNodes = produce(nodes, (draft) => {
draft[emptyNodeIndex] = newNode draft[emptyNodeIndex] = newNode
}) })
setNodes(newNodes) const newNodesWithoutTempNodes = produce(newNodes, (draft) => {
return draft.filter(node => !node.data._isTempNode)
})
setNodes(newNodesWithoutTempNodes)
}, []) }, [])
return { return {

@ -77,8 +77,11 @@ const NoteNode = ({
<NoteEditorContextProvider <NoteEditorContextProvider
key={controlPromptEditorRerenderKey} key={controlPromptEditorRerenderKey}
value={data.text} value={data.text}
editable={!data._isTempNode}
> >
<> <>
{
!data._isTempNode && (
<NodeResizer <NodeResizer
nodeId={id} nodeId={id}
nodeData={data} nodeData={data}
@ -86,13 +89,15 @@ const NoteNode = ({
minWidth={240} minWidth={240}
minHeight={88} minHeight={88}
/> />
)
}
<div <div
className={cn( className={cn(
'h-2 shrink-0 rounded-t-md opacity-50', 'h-2 shrink-0 rounded-t-md opacity-50',
THEME_MAP[theme].title, THEME_MAP[theme].title,
)}></div> )}></div>
{ {
data.selected && ( data.selected && !data._isTempNode && (
<div className='absolute left-1/2 top-[-41px] -translate-x-1/2'> <div className='absolute left-1/2 top-[-41px] -translate-x-1/2'>
<NoteEditorToolbar <NoteEditorToolbar
theme={theme} theme={theme}

@ -85,7 +85,7 @@ export type CommonNodeType<T = {}> = {
_waitingRun?: boolean _waitingRun?: boolean
_retryIndex?: number _retryIndex?: number
_dataSourceStartToAdd?: boolean _dataSourceStartToAdd?: boolean
noteBySystem?: boolean _isTempNode?: boolean
isInIteration?: boolean isInIteration?: boolean
iteration_id?: string iteration_id?: string
selected?: boolean selected?: boolean

Loading…
Cancel
Save