http.ts 3.0 KB

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