default.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { BlockEnum } from '../../types'
  2. import type { NodeDefault } from '../../types'
  3. import type { IterationNodeType } from './types'
  4. import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants'
  5. const i18nPrefix = 'workflow'
  6. const nodeDefault: NodeDefault<IterationNodeType> = {
  7. defaultValue: {
  8. start_node_id: '',
  9. iterator_selector: [],
  10. output_selector: [],
  11. _children: [],
  12. },
  13. getAvailablePrevNodes(isChatMode: boolean) {
  14. const nodes = isChatMode
  15. ? ALL_CHAT_AVAILABLE_BLOCKS
  16. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
  17. return nodes
  18. },
  19. getAvailableNextNodes(isChatMode: boolean) {
  20. const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  21. return nodes
  22. },
  23. checkValid(payload: IterationNodeType, t: any) {
  24. let errorMessages = ''
  25. if (!errorMessages && (!payload.iterator_selector || payload.iterator_selector.length === 0))
  26. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.iteration.input`) })
  27. if (!errorMessages && (!payload.output_selector || payload.output_selector.length === 0))
  28. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.iteration.output`) })
  29. return {
  30. isValid: !errorMessages,
  31. errorMessage: errorMessages,
  32. }
  33. },
  34. }
  35. export default nodeDefault