Skip to content

Commit dc53ff4

Browse files
author
lrhh123
committed
111111111
1 parent 33a019c commit dc53ff4

File tree

4 files changed

+153
-1
lines changed

4 files changed

+153
-1
lines changed

src/main/backend/services/pluginService.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ConfigController } from '../controllers/configController';
99
import { MessageDTO, ReplyDTO, Context } from '../types';
1010
import { MessageService } from './messageService';
1111
import { LoggerService } from './loggerService';
12+
import { PluginDefaultRunCode } from '../constants';
1213

1314
interface PreloadedModules {
1415
[key: string]: any;
@@ -92,7 +93,14 @@ export class PluginService {
9293
): Promise<ReplyDTO> {
9394
const plugin = await this.configController.getPluginConfig(plugin_id);
9495
if (!plugin) {
95-
throw new Error('Plugin not found');
96+
// 有可能插件被删除了,这里直接使用默认插件
97+
this.log.info('使用默认插件');
98+
const result = await this.executePluginCode(
99+
PluginDefaultRunCode,
100+
ctx,
101+
messages,
102+
);
103+
return result.data;
96104
}
97105

98106
try {

src/main/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ const createWindow = async () => {
146146
mainWindow = null;
147147
});
148148

149+
mainWindow.on('close', async (event) => {
150+
event.preventDefault(); // 阻止默认行为
151+
await backendServiceManager?.stop();
152+
BrowserWindow.getAllWindows().forEach((win) => {
153+
if (win !== mainWindow) {
154+
win.close();
155+
}
156+
});
157+
app.quit(); // 关闭应用
158+
});
159+
149160
const menuBuilder = new MenuBuilder(mainWindow);
150161
menuBuilder.buildMenu();
151162

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React from 'react';
2+
import {
3+
Button,
4+
Modal,
5+
ModalOverlay,
6+
ModalContent,
7+
ModalHeader,
8+
ModalFooter,
9+
ModalBody,
10+
ModalCloseButton,
11+
VStack,
12+
Text,
13+
} from '@chakra-ui/react';
14+
15+
interface DisplayContextModalProps {
16+
data: string;
17+
isOpen: boolean;
18+
onClose: () => void;
19+
}
20+
21+
type ParsedData = [string, string | boolean][];
22+
23+
const DisplayContextModal: React.FC<DisplayContextModalProps> = ({
24+
data,
25+
isOpen,
26+
onClose,
27+
}) => {
28+
const parseData = (
29+
// eslint-disable-next-line @typescript-eslint/no-shadow
30+
data: string | [string, string | boolean][] | null,
31+
): ParsedData | null => {
32+
if (!data) return null;
33+
34+
if (Array.isArray(data)) {
35+
return data;
36+
}
37+
try {
38+
const parsedData = JSON.parse(data);
39+
if (Array.isArray(parsedData)) {
40+
return parsedData;
41+
}
42+
} catch (error) {
43+
console.error('Error parsing data:', error);
44+
}
45+
return null;
46+
};
47+
48+
const renderContent = (parsedData: ParsedData | null, rawData: string) => {
49+
if (parsedData) {
50+
return (
51+
<VStack align="start">
52+
{parsedData.map(([key, value], index) => (
53+
<Text key={index}>
54+
<strong>{key}:</strong> {value}
55+
</Text>
56+
))}
57+
</VStack>
58+
);
59+
}
60+
return <Text>{rawData}</Text>;
61+
};
62+
63+
const parsedData = parseData(data);
64+
65+
return (
66+
<>
67+
<Modal isOpen={isOpen} onClose={onClose}>
68+
<ModalOverlay />
69+
<ModalContent>
70+
<ModalHeader>详情</ModalHeader>
71+
<ModalCloseButton />
72+
<ModalBody>
73+
{data ? (
74+
renderContent(parsedData, data)
75+
) : (
76+
<Text>
77+
<strong>No data</strong>
78+
</Text>
79+
)}
80+
</ModalBody>
81+
<ModalFooter>
82+
<Button colorScheme="blue" mr={3} onClick={onClose}>
83+
Close
84+
</Button>
85+
</ModalFooter>
86+
</ModalContent>
87+
</Modal>
88+
</>
89+
);
90+
};
91+
92+
export default DisplayContextModal;

src/renderer/dataview-window/components/SessionHistory/index.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, useMemo, useEffect } from 'react';
22
import {
3+
Button,
34
ChakraProvider,
45
Box,
56
Input,
@@ -36,6 +37,7 @@ import {
3637
} from '../../../common/services/platform/controller';
3738
import { trackPageView } from '../../../common/services/analytics';
3839
import MessageModal from '../MessageModal';
40+
import DisplayContextModal from '../DisplayContextModal';
3941

4042
const SessionHistory = () => {
4143
const toast = useToast();
@@ -49,6 +51,11 @@ const SessionHistory = () => {
4951
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5052
const [selectedSession, setSelectedSession] = useState<Session | null>(null);
5153
const { isOpen, onOpen, onClose } = useDisclosure();
54+
const {
55+
isOpen: isDisplayContextOpen,
56+
onOpen: onDisplayContextOpen,
57+
onClose: onDisplayContextClose,
58+
} = useDisclosure();
5259
const [search, setSearch] = useState('');
5360
const [filterType, setFilterType] = useState('');
5461
const [currentPage, setCurrentPage] = useState(0);
@@ -213,6 +220,8 @@ const SessionHistory = () => {
213220
{column.render('Header')}
214221
</Th>
215222
))}
223+
224+
<Th>操作</Th>
216225
</Tr>
217226
))}
218227
</Thead>
@@ -237,6 +246,33 @@ const SessionHistory = () => {
237246
</Tooltip>
238247
</Td>
239248
))}
249+
250+
<Td>
251+
<Button
252+
size={'sm'}
253+
variant="link"
254+
mr={2}
255+
aria-label="查看消息"
256+
onClick={(e) => {
257+
e.stopPropagation();
258+
handleSessionClick(row.original);
259+
}}
260+
>
261+
查看消息
262+
</Button>
263+
<Button
264+
size={'sm'}
265+
variant="link"
266+
aria-label="查看上下文"
267+
onClick={(e) => {
268+
e.stopPropagation();
269+
setSelectedSession(row.original);
270+
onDisplayContextOpen();
271+
}}
272+
>
273+
查看上下文
274+
</Button>
275+
</Td>
240276
</Tr>
241277
);
242278
})}
@@ -273,6 +309,11 @@ const SessionHistory = () => {
273309
</Box>
274310

275311
<MessageModal isOpen={isOpen} onClose={onClose} messages={messages} />
312+
<DisplayContextModal
313+
isOpen={isDisplayContextOpen}
314+
onClose={onDisplayContextClose}
315+
data={selectedSession?.context || ''}
316+
/>
276317
</ChakraProvider>
277318
);
278319
};

0 commit comments

Comments
 (0)