workflow.ts 6.2 KB

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