workflow.ts 6.5 KB

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