Compare commits
458 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03c18287fc | ||
|
|
01f7faff8a | ||
|
|
c13d584010 | ||
|
|
dbf331b9b4 | ||
|
|
38c8327cbf | ||
|
|
0e5411d3ba | ||
|
|
ee653b1032 | ||
|
|
f5d3c07161 | ||
|
|
12d40713a9 | ||
|
|
151a08d0dd | ||
|
|
74567d5e17 | ||
|
|
85160c2d29 | ||
|
|
4634c88f76 | ||
|
|
2c21553059 | ||
|
|
8227e2553e | ||
|
|
c69c750144 | ||
|
|
a25c0e657b | ||
|
|
67bb1f19f0 | ||
|
|
7d7f9eaa35 | ||
|
|
92ed848d4e | ||
|
|
6bcc21c578 | ||
|
|
48d824fe6f | ||
|
|
db2b92421a | ||
|
|
632b0c17aa | ||
|
|
e61618f1b4 | ||
|
|
2fd3ebb378 | ||
|
|
56dd2d17e7 | ||
|
|
cf92752e79 | ||
|
|
3a6d49d3fc | ||
|
|
9b79051ea5 | ||
|
|
b9d97e8a35 | ||
|
|
89f1de4df4 | ||
|
|
4ca2d7f9dc | ||
|
|
75eb6680d8 | ||
|
|
53892fa5e6 | ||
|
|
3947cf07ec | ||
|
|
c0e85b6caf | ||
|
|
a090984c67 | ||
|
|
2d2a9ea299 | ||
|
|
3ccb06652d | ||
|
|
68685511e7 | ||
|
|
3791f30d8f | ||
|
|
0250ec6f2e | ||
|
|
d98f9909db | ||
|
|
3c310c61d8 | ||
|
|
8a0a109fb2 | ||
|
|
3790e82ef3 | ||
|
|
7fb6fcdeeb | ||
|
|
7ce55cf90f | ||
|
|
4a8dcb2c08 | ||
|
|
2b34150ef7 | ||
|
|
f429f6c39e | ||
|
|
dcc90cd79f | ||
|
|
702568502e | ||
|
|
db636e4b5a | ||
|
|
5c4f0e8e8e | ||
|
|
8e36d29996 | ||
|
|
02604c466d | ||
|
|
219cea0c53 | ||
|
|
08e75c39c0 | ||
|
|
647fa21e7c | ||
|
|
bdf85c68d1 | ||
|
|
a4c0224ab5 | ||
|
|
9e9c954560 | ||
|
|
262213cc8b | ||
|
|
b42da9f154 | ||
|
|
f890da0cda | ||
|
|
670d66b01d | ||
|
|
de1ad09900 | ||
|
|
40163e5c63 | ||
|
|
a8941326dc | ||
|
|
9c9f200874 | ||
|
|
aa33f0242a | ||
|
|
2fc7c4b5c7 | ||
|
|
21b532f581 | ||
|
|
1978cfc356 | ||
|
|
37ee092398 | ||
|
|
85bf4498c0 | ||
|
|
3312befe11 | ||
|
|
49d29d78da | ||
|
|
3f82a692a2 | ||
|
|
c44f3b8a3d | ||
|
|
37d172dbd9 | ||
|
|
8aba2f58c5 | ||
|
|
2db5b3d72f | ||
|
|
9afc6989af | ||
|
|
4a06c86412 | ||
|
|
602a6a5f66 | ||
|
|
d714a53dc6 | ||
|
|
a8451b7c3d | ||
|
|
a0351fb5ad | ||
|
|
f29eeeac9e | ||
|
|
371d38a9ee | ||
|
|
ebef970078 | ||
|
|
2d8d478e2c | ||
|
|
3ba16118b4 | ||
|
|
94e0559dd3 | ||
|
|
0fdb2ed0ef | ||
|
|
2cf67b59d2 | ||
|
|
910bd30b24 | ||
|
|
754693f403 | ||
|
|
e066db763a | ||
|
|
219dc2c8bf | ||
|
|
a4b5ef9bde | ||
|
|
e5664048d9 | ||
|
|
f24177d5c4 | ||
|
|
48f66e785b | ||
|
|
bdb6e30c92 | ||
|
|
062baad682 | ||
|
|
40182befe9 | ||
|
|
026f88d1b3 | ||
|
|
32749d65a4 | ||
|
|
46c7d35bb8 | ||
|
|
c6f036cba5 | ||
|
|
e656db779e | ||
|
|
fa32cd13cf | ||
|
|
a1ae55b29d | ||
|
|
05b3810d4a | ||
|
|
c95c7faa5f | ||
|
|
ed23e9395c | ||
|
|
1738a74e8c | ||
|
|
70eb0a9187 | ||
|
|
a25f4e90dd | ||
|
|
3d701b98aa | ||
|
|
dcaac54c75 | ||
|
|
b2b89a1339 | ||
|
|
4692f98770 | ||
|
|
86a3a108a7 | ||
|
|
5ec4403bfb | ||
|
|
ec0be1ff27 | ||
|
|
516315ac45 | ||
|
|
ff55739376 | ||
|
|
1e24b7bc45 | ||
|
|
dd92dca34b | ||
|
|
a592fdc550 | ||
|
|
846e7ca097 | ||
|
|
93c2a94658 | ||
|
|
309b66e4df | ||
|
|
4d9476e99b | ||
|
|
46f796a74c | ||
|
|
00bf28b999 | ||
|
|
640d3783a0 | ||
|
|
0e4f06e86a | ||
|
|
886a7ec1e9 | ||
|
|
37cf7427f9 | ||
|
|
e69d0c89a6 | ||
|
|
581e2fb786 | ||
|
|
13b465fe73 | ||
|
|
a12d10f4f7 | ||
|
|
e8bfb2b49b | ||
|
|
ae995182b2 | ||
|
|
59c69e065c | ||
|
|
4ca2d61ccc | ||
|
|
d62ff69351 | ||
|
|
012e79a7e2 | ||
|
|
97dc80a07f | ||
|
|
b974f8537f | ||
|
|
c32e17968e | ||
|
|
cf09d1d44d | ||
|
|
ad39d8774d | ||
|
|
687f140a5c | ||
|
|
1b09bb47bf | ||
|
|
808b457503 | ||
|
|
92e054569c | ||
|
|
2f22e68559 | ||
|
|
53a8628fab | ||
|
|
df04503674 | ||
|
|
1fe74fa753 | ||
|
|
55a9be2fa5 | ||
|
|
fdf4821d56 | ||
|
|
84e6caa846 | ||
|
|
3bc8dfdf8c | ||
|
|
ed96940e82 | ||
|
|
1c60375d71 | ||
|
|
c9699609ed | ||
|
|
f91caff7ec | ||
|
|
11bd55701c | ||
|
|
efa9c6c546 | ||
|
|
92ab67eb3d | ||
|
|
ae11490f87 | ||
|
|
956c2f683d | ||
|
|
d01f793558 | ||
|
|
94d9b79957 | ||
|
|
78a7b2759e | ||
|
|
27c0edfb79 | ||
|
|
59b1d8bcc4 | ||
|
|
741d84b4d3 | ||
|
|
5bacf048f2 | ||
|
|
1d4916c516 | ||
|
|
8e1207c2a2 | ||
|
|
ac92f1a783 | ||
|
|
28c59ea436 | ||
|
|
9e808208ab | ||
|
|
feefaaf3e3 | ||
|
|
31078b8ec5 | ||
|
|
f3f32cc591 | ||
|
|
f489b034b5 | ||
|
|
3d9d5b6263 | ||
|
|
89440c9c10 | ||
|
|
4c0f358323 | ||
|
|
ad01fc43e5 | ||
|
|
9b17416f9c | ||
|
|
cda4edfb7f | ||
|
|
acc803aa43 | ||
|
|
2ab8f325df | ||
|
|
a68cbe4438 | ||
|
|
646d0e4ccb | ||
|
|
a7a82be083 | ||
|
|
c0117c25ac | ||
|
|
d51da99b8f | ||
|
|
d4848faa5a | ||
|
|
bfeca0b383 | ||
|
|
79c7c3dc1c | ||
|
|
b2ebbc1e30 | ||
|
|
50e2dd0ec0 | ||
|
|
5e753de71c | ||
|
|
6bc6dab879 | ||
|
|
7d794d33dd | ||
|
|
aab318e8ca | ||
|
|
6554a3817b | ||
|
|
7d76db40e8 | ||
|
|
186c82e355 | ||
|
|
67311f1cbe | ||
|
|
62d969335e | ||
|
|
c6eb77ab8b | ||
|
|
7e17987fa3 | ||
|
|
4bc69b7c5e | ||
|
|
e08029a6f5 | ||
|
|
93d68102d6 | ||
|
|
f448d8a8db | ||
|
|
a047048f69 | ||
|
|
aec14567ee | ||
|
|
bad89e3d28 | ||
|
|
408f2b16ad | ||
|
|
d6b87ece23 | ||
|
|
91104e288c | ||
|
|
aeeded2aa1 | ||
|
|
b10198de1f | ||
|
|
0789ccedbb | ||
|
|
0a5401174b | ||
|
|
69513cc76e | ||
|
|
5a471125db | ||
|
|
06b2ca9149 | ||
|
|
26dd931f70 | ||
|
|
68df5cd211 | ||
|
|
c7071a98f0 | ||
|
|
ff14dcc559 | ||
|
|
bb02ca83dc | ||
|
|
4d9e842381 | ||
|
|
0165bcdce3 | ||
|
|
f015c78060 | ||
|
|
c233ba0a1c | ||
|
|
88dd75827a | ||
|
|
2ab63f2e4c | ||
|
|
91bf356c73 | ||
|
|
28c0748001 | ||
|
|
3108a1c0b3 | ||
|
|
6cfa7d0eb6 | ||
|
|
da6c80ebc2 | ||
|
|
af1a9868db | ||
|
|
f87ba144c8 | ||
|
|
8d61cbcae9 | ||
|
|
c61dde5085 | ||
|
|
3015e90925 | ||
|
|
b3629e83f2 | ||
|
|
cef9312e7e | ||
|
|
802622646a | ||
|
|
ce70c7239c | ||
|
|
c354537f30 | ||
|
|
fb6b0b0c97 | ||
|
|
fc59144b1d | ||
|
|
cacd0a1387 | ||
|
|
af9763d142 | ||
|
|
b9402a8370 | ||
|
|
97a08f00a3 | ||
|
|
4e20bd1ef8 | ||
|
|
5c2d936688 | ||
|
|
6b34aac263 | ||
|
|
f59f6ade69 | ||
|
|
50478c600f | ||
|
|
bba5cac246 | ||
|
|
b9b31aed52 | ||
|
|
40203fb721 | ||
|
|
b83343a8b9 | ||
|
|
7677850547 | ||
|
|
d0e233f1b3 | ||
|
|
903d0043ba | ||
|
|
811815d69d | ||
|
|
d5b9c35f0a | ||
|
|
83c8f06b81 | ||
|
|
acb2ea30fb | ||
|
|
55317b5608 | ||
|
|
b42a5c5e63 | ||
|
|
cc76fe19f9 | ||
|
|
cf2d7ba8b4 | ||
|
|
1c163c55b8 | ||
|
|
69bb661b5a | ||
|
|
f062c56de4 | ||
|
|
4c9bd02f8e | ||
|
|
241cb0c0d8 | ||
|
|
6a57973864 | ||
|
|
369f629206 | ||
|
|
09a8f83650 | ||
|
|
40912eaaf4 | ||
|
|
0d236a94ab | ||
|
|
3a936e0f26 | ||
|
|
81a35d129d | ||
|
|
e2d0c3bbce | ||
|
|
12c9d810a2 | ||
|
|
b18b161094 | ||
|
|
32da853f27 | ||
|
|
bf51a0b5c6 | ||
|
|
ae71a7be9e | ||
|
|
0fb6795833 | ||
|
|
dd6d228760 | ||
|
|
8c5999dc82 | ||
|
|
31b0fbf775 | ||
|
|
39fe583030 | ||
|
|
5c19695e21 | ||
|
|
6e4610e337 | ||
|
|
eb2439b90c | ||
|
|
a4a0980cd3 | ||
|
|
7d99765589 | ||
|
|
5f6cf1bd66 | ||
|
|
02930a2793 | ||
|
|
b31b1c7908 | ||
|
|
d0ee764732 | ||
|
|
01cd10b364 | ||
|
|
29ba156b9a | ||
|
|
e541c7b429 | ||
|
|
5f4142f0c4 | ||
|
|
95bbc70c93 | ||
|
|
4add56ae6a | ||
|
|
16f87537a2 | ||
|
|
7f05626a8f | ||
|
|
2094e2201a | ||
|
|
e0fcdf43c5 | ||
|
|
affc866c17 | ||
|
|
799267049f | ||
|
|
cb8d47a17b | ||
|
|
c494288f7b | ||
|
|
2c3f89dbde | ||
|
|
4721a660fa | ||
|
|
6aaa3def0d | ||
|
|
045708d9b3 | ||
|
|
9ffe92d378 | ||
|
|
7159481217 | ||
|
|
d07e136037 | ||
|
|
b38a9c954a | ||
|
|
7139d5093a | ||
|
|
9e283d6930 | ||
|
|
c9a4e12765 | ||
|
|
7bd644451b | ||
|
|
5a00bdcbc6 | ||
|
|
3c958c3d11 | ||
|
|
1d5ace0fb2 | ||
|
|
f8fce871da | ||
|
|
de76d3fedc | ||
|
|
b2c6662192 | ||
|
|
bf8a7c01b0 | ||
|
|
fb8ed35b59 | ||
|
|
7c4d81c108 | ||
|
|
7199f73e06 | ||
|
|
869e56b53c | ||
|
|
f99851fb6b | ||
|
|
c94450db44 | ||
|
|
195ef92acc | ||
|
|
a67370426b | ||
|
|
9d35205681 | ||
|
|
98087e50db | ||
|
|
bedac4f59d | ||
|
|
aba3874797 | ||
|
|
3383280726 | ||
|
|
0c13e708b9 | ||
|
|
bc77c423b3 | ||
|
|
4821756301 | ||
|
|
78290ca70e | ||
|
|
7feeb07624 | ||
|
|
93e28ed916 | ||
|
|
b4aaf052fe | ||
|
|
b37e0389fc | ||
|
|
e1ebe069a5 | ||
|
|
d73912ee3b | ||
|
|
f81c7c7a6c | ||
|
|
5a7bcd5997 | ||
|
|
09a347cae4 | ||
|
|
266f909045 | ||
|
|
bad2f15c1f | ||
|
|
e3115d00bf | ||
|
|
0c0ccf3d11 | ||
|
|
2076e6f998 | ||
|
|
b49d80b78d | ||
|
|
ab5e830ed1 | ||
|
|
e0eca97053 | ||
|
|
d175212d9a | ||
|
|
642ce160a1 | ||
|
|
574d02a8c9 | ||
|
|
7764507d74 | ||
|
|
fa8bf61532 | ||
|
|
30e8cef9cc | ||
|
|
1a2861e81a | ||
|
|
653e5d82ed | ||
|
|
5be0e0ae72 | ||
|
|
b92b46f2b0 | ||
|
|
23686d4926 | ||
|
|
b340b40bcf | ||
|
|
253fc6f4e1 | ||
|
|
99aa0d3255 | ||
|
|
23a2a6b57c | ||
|
|
a869857fc1 | ||
|
|
4ecedcb267 | ||
|
|
cbd6a30e14 | ||
|
|
5f2cddee09 | ||
|
|
c0e0e924f7 | ||
|
|
b6ad7eeb9a | ||
|
|
9cf74317a6 | ||
|
|
82fcc2292e | ||
|
|
4eb0c25682 | ||
|
|
9e128d2524 | ||
|
|
1473cb3123 | ||
|
|
2c5fe01fbf | ||
|
|
d574a09529 | ||
|
|
f20bccfd7d | ||
|
|
5dcc892f31 | ||
|
|
26e3871688 | ||
|
|
9a6aad35b0 | ||
|
|
16feb49e9e | ||
|
|
30959e2380 | ||
|
|
2c17f75f4f | ||
|
|
2d1a930bfe | ||
|
|
320d27059f | ||
|
|
31014aa8a6 | ||
|
|
b468ecfce7 | ||
|
|
c53d63f7af | ||
|
|
dabff0a847 | ||
|
|
26a5ae0086 | ||
|
|
88e0d293a2 | ||
|
|
0c97b52c53 | ||
|
|
2449a22c69 | ||
|
|
028f9d88d9 | ||
|
|
a07c6cdffb | ||
|
|
5a647b0d61 | ||
|
|
007e6419ba | ||
|
|
caa473639c | ||
|
|
b6825a6ea2 | ||
|
|
710180997f | ||
|
|
fd4334f331 | ||
|
|
80dedc149a | ||
|
|
8eacaa281a | ||
|
|
6e75140939 | ||
|
|
5a3a97135f | ||
|
|
44d42d64ef | ||
|
|
fad3f67678 | ||
|
|
65b30b3b0d | ||
|
|
0278228a84 | ||
|
|
bb0cb1cecc | ||
|
|
f5cd6ecb50 | ||
|
|
76c0ad9985 |
@@ -16,6 +16,7 @@ module.exports = {
|
||||
'react/prop-types': 'off',
|
||||
'simple-import-sort/imports': 'error',
|
||||
'simple-import-sort/exports': 'error',
|
||||
'react/no-is-mounted': 'off'
|
||||
'react/no-is-mounted': 'off',
|
||||
'prettier/prettier': ['error', { endOfLine: 'auto' }]
|
||||
}
|
||||
}
|
||||
|
||||
17
.github/ISSUE_TEMPLATE/#0_bug_report.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: 🐛 错误报告
|
||||
name: 🐛 错误报告 (中文)
|
||||
description: 创建一个报告以帮助我们改进
|
||||
title: '[错误]: '
|
||||
labels: ['bug']
|
||||
@@ -7,17 +7,20 @@ body:
|
||||
attributes:
|
||||
value: |
|
||||
感谢您花时间填写此错误报告!
|
||||
在提交此问题之前,请确保您已经了解了[常见问题](https://docs.cherry-ai.com/question-contact/questions)和[知识科普](https://docs.cherry-ai.com/question-contact/knowledge)
|
||||
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
attributes:
|
||||
label: Issue 检查清单
|
||||
label: 提交前检查
|
||||
description: |
|
||||
在提交 Issue 前请确保您已经完成了以下所有步骤
|
||||
options:
|
||||
- label: 我已经查看了置顶 Issue 并搜索了现有的 Issue,但没有找到类似的问题。
|
||||
- label: 我理解 Issue 是用于反馈和解决问题的,而非吐槽评论区,将尽可能提供更多信息帮助问题解决。
|
||||
required: true
|
||||
- label: 正确填写了 Issue 标题。
|
||||
- label: 我已经查看了置顶 Issue 并搜索了现有的 [开放Issue](https://github.com/CherryHQ/cherry-studio/issues)和[已关闭Issue](https://github.com/CherryHQ/cherry-studio/issues?q=is%3Aissue%20state%3Aclosed%20),没有找到类似的问题。
|
||||
required: true
|
||||
- label: 我填写了简短且清晰明确的标题,以便开发者在翻阅 Issue 列表时能快速确定大致问题。而不是“一个建议”、“卡住了”等。
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
@@ -45,7 +48,7 @@ body:
|
||||
id: description
|
||||
attributes:
|
||||
label: 错误描述
|
||||
description: 清晰简洁地描述错误是什么
|
||||
description: 描述问题时请尽可能详细
|
||||
placeholder: 告诉我们发生了什么...
|
||||
validations:
|
||||
required: true
|
||||
@@ -54,7 +57,7 @@ body:
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: 重现步骤
|
||||
description: 重现行为的步骤
|
||||
description: 提供详细的重现步骤,以便于我们可以准确地重现问题
|
||||
placeholder: |
|
||||
1. 转到 '...'
|
||||
2. 点击 '....'
|
||||
@@ -82,4 +85,4 @@ body:
|
||||
id: additional
|
||||
attributes:
|
||||
label: 附加信息
|
||||
description: 在此添加有关问题的任何其他上下文
|
||||
description: 任何能让我们对你所遇到的问题有更多了解的东西
|
||||
|
||||
36
.github/ISSUE_TEMPLATE/#1_feature_request.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: 💡 功能建议
|
||||
name: 💡 功能建议 (中文)
|
||||
description: 为项目提出新的想法
|
||||
title: '[功能]: '
|
||||
labels: ['enhancement']
|
||||
@@ -7,23 +7,49 @@ body:
|
||||
attributes:
|
||||
value: |
|
||||
感谢您花时间提出新的功能建议!
|
||||
在提交此问题之前,请确保您已经了解了[项目规划](https://docs.cherry-ai.com/cherrystudio/planning)和[功能介绍](https://docs.cherry-ai.com/cherrystudio/preview)
|
||||
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
attributes:
|
||||
label: Issue 检查清单
|
||||
label: 提交前检查
|
||||
description: |
|
||||
在提交 Issue 前请确保您已经完成了以下所有步骤
|
||||
options:
|
||||
- label: 我已经查看了置顶 Issue 并搜索了现有的 Issue,但没有找到类似的问题。
|
||||
- label: 我理解 Issue 是用于反馈和解决问题的,而非吐槽评论区,将尽可能提供更多信息帮助问题解决。
|
||||
required: true
|
||||
- label: 正确填写了 Issue 标题。
|
||||
- label: 我已经查看了置顶 Issue 并搜索了现有的 [开放Issue](https://github.com/CherryHQ/cherry-studio/issues)和[已关闭Issue](https://github.com/CherryHQ/cherry-studio/issues?q=is%3Aissue%20state%3Aclosed%20),没有找到类似的建议。
|
||||
required: true
|
||||
- label: 我填写了简短且清晰明确的标题,以便开发者在翻阅 Issue 列表时能快速确定大致问题。而不是“一个建议”、“卡住了”等。
|
||||
required: true
|
||||
- label: 最新的 Cherry Studio 版本没有实现我所提出的功能。
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: platform
|
||||
attributes:
|
||||
label: 平台
|
||||
description: 您正在使用哪个平台?
|
||||
options:
|
||||
- Windows
|
||||
- macOS
|
||||
- Linux
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: 版本
|
||||
description: 您正在运行的 Cherry Studio 版本是什么?
|
||||
placeholder: 例如 v1.0.0
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: problem
|
||||
attributes:
|
||||
label: 您的功能建议是否与某个问题相关?
|
||||
label: 您的功能建议是否与某个问题/issue相关?
|
||||
description: 请简明扼要地描述您遇到的问题
|
||||
placeholder: 我总是感到沮丧,因为...
|
||||
validations:
|
||||
|
||||
31
.github/ISSUE_TEMPLATE/#2_question.yml
vendored
@@ -1,6 +1,6 @@
|
||||
name: ❓ 提问
|
||||
description: 提出一个问题或寻求帮助
|
||||
title: '[问题]: '
|
||||
name: ❓ 讨论 & 提问 (中文)
|
||||
description: 寻求帮助、讨论问题、提出疑问等...
|
||||
title: '[讨论]: '
|
||||
labels: ['question']
|
||||
body:
|
||||
- type: markdown
|
||||
@@ -15,9 +15,30 @@ body:
|
||||
description: |
|
||||
在提交 Issue 前请确保您已经完成了以下所有步骤
|
||||
options:
|
||||
- label: 我已经查看了置顶 Issue 并搜索了现有的 Issue,但没有找到类似的问题。
|
||||
- label: 我理解 Issue 是用于反馈和解决问题的,而非吐槽评论区,将尽可能提供更多信息帮助问题解决。
|
||||
required: true
|
||||
- label: 正确填写了 Issue 标题。
|
||||
- label: 我确认自己需要的是提出问题并且讨论问题,而不是 Bug 反馈或需求建议。
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: platform
|
||||
attributes:
|
||||
label: 平台
|
||||
description: 您正在使用哪个平台?
|
||||
options:
|
||||
- Windows
|
||||
- macOS
|
||||
- Linux
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: 版本
|
||||
description: 您正在运行的 Cherry Studio 版本是什么?
|
||||
placeholder: 例如 v1.0.0
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
|
||||
21
.github/ISSUE_TEMPLATE/0_bug_report.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: 🐛 Bug Report
|
||||
name: 🐛 Bug Report (English)
|
||||
description: Create a report to help us improve
|
||||
title: '[Bug]: '
|
||||
labels: ['bug']
|
||||
@@ -6,7 +6,8 @@ body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report!
|
||||
Thank you for taking the time to fill out this bug report!
|
||||
Before submitting this issue, please make sure that you have understood the [FAQ](https://docs.cherry-ai.com/question-contact/questions) and [Knowledge Science](https://docs.cherry-ai.com/question-contact/knowledge)
|
||||
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
@@ -15,9 +16,11 @@ body:
|
||||
description: |
|
||||
Before submitting an issue, please make sure you have completed the following steps
|
||||
options:
|
||||
- label: I have viewed the pinned issues and searched existing issues but couldn't find anything similar.
|
||||
- label: I understand that issues are for feedback and problem solving, not for complaining in the comment section, and will provide as much information as possible to help solve the problem.
|
||||
required: true
|
||||
- label: I have filled out the issue title correctly.
|
||||
- label: I've looked at pinned issues and searched for existing [Open Issues](https://github.com/CherryHQ/cherry-studio/issues), [Closed Issues](https://github.com/CherryHQ/cherry-studio/issues?q=is%3Aissue%20state%3Aclosed), and [Discussions](https://github.com/CherryHQ/cherry-studio/discussions), no similar issue or discussion was found.
|
||||
required: true
|
||||
- label: I've filled in short, clear headings so that developers can quickly identify a rough idea of what to expect when flipping through the list of issues. And not "a suggestion", "stuck", etc.
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
@@ -45,8 +48,8 @@ body:
|
||||
id: description
|
||||
attributes:
|
||||
label: Bug Description
|
||||
description: A clear and concise description of what the bug is
|
||||
placeholder: Tell us what happened...
|
||||
description: Please be as detailed as possible when describing the problem. Please provide screenshots or screen recordings whenever possible to help us better understand the issue.
|
||||
placeholder: Tell us what happened... (Remember to attach screenshots/recordings if applicable)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@@ -54,12 +57,14 @@ body:
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: Steps To Reproduce
|
||||
description: Steps to reproduce the behavior
|
||||
description: Provide detailed steps to reproduce the issue so that our developers can reproduce the issue accurately. Please include screenshots or screen recordings for each step when possible.
|
||||
placeholder: |
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
Remember to attach screenshots/recordings for each step when possible!
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@@ -82,4 +87,4 @@ body:
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional Context
|
||||
description: Add any other context about the problem here
|
||||
description: Anything that gives us a better understanding of the problem you're experiencing
|
||||
|
||||
52
.github/ISSUE_TEMPLATE/1_feature_request.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: 💡 Feature Request
|
||||
name: 💡 Feature Request (English)
|
||||
description: Suggest an idea for this project
|
||||
title: '[Feature]: '
|
||||
labels: ['enhancement']
|
||||
@@ -6,7 +6,8 @@ body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to suggest a new feature!
|
||||
Thank you for taking the time to submit a feature request!
|
||||
Before submitting this issue, please make sure you have reviewed the [Project Roadmap](https://docs.cherry-ai.com/cherrystudio/planning) and the [Feature Overview](https://docs.cherry-ai.com/cherrystudio/preview).
|
||||
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
@@ -15,36 +16,61 @@ body:
|
||||
description: |
|
||||
Before submitting an issue, please make sure you have completed the following steps
|
||||
options:
|
||||
- label: I have viewed the pinned issues and searched existing issues but couldn't find anything similar.
|
||||
- label: I understand that issues are for reporting problems and requesting features, not for off-topic comments, and I will provide as much detail as possible to help resolve the issue.
|
||||
required: true
|
||||
- label: I have filled out the issue title correctly.
|
||||
- label: I have checked the pinned issues and searched through the existing [open issues](https://github.com/CherryHQ/cherry-studio/issues), [closed issues](https://github.com/CherryHQ/cherry-studio/issues?q=is%3Aissue%20state%3Aclosed), and [discussions](https://github.com/CherryHQ/cherry-studio/discussions) and did not find a similar suggestion.
|
||||
required: true
|
||||
- label: I have provided a short and descriptive title so that developers can quickly understand the issue when browsing the issue list, rather than vague titles like "A suggestion" or "Stuck."
|
||||
required: true
|
||||
- label: The latest version of Cherry Studio does not include the feature I am suggesting.
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: platform
|
||||
attributes:
|
||||
label: Platform
|
||||
description: What platform are you using?
|
||||
options:
|
||||
- Windows
|
||||
- macOS
|
||||
- Linux
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Version
|
||||
description: What version of Cherry Studio are you running?
|
||||
placeholder: e.g. v1.0.0
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: problem
|
||||
attributes:
|
||||
label: Is your feature request related to a problem?
|
||||
description: A clear and concise description of what the problem is
|
||||
placeholder: I'm always frustrated when...
|
||||
label: Is your feature request related to an existing issue?
|
||||
description: Please briefly describe the problem you are experiencing. If possible, include screenshots or recordings to help illustrate the current situation or pain points.
|
||||
placeholder: I often feel frustrated because... (Remember to attach screenshots/recordings if applicable)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: Describe the solution you'd like
|
||||
description: A clear and concise description of what you want to happen
|
||||
label: Desired Solution
|
||||
description: Please briefly describe what you would like to happen. You can include mockups, screenshots, or screen recordings to better illustrate your proposed solution.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Describe alternatives you've considered
|
||||
description: A clear and concise description of any alternative solutions or features you've considered
|
||||
label: Alternative Solutions
|
||||
description: Please briefly describe any alternative solutions or features you have considered. Feel free to include screenshots or mockups of alternative approaches.
|
||||
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional Context
|
||||
description: Add any other context or screenshots about the feature request here
|
||||
label: Additional Information
|
||||
description: Add any other context, screenshots, mockups or recordings that can help us better understand your feature request.
|
||||
|
||||
49
.github/ISSUE_TEMPLATE/2_question.yml
vendored
@@ -1,12 +1,12 @@
|
||||
name: ❓ Question
|
||||
description: Ask a question or seek help
|
||||
title: '[Question]: '
|
||||
name: ❓ Discussion & Questions
|
||||
description: Seeking help, discussing issues, asking questions, etc...
|
||||
title: '[Discussion]: '
|
||||
labels: ['question']
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for asking a question! Please provide as much detail as possible so we can better assist you.
|
||||
Thank you for your question! Please describe your issue in as much detail as possible so that we can better assist you.
|
||||
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
@@ -15,17 +15,40 @@ body:
|
||||
description: |
|
||||
Before submitting an issue, please make sure you have completed the following steps
|
||||
options:
|
||||
- label: I have viewed the pinned issues and searched existing issues but couldn't find anything similar.
|
||||
- label: I understand that issues are meant for feedback and problem-solving, not for venting, and I will provide as much detail as possible to help resolve the issue.
|
||||
required: true
|
||||
- label: I have filled out the issue title correctly.
|
||||
- label: I have checked the pinned issues and searched through the existing [open issues](https://github.com/CherryHQ/cherry-studio/issues), [closed issues](https://github.com/CherryHQ/cherry-studio/issues?q=is%3Aissue%20state%3Aclosed), and [discussions](https://github.com/CherryHQ/cherry-studio/discussions) and did not find a similar suggestion.
|
||||
required: true
|
||||
- label: I confirm that I am here to ask questions and discuss issues, not to report bugs or request features.
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: platform
|
||||
attributes:
|
||||
label: Platform
|
||||
description: What platform are you using?
|
||||
options:
|
||||
- Windows
|
||||
- macOS
|
||||
- Linux
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Version
|
||||
description: What version of Cherry Studio are you running?
|
||||
placeholder: e.g. v1.0.0
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: question
|
||||
attributes:
|
||||
label: Your Question
|
||||
description: Please describe your question in detail
|
||||
placeholder: Please explain your question as clearly as possible...
|
||||
description: Please describe your issue in detail. Include screenshots or screen recordings whenever possible to help us better understand your question.
|
||||
placeholder: Please explain your issue as clearly as possible...(Remember to attach screenshots/recordings if applicable)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
@@ -33,23 +56,23 @@ body:
|
||||
id: context
|
||||
attributes:
|
||||
label: Context
|
||||
description: Please provide some background information to help us better understand your question
|
||||
placeholder: "For example: use case, solutions you've tried, etc."
|
||||
description: Please provide some background information to help us better understand your question. Screenshots or recordings of your current setup or situation can be very helpful.
|
||||
placeholder: "For example: use case, solutions you've tried, etc. Don't forget to include relevant screenshots/recordings!"
|
||||
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: Any other relevant information, screenshots, or code examples
|
||||
description: Any other relevant information, screenshots, recordings, or code examples that can help us better assist you
|
||||
render: shell
|
||||
|
||||
- type: dropdown
|
||||
id: priority
|
||||
attributes:
|
||||
label: Priority
|
||||
description: How urgent is this question for you?
|
||||
description: How urgent is this issue for you?
|
||||
options:
|
||||
- Low (Can wait)
|
||||
- Low (Review when available)
|
||||
- Medium (Would like a response soon)
|
||||
- High (Blocking progress)
|
||||
validations:
|
||||
|
||||
3
.gitignore
vendored
@@ -44,3 +44,6 @@ stats.html
|
||||
|
||||
# Local
|
||||
local
|
||||
.aider*
|
||||
.cursorrules
|
||||
.cursor/rules
|
||||
|
||||
57
.yarn/patches/@tavily-core-npm-0.3.1-fe69bf2bea.patch
Normal file
@@ -0,0 +1,57 @@
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index 88c405a000d21b3631eaa378690907c5527b8eaf..e03e66440c7c93aee38adf57df3096c6fefcd96d 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -82,7 +82,6 @@ module.exports = __toCommonJS(index_exports);
|
||||
|
||||
// src/utils.ts
|
||||
var import_axios = __toESM(require("axios"));
|
||||
-var import_js_tiktoken = require("js-tiktoken");
|
||||
var BASE_URL = "https://api.tavily.com";
|
||||
var DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo";
|
||||
var DEFAULT_MAX_TOKENS = 4e3;
|
||||
@@ -97,8 +96,7 @@ function post(endpoint, body, apiKey) {
|
||||
});
|
||||
}
|
||||
function getTotalTokensFromString(str, encodingName = DEFAULT_MODEL_ENCODING) {
|
||||
- const encoding = (0, import_js_tiktoken.encodingForModel)(encodingName);
|
||||
- return encoding.encode(str).length;
|
||||
+ return 0;
|
||||
}
|
||||
function getMaxTokensFromList(data, maxTokens = DEFAULT_MAX_TOKENS) {
|
||||
var result = [];
|
||||
diff --git a/dist/index.mjs b/dist/index.mjs
|
||||
index 0a9ea6a0add8d709e6721e806571f373d9fe0487..b81f1ea48a2b2a30ee98d53980a1b04ea3fdc5d4 100644
|
||||
--- a/dist/index.mjs
|
||||
+++ b/dist/index.mjs
|
||||
@@ -49,7 +49,6 @@ var __async = (__this, __arguments, generator) => {
|
||||
|
||||
// src/utils.ts
|
||||
import axios from "axios";
|
||||
-import { encodingForModel } from "js-tiktoken";
|
||||
var BASE_URL = "https://api.tavily.com";
|
||||
var DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo";
|
||||
var DEFAULT_MAX_TOKENS = 4e3;
|
||||
@@ -64,8 +63,7 @@ function post(endpoint, body, apiKey) {
|
||||
});
|
||||
}
|
||||
function getTotalTokensFromString(str, encodingName = DEFAULT_MODEL_ENCODING) {
|
||||
- const encoding = encodingForModel(encodingName);
|
||||
- return encoding.encode(str).length;
|
||||
+ return 0;
|
||||
}
|
||||
function getMaxTokensFromList(data, maxTokens = DEFAULT_MAX_TOKENS) {
|
||||
var result = [];
|
||||
diff --git a/package.json b/package.json
|
||||
index 36d4a613166a7906c1dc5377a89dc0a65f746f73..dc6e0e9363046755cad123e627cc270a2e3580d1 100644
|
||||
--- a/package.json
|
||||
+++ b/package.json
|
||||
@@ -36,7 +36,6 @@
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
- "axios": "^1.7.7",
|
||||
- "js-tiktoken": "^1.0.14"
|
||||
+ "axios": "^1.7.7"
|
||||
}
|
||||
}
|
||||
28
README.md
@@ -12,7 +12,7 @@
|
||||
|
||||
Cherry Studio is a desktop client that supports for multiple LLM providers, available on Windows, Mac and Linux.
|
||||
|
||||
👏 Join [Telegram Group](https://t.me/CherryStudioAI)|[Discord](https://discord.gg/wez8HtpxqQ) | [QQ Group(1022779719)](https://qm.qq.com/q/Qtw8As0cwe)
|
||||
👏 Join [Telegram Group](https://t.me/CherryStudioAI)|[Discord](https://discord.gg/wez8HtpxqQ) | [QQ Group(1025067911)](https://qm.qq.com/q/RIBAO2pPKS)
|
||||
|
||||
❤️ Like Cherry Studio? Give it a star 🌟 or [Sponsor](docs/sponsor.md) to support the development!
|
||||
|
||||
@@ -30,7 +30,7 @@ Cherry Studio is a desktop client that supports for multiple LLM providers, avai
|
||||
|
||||
- ☁️ Major LLM Cloud Services: OpenAI, Gemini, Anthropic, and more
|
||||
- 🔗 AI Web Service Integration: Claude, Peplexity, Poe, and others
|
||||
- 💻 Local Model Support with Ollama
|
||||
- 💻 Local Model Support with Ollama, LM Studio
|
||||
|
||||
2. **AI Assistants & Conversations**:
|
||||
|
||||
@@ -60,6 +60,21 @@ Cherry Studio is a desktop client that supports for multiple LLM providers, avai
|
||||
- 📝 Complete Markdown Rendering
|
||||
- 🤲 Easy Content Sharing
|
||||
|
||||
# 📝 TODO
|
||||
|
||||
- [x] Quick popup (read clipboard, quick question, explain, translate, summarize)
|
||||
- [x] Comparison of multi-model answers
|
||||
- [x] Support login using SSO provided by service providers
|
||||
- [x] All models support networking
|
||||
- [x] Launch of the first official version
|
||||
- [x] Bug fixes and improvements (In progress...)
|
||||
- [ ] Plugin functionality (JavaScript)
|
||||
- [ ] Browser extension (highlight text to translate, summarize, add to knowledge base)
|
||||
- [ ] iOS & Android client
|
||||
- [ ] AI notes
|
||||
- [ ] Voice input and output (AI call)
|
||||
- [ ] Data backup supports custom backup content
|
||||
|
||||
# 🖥️ Develop
|
||||
|
||||
## IDE Setup
|
||||
@@ -71,13 +86,13 @@ Cherry Studio is a desktop client that supports for multiple LLM providers, avai
|
||||
### Install
|
||||
|
||||
```bash
|
||||
$ yarn
|
||||
yarn
|
||||
```
|
||||
|
||||
### Development
|
||||
|
||||
```bash
|
||||
$ yarn dev
|
||||
yarn dev
|
||||
```
|
||||
|
||||
### Build
|
||||
@@ -117,7 +132,10 @@ For more detailed guidelines, please refer to our [Contributing Guide](./CONTRIB
|
||||
Thank you for your support and contributions!
|
||||
|
||||
## Related Projects
|
||||
* [one-api](https://github.com/songquanpeng/one-api):LLM API management and distribution system, supporting mainstream models like OpenAI, Azure, and Anthropic. Features unified API interface, suitable for key management and secondary distribution.
|
||||
|
||||
- [one-api](https://github.com/songquanpeng/one-api):LLM API management and distribution system, supporting mainstream models like OpenAI, Azure, and Anthropic. Features unified API interface, suitable for key management and secondary distribution.
|
||||
|
||||
- [ublacklist](https://github.com/iorate/ublacklist):Blocks specific sites from appearing in Google search results
|
||||
|
||||
# 🚀 Contributors
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<img src="https://github.com/kangfenmao/cherry-studio/blob/main/build/icon.png?raw=true" width="150" height="150" alt="banner" />
|
||||
</a>
|
||||
</h1>
|
||||
<div align="center">
|
||||
<a href="./README.md">English</a> | <a href="./README.zh.md">中文</a> | 日本語
|
||||
</div>
|
||||
<p align="center">
|
||||
<a href="https://github.com/kangfenmao/cherry-studio">English</a> | <a href="./README.zh.md">中文</a> | 日本語 <br>
|
||||
</p>
|
||||
<div align="center">
|
||||
<a href="https://trendshift.io/repositories/11772" target="_blank"><img src="https://trendshift.io/api/badge/repositories/11772" alt="kangfenmao%2Fcherry-studio | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||
</div>
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
Cherry Studioは、複数のLLMプロバイダーをサポートするデスクトップクライアントで、Windows、Mac、Linuxで利用可能です。
|
||||
|
||||
👏 [Telegram](https://t.me/CherryStudioAI)|[Discord](https://discord.gg/wez8HtpxqQ) | [QQグループ(1022779719)](https://qm.qq.com/q/Qtw8As0cwe)
|
||||
👏 [Telegram](https://t.me/CherryStudioAI)|[Discord](https://discord.gg/wez8HtpxqQ) | [QQグループ(1025067911)](https://qm.qq.com/q/RIBAO2pPKS)
|
||||
|
||||
❤️ Cherry Studioをお気に入りにしましたか?小さな星をつけてください 🌟 または [スポンサー](sponsor.md) をして開発をサポートしてください!❤️
|
||||
|
||||
@@ -31,7 +31,7 @@ Cherry Studioは、複数のLLMプロバイダーをサポートするデスク
|
||||
|
||||
- ☁️ 主要な LLM クラウドサービス対応:OpenAI、Gemini、Anthropic など
|
||||
- 🔗 AI Web サービス統合:Claude、Peplexity、Poe など
|
||||
- 💻 Ollama によるローカルモデル実行対応
|
||||
- 💻 Ollama、LM Studio によるローカルモデル実行対応
|
||||
|
||||
2. **AI アシスタントと対話**:
|
||||
|
||||
@@ -61,6 +61,21 @@ Cherry Studioは、複数のLLMプロバイダーをサポートするデスク
|
||||
- 📝 完全な Markdown レンダリング
|
||||
- 🤲 簡単な共有機能
|
||||
|
||||
# 📝 TODO
|
||||
|
||||
- [x] クイックポップアップ(クリップボードの読み取り、簡単な質問、説明、翻訳、要約)
|
||||
- [x] 複数モデルの回答の比較
|
||||
- [x] サービスプロバイダーが提供するSSOを使用したログインをサポート
|
||||
- [x] すべてのモデルがネットワークをサポート
|
||||
- [x] 最初の公式バージョンのリリース
|
||||
- [ ] 錯誤修復と改善 (開発中...)
|
||||
- [ ] プラグイン機能(JavaScript)
|
||||
- [ ] ブラウザ拡張機能(テキストをハイライトして翻訳、要約、ナレッジベースに追加)
|
||||
- [ ] iOS & Android クライアント
|
||||
- [ ] AIノート
|
||||
- [ ] 音声入出力(AIコール)
|
||||
- [ ] データバックアップはカスタムバックアップコンテンツをサポート
|
||||
|
||||
# 🖥️ 開発
|
||||
|
||||
## IDEの設定
|
||||
@@ -118,7 +133,8 @@ Cherry Studioへの貢献を歓迎します!以下の方法で貢献できま
|
||||
ご支援と貢献に感謝します!
|
||||
|
||||
## 関連頁版
|
||||
* [one-api](https://github.com/songquanpeng/one-api):LLM APIの管理・配信システム。OpenAI、Azure、Anthropicなどの主要モデルに対応し、統一APIインターフェースを提供。APIキー管理と再配布に利用可能。
|
||||
|
||||
- [one-api](https://github.com/songquanpeng/one-api):LLM APIの管理・配信システム。OpenAI、Azure、Anthropicなどの主要モデルに対応し、統一APIインターフェースを提供。APIキー管理と再配布に利用可能。
|
||||
|
||||
# 🚀 コントリビューター
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
<img src="https://github.com/kangfenmao/cherry-studio/blob/main/build/icon.png?raw=true" width="150" height="150" alt="banner" />
|
||||
</a>
|
||||
</h1>
|
||||
<div align="center">
|
||||
中文 / <a href="https://github.com/kangfenmao/cherry-studio">English</a> / <a href="./README.ja.md">日本語</a>
|
||||
</div>
|
||||
<p align="center">
|
||||
<a href="https://github.com/kangfenmao/cherry-studio">English</a> | 中文 | <a href="./README.ja.md">日本語</a><br></p>
|
||||
<div align="center">
|
||||
<a href="https://trendshift.io/repositories/11772" target="_blank"><img src="https://trendshift.io/api/badge/repositories/11772" alt="kangfenmao%2Fcherry-studio | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||
</div>
|
||||
@@ -13,7 +12,7 @@
|
||||
|
||||
Cherry Studio 是一款支持多个大语言模型(LLM)服务商的桌面客户端,兼容 Windows、Mac 和 Linux 系统。
|
||||
|
||||
👏 欢迎加入 [Telegram 群组](https://t.me/CherryStudioAI)|[Discord](https://discord.gg/wez8HtpxqQ) | [QQ群(1022779719)](https://qm.qq.com/q/Qtw8As0cwe)
|
||||
👏 欢迎加入 [Telegram 群组](https://t.me/CherryStudioAI)|[Discord](https://discord.gg/wez8HtpxqQ) | [QQ群(1025067911)](https://qm.qq.com/q/RIBAO2pPKS)
|
||||
|
||||
❤️ 喜欢 Cherry Studio? 点亮小星星 🌟 或 [赞助开发者](sponsor.md)! ❤️
|
||||
|
||||
@@ -31,7 +30,7 @@ Cherry Studio 是一款支持多个大语言模型(LLM)服务商的桌面客
|
||||
|
||||
- ☁️ 支持主流 LLM 云服务:OpenAI、Gemini、Anthropic、硅基流动等
|
||||
- 🔗 集成流行 AI Web 服务:Claude、Peplexity、Poe、腾讯元宝、知乎直答等
|
||||
- 💻 支持 Ollama 本地模型部署
|
||||
- 💻 支持 Ollama、LM Studio 本地模型部署
|
||||
|
||||
2. **智能助手与对话**:
|
||||
|
||||
@@ -61,6 +60,21 @@ Cherry Studio 是一款支持多个大语言模型(LLM)服务商的桌面客
|
||||
- 📝 完整的 Markdown 渲染
|
||||
- 🤲 便捷的内容分享功能
|
||||
|
||||
# 📝 待辦事項
|
||||
|
||||
- [x] 快捷弹窗 (读取剪贴板、快速提问、解释、翻译、总结)
|
||||
- [x] 多模型回答对比
|
||||
- [x] 支持使用服务供应商提供的 SSO 进行登入
|
||||
- [x] 全部模型支持连网(开发中...)
|
||||
- [x] 推出第一个正式版
|
||||
- [x] 错误修复和改进(开发中...)
|
||||
- [ ] 插件功能(JavaScript)
|
||||
- [ ] 浏览器插件(划词翻译、总结、新增至知识库)
|
||||
- [ ] iOS & Android 客户端
|
||||
- [ ] AI 笔记
|
||||
- [ ] 语音输入输出(AI 通话)
|
||||
- [ ] 数据备份支持自定义备份内容
|
||||
|
||||
# 🖥️ 开发
|
||||
|
||||
## IDE 设置
|
||||
@@ -118,7 +132,8 @@ $ yarn build:linux
|
||||
感谢您的支持和贡献!
|
||||
|
||||
## 相关项目
|
||||
* [one-api](https://github.com/songquanpeng/one-api):LLM API管理及分发系统,支持OpenAI、Azure、Anthropic等主流模型,统一API接口,可用于密钥管理与二次分发。
|
||||
|
||||
- [one-api](https://github.com/songquanpeng/one-api):LLM API管理及分发系统,支持OpenAI、Azure、Anthropic等主流模型,统一API接口,可用于密钥管理与二次分发。
|
||||
|
||||
# 🚀 贡献者
|
||||
|
||||
|
||||
174
docs/technical/KnowledgeService.md
Normal file
@@ -0,0 +1,174 @@
|
||||
我来详细介绍 KnowledgeService 中控制并发处理的项目数量和工作负载的部分。
|
||||
|
||||
## 并发控制与工作负载管理机制
|
||||
|
||||
KnowledgeService 实现了一个精细的任务队列系统,用于控制并发处理的项目数量和工作负载。这个系统主要通过以下几个关键部分实现:
|
||||
|
||||
### 1. 关键变量和限制
|
||||
|
||||
```typescript
|
||||
private workload = 0
|
||||
private processingItemCount = 0
|
||||
private knowledgeItemProcessingQueueMappingPromise: Map<LoaderTaskOfSet, () => void> = new Map()
|
||||
private static MAXIMUM_WORKLOAD = 1024 * 1024 * 80 // 约80MB
|
||||
private static MAXIMUM_PROCESSING_ITEM_COUNT = 30
|
||||
```
|
||||
|
||||
- `workload`: 跟踪当前正在处理的总工作量(以字节为单位)
|
||||
- `processingItemCount`: 跟踪当前正在处理的项目数量
|
||||
- `MAXIMUM_WORKLOAD`: 设置最大工作负载为80MB
|
||||
- `MAXIMUM_PROCESSING_ITEM_COUNT`: 设置最大并发处理项目数为30个
|
||||
|
||||
### 2. 工作负载评估
|
||||
|
||||
每个任务都有一个评估工作负载的机制,通过 `evaluateTaskWorkload` 属性来表示:
|
||||
|
||||
```typescript
|
||||
interface EvaluateTaskWorkload {
|
||||
workload: number
|
||||
}
|
||||
```
|
||||
|
||||
不同类型的任务有不同的工作负载评估方式:
|
||||
|
||||
- 文件任务:使用文件大小作为工作负载 `{ workload: file.size }`
|
||||
- URL任务:使用固定值 `{ workload: 1024 * 1024 * 2 }` (约2MB)
|
||||
- 网站地图任务:使用固定值 `{ workload: 1024 * 1024 * 20 }` (约20MB)
|
||||
- 笔记任务:使用文本内容的字节长度 `{ workload: contentBytes.length }`
|
||||
|
||||
### 3. 任务状态管理
|
||||
|
||||
任务通过状态枚举来跟踪其生命周期:
|
||||
|
||||
```typescript
|
||||
enum LoaderTaskItemState {
|
||||
PENDING, // 等待处理
|
||||
PROCESSING, // 正在处理
|
||||
DONE // 已完成
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 任务队列处理核心逻辑
|
||||
|
||||
核心的队列处理逻辑在 `processingQueueHandle` 方法中:
|
||||
|
||||
```typescript
|
||||
private processingQueueHandle() {
|
||||
const getSubtasksUntilMaximumLoad = (): QueueTaskItem[] => {
|
||||
const queueTaskList: QueueTaskItem[] = []
|
||||
that: for (const [task, resolve] of this.knowledgeItemProcessingQueueMappingPromise) {
|
||||
for (const item of task.loaderTasks) {
|
||||
if (this.maximumLoad()) {
|
||||
break that
|
||||
}
|
||||
|
||||
const { state, task: taskPromise, evaluateTaskWorkload } = item
|
||||
|
||||
if (state !== LoaderTaskItemState.PENDING) {
|
||||
continue
|
||||
}
|
||||
|
||||
const { workload } = evaluateTaskWorkload
|
||||
this.workload += workload
|
||||
this.processingItemCount += 1
|
||||
item.state = LoaderTaskItemState.PROCESSING
|
||||
queueTaskList.push({
|
||||
taskPromise: () =>
|
||||
taskPromise().then(() => {
|
||||
this.workload -= workload
|
||||
this.processingItemCount -= 1
|
||||
task.loaderTasks.delete(item)
|
||||
if (task.loaderTasks.size === 0) {
|
||||
this.knowledgeItemProcessingQueueMappingPromise.delete(task)
|
||||
resolve()
|
||||
}
|
||||
this.processingQueueHandle()
|
||||
}),
|
||||
resolve: () => {},
|
||||
evaluateTaskWorkload
|
||||
})
|
||||
}
|
||||
}
|
||||
return queueTaskList
|
||||
}
|
||||
|
||||
const subTasks = getSubtasksUntilMaximumLoad()
|
||||
if (subTasks.length > 0) {
|
||||
const subTaskPromises = subTasks.map(({ taskPromise }) => taskPromise())
|
||||
Promise.all(subTaskPromises).then(() => {
|
||||
subTasks.forEach(({ resolve }) => resolve())
|
||||
})
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
这个方法的工作流程是:
|
||||
|
||||
1. 遍历所有待处理的任务集合
|
||||
2. 对于每个任务集合中的每个子任务:
|
||||
- 检查是否已达到最大负载(通过 `maximumLoad()` 方法)
|
||||
- 如果任务状态为 PENDING,则:
|
||||
- 增加当前工作负载和处理项目计数
|
||||
- 将任务状态更新为 PROCESSING
|
||||
- 将任务添加到待执行队列
|
||||
3. 执行所有收集到的子任务
|
||||
4. 当子任务完成时:
|
||||
- 减少工作负载和处理项目计数
|
||||
- 从任务集合中移除已完成的任务
|
||||
- 如果任务集合为空,则解析相应的 Promise
|
||||
- 递归调用 `processingQueueHandle()` 以处理更多任务
|
||||
|
||||
### 5. 负载检查
|
||||
|
||||
```typescript
|
||||
private maximumLoad() {
|
||||
return (
|
||||
this.processingItemCount >= KnowledgeService.MAXIMUM_PROCESSING_ITEM_COUNT ||
|
||||
this.workload >= KnowledgeService.MAXIMUM_WORKLOAD
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
这个方法检查当前是否已达到最大负载,通过两个条件:
|
||||
|
||||
- 处理项目数量达到上限(30个)
|
||||
- 总工作负载达到上限(80MB)
|
||||
|
||||
### 6. 任务添加与执行流程
|
||||
|
||||
当添加新任务时,流程如下:
|
||||
|
||||
1. 创建任务(根据类型不同创建不同的任务)
|
||||
2. 通过 `appendProcessingQueue` 将任务添加到队列
|
||||
3. 调用 `processingQueueHandle` 开始处理队列中的任务
|
||||
|
||||
```typescript
|
||||
private appendProcessingQueue(task: LoaderTask): Promise<LoaderReturn> {
|
||||
return new Promise((resolve) => {
|
||||
this.knowledgeItemProcessingQueueMappingPromise.set(loaderTaskIntoOfSet(task), () => {
|
||||
resolve(task.loaderDoneReturn!)
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## 并发控制的优势
|
||||
|
||||
这种并发控制机制有几个重要优势:
|
||||
|
||||
1. **资源使用优化**:通过限制同时处理的项目数量和总工作负载,避免系统资源过度使用
|
||||
2. **自动调节**:当任务完成时,会自动从队列中获取新任务,保持资源的高效利用
|
||||
3. **灵活性**:不同类型的任务有不同的工作负载评估,更准确地反映实际资源需求
|
||||
4. **可靠性**:通过状态管理和Promise解析机制,确保任务正确完成并通知调用者
|
||||
|
||||
## 实际应用场景
|
||||
|
||||
这种并发控制在处理大量数据时特别有用,例如:
|
||||
|
||||
- 导入大型目录时,可能包含数百个文件
|
||||
- 处理大型网站地图,可能包含大量URL
|
||||
- 处理多个用户同时添加知识库项目的请求
|
||||
|
||||
通过这种机制,系统可以平滑地处理大量请求,避免资源耗尽,同时保持良好的响应性。
|
||||
|
||||
总结来说,KnowledgeService 实现了一个复杂而高效的任务队列系统,通过精确控制并发处理的项目数量和工作负载,确保系统在处理大量数据时保持稳定和高效。
|
||||
@@ -24,9 +24,9 @@ files:
|
||||
- '!**/{LICENSE,LICENSE.txt,LICENSE-MIT.txt,*.LICENSE.txt,NOTICE.txt,README.md,CHANGELOG.md}'
|
||||
- '!node_modules/rollup-plugin-visualizer'
|
||||
- '!node_modules/js-tiktoken'
|
||||
- '!node_modules/@tavily/core/node_modules/js-tiktoken'
|
||||
- '!node_modules/pdf-parse/lib/pdf.js/{v1.9.426,v1.10.88,v2.0.550}'
|
||||
- '!node_modules/mammoth/{mammoth.browser.js,mammoth.browser.min.js}'
|
||||
- '!node_modules/html2canvas/dist/{html2canvas.min.js,html2canvas.esm.js}'
|
||||
asarUnpack:
|
||||
- resources/**
|
||||
- '**/*.{node,dll,metal,exp,lib}'
|
||||
@@ -80,11 +80,4 @@ afterPack: scripts/after-pack.js
|
||||
afterSign: scripts/notarize.js
|
||||
releaseInfo:
|
||||
releaseNotes: |
|
||||
知识库增加更多文件类型支持
|
||||
使用@呼出模型选择列表
|
||||
添加话题固定功能
|
||||
增加导出话题至Notion的功能
|
||||
增加 Google AI Studio 小程序
|
||||
增加 Gitee 服务商
|
||||
增加 PPIO 服务商
|
||||
为 OpenAI 请求添加引用来源数据显示
|
||||
修复公式渲染问题
|
||||
|
||||
@@ -21,7 +21,8 @@ export default defineConfig({
|
||||
'@llm-tools/embedjs-loader-pdf',
|
||||
'@llm-tools/embedjs-loader-sitemap',
|
||||
'@llm-tools/embedjs-libsql',
|
||||
'@llm-tools/embedjs-loader-image'
|
||||
'@llm-tools/embedjs-loader-image',
|
||||
'p-queue'
|
||||
]
|
||||
}),
|
||||
...visualizerPlugin('main')
|
||||
@@ -43,7 +44,24 @@ export default defineConfig({
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
},
|
||||
renderer: {
|
||||
plugins: [react(), ...visualizerPlugin('renderer')],
|
||||
plugins: [
|
||||
react({
|
||||
babel: {
|
||||
plugins: [
|
||||
[
|
||||
'styled-components',
|
||||
{
|
||||
displayName: true, // 开发环境下启用组件名称
|
||||
fileName: false, // 不在类名中包含文件名
|
||||
pure: true, // 优化性能
|
||||
ssr: false // 不需要服务端渲染
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}),
|
||||
...visualizerPlugin('renderer')
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@renderer': resolve('src/renderer/src'),
|
||||
@@ -51,7 +69,7 @@ export default defineConfig({
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
exclude: ['chunk-PZ64DZKH.js', 'chunk-JMKENWIY.js']
|
||||
exclude: ['chunk-PZ64DZKH.js', 'chunk-JMKENWIY.js', 'chunk-UXYB6GHG.js', 'chunk-ALDIEZMG.js']
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
29
package.json
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "CherryStudio",
|
||||
"version": "0.9.23",
|
||||
"version": "1.1.0",
|
||||
"private": true,
|
||||
"description": "A powerful AI assistant for producer.",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "kangfenmao@qq.com",
|
||||
"homepage": "https://github.com/kangfenmao/cherry-studio",
|
||||
"author": "support@cherry-ai.com",
|
||||
"homepage": "https://github.com/CherryHQ/cherry-studio",
|
||||
"workspaces": {
|
||||
"packages": [
|
||||
"local",
|
||||
@@ -45,12 +45,17 @@
|
||||
"generate:icons": "electron-icon-builder --input=./build/logo.png --output=build",
|
||||
"analyze:renderer": "VISUALIZER_RENDERER=true yarn build",
|
||||
"analyze:main": "VISUALIZER_MAIN=true yarn build",
|
||||
"check": "node scripts/check-i18n.js"
|
||||
"check": "node scripts/check-i18n.js",
|
||||
"test": "tsx --test src/**/*.test.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@agentic/exa": "^7.3.3",
|
||||
"@agentic/searxng": "^7.3.3",
|
||||
"@agentic/tavily": "^7.3.3",
|
||||
"@electron-toolkit/preload": "^3.0.0",
|
||||
"@electron-toolkit/utils": "^3.0.0",
|
||||
"@electron/notarize": "^2.5.0",
|
||||
"@emotion/is-prop-valid": "^1.3.1",
|
||||
"@google/generative-ai": "^0.21.0",
|
||||
"@llm-tools/embedjs": "patch:@llm-tools/embedjs@npm%3A0.1.28#~/.yarn/patches/@llm-tools-embedjs-npm-0.1.28-8e4393fa2d.patch",
|
||||
"@llm-tools/embedjs-libsql": "^0.1.28",
|
||||
@@ -62,6 +67,7 @@
|
||||
"@llm-tools/embedjs-loader-web": "^0.1.28",
|
||||
"@llm-tools/embedjs-loader-xml": "^0.1.28",
|
||||
"@llm-tools/embedjs-openai": "^0.1.28",
|
||||
"@modelcontextprotocol/sdk": "^1.6.1",
|
||||
"@notionhq/client": "^2.2.15",
|
||||
"@types/react-infinite-scroll-component": "^5.0.0",
|
||||
"adm-zip": "^0.5.16",
|
||||
@@ -71,15 +77,18 @@
|
||||
"electron-store": "^8.2.0",
|
||||
"electron-updater": "^6.3.9",
|
||||
"electron-window-state": "^5.0.3",
|
||||
"epub": "^1.3.0",
|
||||
"fetch-socks": "^1.3.2",
|
||||
"fs-extra": "^11.2.0",
|
||||
"html2canvas": "^1.4.1",
|
||||
"markdown-it": "^14.1.0",
|
||||
"officeparser": "^4.1.1",
|
||||
"p-queue": "^8.1.0",
|
||||
"tokenx": "^0.4.1",
|
||||
"undici": "^7.4.0",
|
||||
"webdav": "4.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@anthropic-ai/sdk": "^0.24.3",
|
||||
"@anthropic-ai/sdk": "^0.38.0",
|
||||
"@electron-toolkit/eslint-config-prettier": "^2.0.0",
|
||||
"@electron-toolkit/eslint-config-ts": "^1.0.1",
|
||||
"@electron-toolkit/tsconfig": "^1.0.1",
|
||||
@@ -87,12 +96,14 @@
|
||||
"@kangfenmao/keyv-storage": "^0.1.0",
|
||||
"@llm-tools/embedjs-loader-image": "^0.1.28",
|
||||
"@reduxjs/toolkit": "^2.2.5",
|
||||
"@tavily/core": "patch:@tavily/core@npm%3A0.3.1#~/.yarn/patches/@tavily-core-npm-0.3.1-fe69bf2bea.patch",
|
||||
"@types/adm-zip": "^0",
|
||||
"@types/fs-extra": "^11",
|
||||
"@types/lodash": "^4.17.5",
|
||||
"@types/markdown-it": "^14",
|
||||
"@types/md5": "^2.3.5",
|
||||
"@types/node": "^18.19.9",
|
||||
"@types/pako": "^1.0.2",
|
||||
"@types/react": "^18.2.48",
|
||||
"@types/react-dom": "^18.2.18",
|
||||
"@types/react-infinite-scroll-component": "^5.0.0",
|
||||
@@ -101,6 +112,7 @@
|
||||
"antd": "^5.22.5",
|
||||
"applescript": "^1.0.0",
|
||||
"axios": "^1.7.3",
|
||||
"babel-plugin-styled-components": "^2.1.4",
|
||||
"browser-image-compression": "^2.0.2",
|
||||
"dayjs": "^1.11.11",
|
||||
"dexie": "^4.0.8",
|
||||
@@ -118,6 +130,7 @@
|
||||
"eslint-plugin-react-hooks": "^4.6.2",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"eslint-plugin-unused-imports": "^4.0.0",
|
||||
"html-to-image": "^1.11.13",
|
||||
"i18next": "^23.11.5",
|
||||
"lodash": "^4.17.21",
|
||||
"mime": "^4.0.4",
|
||||
@@ -136,7 +149,7 @@
|
||||
"redux": "^5.0.1",
|
||||
"redux-persist": "^6.0.0",
|
||||
"rehype-katex": "^7.0.1",
|
||||
"rehype-mathjax": "^6.0.0",
|
||||
"rehype-mathjax": "^7.0.0",
|
||||
"rehype-raw": "^7.0.0",
|
||||
"remark-gfm": "^4.0.0",
|
||||
"remark-math": "^6.0.0",
|
||||
@@ -160,5 +173,5 @@
|
||||
"@langchain/openai@npm:>=0.1.0 <0.4.0": "patch:@langchain/openai@npm%3A0.3.16#~/.yarn/patches/@langchain-openai-npm-0.3.16-e525b59526.patch",
|
||||
"openai@npm:^4.77.0": "patch:openai@npm%3A4.77.3#~/.yarn/patches/openai-npm-4.77.3-59c6d42e7a.patch"
|
||||
},
|
||||
"packageManager": "yarn@4.5.0"
|
||||
"packageManager": "yarn@4.6.0"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ export const imageExts = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp']
|
||||
export const videoExts = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv']
|
||||
export const audioExts = ['.mp3', '.wav', '.ogg', '.flac', '.aac']
|
||||
export const documentExts = ['.pdf', '.docx', '.pptx', '.xlsx', '.odt', '.odp', '.ods']
|
||||
export const thirdPartyApplicationExts = ['.draftsExport']
|
||||
export const bookExts = ['.epub']
|
||||
export const textExts = [
|
||||
'.txt', // 普通文本文件
|
||||
'.md', // Markdown 文件
|
||||
@@ -17,7 +19,10 @@ export const textExts = [
|
||||
'.ini', // 配置文件
|
||||
'.log', // 日志文件
|
||||
'.rtf', // 富文本格式文件
|
||||
'.org', // org-mode 文件
|
||||
'.wiki', // VimWiki 文件
|
||||
'.tex', // LaTeX 文件
|
||||
'.bib', // BibTeX 文件
|
||||
'.srt', // 字幕文件
|
||||
'.xhtml', // XHTML 文件
|
||||
'.nfo', // 信息文件(主要用于场景发布)
|
||||
@@ -33,6 +38,7 @@ export const textExts = [
|
||||
'.bat', // Windows 批处理文件
|
||||
'.sh', // Unix/Linux Shell 脚本文件
|
||||
'.py', // Python 脚本文件
|
||||
'.ipynb', // Jupyter 笔记本格式
|
||||
'.rb', // Ruby 脚本文件
|
||||
'.pl', // Perl 脚本文件
|
||||
'.sql', // SQL 脚本文件
|
||||
@@ -88,7 +94,16 @@ export const textExts = [
|
||||
'.groovy', // Gradle 构建文件
|
||||
'.kts', // Kotlin Script 文件
|
||||
'.java', // Java 代码文件
|
||||
'.cs' // C# 代码文件
|
||||
'.cs', // C# 代码文件
|
||||
'.cpp', // C++ 代码文件
|
||||
'.c', // C++ 代码文件
|
||||
'.h', // C++ 头文件
|
||||
'.hpp', // C++ 头文件
|
||||
'.cc', // C++ 源文件
|
||||
'.cxx', // C++ 源文件
|
||||
'.cppm', // C++20 模块接口文件
|
||||
'.ipp', // 模板实现文件
|
||||
'.ixx' // C++20 模块实现文件
|
||||
]
|
||||
|
||||
export const ZOOM_SHORTCUTS = [
|
||||
|
||||
@@ -54,7 +54,7 @@ function syncRecursively(target: any, template: any): boolean {
|
||||
|
||||
function syncTranslations() {
|
||||
if (!fs.existsSync(baseFilePath)) {
|
||||
console.error(`主模板文件 ${baseFileName} 不存在,请检查路径或文件名。`)
|
||||
console.error(`主模板文件 ${baseFileName} 不存在,请检查路径或文件名`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -84,13 +84,13 @@ function syncTranslations() {
|
||||
|
||||
if (isUpdated) {
|
||||
try {
|
||||
fs.writeFileSync(filePath, JSON.stringify(targetJson, null, 2), 'utf-8')
|
||||
console.log(`文件 ${file} 已更新同步主模板的内容。`)
|
||||
fs.writeFileSync(filePath, JSON.stringify(targetJson, null, 2) + '\n', 'utf-8')
|
||||
console.log(`文件 ${file} 已更新同步主模板的内容`)
|
||||
} catch (error) {
|
||||
console.error(`写入 ${file} 出错:`, error)
|
||||
}
|
||||
} else {
|
||||
console.log(`文件 ${file} 无需更新。`)
|
||||
console.log(`文件 ${file} 无需更新`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ export const DATA_PATH = getDataPath()
|
||||
|
||||
export const titleBarOverlayDark = {
|
||||
height: 40,
|
||||
color: '#00000000',
|
||||
color: 'rgba(0,0,0,0)',
|
||||
symbolColor: '#ffffff'
|
||||
}
|
||||
|
||||
export const titleBarOverlayLight = {
|
||||
height: 40,
|
||||
color: '#00000000',
|
||||
color: 'rgba(255,255,255,0)',
|
||||
symbolColor: '#000000'
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils'
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import { replaceDevtoolsFont } from '@main/utils/windowUtil'
|
||||
import { app } from 'electron'
|
||||
import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer'
|
||||
|
||||
import { registerIpc } from './ipc'
|
||||
import { registerShortcuts } from './services/ShortcutService'
|
||||
import { TrayService } from './services/TrayService'
|
||||
import { windowService } from './services/WindowService'
|
||||
import { updateUserDataPath } from './utils/upgrade'
|
||||
|
||||
// Check for single instance lock
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
@@ -18,27 +18,6 @@ if (!app.requestSingleInstanceLock()) {
|
||||
// Some APIs can only be used after this event occurs.
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
await updateUserDataPath()
|
||||
|
||||
// Register custom protocol
|
||||
if (!app.isDefaultProtocolClient('cherrystudio')) {
|
||||
app.setAsDefaultProtocolClient('cherrystudio')
|
||||
}
|
||||
|
||||
// Handle protocol open
|
||||
app.on('open-url', (event, url) => {
|
||||
event.preventDefault()
|
||||
const parsedUrl = new URL(url)
|
||||
if (parsedUrl.pathname === 'siliconflow.oauth.login') {
|
||||
const code = parsedUrl.searchParams.get('code')
|
||||
if (code) {
|
||||
// Handle the OAuth code here
|
||||
console.log('OAuth code received:', code)
|
||||
// You can send this code to your renderer process via IPC if needed
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Set app user model id for windows
|
||||
electronApp.setAppUserModelId(import.meta.env.VITE_MAIN_BUNDLE_ID || 'com.kangfenmao.CherryStudio')
|
||||
|
||||
@@ -46,9 +25,8 @@ if (!app.requestSingleInstanceLock()) {
|
||||
new TrayService()
|
||||
|
||||
app.on('activate', function () {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
if (!mainWindow || mainWindow.isDestroyed()) {
|
||||
windowService.createMainWindow()
|
||||
} else {
|
||||
windowService.showMainWindow()
|
||||
@@ -59,6 +37,8 @@ if (!app.requestSingleInstanceLock()) {
|
||||
|
||||
registerIpc(mainWindow, app)
|
||||
|
||||
replaceDevtoolsFont(mainWindow)
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
installExtension(REDUX_DEVTOOLS)
|
||||
.then((name) => console.log(`Added Extension: ${name}`))
|
||||
@@ -68,12 +48,7 @@ if (!app.requestSingleInstanceLock()) {
|
||||
|
||||
// Listen for second instance
|
||||
app.on('second-instance', () => {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0]
|
||||
if (mainWindow) {
|
||||
mainWindow.isMinimized() && mainWindow.restore()
|
||||
mainWindow.show()
|
||||
mainWindow.focus()
|
||||
}
|
||||
windowService.showMainWindow()
|
||||
})
|
||||
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
import { Shortcut, ThemeMode } from '@types'
|
||||
import { BrowserWindow, ipcMain, ProxyConfig, session, shell } from 'electron'
|
||||
import { MCPServer, Shortcut, ThemeMode } from '@types'
|
||||
import { BrowserWindow, ipcMain, session, shell } from 'electron'
|
||||
import log from 'electron-log'
|
||||
|
||||
import { titleBarOverlayDark, titleBarOverlayLight } from './config'
|
||||
@@ -14,40 +13,46 @@ import FileService from './services/FileService'
|
||||
import FileStorage from './services/FileStorage'
|
||||
import { GeminiService } from './services/GeminiService'
|
||||
import KnowledgeService from './services/KnowledgeService'
|
||||
import MCPService from './services/MCPService'
|
||||
import { ProxyConfig, proxyManager } from './services/ProxyManager'
|
||||
import { registerShortcuts, unregisterAllShortcuts } from './services/ShortcutService'
|
||||
import { TrayService } from './services/TrayService'
|
||||
import { windowService } from './services/WindowService'
|
||||
import { getResourcePath } from './utils'
|
||||
import { decrypt } from './utils/aes'
|
||||
import { encrypt } from './utils/aes'
|
||||
import { decrypt, encrypt } from './utils/aes'
|
||||
import { getFilesDir } from './utils/file'
|
||||
import { compress, decompress } from './utils/zip'
|
||||
|
||||
const fileManager = new FileStorage()
|
||||
const backupManager = new BackupManager()
|
||||
const exportService = new ExportService(fileManager)
|
||||
const mcpService = new MCPService()
|
||||
|
||||
export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||
const { autoUpdater } = new AppUpdater(mainWindow)
|
||||
const appUpdater = new AppUpdater(mainWindow)
|
||||
|
||||
ipcMain.handle('app:info', () => ({
|
||||
version: app.getVersion(),
|
||||
isPackaged: app.isPackaged,
|
||||
appPath: app.getAppPath(),
|
||||
filesPath: path.join(app.getPath('userData'), 'Data', 'Files'),
|
||||
filesPath: getFilesDir(),
|
||||
appDataPath: app.getPath('userData'),
|
||||
resourcesPath: getResourcePath(),
|
||||
logsPath: log.transports.file.getFile().path
|
||||
}))
|
||||
|
||||
ipcMain.handle('app:proxy', async (_, proxy: string) => {
|
||||
const sessions = [session.defaultSession, session.fromPartition('persist:webview')]
|
||||
const proxyConfig: ProxyConfig = proxy === 'system' ? { mode: 'system' } : proxy ? { proxyRules: proxy } : {}
|
||||
await Promise.all(sessions.map((session) => session.setProxy(proxyConfig)))
|
||||
const proxyConfig: ProxyConfig =
|
||||
proxy === 'system' ? { mode: 'system' } : proxy ? { mode: 'custom', url: proxy } : { mode: 'none' }
|
||||
await proxyManager.configureProxy(proxyConfig)
|
||||
})
|
||||
|
||||
ipcMain.handle('app:reload', () => mainWindow.reload())
|
||||
ipcMain.handle('open:website', (_, url: string) => shell.openExternal(url))
|
||||
|
||||
// Update
|
||||
ipcMain.handle('app:show-update-dialog', () => appUpdater.showUpdateDialog(mainWindow))
|
||||
|
||||
// language
|
||||
ipcMain.handle('app:set-language', (_, language) => {
|
||||
configManager.setLanguage(language)
|
||||
@@ -99,9 +104,9 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||
|
||||
// check for update
|
||||
ipcMain.handle('app:check-for-update', async () => {
|
||||
const update = await autoUpdater.checkForUpdates()
|
||||
const update = await appUpdater.autoUpdater.checkForUpdates()
|
||||
return {
|
||||
currentVersion: autoUpdater.currentVersion,
|
||||
currentVersion: appUpdater.autoUpdater.currentVersion,
|
||||
updateInfo: update?.updateInfo
|
||||
}
|
||||
})
|
||||
@@ -207,4 +212,31 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||
ipcMain.handle('aes:decrypt', (_, encryptedData: string, iv: string, secretKey: string) =>
|
||||
decrypt(encryptedData, iv, secretKey)
|
||||
)
|
||||
|
||||
// Register MCP handlers
|
||||
ipcMain.on('mcp:servers-from-renderer', (_, servers) => mcpService.setServers(servers))
|
||||
ipcMain.handle('mcp:list-servers', async () => mcpService.listAvailableServices())
|
||||
ipcMain.handle('mcp:add-server', async (_, server: MCPServer) => mcpService.addServer(server))
|
||||
ipcMain.handle('mcp:update-server', async (_, server: MCPServer) => mcpService.updateServer(server))
|
||||
ipcMain.handle('mcp:delete-server', async (_, serverName: string) => mcpService.deleteServer(serverName))
|
||||
ipcMain.handle('mcp:set-server-active', async (_, { name, isActive }) =>
|
||||
mcpService.setServerActive({ name, isActive })
|
||||
)
|
||||
|
||||
// According to preload, this should take no parameters, but our implementation accepts
|
||||
// an optional serverName for better flexibility
|
||||
ipcMain.handle('mcp:list-tools', async (_, serverName?: string) => mcpService.listTools(serverName))
|
||||
ipcMain.handle('mcp:call-tool', async (_, params: { client: string; name: string; args: any }) =>
|
||||
mcpService.callTool(params)
|
||||
)
|
||||
|
||||
ipcMain.handle('mcp:cleanup', async () => mcpService.cleanup())
|
||||
|
||||
// Listen for changes in MCP servers and notify renderer
|
||||
mcpService.on('servers-updated', (servers) => {
|
||||
mainWindow?.webContents.send('mcp:servers-updated', servers)
|
||||
})
|
||||
|
||||
// Clean up MCP services when app quits
|
||||
app.on('before-quit', () => mcpService.cleanup())
|
||||
}
|
||||
|
||||
22
src/main/loader/draftsExportLoader.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as fs from 'node:fs'
|
||||
|
||||
import { JsonLoader } from '@llm-tools/embedjs'
|
||||
|
||||
/**
|
||||
* Drafts 应用导出的笔记文件加载器
|
||||
* 原始文件是一个 JSON 数组。每条笔记只保留 content、tags、modified_at 三个字段
|
||||
*/
|
||||
export class DraftsExportLoader extends JsonLoader {
|
||||
constructor(filePath: string) {
|
||||
const fileContent = fs.readFileSync(filePath, 'utf-8')
|
||||
const rawJson = JSON.parse(fileContent) as any[]
|
||||
const json = rawJson.map((item) => {
|
||||
return {
|
||||
content: item.content?.replace(/\n/g, '<br>'),
|
||||
tags: item.tags,
|
||||
modified_at: item.created_at
|
||||
}
|
||||
})
|
||||
super({ object: json })
|
||||
}
|
||||
}
|
||||
248
src/main/loader/epubLoader.ts
Normal file
@@ -0,0 +1,248 @@
|
||||
import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters'
|
||||
import { BaseLoader } from '@llm-tools/embedjs-interfaces'
|
||||
import { cleanString } from '@llm-tools/embedjs-utils'
|
||||
import { getTempDir } from '@main/utils/file'
|
||||
import Logger from 'electron-log'
|
||||
import EPub from 'epub'
|
||||
import * as fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
/**
|
||||
* epub 加载器的配置选项
|
||||
*/
|
||||
interface EpubLoaderOptions {
|
||||
/** epub 文件路径 */
|
||||
filePath: string
|
||||
/** 文本分块大小 */
|
||||
chunkSize: number
|
||||
/** 分块重叠大小 */
|
||||
chunkOverlap: number
|
||||
}
|
||||
|
||||
/**
|
||||
* epub 文件的元数据信息
|
||||
*/
|
||||
interface EpubMetadata {
|
||||
/** 作者显示名称(例如:"Lewis Carroll") */
|
||||
creator?: string
|
||||
/** 作者规范化名称,用于排序和索引(例如:"Carroll, Lewis") */
|
||||
creatorFileAs?: string
|
||||
/** 书籍标题(例如:"Alice's Adventures in Wonderland") */
|
||||
title?: string
|
||||
/** 语言代码(例如:"en" 或 "zh-CN") */
|
||||
language?: string
|
||||
/** 主题或分类(例如:"Fantasy"、"Fiction") */
|
||||
subject?: string
|
||||
/** 创建日期(例如:"2024-02-14") */
|
||||
date?: string
|
||||
/** 书籍描述或简介 */
|
||||
description?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* epub 章节信息
|
||||
*/
|
||||
interface EpubChapter {
|
||||
/** 章节 ID */
|
||||
id: string
|
||||
/** 章节标题 */
|
||||
title?: string
|
||||
/** 章节顺序 */
|
||||
order?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* epub 文件加载器
|
||||
* 用于解析 epub 电子书文件,提取文本内容和元数据
|
||||
*/
|
||||
export class EpubLoader extends BaseLoader<Record<string, string | number | boolean>, Record<string, unknown>> {
|
||||
protected filePath: string
|
||||
protected chunkSize: number
|
||||
protected chunkOverlap: number
|
||||
private extractedText: string
|
||||
private metadata: EpubMetadata | null
|
||||
|
||||
/**
|
||||
* 创建 epub 加载器实例
|
||||
* @param options 加载器配置选项
|
||||
*/
|
||||
constructor(options: EpubLoaderOptions) {
|
||||
super(options.filePath, {
|
||||
chunkSize: options.chunkSize,
|
||||
chunkOverlap: options.chunkOverlap
|
||||
})
|
||||
this.filePath = options.filePath
|
||||
this.chunkSize = options.chunkSize
|
||||
this.chunkOverlap = options.chunkOverlap
|
||||
this.extractedText = ''
|
||||
this.metadata = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待 epub 文件初始化完成
|
||||
* epub 库使用事件机制,需要等待 'end' 事件触发后才能访问文件内容
|
||||
* @param epub epub 实例
|
||||
* @returns 元数据和章节信息
|
||||
*/
|
||||
private waitForEpubInit(epub: any): Promise<{ metadata: EpubMetadata; chapters: EpubChapter[] }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
epub.on('end', () => {
|
||||
// 提取元数据
|
||||
const metadata: EpubMetadata = {
|
||||
creator: epub.metadata.creator,
|
||||
creatorFileAs: epub.metadata.creatorFileAs,
|
||||
title: epub.metadata.title,
|
||||
language: epub.metadata.language,
|
||||
subject: epub.metadata.subject,
|
||||
date: epub.metadata.date,
|
||||
description: epub.metadata.description
|
||||
}
|
||||
|
||||
// 提取章节信息
|
||||
const chapters: EpubChapter[] = epub.flow.map((chapter: any, index: number) => ({
|
||||
id: chapter.id,
|
||||
title: chapter.title || `Chapter ${index + 1}`,
|
||||
order: index + 1
|
||||
}))
|
||||
|
||||
resolve({ metadata, chapters })
|
||||
})
|
||||
|
||||
epub.on('error', (error: Error) => {
|
||||
reject(error)
|
||||
})
|
||||
|
||||
epub.parse()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取章节内容
|
||||
* @param epub epub 实例
|
||||
* @param chapterId 章节 ID
|
||||
* @returns 章节文本内容
|
||||
*/
|
||||
private getChapter(epub: any, chapterId: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
epub.getChapter(chapterId, (error: Error | null, text: string) => {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(text)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 epub 文件中提取文本内容
|
||||
* 1. 检查文件是否存在
|
||||
* 2. 初始化 epub 并获取元数据
|
||||
* 3. 遍历所有章节并提取文本
|
||||
* 4. 清理 HTML 标签
|
||||
* 5. 合并所有章节文本
|
||||
*/
|
||||
private async extractTextFromEpub() {
|
||||
try {
|
||||
// 检查文件是否存在
|
||||
if (!fs.existsSync(this.filePath)) {
|
||||
throw new Error(`File not found: ${this.filePath}`)
|
||||
}
|
||||
|
||||
const epub = new EPub(this.filePath)
|
||||
|
||||
// 等待 epub 初始化完成并获取元数据
|
||||
const { metadata, chapters } = await this.waitForEpubInit(epub)
|
||||
this.metadata = metadata
|
||||
|
||||
if (!epub.flow || epub.flow.length === 0) {
|
||||
throw new Error('No content found in epub file')
|
||||
}
|
||||
|
||||
// 使用临时文件而不是内存数组
|
||||
const tempFilePath = path.join(getTempDir(), `epub-${Date.now()}.txt`)
|
||||
const writeStream = fs.createWriteStream(tempFilePath)
|
||||
|
||||
// 遍历所有章节
|
||||
for (const chapter of chapters) {
|
||||
try {
|
||||
const content = await this.getChapter(epub, chapter.id)
|
||||
|
||||
if (!content) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 移除 HTML 标签并清理文本
|
||||
const text = content
|
||||
.replace(/<[^>]*>/g, ' ') // 移除所有 HTML 标签
|
||||
.replace(/\s+/g, ' ') // 将多个空白字符替换为单个空格
|
||||
.trim() // 移除首尾空白
|
||||
|
||||
if (text) {
|
||||
// 直接写入文件
|
||||
writeStream.write(text + '\n\n')
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error(`[EpubLoader] Error processing chapter ${chapter.id}:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭写入流
|
||||
writeStream.end()
|
||||
|
||||
// 等待写入完成
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
writeStream.on('finish', resolve)
|
||||
writeStream.on('error', reject)
|
||||
})
|
||||
|
||||
// 从临时文件读取内容
|
||||
this.extractedText = fs.readFileSync(tempFilePath, 'utf-8')
|
||||
|
||||
// 删除临时文件
|
||||
fs.unlinkSync(tempFilePath)
|
||||
|
||||
// 只添加一条完成日志
|
||||
Logger.info(`[EpubLoader] 电子书 ${this.metadata?.title || path.basename(this.filePath)} 处理完成`)
|
||||
} catch (error) {
|
||||
Logger.error('[EpubLoader] Error in extractTextFromEpub:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成文本块
|
||||
* 重写 BaseLoader 的方法,将提取的文本分割成适当大小的块
|
||||
* 每个块都包含源文件和元数据信息
|
||||
*/
|
||||
override async *getUnfilteredChunks() {
|
||||
// 如果还没有提取文本,先提取
|
||||
if (!this.extractedText) {
|
||||
await this.extractTextFromEpub()
|
||||
}
|
||||
|
||||
Logger.info('[EpubLoader] 书名:', this.metadata?.title || '未知书名', ' 文本大小:', this.extractedText.length)
|
||||
|
||||
// 创建文本分块器
|
||||
const chunker = new RecursiveCharacterTextSplitter({
|
||||
chunkSize: this.chunkSize,
|
||||
chunkOverlap: this.chunkOverlap
|
||||
})
|
||||
|
||||
// 清理并分割文本
|
||||
const chunks = await chunker.splitText(cleanString(this.extractedText))
|
||||
|
||||
// 为每个文本块添加元数据
|
||||
for (const chunk of chunks) {
|
||||
yield {
|
||||
pageContent: chunk,
|
||||
metadata: {
|
||||
source: this.filePath,
|
||||
title: this.metadata?.title || '',
|
||||
creator: this.metadata?.creator || '',
|
||||
language: this.metadata?.language || ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
import * as fs from 'node:fs'
|
||||
|
||||
import { LocalPathLoader, RAGApplication, TextLoader } from '@llm-tools/embedjs'
|
||||
import { JsonLoader, LocalPathLoader, RAGApplication, TextLoader } from '@llm-tools/embedjs'
|
||||
import type { AddLoaderReturn } from '@llm-tools/embedjs-interfaces'
|
||||
import { WebLoader } from '@llm-tools/embedjs-loader-web'
|
||||
import { LoaderReturn } from '@shared/config/types'
|
||||
import { FileType, KnowledgeBaseParams } from '@types'
|
||||
import Logger from 'electron-log'
|
||||
|
||||
import { DraftsExportLoader } from './draftsExportLoader'
|
||||
import { EpubLoader } from './epubLoader'
|
||||
import { OdLoader, OdType } from './odLoader'
|
||||
|
||||
// embedjs内置loader类型
|
||||
const commonExts = ['.pdf', '.csv', '.json', '.docx', '.pptx', '.xlsx', '.md']
|
||||
const commonExts = ['.pdf', '.csv', '.docx', '.pptx', '.xlsx', '.md']
|
||||
|
||||
export async function addOdLoader(
|
||||
ragApplication: RAGApplication,
|
||||
@@ -69,8 +72,77 @@ export async function addFileLoader(
|
||||
} as LoaderReturn
|
||||
}
|
||||
|
||||
// 文本类型
|
||||
// epub 文件处理
|
||||
if (file.ext === '.epub') {
|
||||
const loaderReturn = await ragApplication.addLoader(
|
||||
new EpubLoader({
|
||||
filePath: file.path,
|
||||
chunkSize: base.chunkSize ?? 1000,
|
||||
chunkOverlap: base.chunkOverlap ?? 200
|
||||
}) as any,
|
||||
forceReload
|
||||
)
|
||||
return {
|
||||
entriesAdded: loaderReturn.entriesAdded,
|
||||
uniqueId: loaderReturn.uniqueId,
|
||||
uniqueIds: [loaderReturn.uniqueId],
|
||||
loaderType: loaderReturn.loaderType
|
||||
} as LoaderReturn
|
||||
}
|
||||
|
||||
// DraftsExport类型 (file.ext会自动转换成小写)
|
||||
if (['.draftsexport'].includes(file.ext)) {
|
||||
const loaderReturn = await ragApplication.addLoader(new DraftsExportLoader(file.path) as any, forceReload)
|
||||
return {
|
||||
entriesAdded: loaderReturn.entriesAdded,
|
||||
uniqueId: loaderReturn.uniqueId,
|
||||
uniqueIds: [loaderReturn.uniqueId],
|
||||
loaderType: loaderReturn.loaderType
|
||||
}
|
||||
}
|
||||
|
||||
const fileContent = fs.readFileSync(file.path, 'utf-8')
|
||||
|
||||
// HTML类型
|
||||
if (['.html', '.htm'].includes(file.ext)) {
|
||||
const loaderReturn = await ragApplication.addLoader(
|
||||
new WebLoader({
|
||||
urlOrContent: fileContent,
|
||||
chunkSize: base.chunkSize,
|
||||
chunkOverlap: base.chunkOverlap
|
||||
}) as any,
|
||||
forceReload
|
||||
)
|
||||
return {
|
||||
entriesAdded: loaderReturn.entriesAdded,
|
||||
uniqueId: loaderReturn.uniqueId,
|
||||
uniqueIds: [loaderReturn.uniqueId],
|
||||
loaderType: loaderReturn.loaderType
|
||||
}
|
||||
}
|
||||
|
||||
// JSON类型
|
||||
if (['.json'].includes(file.ext)) {
|
||||
let jsonObject = {}
|
||||
let jsonParsed = true
|
||||
try {
|
||||
jsonObject = JSON.parse(fileContent)
|
||||
} catch (error) {
|
||||
jsonParsed = false
|
||||
Logger.warn('[KnowledgeBase] failed parsing json file, failling back to text processing:', file.path, error)
|
||||
}
|
||||
if (jsonParsed) {
|
||||
const loaderReturn = await ragApplication.addLoader(new JsonLoader({ object: jsonObject }))
|
||||
return {
|
||||
entriesAdded: loaderReturn.entriesAdded,
|
||||
uniqueId: loaderReturn.uniqueId,
|
||||
uniqueIds: [loaderReturn.uniqueId],
|
||||
loaderType: loaderReturn.loaderType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 文本类型
|
||||
const loaderReturn = await ragApplication.addLoader(
|
||||
new TextLoader({ text: fileContent, chunkSize: base.chunkSize, chunkOverlap: base.chunkOverlap }) as any,
|
||||
forceReload
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { UpdateInfo } from 'builder-util-runtime'
|
||||
import { app, BrowserWindow, dialog } from 'electron'
|
||||
import logger from 'electron-log'
|
||||
import { AppUpdater as _AppUpdater, autoUpdater, UpdateInfo } from 'electron-updater'
|
||||
import { AppUpdater as _AppUpdater, autoUpdater } from 'electron-updater'
|
||||
|
||||
import icon from '../../../build/icon.png?asset'
|
||||
|
||||
export default class AppUpdater {
|
||||
autoUpdater: _AppUpdater = autoUpdater
|
||||
private releaseInfo: UpdateInfo | undefined
|
||||
|
||||
constructor(mainWindow: BrowserWindow) {
|
||||
logger.transports.file.level = 'info'
|
||||
@@ -16,7 +18,12 @@ export default class AppUpdater {
|
||||
|
||||
// 检测下载错误
|
||||
autoUpdater.on('error', (error) => {
|
||||
logger.error('更新异常', error)
|
||||
// 简单记录错误信息和时间戳
|
||||
logger.error('更新异常', {
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
time: new Date().toISOString()
|
||||
})
|
||||
mainWindow.webContents.send('update-error', error)
|
||||
})
|
||||
|
||||
@@ -37,17 +44,26 @@ export default class AppUpdater {
|
||||
|
||||
// 当需要更新的内容下载完成后
|
||||
autoUpdater.on('update-downloaded', (releaseInfo: UpdateInfo) => {
|
||||
mainWindow.webContents.send('update-downloaded')
|
||||
mainWindow.webContents.send('update-downloaded', releaseInfo)
|
||||
this.releaseInfo = releaseInfo
|
||||
logger.info('下载完成', releaseInfo)
|
||||
})
|
||||
|
||||
logger.info('下载完成,询问用户是否更新', releaseInfo)
|
||||
this.autoUpdater = autoUpdater
|
||||
}
|
||||
|
||||
public async showUpdateDialog(mainWindow: BrowserWindow) {
|
||||
if (!this.releaseInfo) {
|
||||
return
|
||||
}
|
||||
|
||||
dialog
|
||||
.showMessageBox({
|
||||
type: 'info',
|
||||
title: '安装更新',
|
||||
icon,
|
||||
message: `新版本 ${releaseInfo.version} 已准备就绪`,
|
||||
detail: this.formatReleaseNotes(releaseInfo.releaseNotes),
|
||||
message: `新版本 ${this.releaseInfo.version} 已准备就绪`,
|
||||
detail: this.formatReleaseNotes(this.releaseInfo.releaseNotes),
|
||||
buttons: ['稍后安装', '立即安装'],
|
||||
defaultId: 1,
|
||||
cancelId: 0
|
||||
@@ -60,9 +76,6 @@ export default class AppUpdater {
|
||||
mainWindow.webContents.send('update-downloaded-cancelled')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
this.autoUpdater = autoUpdater
|
||||
}
|
||||
|
||||
private formatReleaseNotes(releaseNotes: string | ReleaseNoteInfo[] | null | undefined): string {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { WebDavConfig } from '@types'
|
||||
import AdmZip from 'adm-zip'
|
||||
import { exec } from 'child_process'
|
||||
import { app } from 'electron'
|
||||
import Logger from 'electron-log'
|
||||
import * as fs from 'fs-extra'
|
||||
import * as path from 'path'
|
||||
|
||||
import WebDav from './WebDav'
|
||||
import { windowService } from './WindowService'
|
||||
|
||||
class BackupManager {
|
||||
private tempDir = path.join(app.getPath('temp'), 'cherry-studio', 'backup', 'temp')
|
||||
@@ -18,23 +20,92 @@ class BackupManager {
|
||||
this.restoreFromWebdav = this.restoreFromWebdav.bind(this)
|
||||
}
|
||||
|
||||
private async setWritableRecursive(dirPath: string): Promise<void> {
|
||||
try {
|
||||
const items = await fs.readdir(dirPath, { withFileTypes: true })
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(dirPath, item.name)
|
||||
|
||||
// 先处理子目录
|
||||
if (item.isDirectory()) {
|
||||
await this.setWritableRecursive(fullPath)
|
||||
}
|
||||
|
||||
// 统一设置权限(Windows需要特殊处理)
|
||||
await this.forceSetWritable(fullPath)
|
||||
}
|
||||
|
||||
// 确保根目录权限
|
||||
await this.forceSetWritable(dirPath)
|
||||
} catch (error) {
|
||||
Logger.error(`权限设置失败:${dirPath}`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 新增跨平台权限设置方法
|
||||
private async forceSetWritable(targetPath: string): Promise<void> {
|
||||
try {
|
||||
// Windows系统需要先取消只读属性
|
||||
if (process.platform === 'win32') {
|
||||
await fs.chmod(targetPath, 0o666) // Windows会忽略权限位但能移除只读
|
||||
} else {
|
||||
const stats = await fs.stat(targetPath)
|
||||
const mode = stats.isDirectory() ? 0o777 : 0o666
|
||||
await fs.chmod(targetPath, mode)
|
||||
}
|
||||
|
||||
// 双重保险:使用文件属性命令(Windows专用)
|
||||
if (process.platform === 'win32') {
|
||||
await exec(`attrib -R "${targetPath}" /L /D`)
|
||||
}
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
||||
Logger.warn(`权限设置警告:${targetPath}`, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async backup(
|
||||
_: Electron.IpcMainInvokeEvent,
|
||||
fileName: string,
|
||||
data: string,
|
||||
destinationPath: string = this.backupDir
|
||||
): Promise<string> {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
|
||||
const onProgress = (processData: { stage: string; progress: number; total: number }) => {
|
||||
mainWindow?.webContents.send('backup-progress', processData)
|
||||
Logger.log('[BackupManager] backup progress', processData)
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.ensureDir(this.tempDir)
|
||||
onProgress({ stage: 'preparing', progress: 0, total: 100 })
|
||||
|
||||
// 将 data 写入临时文件
|
||||
const tempDataPath = path.join(this.tempDir, 'data.json')
|
||||
await fs.writeFile(tempDataPath, data)
|
||||
onProgress({ stage: 'writing_data', progress: 20, total: 100 })
|
||||
|
||||
// 复制 Data 目录到临时目录
|
||||
const sourcePath = path.join(app.getPath('userData'), 'Data')
|
||||
const tempDataDir = path.join(this.tempDir, 'Data')
|
||||
await fs.copy(sourcePath, tempDataDir)
|
||||
|
||||
// 获取源目录总大小
|
||||
const totalSize = await this.getDirSize(sourcePath)
|
||||
let copiedSize = 0
|
||||
|
||||
// 使用流式复制
|
||||
await this.copyDirWithProgress(sourcePath, tempDataDir, (size) => {
|
||||
copiedSize += size
|
||||
const progress = Math.min(80, 20 + Math.floor((copiedSize / totalSize) * 60))
|
||||
onProgress({ stage: 'copying_files', progress, total: 100 })
|
||||
})
|
||||
|
||||
await this.setWritableRecursive(tempDataDir)
|
||||
onProgress({ stage: 'compressing', progress: 80, total: 100 })
|
||||
|
||||
// 使用 adm-zip 创建压缩文件
|
||||
const zip = new AdmZip()
|
||||
@@ -44,6 +115,7 @@ class BackupManager {
|
||||
|
||||
// 清理临时目录
|
||||
await fs.remove(this.tempDir)
|
||||
onProgress({ stage: 'completed', progress: 100, total: 100 })
|
||||
|
||||
Logger.log('Backup completed successfully')
|
||||
return backupedFilePath
|
||||
@@ -54,34 +126,54 @@ class BackupManager {
|
||||
}
|
||||
|
||||
async restore(_: Electron.IpcMainInvokeEvent, backupPath: string): Promise<string> {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
|
||||
const onProgress = (processData: { stage: string; progress: number; total: number }) => {
|
||||
mainWindow?.webContents.send('restore-progress', processData)
|
||||
Logger.log('[BackupManager] restore progress', processData)
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建临时目录
|
||||
await fs.ensureDir(this.tempDir)
|
||||
onProgress({ stage: 'preparing', progress: 0, total: 100 })
|
||||
|
||||
Logger.log('[backup] step 1: unzip backup file', this.tempDir)
|
||||
|
||||
// 使用 adm-zip 解压
|
||||
const zip = new AdmZip(backupPath)
|
||||
zip.extractAllTo(this.tempDir, true) // true 表示覆盖已存在的文件
|
||||
onProgress({ stage: 'extracting', progress: 20, total: 100 })
|
||||
|
||||
Logger.log('[backup] step 2: read data.json')
|
||||
|
||||
// 读取 data.json
|
||||
const dataPath = path.join(this.tempDir, 'data.json')
|
||||
const data = await fs.readFile(dataPath, 'utf-8')
|
||||
onProgress({ stage: 'reading_data', progress: 40, total: 100 })
|
||||
|
||||
Logger.log('[backup] step 3: restore Data directory')
|
||||
|
||||
// 恢复 Data 目录
|
||||
const sourcePath = path.join(this.tempDir, 'Data')
|
||||
const destPath = path.join(app.getPath('userData'), 'Data')
|
||||
|
||||
// 获取源目录总大小
|
||||
const totalSize = await this.getDirSize(sourcePath)
|
||||
let copiedSize = 0
|
||||
|
||||
await this.setWritableRecursive(destPath)
|
||||
await fs.remove(destPath)
|
||||
await fs.copy(sourcePath, destPath)
|
||||
|
||||
// 使用流式复制
|
||||
await this.copyDirWithProgress(sourcePath, destPath, (size) => {
|
||||
copiedSize += size
|
||||
const progress = Math.min(90, 40 + Math.floor((copiedSize / totalSize) * 50))
|
||||
onProgress({ stage: 'copying_files', progress, total: 100 })
|
||||
})
|
||||
|
||||
Logger.log('[backup] step 4: clean up temp directory')
|
||||
|
||||
// 清理临时目录
|
||||
await this.setWritableRecursive(this.tempDir)
|
||||
await fs.remove(this.tempDir)
|
||||
onProgress({ stage: 'completed', progress: 100, total: 100 })
|
||||
|
||||
Logger.log('[backup] step 5: Restore completed successfully')
|
||||
|
||||
@@ -116,6 +208,44 @@ class BackupManager {
|
||||
|
||||
return await this.restore(_, backupedFilePath)
|
||||
}
|
||||
|
||||
private async getDirSize(dirPath: string): Promise<number> {
|
||||
let size = 0
|
||||
const items = await fs.readdir(dirPath, { withFileTypes: true })
|
||||
|
||||
for (const item of items) {
|
||||
const fullPath = path.join(dirPath, item.name)
|
||||
if (item.isDirectory()) {
|
||||
size += await this.getDirSize(fullPath)
|
||||
} else {
|
||||
const stats = await fs.stat(fullPath)
|
||||
size += stats.size
|
||||
}
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
private async copyDirWithProgress(
|
||||
source: string,
|
||||
destination: string,
|
||||
onProgress: (size: number) => void
|
||||
): Promise<void> {
|
||||
const items = await fs.readdir(source, { withFileTypes: true })
|
||||
|
||||
for (const item of items) {
|
||||
const sourcePath = path.join(source, item.name)
|
||||
const destPath = path.join(destination, item.name)
|
||||
|
||||
if (item.isDirectory()) {
|
||||
await fs.ensureDir(destPath)
|
||||
await this.copyDirWithProgress(sourcePath, destPath, onProgress)
|
||||
} else {
|
||||
const stats = await fs.stat(sourcePath)
|
||||
await fs.copy(sourcePath, destPath)
|
||||
onProgress(stats.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default BackupManager
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
// ExportService
|
||||
|
||||
import { AlignmentType, BorderStyle, Document, HeadingLevel, Packer, Paragraph, ShadingType, TextRun } from 'docx'
|
||||
import {
|
||||
AlignmentType,
|
||||
BorderStyle,
|
||||
Document,
|
||||
ExternalHyperlink,
|
||||
HeadingLevel,
|
||||
Packer,
|
||||
Paragraph,
|
||||
ShadingType,
|
||||
Table,
|
||||
TableCell,
|
||||
TableRow,
|
||||
TextRun,
|
||||
VerticalAlign,
|
||||
WidthType
|
||||
} from 'docx'
|
||||
import { dialog } from 'electron'
|
||||
import Logger from 'electron-log'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
@@ -21,13 +36,54 @@ export class ExportService {
|
||||
const tokens = this.md.parse(markdown, {})
|
||||
const elements: any[] = []
|
||||
let listLevel = 0
|
||||
let currentTable: Table | null = null
|
||||
let currentRowCells: TableCell[] = []
|
||||
let isHeaderRow = false
|
||||
let tableColumnCount = 0
|
||||
let tableRows: TableRow[] = [] // Store rows temporarily
|
||||
|
||||
const processInlineTokens = (tokens: any[]): TextRun[] => {
|
||||
const runs: TextRun[] = []
|
||||
for (const token of tokens) {
|
||||
const processInlineTokens = (tokens: any[], isHeaderRow: boolean): (TextRun | ExternalHyperlink)[] => {
|
||||
const runs: (TextRun | ExternalHyperlink)[] = []
|
||||
let linkText = ''
|
||||
let linkUrl = ''
|
||||
let insideLink = false
|
||||
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
const token = tokens[i]
|
||||
switch (token.type) {
|
||||
case 'link_open':
|
||||
insideLink = true
|
||||
linkUrl = token.attrs.find((attr: [string, string]) => attr[0] === 'href')[1]
|
||||
linkText = tokens[i + 1].content
|
||||
i += 1
|
||||
break
|
||||
case 'link_close':
|
||||
if (insideLink && linkUrl && linkText) {
|
||||
// Handle any accumulated link text with the ExternalHyperlink
|
||||
runs.push(
|
||||
new ExternalHyperlink({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: linkText,
|
||||
style: 'Hyperlink',
|
||||
color: '0000FF',
|
||||
underline: {
|
||||
type: 'single'
|
||||
}
|
||||
})
|
||||
],
|
||||
link: linkUrl
|
||||
})
|
||||
)
|
||||
|
||||
// Reset link variables
|
||||
linkText = ''
|
||||
linkUrl = ''
|
||||
insideLink = false
|
||||
}
|
||||
break
|
||||
case 'text':
|
||||
runs.push(new TextRun(token.content))
|
||||
runs.push(new TextRun({ text: token.content, bold: isHeaderRow ? true : false }))
|
||||
break
|
||||
case 'strong':
|
||||
runs.push(new TextRun({ text: token.content, bold: true }))
|
||||
@@ -45,7 +101,6 @@ export class ExportService {
|
||||
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
const token = tokens[i]
|
||||
|
||||
switch (token.type) {
|
||||
case 'heading_open':
|
||||
// 获取标题级别 (h1 -> h6)
|
||||
@@ -68,7 +123,7 @@ export class ExportService {
|
||||
const inlineTokens = tokens[i + 1].children || []
|
||||
elements.push(
|
||||
new Paragraph({
|
||||
children: processInlineTokens(inlineTokens),
|
||||
children: processInlineTokens(inlineTokens, false),
|
||||
spacing: {
|
||||
before: 120,
|
||||
after: 120
|
||||
@@ -93,7 +148,7 @@ export class ExportService {
|
||||
children: [
|
||||
new TextRun({ text: '•', bold: true }),
|
||||
new TextRun({ text: '\t' }),
|
||||
...processInlineTokens(itemInlineTokens)
|
||||
...processInlineTokens(itemInlineTokens, false)
|
||||
],
|
||||
indent: {
|
||||
left: listLevel * 720
|
||||
@@ -171,6 +226,116 @@ export class ExportService {
|
||||
)
|
||||
i += 3
|
||||
break
|
||||
|
||||
// 表格处理
|
||||
case 'table_open':
|
||||
tableRows = [] // Reset table rows for new table
|
||||
break
|
||||
|
||||
case 'thead_open':
|
||||
isHeaderRow = true
|
||||
break
|
||||
|
||||
case 'tbody_open':
|
||||
isHeaderRow = false
|
||||
break
|
||||
|
||||
case 'tr_open':
|
||||
currentRowCells = []
|
||||
break
|
||||
|
||||
case 'tr_close':
|
||||
const row = new TableRow({
|
||||
children: currentRowCells,
|
||||
tableHeader: isHeaderRow
|
||||
})
|
||||
tableRows.push(row)
|
||||
// 计算表格有多少列(针对第一行)
|
||||
if (tableColumnCount === 0) {
|
||||
tableColumnCount = currentRowCells.length
|
||||
}
|
||||
break
|
||||
|
||||
case 'th_open':
|
||||
case 'td_open':
|
||||
const isFirstColumn = currentRowCells.length === 0 // 判断是否是第一列
|
||||
const borders = {
|
||||
top: {
|
||||
style: BorderStyle.NONE
|
||||
},
|
||||
bottom: isHeaderRow
|
||||
? {
|
||||
style: BorderStyle.SINGLE,
|
||||
size: 0.5,
|
||||
color: '000000'
|
||||
}
|
||||
: {
|
||||
style: BorderStyle.NONE
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.NONE
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.NONE
|
||||
}
|
||||
}
|
||||
const cellContent = tokens[i + 1]
|
||||
const cellOptions = {
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: cellContent.children
|
||||
? processInlineTokens(cellContent.children, isHeaderRow || isFirstColumn)
|
||||
: [new TextRun({ text: cellContent.content || '', bold: isHeaderRow || isFirstColumn })],
|
||||
alignment: AlignmentType.CENTER
|
||||
})
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
borders: borders
|
||||
}
|
||||
currentRowCells.push(new TableCell(cellOptions))
|
||||
i += 2 // 跳过内容和结束标记
|
||||
break
|
||||
case 'table_close':
|
||||
// Create table with the collected rows - avoid using protected properties
|
||||
// Create the table with all rows
|
||||
currentTable = new Table({
|
||||
width: {
|
||||
size: 100,
|
||||
type: WidthType.PERCENTAGE
|
||||
},
|
||||
rows: tableRows,
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.SINGLE,
|
||||
size: 1,
|
||||
color: '000000'
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.SINGLE,
|
||||
size: 1,
|
||||
color: '000000'
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.NONE
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.NONE
|
||||
},
|
||||
insideHorizontal: {
|
||||
style: BorderStyle.NONE
|
||||
},
|
||||
insideVertical: {
|
||||
style: BorderStyle.NONE
|
||||
}
|
||||
}
|
||||
})
|
||||
elements.push(currentTable)
|
||||
currentTable = null
|
||||
tableColumnCount = 0
|
||||
tableRows = []
|
||||
currentRowCells = []
|
||||
isHeaderRow = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { getFileType } from '@main/utils/file'
|
||||
import { getFilesDir, getFileType, getTempDir } from '@main/utils/file'
|
||||
import { documentExts, imageExts } from '@shared/config/constant'
|
||||
import { FileType } from '@types'
|
||||
import * as crypto from 'crypto'
|
||||
import {
|
||||
app,
|
||||
dialog,
|
||||
OpenDialogOptions,
|
||||
OpenDialogReturnValue,
|
||||
@@ -21,8 +20,8 @@ import { chdir } from 'process'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
class FileStorage {
|
||||
private storageDir = path.join(app.getPath('userData'), 'Data', 'Files')
|
||||
private tempDir = path.join(app.getPath('temp'), 'CherryStudio')
|
||||
private storageDir = getFilesDir()
|
||||
private tempDir = getTempDir()
|
||||
|
||||
constructor() {
|
||||
this.initStorageDir()
|
||||
@@ -70,7 +69,7 @@ class FileStorage {
|
||||
origin_name: file,
|
||||
name: file + ext,
|
||||
path: storedFilePath,
|
||||
created_at: storedStats.birthtime,
|
||||
created_at: storedStats.birthtime.toISOString(),
|
||||
size: storedStats.size,
|
||||
ext,
|
||||
type: getFileType(ext),
|
||||
@@ -109,7 +108,7 @@ class FileStorage {
|
||||
origin_name: path.basename(filePath),
|
||||
name: path.basename(filePath),
|
||||
path: filePath,
|
||||
created_at: stats.birthtime,
|
||||
created_at: stats.birthtime.toISOString(),
|
||||
size: stats.size,
|
||||
ext: ext,
|
||||
type: fileType,
|
||||
@@ -174,7 +173,7 @@ class FileStorage {
|
||||
origin_name,
|
||||
name: uuid + ext,
|
||||
path: destPath,
|
||||
created_at: stats.birthtime,
|
||||
created_at: stats.birthtime.toISOString(),
|
||||
size: stats.size,
|
||||
ext: ext,
|
||||
type: fileType,
|
||||
@@ -198,7 +197,7 @@ class FileStorage {
|
||||
origin_name: path.basename(filePath),
|
||||
name: path.basename(filePath),
|
||||
path: filePath,
|
||||
created_at: stats.birthtime,
|
||||
created_at: stats.birthtime.toISOString(),
|
||||
size: stats.size,
|
||||
ext: ext,
|
||||
type: fileType,
|
||||
@@ -255,7 +254,8 @@ class FileStorage {
|
||||
const filePath = path.join(this.storageDir, id)
|
||||
const data = await fs.promises.readFile(filePath)
|
||||
const base64 = data.toString('base64')
|
||||
const mime = `image/${path.extname(filePath).slice(1)}`
|
||||
const ext = path.extname(filePath).slice(1) == 'jpg' ? 'jpeg' : path.extname(filePath).slice(1)
|
||||
const mime = `image/${ext}`
|
||||
return {
|
||||
mime,
|
||||
base64,
|
||||
@@ -416,7 +416,7 @@ class FileStorage {
|
||||
origin_name: filename,
|
||||
name: uuid + ext,
|
||||
path: destPath,
|
||||
created_at: stats.birthtime,
|
||||
created_at: stats.birthtime.toISOString(),
|
||||
size: stats.size,
|
||||
ext: ext,
|
||||
type: fileType,
|
||||
|
||||
@@ -3,12 +3,14 @@ import { FileType } from '@types'
|
||||
import fs from 'fs'
|
||||
|
||||
import { CacheService } from './CacheService'
|
||||
import { proxyManager } from './ProxyManager'
|
||||
|
||||
export class GeminiService {
|
||||
private static readonly FILE_LIST_CACHE_KEY = 'gemini_file_list'
|
||||
private static readonly CACHE_DURATION = 3000
|
||||
|
||||
static async uploadFile(_: Electron.IpcMainInvokeEvent, file: FileType, apiKey: string) {
|
||||
proxyManager.setGlobalProxy()
|
||||
const fileManager = new GoogleAIFileManager(apiKey)
|
||||
const uploadResult = await fileManager.uploadFile(file.path, {
|
||||
mimeType: 'application/pdf',
|
||||
@@ -29,6 +31,7 @@ export class GeminiService {
|
||||
file: FileType,
|
||||
apiKey: string
|
||||
): Promise<FileMetadataResponse | undefined> {
|
||||
proxyManager.setGlobalProxy()
|
||||
const fileManager = new GoogleAIFileManager(apiKey)
|
||||
|
||||
const cachedResponse = CacheService.get<any>(GeminiService.FILE_LIST_CACHE_KEY)
|
||||
@@ -52,11 +55,13 @@ export class GeminiService {
|
||||
}
|
||||
|
||||
static async listFiles(_: Electron.IpcMainInvokeEvent, apiKey: string) {
|
||||
proxyManager.setGlobalProxy()
|
||||
const fileManager = new GoogleAIFileManager(apiKey)
|
||||
return await fileManager.listFiles()
|
||||
}
|
||||
|
||||
static async deleteFile(_: Electron.IpcMainInvokeEvent, apiKey: string, fileId: string) {
|
||||
proxyManager.setGlobalProxy()
|
||||
const fileManager = new GoogleAIFileManager(apiKey)
|
||||
await fileManager.deleteFile(fileId)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/**
|
||||
* Knowledge Service - Manages knowledge bases using RAG (Retrieval-Augmented Generation)
|
||||
*
|
||||
* This service handles creation, management, and querying of knowledge bases from various sources
|
||||
* including files, directories, URLs, sitemaps, and notes.
|
||||
*
|
||||
* Features:
|
||||
* - Concurrent task processing with workload management
|
||||
* - Multiple data source support
|
||||
* - Vector database integration
|
||||
*
|
||||
* For detailed documentation, see:
|
||||
* @see {@link ../../../docs/technical/KnowledgeService.md}
|
||||
*/
|
||||
|
||||
import * as fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
@@ -8,15 +23,78 @@ import { SitemapLoader } from '@llm-tools/embedjs-loader-sitemap'
|
||||
import { WebLoader } from '@llm-tools/embedjs-loader-web'
|
||||
import { AzureOpenAiEmbeddings, OpenAiEmbeddings } from '@llm-tools/embedjs-openai'
|
||||
import { addFileLoader } from '@main/loader'
|
||||
import { proxyManager } from '@main/services/ProxyManager'
|
||||
import { windowService } from '@main/services/WindowService'
|
||||
import { getInstanceName } from '@main/utils'
|
||||
import { getAllFiles } from '@main/utils/file'
|
||||
import type { LoaderReturn } from '@shared/config/types'
|
||||
import { FileType, KnowledgeBaseParams, KnowledgeItem } from '@types'
|
||||
import { app } from 'electron'
|
||||
import Logger from 'electron-log'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
export interface KnowledgeBaseAddItemOptions {
|
||||
base: KnowledgeBaseParams
|
||||
item: KnowledgeItem
|
||||
forceReload?: boolean
|
||||
}
|
||||
|
||||
interface KnowledgeBaseAddItemOptionsNonNullableAttribute {
|
||||
base: KnowledgeBaseParams
|
||||
item: KnowledgeItem
|
||||
forceReload: boolean
|
||||
}
|
||||
|
||||
interface EvaluateTaskWorkload {
|
||||
workload: number
|
||||
}
|
||||
|
||||
type LoaderDoneReturn = LoaderReturn | null
|
||||
|
||||
enum LoaderTaskItemState {
|
||||
PENDING,
|
||||
PROCESSING,
|
||||
DONE
|
||||
}
|
||||
|
||||
interface LoaderTaskItem {
|
||||
state: LoaderTaskItemState
|
||||
task: () => Promise<unknown>
|
||||
evaluateTaskWorkload: EvaluateTaskWorkload
|
||||
}
|
||||
|
||||
interface LoaderTask {
|
||||
loaderTasks: LoaderTaskItem[]
|
||||
loaderDoneReturn: LoaderDoneReturn
|
||||
}
|
||||
|
||||
interface LoaderTaskOfSet {
|
||||
loaderTasks: Set<LoaderTaskItem>
|
||||
loaderDoneReturn: LoaderDoneReturn
|
||||
}
|
||||
|
||||
interface QueueTaskItem {
|
||||
taskPromise: () => Promise<unknown>
|
||||
resolve: () => void
|
||||
evaluateTaskWorkload: EvaluateTaskWorkload
|
||||
}
|
||||
|
||||
const loaderTaskIntoOfSet = (loaderTask: LoaderTask): LoaderTaskOfSet => {
|
||||
return {
|
||||
loaderTasks: new Set(loaderTask.loaderTasks),
|
||||
loaderDoneReturn: loaderTask.loaderDoneReturn
|
||||
}
|
||||
}
|
||||
|
||||
class KnowledgeService {
|
||||
private storageDir = path.join(app.getPath('userData'), 'Data', 'KnowledgeBase')
|
||||
// Byte based
|
||||
private workload = 0
|
||||
private processingItemCount = 0
|
||||
private knowledgeItemProcessingQueueMappingPromise: Map<LoaderTaskOfSet, () => void> = new Map()
|
||||
private static MAXIMUM_WORKLOAD = 1024 * 1024 * 80
|
||||
private static MAXIMUM_PROCESSING_ITEM_COUNT = 30
|
||||
private static ERROR_LOADER_RETURN: LoaderReturn = { entriesAdded: 0, uniqueId: '', uniqueIds: [''], loaderType: '' }
|
||||
|
||||
constructor() {
|
||||
this.initStorageDir()
|
||||
@@ -46,13 +124,14 @@ class KnowledgeService {
|
||||
azureOpenAIApiVersion: apiVersion,
|
||||
azureOpenAIApiDeploymentName: model,
|
||||
azureOpenAIApiInstanceName: getInstanceName(baseURL),
|
||||
configuration: { httpAgent: proxyManager.getProxyAgent() },
|
||||
dimensions,
|
||||
batchSize
|
||||
})
|
||||
: new OpenAiEmbeddings({
|
||||
model,
|
||||
apiKey,
|
||||
configuration: { baseURL },
|
||||
configuration: { baseURL, httpAgent: proxyManager.getProxyAgent() },
|
||||
dimensions,
|
||||
batchSize
|
||||
})
|
||||
@@ -77,79 +156,313 @@ class KnowledgeService {
|
||||
}
|
||||
}
|
||||
|
||||
public add = async (
|
||||
_: Electron.IpcMainInvokeEvent,
|
||||
{ base, item, forceReload = false }: { base: KnowledgeBaseParams; item: KnowledgeItem; forceReload: boolean }
|
||||
): Promise<LoaderReturn> => {
|
||||
const ragApplication = await this.getRagApplication(base)
|
||||
private maximumLoad() {
|
||||
return (
|
||||
this.processingItemCount >= KnowledgeService.MAXIMUM_PROCESSING_ITEM_COUNT ||
|
||||
this.workload >= KnowledgeService.MAXIMUM_WORKLOAD
|
||||
)
|
||||
}
|
||||
|
||||
if (item.type === 'directory') {
|
||||
private fileTask(
|
||||
ragApplication: RAGApplication,
|
||||
options: KnowledgeBaseAddItemOptionsNonNullableAttribute
|
||||
): LoaderTask {
|
||||
const { base, item, forceReload } = options
|
||||
const file = item.content as FileType
|
||||
|
||||
const loaderTask: LoaderTask = {
|
||||
loaderTasks: [
|
||||
{
|
||||
state: LoaderTaskItemState.PENDING,
|
||||
task: () =>
|
||||
addFileLoader(ragApplication, file, base, forceReload)
|
||||
.then((result) => {
|
||||
loaderTask.loaderDoneReturn = result
|
||||
return result
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.error(err)
|
||||
return KnowledgeService.ERROR_LOADER_RETURN
|
||||
}),
|
||||
evaluateTaskWorkload: { workload: file.size }
|
||||
}
|
||||
],
|
||||
loaderDoneReturn: null
|
||||
}
|
||||
|
||||
return loaderTask
|
||||
}
|
||||
|
||||
private directoryTask(
|
||||
ragApplication: RAGApplication,
|
||||
options: KnowledgeBaseAddItemOptionsNonNullableAttribute
|
||||
): LoaderTask {
|
||||
const { base, item, forceReload } = options
|
||||
const directory = item.content as string
|
||||
const files = getAllFiles(directory)
|
||||
const loaderPromises = files.map((file) => addFileLoader(ragApplication, file, base, forceReload))
|
||||
const loaderResults = await Promise.all(loaderPromises)
|
||||
const uniqueIds = loaderResults.map((result) => result.uniqueId)
|
||||
return {
|
||||
entriesAdded: loaderResults.length,
|
||||
const totalFiles = files.length
|
||||
let processedFiles = 0
|
||||
|
||||
const sendDirectoryProcessingPercent = (totalFiles: number, processedFiles: number) => {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
mainWindow?.webContents.send('directory-processing-percent', {
|
||||
itemId: item.id,
|
||||
percent: (processedFiles / totalFiles) * 100
|
||||
})
|
||||
}
|
||||
|
||||
const loaderDoneReturn: LoaderDoneReturn = {
|
||||
entriesAdded: 0,
|
||||
uniqueId: `DirectoryLoader_${uuidv4()}`,
|
||||
uniqueIds,
|
||||
uniqueIds: [],
|
||||
loaderType: 'DirectoryLoader'
|
||||
} as LoaderReturn
|
||||
}
|
||||
const loaderTasks: LoaderTaskItem[] = []
|
||||
for (const file of files) {
|
||||
loaderTasks.push({
|
||||
state: LoaderTaskItemState.PENDING,
|
||||
task: () =>
|
||||
addFileLoader(ragApplication, file, base, forceReload)
|
||||
.then((result) => {
|
||||
loaderDoneReturn.entriesAdded += 1
|
||||
processedFiles += 1
|
||||
sendDirectoryProcessingPercent(totalFiles, processedFiles)
|
||||
loaderDoneReturn.uniqueIds.push(result.uniqueId)
|
||||
return result
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.error(err)
|
||||
return KnowledgeService.ERROR_LOADER_RETURN
|
||||
}),
|
||||
evaluateTaskWorkload: { workload: file.size }
|
||||
})
|
||||
}
|
||||
|
||||
if (item.type === 'url') {
|
||||
const content = item.content as string
|
||||
if (content.startsWith('http')) {
|
||||
const loaderReturn = await ragApplication.addLoader(
|
||||
new WebLoader({ urlOrContent: content, chunkSize: base.chunkSize, chunkOverlap: base.chunkOverlap }) as any,
|
||||
forceReload
|
||||
)
|
||||
return {
|
||||
entriesAdded: loaderReturn.entriesAdded,
|
||||
uniqueId: loaderReturn.uniqueId,
|
||||
uniqueIds: [loaderReturn.uniqueId],
|
||||
loaderType: loaderReturn.loaderType
|
||||
} as LoaderReturn
|
||||
loaderTasks,
|
||||
loaderDoneReturn
|
||||
}
|
||||
}
|
||||
|
||||
if (item.type === 'sitemap') {
|
||||
private urlTask(
|
||||
ragApplication: RAGApplication,
|
||||
options: KnowledgeBaseAddItemOptionsNonNullableAttribute
|
||||
): LoaderTask {
|
||||
const { base, item, forceReload } = options
|
||||
const content = item.content as string
|
||||
// @ts-ignore loader type
|
||||
const loaderReturn = await ragApplication.addLoader(
|
||||
|
||||
const loaderTask: LoaderTask = {
|
||||
loaderTasks: [
|
||||
{
|
||||
state: LoaderTaskItemState.PENDING,
|
||||
task: () => {
|
||||
const loaderReturn = ragApplication.addLoader(
|
||||
new WebLoader({
|
||||
urlOrContent: content,
|
||||
chunkSize: base.chunkSize,
|
||||
chunkOverlap: base.chunkOverlap
|
||||
}),
|
||||
forceReload
|
||||
) as Promise<LoaderReturn>
|
||||
|
||||
return loaderReturn
|
||||
.then((result) => {
|
||||
const { entriesAdded, uniqueId, loaderType } = result
|
||||
loaderTask.loaderDoneReturn = {
|
||||
entriesAdded: entriesAdded,
|
||||
uniqueId: uniqueId,
|
||||
uniqueIds: [uniqueId],
|
||||
loaderType: loaderType
|
||||
}
|
||||
return result
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.error(err)
|
||||
return KnowledgeService.ERROR_LOADER_RETURN
|
||||
})
|
||||
},
|
||||
evaluateTaskWorkload: { workload: 1024 * 1024 * 2 }
|
||||
}
|
||||
],
|
||||
loaderDoneReturn: null
|
||||
}
|
||||
return loaderTask
|
||||
}
|
||||
|
||||
private sitemapTask(
|
||||
ragApplication: RAGApplication,
|
||||
options: KnowledgeBaseAddItemOptionsNonNullableAttribute
|
||||
): LoaderTask {
|
||||
const { base, item, forceReload } = options
|
||||
const content = item.content as string
|
||||
|
||||
const loaderTask: LoaderTask = {
|
||||
loaderTasks: [
|
||||
{
|
||||
state: LoaderTaskItemState.PENDING,
|
||||
task: () =>
|
||||
ragApplication
|
||||
.addLoader(
|
||||
new SitemapLoader({ url: content, chunkSize: base.chunkSize, chunkOverlap: base.chunkOverlap }) as any,
|
||||
forceReload
|
||||
)
|
||||
return {
|
||||
entriesAdded: loaderReturn.entriesAdded,
|
||||
uniqueId: loaderReturn.uniqueId,
|
||||
uniqueIds: [loaderReturn.uniqueId],
|
||||
loaderType: loaderReturn.loaderType
|
||||
} as LoaderReturn
|
||||
.then((result) => {
|
||||
const { entriesAdded, uniqueId, loaderType } = result
|
||||
loaderTask.loaderDoneReturn = {
|
||||
entriesAdded: entriesAdded,
|
||||
uniqueId: uniqueId,
|
||||
uniqueIds: [uniqueId],
|
||||
loaderType: loaderType
|
||||
}
|
||||
return result
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.error(err)
|
||||
return KnowledgeService.ERROR_LOADER_RETURN
|
||||
}),
|
||||
evaluateTaskWorkload: { workload: 1024 * 1024 * 20 }
|
||||
}
|
||||
],
|
||||
loaderDoneReturn: null
|
||||
}
|
||||
return loaderTask
|
||||
}
|
||||
|
||||
if (item.type === 'note') {
|
||||
private noteTask(
|
||||
ragApplication: RAGApplication,
|
||||
options: KnowledgeBaseAddItemOptionsNonNullableAttribute
|
||||
): LoaderTask {
|
||||
const { base, item, forceReload } = options
|
||||
const content = item.content as string
|
||||
console.debug('chunkSize', base.chunkSize)
|
||||
const loaderReturn = await ragApplication.addLoader(
|
||||
|
||||
const encoder = new TextEncoder()
|
||||
const contentBytes = encoder.encode(content)
|
||||
const loaderTask: LoaderTask = {
|
||||
loaderTasks: [
|
||||
{
|
||||
state: LoaderTaskItemState.PENDING,
|
||||
task: () => {
|
||||
const loaderReturn = ragApplication.addLoader(
|
||||
new TextLoader({ text: content, chunkSize: base.chunkSize, chunkOverlap: base.chunkOverlap }),
|
||||
forceReload
|
||||
)
|
||||
return {
|
||||
entriesAdded: loaderReturn.entriesAdded,
|
||||
uniqueId: loaderReturn.uniqueId,
|
||||
uniqueIds: [loaderReturn.uniqueId],
|
||||
loaderType: loaderReturn.loaderType
|
||||
} as LoaderReturn
|
||||
) as Promise<LoaderReturn>
|
||||
|
||||
return loaderReturn
|
||||
.then(({ entriesAdded, uniqueId, loaderType }) => {
|
||||
loaderTask.loaderDoneReturn = {
|
||||
entriesAdded: entriesAdded,
|
||||
uniqueId: uniqueId,
|
||||
uniqueIds: [uniqueId],
|
||||
loaderType: loaderType
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.error(err)
|
||||
return KnowledgeService.ERROR_LOADER_RETURN
|
||||
})
|
||||
},
|
||||
evaluateTaskWorkload: { workload: contentBytes.length }
|
||||
}
|
||||
],
|
||||
loaderDoneReturn: null
|
||||
}
|
||||
return loaderTask
|
||||
}
|
||||
|
||||
if (item.type === 'file') {
|
||||
const file = item.content as FileType
|
||||
|
||||
return await addFileLoader(ragApplication, file, base, forceReload)
|
||||
private processingQueueHandle() {
|
||||
const getSubtasksUntilMaximumLoad = (): QueueTaskItem[] => {
|
||||
const queueTaskList: QueueTaskItem[] = []
|
||||
that: for (const [task, resolve] of this.knowledgeItemProcessingQueueMappingPromise) {
|
||||
for (const item of task.loaderTasks) {
|
||||
if (this.maximumLoad()) {
|
||||
break that
|
||||
}
|
||||
|
||||
return { entriesAdded: 0, uniqueId: '', uniqueIds: [''], loaderType: '' }
|
||||
const { state, task: taskPromise, evaluateTaskWorkload } = item
|
||||
|
||||
if (state !== LoaderTaskItemState.PENDING) {
|
||||
continue
|
||||
}
|
||||
|
||||
const { workload } = evaluateTaskWorkload
|
||||
this.workload += workload
|
||||
this.processingItemCount += 1
|
||||
item.state = LoaderTaskItemState.PROCESSING
|
||||
queueTaskList.push({
|
||||
taskPromise: () =>
|
||||
taskPromise().then(() => {
|
||||
this.workload -= workload
|
||||
this.processingItemCount -= 1
|
||||
task.loaderTasks.delete(item)
|
||||
if (task.loaderTasks.size === 0) {
|
||||
this.knowledgeItemProcessingQueueMappingPromise.delete(task)
|
||||
resolve()
|
||||
}
|
||||
this.processingQueueHandle()
|
||||
}),
|
||||
resolve: () => {},
|
||||
evaluateTaskWorkload
|
||||
})
|
||||
}
|
||||
}
|
||||
return queueTaskList
|
||||
}
|
||||
const subTasks = getSubtasksUntilMaximumLoad()
|
||||
if (subTasks.length > 0) {
|
||||
const subTaskPromises = subTasks.map(({ taskPromise }) => taskPromise())
|
||||
Promise.all(subTaskPromises).then(() => {
|
||||
subTasks.forEach(({ resolve }) => resolve())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private appendProcessingQueue(task: LoaderTask): Promise<LoaderReturn> {
|
||||
return new Promise((resolve) => {
|
||||
this.knowledgeItemProcessingQueueMappingPromise.set(loaderTaskIntoOfSet(task), () => {
|
||||
resolve(task.loaderDoneReturn!)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public add = (_: Electron.IpcMainInvokeEvent, options: KnowledgeBaseAddItemOptions): Promise<LoaderReturn> => {
|
||||
proxyManager.setGlobalProxy()
|
||||
return new Promise((resolve) => {
|
||||
const { base, item, forceReload = false } = options
|
||||
const optionsNonNullableAttribute = { base, item, forceReload }
|
||||
this.getRagApplication(base)
|
||||
.then((ragApplication) => {
|
||||
const task = (() => {
|
||||
switch (item.type) {
|
||||
case 'file':
|
||||
return this.fileTask(ragApplication, optionsNonNullableAttribute)
|
||||
case 'directory':
|
||||
return this.directoryTask(ragApplication, optionsNonNullableAttribute)
|
||||
case 'url':
|
||||
return this.urlTask(ragApplication, optionsNonNullableAttribute)
|
||||
case 'sitemap':
|
||||
return this.sitemapTask(ragApplication, optionsNonNullableAttribute)
|
||||
case 'note':
|
||||
return this.noteTask(ragApplication, optionsNonNullableAttribute)
|
||||
default:
|
||||
return null
|
||||
}
|
||||
})()
|
||||
|
||||
if (task) {
|
||||
this.appendProcessingQueue(task).then(() => {
|
||||
resolve(task.loaderDoneReturn!)
|
||||
})
|
||||
this.processingQueueHandle()
|
||||
} else {
|
||||
resolve(KnowledgeService.ERROR_LOADER_RETURN)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.error(err)
|
||||
resolve(KnowledgeService.ERROR_LOADER_RETURN)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public remove = async (
|
||||
|
||||
494
src/main/services/MCPService.ts
Normal file
@@ -0,0 +1,494 @@
|
||||
import { MCPServer, MCPTool } from '@types'
|
||||
import log from 'electron-log'
|
||||
import { EventEmitter } from 'events'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
import { windowService } from './WindowService'
|
||||
|
||||
/**
|
||||
* Service for managing Model Context Protocol servers and tools
|
||||
*/
|
||||
export default class MCPService extends EventEmitter {
|
||||
private servers: MCPServer[] = []
|
||||
private activeServers: Map<string, any> = new Map()
|
||||
private clients: { [key: string]: any } = {}
|
||||
private Client: any
|
||||
private stoioTransport: any
|
||||
private sseTransport: any
|
||||
private initialized = false
|
||||
private initPromise: Promise<void> | null = null
|
||||
|
||||
// Simplified server loading state management
|
||||
private readyState = {
|
||||
serversLoaded: false,
|
||||
promise: null as Promise<void> | null,
|
||||
resolve: null as ((value: void) => void) | null
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.createServerLoadingPromise()
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a promise that resolves when servers are loaded
|
||||
*/
|
||||
private createServerLoadingPromise(): void {
|
||||
this.readyState.promise = new Promise<void>((resolve) => {
|
||||
this.readyState.resolve = resolve
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Set servers received from Redux and trigger initialization if needed
|
||||
*/
|
||||
public setServers(servers: MCPServer[]): void {
|
||||
this.servers = servers
|
||||
log.info(`[MCP] Received ${servers.length} servers from Redux`)
|
||||
|
||||
// Mark servers as loaded and resolve the waiting promise
|
||||
if (!this.readyState.serversLoaded && this.readyState.resolve) {
|
||||
this.readyState.serversLoaded = true
|
||||
this.readyState.resolve()
|
||||
this.readyState.resolve = null
|
||||
}
|
||||
|
||||
// Initialize if not already initialized
|
||||
if (!this.initialized) {
|
||||
this.init().catch(this.logError('Failed to initialize MCP service'))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the MCP service if not already initialized
|
||||
*/
|
||||
public async init(): Promise<void> {
|
||||
// If already initialized, return immediately
|
||||
if (this.initialized) return
|
||||
|
||||
// If initialization is in progress, return that promise
|
||||
if (this.initPromise) return this.initPromise
|
||||
|
||||
this.initPromise = (async () => {
|
||||
try {
|
||||
// Wait for servers to be loaded from Redux
|
||||
await this.waitForServers()
|
||||
|
||||
log.info('[MCP] Starting initialization')
|
||||
|
||||
// Load SDK components in parallel for better performance
|
||||
const [Client, StdioTransport, SSETransport] = await Promise.all([
|
||||
this.importClient(),
|
||||
this.importStdioClientTransport(),
|
||||
this.importSSEClientTransport()
|
||||
])
|
||||
|
||||
this.Client = Client
|
||||
this.stoioTransport = StdioTransport
|
||||
this.sseTransport = SSETransport
|
||||
|
||||
// Mark as initialized before loading servers
|
||||
this.initialized = true
|
||||
|
||||
// Load active servers
|
||||
await this.loadActiveServers()
|
||||
log.info('[MCP] Initialization completed successfully')
|
||||
|
||||
return
|
||||
} catch (err) {
|
||||
this.initialized = false // Reset flag on error
|
||||
log.error('[MCP] Failed to initialize:', err)
|
||||
throw err
|
||||
} finally {
|
||||
this.initPromise = null
|
||||
}
|
||||
})()
|
||||
|
||||
return this.initPromise
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for servers to be loaded from Redux
|
||||
*/
|
||||
private async waitForServers(): Promise<void> {
|
||||
if (!this.readyState.serversLoaded && this.readyState.promise) {
|
||||
log.info('[MCP] Waiting for servers data from Redux...')
|
||||
await this.readyState.promise
|
||||
log.info('[MCP] Servers received, continuing initialization')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create consistent error logging functions
|
||||
*/
|
||||
private logError(message: string) {
|
||||
return (err: Error) => log.error(`[MCP] ${message}:`, err)
|
||||
}
|
||||
|
||||
/**
|
||||
* Import the MCP client SDK
|
||||
*/
|
||||
private async importClient() {
|
||||
try {
|
||||
const { Client } = await import('@modelcontextprotocol/sdk/client/index.js')
|
||||
return Client
|
||||
} catch (err) {
|
||||
log.error('[MCP] Failed to import Client:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import the stdio transport
|
||||
*/
|
||||
private async importStdioClientTransport() {
|
||||
try {
|
||||
const { StdioClientTransport } = await import('@modelcontextprotocol/sdk/client/stdio.js')
|
||||
return StdioClientTransport
|
||||
} catch (err) {
|
||||
log.error('[MCP] Failed to import StdioTransport:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import the SSE transport
|
||||
*/
|
||||
private async importSSEClientTransport() {
|
||||
try {
|
||||
const { SSEClientTransport } = await import('@modelcontextprotocol/sdk/client/sse.js')
|
||||
return SSEClientTransport
|
||||
} catch (err) {
|
||||
log.error('[MCP] Failed to import SSETransport:', err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all available MCP servers
|
||||
*/
|
||||
public async listAvailableServices(): Promise<MCPServer[]> {
|
||||
await this.ensureInitialized()
|
||||
return this.servers
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the service is initialized before operations
|
||||
*/
|
||||
private async ensureInitialized() {
|
||||
if (!this.initialized) {
|
||||
log.debug('[MCP] Ensuring initialization')
|
||||
await this.init()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new MCP server
|
||||
*/
|
||||
public async addServer(server: MCPServer): Promise<void> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
// Check for duplicate name
|
||||
if (this.servers.some((s) => s.name === server.name)) {
|
||||
throw new Error(`Server with name ${server.name} already exists`)
|
||||
}
|
||||
|
||||
// Add to servers list
|
||||
const updatedServers = [...this.servers, server]
|
||||
this.servers = updatedServers
|
||||
this.notifyReduxServersChanged(updatedServers)
|
||||
|
||||
// Activate if needed
|
||||
if (server.isActive) {
|
||||
await this.activate(server).catch(this.logError(`Failed to activate server ${server.name}`))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing MCP server
|
||||
*/
|
||||
public async updateServer(server: MCPServer): Promise<void> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
const index = this.servers.findIndex((s) => s.name === server.name)
|
||||
if (index === -1) {
|
||||
throw new Error(`Server ${server.name} not found`)
|
||||
}
|
||||
|
||||
// Check activation status change
|
||||
const wasActive = this.servers[index].isActive
|
||||
if (wasActive && !server.isActive) {
|
||||
await this.deactivate(server.name)
|
||||
} else if (!wasActive && server.isActive) {
|
||||
await this.activate(server)
|
||||
}
|
||||
|
||||
// Update servers list
|
||||
const updatedServers = [...this.servers]
|
||||
updatedServers[index] = server
|
||||
this.servers = updatedServers
|
||||
this.notifyReduxServersChanged(updatedServers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an MCP server
|
||||
*/
|
||||
public async deleteServer(serverName: string): Promise<void> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
// Deactivate if running
|
||||
if (this.clients[serverName]) {
|
||||
await this.deactivate(serverName)
|
||||
}
|
||||
|
||||
// Update servers list
|
||||
const filteredServers = this.servers.filter((s) => s.name !== serverName)
|
||||
this.servers = filteredServers
|
||||
this.notifyReduxServersChanged(filteredServers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a server's active state
|
||||
*/
|
||||
public async setServerActive(params: { name: string; isActive: boolean }): Promise<void> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
const { name, isActive } = params
|
||||
const server = this.servers.find((s) => s.name === name)
|
||||
|
||||
if (!server) {
|
||||
throw new Error(`Server ${name} not found`)
|
||||
}
|
||||
|
||||
// Update server status
|
||||
server.isActive = isActive
|
||||
this.notifyReduxServersChanged([...this.servers])
|
||||
|
||||
// Activate or deactivate as needed
|
||||
if (isActive) {
|
||||
await this.activate(server)
|
||||
} else {
|
||||
await this.deactivate(name)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Redux in the renderer process about server changes
|
||||
*/
|
||||
private notifyReduxServersChanged(servers: MCPServer[]): void {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
if (mainWindow) {
|
||||
mainWindow.webContents.send('mcp:servers-changed', servers)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate an MCP server
|
||||
*/
|
||||
public async activate(server: MCPServer): Promise<void> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
const { name, baseUrl, command, args, env } = server
|
||||
|
||||
// Skip if already running
|
||||
if (this.clients[name]) {
|
||||
log.info(`[MCP] Server ${name} is already running`)
|
||||
return
|
||||
}
|
||||
|
||||
let transport: any = null
|
||||
|
||||
try {
|
||||
// Create appropriate transport based on configuration
|
||||
if (baseUrl) {
|
||||
transport = new this.sseTransport(new URL(baseUrl))
|
||||
} else if (command) {
|
||||
let cmd: string = command
|
||||
if (command === 'npx') {
|
||||
cmd = process.platform === 'win32' ? `${command}.cmd` : command
|
||||
}
|
||||
|
||||
const mergedEnv = {
|
||||
...env,
|
||||
PATH: process.env.PATH
|
||||
}
|
||||
|
||||
transport = new this.stoioTransport({
|
||||
command: cmd,
|
||||
args,
|
||||
stderr: process.platform === 'win32' ? 'pipe' : 'inherit',
|
||||
env: mergedEnv
|
||||
})
|
||||
} else {
|
||||
throw new Error('Either baseUrl or command must be provided')
|
||||
}
|
||||
|
||||
// Create and connect client
|
||||
const client = new this.Client({ name, version: '1.0.0' }, { capabilities: {} })
|
||||
|
||||
await client.connect(transport)
|
||||
|
||||
// Store client and server info
|
||||
this.clients[name] = client
|
||||
this.activeServers.set(name, { client, server })
|
||||
|
||||
log.info(`[MCP] Server ${name} started successfully`)
|
||||
this.emit('server-started', { name })
|
||||
} catch (error) {
|
||||
log.error(`[MCP] Error activating server ${name}:`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate an MCP server
|
||||
*/
|
||||
public async deactivate(name: string): Promise<void> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
if (!this.clients[name]) {
|
||||
log.warn(`[MCP] Server ${name} is not running`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
log.info(`[MCP] Stopping server: ${name}`)
|
||||
await this.clients[name].close()
|
||||
delete this.clients[name]
|
||||
this.activeServers.delete(name)
|
||||
this.emit('server-stopped', { name })
|
||||
} catch (error) {
|
||||
log.error(`[MCP] Error deactivating server ${name}:`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tools from active MCP servers
|
||||
*/
|
||||
public async listTools(serverName?: string): Promise<MCPTool[]> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
try {
|
||||
// If server name provided, list tools for that server only
|
||||
if (serverName) {
|
||||
return await this.listToolsFromServer(serverName)
|
||||
}
|
||||
|
||||
// Otherwise list tools from all active servers
|
||||
let allTools: MCPTool[] = []
|
||||
|
||||
for (const clientName in this.clients) {
|
||||
try {
|
||||
const tools = await this.listToolsFromServer(clientName)
|
||||
allTools = allTools.concat(tools)
|
||||
} catch (error) {
|
||||
this.logError(`[MCP] Error listing tools for ${clientName}`)
|
||||
}
|
||||
}
|
||||
|
||||
log.info(`[MCP] Total tools listed: ${allTools.length}`)
|
||||
return allTools
|
||||
} catch (error) {
|
||||
this.logError('Error listing tools:')
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to list tools from a specific server
|
||||
*/
|
||||
private async listToolsFromServer(serverName: string): Promise<MCPTool[]> {
|
||||
if (!this.clients[serverName]) {
|
||||
throw new Error(`MCP Client ${serverName} not found`)
|
||||
}
|
||||
|
||||
const { tools } = await this.clients[serverName].listTools()
|
||||
return tools.map((tool: any) => ({
|
||||
...tool,
|
||||
serverName,
|
||||
id: 'f' + uuidv4().replace(/-/g, '')
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a tool on an MCP server
|
||||
*/
|
||||
public async callTool(params: { client: string; name: string; args: any }): Promise<any> {
|
||||
await this.ensureInitialized()
|
||||
|
||||
const { client, name, args } = params
|
||||
|
||||
if (!this.clients[client]) {
|
||||
throw new Error(`MCP Client ${client} not found`)
|
||||
}
|
||||
|
||||
log.info('[MCP] Calling:', client, name, args)
|
||||
|
||||
try {
|
||||
return await this.clients[client].callTool({
|
||||
name,
|
||||
arguments: args
|
||||
})
|
||||
} catch (error) {
|
||||
log.error(`[MCP] Error calling tool ${name} on ${client}:`, error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up all MCP resources
|
||||
*/
|
||||
public async cleanup(): Promise<void> {
|
||||
const clientNames = Object.keys(this.clients)
|
||||
|
||||
if (clientNames.length === 0) {
|
||||
log.info('[MCP] No active servers to clean up')
|
||||
return
|
||||
}
|
||||
|
||||
log.info(`[MCP] Cleaning up ${clientNames.length} active servers`)
|
||||
|
||||
// Deactivate all clients
|
||||
await Promise.allSettled(
|
||||
clientNames.map((name) =>
|
||||
this.deactivate(name).catch((err) => {
|
||||
log.error(`[MCP] Error during cleanup of ${name}:`, err)
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
this.clients = {}
|
||||
this.activeServers.clear()
|
||||
log.info('[MCP] All servers cleaned up')
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all active servers
|
||||
*/
|
||||
private async loadActiveServers(): Promise<void> {
|
||||
const activeServers = this.servers.filter((server) => server.isActive)
|
||||
|
||||
if (activeServers.length === 0) {
|
||||
log.info('[MCP] No active servers to load')
|
||||
return
|
||||
}
|
||||
|
||||
log.info(`[MCP] Loading ${activeServers.length} active servers`)
|
||||
|
||||
// Activate servers in parallel for better performance
|
||||
await Promise.allSettled(
|
||||
activeServers.map(async (server) => {
|
||||
try {
|
||||
await this.activate(server)
|
||||
log.info(`[MCP] Successfully activated server: ${server.name}`)
|
||||
} catch (error) {
|
||||
this.logError(`Failed to activate server ${server.name}`)
|
||||
this.emit('server-error', { name: server.name, error })
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
log.info(`[MCP] Loaded and activated ${Object.keys(this.clients).length} servers`)
|
||||
}
|
||||
}
|
||||
145
src/main/services/ProxyManager.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
import { ProxyConfig as _ProxyConfig, session } from 'electron'
|
||||
import { socksDispatcher } from 'fetch-socks'
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent'
|
||||
import { ProxyAgent, setGlobalDispatcher } from 'undici'
|
||||
|
||||
type ProxyMode = 'system' | 'custom' | 'none'
|
||||
|
||||
export interface ProxyConfig {
|
||||
mode: ProxyMode
|
||||
url?: string | null
|
||||
}
|
||||
|
||||
export class ProxyManager {
|
||||
private config: ProxyConfig
|
||||
private proxyAgent: HttpsProxyAgent | null = null
|
||||
private proxyUrl: string | null = null
|
||||
|
||||
constructor() {
|
||||
this.config = {
|
||||
mode: 'system',
|
||||
url: ''
|
||||
}
|
||||
this.monitorSystemProxy()
|
||||
}
|
||||
|
||||
private async setSessionsProxy(config: _ProxyConfig): Promise<void> {
|
||||
const sessions = [session.defaultSession, session.fromPartition('persist:webview')]
|
||||
await Promise.all(sessions.map((session) => session.setProxy(config)))
|
||||
}
|
||||
|
||||
private async monitorSystemProxy(): Promise<void> {
|
||||
setInterval(async () => {
|
||||
await this.setSystemProxy()
|
||||
}, 10000)
|
||||
}
|
||||
|
||||
async configureProxy(config: ProxyConfig): Promise<void> {
|
||||
try {
|
||||
this.config = config
|
||||
if (this.config.mode === 'system') {
|
||||
await this.setSystemProxy()
|
||||
} else if (this.config.mode == 'custom') {
|
||||
await this.setCustomProxy()
|
||||
} else {
|
||||
await this.clearProxy()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to config proxy:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
private setEnvironment(url: string): void {
|
||||
process.env.grpc_proxy = url
|
||||
process.env.HTTP_PROXY = url
|
||||
process.env.HTTPS_PROXY = url
|
||||
process.env.http_proxy = url
|
||||
process.env.https_proxy = url
|
||||
}
|
||||
|
||||
private async setSystemProxy(): Promise<void> {
|
||||
try {
|
||||
await this.setSessionsProxy({ mode: 'system' })
|
||||
const url = await this.resolveSystemProxy()
|
||||
if (url && url !== this.proxyUrl) {
|
||||
this.proxyUrl = url.toLowerCase()
|
||||
this.proxyAgent = new HttpsProxyAgent(this.proxyUrl)
|
||||
this.setEnvironment(this.proxyUrl)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to set system proxy:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
private async setCustomProxy(): Promise<void> {
|
||||
try {
|
||||
if (this.config.url) {
|
||||
this.proxyUrl = this.config.url.toLowerCase()
|
||||
this.proxyAgent = new HttpsProxyAgent(this.proxyUrl)
|
||||
this.setEnvironment(this.proxyUrl)
|
||||
await this.setSessionsProxy({ proxyRules: this.proxyUrl })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to set custom proxy:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
private async clearProxy(): Promise<void> {
|
||||
delete process.env.HTTP_PROXY
|
||||
delete process.env.HTTPS_PROXY
|
||||
await this.setSessionsProxy({})
|
||||
this.config = { mode: 'none' }
|
||||
this.proxyAgent = null
|
||||
this.proxyUrl = null
|
||||
}
|
||||
|
||||
private async resolveSystemProxy(): Promise<string | null> {
|
||||
try {
|
||||
return await this.resolveElectronProxy()
|
||||
} catch (error) {
|
||||
console.error('Failed to resolve system proxy:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private async resolveElectronProxy(): Promise<string | null> {
|
||||
try {
|
||||
const proxyString = await session.defaultSession.resolveProxy('https://dummy.com')
|
||||
const [protocol, address] = proxyString.split(';')[0].split(' ')
|
||||
return protocol === 'PROXY' ? `http://${address}` : null
|
||||
} catch (error) {
|
||||
console.error('Failed to resolve electron proxy:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
getProxyAgent(): HttpsProxyAgent | null {
|
||||
return this.proxyAgent
|
||||
}
|
||||
|
||||
getProxyUrl(): string | null {
|
||||
return this.proxyUrl
|
||||
}
|
||||
|
||||
setGlobalProxy() {
|
||||
const proxyUrl = this.proxyUrl
|
||||
if (proxyUrl) {
|
||||
const [protocol, host, port] = proxyUrl.split(':')
|
||||
if (!protocol.includes('socks')) {
|
||||
setGlobalDispatcher(new ProxyAgent(proxyUrl))
|
||||
} else {
|
||||
const dispatcher = socksDispatcher({
|
||||
port: parseInt(port),
|
||||
type: protocol === 'socks5' ? 5 : 4,
|
||||
host: host
|
||||
})
|
||||
global[Symbol.for('undici.globalDispatcher.1')] = dispatcher
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const proxyManager = new ProxyManager()
|
||||
220
src/main/services/ReduxService.ts
Normal file
@@ -0,0 +1,220 @@
|
||||
import { ipcMain } from 'electron'
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
import { windowService } from './WindowService'
|
||||
|
||||
type StoreValue = any
|
||||
type Unsubscribe = () => void
|
||||
|
||||
export class ReduxService extends EventEmitter {
|
||||
private stateCache: any = {}
|
||||
private isReady = false
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.setupIpcHandlers()
|
||||
}
|
||||
|
||||
private setupIpcHandlers() {
|
||||
// 监听 store 就绪事件
|
||||
ipcMain.handle('redux-store-ready', () => {
|
||||
this.isReady = true
|
||||
this.emit('ready')
|
||||
})
|
||||
|
||||
// 监听 store 状态变化
|
||||
ipcMain.on('redux-state-change', (_, newState) => {
|
||||
this.stateCache = newState
|
||||
this.emit('stateChange', newState)
|
||||
})
|
||||
}
|
||||
|
||||
private async waitForStoreReady(webContents: Electron.WebContents, timeout = 10000): Promise<void> {
|
||||
if (this.isReady) return
|
||||
|
||||
const startTime = Date.now()
|
||||
while (Date.now() - startTime < timeout) {
|
||||
try {
|
||||
const isReady = await webContents.executeJavaScript(`
|
||||
!!window.store && typeof window.store.getState === 'function'
|
||||
`)
|
||||
if (isReady) {
|
||||
this.isReady = true
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
// 忽略错误,继续等待
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
}
|
||||
throw new Error('Timeout waiting for Redux store to be ready')
|
||||
}
|
||||
|
||||
// 添加同步获取状态的方法
|
||||
getStateSync() {
|
||||
return this.stateCache
|
||||
}
|
||||
|
||||
// 添加同步选择器方法
|
||||
selectSync<T = StoreValue>(selector: string): T | undefined {
|
||||
try {
|
||||
// 使用 Function 构造器来安全地执行选择器
|
||||
const selectorFn = new Function('state', `return ${selector}`)
|
||||
return selectorFn(this.stateCache)
|
||||
} catch (error) {
|
||||
console.error('Failed to select from cache:', error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
// 修改 select 方法,优先使用缓存
|
||||
async select<T = StoreValue>(selector: string): Promise<T> {
|
||||
try {
|
||||
// 如果已经准备就绪,先尝试从缓存中获取
|
||||
if (this.isReady) {
|
||||
const cachedValue = this.selectSync<T>(selector)
|
||||
if (cachedValue !== undefined) {
|
||||
return cachedValue
|
||||
}
|
||||
}
|
||||
|
||||
// 如果缓存中没有,再从渲染进程获取
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
if (!mainWindow) {
|
||||
throw new Error('Main window is not available')
|
||||
}
|
||||
await this.waitForStoreReady(mainWindow.webContents)
|
||||
return await mainWindow.webContents.executeJavaScript(`
|
||||
(() => {
|
||||
const state = window.store.getState();
|
||||
return ${selector};
|
||||
})()
|
||||
`)
|
||||
} catch (error) {
|
||||
console.error('Failed to select store value:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 派发 action
|
||||
async dispatch(action: any): Promise<void> {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
if (!mainWindow) {
|
||||
throw new Error('Main window is not available')
|
||||
}
|
||||
await this.waitForStoreReady(mainWindow.webContents)
|
||||
try {
|
||||
await mainWindow.webContents.executeJavaScript(`
|
||||
window.store.dispatch(${JSON.stringify(action)})
|
||||
`)
|
||||
} catch (error) {
|
||||
console.error('Failed to dispatch action:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 订阅状态变化
|
||||
async subscribe(selector: string, callback: (newValue: any) => void): Promise<Unsubscribe> {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
if (!mainWindow) {
|
||||
throw new Error('Main window is not available')
|
||||
}
|
||||
await this.waitForStoreReady(mainWindow.webContents)
|
||||
|
||||
// 在渲染进程中设置监听
|
||||
await mainWindow.webContents.executeJavaScript(`
|
||||
if (!window._storeSubscriptions) {
|
||||
window._storeSubscriptions = new Set();
|
||||
|
||||
// 设置全局状态变化监听
|
||||
const unsubscribe = window.store.subscribe(() => {
|
||||
const state = window.store.getState();
|
||||
window.electron.ipcRenderer.send('redux-state-change', state);
|
||||
});
|
||||
|
||||
window._storeSubscriptions.add(unsubscribe);
|
||||
}
|
||||
`)
|
||||
|
||||
// 在主进程中处理回调
|
||||
const handler = async () => {
|
||||
try {
|
||||
const newValue = await this.select(selector)
|
||||
callback(newValue)
|
||||
} catch (error) {
|
||||
console.error('Error in subscription handler:', error)
|
||||
}
|
||||
}
|
||||
|
||||
this.on('stateChange', handler)
|
||||
return () => {
|
||||
this.off('stateChange', handler)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取整个状态树
|
||||
async getState(): Promise<any> {
|
||||
const mainWindow = windowService.getMainWindow()
|
||||
if (!mainWindow) {
|
||||
throw new Error('Main window is not available')
|
||||
}
|
||||
await this.waitForStoreReady(mainWindow.webContents)
|
||||
try {
|
||||
return await mainWindow.webContents.executeJavaScript(`
|
||||
window.store.getState()
|
||||
`)
|
||||
} catch (error) {
|
||||
console.error('Failed to get state:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 批量执行 actions
|
||||
async batch(actions: any[]): Promise<void> {
|
||||
for (const action of actions) {
|
||||
await this.dispatch(action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const reduxService = new ReduxService()
|
||||
|
||||
/** example
|
||||
async function example() {
|
||||
try {
|
||||
// 读取状态
|
||||
const settings = await reduxService.select('state.settings')
|
||||
console.log('settings', settings)
|
||||
|
||||
// 派发 action
|
||||
await reduxService.dispatch({
|
||||
type: 'settings/updateApiKey',
|
||||
payload: 'new-api-key'
|
||||
})
|
||||
|
||||
// 订阅状态变化
|
||||
const unsubscribe = await reduxService.subscribe('state.settings.apiKey', (newValue) => {
|
||||
console.log('API key changed:', newValue)
|
||||
})
|
||||
|
||||
// 批量执行 actions
|
||||
await reduxService.batch([
|
||||
{ type: 'action1', payload: 'data1' },
|
||||
{ type: 'action2', payload: 'data2' }
|
||||
])
|
||||
|
||||
// 同步方法虽然可能不是最新的数据,但响应更快
|
||||
const apiKey = reduxService.selectSync('state.settings.apiKey')
|
||||
console.log('apiKey', apiKey)
|
||||
|
||||
// 处理保证是最新的数据
|
||||
const apiKey1 = await reduxService.select('state.settings.apiKey')
|
||||
console.log('apiKey1', apiKey1)
|
||||
|
||||
// 取消订阅
|
||||
unsubscribe()
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -22,7 +22,11 @@ function getShortcutHandler(shortcut: Shortcut) {
|
||||
case 'show_app':
|
||||
return (window: BrowserWindow) => {
|
||||
if (window.isVisible()) {
|
||||
if (window.isFocused()) {
|
||||
window.hide()
|
||||
} else {
|
||||
window.focus()
|
||||
}
|
||||
} else {
|
||||
window.show()
|
||||
window.focus()
|
||||
@@ -43,8 +47,8 @@ function formatShortcutKey(shortcut: string[]): string {
|
||||
|
||||
function handleZoom(delta: number) {
|
||||
return (window: BrowserWindow) => {
|
||||
const currentZoom = window.webContents.getZoomFactor()
|
||||
const newZoom = currentZoom + delta
|
||||
const currentZoom = configManager.getZoomFactor()
|
||||
const newZoom = Number((currentZoom + delta).toFixed(1))
|
||||
if (newZoom >= 0.1 && newZoom <= 5.0) {
|
||||
window.webContents.setZoomFactor(newZoom)
|
||||
configManager.setZoomFactor(newZoom)
|
||||
@@ -52,8 +56,65 @@ function handleZoom(delta: number) {
|
||||
}
|
||||
}
|
||||
|
||||
const convertShortcutRecordedByKeyboardEventKeyValueToElectronGlobalShortcutFormat = (
|
||||
shortcut: string | string[]
|
||||
): string => {
|
||||
const accelerator = (() => {
|
||||
if (Array.isArray(shortcut)) {
|
||||
return shortcut
|
||||
} else {
|
||||
return shortcut.split('+').map((key) => key.trim())
|
||||
}
|
||||
})()
|
||||
|
||||
return accelerator
|
||||
.map((key) => {
|
||||
switch (key) {
|
||||
case 'Command':
|
||||
return 'CommandOrControl'
|
||||
case 'Control':
|
||||
return 'Control'
|
||||
case 'Ctrl':
|
||||
return 'Control'
|
||||
case 'ArrowUp':
|
||||
return 'Up'
|
||||
case 'ArrowDown':
|
||||
return 'Down'
|
||||
case 'ArrowLeft':
|
||||
return 'Left'
|
||||
case 'ArrowRight':
|
||||
return 'Right'
|
||||
case 'AltGraph':
|
||||
return 'Alt'
|
||||
case 'Slash':
|
||||
return '/'
|
||||
case 'Semicolon':
|
||||
return ';'
|
||||
case 'BracketLeft':
|
||||
return '['
|
||||
case 'BracketRight':
|
||||
return ']'
|
||||
case 'Backslash':
|
||||
return '\\'
|
||||
case 'Quote':
|
||||
return "'"
|
||||
case 'Comma':
|
||||
return ','
|
||||
case 'Minus':
|
||||
return '-'
|
||||
case 'Equal':
|
||||
return '='
|
||||
default:
|
||||
return key
|
||||
}
|
||||
})
|
||||
.join('+')
|
||||
}
|
||||
|
||||
export function registerShortcuts(window: BrowserWindow) {
|
||||
window.once('ready-to-show', () => {
|
||||
window.webContents.setZoomFactor(configManager.getZoomFactor())
|
||||
})
|
||||
|
||||
const register = () => {
|
||||
if (window.isDestroyed()) return
|
||||
@@ -75,11 +136,11 @@ export function registerShortcuts(window: BrowserWindow) {
|
||||
|
||||
const accelerator = formatShortcutKey(shortcut.shortcut)
|
||||
|
||||
if (shortcut.key === 'show_app') {
|
||||
if (shortcut.key === 'show_app' && shortcut.enabled) {
|
||||
showAppAccelerator = accelerator
|
||||
}
|
||||
|
||||
if (shortcut.key === 'mini_window') {
|
||||
if (shortcut.key === 'mini_window' && shortcut.enabled) {
|
||||
showMiniWindowAccelerator = accelerator
|
||||
}
|
||||
|
||||
@@ -100,7 +161,10 @@ export function registerShortcuts(window: BrowserWindow) {
|
||||
}
|
||||
|
||||
if (shortcut.enabled) {
|
||||
globalShortcut.register(formatShortcutKey(shortcut.shortcut), () => handler(window))
|
||||
const accelerator = convertShortcutRecordedByKeyboardEventKeyValueToElectronGlobalShortcutFormat(
|
||||
shortcut.shortcut
|
||||
)
|
||||
globalShortcut.register(accelerator, () => handler(window))
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error(`[ShortcutService] Failed to register shortcut ${shortcut.key}`)
|
||||
@@ -116,12 +180,16 @@ export function registerShortcuts(window: BrowserWindow) {
|
||||
|
||||
if (showAppAccelerator) {
|
||||
const handler = getShortcutHandler({ key: 'show_app' } as Shortcut)
|
||||
handler && globalShortcut.register(showAppAccelerator, () => handler(window))
|
||||
const accelerator =
|
||||
convertShortcutRecordedByKeyboardEventKeyValueToElectronGlobalShortcutFormat(showAppAccelerator)
|
||||
handler && globalShortcut.register(accelerator, () => handler(window))
|
||||
}
|
||||
|
||||
if (showMiniWindowAccelerator) {
|
||||
const handler = getShortcutHandler({ key: 'mini_window' } as Shortcut)
|
||||
handler && globalShortcut.register(showMiniWindowAccelerator, () => handler(window))
|
||||
const accelerator =
|
||||
convertShortcutRecordedByKeyboardEventKeyValueToElectronGlobalShortcutFormat(showMiniWindowAccelerator)
|
||||
handler && globalShortcut.register(accelerator, () => handler(window))
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error('[ShortcutService] Failed to unregister shortcuts')
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
import { proxyManager } from '@main/services/ProxyManager'
|
||||
import { WebDavConfig } from '@types'
|
||||
import Logger from 'electron-log'
|
||||
import { HttpProxyAgent } from 'http-proxy-agent'
|
||||
import Stream from 'stream'
|
||||
import { BufferLike, createClient, GetFileContentsOptions, PutFileContentsOptions, WebDAVClient } from 'webdav'
|
||||
|
||||
export default class WebDav {
|
||||
public instance: WebDAVClient | undefined
|
||||
private webdavPath: string
|
||||
|
||||
constructor(params: WebDavConfig) {
|
||||
this.webdavPath = params.webdavPath
|
||||
const url = proxyManager.getProxyUrl()
|
||||
|
||||
this.instance = createClient(params.webdavHost, {
|
||||
username: params.webdavUser,
|
||||
password: params.webdavPass,
|
||||
maxBodyLength: Infinity,
|
||||
maxContentLength: Infinity
|
||||
maxContentLength: Infinity,
|
||||
httpAgent: url ? new HttpProxyAgent(url) : undefined,
|
||||
httpsAgent: proxyManager.getProxyAgent()
|
||||
})
|
||||
|
||||
this.putFileContents = this.putFileContents.bind(this)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import { isLinux, isWin } from '@main/constant'
|
||||
import { getFilesDir } from '@main/utils/file'
|
||||
import { app, BrowserWindow, ipcMain, Menu, MenuItem, shell } from 'electron'
|
||||
import Logger from 'electron-log'
|
||||
import windowStateKeeper from 'electron-window-state'
|
||||
import path, { join } from 'path'
|
||||
import { join } from 'path'
|
||||
|
||||
import icon from '../../../build/icon.png?asset'
|
||||
import { titleBarOverlayDark, titleBarOverlayLight } from '../config'
|
||||
@@ -28,6 +29,7 @@ export class WindowService {
|
||||
|
||||
public createMainWindow(): BrowserWindow {
|
||||
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||
this.mainWindow.show()
|
||||
return this.mainWindow
|
||||
}
|
||||
|
||||
@@ -50,7 +52,7 @@ export class WindowService {
|
||||
show: false, // 初始不显示
|
||||
autoHideMenuBar: true,
|
||||
transparent: isMac,
|
||||
vibrancy: 'under-window',
|
||||
vibrancy: 'sidebar',
|
||||
visualEffectState: 'active',
|
||||
titleBarStyle: isLinux ? 'default' : 'hidden',
|
||||
titleBarOverlay: theme === 'dark' ? titleBarOverlayDark : titleBarOverlayLight,
|
||||
@@ -149,6 +151,17 @@ export class WindowService {
|
||||
this.wasFullScreen = false
|
||||
mainWindow.webContents.send('fullscreen-status-changed', false)
|
||||
})
|
||||
|
||||
// 添加Escape键退出全屏的支持
|
||||
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||
// 当按下Escape键且窗口处于全屏状态时退出全屏
|
||||
if (input.key === 'Escape' && !input.alt && !input.control && !input.meta && !input.shift) {
|
||||
if (mainWindow.isFullScreen()) {
|
||||
event.preventDefault()
|
||||
mainWindow.setFullScreen(false)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private setupWebContentsHandlers(mainWindow: BrowserWindow) {
|
||||
@@ -184,7 +197,7 @@ export class WindowService {
|
||||
|
||||
if (url.includes('http://file/')) {
|
||||
const fileName = url.replace('http://file/', '')
|
||||
const storageDir = path.join(app.getPath('userData'), 'Data', 'Files')
|
||||
const storageDir = getFilesDir()
|
||||
const filePath = storageDir + '/' + fileName
|
||||
shell.openPath(filePath).catch((err) => Logger.error('Failed to open file:', err))
|
||||
} else {
|
||||
@@ -240,25 +253,45 @@ export class WindowService {
|
||||
return app.quit()
|
||||
}
|
||||
|
||||
// 如果是全屏状态,直接退出
|
||||
// 如果是Windows或Linux,且处于全屏状态,则退出应用
|
||||
if (this.wasFullScreen) {
|
||||
if (isWin || isLinux) {
|
||||
return app.quit()
|
||||
} else {
|
||||
event.preventDefault()
|
||||
mainWindow.setFullScreen(false)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
mainWindow.hide()
|
||||
})
|
||||
|
||||
mainWindow.on('closed', () => {
|
||||
this.mainWindow = null
|
||||
})
|
||||
|
||||
mainWindow.on('show', () => {
|
||||
if (this.miniWindow && !this.miniWindow.isDestroyed()) {
|
||||
this.miniWindow.hide()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public showMainWindow() {
|
||||
if (this.mainWindow) {
|
||||
if (this.miniWindow && !this.miniWindow.isDestroyed()) {
|
||||
this.miniWindow.hide()
|
||||
}
|
||||
|
||||
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||
if (this.mainWindow.isMinimized()) {
|
||||
return this.mainWindow.restore()
|
||||
this.mainWindow.restore()
|
||||
}
|
||||
this.mainWindow.show()
|
||||
this.mainWindow.focus()
|
||||
} else {
|
||||
this.createMainWindow()
|
||||
this.mainWindow = this.createMainWindow()
|
||||
this.mainWindow.focus()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +302,10 @@ export class WindowService {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.selectionMenuWindow) {
|
||||
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||
this.mainWindow.hide()
|
||||
}
|
||||
if (this.selectionMenuWindow && !this.selectionMenuWindow.isDestroyed()) {
|
||||
this.selectionMenuWindow.hide()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,37 @@ import path from 'node:path'
|
||||
|
||||
import { audioExts, documentExts, imageExts, textExts, videoExts } from '@shared/config/constant'
|
||||
import { FileType, FileTypes } from '@types'
|
||||
import { app } from 'electron'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
// 创建文件类型映射表,提高查找效率
|
||||
const fileTypeMap = new Map<string, FileTypes>()
|
||||
|
||||
// 初始化映射表
|
||||
function initFileTypeMap() {
|
||||
imageExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.IMAGE))
|
||||
videoExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.VIDEO))
|
||||
audioExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.AUDIO))
|
||||
textExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.TEXT))
|
||||
documentExts.forEach((ext) => fileTypeMap.set(ext, FileTypes.DOCUMENT))
|
||||
}
|
||||
|
||||
// 初始化映射表
|
||||
initFileTypeMap()
|
||||
|
||||
export function getFileType(ext: string): FileTypes {
|
||||
ext = ext.toLowerCase()
|
||||
if (imageExts.includes(ext)) return FileTypes.IMAGE
|
||||
if (videoExts.includes(ext)) return FileTypes.VIDEO
|
||||
if (audioExts.includes(ext)) return FileTypes.AUDIO
|
||||
if (textExts.includes(ext)) return FileTypes.TEXT
|
||||
if (documentExts.includes(ext)) return FileTypes.DOCUMENT
|
||||
return FileTypes.OTHER
|
||||
return fileTypeMap.get(ext) || FileTypes.OTHER
|
||||
}
|
||||
|
||||
export function getAllFiles(dirPath: string, arrayOfFiles: FileType[] = []): FileType[] {
|
||||
const files = fs.readdirSync(dirPath)
|
||||
|
||||
files.forEach((file) => {
|
||||
if (file.startsWith('.')) {
|
||||
return
|
||||
}
|
||||
|
||||
const fullPath = path.join(dirPath, file)
|
||||
if (fs.statSync(fullPath).isDirectory()) {
|
||||
arrayOfFiles = getAllFiles(fullPath, arrayOfFiles)
|
||||
@@ -41,7 +57,7 @@ export function getAllFiles(dirPath: string, arrayOfFiles: FileType[] = []): Fil
|
||||
count: 1,
|
||||
origin_name: name,
|
||||
type: fileType,
|
||||
created_at: new Date()
|
||||
created_at: new Date().toISOString()
|
||||
}
|
||||
|
||||
arrayOfFiles.push(fileItem)
|
||||
@@ -50,3 +66,11 @@ export function getAllFiles(dirPath: string, arrayOfFiles: FileType[] = []): Fil
|
||||
|
||||
return arrayOfFiles
|
||||
}
|
||||
|
||||
export function getTempDir() {
|
||||
return path.join(app.getPath('temp'), 'CherryStudio')
|
||||
}
|
||||
|
||||
export function getFilesDir() {
|
||||
return path.join(app.getPath('userData'), 'Data', 'Files')
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
import { spawn } from 'child_process'
|
||||
import { app, dialog } from 'electron'
|
||||
import Logger from 'electron-log'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
export async function updateUserDataPath() {
|
||||
const currentPath = app.getPath('userData')
|
||||
const oldPath = currentPath.replace('CherryStudio', 'cherry-studio')
|
||||
|
||||
if (currentPath !== oldPath && fs.existsSync(oldPath)) {
|
||||
Logger.log('Update userData path')
|
||||
|
||||
try {
|
||||
if (process.platform === 'win32') {
|
||||
// Windows 系统:创建 bat 文件
|
||||
const batPath = await createWindowsBatFile(oldPath, currentPath)
|
||||
await promptRestartAndExecute(batPath)
|
||||
} else {
|
||||
// 其他系统:直接更新
|
||||
fs.rmSync(currentPath, { recursive: true, force: true })
|
||||
fs.renameSync(oldPath, currentPath)
|
||||
Logger.log(`Directory renamed: ${currentPath}`)
|
||||
await promptRestart()
|
||||
}
|
||||
} catch (error: any) {
|
||||
Logger.error('Error updating userData path:', error)
|
||||
dialog.showErrorBox('错误', `更新用户数据目录时发生错误: ${error.message}`)
|
||||
}
|
||||
} else {
|
||||
Logger.log('userData path does not need to be updated')
|
||||
}
|
||||
}
|
||||
|
||||
async function createWindowsBatFile(oldPath: string, currentPath: string): Promise<string> {
|
||||
const batPath = path.join(app.getPath('temp'), 'rename_userdata.bat')
|
||||
const appPath = app.getPath('exe')
|
||||
const batContent = `
|
||||
@echo off
|
||||
timeout /t 2 /nobreak
|
||||
rmdir /s /q "${currentPath}"
|
||||
rename "${oldPath}" "${path.basename(currentPath)}"
|
||||
start "" "${appPath}"
|
||||
del "%~f0"
|
||||
`
|
||||
fs.writeFileSync(batPath, batContent)
|
||||
return batPath
|
||||
}
|
||||
|
||||
async function promptRestartAndExecute(batPath: string) {
|
||||
await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: '应用需要重启',
|
||||
message: '用户数据目录将在重启后更新。请重启应用以应用更改。',
|
||||
buttons: ['手动重启']
|
||||
})
|
||||
|
||||
// 执行 bat 文件
|
||||
spawn('cmd.exe', ['/c', batPath], {
|
||||
detached: true,
|
||||
stdio: 'ignore'
|
||||
})
|
||||
|
||||
app.exit(0)
|
||||
}
|
||||
|
||||
async function promptRestart() {
|
||||
await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: '应用需要重启',
|
||||
message: '用户数据目录已更新。请重启应用以应用更改。',
|
||||
buttons: ['重启']
|
||||
})
|
||||
|
||||
app.relaunch()
|
||||
app.exit(0)
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { BrowserWindow } from 'electron'
|
||||
|
||||
function isTilingWindowManager() {
|
||||
if (process.platform === 'darwin') {
|
||||
return false
|
||||
@@ -13,4 +15,33 @@ function isTilingWindowManager() {
|
||||
return tilingSystems.some((system) => desktopEnv?.includes(system))
|
||||
}
|
||||
|
||||
export const replaceDevtoolsFont = (browserWindow: BrowserWindow) => {
|
||||
if (process.platform === 'win32') {
|
||||
browserWindow.webContents.on('devtools-opened', () => {
|
||||
const css = `
|
||||
:root {
|
||||
--sys-color-base: var(--ref-palette-neutral100);
|
||||
--source-code-font-family: consolas;
|
||||
--source-code-font-size: 12px;
|
||||
--monospace-font-family: consolas;
|
||||
--monospace-font-size: 12px;
|
||||
--default-font-family: system-ui, sans-serif;
|
||||
--default-font-size: 12px;
|
||||
}
|
||||
.-theme-with-dark-background {
|
||||
--sys-color-base: var(--ref-palette-secondary25);
|
||||
}
|
||||
body {
|
||||
--default-font-family: system-ui,sans-serif;
|
||||
}`
|
||||
|
||||
browserWindow.webContents.devToolsWebContents?.executeJavaScript(`
|
||||
const overriddenStyle = document.createElement('style');
|
||||
overriddenStyle.innerHTML = '${css.replaceAll('\n', ' ')}';
|
||||
document.body.append(overriddenStyle);
|
||||
document.body.classList.remove('platform-windows');`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export { isTilingWindowManager }
|
||||
|
||||
21
src/preload/index.d.ts
vendored
@@ -1,9 +1,7 @@
|
||||
import { ElectronAPI } from '@electron-toolkit/preload'
|
||||
import type { FileMetadataResponse, ListFilesResponse, UploadFileResponse } from '@google/generative-ai/server'
|
||||
import { ExtractChunkData } from '@llm-tools/embedjs-interfaces'
|
||||
import { FileType } from '@renderer/types'
|
||||
import { WebDavConfig } from '@renderer/types'
|
||||
import { AppInfo, KnowledgeBaseParams, KnowledgeItem, LanguageVarious } from '@renderer/types'
|
||||
import { AppInfo, FileType, KnowledgeBaseParams, KnowledgeItem, LanguageVarious, WebDavConfig } from '@renderer/types'
|
||||
import type { LoaderReturn } from '@shared/config/types'
|
||||
import type { OpenDialogOptions } from 'electron'
|
||||
import type { UpdateInfo } from 'electron-updater'
|
||||
@@ -15,6 +13,7 @@ declare global {
|
||||
api: {
|
||||
getAppInfo: () => Promise<AppInfo>
|
||||
checkForUpdate: () => Promise<{ currentVersion: string; updateInfo: UpdateInfo | null }>
|
||||
showUpdateDialog: () => Promise<void>
|
||||
openWebsite: (url: string) => void
|
||||
setProxy: (proxy: string | undefined) => void
|
||||
setLanguage: (theme: LanguageVarious) => void
|
||||
@@ -119,6 +118,22 @@ declare global {
|
||||
encrypt: (text: string, secretKey: string, iv: string) => Promise<{ iv: string; encryptedData: string }>
|
||||
decrypt: (encryptedData: string, iv: string, secretKey: string) => Promise<string>
|
||||
}
|
||||
shell: {
|
||||
openExternal: (url: string, options?: OpenExternalOptions) => Promise<void>
|
||||
}
|
||||
mcp: {
|
||||
// servers
|
||||
listServers: () => Promise<MCPServer[]>
|
||||
addServer: (server: MCPServer) => Promise<void>
|
||||
updateServer: (server: MCPServer) => Promise<void>
|
||||
deleteServer: (serverName: string) => Promise<void>
|
||||
setServerActive: (name: string, isActive: boolean) => Promise<void>
|
||||
// tools
|
||||
listTools: () => Promise<MCPTool>
|
||||
callTool: ({ client, name, args }: { client: string; name: string; args: any }) => Promise<any>
|
||||
// status
|
||||
cleanup: () => Promise<void>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
import { FileType, KnowledgeBaseParams, KnowledgeItem, Shortcut, WebDavConfig } from '@types'
|
||||
import { contextBridge, ipcRenderer, OpenDialogOptions } from 'electron'
|
||||
import { FileType, KnowledgeBaseParams, KnowledgeItem, MCPServer, Shortcut, WebDavConfig } from '@types'
|
||||
import { contextBridge, ipcRenderer, OpenDialogOptions, shell } from 'electron'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
@@ -8,6 +8,7 @@ const api = {
|
||||
reload: () => ipcRenderer.invoke('app:reload'),
|
||||
setProxy: (proxy: string) => ipcRenderer.invoke('app:proxy', proxy),
|
||||
checkForUpdate: () => ipcRenderer.invoke('app:check-for-update'),
|
||||
showUpdateDialog: () => ipcRenderer.invoke('app:show-update-dialog'),
|
||||
setLanguage: (lang: string) => ipcRenderer.invoke('app:set-language', lang),
|
||||
setTray: (isActive: boolean) => ipcRenderer.invoke('app:set-tray', isActive),
|
||||
restartTray: () => ipcRenderer.invoke('app:restart-tray'),
|
||||
@@ -104,6 +105,20 @@ const api = {
|
||||
encrypt: (text: string, secretKey: string, iv: string) => ipcRenderer.invoke('aes:encrypt', text, secretKey, iv),
|
||||
decrypt: (encryptedData: string, iv: string, secretKey: string) =>
|
||||
ipcRenderer.invoke('aes:decrypt', encryptedData, iv, secretKey)
|
||||
},
|
||||
mcp: {
|
||||
listServers: () => ipcRenderer.invoke('mcp:list-servers'),
|
||||
addServer: (server: MCPServer) => ipcRenderer.invoke('mcp:add-server', server),
|
||||
updateServer: (server: MCPServer) => ipcRenderer.invoke('mcp:update-server', server),
|
||||
deleteServer: (serverName: string) => ipcRenderer.invoke('mcp:delete-server', serverName),
|
||||
setServerActive: (name: string, isActive: boolean) =>
|
||||
ipcRenderer.invoke('mcp:set-server-active', { name, isActive }),
|
||||
listTools: (serverName?: string) => ipcRenderer.invoke('mcp:list-tools', serverName),
|
||||
callTool: (params: { client: string; name: string; args: any }) => ipcRenderer.invoke('mcp:call-tool', params),
|
||||
cleanup: () => ipcRenderer.invoke('mcp:cleanup')
|
||||
},
|
||||
shell: {
|
||||
openExternal: shell.openExternal
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<meta name="viewport" content="initial-scale=1, width=device-width" />
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; connect-src blob: *; script-src 'self' 'unsafe-eval' *; worker-src 'self' blob:; style-src 'self' 'unsafe-inline' *; font-src 'self' data: *; img-src 'self' data: file: * blob:; frame-src * file:" />
|
||||
<title>Cherry Studio</title>
|
||||
|
||||
<style>
|
||||
html,
|
||||
|
||||
@@ -8,8 +8,10 @@ import { PersistGate } from 'redux-persist/integration/react'
|
||||
import Sidebar from './components/app/Sidebar'
|
||||
import TopViewContainer from './components/TopView'
|
||||
import AntdProvider from './context/AntdProvider'
|
||||
import StyleSheetManager from './context/StyleSheetManager'
|
||||
import { SyntaxHighlighterProvider } from './context/SyntaxHighlighterProvider'
|
||||
import { ThemeProvider } from './context/ThemeProvider'
|
||||
import NavigationHandler from './handler/NavigationHandler'
|
||||
import AgentsPage from './pages/agents/AgentsPage'
|
||||
import AppsPage from './pages/apps/AppsPage'
|
||||
import FilesPage from './pages/files/FilesPage'
|
||||
@@ -22,12 +24,14 @@ import TranslatePage from './pages/translate/TranslatePage'
|
||||
function App(): JSX.Element {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<StyleSheetManager>
|
||||
<ThemeProvider>
|
||||
<AntdProvider>
|
||||
<SyntaxHighlighterProvider>
|
||||
<PersistGate loading={null} persistor={persistor}>
|
||||
<TopViewContainer>
|
||||
<HashRouter>
|
||||
<NavigationHandler />
|
||||
<Sidebar />
|
||||
<Routes>
|
||||
<Route path="/" element={<HomePage />} />
|
||||
@@ -45,6 +49,7 @@ function App(): JSX.Element {
|
||||
</SyntaxHighlighterProvider>
|
||||
</AntdProvider>
|
||||
</ThemeProvider>
|
||||
</StyleSheetManager>
|
||||
</Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@font-face {
|
||||
font-family: 'iconfont'; /* Project id 4753420 */
|
||||
src: url('iconfont.woff2?t=1738750230250') format('woff2');
|
||||
src: url('iconfont.woff2?t=1741743579060') format('woff2');
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
@@ -11,6 +11,10 @@
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.icon-notion:before {
|
||||
content: '\e690';
|
||||
}
|
||||
|
||||
.icon-thinking:before {
|
||||
content: '\e65b';
|
||||
}
|
||||
@@ -27,10 +31,6 @@
|
||||
content: '\e630';
|
||||
}
|
||||
|
||||
.icon-a-darkmode:before {
|
||||
content: '\e6cd';
|
||||
}
|
||||
|
||||
.icon-ai-model:before {
|
||||
content: '\e827';
|
||||
}
|
||||
|
||||
BIN
src/renderer/src/assets/images/apps/abacus.webp
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/renderer/src/assets/images/apps/baidu-ai-search.webp
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
src/renderer/src/assets/images/apps/cici-app-logo.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
src/renderer/src/assets/images/apps/cici.webp
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
src/renderer/src/assets/images/apps/coze.webp
Normal file
|
After Width: | Height: | Size: 12 KiB |
1
src/renderer/src/assets/images/apps/dify.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Dify</title><clipPath id="lobe-icons-dify-fill"><path d="M1 0h10.286c6.627 0 12 5.373 12 12s-5.373 12-12 12H1V0z"></path></clipPath><foreignObject clip-path="url(#lobe-icons-dify-fill)" height="24" style="background:conic-gradient(from 180deg at 50% 50%, #0222C3, #8FB1F4, #FFFFFF)" width="24"></foreignObject></svg>
|
||||
|
After Width: | Height: | Size: 480 B |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 20 KiB |
BIN
src/renderer/src/assets/images/apps/kimi.webp
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
src/renderer/src/assets/images/apps/lambdachat.webp
Normal file
|
After Width: | Height: | Size: 724 B |
BIN
src/renderer/src/assets/images/apps/lechat.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/renderer/src/assets/images/apps/monica.webp
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
BIN
src/renderer/src/assets/images/apps/nm.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
7
src/renderer/src/assets/images/apps/notebooklm.svg
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512px" height="512px" viewBox="0 0 512 512" version="1.1">
|
||||
<g id="surface1">
|
||||
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(85.09804%,85.09804%,85.09804%);fill-opacity:1;" d="M 512 256 C 512 114.613281 397.386719 0 256 0 C 114.613281 0 0 114.613281 0 256 C 0 397.386719 114.613281 512 256 512 C 397.386719 512 512 397.386719 512 256 Z M 512 256 "/>
|
||||
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(0%,0%,0%);fill-opacity:1;" d="M 256.011719 114.753906 C 167.050781 114.753906 94.945312 186.261719 94.945312 274.507812 L 94.945312 350.988281 L 124.628906 350.988281 L 124.628906 343.359375 C 124.628906 307.574219 153.867188 278.558594 189.941406 278.558594 C 226.015625 278.558594 255.253906 307.585938 255.253906 343.359375 L 255.253906 350.988281 L 284.9375 350.988281 L 284.9375 343.359375 C 284.9375 291.308594 242.390625 249.140625 189.929688 249.140625 C 169.503906 249.140625 150.582031 255.53125 135.082031 266.433594 C 151.296875 234.464844 184.691406 212.535156 223.242188 212.535156 C 277.707031 212.535156 321.867188 256.339844 321.867188 310.355469 L 321.867188 350.996094 L 351.5625 350.996094 L 351.5625 310.355469 C 351.5625 240.074219 294.113281 183.082031 223.242188 183.082031 C 191.382812 183.082031 162.230469 194.601562 139.785156 213.683594 C 161.824219 172.375 205.578125 144.214844 256 144.214844 C 328.566406 144.214844 387.382812 202.550781 387.382812 274.515625 L 387.382812 350.996094 L 417.066406 350.996094 L 417.066406 274.515625 C 417.066406 186.28125 344.960938 114.761719 256 114.761719 Z M 256.011719 114.753906 "/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 13 KiB |
BIN
src/renderer/src/assets/images/apps/sparkdesk.webp
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
src/renderer/src/assets/images/apps/wpslingxi.webp
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
src/renderer/src/assets/images/apps/xiaoyi.webp
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
src/renderer/src/assets/images/apps/you.jpg
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 14 KiB |
BIN
src/renderer/src/assets/images/apps/yuanbao.webp
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
src/renderer/src/assets/images/models/codestral.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 7.5 KiB |
BIN
src/renderer/src/assets/images/models/perplexity.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
src/renderer/src/assets/images/models/xirang.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
src/renderer/src/assets/images/models/xirang_dark.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
src/renderer/src/assets/images/providers/DMXAPI.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
src/renderer/src/assets/images/providers/cohere.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
BIN
src/renderer/src/assets/images/providers/lmstudio.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
src/renderer/src/assets/images/providers/modelscope.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
src/renderer/src/assets/images/providers/o3.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 6.0 KiB |
BIN
src/renderer/src/assets/images/providers/perplexity.webp
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
src/renderer/src/assets/images/providers/tencent-cloud-ti.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src/renderer/src/assets/images/providers/xirang.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
src/renderer/src/assets/images/search/exa.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
1
src/renderer/src/assets/images/search/searxng.svg
Executable file
@@ -0,0 +1 @@
|
||||
<svg height="92mm" viewBox="0 0 92 92" width="92mm" xmlns="http://www.w3.org/2000/svg"><g transform="translate(-40.921303 -17.416526)"><g fill="none"><circle cx="75" cy="92" r="0" stroke="#000" stroke-width="12"/><circle cx="75.921" cy="53.903" r="30" stroke="#3050ff" stroke-width="10"/><path d="m67.514849 37.91524a18 18 0 0 1 21.051475 3.312407 18 18 0 0 1 3.137312 21.078282" stroke="#3050ff" stroke-width="5"/></g><path d="m3.706 122.09h18.846v39.963h-18.846z" fill="#3050ff" transform="matrix(.69170581 -.72217939 .72217939 .69170581 0 0)"/></g></svg>
|
||||
|
After Width: | Height: | Size: 557 B |
BIN
src/renderer/src/assets/images/search/tavily.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
14
src/renderer/src/assets/images/search/tavily.svg
Normal file
@@ -0,0 +1,14 @@
|
||||
<svg width="778" height="257" viewBox="0 0 778 257" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M97.1853 5.35901L127.346 53.1064C132.19 60.7745 126.68 70.7725 117.61 70.7725H105.279V142.278H87.4492V-0.00683594C91.1876 -0.00683594 94.926 1.78179 97.1853 5.35901Z" fill="#8FBCFA"/>
|
||||
<path d="M47.5482 53.1064L77.7098 5.35901C79.9691 1.78179 83.7075 -0.00683594 87.4459 -0.00683594V142.279C81.0587 141.981 74.8755 143.829 69.616 147.544V70.7725H57.2849C48.2149 70.7725 42.7047 60.7745 47.5482 53.1064Z" fill="#468BFF"/>
|
||||
<path d="M182.003 189.445L107.34 189.445C111.648 184.622 114.201 178.481 114.476 171.615H252.782C252.782 175.353 250.993 179.092 247.416 181.351L199.669 211.512C192.001 216.356 182.003 210.846 182.003 201.776V189.445Z" fill="#FDBB11"/>
|
||||
<path d="M199.668 131.718L247.415 161.879C250.993 164.138 252.781 167.877 252.781 171.615H114.471C114.72 165.212 112.733 158.898 108.957 153.785H182.002V141.454C182.002 132.384 192 126.874 199.668 131.718Z" fill="#F6D785"/>
|
||||
<path d="M46.9409 209.797L3.37891 253.359C6.02226 256.003 9.93035 257.381 14.0576 256.45L69.1472 244.014C77.9944 242.017 81.1678 231.051 74.7545 224.638L66.035 215.918L98.7916 183.055C105.771 176.075 105.462 164.899 98.6758 158.113L46.9409 209.797Z" fill="#FF9A9D"/>
|
||||
<path d="M40.8221 190.708L73.6898 157.963C80.6694 150.983 91.8931 151.328 98.679 158.113L46.9436 209.802L3.38131 253.364C0.737954 250.721 -0.640662 246.812 0.291 242.685L12.7265 187.596C14.7236 178.748 25.6895 175.575 32.1028 181.988L40.8221 190.708Z" fill="#FE363B"/>
|
||||
<path d="M777.344 93.6689L718.337 234.049H692.704L713.348 186.567L675.156 93.6689H702.166L726.766 160.246L751.711 93.6689H777.344Z" fill="#2C2F32"/>
|
||||
<path d="M664.096 70.1191V188.976H640.012V70.1191H664.096Z" fill="#2C2F32"/>
|
||||
<path d="M606.041 82.2736C601.797 82.2736 598.242 80.9547 595.375 78.3168C592.622 75.5643 591.246 72.181 591.246 68.1668C591.246 64.1527 592.622 60.8267 595.375 58.1889C598.242 55.4363 601.797 54.0601 606.041 54.0601C610.284 54.0601 613.783 55.4363 616.535 58.1889C619.402 60.8267 620.836 63.6942 620.836 67.7084C620.836 71.7225 619.402 75.5643 616.535 78.3168C613.783 80.9547 610.284 82.2736 606.041 82.2736ZM617.911 93.6279V188.978H593.827V93.6279H617.911Z" fill="#2C2F32"/>
|
||||
<path d="M532.3 166.783L556.385 93.6689H582.018L546.751 188.976H517.505L482.41 93.6689H508.215L532.3 166.783Z" fill="#2C2F32"/>
|
||||
<path d="M371.52 140.972C371.52 131.338 373.412 122.794 377.197 115.339C381.096 107.884 386.314 102.15 392.852 98.1355C399.504 94.1213 406.901 92.1143 415.044 92.1143C422.155 92.1143 428.348 93.5479 433.624 96.4151C439.014 99.2823 443.315 102.895 446.526 107.253V93.6626H470.783V188.969H446.526V175.035C443.43 179.507 439.129 183.235 433.624 186.217C428.233 189.084 421.983 190.518 414.872 190.518C406.844 190.518 399.504 188.453 392.852 184.324C386.314 180.196 381.096 174.404 377.197 166.949C373.412 159.38 371.52 150.72 371.52 140.972ZM446.526 141.316C446.526 135.467 445.379 130.478 443.086 126.349C440.792 122.105 437.695 118.894 433.796 116.715C429.896 114.421 425.71 113.274 421.237 113.274C416.764 113.274 412.636 114.364 408.851 116.543C405.066 118.722 401.97 121.933 399.561 126.177C397.267 130.306 396.12 135.237 396.12 140.972C396.12 146.706 397.267 151.753 399.561 156.111C401.97 160.354 405.066 163.623 408.851 165.917C412.75 168.211 416.879 169.357 421.237 169.357C425.71 169.357 429.896 168.268 433.796 166.089C437.695 163.795 440.792 160.584 443.086 156.455C445.379 152.211 446.526 147.165 446.526 141.316Z" fill="#2C2F32"/>
|
||||
<path d="M340.767 113.445V159.55C340.767 162.762 341.513 165.113 343.004 166.604C344.609 167.98 347.247 168.668 350.917 168.668H362.099V188.968H346.96C326.66 188.968 316.51 179.105 316.51 159.378V113.445H305.156V93.6614H316.51V70.0928H340.767V93.6614H362.099V113.445H340.767Z" fill="#2C2F32"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
@@ -1,3 +1,5 @@
|
||||
@use './container.scss';
|
||||
|
||||
#inputbar {
|
||||
resize: none;
|
||||
}
|
||||
@@ -10,6 +12,10 @@
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.ant-tabs-tabpane:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.ant-segmented-group {
|
||||
gap: 4px;
|
||||
}
|
||||
@@ -47,3 +53,142 @@
|
||||
background-color: initial !important;
|
||||
}
|
||||
}
|
||||
|
||||
.mention-models-dropdown {
|
||||
&.ant-dropdown {
|
||||
background: rgba(var(--color-base-rgb), 0.65) !important;
|
||||
backdrop-filter: blur(35px) saturate(150%) !important;
|
||||
animation-duration: 0.15s !important;
|
||||
}
|
||||
|
||||
/* 移动其他样式到 mention-models-dropdown 类下 */
|
||||
.ant-slide-up-enter .ant-dropdown-menu,
|
||||
.ant-slide-up-appear .ant-dropdown-menu,
|
||||
.ant-slide-up-leave .ant-dropdown-menu,
|
||||
.ant-slide-up-enter-active .ant-dropdown-menu,
|
||||
.ant-slide-up-appear-active .ant-dropdown-menu,
|
||||
.ant-slide-up-leave-active .ant-dropdown-menu {
|
||||
background: rgba(var(--color-base-rgb), 0.65) !important;
|
||||
backdrop-filter: blur(35px) saturate(150%) !important;
|
||||
}
|
||||
|
||||
.ant-dropdown-menu {
|
||||
/* 保持原有的下拉菜单样式,但限定在 mention-models-dropdown 类下 */
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 4px 12px;
|
||||
position: relative;
|
||||
background: rgba(var(--color-base-rgb), 0.65) !important;
|
||||
backdrop-filter: blur(35px) saturate(150%) !important;
|
||||
border: 0.5px solid rgba(var(--color-border-rgb), 0.3);
|
||||
border-radius: 10px;
|
||||
box-shadow:
|
||||
0 0 0 0.5px rgba(0, 0, 0, 0.15),
|
||||
0 4px 16px rgba(0, 0, 0, 0.15),
|
||||
0 2px 8px rgba(0, 0, 0, 0.12),
|
||||
inset 0 0 0 0.5px rgba(255, 255, 255, var(--inner-glow-opacity, 0.1));
|
||||
transform-origin: top;
|
||||
will-change: transform, opacity;
|
||||
transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
margin-bottom: 0;
|
||||
|
||||
&.no-scrollbar {
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
&.has-scrollbar {
|
||||
padding-right: 2px;
|
||||
}
|
||||
|
||||
// Scrollbar styles
|
||||
&::-webkit-scrollbar {
|
||||
width: 14px;
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
border: 4px solid transparent;
|
||||
background-clip: padding-box;
|
||||
border-radius: 7px;
|
||||
background-color: var(--color-scrollbar-thumb);
|
||||
min-height: 50px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
&:hover::-webkit-scrollbar-thumb {
|
||||
background-color: var(--color-scrollbar-thumb);
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb:hover {
|
||||
background-color: var(--color-scrollbar-thumb-hover);
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb:active {
|
||||
background-color: var(--color-scrollbar-thumb-hover);
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
border-radius: 7px;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-dropdown-menu-item-group {
|
||||
margin-bottom: 4px;
|
||||
|
||||
&:not(:first-child) {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.ant-dropdown-menu-item-group-title {
|
||||
padding: 5px 12px;
|
||||
color: var(--color-text-3);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle no-results case margin
|
||||
.no-results {
|
||||
padding: 8px 12px;
|
||||
color: var(--color-text-3);
|
||||
cursor: default;
|
||||
font-size: 13px;
|
||||
opacity: 0.8;
|
||||
margin-bottom: 40px;
|
||||
|
||||
&:hover {
|
||||
background: none;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-dropdown-menu-item {
|
||||
padding: 5px 12px;
|
||||
margin: 0 -12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
|
||||
&:hover {
|
||||
background: rgba(var(--color-hover-rgb), 0.5);
|
||||
}
|
||||
|
||||
&.ant-dropdown-menu-item-selected {
|
||||
background-color: rgba(var(--color-primary-rgb), 0.12);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.ant-dropdown-menu-item-icon {
|
||||
margin-right: 0;
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
src/renderer/src/assets/styles/container.scss
Normal file
@@ -0,0 +1,7 @@
|
||||
#content-container {
|
||||
background-color: var(--color-background);
|
||||
border-top: 0.5px solid var(--color-border);
|
||||
border-top-left-radius: 10px;
|
||||
border-left: 0.5px solid var(--color-border);
|
||||
box-shadow: -2px 0px 20px -4px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
@import './markdown.scss';
|
||||
@import './ant.scss';
|
||||
@import './scrollbar.scss';
|
||||
@use './markdown.scss';
|
||||
@use './ant.scss';
|
||||
@use './scrollbar.scss';
|
||||
@use './container.scss';
|
||||
@import '../fonts/icon-fonts/iconfont.css';
|
||||
@import '../fonts/ubuntu/ubuntu.css';
|
||||
|
||||
@@ -25,6 +26,7 @@
|
||||
--color-background-soft: var(--color-black-soft);
|
||||
--color-background-mute: var(--color-black-mute);
|
||||
--color-background-opacity: rgba(34, 34, 34, 0.7);
|
||||
--inner-glow-opacity: 0.3; // For the glassmorphism effect in the dropdown menu
|
||||
|
||||
--color-primary: #00b96b;
|
||||
--color-primary-soft: #00b96b99;
|
||||
@@ -88,7 +90,8 @@ body[theme-mode='light'] {
|
||||
--color-background: var(--color-white);
|
||||
--color-background-soft: var(--color-white-soft);
|
||||
--color-background-mute: var(--color-white-mute);
|
||||
--color-background-opacity: rgba(255, 255, 255, 0.7);
|
||||
--color-background-opacity: rgba(235, 235, 235, 0.7);
|
||||
--inner-glow-opacity: 0.1;
|
||||
|
||||
--color-primary: #00b96b;
|
||||
--color-primary-soft: #00b96b99;
|
||||
@@ -176,14 +179,6 @@ body,
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
#content-container {
|
||||
background-color: var(--color-background);
|
||||
border-top: 0.5px solid var(--color-border);
|
||||
border-top-left-radius: 10px;
|
||||
border-left: 0.5px solid var(--color-border);
|
||||
box-shadow: -2px 0px 20px -4px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.loader {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
@@ -256,6 +251,9 @@ body,
|
||||
border: 1px solid var(--color-background-mute);
|
||||
}
|
||||
}
|
||||
.group-menu-bar {
|
||||
background-color: var(--color-background);
|
||||
}
|
||||
code {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
&:has(+ ul) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
ul {
|
||||
|
||||
@@ -14,7 +14,15 @@ const ModelAvatar: FC<Props> = ({ model, size, props }) => {
|
||||
return (
|
||||
<Avatar
|
||||
src={getModelLogo(model?.id || '')}
|
||||
style={{ width: size, height: size, display: 'flex', alignItems: 'center', justifyContent: 'center' }}
|
||||
style={{
|
||||
width: size,
|
||||
height: size,
|
||||
minWidth: size,
|
||||
minHeight: size,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center'
|
||||
}}
|
||||
{...props}>
|
||||
{first(model?.name)}
|
||||
</Avatar>
|
||||
|
||||
@@ -46,23 +46,28 @@ const DragableList: FC<Props<any>> = ({
|
||||
<DragDropContext onDragStart={onDragStart} onDragEnd={_onDragEnd}>
|
||||
<Droppable droppableId="droppable" {...droppableProps}>
|
||||
{(provided) => (
|
||||
<div {...provided.droppableProps} ref={provided.innerRef} style={{ ...style }}>
|
||||
<div {...provided.droppableProps} ref={provided.innerRef} style={style}>
|
||||
{list.map((item, index) => {
|
||||
const id = item.id || item
|
||||
return (
|
||||
<Draggable key={`draggable_${id}_${index}`} draggableId={id} index={index} {...droppableProps}>
|
||||
<Draggable key={`draggable_${id}_${index}`} draggableId={id} index={index}>
|
||||
{(provided) => (
|
||||
<div
|
||||
ref={provided.innerRef}
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
style={{ ...provided.draggableProps.style, marginBottom: 8, ...listStyle }}>
|
||||
style={{
|
||||
...listStyle,
|
||||
...provided.draggableProps.style,
|
||||
marginBottom: 8
|
||||
}}>
|
||||
{children(item, index)}
|
||||
</div>
|
||||
)}
|
||||
</Draggable>
|
||||
)
|
||||
})}
|
||||
{provided.placeholder}
|
||||
</div>
|
||||
)}
|
||||
</Droppable>
|
||||
|
||||
35
src/renderer/src/components/Ellipsis/index.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { HTMLAttributes } from 'react'
|
||||
import styled, { css } from 'styled-components'
|
||||
|
||||
type Props = {
|
||||
maxLine?: number
|
||||
} & HTMLAttributes<HTMLDivElement>
|
||||
|
||||
const Ellipsis = (props: Props) => {
|
||||
const { maxLine = 1, children, ...rest } = props
|
||||
return (
|
||||
<EllipsisContainer $maxLine={maxLine} {...rest}>
|
||||
{children}
|
||||
</EllipsisContainer>
|
||||
)
|
||||
}
|
||||
|
||||
const multiLineEllipsis = css<{ $maxLine: number }>`
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: ${({ $maxLine }) => $maxLine};
|
||||
overflow-wrap: break-word;
|
||||
`
|
||||
|
||||
const singleLineEllipsis = css`
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
`
|
||||
|
||||
const EllipsisContainer = styled.div<{ $maxLine: number }>`
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
${({ $maxLine }) => ($maxLine > 1 ? multiLineEllipsis : singleLineEllipsis)}
|
||||
`
|
||||
|
||||
export default Ellipsis
|
||||
134
src/renderer/src/components/Icons/FallbackFavicon.tsx
Normal file
@@ -0,0 +1,134 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
// FallbackFavicon component that tries multiple favicon sources
|
||||
interface FallbackFaviconProps {
|
||||
hostname: string
|
||||
alt: string
|
||||
}
|
||||
|
||||
const FallbackFavicon: React.FC<FallbackFaviconProps> = ({ hostname, alt }) => {
|
||||
type FaviconState =
|
||||
| { status: 'idle' }
|
||||
| { status: 'loading' }
|
||||
| { status: 'failed' }
|
||||
| { status: 'loaded'; src: string }
|
||||
|
||||
const [faviconState, setFaviconState] = useState<FaviconState>({ status: 'idle' })
|
||||
|
||||
useEffect(() => {
|
||||
// Reset state when hostname changes
|
||||
setFaviconState({ status: 'loading' })
|
||||
|
||||
// Generate all possible favicon URLs
|
||||
const faviconUrls = [
|
||||
`https://favicon.splitbee.io/?url=${hostname}`,
|
||||
`https://${hostname}/favicon.ico`,
|
||||
`https://icon.horse/icon/${hostname}`,
|
||||
`https://favicon.cccyun.cc/${hostname}`,
|
||||
`https://favicon.im/${hostname}`,
|
||||
`https://www.google.com/s2/favicons?domain=${hostname}`
|
||||
]
|
||||
|
||||
// Main controller to abort all requests when needed
|
||||
const controller = new AbortController()
|
||||
const { signal } = controller
|
||||
|
||||
// Create a promise for each favicon URL
|
||||
const faviconPromises = faviconUrls.map((url) =>
|
||||
fetch(url, {
|
||||
method: 'HEAD',
|
||||
signal,
|
||||
credentials: 'omit'
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return url
|
||||
}
|
||||
throw new Error(`Failed to fetch ${url}`)
|
||||
})
|
||||
.catch((error) => {
|
||||
// Rethrow aborted errors but silence other failures
|
||||
if (error.name === 'AbortError') {
|
||||
throw error
|
||||
}
|
||||
console.debug(`Failed to fetch favicon from ${url}:`, error)
|
||||
return null // Return null for failed requests
|
||||
})
|
||||
)
|
||||
|
||||
// Create a timeout promise
|
||||
const timeoutPromise = new Promise<string>((resolve) => {
|
||||
const timer = setTimeout(() => {
|
||||
resolve(faviconUrls[0]) // Default to first URL after timeout
|
||||
}, 2000)
|
||||
|
||||
// Clear timeout if signal is aborted
|
||||
signal.addEventListener('abort', () => clearTimeout(timer))
|
||||
})
|
||||
|
||||
// Use Promise.race to get the first successful result
|
||||
Promise.race([
|
||||
// Filter out failed requests (null results)
|
||||
Promise.any(faviconPromises)
|
||||
.then((result) => result || faviconUrls[0]) // Ensure we always have a string, not null
|
||||
.catch(() => faviconUrls[0]),
|
||||
timeoutPromise
|
||||
])
|
||||
.then((url) => {
|
||||
setFaviconState({ status: 'loaded', src: url })
|
||||
})
|
||||
.catch((error) => {
|
||||
console.debug('All favicon requests failed:', error)
|
||||
setFaviconState({ status: 'loaded', src: faviconUrls[0] })
|
||||
})
|
||||
|
||||
// Cleanup function
|
||||
return () => {
|
||||
controller.abort()
|
||||
}
|
||||
}, [hostname]) // Only depend on hostname
|
||||
|
||||
const handleError = () => {
|
||||
setFaviconState({ status: 'failed' })
|
||||
}
|
||||
|
||||
// Render based on current state
|
||||
if (faviconState.status === 'failed') {
|
||||
return <FaviconPlaceholder>{hostname.charAt(0).toUpperCase()}</FaviconPlaceholder>
|
||||
}
|
||||
|
||||
if (faviconState.status === 'loaded') {
|
||||
return <Favicon src={faviconState.src} alt={alt} onError={handleError} />
|
||||
}
|
||||
|
||||
return <FaviconLoading />
|
||||
}
|
||||
|
||||
const FaviconLoading = styled.div`
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 4px;
|
||||
background-color: var(--color-background-mute);
|
||||
`
|
||||
|
||||
const FaviconPlaceholder = styled.div`
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 4px;
|
||||
background-color: var(--color-primary-1);
|
||||
color: var(--color-primary-6);
|
||||
font-size: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
`
|
||||
const Favicon = styled.img`
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 4px;
|
||||
background-color: var(--color-background-mute);
|
||||
`
|
||||
|
||||
export default FallbackFavicon
|
||||
@@ -24,6 +24,7 @@ const MinAppIcon: FC<Props> = ({ app, size = 48, style }) => {
|
||||
width: `${size}px`,
|
||||
height: `${size}px`,
|
||||
backgroundColor: _app.background,
|
||||
...app.style,
|
||||
...style
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { Tooltip } from 'antd'
|
||||
import React, { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled from 'styled-components'
|
||||
|
||||
const ReasoningIcon: FC<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>> = (props) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Tooltip title={t('models.reasoning')} placement="top">
|
||||
<Icon className="iconfont icon-thinking" {...(props as any)} />
|
||||
</Tooltip>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
31
src/renderer/src/components/Icons/ToolsCallingIcon.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { ToolOutlined } from '@ant-design/icons'
|
||||
import { Tooltip } from 'antd'
|
||||
import React, { FC } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled from 'styled-components'
|
||||
|
||||
const ToolsCallingIcon: FC<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>> = (props) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Tooltip title={t('models.function_calling')} placement="top">
|
||||
<Icon {...(props as any)} />
|
||||
</Tooltip>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
const Container = styled.div`
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
`
|
||||
|
||||
const Icon = styled(ToolOutlined)`
|
||||
color: #d97757;
|
||||
font-size: 15px;
|
||||
margin-right: 6px;
|
||||
`
|
||||
|
||||
export default ToolsCallingIcon
|
||||
17
src/renderer/src/components/Icons/UnWrapIcon.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
const UnWrapIcon = (props: React.SVGProps<SVGSVGElement>) => (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="1em"
|
||||
height="1em"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
className="unwrap_svg__lucide unwrap_svg__lucide-text unwrap_svg__size-4"
|
||||
viewBox="0 0 24 24"
|
||||
{...props}>
|
||||
<path d="M17 6.1H3M21 12.1H3M15.1 18H3" />
|
||||
</svg>
|
||||
)
|
||||
export default UnWrapIcon
|
||||