index.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { useContext } from 'use-context-selector'
  4. import { RiCloseLine, RiInformation2Fill } from '@remixicon/react'
  5. import DialogWrapper from '@/app/components/base/features/new-feature-panel/dialog-wrapper'
  6. import { useDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
  7. import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
  8. import type { OnFeaturesChange } from '@/app/components/base/features/types'
  9. import MoreLikeThis from '@/app/components/base/features/new-feature-panel/more-like-this'
  10. import ConversationOpener from '@/app/components/base/features/new-feature-panel/conversation-opener'
  11. import FollowUp from '@/app/components/base/features/new-feature-panel/follow-up'
  12. import SpeechToText from '@/app/components/base/features/new-feature-panel/speech-to-text'
  13. import TextToSpeech from '@/app/components/base/features/new-feature-panel/text-to-speech'
  14. import FileUpload from '@/app/components/base/features/new-feature-panel/file-upload'
  15. import Citation from '@/app/components/base/features/new-feature-panel/citation'
  16. import ImageUpload from '@/app/components/base/features/new-feature-panel/image-upload'
  17. import Moderation from '@/app/components/base/features/new-feature-panel/moderation'
  18. import AnnotationReply from '@/app/components/base/features/new-feature-panel/annotation-reply'
  19. import type { PromptVariable } from '@/models/debug'
  20. import type { InputVar } from '@/app/components/workflow/types'
  21. import I18n from '@/context/i18n'
  22. import { LanguagesSupported } from '@/i18n/language'
  23. type Props = {
  24. show: boolean
  25. isChatMode: boolean
  26. disabled: boolean
  27. onChange?: OnFeaturesChange
  28. onClose: () => void
  29. inWorkflow?: boolean
  30. showFileUpload?: boolean
  31. promptVariables?: PromptVariable[]
  32. workflowVariables?: InputVar[]
  33. onAutoAddPromptVariable?: (variable: PromptVariable[]) => void
  34. }
  35. const NewFeaturePanel = ({
  36. show,
  37. isChatMode,
  38. disabled,
  39. onChange,
  40. onClose,
  41. inWorkflow = true,
  42. showFileUpload = true,
  43. promptVariables,
  44. workflowVariables,
  45. onAutoAddPromptVariable,
  46. }: Props) => {
  47. const { t } = useTranslation()
  48. const { locale } = useContext(I18n)
  49. const { data: speech2textDefaultModel } = useDefaultModel(ModelTypeEnum.speech2text)
  50. const { data: text2speechDefaultModel } = useDefaultModel(ModelTypeEnum.tts)
  51. return (
  52. <DialogWrapper
  53. show={show}
  54. onClose={onClose}
  55. inWorkflow={inWorkflow}
  56. >
  57. <div className='grow flex flex-col h-full'>
  58. {/* header */}
  59. <div className='shrink-0 flex justify-between p-4 pb-3'>
  60. <div>
  61. <div className='text-text-primary system-xl-semibold'>{t('workflow.common.features')}</div>
  62. <div className='text-text-tertiary body-xs-regular'>{t('workflow.common.featuresDescription')}</div>
  63. </div>
  64. <div className='w-8 h-8 p-2 cursor-pointer' onClick={onClose}><RiCloseLine className='w-4 h-4 text-text-tertiary'/></div>
  65. </div>
  66. {/* list */}
  67. <div className='grow basis-0 overflow-y-auto px-4 pb-4'>
  68. {showFileUpload && (
  69. <div className='relative mb-1 p-2 rounded-xl border border-components-panel-border shadow-xs'>
  70. <div className='absolute top-0 left-0 w-full h-full rounded-xl opacity-40' style={{ background: 'linear-gradient(92deg, rgba(11, 165, 236, 0.25) 18.12%, rgba(255, 255, 255, 0.00) 167.31%)' }}></div>
  71. <div className='relative flex items-start w-full h-full'>
  72. <div className='shrink-0 mr-0.5 p-0.5'>
  73. <RiInformation2Fill className='w-5 h-5 text-text-accent' />
  74. </div>
  75. <div className='p-1 text-text-primary system-xs-medium'>
  76. <span>{isChatMode ? t('workflow.common.fileUploadTip') : t('workflow.common.ImageUploadLegacyTip')}</span>
  77. <a
  78. className='text-text-accent'
  79. href={`https://docs.dify.ai/${locale === LanguagesSupported[1] ? 'v/zh-hans/' : ''}guides/workflow/bulletin`}
  80. target='_blank' rel='noopener noreferrer'
  81. >{t('workflow.common.featuresDocLink')}</a>
  82. </div>
  83. </div>
  84. </div>
  85. )}
  86. {!isChatMode && !inWorkflow && (
  87. <MoreLikeThis disabled={disabled} onChange={onChange} />
  88. )}
  89. {isChatMode && (
  90. <ConversationOpener
  91. disabled={disabled}
  92. onChange={onChange}
  93. promptVariables={promptVariables}
  94. workflowVariables={workflowVariables}
  95. onAutoAddPromptVariable={onAutoAddPromptVariable}
  96. />
  97. )}
  98. {isChatMode && (
  99. <FollowUp disabled={disabled} onChange={onChange} />
  100. )}
  101. {text2speechDefaultModel && (isChatMode || !inWorkflow) && (
  102. <TextToSpeech disabled={disabled} onChange={onChange} />
  103. )}
  104. {isChatMode && speech2textDefaultModel && (
  105. <SpeechToText disabled={disabled} onChange={onChange} />
  106. )}
  107. {showFileUpload && isChatMode && <FileUpload disabled={disabled} onChange={onChange} />}
  108. {showFileUpload && !isChatMode && <ImageUpload disabled={disabled} onChange={onChange} />}
  109. {isChatMode && (
  110. <Citation disabled={disabled} onChange={onChange} />
  111. )}
  112. {(isChatMode || !inWorkflow) && <Moderation disabled={disabled} onChange={onChange} />}
  113. {!inWorkflow && isChatMode && (
  114. <AnnotationReply disabled={disabled} onChange={onChange} />
  115. )}
  116. </div>
  117. </div>
  118. </DialogWrapper>
  119. )
  120. }
  121. export default NewFeaturePanel