Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

nodes.ts 4.0KB

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