default.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.post,
  13. url: ['localhost', '1.95.78.201'].includes(location.hostname) ? 'http://1.95.78.201:30001/call' : 'http://10.76.102.168.:5006/call',
  14. authorization: {
  15. type: AuthorizationType.none,
  16. config: null,
  17. },
  18. headers: 'accept:application/json\nContent-Type:application/json',
  19. params: '',
  20. body: {
  21. type: BodyType.rawText,
  22. data: <any>[
  23. {
  24. type: 'text',
  25. value: '{\n "input": {\n "text": ""\n },\n "parameters": {\n "candidate_labels": []\n }\n}',
  26. },
  27. ],
  28. },
  29. timeout: {
  30. max_connect_timeout: 0,
  31. max_read_timeout: 0,
  32. max_write_timeout: 0,
  33. },
  34. retry_config: {
  35. retry_enabled: true,
  36. max_retries: 3,
  37. retry_interval: 100,
  38. },
  39. },
  40. getAvailablePrevNodes(isChatMode: boolean) {
  41. const nodes = isChatMode
  42. ? ALL_CHAT_AVAILABLE_BLOCKS
  43. : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
  44. return nodes
  45. },
  46. getAvailableNextNodes(isChatMode: boolean) {
  47. const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
  48. return nodes
  49. },
  50. checkValid(payload: HttpNodeType, t: any) {
  51. let errorMessages = ''
  52. if (!errorMessages && !payload.url)
  53. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') })
  54. if (!errorMessages
  55. && payload.body.type === BodyType.binary
  56. && ((!(payload.body.data as BodyPayload)[0]?.file) || (payload.body.data as BodyPayload)[0]?.file?.length === 0)
  57. )
  58. errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.binaryFileVariable') })
  59. return {
  60. isValid: !errorMessages,
  61. errorMessage: errorMessages,
  62. }
  63. },
  64. }
  65. export default nodeDefault