http.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { NodeConnectionTypes, type INodeType } from '../Interface'
  2. export type HttpData = {
  3. outputs: Array<{
  4. name: 'body' | 'status_code' | 'headers'
  5. describe: string
  6. type: 'string' | 'number' | 'object'
  7. }>
  8. output_can_alter: boolean
  9. variables: any[]
  10. method: 'post'
  11. ssl_verify: boolean
  12. isInIteration: boolean
  13. default_value: any[]
  14. body: {
  15. type: 'json'
  16. data: Array<{
  17. key: string
  18. type: 'text'
  19. value: string
  20. }>
  21. }
  22. params: any[]
  23. title: string
  24. type: 'http-request'
  25. error_strategy: 'none' | string
  26. retry_config: {
  27. max_retries: number
  28. retry_enabled: boolean
  29. retry_interval: number
  30. }
  31. url: string
  32. authorization: {
  33. type: string
  34. config: {
  35. api_key: string
  36. header: string
  37. type: string
  38. }
  39. }
  40. timeout_config: {
  41. max_write_timeout: number
  42. max_read_timeout: number
  43. max_connect_timeout: number
  44. }
  45. heads: Array<{
  46. name: string
  47. value: string
  48. }>
  49. selected: boolean
  50. desc: string
  51. isInLoop: boolean
  52. }
  53. export const httpNode: INodeType = {
  54. version: ['1'],
  55. displayName: 'HTTP 请求',
  56. name: 'http-request',
  57. description: '通过HTTP请求获取数据',
  58. group: '数据处理',
  59. icon: 'lucide:link',
  60. iconColor: '#9373ee',
  61. inputs: [NodeConnectionTypes.main],
  62. outputs: (data: HttpData) => {
  63. // todo: 判断异常处理,如果是分支,添加异常出口
  64. return data?.error_strategy === 'exception'
  65. ? [NodeConnectionTypes.main, NodeConnectionTypes.main]
  66. : [NodeConnectionTypes.main]
  67. },
  68. validate: (data: HttpData) => {
  69. return !!data?.url.trim() ? false : '请填写URL'
  70. },
  71. // 业务数据
  72. schema: {
  73. appAgentId: '',
  74. parentId: '',
  75. position: {
  76. x: 20,
  77. y: 30
  78. },
  79. width: 96,
  80. height: 96,
  81. selected: false,
  82. nodeType: 'http-request',
  83. zIndex: 1,
  84. data: {
  85. outputs: [
  86. {
  87. name: 'body',
  88. describe: '响应内容',
  89. type: 'string'
  90. },
  91. {
  92. name: 'status_code',
  93. describe: '响应状态码',
  94. type: 'number'
  95. },
  96. {
  97. name: 'headers',
  98. describe: '响应头列表 JSON',
  99. type: 'object'
  100. }
  101. ],
  102. output_can_alter: false,
  103. variables: [],
  104. method: 'post',
  105. ssl_verify: false,
  106. isInIteration: false,
  107. default_value: [],
  108. body: {
  109. type: 'json',
  110. data: [
  111. {
  112. key: '',
  113. type: 'text',
  114. value: '{"id":"b3a4aabb-a6b8-47f3-8a32-f45930f7d7b8"}'
  115. }
  116. ]
  117. },
  118. params: [],
  119. title: 'HTTP 请求',
  120. type: 'http-request',
  121. error_strategy: 'none',
  122. retry_config: {
  123. max_retries: 3,
  124. retry_enabled: false,
  125. retry_interval: 100
  126. },
  127. url: '#{env.api_address}/api/agent/getAgentInfo',
  128. authorization: {
  129. type: 'none',
  130. config: {
  131. api_key: '',
  132. header: '',
  133. type: ''
  134. }
  135. },
  136. timeout_config: {
  137. max_write_timeout: 0,
  138. max_read_timeout: 0,
  139. max_connect_timeout: 0
  140. },
  141. heads: [
  142. {
  143. name: 'Authorization',
  144. value: ''
  145. }
  146. ],
  147. selected: true,
  148. desc: '',
  149. isInLoop: false
  150. }
  151. }
  152. }