您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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/blocks'
  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. ssl_verify: true,
  25. timeout: {
  26. max_connect_timeout: 0,
  27. max_read_timeout: 0,
  28. max_write_timeout: 0,
  29. },
  30. retry_config: {
  31. retry_enabled: true,
  32. max_retries: 3,
  33. retry_interval: 100,
  34. },
  35. },
  36. getAvailablePrevNodes(isChatMode: boolean) {
  37. const nodes = isChatMode
  38. ? ALL_CHAT_AVAILABLE_BLOCKS
  39. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
  40. return nodes
  41. },
  42. getAvailableNextNodes(isChatMode: boolean) {
  43. const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  44. return nodes
  45. },
  46. checkValid(payload: HttpNodeType, t: any) {
  47. let errorMessages = ''
  48. if (!errorMessages && !payload.url)
  49. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') })
  50. if (!errorMessages
  51. && payload.body.type === BodyType.binary
  52. && ((!(payload.body.data as BodyPayload)[0]?.file) || (payload.body.data as BodyPayload)[0]?.file?.length === 0)
  53. )
  54. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.binaryFileVariable') })
  55. return {
  56. isValid: !errorMessages,
  57. errorMessage: errorMessages,
  58. }
  59. },
  60. }
  61. export default nodeDefault