Skip to content

Commit 80a4f1c

Browse files
committed
Add @mantine/form package and ConfigStore to RootStore
1 parent 96f6f79 commit 80a4f1c

10 files changed

Lines changed: 557 additions & 43 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"@emotion/react": "^11.10.8",
113113
"@mantine/core": "^6.0.10",
114114
"@mantine/dropzone": "^6.0.10",
115+
"@mantine/form": "^7.5.3",
115116
"@mantine/hooks": "^6.0.10",
116117
"@mantine/prism": "^6.0.10",
117118
"@mantine/tiptap": "^6.0.10",
@@ -126,6 +127,7 @@
126127
"dotenv": "^16.0.3",
127128
"i18next": "^23.7.11",
128129
"js-yaml": "^4.1.0",
130+
"lodash.isequal": "^4.5.0",
129131
"mdast": "^3.0.0",
130132
"mdast-util-from-markdown": "^2.0.0",
131133
"mdast-util-to-markdown": "^2.1.0",

src/util/ideaBridge.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ const JStoIdea = {
318318

319319
window.JSJavaBridge.callJava(JSON.stringify(params));
320320
},
321+
readConfig: () => {
322+
// 获取完整的用户设置
323+
const params = {
324+
action: "getSetting/request",
325+
metadata: {
326+
callback: "IdeaToJSMessage",
327+
},
328+
payload: {},
329+
};
330+
window.JSJavaBridge.callJava(JSON.stringify(params));
331+
},
332+
saveConfig: (data) => {
333+
const params = {
334+
action: "updateSettings/request",
335+
metadata: {
336+
callback: "IdeaToJSMessage",
337+
},
338+
payload: data,
339+
};
340+
console.log("saveConfig params: ", params);
341+
window.JSJavaBridge.callJava(JSON.stringify(params));
342+
},
321343
};
322344

