2023-03-31 16:35:30 +08:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { useRecoilValue } from 'recoil';
|
2023-04-04 01:12:14 +08:00
|
|
|
import EndpointOptionsDialog from '../Endpoints/EndpointOptionsDialog';
|
|
|
|
|
import { Button } from '../ui/Button.tsx';
|
2023-03-31 16:35:30 +08:00
|
|
|
|
|
|
|
|
import store from '~/store';
|
|
|
|
|
|
|
|
|
|
const clipPromptPrefix = str => {
|
|
|
|
|
if (typeof str !== 'string') {
|
|
|
|
|
return null;
|
|
|
|
|
} else if (str.length > 10) {
|
|
|
|
|
return str.slice(0, 10) + '...';
|
|
|
|
|
} else {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const MessageHeader = ({ isSearchView = false }) => {
|
2023-04-04 01:12:14 +08:00
|
|
|
const [saveAsDialogShow, setSaveAsDialogShow] = useState(false);
|
2023-03-31 16:35:30 +08:00
|
|
|
const conversation = useRecoilValue(store.conversation);
|
|
|
|
|
const searchQuery = useRecoilValue(store.searchQuery);
|
|
|
|
|
const { endpoint } = conversation;
|
|
|
|
|
|
|
|
|
|
const getConversationTitle = () => {
|
|
|
|
|
if (isSearchView) return `Search: ${searchQuery}`;
|
|
|
|
|
else {
|
|
|
|
|
let _title = `${endpoint}`;
|
|
|
|
|
|
|
|
|
|
if (endpoint === 'azureOpenAI' || endpoint === 'openAI') {
|
|
|
|
|
const { chatGptLabel, model } = conversation;
|
|
|
|
|
if (model) _title += `: ${model}`;
|
|
|
|
|
if (chatGptLabel) _title += ` as ${chatGptLabel}`;
|
|
|
|
|
} else if (endpoint === 'bingAI') {
|
|
|
|
|
const { jailbreak, toneStyle } = conversation;
|
|
|
|
|
if (toneStyle) _title += `: ${toneStyle}`;
|
|
|
|
|
if (jailbreak) _title += ` as Sydney`;
|
|
|
|
|
} else if (endpoint === 'chatGPTBrowser') {
|
|
|
|
|
const { model } = conversation;
|
|
|
|
|
if (model) _title += `: ${model}`;
|
|
|
|
|
} else if (endpoint === null) {
|
|
|
|
|
null;
|
|
|
|
|
} else {
|
|
|
|
|
null;
|
|
|
|
|
}
|
|
|
|
|
return _title;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2023-04-04 01:12:14 +08:00
|
|
|
<>
|
|
|
|
|
<div
|
2023-04-04 01:23:37 +08:00
|
|
|
className="dark:text-gray-450 w-full cursor-pointer gap-1 border-b border-black/10 bg-gray-50 text-sm text-gray-500 transition-all hover:bg-gray-100 dark:border-gray-900/50 dark:bg-gray-700 dark:hover:bg-gray-600"
|
|
|
|
|
onClick={() => setSaveAsDialogShow(true)}
|
2023-04-04 01:12:14 +08:00
|
|
|
>
|
|
|
|
|
<div className="d-block flex w-full items-center justify-center p-3">{getConversationTitle()}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<EndpointOptionsDialog
|
|
|
|
|
open={saveAsDialogShow}
|
|
|
|
|
onOpenChange={setSaveAsDialogShow}
|
|
|
|
|
preset={conversation}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2023-03-31 16:35:30 +08:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MessageHeader;
|