|
|
@@ -8,7 +8,7 @@ import {
|
|
|
RightOutlined,
|
|
|
} from "@ant-design/icons";
|
|
|
import { IAiModel } from "../api/ai";
|
|
|
-import { useState } from "react";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
import { MenuProps } from "antd/es/menu";
|
|
|
import Marked from "../general/Marked";
|
|
|
import MsgContainer from "./MsgContainer";
|
|
|
@@ -18,19 +18,17 @@ const { Text } = Typography;
|
|
|
interface IWidget {
|
|
|
msg?: Message;
|
|
|
models?: IAiModel[];
|
|
|
- onSwitchMsgVersion?: (version: number) => void;
|
|
|
- onRefresh?: (modelIndex: number) => void;
|
|
|
+ onRefresh?: (modelId: string) => void;
|
|
|
}
|
|
|
|
|
|
-const MsgAssistant = ({
|
|
|
- msg,
|
|
|
- models,
|
|
|
- onRefresh,
|
|
|
- onSwitchMsgVersion,
|
|
|
-}: IWidget) => {
|
|
|
- const [currentVersion, setCurrentVersion] = useState(
|
|
|
- msg?.currentVersionIndex ?? 0
|
|
|
- );
|
|
|
+const MsgAssistant = ({ msg, models, onRefresh }: IWidget) => {
|
|
|
+ const [currentVersion, setCurrentVersion] = useState(0);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (msg) {
|
|
|
+ setCurrentVersion(msg?.versions.length - 1);
|
|
|
+ }
|
|
|
+ }, [msg]);
|
|
|
|
|
|
const switchMessageVersion = (direction: "prev" | "next"): void => {
|
|
|
if (msg && msg.versions) {
|
|
|
@@ -42,18 +40,14 @@ const MsgAssistant = ({
|
|
|
} else if (direction === "next" && currentVersion < maxIndex) {
|
|
|
newIndex = currentVersion + 1;
|
|
|
}
|
|
|
- if (onSwitchMsgVersion) {
|
|
|
- onSwitchMsgVersion(newIndex);
|
|
|
- } else {
|
|
|
- setCurrentVersion(newIndex);
|
|
|
- }
|
|
|
+ setCurrentVersion(newIndex);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const refreshMenu: MenuProps = {
|
|
|
onClick: ({ key }) => {
|
|
|
- if (key === "refresh") {
|
|
|
- onRefresh && onRefresh(0);
|
|
|
+ if (key === "refresh" && msg) {
|
|
|
+ onRefresh && onRefresh(msg.versions[currentVersion].model);
|
|
|
}
|
|
|
},
|
|
|
items: [
|
|
|
@@ -71,7 +65,7 @@ const MsgAssistant = ({
|
|
|
key: model.uid,
|
|
|
label: model.name,
|
|
|
onClick: () => {
|
|
|
- onRefresh && onRefresh(id);
|
|
|
+ onRefresh && onRefresh(model.uid);
|
|
|
},
|
|
|
})),
|
|
|
},
|
|
|
@@ -86,10 +80,13 @@ const MsgAssistant = ({
|
|
|
marginBottom: "4px",
|
|
|
}}
|
|
|
>
|
|
|
- {msg?.model ? models?.find((m) => m.uid === msg.model)?.name : "AI助手"}
|
|
|
+ {msg?.versions[currentVersion].model
|
|
|
+ ? models?.find((m) => m.uid === msg.versions[currentVersion].model)
|
|
|
+ ?.name
|
|
|
+ : "AI助手"}
|
|
|
</div>
|
|
|
<div>
|
|
|
- <Marked text={msg?.content} />
|
|
|
+ <Marked text={msg?.versions[currentVersion].content} />
|
|
|
</div>
|
|
|
<div>
|
|
|
<Space>
|
|
|
@@ -100,7 +97,7 @@ const MsgAssistant = ({
|
|
|
size="small"
|
|
|
type="text"
|
|
|
icon={<LeftOutlined />}
|
|
|
- disabled={msg.currentVersionIndex === 0}
|
|
|
+ disabled={currentVersion === 0}
|
|
|
onClick={() => switchMessageVersion("prev")}
|
|
|
/>
|
|
|
<Text
|
|
|
@@ -110,13 +107,13 @@ const MsgAssistant = ({
|
|
|
msg.type === "user" ? "rgba(255,255,255,0.7)" : "#666",
|
|
|
}}
|
|
|
>
|
|
|
- {(msg.currentVersionIndex || 0) + 1}/{msg.versions.length}
|
|
|
+ {(currentVersion || 0) + 1}/{msg.versions.length}
|
|
|
</Text>
|
|
|
<Button
|
|
|
size="small"
|
|
|
type="text"
|
|
|
icon={<RightOutlined />}
|
|
|
- disabled={msg.currentVersionIndex === msg.versions.length - 1}
|
|
|
+ disabled={currentVersion === msg.versions.length - 1}
|
|
|
onClick={() => switchMessageVersion("next")}
|
|
|
/>
|
|
|
</Space>
|
|
|
@@ -132,7 +129,7 @@ const MsgAssistant = ({
|
|
|
onClick={() => {
|
|
|
msg &&
|
|
|
navigator.clipboard
|
|
|
- .writeText(msg.content)
|
|
|
+ .writeText(msg.versions[currentVersion].content)
|
|
|
.then((value) => message.success("已复制到剪贴板"))
|
|
|
.catch((reason: any) => {
|
|
|
console.error("复制失败:", reason);
|