default.ts 1.2 KB

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