workflow.ts 6.9 KB

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