workflow.ts 6.0 KB

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