workflow.ts 6.6 KB

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