mirror of
https://github.com/langgenius/dify.git
synced 2026-05-14 19:00:33 -04:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Yansong Zhang <916125788@qq.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: hj24 <mambahj24@gmail.com> Co-authored-by: hj24 <huangjian@dify.ai> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Ayush Baluni <73417844+aayushbaluni@users.noreply.github.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: jimcody1995 <jjimcody@gmail.com> Co-authored-by: James <63717587+jamesrayammons@users.noreply.github.com> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: Stephen Zhou <hi@hyoban.cc> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jerryzai <jerryzh8710@protonmail.com> Co-authored-by: NVIDIAN <speedy.hpc@hotmail.com> Co-authored-by: ai-hpc <ai-hpc@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Junghwan <70629228+shaun0927@users.noreply.github.com> Co-authored-by: HeYinKazune <70251095+HeYin-OS@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Jingyi <jingyi.qi@dify.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: sxxtony <166789813+sxxtony@users.noreply.github.com>
91 lines
4.0 KiB
TypeScript
91 lines
4.0 KiB
TypeScript
import type { Viewport } from 'reactflow'
|
|
import type { NoteNodeType } from '@/app/components/workflow/note-node/types'
|
|
import type { Node } from '@/app/components/workflow/types'
|
|
import {
|
|
CUSTOM_NODE,
|
|
NODE_WIDTH_X_OFFSET,
|
|
START_INITIAL_POSITION,
|
|
} from '@/app/components/workflow/constants'
|
|
import { CUSTOM_DATA_SOURCE_EMPTY_NODE } from '@/app/components/workflow/nodes/data-source-empty/constants'
|
|
import { CUSTOM_NOTE_NODE } from '@/app/components/workflow/note-node/constants'
|
|
import { NoteTheme } from '@/app/components/workflow/note-node/types'
|
|
import { BlockEnum } from '@/app/components/workflow/types'
|
|
import { generateNewNode } from '@/app/components/workflow/utils'
|
|
|
|
export const processNodesWithoutDataSource = (nodes: Node[], viewport?: Viewport) => {
|
|
let leftNode
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
const node = nodes[i]
|
|
|
|
if (node!.data.type === BlockEnum.DataSource) {
|
|
return {
|
|
nodes,
|
|
viewport,
|
|
}
|
|
}
|
|
|
|
if (node!.type === CUSTOM_NODE && !leftNode)
|
|
leftNode = node
|
|
|
|
if (node!.type === CUSTOM_NODE && leftNode && node!.position.x < leftNode.position.x)
|
|
leftNode = node
|
|
}
|
|
|
|
if (leftNode) {
|
|
const startX = leftNode.position.x - NODE_WIDTH_X_OFFSET
|
|
const startY = leftNode.position.y
|
|
const { newNode } = generateNewNode({
|
|
id: 'data-source-empty',
|
|
type: CUSTOM_DATA_SOURCE_EMPTY_NODE,
|
|
data: {
|
|
title: '',
|
|
desc: '',
|
|
type: BlockEnum.DataSourceEmpty,
|
|
width: 240,
|
|
_isTempNode: true,
|
|
},
|
|
position: {
|
|
x: startX,
|
|
y: startY,
|
|
},
|
|
})
|
|
const newNoteNode = generateNewNode({
|
|
id: 'note',
|
|
type: CUSTOM_NOTE_NODE,
|
|
data: {
|
|
title: '',
|
|
desc: '',
|
|
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":"_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,
|
|
author: '',
|
|
showAuthor: true,
|
|
width: 240,
|
|
height: 300,
|
|
_isTempNode: true,
|
|
} as NoteNodeType,
|
|
position: {
|
|
x: startX,
|
|
y: startY + 100,
|
|
},
|
|
}).newNode
|
|
return {
|
|
nodes: [
|
|
newNode,
|
|
newNoteNode,
|
|
...nodes,
|
|
],
|
|
viewport: {
|
|
x: (START_INITIAL_POSITION.x - startX) * (viewport?.zoom || 1),
|
|
y: (START_INITIAL_POSITION.y - startY) * (viewport?.zoom || 1),
|
|
zoom: viewport?.zoom || 1,
|
|
},
|
|
}
|
|
}
|
|
|
|
return {
|
|
nodes,
|
|
viewport,
|
|
}
|
|
}
|