323345
class IdeaBridge {
@@ -444,7 +466,10 @@ class IdeaBridge {
444466

445467
resviceSettings(res) {
446468
// 用户设置的回调
447-
const setting = res.payload.setting;
469+
const setting = res?.payload || {};
470+
console.log("setting: ", setting);
471+
this.executeHandlers("readConfig", setting);
472+
return;
448473

449474
let key = setting?.apiKey || "";
450475
// idea 默认的 key 是 change_me,所以这里要清空
@@ -460,23 +485,12 @@ class IdeaBridge {
460485
key2: "defaultModel",
461486
});
462487

463-
// this.handle.getUserAccessKey({
464-
// endPoint: setting.apiBase,
465-
// accessKey: key,
466-
// keyType: key.startsWith("DC") ? "DevChat" : "OpenAi",
467-
// });
468-
469488
this.executeHandlers("getUserAccessKey", {
470489
endPoint: setting.apiBase,
471490
accessKey: key,
472491
keyType: key.startsWith("DC") ? "DevChat" : "OpenAi",
473492
});
474493

475-
// this.handle.getSetting({
476-
// value: setting.language,
477-
// key2: "Language",
478-
// });
479-
480494
this.executeHandlers("getSetting", {
481495
value: setting.language,
482496
key2: "Language",
@@ -645,6 +659,13 @@ class IdeaBridge {
645659
case "stopDevChat":
646660
JStoIdea.stopDevChat();
647661
break;
662+
case "readConfig":
663+
JStoIdea.readConfig();
664+
break;
665+
case "saveConfig":
666+
// 保存用户设置
667+
JStoIdea.saveConfig(message.data);
668+
break;
648669
default:
649670
break;
650671
}

src/util/modelName.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const nameMap = {
2+
"gpt-3.5-turbo": "GPT-3.5",
3+
"gpt-4": "GPT-4",
4+
"gpt-4-turbo-preview": "GPT-4-turbo",
5+
"claude-2.1": "CLAUDE-2.1",
6+
"xinghuo-3.5": "xinghuo-3.5",
7+
"GLM-4": "GLM-4",
8+
"ERNIE-Bot-4.0": "ERNIE-Bot-4.0",
9+
"togetherai/codellama/CodeLlama-70b-Instruct-hf": "CodeLlama-70b",
10+
"togetherai/mistralai/Mixtral-8x7B-Instruct-v0.1": "Mixtral-8x7B",
11+
"minimax/abab6-chat": "minimax-abab6",
12+
"llama-2-70b-chat": "llama2-70b",
13+
};
14+
15+
export default function getModelShowName(modelName: string) {
16+
if (modelName in nameMap) {
17+
return nameMap[modelName];
18+
} else if (modelName.lastIndexOf("/") > -1) {
19+
return modelName
20+
.substring(modelName.lastIndexOf("/") + 1)
21+
.toLocaleUpperCase();
22+
} else {
23+
return modelName.toUpperCase();
24+
}
25+
}

src/views/App.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import * as React from "react";
22
import { AppShell, LoadingOverlay } from "@mantine/core";
33
import ChatPanel from "@/views/pages/ChatPanel";
4+
import Config from "./pages/Config";
45
import Head from "@/views/components/Header";
6+
import { CurrentRouteType, IRouter, RouterContext } from "./router";
57
import "./App.css";
68
import "./i18n";
79

810
export default function App() {
911
const [ready, setReady] = React.useState(false);
12+
const [currentRoute, setCurrentRoute] =
13+
React.useState<CurrentRouteType>("chat");
14+
15+
const router: IRouter = {
16+
currentRoute,
17+
updateRoute: setCurrentRoute,
18+
};
1019

1120
React.useEffect(() => {
1221
if (process.env.platform === "vscode") {
@@ -24,17 +33,26 @@ export default function App() {
2433
}, []);
2534

2635
return (
27-
<AppShell
28-
header={ready ? <Head /> : <div></div>}
29-
styles={{
30-
main: {
31-
padding: "40px 0 0 0",
32-
fontFamily: "var(--vscode-editor-font-family)",
33-
fontSize: "var(--vscode-editor-font-size)",
34-
},
35-
}}
36-
>
37-
{ready ? <ChatPanel /> : <LoadingOverlay visible />}
38-
</AppShell>
36+
<RouterContext.Provider value={router}>
37+
<AppShell
38+
header={ready ? <Head /> : <div></div>}
39+
styles={{
40+
main: {
41+
padding: "40px 0 0 0",
42+
fontFamily: "var(--vscode-editor-font-family)",
43+
fontSize: "var(--vscode-editor-font-size)",
44+
},
45+
}}
46+
>
47+
{ready ? (
48+
<>
49+
<ChatPanel />
50+
<Config />
51+
</>
52+
) : (
53+
<LoadingOverlay visible />
54+
)}
55+
</AppShell>
56+
</RouterContext.Provider>
3957
);
4058
}

src/views/components/Header/index.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import {
88
createStyles,
99
} from "@mantine/core";
1010
import BalanceTip from "@/views/components/BalanceTip";
11-
import { IconSettings, IconLanguage } from "@tabler/icons-react";
11+
import { IconSettings, IconLanguage, IconMessages } from "@tabler/icons-react";
1212
import { useTranslation } from "react-i18next";
1313
// @ts-ignore
1414
import SvgAvatarDevChat from "../MessageAvatar/avatar_devchat.svg";
1515
import messageUtil from "@/util/MessageUtil";
16+
import { useRouter } from "@/views/router";
1617

1718
const useStyles = createStyles((theme) => ({
1819
logoName: {
@@ -21,6 +22,7 @@ const useStyles = createStyles((theme) => ({
2122
}));
2223

2324
export default function Head() {
25+
const router = useRouter();
2426
const { classes } = useStyles();
2527
const { i18n } = useTranslation();
2628

@@ -46,10 +48,21 @@ export default function Head() {
4648
}, []);
4749

4850
const openSetting = () => {
49-
messageUtil.sendMessage({
50-
command: "doCommand",
51-
content: ["workbench.action.openSettings", "@ext:merico.devchat"],
52-
});
51+
if (router.currentRoute === "config") return;
52+
router.updateRoute("config");
53+
// messageUtil.sendMessage({
54+
// command: "doCommand",
55+
// content: ["workbench.action.openSettings", "@ext:merico.devchat"],
56+
// });
57+
};
58+
59+
const openChat = () => {
60+
if (router.currentRoute === "chat") return;
61+
router.updateRoute("chat");
62+
// messageUtil.sendMessage({
63+
// command: "doCommand",
64+
// content: ["workbench.action.openSettings", "@ext:merico.devchat"],
65+
// });
5366
};
5467

5568
const switchLang = () => {
@@ -89,10 +102,22 @@ export default function Head() {
89102
</Flex>
90103
<Flex align="center" gap="xs" sx={{ paddingRight: 10 }}>
91104
<div>
92-
<BalanceTip />
105+
<ActionIcon
106+
size="sm"
107+
onClick={openChat}
108+
color={router.currentRoute === "chat" ? "merico" : "gray"}
109+
variant={router.currentRoute === "chat" ? "filled" : "subtle"}
110+
>
111+
<IconMessages size="1.125rem" />
112+
</ActionIcon>
93113
</div>
94114
<div>
95-
<ActionIcon size="sm" onClick={openSetting}>
115+
<ActionIcon
116+
size="sm"
117+
onClick={openSetting}
118+
color={router.currentRoute === "config" ? "merico" : "gray"}
119+
variant={router.currentRoute === "config" ? "filled" : "subtle"}
120+
>
96121
<IconSettings size="1.125rem" />
97122
</ActionIcon>
98123
</div>
@@ -101,6 +126,9 @@ export default function Head() {
101126
<IconLanguage size="1.125rem" />
102127
</ActionIcon>
103128
</div>
129+
<div>
130+
<BalanceTip />
131+
</div>
104132
</Flex>
105133
</Flex>
106134
</Header>

0 commit comments

Comments
 (0)