default.ts 1.7 KB

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