default.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { BlockEnum } from '../../types'
  2. import type { NodeDefault } from '../../types'
  3. import type { TemplateTransformNodeType } 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<TemplateTransformNodeType> = {
  7. defaultValue: {
  8. variables: [],
  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 ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  18. return nodes
  19. },
  20. checkValid(payload: TemplateTransformNodeType, t: any) {
  21. let errorMessages = ''
  22. const { template, variables } = payload
  23. if (!errorMessages && variables.filter(v => !v.variable).length > 0)
  24. errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.variable`) })
  25. if (!errorMessages && variables.filter(v => !v.value_selector.length).length > 0)
  26. errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.variableValue`) })
  27. if (!errorMessages && !template)
  28. errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t('workflow.nodes.templateTransform.code') })
  29. return {
  30. isValid: !errorMessages,
  31. errorMessage: errorMessages,
  32. }
  33. },
  34. }
  35. export default nodeDefault