Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

5.6 KB
Raw Blame
import type { ReactNode } from 'react'
import type { OnFeaturesChange } from '@/app/components/base/features/types'
import type { InputVar } from '@/app/components/workflow/types'
import type { PromptVariable } from '@/models/debug'
import { DrawerClose, DrawerTitle } from '@langgenius/dify-ui/drawer'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import { useQueryState } from 'nuqs'
import { useTranslation } from 'react-i18next'
import AnnotationReply from '@/app/components/base/features/new-feature-panel/annotation-reply'
import Citation from '@/app/components/base/features/new-feature-panel/citation'
import ConversationOpener from '@/app/components/base/features/new-feature-panel/conversation-opener'
import { FeaturePanelDrawer } from '@/app/components/base/features/new-feature-panel/feature-panel-drawer'
import FileUpload from '@/app/components/base/features/new-feature-panel/file-upload'
import { FollowUp } from '@/app/components/base/features/new-feature-panel/follow-up'
import ImageUpload from '@/app/components/base/features/new-feature-panel/image-upload'
import Moderation from '@/app/components/base/features/new-feature-panel/moderation'
import MoreLikeThis from '@/app/components/base/features/new-feature-panel/more-like-this'
import ShowThoughts from '@/app/components/base/features/new-feature-panel/show-thoughts'
import SpeechToText from '@/app/components/base/features/new-feature-panel/speech-to-text'
import TextToSpeech from '@/app/components/base/features/new-feature-panel/text-to-speech'
import {
  pricingQueryParamName,
  pricingQueryParser,
} from '@/app/components/billing/pricing/query-params'
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import { useDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useModalContext } from '@/context/modal-context'

type Props = Readonly<{
  show: boolean
  isChatMode: boolean
  disabled: boolean
  onChange?: OnFeaturesChange
  onClose: () => void
  inWorkflow?: boolean
  showFileUpload?: boolean
  showThoughtsToggle?: boolean
  showModeration?: boolean
  showAnnotationReply?: boolean
  promptVariables?: PromptVariable[]
  workflowVariables?: InputVar[]
  onAutoAddPromptVariable?: (variable: PromptVariable[]) => void
  title?: ReactNode
  description?: ReactNode
  drawerClassName?: string
}>

const NewFeaturePanel = ({
  show,
  isChatMode,
  disabled,
  onChange,
  onClose,
  inWorkflow = true,
  showFileUpload = true,
  showThoughtsToggle = false,
  showModeration = true,
  showAnnotationReply = true,
  promptVariables,
  workflowVariables,
  onAutoAddPromptVariable,
  title,
  description,
  drawerClassName,
}: Props) => {
  const [pricing] = useQueryState(pricingQueryParamName, pricingQueryParser)
  const { t } = useTranslation(['common', 'workflow'])
  const { data: speech2textDefaultModel } = useDefaultModel(ModelTypeEnum.speech2text)
  const { data: text2speechDefaultModel } = useDefaultModel(ModelTypeEnum.tts)
  const { hasBlockingModalOpen } = useModalContext()

  return (
    <FeaturePanelDrawer
      show={show && !hasBlockingModalOpen && pricing !== 'open'}
      onClose={onClose}
      inWorkflow={inWorkflow}
      className={drawerClassName}
    >
      <div className="flex h-full grow flex-col">
        {/* header */}
        <div className="flex shrink-0 justify-between p-4 pb-3">
          <div>
            <DrawerTitle className="system-xl-semibold text-text-primary">
              {title ?? t(($) => $['common.features'], { ns: 'workflow' })}
            </DrawerTitle>
            <div className="body-xs-regular text-text-tertiary">
              {description ?? t(($) => $['common.featuresDescription'], { ns: 'workflow' })}
            </div>
          </div>
          <DrawerClose
            render={
              <IconButton aria-label={t(($) => $['operation.close'], { ns: 'common' })} size="lg">
                <span aria-hidden="true" className="i-ri-close-line size-4" />
              </IconButton>
            }
          />
        </div>
        {/* list */}
        <div className="grow basis-0 overflow-y-auto px-4 pb-4">
          {!isChatMode && !inWorkflow && <MoreLikeThis disabled={disabled} onChange={onChange} />}
          {isChatMode && (
            <ConversationOpener
              disabled={disabled}
              onChange={onChange}
              promptVariables={promptVariables}
              workflowVariables={workflowVariables}
              onAutoAddPromptVariable={onAutoAddPromptVariable}
            />
          )}
          {isChatMode && <FollowUp disabled={disabled} onChange={onChange} />}
          {text2speechDefaultModel && (isChatMode || !inWorkflow) && (
            <TextToSpeech disabled={disabled} onChange={onChange} />
          )}
          {isChatMode && speech2textDefaultModel && (
            <SpeechToText disabled={disabled} onChange={onChange} />
          )}
          {showFileUpload && isChatMode && <FileUpload disabled={disabled} onChange={onChange} />}
          {showFileUpload && !isChatMode && <ImageUpload disabled={disabled} onChange={onChange} />}
          {isChatMode && <Citation disabled={disabled} onChange={onChange} />}
          {isChatMode && showThoughtsToggle && (
            <ShowThoughts disabled={disabled} onChange={onChange} />
          )}
          {showModeration && (isChatMode || !inWorkflow) && (
            <Moderation disabled={disabled} onChange={onChange} />
          )}
          {showAnnotationReply && !inWorkflow && isChatMode && (
            <AnnotationReply disabled={disabled} onChange={onChange} />
          )}
        </div>
      </div>
    </FeaturePanelDrawer>
  )
}

export default NewFeaturePanel