From 58fd2f7a2f78a273d418064f5734e73d81b0a2d2 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 30 Jul 2025 14:42:46 +0800 Subject: [PATCH] add chat memory action button --- .../base/chat/chat-with-history/context.tsx | 4 +++ .../chat/chat-with-history/header/index.tsx | 18 +++++++++++- .../base/chat/chat-with-history/hooks.tsx | 4 +++ .../base/chat/chat-with-history/index.tsx | 4 +++ .../assets/vender/line/others/memory.svg | 3 ++ .../icons/src/vender/line/others/Memory.json | 28 +++++++++++++++++++ .../icons/src/vender/line/others/Memory.tsx | 20 +++++++++++++ .../icons/src/vender/line/others/index.ts | 1 + web/i18n/en-US/share.ts | 1 + web/i18n/zh-Hans/share.ts | 1 + 10 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 web/app/components/base/icons/assets/vender/line/others/memory.svg create mode 100644 web/app/components/base/icons/src/vender/line/others/Memory.json create mode 100644 web/app/components/base/icons/src/vender/line/others/Memory.tsx diff --git a/web/app/components/base/chat/chat-with-history/context.tsx b/web/app/components/base/chat/chat-with-history/context.tsx index 03a0399137..5d4f9ec358 100644 --- a/web/app/components/base/chat/chat-with-history/context.tsx +++ b/web/app/components/base/chat/chat-with-history/context.tsx @@ -60,6 +60,8 @@ export type ChatWithHistoryContextValue = { name?: string avatar_url?: string } + showChatMemory?: boolean + setShowChatMemory: (state: boolean) => void } export const ChatWithHistoryContext = createContext({ @@ -95,5 +97,7 @@ export const ChatWithHistoryContext = createContext setCurrentConversationInputs: noop, allInputsHidden: false, initUserVariables: {}, + showChatMemory: false, + setShowChatMemory: noop, }) export const useChatWithHistoryContext = () => useContext(ChatWithHistoryContext) diff --git a/web/app/components/base/chat/chat-with-history/header/index.tsx b/web/app/components/base/chat/chat-with-history/header/index.tsx index b5c5bccec1..7098b17a1f 100644 --- a/web/app/components/base/chat/chat-with-history/header/index.tsx +++ b/web/app/components/base/chat/chat-with-history/header/index.tsx @@ -1,10 +1,11 @@ import { useCallback, useState } from 'react' +import { useTranslation } from 'react-i18next' import { RiEditBoxLine, RiLayoutRight2Line, RiResetLeftLine, } from '@remixicon/react' -import { useTranslation } from 'react-i18next' +import { Memory } from '@/app/components/base/icons/src/vender/line/others' import { useChatWithHistoryContext, } from '../context' @@ -34,6 +35,8 @@ const Header = () => { sidebarCollapseState, handleSidebarCollapse, isResponding, + showChatMemory, + setShowChatMemory, } = useChatWithHistoryContext() const { t } = useTranslation() const isSidebarCollapsed = sidebarCollapseState @@ -70,6 +73,10 @@ const Header = () => { handleRenameConversation(showRename.id, newName, { onSuccess: handleCancelRename }) }, [showRename, handleRenameConversation, handleCancelRename]) + const handleChatMemoryToggle = useCallback(() => { + setShowChatMemory(!showChatMemory) + }, [setShowChatMemory, showChatMemory]) + return ( <>
@@ -137,6 +144,15 @@ const Header = () => { {currentConversationId && inputsForms.length > 0 && ( )} + {currentConversationId && ( + + + + + + )}
{!!showConfirm && ( diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index 382ded3201..22668fcc2e 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -478,6 +478,8 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { notify({ type: 'success', message: t('common.api.success') }) }, [isInstalledApp, appId, t, notify]) + const [showChatMemory, setShowChatMemory] = useState(false) + return { isInstalledApp, appId, @@ -524,5 +526,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { setCurrentConversationInputs, allInputsHidden, initUserVariables, + showChatMemory, + setShowChatMemory, } } diff --git a/web/app/components/base/chat/chat-with-history/index.tsx b/web/app/components/base/chat/chat-with-history/index.tsx index cfde517a61..c96cde8d60 100644 --- a/web/app/components/base/chat/chat-with-history/index.tsx +++ b/web/app/components/base/chat/chat-with-history/index.tsx @@ -143,6 +143,8 @@ const ChatWithHistoryWrap: FC = ({ setCurrentConversationInputs, allInputsHidden, initUserVariables, + showChatMemory, + setShowChatMemory, } = useChatWithHistory(installedAppInfo) return ( @@ -186,6 +188,8 @@ const ChatWithHistoryWrap: FC = ({ setCurrentConversationInputs, allInputsHidden, initUserVariables, + showChatMemory, + setShowChatMemory, }}> diff --git a/web/app/components/base/icons/assets/vender/line/others/memory.svg b/web/app/components/base/icons/assets/vender/line/others/memory.svg new file mode 100644 index 0000000000..3a0384ba41 --- /dev/null +++ b/web/app/components/base/icons/assets/vender/line/others/memory.svg @@ -0,0 +1,3 @@ + + + diff --git a/web/app/components/base/icons/src/vender/line/others/Memory.json b/web/app/components/base/icons/src/vender/line/others/Memory.json new file mode 100644 index 0000000000..2eb169a9d5 --- /dev/null +++ b/web/app/components/base/icons/src/vender/line/others/Memory.json @@ -0,0 +1,28 @@ +{ + "icon": { + "type": "element", + "isRootNode": true, + "name": "svg", + "attributes": { + "width": "18", + "height": "18", + "viewBox": "0 0 18 18", + "fill": "none", + "xmlns": "http://www.w3.org/2000/svg" + }, + "children": [ + { + "type": "element", + "name": "path", + "attributes": { + "fill-rule": "evenodd", + "clip-rule": "evenodd", + "d": "M10.678 1.6502C11.1023 1.50885 11.5679 1.56398 11.9473 1.80108L14.2947 3.26885C14.7333 3.54295 15 4.02396 15 4.54107V5.62505L15.9001 6.30035C16.2777 6.58359 16.5 7.02807 16.5 7.50005V9.75005C16.5 10.222 16.2777 10.6665 15.9001 10.9498L15 11.6251V13.4598C14.9999 13.9767 14.7336 14.4572 14.2954 14.7313L11.9473 16.199C11.6152 16.4066 11.217 16.4748 10.8384 16.3939L10.678 16.3499L9 15.7903L7.32202 16.3499C6.89768 16.4913 6.43213 16.4362 6.05273 16.199L3.70532 14.7313C3.2672 14.4572 3.00013 13.9768 3 13.4598V11.6251L2.09985 10.9498C1.72225 10.6665 1.5 10.222 1.5 9.75005V7.50005C1.50004 7.02809 1.72231 6.5836 2.09985 6.30035L3 5.62505V4.54107C3.00005 4.02394 3.26679 3.54294 3.70532 3.26885L6.05273 1.80108C6.43204 1.56403 6.89766 1.50884 7.32202 1.6502L9 2.20977L10.678 1.6502ZM9.75 3.54058V5.68951L10.8625 6.80206C10.9863 6.76904 11.1159 6.75005 11.25 6.75005C12.0784 6.75005 12.75 7.42165 12.75 8.25005C12.75 9.07848 12.0784 9.75005 11.25 9.75005C10.4216 9.75005 9.75 9.07848 9.75 8.25005C9.75001 8.11594 9.76898 7.98631 9.802 7.8626L8.68945 6.75005C8.40829 6.46885 8.25003 6.08736 8.25 5.68951V3.54058L6.84814 3.0733L4.5 4.54107V5.62505C4.5 6.09705 4.27767 6.54146 3.90015 6.82476L3 7.50005V9.75005L3.90015 10.4253C4.27764 10.7086 4.49996 11.1531 4.5 11.6251V13.459L6.84814 14.9268L8.25 14.4588V12.3106L7.13672 11.1973C7.01316 11.2303 6.88394 11.2501 6.75 11.2501C5.92157 11.2501 5.25 10.5785 5.25 9.75005C5.25003 8.92165 5.92159 8.25005 6.75 8.25005C7.57841 8.25005 8.24997 8.92165 8.25 9.75005C8.25 9.88396 8.23019 10.0132 8.19727 10.1368L9.31055 11.2501C9.59176 11.5313 9.74996 11.9128 9.75 12.3106V14.4588L11.1519 14.9268L13.5 13.459V11.6251C13.5 11.153 13.7224 10.7086 14.0999 10.4253L15 9.75005V7.50005L14.0999 6.82476C13.7224 6.54147 13.5 6.09707 13.5 5.62505V4.54107L11.1519 3.0733L9.75 3.54058Z", + "fill": "currentColor" + }, + "children": [] + } + ] + }, + "name": "Memory" +} diff --git a/web/app/components/base/icons/src/vender/line/others/Memory.tsx b/web/app/components/base/icons/src/vender/line/others/Memory.tsx new file mode 100644 index 0000000000..26b56ecc39 --- /dev/null +++ b/web/app/components/base/icons/src/vender/line/others/Memory.tsx @@ -0,0 +1,20 @@ +// GENERATE BY script +// DON NOT EDIT IT MANUALLY + +import * as React from 'react' +import data from './Memory.json' +import IconBase from '@/app/components/base/icons/IconBase' +import type { IconData } from '@/app/components/base/icons/IconBase' + +const Icon = ( + { + ref, + ...props + }: React.SVGProps & { + ref?: React.RefObject>; + }, +) => + +Icon.displayName = 'Memory' + +export default Icon diff --git a/web/app/components/base/icons/src/vender/line/others/index.ts b/web/app/components/base/icons/src/vender/line/others/index.ts index 2322e9d9f1..3c89921497 100644 --- a/web/app/components/base/icons/src/vender/line/others/index.ts +++ b/web/app/components/base/icons/src/vender/line/others/index.ts @@ -9,5 +9,6 @@ export { default as GlobalVariable } from './GlobalVariable' export { default as Icon3Dots } from './Icon3Dots' export { default as LongArrowLeft } from './LongArrowLeft' export { default as LongArrowRight } from './LongArrowRight' +export { default as Memory } from './Memory' export { default as SearchMenu } from './SearchMenu' export { default as Tools } from './Tools' diff --git a/web/i18n/en-US/share.ts b/web/i18n/en-US/share.ts index ab589ffb76..0470a76712 100644 --- a/web/i18n/en-US/share.ts +++ b/web/i18n/en-US/share.ts @@ -36,6 +36,7 @@ const translation = { temporarySystemIssue: 'Sorry, temporary system issue.', expand: 'Expand', collapse: 'Collapse', + memory: 'Chat Memory', }, generation: { tabs: { diff --git a/web/i18n/zh-Hans/share.ts b/web/i18n/zh-Hans/share.ts index ce1270dae8..b59adb7e31 100644 --- a/web/i18n/zh-Hans/share.ts +++ b/web/i18n/zh-Hans/share.ts @@ -32,6 +32,7 @@ const translation = { temporarySystemIssue: '抱歉,临时系统问题。', expand: '展开', collapse: '折叠', + memory: '聊天记忆', }, generation: { tabs: {