workflow.ts 6.0 KB

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