您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

default.ts 2.3KB

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