mirror of
https://github.com/cs-lazy-tools/ChatGPT-On-CS.git
synced 2026-08-29 02:31:00 +08:00
111111111
This commit is contained in:
@@ -9,6 +9,7 @@ import { ConfigController } from '../controllers/configController';
|
||||
import { MessageDTO, ReplyDTO, Context } from '../types';
|
||||
import { MessageService } from './messageService';
|
||||
import { LoggerService } from './loggerService';
|
||||
import { PluginDefaultRunCode } from '../constants';
|
||||
|
||||
interface PreloadedModules {
|
||||
[key: string]: any;
|
||||
@@ -92,7 +93,14 @@ export class PluginService {
|
||||
): Promise<ReplyDTO> {
|
||||
const plugin = await this.configController.getPluginConfig(plugin_id);
|
||||
if (!plugin) {
|
||||
throw new Error('Plugin not found');
|
||||
// 有可能插件被删除了,这里直接使用默认插件
|
||||
this.log.info('使用默认插件');
|
||||
const result = await this.executePluginCode(
|
||||
PluginDefaultRunCode,
|
||||
ctx,
|
||||
messages,
|
||||
);
|
||||
return result.data;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -146,6 +146,17 @@ const createWindow = async () => {
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
mainWindow.on('close', async (event) => {
|
||||
event.preventDefault(); // 阻止默认行为
|
||||
await backendServiceManager?.stop();
|
||||
BrowserWindow.getAllWindows().forEach((win) => {
|
||||
if (win !== mainWindow) {
|
||||
win.close();
|
||||
}
|
||||
});
|
||||
app.quit(); // 关闭应用
|
||||
});
|
||||
|
||||
const menuBuilder = new MenuBuilder(mainWindow);
|
||||
menuBuilder.buildMenu();
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
ModalOverlay,
|
||||
ModalContent,
|
||||
ModalHeader,
|
||||
ModalFooter,
|
||||
ModalBody,
|
||||
ModalCloseButton,
|
||||
VStack,
|
||||
Text,
|
||||
} from '@chakra-ui/react';
|
||||
|
||||
interface DisplayContextModalProps {
|
||||
data: string;
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
type ParsedData = [string, string | boolean][];
|
||||
|
||||
const DisplayContextModal: React.FC<DisplayContextModalProps> = ({
|
||||
data,
|
||||
isOpen,
|
||||
onClose,
|
||||
}) => {
|
||||
const parseData = (
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
data: string | [string, string | boolean][] | null,
|
||||
): ParsedData | null => {
|
||||
if (!data) return null;
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
return data;
|
||||
}
|
||||
try {
|
||||
const parsedData = JSON.parse(data);
|
||||
if (Array.isArray(parsedData)) {
|
||||
return parsedData;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing data:', error);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const renderContent = (parsedData: ParsedData | null, rawData: string) => {
|
||||
if (parsedData) {
|
||||
return (
|
||||
<VStack align="start">
|
||||
{parsedData.map(([key, value], index) => (
|
||||
<Text key={index}>
|
||||
<strong>{key}:</strong> {value}
|
||||
</Text>
|
||||
))}
|
||||
</VStack>
|
||||
);
|
||||
}
|
||||
return <Text>{rawData}</Text>;
|
||||
};
|
||||
|
||||
const parsedData = parseData(data);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal isOpen={isOpen} onClose={onClose}>
|
||||
<ModalOverlay />
|
||||
<ModalContent>
|
||||
<ModalHeader>详情</ModalHeader>
|
||||
<ModalCloseButton />
|
||||
<ModalBody>
|
||||
{data ? (
|
||||
renderContent(parsedData, data)
|
||||
) : (
|
||||
<Text>
|
||||
<strong>No data</strong>
|
||||
</Text>
|
||||
)}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button colorScheme="blue" mr={3} onClick={onClose}>
|
||||
Close
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default DisplayContextModal;
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { useState, useMemo, useEffect } from 'react';
|
||||
import {
|
||||
Button,
|
||||
ChakraProvider,
|
||||
Box,
|
||||
Input,
|
||||
@@ -36,6 +37,7 @@ import {
|
||||
} from '../../../common/services/platform/controller';
|
||||
import { trackPageView } from '../../../common/services/analytics';
|
||||
import MessageModal from '../MessageModal';
|
||||
import DisplayContextModal from '../DisplayContextModal';
|
||||
|
||||
const SessionHistory = () => {
|
||||
const toast = useToast();
|
||||
@@ -49,6 +51,11 @@ const SessionHistory = () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const [selectedSession, setSelectedSession] = useState<Session | null>(null);
|
||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||
const {
|
||||
isOpen: isDisplayContextOpen,
|
||||
onOpen: onDisplayContextOpen,
|
||||
onClose: onDisplayContextClose,
|
||||
} = useDisclosure();
|
||||
const [search, setSearch] = useState('');
|
||||
const [filterType, setFilterType] = useState('');
|
||||
const [currentPage, setCurrentPage] = useState(0);
|
||||
@@ -213,6 +220,8 @@ const SessionHistory = () => {
|
||||
{column.render('Header')}
|
||||
</Th>
|
||||
))}
|
||||
|
||||
<Th>操作</Th>
|
||||
</Tr>
|
||||
))}
|
||||
</Thead>
|
||||
@@ -237,6 +246,33 @@ const SessionHistory = () => {
|
||||
</Tooltip>
|
||||
</Td>
|
||||
))}
|
||||
|
||||
<Td>
|
||||
<Button
|
||||
size={'sm'}
|
||||
variant="link"
|
||||
mr={2}
|
||||
aria-label="查看消息"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleSessionClick(row.original);
|
||||
}}
|
||||
>
|
||||
查看消息
|
||||
</Button>
|
||||
<Button
|
||||
size={'sm'}
|
||||
variant="link"
|
||||
aria-label="查看上下文"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setSelectedSession(row.original);
|
||||
onDisplayContextOpen();
|
||||
}}
|
||||
>
|
||||
查看上下文
|
||||
</Button>
|
||||
</Td>
|
||||
</Tr>
|
||||
);
|
||||
})}
|
||||
@@ -273,6 +309,11 @@ const SessionHistory = () => {
|
||||
</Box>
|
||||
|
||||
<MessageModal isOpen={isOpen} onClose={onClose} messages={messages} />
|
||||
<DisplayContextModal
|
||||
isOpen={isDisplayContextOpen}
|
||||
onClose={onDisplayContextClose}
|
||||
data={selectedSession?.context || ''}
|
||||
/>
|
||||
</ChakraProvider>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user