default.ts 1.1 KB

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