constants.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. import type { Var } from './types'
  2. import { BlockEnum, VarType } from './types'
  3. import StartNodeDefault from './nodes/start/default'
  4. import AnswerDefault from './nodes/answer/default'
  5. import LLMDefault from './nodes/llm/default'
  6. import KnowledgeRetrievalDefault from './nodes/knowledge-retrieval/default'
  7. import QuestionClassifierDefault from './nodes/question-classifier/default'
  8. import IfElseDefault from './nodes/if-else/default'
  9. import CodeDefault from './nodes/code/default'
  10. import TemplateTransformDefault from './nodes/template-transform/default'
  11. import HttpRequestDefault from './nodes/http/default'
  12. import ParameterExtractorDefault from './nodes/parameter-extractor/default'
  13. import ToolDefault from './nodes/tool/default'
  14. import VariableAssignerDefault from './nodes/variable-assigner/default'
  15. import AssignerDefault from './nodes/assigner/default'
  16. import EndNodeDefault from './nodes/end/default'
  17. import IterationDefault from './nodes/iteration/default'
  18. import DocExtractorDefault from './nodes/document-extractor/default'
  19. import ListFilterDefault from './nodes/list-operator/default'
  20. import IterationStartDefault from './nodes/iteration-start/default'
  21. type NodesExtraData = {
  22. author: string
  23. about: string
  24. availablePrevNodes: BlockEnum[]
  25. availableNextNodes: BlockEnum[]
  26. getAvailablePrevNodes: (isChatMode: boolean) => BlockEnum[]
  27. getAvailableNextNodes: (isChatMode: boolean) => BlockEnum[]
  28. checkValid: any
  29. }
  30. export const NODES_EXTRA_DATA: Record<BlockEnum, NodesExtraData> = {
  31. [BlockEnum.Start]: {
  32. author: 'Dify',
  33. about: '',
  34. availablePrevNodes: [],
  35. availableNextNodes: [],
  36. getAvailablePrevNodes: StartNodeDefault.getAvailablePrevNodes,
  37. getAvailableNextNodes: StartNodeDefault.getAvailableNextNodes,
  38. checkValid: StartNodeDefault.checkValid,
  39. },
  40. [BlockEnum.End]: {
  41. author: 'Dify',
  42. about: '',
  43. availablePrevNodes: [],
  44. availableNextNodes: [],
  45. getAvailablePrevNodes: EndNodeDefault.getAvailablePrevNodes,
  46. getAvailableNextNodes: EndNodeDefault.getAvailableNextNodes,
  47. checkValid: EndNodeDefault.checkValid,
  48. },
  49. [BlockEnum.Answer]: {
  50. author: 'Dify',
  51. about: '',
  52. availablePrevNodes: [],
  53. availableNextNodes: [],
  54. getAvailablePrevNodes: AnswerDefault.getAvailablePrevNodes,
  55. getAvailableNextNodes: AnswerDefault.getAvailableNextNodes,
  56. checkValid: AnswerDefault.checkValid,
  57. },
  58. [BlockEnum.LLM]: {
  59. author: 'Dify',
  60. about: '',
  61. availablePrevNodes: [],
  62. availableNextNodes: [],
  63. getAvailablePrevNodes: LLMDefault.getAvailablePrevNodes,
  64. getAvailableNextNodes: LLMDefault.getAvailableNextNodes,
  65. checkValid: LLMDefault.checkValid,
  66. },
  67. [BlockEnum.KnowledgeRetrieval]: {
  68. author: 'Dify',
  69. about: '',
  70. availablePrevNodes: [],
  71. availableNextNodes: [],
  72. getAvailablePrevNodes: KnowledgeRetrievalDefault.getAvailablePrevNodes,
  73. getAvailableNextNodes: KnowledgeRetrievalDefault.getAvailableNextNodes,
  74. checkValid: KnowledgeRetrievalDefault.checkValid,
  75. },
  76. [BlockEnum.IfElse]: {
  77. author: 'Dify',
  78. about: '',
  79. availablePrevNodes: [],
  80. availableNextNodes: [],
  81. getAvailablePrevNodes: IfElseDefault.getAvailablePrevNodes,
  82. getAvailableNextNodes: IfElseDefault.getAvailableNextNodes,
  83. checkValid: IfElseDefault.checkValid,
  84. },
  85. [BlockEnum.Iteration]: {
  86. author: 'Dify',
  87. about: '',
  88. availablePrevNodes: [],
  89. availableNextNodes: [],
  90. getAvailablePrevNodes: IterationDefault.getAvailablePrevNodes,
  91. getAvailableNextNodes: IterationDefault.getAvailableNextNodes,
  92. checkValid: IterationDefault.checkValid,
  93. },
  94. [BlockEnum.IterationStart]: {
  95. author: 'Dify',
  96. about: '',
  97. availablePrevNodes: [],
  98. availableNextNodes: [],
  99. getAvailablePrevNodes: IterationStartDefault.getAvailablePrevNodes,
  100. getAvailableNextNodes: IterationStartDefault.getAvailableNextNodes,
  101. checkValid: IterationStartDefault.checkValid,
  102. },
  103. [BlockEnum.Code]: {
  104. author: 'Dify',
  105. about: '',
  106. availablePrevNodes: [],
  107. availableNextNodes: [],
  108. getAvailablePrevNodes: CodeDefault.getAvailablePrevNodes,
  109. getAvailableNextNodes: CodeDefault.getAvailableNextNodes,
  110. checkValid: CodeDefault.checkValid,
  111. },
  112. [BlockEnum.TemplateTransform]: {
  113. author: 'Dify',
  114. about: '',
  115. availablePrevNodes: [],
  116. availableNextNodes: [],
  117. getAvailablePrevNodes: TemplateTransformDefault.getAvailablePrevNodes,
  118. getAvailableNextNodes: TemplateTransformDefault.getAvailableNextNodes,
  119. checkValid: TemplateTransformDefault.checkValid,
  120. },
  121. [BlockEnum.QuestionClassifier]: {
  122. author: 'Dify',
  123. about: '',
  124. availablePrevNodes: [],
  125. availableNextNodes: [],
  126. getAvailablePrevNodes: QuestionClassifierDefault.getAvailablePrevNodes,
  127. getAvailableNextNodes: QuestionClassifierDefault.getAvailableNextNodes,
  128. checkValid: QuestionClassifierDefault.checkValid,
  129. },
  130. [BlockEnum.HttpRequest]: {
  131. author: 'Dify',
  132. about: '',
  133. availablePrevNodes: [],
  134. availableNextNodes: [],
  135. getAvailablePrevNodes: HttpRequestDefault.getAvailablePrevNodes,
  136. getAvailableNextNodes: HttpRequestDefault.getAvailableNextNodes,
  137. checkValid: HttpRequestDefault.checkValid,
  138. },
  139. [BlockEnum.VariableAssigner]: {
  140. author: 'Dify',
  141. about: '',
  142. availablePrevNodes: [],
  143. availableNextNodes: [],
  144. getAvailablePrevNodes: VariableAssignerDefault.getAvailablePrevNodes,
  145. getAvailableNextNodes: VariableAssignerDefault.getAvailableNextNodes,
  146. checkValid: VariableAssignerDefault.checkValid,
  147. },
  148. [BlockEnum.Assigner]: {
  149. author: 'Dify',
  150. about: '',
  151. availablePrevNodes: [],
  152. availableNextNodes: [],
  153. getAvailablePrevNodes: AssignerDefault.getAvailablePrevNodes,
  154. getAvailableNextNodes: AssignerDefault.getAvailableNextNodes,
  155. checkValid: AssignerDefault.checkValid,
  156. },
  157. [BlockEnum.VariableAggregator]: {
  158. author: 'Dify',
  159. about: '',
  160. availablePrevNodes: [],
  161. availableNextNodes: [],
  162. getAvailablePrevNodes: VariableAssignerDefault.getAvailablePrevNodes,
  163. getAvailableNextNodes: VariableAssignerDefault.getAvailableNextNodes,
  164. checkValid: VariableAssignerDefault.checkValid,
  165. },
  166. [BlockEnum.ParameterExtractor]: {
  167. author: 'Dify',
  168. about: '',
  169. availablePrevNodes: [],
  170. availableNextNodes: [],
  171. getAvailablePrevNodes: ParameterExtractorDefault.getAvailablePrevNodes,
  172. getAvailableNextNodes: ParameterExtractorDefault.getAvailableNextNodes,
  173. checkValid: ParameterExtractorDefault.checkValid,
  174. },
  175. [BlockEnum.Tool]: {
  176. author: 'Dify',
  177. about: '',
  178. availablePrevNodes: [],
  179. availableNextNodes: [],
  180. getAvailablePrevNodes: ToolDefault.getAvailablePrevNodes,
  181. getAvailableNextNodes: ToolDefault.getAvailableNextNodes,
  182. checkValid: ToolDefault.checkValid,
  183. },
  184. [BlockEnum.DocExtractor]: {
  185. author: 'Dify',
  186. about: '',
  187. availablePrevNodes: [],
  188. availableNextNodes: [],
  189. getAvailablePrevNodes: DocExtractorDefault.getAvailablePrevNodes,
  190. getAvailableNextNodes: DocExtractorDefault.getAvailableNextNodes,
  191. checkValid: DocExtractorDefault.checkValid,
  192. },
  193. [BlockEnum.ListFilter]: {
  194. author: 'Dify',
  195. about: '',
  196. availablePrevNodes: [],
  197. availableNextNodes: [],
  198. getAvailablePrevNodes: ListFilterDefault.getAvailablePrevNodes,
  199. getAvailableNextNodes: ListFilterDefault.getAvailableNextNodes,
  200. checkValid: ListFilterDefault.checkValid,
  201. },
  202. }
  203. export const NODES_INITIAL_DATA = {
  204. [BlockEnum.Start]: {
  205. type: BlockEnum.Start,
  206. title: '',
  207. desc: '',
  208. ...StartNodeDefault.defaultValue,
  209. },
  210. [BlockEnum.End]: {
  211. type: BlockEnum.End,
  212. title: '',
  213. desc: '',
  214. ...EndNodeDefault.defaultValue,
  215. },
  216. [BlockEnum.Answer]: {
  217. type: BlockEnum.Answer,
  218. title: '',
  219. desc: '',
  220. ...AnswerDefault.defaultValue,
  221. },
  222. [BlockEnum.LLM]: {
  223. type: BlockEnum.LLM,
  224. title: '',
  225. desc: '',
  226. variables: [],
  227. ...LLMDefault.defaultValue,
  228. },
  229. [BlockEnum.KnowledgeRetrieval]: {
  230. type: BlockEnum.KnowledgeRetrieval,
  231. title: '',
  232. desc: '',
  233. query_variable_selector: [],
  234. dataset_ids: [],
  235. retrieval_mode: 'single',
  236. ...KnowledgeRetrievalDefault.defaultValue,
  237. },
  238. [BlockEnum.IfElse]: {
  239. type: BlockEnum.IfElse,
  240. title: '',
  241. desc: '',
  242. ...IfElseDefault.defaultValue,
  243. },
  244. [BlockEnum.Iteration]: {
  245. type: BlockEnum.Iteration,
  246. title: '',
  247. desc: '',
  248. ...IterationDefault.defaultValue,
  249. },
  250. [BlockEnum.IterationStart]: {
  251. type: BlockEnum.IterationStart,
  252. title: '',
  253. desc: '',
  254. ...IterationStartDefault.defaultValue,
  255. },
  256. [BlockEnum.Code]: {
  257. type: BlockEnum.Code,
  258. title: '',
  259. desc: '',
  260. variables: [],
  261. code_language: 'python3',
  262. code: '',
  263. outputs: [],
  264. ...CodeDefault.defaultValue,
  265. },
  266. [BlockEnum.TemplateTransform]: {
  267. type: BlockEnum.TemplateTransform,
  268. title: '',
  269. desc: '',
  270. variables: [],
  271. template: '',
  272. ...TemplateTransformDefault.defaultValue,
  273. },
  274. [BlockEnum.QuestionClassifier]: {
  275. type: BlockEnum.QuestionClassifier,
  276. title: '',
  277. desc: '',
  278. query_variable_selector: [],
  279. topics: [],
  280. ...QuestionClassifierDefault.defaultValue,
  281. },
  282. [BlockEnum.HttpRequest]: {
  283. type: BlockEnum.HttpRequest,
  284. title: '',
  285. desc: '',
  286. variables: [],
  287. ...HttpRequestDefault.defaultValue,
  288. },
  289. [BlockEnum.ParameterExtractor]: {
  290. type: BlockEnum.ParameterExtractor,
  291. title: '',
  292. desc: '',
  293. variables: [],
  294. ...ParameterExtractorDefault.defaultValue,
  295. },
  296. [BlockEnum.VariableAssigner]: {
  297. type: BlockEnum.VariableAssigner,
  298. title: '',
  299. desc: '',
  300. variables: [],
  301. output_type: '',
  302. ...VariableAssignerDefault.defaultValue,
  303. },
  304. [BlockEnum.VariableAggregator]: {
  305. type: BlockEnum.VariableAggregator,
  306. title: '',
  307. desc: '',
  308. variables: [],
  309. output_type: '',
  310. ...VariableAssignerDefault.defaultValue,
  311. },
  312. [BlockEnum.Assigner]: {
  313. type: BlockEnum.Assigner,
  314. title: '',
  315. desc: '',
  316. ...AssignerDefault.defaultValue,
  317. },
  318. [BlockEnum.Tool]: {
  319. type: BlockEnum.Tool,
  320. title: '',
  321. desc: '',
  322. ...ToolDefault.defaultValue,
  323. },
  324. [BlockEnum.DocExtractor]: {
  325. type: BlockEnum.DocExtractor,
  326. title: '',
  327. desc: '',
  328. ...DocExtractorDefault.defaultValue,
  329. },
  330. [BlockEnum.ListFilter]: {
  331. type: BlockEnum.ListFilter,
  332. title: '',
  333. desc: '',
  334. ...ListFilterDefault.defaultValue,
  335. },
  336. }
  337. export const MAX_ITERATION_PARALLEL_NUM = 10
  338. export const MIN_ITERATION_PARALLEL_NUM = 1
  339. export const DEFAULT_ITER_TIMES = 1
  340. export const NODE_WIDTH = 240
  341. export const X_OFFSET = 60
  342. export const NODE_WIDTH_X_OFFSET = NODE_WIDTH + X_OFFSET
  343. export const Y_OFFSET = 39
  344. export const MAX_TREE_DEPTH = 50
  345. export const START_INITIAL_POSITION = { x: 80, y: 282 }
  346. export const AUTO_LAYOUT_OFFSET = {
  347. x: -42,
  348. y: 243,
  349. }
  350. export const ITERATION_NODE_Z_INDEX = 1
  351. export const ITERATION_CHILDREN_Z_INDEX = 1002
  352. export const ITERATION_PADDING = {
  353. top: 65,
  354. right: 16,
  355. bottom: 20,
  356. left: 16,
  357. }
  358. export const PARALLEL_LIMIT = 10
  359. export const PARALLEL_DEPTH_LIMIT = 3
  360. export const RETRIEVAL_OUTPUT_STRUCT = `{
  361. "content": "",
  362. "title": "",
  363. "url": "",
  364. "icon": "",
  365. "metadata": {
  366. "dataset_id": "",
  367. "dataset_name": "",
  368. "document_id": [],
  369. "document_name": "",
  370. "document_data_source_type": "",
  371. "segment_id": "",
  372. "segment_position": "",
  373. "segment_word_count": "",
  374. "segment_hit_count": "",
  375. "segment_index_node_hash": "",
  376. "score": ""
  377. }
  378. }`
  379. export const SUPPORT_OUTPUT_VARS_NODE = [
  380. BlockEnum.Start, BlockEnum.LLM, BlockEnum.KnowledgeRetrieval, BlockEnum.Code, BlockEnum.TemplateTransform,
  381. BlockEnum.HttpRequest, BlockEnum.Tool, BlockEnum.VariableAssigner, BlockEnum.VariableAggregator, BlockEnum.QuestionClassifier,
  382. BlockEnum.ParameterExtractor, BlockEnum.Iteration,
  383. BlockEnum.DocExtractor, BlockEnum.ListFilter,
  384. ]
  385. export const LLM_OUTPUT_STRUCT: Var[] = [
  386. {
  387. variable: 'text',
  388. type: VarType.string,
  389. },
  390. ]
  391. export const KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT: Var[] = [
  392. {
  393. variable: 'result',
  394. type: VarType.arrayObject,
  395. },
  396. ]
  397. export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [
  398. {
  399. variable: 'output',
  400. type: VarType.string,
  401. },
  402. ]
  403. export const QUESTION_CLASSIFIER_OUTPUT_STRUCT = [
  404. {
  405. variable: 'class_name',
  406. type: VarType.string,
  407. },
  408. ]
  409. export const HTTP_REQUEST_OUTPUT_STRUCT: Var[] = [
  410. {
  411. variable: 'body',
  412. type: VarType.string,
  413. },
  414. {
  415. variable: 'status_code',
  416. type: VarType.number,
  417. },
  418. {
  419. variable: 'headers',
  420. type: VarType.object,
  421. },
  422. {
  423. variable: 'files',
  424. type: VarType.arrayFile,
  425. },
  426. ]
  427. export const TOOL_OUTPUT_STRUCT: Var[] = [
  428. {
  429. variable: 'text',
  430. type: VarType.string,
  431. },
  432. {
  433. variable: 'files',
  434. type: VarType.arrayFile,
  435. },
  436. {
  437. variable: 'json',
  438. type: VarType.arrayObject,
  439. },
  440. ]
  441. export const PARAMETER_EXTRACTOR_COMMON_STRUCT: Var[] = [
  442. {
  443. variable: '__is_success',
  444. type: VarType.number,
  445. },
  446. {
  447. variable: '__reason',
  448. type: VarType.string,
  449. },
  450. ]
  451. export const FILE_STRUCT: Var[] = [
  452. {
  453. variable: 'name',
  454. type: VarType.string,
  455. },
  456. {
  457. variable: 'size',
  458. type: VarType.number,
  459. },
  460. {
  461. variable: 'type',
  462. type: VarType.string,
  463. },
  464. {
  465. variable: 'extension',
  466. type: VarType.string,
  467. },
  468. {
  469. variable: 'mime_type',
  470. type: VarType.string,
  471. },
  472. {
  473. variable: 'transfer_method',
  474. type: VarType.string,
  475. },
  476. {
  477. variable: 'url',
  478. type: VarType.string,
  479. },
  480. ]
  481. export const DEFAULT_FILE_UPLOAD_SETTING = {
  482. allowed_file_upload_methods: ['local_file', 'remote_url'],
  483. max_length: 5,
  484. allowed_file_types: ['image'],
  485. allowed_file_extensions: [],
  486. }
  487. export const WORKFLOW_DATA_UPDATE = 'WORKFLOW_DATA_UPDATE'
  488. export const CUSTOM_NODE = 'custom'
  489. export const CUSTOM_EDGE = 'custom'
  490. export const DSL_EXPORT_CHECK = 'DSL_EXPORT_CHECK'
  491. export const DEFAULT_RETRY_MAX = 3
  492. export const DEFAULT_RETRY_INTERVAL = 100