default.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { BlockEnum, ErrorHandleMode } from '../../types'
  2. import type { NodeDefault } from '../../types'
  3. import type { IterationNodeType } from './types'
  4. import {
  5. ALL_CHAT_AVAILABLE_BLOCKS,
  6. ALL_COMPLETION_AVAILABLE_BLOCKS,
  7. } from '@/app/components/workflow/constants'
  8. const i18nPrefix = 'workflow'
  9. const nodeDefault: NodeDefault<IterationNodeType> = {
  10. defaultValue: {
  11. start_node_id: '',
  12. iterator_selector: [],
  13. output_selector: [],
  14. _children: [],
  15. _isShowTips: false,
  16. is_parallel: false,
  17. parallel_nums: 10,
  18. error_handle_mode: ErrorHandleMode.Terminated,
  19. },
  20. getAvailablePrevNodes(isChatMode: boolean) {
  21. const nodes = isChatMode
  22. ? ALL_CHAT_AVAILABLE_BLOCKS
  23. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(
  24. type => type !== BlockEnum.End,
  25. )
  26. return nodes
  27. },
  28. getAvailableNextNodes(isChatMode: boolean) {
  29. const nodes = isChatMode
  30. ? ALL_CHAT_AVAILABLE_BLOCKS
  31. : ALL_COMPLETION_AVAILABLE_BLOCKS
  32. return nodes
  33. },
  34. checkValid(payload: IterationNodeType, t: any) {
  35. let errorMessages = ''
  36. if (
  37. !errorMessages
  38. && (!payload.iterator_selector || payload.iterator_selector.length === 0)
  39. ) {
  40. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, {
  41. field: t(`${i18nPrefix}.nodes.iteration.input`),
  42. })
  43. }
  44. if (
  45. !errorMessages
  46. && (!payload.output_selector || payload.output_selector.length === 0)
  47. ) {
  48. errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, {
  49. field: t(`${i18nPrefix}.nodes.iteration.output`),
  50. })
  51. }
  52. return {
  53. isValid: !errorMessages,
  54. errorMessage: errorMessages,
  55. }
  56. },
  57. }
  58. export default nodeDefault