Commit 26e9e006 by liimin

refactor(base): 重构聊天组件并优化状态管理

- 新增 useChatStore 用于全局状态管理
- 重构 ChatWrapper 组件,使用新的聊天上下文
- 更新 Answer、Operation、ChatInputArea 等组件以使用新状态
- 优化 Footer 组件,移除不必要的 useMemo
- 调整 Practice、StopResponding、TryToAsk 组件以适应新逻辑
1 parent 63bf4926
......@@ -2,14 +2,14 @@
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: limin
* @LastEditTime: 2025-07-03 18:48:32
* @LastEditTime: 2025-07-08 18:29:59
* @FilePath: \ai-assistant\app\components\base\chat\chat-with-history\chat-wrapper.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { useCallback, useEffect, useMemo, useState, FC, useRef, use } from 'react'
import Chat from '../chat'
import type { ChatConfig, ChatItem, ChatItemInTree, OnSend } from '../types'
import { useChat, useChatMethods } from '../chat/hooks'
import { useChat } from '../chat/hooks'
import { getLastAnswer, isValidGeneratedAnswer } from '../utils'
import { useChatWithHistoryContext } from './context'
import { InputVarType } from '@/app/components/workflow/types'
......@@ -24,6 +24,8 @@ import cn from '@/utils/classnames'
// import { SELF_INPUT } from "@/app/components/base/chat/constants";
import { InputMessageType } from '../types'
import { useChatWithHistory } from './hooks'
import { useChatStore } from './store'
import { ChatContextProvider } from '@/app/components/base/chat/chat/context'
enum MessageListenerType {
RESET_CHAT = 'reset_chat',
}
......@@ -45,7 +47,6 @@ type Props = {
isShowPracticeButton: boolean
}
const ChatWrapper: FC<Props> = ({ presuppositionQuestion, inputs, isShowPracticeButton }) => {
const chatRef = useRef<{ handleSend: Function }>()
const {
appParams,
currentConversationId,
......@@ -61,39 +62,109 @@ const ChatWrapper: FC<Props> = ({ presuppositionQuestion, inputs, isShowPractice
clearChatList,
setClearChatList,
} = useChatWithHistory(undefined, inputs)
const config = useMemo(() => {
const config = appParams || {}
return {
...config,
file_upload: {
...(config as any).file_upload,
fileUploadConfig: (config as any).system_parameters,
},
supportFeedback: true,
opening_statement: (config as any).opening_statement,
initial_message: (config as any).opening_statement,
} as ChatConfig
}, [appParams])
const {
chatList,
isResponding,
handleRestart,
handleStop,
sendMessage,
doRegenerate,
} = useChat(
config,
{
inputs: inputs as any,
inputsForm: [], //InputsForm,
},
appPrevChatTree,
taskId => stopChatMessageResponding('', taskId, isInstalledApp, appId),
clearChatList,
setClearChatList,
currentConversationId,
handleNewConversationCompleted,
isInstalledApp,
newConversationInputs,
appId,
handleFeedback,
)
useEffect(() => {
if (currentChatInstanceRef.current) currentChatInstanceRef.current.handleStop = handleStop
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
useEffect(() => {
if (presuppositionQuestion) {
chatRef.current?.handleSend(
{
message: presuppositionQuestion,
type: InputMessageType.SYSTEM,
},
undefined,
)
sendMessage(presuppositionQuestion)
}
}, [presuppositionQuestion])
useEffect(() => {
Object.defineProperty(globalThis, SEND_MESSAGE_KEY, {
value: (data: MessageListenerProps) => {
try {
switch (data.type) {
case MessageListenerType.RESET_CHAT:
handleNewConversation()
data.payload.message && sendMessage(data.payload.message)
break
}
} catch (error) {
console.error('send failed:', error)
}
},
writable: false,
configurable: true,
enumerable: false,
})
return () => {
if (SEND_MESSAGE_KEY in globalThis) {
delete (globalThis as IGlobalThis)[SEND_MESSAGE_KEY] // 使用 Symbol 作为 key
}
}
}, [])
return (
<div className="h-full overflow-hidden">
<Chat
ref={chatRef}
inputs={inputs}
isShowPracticeButton={isShowPracticeButton}
appParams={appParams}
clearChatList={clearChatList}
setClearChatList={setClearChatList}
currentChatInstanceRef={currentChatInstanceRef}
handleFeedback={handleFeedback}
appId={appId || ''}
isInstalledApp={isInstalledApp}
currentConversationId={currentConversationId}
appPrevChatTree={appPrevChatTree}
newConversationInputs={newConversationInputs}
newConversationInputsRef={newConversationInputsRef}
handleNewConversation={handleNewConversation}
handleNewConversationCompleted={handleNewConversationCompleted}
/>
<ChatContextProvider
config={config}
chatList={chatList}
isResponding={isResponding}
onSend={sendMessage}
onRegenerate={doRegenerate}
onRestart={handleRestart}
onStopResponding={handleStop}
onFeedback={handleFeedback}>
<Chat
// ref={chatRef}
// inputs={inputs}
isShowPracticeButton={isShowPracticeButton}
// appParams={appParams}
// clearChatList={clearChatList}
// setClearChatList={setClearChatList}
// currentChatInstanceRef={currentChatInstanceRef}
// handleFeedback={handleFeedback}
// appId={appId || ''}
// isInstalledApp={isInstalledApp}
// currentConversationId={currentConversationId}
// appPrevChatTree={appPrevChatTree}
// newConversationInputs={newConversationInputs}
// newConversationInputsRef={newConversationInputsRef}
// handleNewConversation={handleNewConversation}
// handleNewConversationCompleted={handleNewConversationCompleted}
/>
</ChatContextProvider>
</div>
)
}
......
......@@ -55,7 +55,6 @@ const avatarUrl: string = avatar ?? AVATAR_USER_URL
const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
const { appInfoError, appInfoLoading, isMobile } = useChatWithHistoryContext()
if (appInfoLoading) {
return <Loading type="app" />
} else if (appInfoError) {
......
import { create } from 'zustand'
import { InputMessageProp } from '../types'
import { FileEntity } from '../../file-uploader/types'
import { noop } from 'lodash-es'
import { ChatConfig, ChatItemInTree, Feedback } from '@/app/components/base/chat/types'
import { OnSendMessage } from '@/app/components/base/chat/chat/context'
type OnRegenerate = (chatItem: ChatItemInTree) => void
type State = {
handleNewConversation: () => void
handleSend: (query: InputMessageProp, files: FileEntity[] | undefined) => void
chatList: ChatItemInTree[],
isResponding: boolean
sendMessage:OnSendMessage
config: ChatConfig,
doRegenerate:(chatItem: ChatItemInTree)=>void
stopResponding: ()=>void
restartChat: () => void
handleFeedback: (messageId: string, feedback: Feedback) => Promise<void>,
}
type Action = {
setHandleNewConversation: (fn: () => void) => void
setHandleSend: (fn: (query: InputMessageProp, files: FileEntity[] | undefined) => void) => void
setChatList: (chatList: ChatItemInTree[]) => void
setIsResponding: (isRespongding: boolean) => void
setSendMessage: (sendMessage:OnSendMessage) => void
setConfig: (config: ChatConfig) => void
setDoRegenerate: (doRegenerate:OnRegenerate) => void
setStopResponding: (stopResponding: ()=>void) => void
setRestartChat: (restartChat: () => void) => void
setHandleFeedback: (handleFeedback: (messageId: string, feedback: Feedback) => Promise<void>) => void
}
export const useChatStore = create<State & Action>(set => ({
handleNewConversation: noop,
setHandleNewConversation: handleNewConversation => set({ handleNewConversation }),
handleSend: noop,
setHandleSend: handleSend => set({ handleSend }),
chatList: [],
setChatList: chatList => set({ chatList }),
isResponding: false,
setIsResponding: (isResponding: boolean) => set({ isResponding }),
sendMessage: () => {},
setSendMessage: (sendMessage: OnSendMessage) => set({ sendMessage }),
config: {} as ChatConfig,
setConfig: (config: ChatConfig) => set({ config }),
doRegenerate: () => {},
setDoRegenerate: (doRegenerate: OnRegenerate) => set({ doRegenerate }),
stopResponding: () => {},
setStopResponding: (stopResponding: () => void) => set({ stopResponding }),
restartChat: () => {},
setRestartChat: (restartChat:() => void) => set({ restartChat }),
handleFeedback: () => Promise.resolve(),
setHandleFeedback: (handleFeedback:(messageId: string, feedback: Feedback) => Promise<void>) => set({ handleFeedback }),
}))
......@@ -17,6 +17,7 @@ import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows
import cn from '@/utils/classnames'
import { FileList } from '@/app/components/base/file-uploader'
import { useChatContext } from '../context'
import { useChatStore } from '../../chat-with-history/store'
type AnswerProps = {
item: ChatItem
......@@ -48,6 +49,7 @@ const Answer: FC<AnswerProps> = ({
const containerRef = useRef<HTMLDivElement>(null)
const contentRef = useRef<HTMLDivElement>(null)
const { config, isResponding } = useChatContext()
// const [config,isResponding] = useChatStore(state =>[state.config,state.isResponding])
const responding = isLast && isResponding
const getContainerWidth = () => {
if (containerRef.current) setContainerWidth(containerRef.current?.clientWidth + 16)
......
......@@ -7,12 +7,14 @@ import SuggestedQuestions from './suggested-questions'
import AnswerIcon from '@/app/components/base/answer-icon'
import cn from '@/utils/classnames'
import { useChatContext } from '../context'
import { useChatStore } from '../../chat-with-history/store'
type InitQuestionsProps = {
// config: ChatConfig
answerIcon: ReactNode
chatAnswerContainerInner?: string
}
const InitQuestions: FC<InitQuestionsProps> = ({ answerIcon, chatAnswerContainerInner }) => {
// const config = useChatStore(state => state.config)
const {config} = useChatContext()
const questions = useMemo(() => {
const { suggested_questions, initial_message } = config
......
......@@ -10,6 +10,7 @@ import Log from '@/app/components/base/chat/chat/log'
import ActionButton, { ActionButtonState } from '@/app/components/base/action-button'
import NewAudioButton from '@/app/components/base/new-audio-button'
import cn from '@/utils/classnames'
import { useChatStore } from '../../chat-with-history/store'
type OperationProps = {
item: ChatItem
......@@ -25,7 +26,8 @@ type OperationProps = {
const Operation: FC<OperationProps> = ({ item, isLast, question, index, showPromptLog, maxSize, contentWidth, hasWorkflowProcess, noChatInput }) => {
const { t } = useTranslation()
const { config, onFeedback, onRegenerate } = useChatContext()
const { config, onFeedback, onSend:sendMessage,onRegenerate } = useChatContext()
// const [config,onFeedback,sendMessage,onRegenerate] = useChatStore(state => [state.config,state.handleFeedback,state.sendMessage,state.doRegenerate])
const [isShowReplyModal, setIsShowReplyModal] = useState(false)
const [showLike, setShowLike] = useState(false)
......@@ -39,10 +41,10 @@ const Operation: FC<OperationProps> = ({ item, isLast, question, index, showProm
}, [agent_thoughts, messageContent])
// 判断反馈按钮是否启用
const feedbackEnabled = useMemo(() => config?.supportFeedback && !localFeedback?.rating && onFeedback && !isOpeningStatement, [config?.supportFeedback, localFeedback?.rating, onFeedback, isOpeningStatement])
const feedbackEnabled = useMemo(() => config?.supportFeedback && !localFeedback?.rating && !isOpeningStatement, [config?.supportFeedback, localFeedback?.rating, onFeedback, isOpeningStatement])
// 判断是否已点赞
const feedbackActive = useMemo(() => config?.supportFeedback && localFeedback?.rating && onFeedback && !isOpeningStatement, [config?.supportFeedback, localFeedback?.rating, onFeedback, isOpeningStatement])
const feedbackActive = useMemo(() => config?.supportFeedback && localFeedback?.rating && !isOpeningStatement, [config?.supportFeedback, localFeedback?.rating, onFeedback, isOpeningStatement])
// 处理反馈
const handleFeedback = async (rating: 'like' | 'dislike' | null) => {
......@@ -96,8 +98,8 @@ const Operation: FC<OperationProps> = ({ item, isLast, question, index, showProm
if (!isOpeningStatement && showPromptLog) width += 28 + 8
if (!isOpeningStatement && config?.text_to_speech?.enabled) width += 26
if (!isOpeningStatement && config?.supportAnnotation && config?.annotation_reply?.enabled) width += 26
if (config?.supportFeedback && !localFeedback?.rating && onFeedback && !isOpeningStatement) width += 60 + 8
if (config?.supportFeedback && localFeedback?.rating && onFeedback && !isOpeningStatement) width += 28 + 8
if (config?.supportFeedback && !localFeedback?.rating && !isOpeningStatement) width += 60 + 8
if (config?.supportFeedback && localFeedback?.rating && !isOpeningStatement) width += 28 + 8
return width
}, [isOpeningStatement, showPromptLog, config?.text_to_speech?.enabled, config?.supportAnnotation, config?.annotation_reply?.enabled, config?.supportFeedback, localFeedback?.rating, onFeedback])
......
......@@ -2,7 +2,7 @@
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: limin
* @LastEditTime: 2025-06-26 10:32:55
* @LastEditTime: 2025-07-08 18:09:11
* @FilePath: \ai-assistant\app\components\base\chat\chat\answer\suggested-questions.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
......@@ -13,11 +13,13 @@ import { useChatContext } from '../context'
import Button from '@/app/components/base/button/next-button'
// import { AUTO_INPUT } from '@/app/components/base/chat/constants'
import { InputMessageType } from '../../types'
import { useChatStore } from '../../chat-with-history/store'
type SuggestedQuestionsProps = {
item: ChatItem
}
const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({ item }) => {
const { onSend } = useChatContext()
// const sendMessage = useChatStore(state=>state.sendMessage)
const { onSend:sendMessage } = useChatContext()
const { suggestedQuestions } = item
if (!suggestedQuestions?.length) return null
// const questionList = useMemo(() => {
......@@ -30,7 +32,7 @@ const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({ item }) => {
<Button
key={index}
text={question}
onClick={() => onSend?.({ message: question, type: InputMessageType.SYSTEM })}></Button>
onClick={() => sendMessage?.(question, InputMessageType.SYSTEM )}></Button>
))}
</div>
)
......
import { memo, FC, useEffect, ReactNode } from 'react'
import Answer from '../answer'
import Question from '../question'
import { useChatStore } from '@/app/components/base/chat/chat-with-history/store'
import { useChatContext } from '../context'
import { state } from 'mermaid/dist/rendering-util/rendering-elements/shapes/state'
type ChatBodyProps = {
answerIcon?: ReactNode
questionIcon?: ReactNode
}
const ChatBody: FC<ChatBodyProps> = ({ answerIcon, questionIcon }) => {
// const chatList = useChatStore(state=>state.chatList)
const { chatList } = useChatContext()
return (
<>
{chatList.map((item, index) => {
if (item.isAnswer) {
const isLast = item.id === chatList[chatList.length - 1]?.id
return (
<Answer
key={item.id}
item={item}
question={chatList[index - 1]?.content}
index={index}
answerIcon={answerIcon}
isLast={isLast}
/>
)
}
return <Question key={item.id} item={item} questionIcon={questionIcon} />
})}
</>
)
}
export default memo(ChatBody)
......@@ -20,6 +20,7 @@ import { TransferMethod } from '@/types/app'
import { InputMessageType } from '../../types'
import { useChatContext } from '../context'
import Confirm from '@/app/components/base/confirm'
import { useChatStore } from '../../chat-with-history/store'
type ChatInputAreaProps = {
showFeatureBar?: boolean
showFileUpload?: boolean
......@@ -45,10 +46,16 @@ const ChatInputArea = ({
// disabled,
}: ChatInputAreaProps) => {
const { t } = useTranslation()
const { onSend, onRestart, isResponding,config } = useChatContext()
// const { onSend, onRestart, isResponding } = useChatContext()
// const config= useChatStore(state => state.config)
// console.log('config', config)
const { notify } = useToastContext()
const {isResponding, onSend:sendMessage, onRestart:restartChat,config} = useChatContext()
const visionConfig = config.file_upload
const speechToTextConfig = config.speech_to_text
// const sendMessage = useChatStore(state => state.sendMessage)
// const isResponding = useChatStore(state => state.isResponding)
// const restartChat = useChatStore(state => state.restartChat)
const {
wrapperRef,
textareaRef,
......@@ -85,7 +92,7 @@ const ChatInputArea = ({
return
}
if (onSend) {
if (sendMessage) {
const { files, setFiles } = filesStore.getState()
if (files.find(item => item.transferMethod === TransferMethod.local_file && !item.uploadedId)) {
notify({
......@@ -102,7 +109,7 @@ const ChatInputArea = ({
return
}
// if (checkInputsForm(inputs, inputsForm)) {
onSend({ message: query, type: InputMessageType.SELF }, files)
sendMessage(query, InputMessageType.SELF, files)
setQuery('')
setFiles([])
// }
......@@ -170,9 +177,9 @@ const ChatInputArea = ({
setShowConfirm(true)
}, [isResponding])
const doRestart = useCallback(() => {
onRestart()
restartChat()
setShowConfirm(false)
},[])
}, [])
const operation = (
<Operation
......
......@@ -7,6 +7,7 @@ import ActionButton from '@/app/components/base/action-button'
import { FileUploaderInChatInput } from '@/app/components/base/file-uploader'
import type { FileUpload } from '@/app/components/base/features/types'
import cn from '@/utils/classnames'
import { useChatStore } from '@/app/components/base/chat/chat-with-history/store'
import {
// SELF_INPUT,
SEND_BUTTON,
......
'use client'
import type { ReactNode } from 'react'
import { useMemo, type ReactNode } from 'react'
import { createContext, useContext } from 'use-context-selector'
import { noop } from 'lodash-es'
import { ChatConfig, ChatItem, Feedback, OnRegenerate, OnSend } from '../types'
import { ChatConfig, ChatItem, Feedback, InputMessageProp, InputMessageType, OnRegenerate, OnSend } from '../types'
import { FileEntity } from '../../file-uploader/types'
export type OnSendMessage = (
message: string,
type?: InputMessageType,
files?: FileEntity[],
parentMessageId?: string,
) => void
export type ChatContextValue = {
config: ChatConfig
chatList: ChatItem[]
isResponding?: boolean
onSend: OnSend
onSend: OnSendMessage
onRegenerate?: OnRegenerate
onStopResponding?: () => void
onRestart: () => void
......@@ -21,7 +28,7 @@ const ChatContext = createContext<ChatContextValue>({
onRestart: noop,
onSend: noop,
chatList: [],
onFeedback:noop
onFeedback: noop,
})
type ChatContextProviderProps = {
......
......@@ -9,6 +9,8 @@ import ChatInputArea from '../chat-input-area'
import StopResponding from './stopResponding'
import cn from '@/utils/classnames'
import { useChatContext } from '../context'
import { useChatStore } from '@/app/components/base/chat/chat-with-history/store'
import { state } from 'mermaid/dist/rendering-util/rendering-elements/shapes/state'
type FooterProps = {
chatFooterClassName?: string
chatFooterInnerClassName?: string
......@@ -28,12 +30,13 @@ const Footer: FC<FooterProps> = ({
chatFooterRef,
chatFooterInnerRef,
}) => {
// const config = useChatStore(state=> state.config)
// const {config} = useChatContext()
// const hasTryToAsk = useMemo(
// () => config?.suggested_questions_after_answer?.enabled && !!suggestedQuestions?.length,
// [config?.suggested_questions_after_answer?.enabled, suggestedQuestions]
// )
console.log('Footer')
const { config } = useChatContext()
const hasTryToAsk = useMemo(
() => config?.suggested_questions_after_answer?.enabled && !!suggestedQuestions?.length,
[config?.suggested_questions_after_answer?.enabled, suggestedQuestions]
)
return (
<div
className={`absolute bottom-0 flex justify-center bg-chat-input-mask ${chatFooterClassName}`}
......@@ -43,7 +46,7 @@ const Footer: FC<FooterProps> = ({
{isShowPracticeButton && <Practice />}
{ <StopResponding />}
</div>
{hasTryToAsk && <TryToAsk suggestedQuestions={suggestedQuestions} isMobile={isMobile} />}
{!!suggestedQuestions?.length && <TryToAsk suggestedQuestions={suggestedQuestions} isMobile={isMobile} />}
{<ChatInputArea />}
</div>
</div>
......@@ -51,11 +54,5 @@ const Footer: FC<FooterProps> = ({
}
export default memo(Footer, (prevProps, nextProps) => {
return (
prevProps.chatFooterClassName === nextProps.chatFooterClassName &&
prevProps.chatFooterInnerClassName === nextProps.chatFooterInnerClassName &&
prevProps.isMobile === nextProps.isMobile &&
prevProps.suggestedQuestions === nextProps.suggestedQuestions &&
prevProps.isShowPracticeButton === nextProps.isShowPracticeButton
)
return true
})
......@@ -5,11 +5,12 @@ import { InputMessageType } from '@/app/components/base/chat/types'
import { Practice as PracticeIcon } from '@/app/components/base/icons/src/image/icons'
import { useChatContext } from '../context'
import { useTranslation } from 'react-i18next'
import { useChatStore } from '@/app/components/base/chat/chat-with-history/store'
const Practice: FC = () => {
const { t } = useTranslation()
const { onSend } = useChatContext()
// const sendMessage = useChatStore(state => state.sendMessage)
const { onSend: sendMessage } = useChatContext()
const question = t('appDebug.feature.practice.text')
console.log('question', question)
return (
<div>
{
......@@ -19,12 +20,7 @@ const Practice: FC = () => {
className="mb-1 w-40 h-8 pl-2
rounded-8
shadow-[0_3px_8px_0_#7D94B840]"
onClick={() =>
onSend?.({
message: question,
type: InputMessageType.SELF,
})
}>
onClick={() => sendMessage?.(question, InputMessageType.SELF)}>
<PracticeIcon className="size-4 mr-3" />
{question}
</Button>
......
......@@ -3,13 +3,17 @@ import Button from '@/app/components/base/button'
import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import { useTranslation } from 'react-i18next'
import { useChatContext } from '../context'
import { useChatStore } from '../../chat-with-history/store'
import { state } from 'mermaid/dist/rendering-util/rendering-elements/shapes/state'
const StopRespondingButton: FC = () => {
const { t } = useTranslation()
const { onStopResponding,isResponding } = useChatContext()
if(!isResponding) return null
// const isResponding = useChatStore(state => state.isResponding)
// const stopResponding = useChatStore(state => state.stopResponding)
const { isResponding, onStopResponding: stopResponding } = useChatContext()
if (!isResponding) return null
return (
<div className="absolute left-1/2 top-1/2 transform -translate-x-1/2 -translate-y-1/2">
<Button onClick={onStopResponding}>
<Button onClick={stopResponding}>
<StopCircle className="mr-[5px] h-3.5 w-3.5 text-gray-500" />
<span className="text-xs font-normal text-gray-500">{t('appDebug.operation.stopResponding')}</span>
</Button>
......
......@@ -11,37 +11,30 @@ type TryToAskProps = {
suggestedQuestions?: string[]
isMobile?: boolean
}
const TryToAsk: FC<TryToAskProps> = ({
suggestedQuestions,
isMobile,
}) => {
const TryToAsk: FC<TryToAskProps> = ({ suggestedQuestions, isMobile }) => {
const { onSend } = useChatContext()
const { t } = useTranslation()
return (
<div className='mb-2 py-2'>
<div className="mb-2 py-2">
<div className={cn('mb-2.5 flex items-center justify-between gap-2', isMobile && 'justify-end')}>
<Divider bgStyle='gradient' className='h-px grow rotate-180' />
<div className='system-xs-medium-uppercase shrink-0 text-text-tertiary'>{t('appDebug.feature.suggestedQuestionsAfterAnswer.tryToAsk')}</div>
{!isMobile && <Divider bgStyle='gradient' className='h-px grow' />}
<Divider bgStyle="gradient" className="h-px grow rotate-180" />
<div className="system-xs-medium-uppercase shrink-0 text-text-tertiary">
{t('appDebug.feature.suggestedQuestionsAfterAnswer.tryToAsk')}
</div>
{!isMobile && <Divider bgStyle="gradient" className="h-px grow" />}
</div>
<div className={cn('flex flex-wrap justify-center', isMobile && 'justify-end')}>
{
suggestedQuestions?.map((suggestQuestion, index) => (
<Button
size='small'
key={index}
variant='secondary-accent'
className='mb-1 mr-1 last:mr-0'
onClick={() => onSend({
message: suggestQuestion,
type: InputMessageType.SELF
})}
>
{suggestQuestion}
</Button>
))
}
{suggestedQuestions?.map((suggestQuestion, index) => (
<Button
size="small"
key={index}
variant="secondary-accent"
className="mb-1 mr-1 last:mr-0"
onClick={() => onSend(suggestQuestion, InputMessageType.SELF)}>
{suggestQuestion}
</Button>
))}
</div>
</div>
)
......
......@@ -85,10 +85,11 @@ export enum PracticeStatus {
Failed = '3',
}
export type OnSend = {
(message: InputMessageProp, files?: FileEntity[]): void
(message: InputMessageProp, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void
(sendProps:SendProps): void
}
export type SendProps = {messageObj?: InputMessageProp, files?: FileEntity[], parentMessageId?: string}
export type OnRegenerate = (chatItem: ChatItem) => void
export type Callback = {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!