From 3209fdca534f98ff95834275a07647ca43ad1bb2 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Tue, 24 Sep 2024 17:08:23 +0800 Subject: [PATCH] legacy for sys.files --- .../file-upload/setting-content.tsx | 5 +- .../file-upload/setting-modal.tsx | 3 + .../new-feature-panel/image-upload/index.tsx | 114 ++++++++++++++++++ .../base/features/new-feature-panel/index.tsx | 6 +- .../_base/components/file-upload-setting.tsx | 8 +- .../nodes/start/components/var-item.tsx | 9 ++ .../components/workflow/nodes/start/panel.tsx | 1 + web/i18n/en-US/app-debug.ts | 7 ++ web/i18n/zh-Hans/app-debug.ts | 7 ++ 9 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 web/app/components/base/features/new-feature-panel/image-upload/index.tsx diff --git a/web/app/components/base/features/new-feature-panel/file-upload/setting-content.tsx b/web/app/components/base/features/new-feature-panel/file-upload/setting-content.tsx index 59d363f880..7493f795d3 100644 --- a/web/app/components/base/features/new-feature-panel/file-upload/setting-content.tsx +++ b/web/app/components/base/features/new-feature-panel/file-upload/setting-content.tsx @@ -11,10 +11,12 @@ import { SupportUploadFileTypes } from '@/app/components/workflow/types' import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants' type SettingContentProps = { + imageUpload?: boolean onClose: () => void onChange?: OnFeaturesChange } const SettingContent = ({ + imageUpload, onClose, onChange, }: SettingContentProps) => { @@ -55,12 +57,13 @@ const SettingContent = ({ return ( <>
-
{t('appDebug.feature.fileUpload.modalTitle')}
+
{!imageUpload ? t('appDebug.feature.fileUpload.modalTitle') : t('appDebug.feature.imageUpload.modalTitle')}
setTempPayload(p)} /> diff --git a/web/app/components/base/features/new-feature-panel/file-upload/setting-modal.tsx b/web/app/components/base/features/new-feature-panel/file-upload/setting-modal.tsx index f632cd0ae7..e3023099a5 100644 --- a/web/app/components/base/features/new-feature-panel/file-upload/setting-modal.tsx +++ b/web/app/components/base/features/new-feature-panel/file-upload/setting-modal.tsx @@ -14,6 +14,7 @@ type FileUploadSettingsProps = { onChange?: OnFeaturesChange disabled?: boolean children?: React.ReactNode + imageUpload?: boolean } const FileUploadSettings = ({ open, @@ -21,6 +22,7 @@ const FileUploadSettings = ({ onChange, disabled, children, + imageUpload, }: FileUploadSettingsProps) => { return (
onOpen(false)} onChange={(v) => { onChange?.(v) diff --git a/web/app/components/base/features/new-feature-panel/image-upload/index.tsx b/web/app/components/base/features/new-feature-panel/image-upload/index.tsx new file mode 100644 index 0000000000..f728520e9b --- /dev/null +++ b/web/app/components/base/features/new-feature-panel/image-upload/index.tsx @@ -0,0 +1,114 @@ +import React, { useCallback, useMemo, useState } from 'react' +import { useTranslation } from 'react-i18next' +import produce from 'immer' +import { RiEqualizer2Line, RiImage2Fill } from '@remixicon/react' +import FeatureCard from '@/app/components/base/features/new-feature-panel/feature-card' +import SettingModal from '@/app/components/base/features/new-feature-panel/file-upload/setting-modal' +import Badge from '@/app/components/base/badge' +import Button from '@/app/components/base/button' +import { useFeatures, useFeaturesStore } from '@/app/components/base/features/hooks' +import type { OnFeaturesChange } from '@/app/components/base/features/types' +import { FeatureEnum } from '@/app/components/base/features/types' + +type Props = { + disabled: boolean + onChange?: OnFeaturesChange +} + +const FileUpload = ({ + disabled, + onChange, +}: Props) => { + const { t } = useTranslation() + const file = useFeatures(s => s.features.file) + const featuresStore = useFeaturesStore() + const [modalOpen, setModalOpen] = useState(false) + const [isHovering, setIsHovering] = useState(false) + + const supportedTypes = useMemo(() => { + return file?.allowed_file_types?.join(',') || '-' + }, [file?.allowed_file_types]) + + const handleChange = useCallback((type: FeatureEnum, enabled: boolean) => { + const { + features, + setFeatures, + } = featuresStore!.getState() + + const newFeatures = produce(features, (draft) => { + draft[type] = { + ...draft[type], + enabled, + image: { enabled }, + } + }) + setFeatures(newFeatures) + if (onChange) + onChange() + }, [featuresStore, onChange]) + + return ( + + +
+ } + title={ +
+ {t('appDebug.feature.imageUpload.title')} + +
+ } + value={file?.enabled} + onChange={state => handleChange(FeatureEnum.file, state)} + onMouseEnter={() => setIsHovering(true)} + onMouseLeave={() => setIsHovering(false)} + disabled={disabled} + > + <> + {!file?.enabled && ( +
{t('appDebug.feature.imageUpload.description')}
+ )} + {file?.enabled && ( + <> + {!isHovering && !modalOpen && ( +
+
+
{t('appDebug.feature.imageUpload.supportedTypes')}
+
{supportedTypes}
+
+
+
+
{t('appDebug.feature.imageUpload.numberLimit')}
+
{file?.number_limits}
+
+
+ )} + {(isHovering || modalOpen) && ( + { + setModalOpen(v) + setIsHovering(v) + }} + onChange={onChange} + > + + + )} + + )} + + + ) +} + +export default FileUpload diff --git a/web/app/components/base/features/new-feature-panel/index.tsx b/web/app/components/base/features/new-feature-panel/index.tsx index 22a1f5a69f..519742442f 100644 --- a/web/app/components/base/features/new-feature-panel/index.tsx +++ b/web/app/components/base/features/new-feature-panel/index.tsx @@ -8,12 +8,13 @@ import type { OnFeaturesChange } from '@/app/components/base/features/types' import MoreLikeThis from '@/app/components/base/features/new-feature-panel/more-like-this' import ConversationOpener from '@/app/components/base/features/new-feature-panel/conversation-opener' -import Moderation from '@/app/components/base/features/new-feature-panel/moderation' +import FollowUp from '@/app/components/base/features/new-feature-panel/follow-up' 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 FileUpload from '@/app/components/base/features/new-feature-panel/file-upload' -import FollowUp from '@/app/components/base/features/new-feature-panel/follow-up' import Citation from '@/app/components/base/features/new-feature-panel/citation' +import ImageUpload from '@/app/components/base/features/new-feature-panel/image-upload' +import Moderation from '@/app/components/base/features/new-feature-panel/moderation' import AnnotationReply from '@/app/components/base/features/new-feature-panel/annotation-reply' import type { PromptVariable } from '@/models/debug' @@ -82,6 +83,7 @@ const NewFeaturePanel = ({ )} {showFileUpload && isChatMode && } + {showFileUpload && !isChatMode && } {isChatMode && ( )} diff --git a/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx b/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx index df7a8f21d8..e0d545c83f 100644 --- a/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx +++ b/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx @@ -17,6 +17,7 @@ type Props = { payload: UploadFileSetting isMultiple: boolean inFeaturePanel?: boolean + hideSupportFileType?: boolean onChange: (payload: UploadFileSetting) => void } @@ -24,6 +25,7 @@ const FileUploadSetting: FC = ({ payload, isMultiple, inFeaturePanel = false, + hideSupportFileType = false, onChange, }) => { const { t } = useTranslation() @@ -93,7 +95,7 @@ const FileUploadSetting: FC = ({ >
{ - [SupportUploadFileTypes.image, SupportUploadFileTypes.document, SupportUploadFileTypes.audio, SupportUploadFileTypes.video].map((type: SupportUploadFileTypes) => ( + [SupportUploadFileTypes.document, SupportUploadFileTypes.image, SupportUploadFileTypes.audio, SupportUploadFileTypes.video].map((type: SupportUploadFileTypes) => ( = ({
)} - {inFeaturePanel && ( + {inFeaturePanel && !hideSupportFileType && (
{ - [SupportUploadFileTypes.image, SupportUploadFileTypes.document, SupportUploadFileTypes.audio, SupportUploadFileTypes.video].map((type: SupportUploadFileTypes) => ( + [SupportUploadFileTypes.document, SupportUploadFileTypes.image, SupportUploadFileTypes.audio, SupportUploadFileTypes.video].map((type: SupportUploadFileTypes) => ( void rightContent?: JSX.Element varKeys?: string[] + showLegacyBadge?: boolean } const VarItem: FC = ({ @@ -28,6 +30,7 @@ const VarItem: FC = ({ onRemove = () => { }, rightContent, varKeys = [], + showLegacyBadge = false, }) => { const { t } = useTranslation() @@ -50,6 +53,12 @@ const VarItem: FC = ({ {payload.label && (<>
·
{payload.label as string}
)} + {showLegacyBadge && ( + + )}
{rightContent || (<> diff --git a/web/app/components/workflow/nodes/start/panel.tsx b/web/app/components/workflow/nodes/start/panel.tsx index 94c348b371..275cb352a2 100644 --- a/web/app/components/workflow/nodes/start/panel.tsx +++ b/web/app/components/workflow/nodes/start/panel.tsx @@ -73,6 +73,7 @@ const Panel: FC> = ({