Commit f0e4147f by liimin

refactor(chat): 重构聊天组件的输入消息类型

- 创建 InputMessageType 枚举,替代原有的字符串类型
- 更新相关组件中的消息类型引用
- 调整部分代码逻辑以适应新的消息类型
1 parent 0cd81782
function readPackage(pkg, context) {
if (pkg.name === 'mdast-util-gfm') {
pkg.dependencies = {
...pkg.dependencies,
'mdast-util-gfm-autolink-literal': '2.0.0',
};
context.log('mdast-util-gfm -> mdast-util-gfm-autolink-literal@2.0.0');
}
return pkg;
}
module.exports = {
hooks: {
readPackage,
},
};
/*
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-07 13:51:00
* @FilePath: \glsk-ai-assistant\app\components\base\chat\chat-with-history\chat-wrapper.tsx
* @LastEditors: limin
* @LastEditTime: 2025-06-10 18:00:46
* @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 {
......@@ -33,7 +33,8 @@ import AnswerIcon from "@/app/components/base/answer-icon";
import SuggestedQuestions from "@/app/components/base/chat/chat/answer/suggested-questions";
import { Markdown } from "@/app/components/base/markdown";
import cn from "@/utils/classnames";
import { SELF_INPUT } from "@/app/components/base/chat/constants";
// import { SELF_INPUT } from "@/app/components/base/chat/constants";
import { InputMessageType } from "../types";
type Props = {
avatar: string;
aiAvatar: string;
......@@ -205,7 +206,7 @@ const ChatWrapper = forwardRef<ChatWrapperMethods, Props>(
(item) => item.id === question.parentMessageId
);
doSend(
{ message: question.content, type: SELF_INPUT },
{ message: question.content, type: InputMessageType.SELF },
question.message_files,
true,
isValidGeneratedAnswer(parentAnswer) ? parentAnswer : null
......
......@@ -420,7 +420,6 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
);
const handleNewConversation = useCallback(
(inputs?: Record<string, any>) => {
console.log(123);
currentChatInstanceRef.current.handleStop();
setShowNewConversationItemInList(true);
handleChangeConversation("");
......
......@@ -14,7 +14,8 @@ import { checkOrSetAccessToken } from "@/app/components/share/utils";
import AppUnavailable from "@/app/components/base/app-unavailable";
import Confirm from "@/app/components/base/confirm";
import cn from "@/utils/classnames";
import { SELF_INPUT } from "@/app/components/base/chat/constants";
// import { SELF_INPUT } from "@/app/components/base/chat/constants";
import { InputMessageType } from "../types";
import {
AVATAR_USER_URL,
AVATAR_AI_URL,
......@@ -60,15 +61,15 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
// 示例:调用 ChatWrapper 的方法
const autoSend = () => {
console.log(
chatWrapperRef.current,
presuppositionProblem,
"presuppositionProblem"
);
// console.log(
// chatWrapperRef.current,
// presuppositionProblem,
// "presuppositionProblem"
// );
if (chatWrapperRef.current && presuppositionProblem) {
chatWrapperRef.current.doSend({
message: presuppositionProblem,
type: SELF_INPUT,
type: InputMessageType.SELF,
});
}
};
......@@ -95,7 +96,6 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
useEffect(() => {
//新建对话
if (!hasSent.current && chatWrapperRef.current) {
console.log("newInputs", newInputs);
handleNewConversation(newInputs);
setTimeout(() => {
autoSend();
......
/*
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-02 16:46:21
* @FilePath: \glsk-ai-assistant\app\components\base\chat\chat\answer\suggested-questions.tsx
* @LastEditors: limin
* @LastEditTime: 2025-06-10 18:06:15
* @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
*/
import type { FC } from 'react'
......@@ -11,7 +11,8 @@ import { memo, useMemo } from 'react'
import type { ChatItem } from '../../types'
import { useChatContext } from '../context'
import Button from '@/app/components/base/button/next-button'
import { AUTO_INPUT } from '@/app/components/base/chat/constants'
// import { AUTO_INPUT } from '@/app/components/base/chat/constants'
import { InputMessageType } from '../../types'
type SuggestedQuestionsProps = {
item: ChatItem
}
......@@ -26,7 +27,7 @@ const SuggestedQuestions: FC<SuggestedQuestionsProps> = ({ item }) => {
return (
<div className="w-[fit-content]">
{questionList.map((question, index) => (
<Button key={index} text={question} onClick={() => onSend?.({ message: question, type: AUTO_INPUT })}></Button>
<Button key={index} text={question} onClick={() => onSend?.({ message: question, type: InputMessageType.SYSTEM })}></Button>
))}
</div>
)
......
......@@ -21,10 +21,12 @@ import FeatureBar from "@/app/components/base/features/new-feature-panel/feature
import type { FileUpload } from "@/app/components/base/features/types";
import { TransferMethod } from "@/types/app";
import {
SELF_INPUT,
// SELF_INPUT,
SEND_BUTTON,
CLEAR_BUTTON,
} from "@/app/components/base/chat/constants";
import { InputMessageType } from "../../types"
type ChatInputAreaProps = {
showFeatureBar?: boolean;
showFileUpload?: boolean;
......@@ -112,7 +114,7 @@ const ChatInputArea = ({
return;
}
// if (checkInputsForm(inputs, inputsForm)) {
onSend({ message: query, type: SELF_INPUT }, files);
onSend({ message: query, type: InputMessageType.SELF }, files);
setQuery("");
setFiles([]);
// }
......
/*
* @Author: liimin 17653212@qq.com
* @Date: 2025-04-16 18:17:38
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-14 14:02:55
* @LastEditors: limin
* @LastEditTime: 2025-06-10 18:42:49
* @FilePath: \ai-assistant\app\components\base\chat\chat\index.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
......@@ -27,6 +27,7 @@ import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAn
// import PromptLogModal from "@/app/components/base/prompt-log-modal";
import { useStore as useAppStore } from '@/app/components/app/store'
import type { AppData } from '@/models/share'
import Practice from './practice'
export type ChatProps = {
appData?: AppData
......@@ -216,6 +217,7 @@ const Chat: FC<ChatProps> = ({ appData, config, onSend, onClear, inputs, inputsF
</div>
)}
{hasTryToAsk && <TryToAsk suggestedQuestions={suggestedQuestions} onSend={onSend} isMobile={isMobile} />}
{<Practice question='AI导师 模拟对练' onSend={handleSend} />}
{!noChatInput && <ChatInputArea disabled={inputDisabled} showFeatureBar={showFeatureBar} showFileUpload={showFileUpload} featureBarDisabled={isResponding} onFeatureBarClick={onFeatureBarClick} visionConfig={config?.file_upload} speechToTextConfig={config?.speech_to_text} onSend={handleSend} onClear={onClear} inputs={inputs} inputsForm={inputsForm} theme={themeBuilder?.theme} isResponding={isResponding} />}
</div>
</div>
......
import type { FC } from 'react'
import { memo } from 'react'
import { useTranslation } from 'react-i18next'
import type { OnSend } from '../types'
import Button from '@/app/components/base/button'
import cn from '@/utils/classnames'
import { InputMessageType } from '../types'
type PracticeProps = {
question: string
onSend: OnSend
}
const Practice: FC<PracticeProps> = ({ question, onSend }) => {
return (
<div className="[margin-bottom:12px]">
<div className={cn('flex flex-wrap')}>
{
<Button
size="small"
variant="secondary-accent"
className="mb-1 mr-1 last:mr-0 [width:159px] [height:32px]
rounded-8 opacity-100 bg-white
shadow-[0_3px_8px_0_#7D94B840]"
onClick={() =>
onSend({
message: question,
type: InputMessageType.SELF,
})
}>
{question}
</Button>
}
</div>
</div>
)
}
export default memo(Practice)
......@@ -5,7 +5,7 @@ import type { OnSend } from '../types'
import Button from '@/app/components/base/button'
import Divider from '@/app/components/base/divider'
import cn from '@/utils/classnames'
import { InputMessageType } from '../types'
type TryToAskProps = {
suggestedQuestions: string[]
onSend: OnSend
......@@ -33,7 +33,10 @@ const TryToAsk: FC<TryToAskProps> = ({
key={index}
variant='secondary-accent'
className='mb-1 mr-1 last:mr-0'
onClick={() => onSend(suggestQuestion)}
onClick={() => onSend({
message: suggestQuestion,
type: InputMessageType.SELF
})}
>
{suggestQuestion}
</Button>
......
/*
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-07 13:56:34
* @FilePath: \glsk-ai-assistant\app\components\base\chat\types.ts
* @LastEditors: limin
* @LastEditTime: 2025-06-10 17:57:27
* @FilePath: \ai-assistant\app\components\base\chat\types.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import type {
......@@ -76,13 +76,17 @@ export type ChatItem = IChatItem & {
export type ChatItemInTree = {
children?: ChatItemInTree[]
} & ChatItem
export type messageProp = {
export type InputMessageProp = {
message:string
type:string
type:InputMessageType
}
export enum InputMessageType {
SELF = '0',
SYSTEM = '1'
}
export type OnSend = {
(message: messageProp, files?: FileEntity[]): void
(message: messageProp, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void
(message: InputMessageProp, files?: FileEntity[]): void
(message: InputMessageProp, files: FileEntity[] | undefined, isRegenerate: boolean, lastAnswer?: ChatItem | null): void
}
export type OnRegenerate = (chatItem: ChatItem) => void
......
......@@ -103,7 +103,7 @@ const FeatureBar = ({
</div>
</Tooltip>
)}
{!!features.suggested?.enabled && (
{!!!features.suggested?.enabled && (
<Tooltip
popupContent={t('appDebug.feature.suggestedQuestionsAfterAnswer.title')}
>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!