constants.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { SupportUploadFileTypes, type ValueSelector } from '../../workflow/types'
  2. export const CONTEXT_PLACEHOLDER_TEXT = '{{#context#}}'
  3. export const HISTORY_PLACEHOLDER_TEXT = '{{#histories#}}'
  4. export const QUERY_PLACEHOLDER_TEXT = '{{#query#}}'
  5. export const PRE_PROMPT_PLACEHOLDER_TEXT = '{{#pre_prompt#}}'
  6. export const UPDATE_DATASETS_EVENT_EMITTER = 'prompt-editor-context-block-update-datasets'
  7. export const UPDATE_HISTORY_EVENT_EMITTER = 'prompt-editor-history-block-update-role'
  8. export const checkHasContextBlock = (text: string) => {
  9. if (!text)
  10. return false
  11. return text.includes(CONTEXT_PLACEHOLDER_TEXT)
  12. }
  13. export const checkHasHistoryBlock = (text: string) => {
  14. if (!text)
  15. return false
  16. return text.includes(HISTORY_PLACEHOLDER_TEXT)
  17. }
  18. export const checkHasQueryBlock = (text: string) => {
  19. if (!text)
  20. return false
  21. return text.includes(QUERY_PLACEHOLDER_TEXT)
  22. }
  23. /*
  24. * {{#1711617514996.name#}} => [1711617514996, name]
  25. * {{#1711617514996.sys.query#}} => [sys, query]
  26. */
  27. export const getInputVars = (text: string): ValueSelector[] => {
  28. if (!text)
  29. return []
  30. const allVars = text.match(/{{#([^#]*)#}}/g)
  31. if (allVars && allVars?.length > 0) {
  32. // {{#context#}}, {{#query#}} is not input vars
  33. const inputVars = allVars
  34. .filter(item => item.includes('.'))
  35. .map((item) => {
  36. const valueSelector = item.replace('{{#', '').replace('#}}', '').split('.')
  37. if (valueSelector[1] === 'sys' && /^\d+$/.test(valueSelector[0]))
  38. return valueSelector.slice(1)
  39. return valueSelector
  40. })
  41. return inputVars
  42. }
  43. return []
  44. }
  45. export const FILE_EXTS: Record<string, string[]> = {
  46. [SupportUploadFileTypes.image]: ['JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'],
  47. [SupportUploadFileTypes.document]: ['TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'],
  48. [SupportUploadFileTypes.audio]: ['MP3', 'M4A', 'WAV', 'WEBM', 'AMR', 'MPGA'],
  49. [SupportUploadFileTypes.video]: ['MP4', 'MOV', 'MPEG', 'MPGA'],
  50. }