Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
h5
/
glsk-ai-assistant
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c73ec622
authored
May 07, 2025
by
杨明
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
预设
1 parent
2bbb2763
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
17 deletions
app/components/base/chat/chat-with-history/chat-wrapper.tsx
app/components/base/chat/chat-with-history/index.tsx
app/components/base/chat/chat/hooks.ts
app/components/base/chat/types.ts
app/components/base/chat/chat-with-history/chat-wrapper.tsx
View file @
c73ec62
...
@@ -2,11 +2,19 @@
...
@@ -2,11 +2,19 @@
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2025-04-22 09:29:17
* @Date: 2025-04-22 09:29:17
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-0
4-28 10:51:44
* @LastEditTime: 2025-0
5-07 13:51:00
* @FilePath: \glsk-ai-assistant\app\components\base\chat\chat-with-history\chat-wrapper.tsx
* @FilePath: \glsk-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
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
*/
import { useCallback, useEffect, useMemo, useState } from "react";
import {
useCallback,
useEffect,
useMemo,
useState,
forwardRef,
useRef,
useImperativeHandle,
} from "react";
import Chat from "../chat";
import Chat from "../chat";
import type { ChatConfig, ChatItem, ChatItemInTree, OnSend } from "../types";
import type { ChatConfig, ChatItem, ChatItemInTree, OnSend } from "../types";
import { useChat } from "../chat/hooks";
import { useChat } from "../chat/hooks";
...
@@ -31,7 +39,12 @@ type Props = {
...
@@ -31,7 +39,12 @@ type Props = {
aiAvatar: string;
aiAvatar: string;
doClear?: () => void;
doClear?: () => void;
};
};
const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
// 定义组件方法的类型
export type ChatWrapperMethods = {
doSend: OnSend;
};
const ChatWrapper = forwardRef<ChatWrapperMethods, Props>(
({ avatar, aiAvatar, doClear }: Props, ref) => {
const {
const {
appParams,
appParams,
appPrevChatTree,
appPrevChatTree,
...
@@ -70,7 +83,11 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
...
@@ -70,7 +83,11 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
? currentConversationItem?.introduction
? currentConversationItem?.introduction
: (config as any).opening_statement,
: (config as any).opening_statement,
} as ChatConfig;
} as ChatConfig;
}, [appParams, currentConversationItem?.introduction, currentConversationId]);
}, [
appParams,
currentConversationItem?.introduction,
currentConversationId,
]);
const {
const {
chatList,
chatList,
setTargetMessageId,
setTargetMessageId,
...
@@ -196,7 +213,10 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
...
@@ -196,7 +213,10 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
},
},
[chatList, doSend]
[chatList, doSend]
);
);
// 使用 useImperativeHandle 暴露方法
useImperativeHandle(ref, () => ({
doSend,
}));
const messageList = useMemo(() => {
const messageList = useMemo(() => {
return chatList;
return chatList;
}, [chatList, currentConversationId]);
}, [chatList, currentConversationId]);
...
@@ -207,7 +227,9 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
...
@@ -207,7 +227,9 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
if (!inputsForms.length) return null;
if (!inputsForms.length) return null;
if (isMobile) {
if (isMobile) {
if (!currentConversationId)
if (!currentConversationId)
return <InputsForm collapsed={collapsed} setCollapsed={setCollapsed} />;
return (
<InputsForm collapsed={collapsed} setCollapsed={setCollapsed} />
);
return null;
return null;
} else {
} else {
return <InputsForm collapsed={collapsed} setCollapsed={setCollapsed} />;
return <InputsForm collapsed={collapsed} setCollapsed={setCollapsed} />;
...
@@ -325,6 +347,7 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
...
@@ -325,6 +347,7 @@ const ChatWrapper = ({ avatar, aiAvatar, doClear }: Props) => {
/>
/>
</div>
</div>
);
);
};
}
);
export default ChatWrapper;
export default ChatWrapper;
app/components/base/chat/chat-with-history/index.tsx
View file @
c73ec62
import type { FC } from "react";
import type { FC } from "react";
import { useEffect, useState, useCallback } from "react";
import { useEffect, useState, useCallback
, useRef
} from "react";
import { useAsyncEffect } from "ahooks";
import { useAsyncEffect } from "ahooks";
import { useThemeContext } from "../embedded-chatbot/theme/theme-context";
import { useThemeContext } from "../embedded-chatbot/theme/theme-context";
import { ChatWithHistoryContext, useChatWithHistoryContext } from "./context";
import { ChatWithHistoryContext, useChatWithHistoryContext } from "./context";
import { useChatWithHistory } from "./hooks";
import { useChatWithHistory } from "./hooks";
import Header from "./header";
import Header from "./header";
import ChatWrapper from "./chat-wrapper";
import ChatWrapper from "./chat-wrapper";
import type { ChatWrapperMethods } from "./chat-wrapper";
import type { InstalledApp } from "@/models/explore";
import type { InstalledApp } from "@/models/explore";
import Loading from "@/app/components/base/loading";
import Loading from "@/app/components/base/loading";
import useBreakpoints, { MediaType } from "@/hooks/use-breakpoints";
import useBreakpoints, { MediaType } from "@/hooks/use-breakpoints";
...
@@ -13,6 +14,7 @@ import { checkOrSetAccessToken } from "@/app/components/share/utils";
...
@@ -13,6 +14,7 @@ import { checkOrSetAccessToken } from "@/app/components/share/utils";
import AppUnavailable from "@/app/components/base/app-unavailable";
import AppUnavailable from "@/app/components/base/app-unavailable";
import Confirm from "@/app/components/base/confirm";
import Confirm from "@/app/components/base/confirm";
import cn from "@/utils/classnames";
import cn from "@/utils/classnames";
import { SELF_INPUT } from "@/app/components/base/chat/constants";
import {
import {
AVATAR_USER_URL,
AVATAR_USER_URL,
AVATAR_AI_URL,
AVATAR_AI_URL,
...
@@ -32,24 +34,39 @@ type urlProps = {
...
@@ -32,24 +34,39 @@ type urlProps = {
queryType?: string; //问题类型
queryType?: string; //问题类型
position?: string; // 岗位
position?: string; // 岗位
platformType?: string; // 平台类型
platformType?: string; // 平台类型
presuppositionProblem?: string; // 平台类型
};
};
// 获取地址栏参数
// 获取地址栏参数
const getQueryParams = function (): urlProps {
const getQueryParams = function (): urlProps {
const urlParams = new URLSearchParams(globalThis.location?.search);
const urlParams = new URLSearchParams(globalThis.location?.search);
const avatar = urlParams.get("avatar") ?? AVATAR_USER_URL;
const avatar = urlParams.get("avatar") ?? AVATAR_USER_URL;
const presuppositionProblem = urlParams.get("presuppositionProblem") ?? "";
const paramsObject = Object.fromEntries(urlParams.entries());
const paramsObject = Object.fromEntries(urlParams.entries());
return {
return {
...paramsObject,
...paramsObject,
avatar,
avatar,
presuppositionProblem,
};
};
};
};
const newInputs = getQueryParams();
const newInputs = getQueryParams();
newInputs.queryType = "0";
newInputs.queryType = "0";
const avatar: string = newInputs.avatar!;
const avatar: string = newInputs.avatar!;
const presuppositionProblem = newInputs.presuppositionProblem;
delete newInputs.avatar;
delete newInputs.avatar;
delete newInputs.domain;
delete newInputs.domain;
delete newInputs.presuppositionProblem;
const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
const chatWrapperRef = useRef<ChatWrapperMethods>(null);
// 示例:调用 ChatWrapper 的方法
const autoSend = () => {
if (chatWrapperRef.current && presuppositionProblem) {
chatWrapperRef.current.doSend({
message: presuppositionProblem,
type: SELF_INPUT,
});
}
};
const [showConfirm, setShowConfirm] = useState(false);
const [showConfirm, setShowConfirm] = useState(false);
const handleReset = () => {
const handleReset = () => {
handleNewConversation();
handleNewConversation();
...
@@ -71,6 +88,20 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
...
@@ -71,6 +88,20 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
handleNewConversation,
handleNewConversation,
handleNewConversationInputsChange,
handleNewConversationInputsChange,
} = useChatWithHistoryContext();
} = useChatWithHistoryContext();
const hasSent = useRef(false); // 标记是否已发送
useEffect(() => {
//新建对话
if (!hasSent.current) {
handleNewConversation();
setTimeout(() => {
handleNewConversationInputsChange(newInputs);
setTimeout(() => {
autoSend();
}, 300);
}, 1000);
hasSent.current = true; // 标记已发送
}
}, []);
const doClear = useCallback(() => {
const doClear = useCallback(() => {
setShowConfirm(true);
setShowConfirm(true);
}, [handleNewConversation]);
}, [handleNewConversation]);
...
@@ -111,6 +142,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
...
@@ -111,6 +142,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
)}
)}
{!appChatListDataLoading && (
{!appChatListDataLoading && (
<ChatWrapper
<ChatWrapper
ref={chatWrapperRef} // 传递 ref
doClear={doClear}
doClear={doClear}
key={chatShouldReloadKey}
key={chatShouldReloadKey}
avatar={avatar}
avatar={avatar}
...
@@ -174,13 +206,6 @@ const ChatWithHistoryWrap: FC<ChatWithHistoryWrapProps> = ({
...
@@ -174,13 +206,6 @@ const ChatWithHistoryWrap: FC<ChatWithHistoryWrapProps> = ({
currentConversationInputs,
currentConversationInputs,
setCurrentConversationInputs,
setCurrentConversationInputs,
} = useChatWithHistory(installedAppInfo);
} = useChatWithHistory(installedAppInfo);
useEffect(() => {
//新建对话
handleNewConversation();
setTimeout(() => {
handleNewConversationInputsChange(newInputs);
}, 1000);
}, []);
return (
return (
<ChatWithHistoryContext.Provider
<ChatWithHistoryContext.Provider
value={{
value={{
...
...
app/components/base/chat/chat/hooks.ts
View file @
c73ec62
...
@@ -363,7 +363,6 @@ export const useChat = (
...
@@ -363,7 +363,6 @@ export const useChat = (
isFirstMessage
:
boolean
,
isFirstMessage
:
boolean
,
{
conversationId
:
newConversationId
,
messageId
,
taskId
}:
any
{
conversationId
:
newConversationId
,
messageId
,
taskId
}:
any
)
=>
{
)
=>
{
console
.
log
(
"onData"
,
message
);
if
(
!
isAgentMode
)
{
if
(
!
isAgentMode
)
{
responseItem
.
content
=
responseItem
.
content
+
message
;
responseItem
.
content
=
responseItem
.
content
+
message
;
}
else
{
}
else
{
...
...
app/components/base/chat/types.ts
View file @
c73ec62
/*
* @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
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import
type
{
import
type
{
ModelConfig
,
ModelConfig
,
VisionSettings
,
VisionSettings
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment