Commit c73ec622 by 杨明

预设

1 parent 2bbb2763
import type { FC } from "react";
import { useEffect, useState, useCallback } from "react";
import { useEffect, useState, useCallback, useRef } from "react";
import { useAsyncEffect } from "ahooks";
import { useThemeContext } from "../embedded-chatbot/theme/theme-context";
import { ChatWithHistoryContext, useChatWithHistoryContext } from "./context";
import { useChatWithHistory } from "./hooks";
import Header from "./header";
import ChatWrapper from "./chat-wrapper";
import type { ChatWrapperMethods } from "./chat-wrapper";
import type { InstalledApp } from "@/models/explore";
import Loading from "@/app/components/base/loading";
import useBreakpoints, { MediaType } from "@/hooks/use-breakpoints";
......@@ -13,6 +14,7 @@ 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 {
AVATAR_USER_URL,
AVATAR_AI_URL,
......@@ -32,24 +34,39 @@ type urlProps = {
queryType?: string; //问题类型
position?: string; // 岗位
platformType?: string; // 平台类型
presuppositionProblem?: string; // 平台类型
};
// 获取地址栏参数
const getQueryParams = function (): urlProps {
const urlParams = new URLSearchParams(globalThis.location?.search);
const avatar = urlParams.get("avatar") ?? AVATAR_USER_URL;
const presuppositionProblem = urlParams.get("presuppositionProblem") ?? "";
const paramsObject = Object.fromEntries(urlParams.entries());
return {
...paramsObject,
avatar,
presuppositionProblem,
};
};
const newInputs = getQueryParams();
newInputs.queryType = "0";
const avatar: string = newInputs.avatar!;
const presuppositionProblem = newInputs.presuppositionProblem;
delete newInputs.avatar;
delete newInputs.domain;
delete newInputs.presuppositionProblem;
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 handleReset = () => {
handleNewConversation();
......@@ -71,6 +88,20 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
handleNewConversation,
handleNewConversationInputsChange,
} = useChatWithHistoryContext();
const hasSent = useRef(false); // 标记是否已发送
useEffect(() => {
//新建对话
if (!hasSent.current) {
handleNewConversation();
setTimeout(() => {
handleNewConversationInputsChange(newInputs);
setTimeout(() => {
autoSend();
}, 300);
}, 1000);
hasSent.current = true; // 标记已发送
}
}, []);
const doClear = useCallback(() => {
setShowConfirm(true);
}, [handleNewConversation]);
......@@ -111,6 +142,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({ className }) => {
)}
{!appChatListDataLoading && (
<ChatWrapper
ref={chatWrapperRef} // 传递 ref
doClear={doClear}
key={chatShouldReloadKey}
avatar={avatar}
......@@ -174,13 +206,6 @@ const ChatWithHistoryWrap: FC<ChatWithHistoryWrapProps> = ({
currentConversationInputs,
setCurrentConversationInputs,
} = useChatWithHistory(installedAppInfo);
useEffect(() => {
//新建对话
handleNewConversation();
setTimeout(() => {
handleNewConversationInputsChange(newInputs);
}, 1000);
}, []);
return (
<ChatWithHistoryContext.Provider
value={{
......
......@@ -363,7 +363,6 @@ export const useChat = (
isFirstMessage: boolean,
{ conversationId: newConversationId, messageId, taskId }: any
) => {
console.log("onData", message);
if (!isAgentMode) {
responseItem.content = responseItem.content + message;
} else {
......
/*
* @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 {
ModelConfig,
VisionSettings,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!