default.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. timeout: {
  21. max_connect_timeout: 0,
  22. max_read_timeout: 0,
  23. max_write_timeout: 0,
  24. },
  25. },
  26. getAvailablePrevNodes(isChatMode: boolean) {
  27. const nodes = isChatMode
  28. ? ALL_CHAT_AVAILABLE_BLOCKS
  29. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
  30. return nodes
  31. },
  32. getAvailableNextNodes(isChatMode: boolean) {
  33. const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  34. return nodes
  35. },
  36. checkValid(payload: HttpNodeType, t: any) {
  37. let errorMessages = ''
  38. if (!errorMessages && !payload.url)
  39. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') })
  40. return {
  41. isValid: !errorMessages,
  42. errorMessage: errorMessages,
  43. }
  44. },
  45. }
  46. export default nodeDefault