You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nodes.ts 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import type { Node } from '@/app/components/workflow/types'
  2. import { BlockEnum } from '@/app/components/workflow/types'
  3. import { generateNewNode } from '@/app/components/workflow/utils'
  4. import { CUSTOM_DATA_SOURCE_EMPTY_NODE } from '@/app/components/workflow/nodes/data-source-empty/constants'
  5. import { CUSTOM_NOTE_NODE } from '@/app/components/workflow/note-node/constants'
  6. import { NoteTheme } from '@/app/components/workflow/note-node/types'
  7. import type { NoteNodeType } from '@/app/components/workflow/note-node/types'
  8. import { CUSTOM_NODE } from '@/app/components/workflow/constants'
  9. export const processNodesWithoutDataSource = (nodes: Node[]) => {
  10. if (!nodes || nodes.length === 0) return []
  11. let leftNode
  12. let hasNoteBySystem
  13. for (let i = 0; i < nodes.length; i++) {
  14. const node = nodes[i]
  15. if (node.type === CUSTOM_NOTE_NODE && node.data.noteBySystem)
  16. hasNoteBySystem = true
  17. if (node.type !== CUSTOM_NODE)
  18. continue
  19. if (node.data.type === BlockEnum.DataSource)
  20. return nodes
  21. if (!leftNode)
  22. leftNode = node
  23. if (node.position.x < leftNode.position.x)
  24. leftNode = node
  25. }
  26. if (leftNode) {
  27. const { newNode } = generateNewNode({
  28. type: CUSTOM_DATA_SOURCE_EMPTY_NODE,
  29. data: {
  30. title: '',
  31. desc: '',
  32. type: BlockEnum.DataSourceEmpty,
  33. width: 240,
  34. },
  35. position: {
  36. x: leftNode.position.x - 500,
  37. y: leftNode.position.y,
  38. },
  39. })
  40. let newNoteNode
  41. if (!hasNoteBySystem) {
  42. newNoteNode = generateNewNode({
  43. type: CUSTOM_NOTE_NODE,
  44. data: {
  45. title: '',
  46. desc: '',
  47. type: '' as any,
  48. 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;"}}',
  49. theme: NoteTheme.blue,
  50. author: '',
  51. showAuthor: true,
  52. width: 240,
  53. height: 300,
  54. noteBySystem: true,
  55. } as NoteNodeType,
  56. position: {
  57. x: leftNode.position.x - 500,
  58. y: leftNode.position.y + 100,
  59. },
  60. }).newNode
  61. }
  62. return [
  63. newNode,
  64. ...(newNoteNode ? [newNoteNode] : []),
  65. ...nodes,
  66. ]
  67. }
  68. return nodes
  69. }