workflow.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import type { Viewport } from 'reactflow'
  2. import type {
  3. BlockEnum,
  4. ConversationVariable,
  5. Edge,
  6. EnvironmentVariable,
  7. Node,
  8. } from '@/app/components/workflow/types'
  9. import type { TransferMethod } from '@/types/app'
  10. import type { ErrorHandleTypeEnum } from '@/app/components/workflow/nodes/_base/components/error-handle/types'
  11. export type NodeTracing = {
  12. id: string
  13. index: number
  14. predecessor_node_id: string
  15. node_id: string
  16. node_type: BlockEnum
  17. title: string
  18. inputs: any
  19. process_data: any
  20. outputs?: any
  21. status: string
  22. parallel_run_id?: string
  23. error?: string
  24. elapsed_time: number
  25. execution_metadata?: {
  26. total_tokens: number
  27. total_price: number
  28. currency: string
  29. iteration_id?: string
  30. iteration_index?: number
  31. parallel_id?: string
  32. parallel_start_node_id?: string
  33. parent_parallel_id?: string
  34. parent_parallel_start_node_id?: string
  35. parallel_mode_run_id?: string
  36. iteration_duration_map?: IterationDurationMap
  37. error_strategy?: ErrorHandleTypeEnum
  38. }
  39. metadata: {
  40. iterator_length: number
  41. iterator_index: number
  42. }
  43. created_at: number
  44. created_by: {
  45. id: string
  46. name: string
  47. email: string
  48. }
  49. iterDurationMap?: IterationDurationMap
  50. finished_at: number
  51. extras?: any
  52. expand?: boolean // for UI
  53. details?: NodeTracing[][] // iteration detail
  54. retryDetail?: NodeTracing[] // retry detail
  55. parallel_id?: string
  56. parallel_start_node_id?: string
  57. parent_parallel_id?: string
  58. parent_parallel_start_node_id?: string
  59. retry_index?: number
  60. }
  61. export type FetchWorkflowDraftResponse = {
  62. id: string
  63. graph: {
  64. nodes: Node[]
  65. edges: Edge[]
  66. viewport?: Viewport
  67. }
  68. features?: any
  69. created_at: number
  70. created_by: {
  71. id: string
  72. name: string
  73. email: string
  74. }
  75. hash: string
  76. updated_at: number
  77. tool_published: boolean
  78. environment_variables?: EnvironmentVariable[]
  79. conversation_variables?: ConversationVariable[]
  80. }
  81. export type NodeTracingListResponse = {
  82. data: NodeTracing[]
  83. }
  84. export type WorkflowStartedResponse = {
  85. task_id: string
  86. workflow_run_id: string
  87. event: string
  88. data: {
  89. id: string
  90. workflow_id: string
  91. sequence_number: number
  92. created_at: number
  93. }
  94. }
  95. export type WorkflowFinishedResponse = {
  96. task_id: string
  97. workflow_run_id: string
  98. event: string
  99. data: {
  100. id: string
  101. workflow_id: string
  102. status: string
  103. outputs: any
  104. error: string
  105. elapsed_time: number
  106. total_tokens: number
  107. total_steps: number
  108. created_at: number
  109. created_by: {
  110. id: string
  111. name: string
  112. email: string
  113. }
  114. finished_at: number
  115. files?: FileResponse[]
  116. }
  117. }
  118. export type NodeStartedResponse = {
  119. task_id: string
  120. workflow_run_id: string
  121. event: string
  122. data: {
  123. id: string
  124. node_id: string
  125. iteration_id?: string
  126. parallel_run_id?: string
  127. node_type: string
  128. index: number
  129. predecessor_node_id?: string
  130. inputs: any
  131. created_at: number
  132. extras?: any
  133. }
  134. }
  135. export type FileResponse = {
  136. related_id: string
  137. extension: string
  138. filename: string
  139. size: number
  140. mime_type: string
  141. transfer_method: TransferMethod
  142. type: string
  143. url: string
  144. }
  145. export type NodeFinishedResponse = {
  146. task_id: string
  147. workflow_run_id: string
  148. event: string
  149. data: {
  150. id: string
  151. node_id: string
  152. iteration_id?: string
  153. node_type: string
  154. index: number
  155. predecessor_node_id?: string
  156. inputs: any
  157. process_data: any
  158. outputs: any
  159. status: string
  160. error: string
  161. elapsed_time: number
  162. execution_metadata: {
  163. total_tokens: number
  164. total_price: number
  165. currency: string
  166. parallel_id?: string
  167. parallel_start_node_id?: string
  168. iteration_index?: number
  169. iteration_id?: string
  170. parallel_mode_run_id: string
  171. error_strategy?: ErrorHandleTypeEnum
  172. }
  173. created_at: number
  174. files?: FileResponse[]
  175. retry_index?: number
  176. }
  177. }
  178. export type IterationStartedResponse = {
  179. task_id: string
  180. workflow_run_id: string
  181. event: string
  182. data: {
  183. id: string
  184. node_id: string
  185. metadata: {
  186. iterator_length: number
  187. iteration_id: string
  188. iteration_index: number
  189. }
  190. created_at: number
  191. extras?: any
  192. }
  193. }
  194. export type IterationNextResponse = {
  195. task_id: string
  196. workflow_run_id: string
  197. event: string
  198. data: {
  199. id: string
  200. node_id: string
  201. index: number
  202. output: any
  203. extras?: any
  204. created_at: number
  205. parallel_mode_run_id: string
  206. execution_metadata: {
  207. parallel_id?: string
  208. iteration_index: number
  209. parallel_mode_run_id?: string
  210. }
  211. duration?: number
  212. }
  213. }
  214. export type IterationFinishedResponse = {
  215. task_id: string
  216. workflow_run_id: string
  217. event: string
  218. data: {
  219. id: string
  220. node_id: string
  221. outputs: any
  222. extras?: any
  223. status: string
  224. created_at: number
  225. error: string
  226. execution_metadata: {
  227. parallel_id?: string
  228. }
  229. }
  230. }
  231. export type ParallelBranchStartedResponse = {
  232. task_id: string
  233. workflow_run_id: string
  234. event: string
  235. data: {
  236. parallel_id: string
  237. parallel_start_node_id: string
  238. parent_parallel_id: string
  239. parent_parallel_start_node_id: string
  240. iteration_id?: string
  241. created_at: number
  242. }
  243. }
  244. export type ParallelBranchFinishedResponse = {
  245. task_id: string
  246. workflow_run_id: string
  247. event: string
  248. data: {
  249. parallel_id: string
  250. parallel_start_node_id: string
  251. parent_parallel_id: string
  252. parent_parallel_start_node_id: string
  253. iteration_id?: string
  254. status: string
  255. created_at: number
  256. error: string
  257. }
  258. }
  259. export type TextChunkResponse = {
  260. task_id: string
  261. workflow_run_id: string
  262. event: string
  263. data: {
  264. text: string
  265. }
  266. }
  267. export type TextReplaceResponse = {
  268. task_id: string
  269. workflow_run_id: string
  270. event: string
  271. data: {
  272. text: string
  273. }
  274. }
  275. export type WorkflowRunHistory = {
  276. id: string
  277. sequence_number: number
  278. version: string
  279. conversation_id?: string
  280. message_id?: string
  281. graph: {
  282. nodes: Node[]
  283. edges: Edge[]
  284. viewport?: Viewport
  285. }
  286. inputs: Record<string, string>
  287. status: string
  288. outputs: Record<string, any>
  289. error?: string
  290. elapsed_time: number
  291. total_tokens: number
  292. total_steps: number
  293. created_at: number
  294. finished_at: number
  295. created_by_account: {
  296. id: string
  297. name: string
  298. email: string
  299. }
  300. }
  301. export type WorkflowRunHistoryResponse = {
  302. data: WorkflowRunHistory[]
  303. }
  304. export type ChatRunHistoryResponse = {
  305. data: WorkflowRunHistory[]
  306. }
  307. export type NodesDefaultConfigsResponse = {
  308. type: string
  309. config: any
  310. }[]
  311. export type ConversationVariableResponse = {
  312. data: (ConversationVariable & { updated_at: number; created_at: number })[]
  313. has_more: boolean
  314. limit: number
  315. total: number
  316. page: number
  317. }
  318. export type IterationDurationMap = Record<string, number>
  319. export type WorkflowConfigResponse = {
  320. parallel_depth_limit: number
  321. }