default.ts 1.8 KB

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