workflow.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. }
  29. metadata: {
  30. iterator_length: number
  31. }
  32. created_at: number
  33. created_by: {
  34. id: string
  35. name: string
  36. email: string
  37. }
  38. finished_at: number
  39. extras?: any
  40. expand?: boolean // for UI
  41. details?: NodeTracing[][] // iteration detail
  42. }
  43. export type FetchWorkflowDraftResponse = {
  44. id: string
  45. graph: {
  46. nodes: Node[]
  47. edges: Edge[]
  48. viewport?: Viewport
  49. }
  50. features?: any
  51. created_at: number
  52. created_by: {
  53. id: string
  54. name: string
  55. email: string
  56. }
  57. hash: string
  58. updated_at: number
  59. tool_published: boolean
  60. environment_variables?: EnvironmentVariable[]
  61. conversation_variables?: ConversationVariable[]
  62. }
  63. export type NodeTracingListResponse = {
  64. data: NodeTracing[]
  65. }
  66. export type WorkflowStartedResponse = {
  67. task_id: string
  68. workflow_run_id: string
  69. event: string
  70. data: {
  71. id: string
  72. workflow_id: string
  73. sequence_number: number
  74. created_at: number
  75. }
  76. }
  77. export type WorkflowFinishedResponse = {
  78. task_id: string
  79. workflow_run_id: string
  80. event: string
  81. data: {
  82. id: string
  83. workflow_id: string
  84. status: string
  85. outputs: any
  86. error: string
  87. elapsed_time: number
  88. total_tokens: number
  89. total_steps: number
  90. created_at: number
  91. created_by: {
  92. id: string
  93. name: string
  94. email: string
  95. }
  96. finished_at: number
  97. }
  98. }
  99. export type NodeStartedResponse = {
  100. task_id: string
  101. workflow_run_id: string
  102. event: string
  103. data: {
  104. id: string
  105. node_id: string
  106. node_type: string
  107. index: number
  108. predecessor_node_id?: string
  109. inputs: any
  110. created_at: number
  111. extras?: any
  112. }
  113. }
  114. export type NodeFinishedResponse = {
  115. task_id: string
  116. workflow_run_id: string
  117. event: string
  118. data: {
  119. id: string
  120. node_id: string
  121. node_type: string
  122. index: number
  123. predecessor_node_id?: string
  124. inputs: any
  125. process_data: any
  126. outputs: any
  127. status: string
  128. error: string
  129. elapsed_time: number
  130. execution_metadata: {
  131. total_tokens: number
  132. total_price: number
  133. currency: string
  134. }
  135. created_at: number
  136. }
  137. }
  138. export type IterationStartedResponse = {
  139. task_id: string
  140. workflow_run_id: string
  141. event: string
  142. data: {
  143. id: string
  144. node_id: string
  145. metadata: {
  146. iterator_length: number
  147. }
  148. created_at: number
  149. extras?: any
  150. }
  151. }
  152. export type IterationNextedResponse = {
  153. task_id: string
  154. workflow_run_id: string
  155. event: string
  156. data: {
  157. id: string
  158. node_id: string
  159. index: number
  160. output: any
  161. extras?: any
  162. created_at: number
  163. }
  164. }
  165. export type IterationFinishedResponse = {
  166. task_id: string
  167. workflow_run_id: string
  168. event: string
  169. data: {
  170. id: string
  171. node_id: string
  172. outputs: any
  173. extras?: any
  174. status: string
  175. created_at: number
  176. error: string
  177. }
  178. }
  179. export type TextChunkResponse = {
  180. task_id: string
  181. workflow_run_id: string
  182. event: string
  183. data: {
  184. text: string
  185. }
  186. }
  187. export type TextReplaceResponse = {
  188. task_id: string
  189. workflow_run_id: string
  190. event: string
  191. data: {
  192. text: string
  193. }
  194. }
  195. export type WorkflowRunHistory = {
  196. id: string
  197. sequence_number: number
  198. version: string
  199. conversation_id?: string
  200. message_id?: string
  201. graph: {
  202. nodes: Node[]
  203. edges: Edge[]
  204. viewport?: Viewport
  205. }
  206. inputs: Record<string, string>
  207. status: string
  208. outputs: Record<string, any>
  209. error?: string
  210. elapsed_time: number
  211. total_tokens: number
  212. total_steps: number
  213. created_at: number
  214. finished_at: number
  215. created_by_account: {
  216. id: string
  217. name: string
  218. email: string
  219. }
  220. }
  221. export type WorkflowRunHistoryResponse = {
  222. data: WorkflowRunHistory[]
  223. }
  224. export type ChatRunHistoryResponse = {
  225. data: WorkflowRunHistory[]
  226. }
  227. export type NodesDefaultConfigsResponse = {
  228. type: string
  229. config: any
  230. }[]
  231. export type ConversationVariableResponse = {
  232. data: (ConversationVariable & { updated_at: number; created_at: number })[]
  233. has_more: boolean
  234. limit: number
  235. total: number
  236. page: number
  237. }