workflow.ts 5.7 KB

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