workflow.ts 6.4 KB

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