default.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { BlockEnum } from '../../types'
  2. import type { NodeDefault } from '../../types'
  3. import { AuthorizationType, BodyType, type HttpNodeType, Method } from './types'
  4. import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants'
  5. const nodeDefault: NodeDefault<HttpNodeType> = {
  6. defaultValue: {
  7. variables: [],
  8. method: Method.get,
  9. url: '',
  10. authorization: {
  11. type: AuthorizationType.none,
  12. config: null,
  13. },
  14. headers: '',
  15. params: '',
  16. body: {
  17. type: BodyType.none,
  18. data: '',
  19. },
  20. },
  21. getAvailablePrevNodes(isChatMode: boolean) {
  22. const nodes = isChatMode
  23. ? ALL_CHAT_AVAILABLE_BLOCKS
  24. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
  25. return nodes
  26. },
  27. getAvailableNextNodes(isChatMode: boolean) {
  28. const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  29. return nodes
  30. },
  31. checkValid(payload: HttpNodeType, t: any) {
  32. let errorMessages = ''
  33. if (!errorMessages && !payload.url)
  34. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') })
  35. if (!errorMessages && !payload.url.startsWith('http://') && !payload.url.startsWith('https://'))
  36. errorMessages = t('workflow.nodes.http.notStartWithHttp')
  37. return {
  38. isValid: !errorMessages,
  39. errorMessage: errorMessages,
  40. }
  41. },
  42. }
  43. export default nodeDefault