workflow.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. updated_by: {
  111. id: string
  112. name: string
  113. email: string
  114. },
  115. tool_published: boolean
  116. environment_variables?: EnvironmentVariable[]
  117. conversation_variables?: ConversationVariable[]
  118. version: string
  119. marked_name: string
  120. marked_comment: string
  121. }
  122. export type VersionHistory = FetchWorkflowDraftResponse
  123. export type FetchWorkflowDraftPageParams = {
  124. appId: string
  125. initialPage: number
  126. limit: number
  127. userId?: string
  128. namedOnly?: boolean
  129. }
  130. export type FetchWorkflowDraftPageResponse = {
  131. items: VersionHistory[]
  132. has_more: boolean
  133. page: number
  134. }
  135. export type NodeTracingListResponse = {
  136. data: NodeTracing[]
  137. }
  138. export type WorkflowStartedResponse = {
  139. task_id: string
  140. workflow_run_id: string
  141. event: string
  142. data: {
  143. id: string
  144. workflow_id: string
  145. sequence_number: number
  146. created_at: number
  147. }
  148. }
  149. export type WorkflowFinishedResponse = {
  150. task_id: string
  151. workflow_run_id: string
  152. event: string
  153. data: {
  154. id: string
  155. workflow_id: string
  156. status: string
  157. outputs: any
  158. error: string
  159. elapsed_time: number
  160. total_tokens: number
  161. total_steps: number
  162. created_at: number
  163. created_by: {
  164. id: string
  165. name: string
  166. email: string
  167. }
  168. finished_at: number
  169. files?: FileResponse[]
  170. }
  171. }
  172. export type NodeStartedResponse = {
  173. task_id: string
  174. workflow_run_id: string
  175. event: string
  176. data: NodeTracing
  177. }
  178. export type FileResponse = {
  179. related_id: string
  180. extension: string
  181. filename: string
  182. size: number
  183. mime_type: string
  184. transfer_method: TransferMethod
  185. type: string
  186. url: string
  187. }
  188. export type NodeFinishedResponse = {
  189. task_id: string
  190. workflow_run_id: string
  191. event: string
  192. data: NodeTracing
  193. }
  194. export type IterationStartedResponse = {
  195. task_id: string
  196. workflow_run_id: string
  197. event: string
  198. data: NodeTracing
  199. }
  200. export type IterationNextResponse = {
  201. task_id: string
  202. workflow_run_id: string
  203. event: string
  204. data: NodeTracing
  205. }
  206. export type IterationFinishedResponse = {
  207. task_id: string
  208. workflow_run_id: string
  209. event: string
  210. data: NodeTracing
  211. }
  212. export type LoopStartedResponse = {
  213. task_id: string
  214. workflow_run_id: string
  215. event: string
  216. data: NodeTracing
  217. }
  218. export type LoopNextResponse = {
  219. task_id: string
  220. workflow_run_id: string
  221. event: string
  222. data: NodeTracing
  223. }
  224. export type LoopFinishedResponse = {
  225. task_id: string
  226. workflow_run_id: string
  227. event: string
  228. data: NodeTracing
  229. }
  230. export type ParallelBranchStartedResponse = {
  231. task_id: string
  232. workflow_run_id: string
  233. event: string
  234. data: NodeTracing
  235. }
  236. export type ParallelBranchFinishedResponse = {
  237. task_id: string
  238. workflow_run_id: string
  239. event: string
  240. data: NodeTracing
  241. }
  242. export type TextChunkResponse = {
  243. task_id: string
  244. workflow_run_id: string
  245. event: string
  246. data: {
  247. text: string
  248. }
  249. }
  250. export type TextReplaceResponse = {
  251. task_id: string
  252. workflow_run_id: string
  253. event: string
  254. data: {
  255. text: string
  256. }
  257. }
  258. export type AgentLogResponse = {
  259. task_id: string
  260. event: string
  261. data: AgentLogItemWithChildren
  262. }
  263. export type WorkflowRunHistory = {
  264. id: string
  265. sequence_number: number
  266. version: string
  267. conversation_id?: string
  268. message_id?: string
  269. graph: {
  270. nodes: Node[]
  271. edges: Edge[]
  272. viewport?: Viewport
  273. }
  274. inputs: Record<string, string>
  275. status: string
  276. outputs: Record<string, any>
  277. error?: string
  278. elapsed_time: number
  279. total_tokens: number
  280. total_steps: number
  281. created_at: number
  282. finished_at: number
  283. created_by_account: {
  284. id: string
  285. name: string
  286. email: string
  287. }
  288. }
  289. export type WorkflowRunHistoryResponse = {
  290. data: WorkflowRunHistory[]
  291. }
  292. export type ChatRunHistoryResponse = {
  293. data: WorkflowRunHistory[]
  294. }
  295. export type NodesDefaultConfigsResponse = {
  296. type: string
  297. config: any
  298. }[]
  299. export type ConversationVariableResponse = {
  300. data: (ConversationVariable & { updated_at: number; created_at: number })[]
  301. has_more: boolean
  302. limit: number
  303. total: number
  304. page: number
  305. }
  306. export type IterationDurationMap = Record<string, number>
  307. export type LoopDurationMap = Record<string, number>
  308. export type WorkflowConfigResponse = {
  309. parallel_depth_limit: number
  310. }
  311. export type PublishWorkflowParams = {
  312. title: string
  313. releaseNotes: string
  314. }
  315. export type UpdateWorkflowParams = {
  316. workflowId: string
  317. title: string
  318. releaseNotes: string
  319. }