workflow.ts 4.4 KB

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