Skip to content

Commit 3d571b9

Browse files
committed
Add lastRoute property to IRouter interface and update setCurrentRoute function
1 parent 80a4f1c commit 3d571b9

16 files changed

Lines changed: 357 additions & 347 deletions

File tree

src/index.tsx

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
1-
import * as React from 'react';
2-
import { createRoot } from 'react-dom/client';
3-
import { MantineProvider, MantineThemeOverride } from '@mantine/core';
4-
import { Provider, rootStore } from '@/views/stores/RootStore';
5-
import App from '@/views/App';
1+
import * as React from "react";
2+
import { createRoot } from "react-dom/client";
3+
import { MantineProvider, MantineThemeOverride } from "@mantine/core";
4+
import { Provider, rootStore } from "@/views/stores/RootStore";
5+
import App from "@/views/App";
66

7-
const container = document.getElementById('app')!;
7+
const container = document.getElementById("app")!;
88
const root = createRoot(container); // createRoot(container!) if you use TypeScript
99
const myTheme: MantineThemeOverride = {
10-
fontFamily: 'var(--vscode-editor-font-family)',
11-
colors: {
12-
"merico":[
13-
"#F9F5F4",
14-
"#EADAD6",
15-
"#E1C0B6",
16-
"#DEA594",
17-
"#E1886F",
18-
"#ED6A45",
19-
"#D75E3C",
20-
"#BD573B",
21-
"#9F5541",
22-
"#865143",
23-
],
24-
},
25-
primaryColor: 'merico',
26-
components: {
27-
Text: {
28-
styles: {
29-
root:{
30-
fontSize: 'var(--vscode-editor-font-size)',
31-
}
32-
}
10+
fontFamily: "var(--vscode-editor-font-family)",
11+
colors: {
12+
merico: [
13+
"#F9F5F4",
14+
"#EADAD6",
15+
"#E1C0B6",
16+
"#DEA594",
17+
"#E1886F",
18+
"#ED6A45",
19+
"#D75E3C",
20+
"#BD573B",
21+
"#9F5541",
22+
"#865143",
23+
],
24+
},
25+
primaryColor: "merico",
26+
components: {
27+
Text: {
28+
styles: {
29+
root: {
30+
fontSize: "var(--vscode-editor-font-size)",
3331
},
3432
},
33+
},
34+
},
3535
};
36-
3736

3837
root.render(
39-
<MantineProvider withGlobalStyles withNormalizeCSS withCSSVariables
40-
theme={myTheme}>
41-
<Provider value={rootStore}>
42-
<App />
43-
</Provider>
44-
</MantineProvider>
38+
<MantineProvider
39+
withGlobalStyles
40+
withNormalizeCSS
41+
withCSSVariables
42+
theme={myTheme}
43+
>
44+
<Provider value={rootStore}>
45+
<App />
46+
</Provider>
47+
</MantineProvider>
4548
);

src/models/index.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const modelsTemplate = [
2+
{
3+
name: "gpt-3.5-turbo",
4+
provider: "openai",
5+
max_input_tokens: 13000,
6+
temperature: 0.3,
7+
max_tokens: 2048,
8+
},
9+
{
10+
name: "gpt-4",
11+
provider: "openai",
12+
max_input_tokens: 6000,
13+
temperature: 0.3,
14+
max_tokens: 2048,
15+
},
16+
{
17+
name: "gpt-4-turbo-preview",
18+
provider: "openai",
19+
max_input_tokens: 32000,
20+
temperature: 0.3,
21+
max_tokens: 2048,
22+
},
23+
{
24+
name: "claude-2.1",
25+
provider: "devchat",
26+
max_input_tokens: 32000,
27+
temperature: 0.3,
28+
max_tokens: 2048,
29+
},
30+
{
31+
name: "xinghuo-3.5",
32+
provider: "devchat",
33+
max_input_tokens: 6000,
34+
temperature: 0.3,
35+
max_tokens: 2048,
36+
},
37+
{
38+
name: "GLM-4",
39+
provider: "devchat",
40+
max_input_tokens: 8000,
41+
temperature: 0.3,
42+
max_tokens: 2048,
43+
},
44+
{
45+
name: "ERNIE-Bot-4.0",
46+
provider: "devchat",
47+
max_input_tokens: 8000,
48+
temperature: 0.3,
49+
max_tokens: 2048,
50+
},
51+
{
52+
name: "togetherai/codellama/CodeLlama-70b-Instruct-hf",
53+
provider: "devchat",
54+
max_input_tokens: 4000,
55+
temperature: 0.3,
56+
max_tokens: 2048,
57+
},
58+
{
59+
name: "togetherai/mistralai/Mixtral-8x7B-Instruct-v0.1",
60+
provider: "devchat",
61+
max_input_tokens: 4000,
62+
temperature: 0.3,
63+
max_tokens: 2048,
64+
},
65+
{
66+
name: "minimax/abab6-chat",
67+
provider: "devchat",
68+
max_input_tokens: 4000,
69+
temperature: 0.3,
70+
max_tokens: 2048,
71+
},
72+
{
73+
name: "llama-2-70b-chat",
74+
provider: "devchat",
75+
max_input_tokens: 4000,
76+
temperature: 0.3,
77+
max_tokens: 2048,
78+
},
79+
];
80+
81+
export default modelsTemplate;

src/util/ideaBridge.ts

Lines changed: 14 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,7 @@ const JStoIdea = {
9999

100100
window.JSJavaBridge.callJava(JSON.stringify(params));
101101
},
102-
getUserAccessKey: () => {
103-
// 这里需要发送一个请求,获取完整的用户设置
104-
const params = {
105-
action: "getSetting/request",
106-
metadata: {
107-
callback: "IdeaToJSMessage",
108-
},
109-
payload: {},
110-
};
111-
window.JSJavaBridge.callJava(JSON.stringify(params));
112-
},
102+
113103
etcCommand: (command: any) => {
114104
/**
115105
* 有四种命令
@@ -160,24 +150,6 @@ const JStoIdea = {
160150

161151
window.JSJavaBridge.callJava(JSON.stringify(params));
162152
},
163-
updateSetting: (message: { value: string; key2: string }) => {
164-
if (message.key2 === "Language") {
165-
JStoIdea.setLanguage(message.value);
166-
return;
167-
}
168-
const params = {
169-
action: "updateSetting/request",
170-
metadata: {
171-
callback: "IdeaToJSMessage",
172-
},
173-
payload: {
174-
setting: {
175-
currentModel: message.value,
176-
},
177-
},
178-
};
179-
window.JSJavaBridge.callJava(JSON.stringify(params));
180-
},
181153
commit: (code: string) => {
182154
const params = {
183155
action: "commitCode/request",
@@ -270,19 +242,6 @@ const JStoIdea = {
270242

271243
window.JSJavaBridge.callJava(JSON.stringify(params));
272244
},
273-
setLanguage: (language) => {
274-
const params = {
275-
action: "updateLanguage/request",
276-
metadata: {
277-
callback: "IdeaToJSMessage",
278-
},
279-
payload: {
280-
language: language || "en",
281-
},
282-
};
283-
console.log("setLanguage params: ", params);
284-
window.JSJavaBridge.callJava(JSON.stringify(params));
285-
},
286245
userInput: (message) => {
287246
const params = {
288247
action: "input/request",
@@ -331,13 +290,14 @@ const JStoIdea = {
331290
},
332291
saveConfig: (data) => {
333292
const params = {
334-
action: "updateSettings/request",
293+
action: "updateSetting/request",
335294
metadata: {
336295
callback: "IdeaToJSMessage",
337296
},
338297
payload: data,
339298
};
340-
console.log("saveConfig params: ", params);
299+
300+
console.log("ready to call java: ", JSON.stringify(params));
341301
window.JSJavaBridge.callJava(JSON.stringify(params));
342302
},
343303
};
@@ -350,8 +310,11 @@ class IdeaBridge {
350310
this.handle = {};
351311
// 注册全局的回调函数,用于接收来自 IDEA 的消息
352312
window.IdeaToJSMessage = (res: any) => {
353-
console.log("IdeaToJSMessage: ", res);
313+
console.info("IdeaToJSMessage get res: ", res);
354314
switch (res.action) {
315+
case "updateSetting/response":
316+
this.resviceUpdateSetting(res);
317+
break;
355318
case "sendUserMessage/response":
356319
this.resviceSendUserMessage(res);
357320
break;
@@ -395,6 +358,11 @@ class IdeaBridge {
395358
};
396359
}
397360

361+
resviceUpdateSetting(res) {
362+
// 更新用户设置之后的回调
363+
this.executeHandlers("updateSetting", res.payload);
364+
}
365+
398366
resviceSendUserMessage(res) {
399367
this.executeHandlers("chatWithDevChat", {
400368
command: "chatWithDevChat",
@@ -467,34 +435,8 @@ class IdeaBridge {
467435
resviceSettings(res) {
468436
// 用户设置的回调
469437
const setting = res?.payload || {};
470-
console.log("setting: ", setting);
471-
this.executeHandlers("readConfig", setting);
472-
return;
473438

474-
let key = setting?.apiKey || "";
475-
// idea 默认的 key 是 change_me,所以这里要清空
476-
if (setting?.apiKey.includes("change")) {
477-
key = "";
478-
}
479-
480-
// 当前的默认模型
481-
// this.handle.getSetting({});
482-
483-
this.executeHandlers("getSetting", {
484-
value: setting.currentModel,
485-
key2: "defaultModel",
486-
});
487-
488-
this.executeHandlers("getUserAccessKey", {
489-
endPoint: setting.apiBase,
490-
accessKey: key,
491-
keyType: key.startsWith("DC") ? "DevChat" : "OpenAi",
492-
});
493-
494-
this.executeHandlers("getSetting", {
495-
value: setting.language,
496-
key2: "Language",
497-
});
439+
this.executeHandlers("readConfig", setting);
498440
}
499441

500442
resviceCommandList(res) {
@@ -582,7 +524,6 @@ class IdeaBridge {
582524
}
583525

584526
sendMessage(message: any) {
585-
console.log("sendMessage message: ", message);
586527
// 根据 command 分发到不同的方法·
587528
switch (message.command) {
588529
// 发送消息
@@ -614,18 +555,12 @@ class IdeaBridge {
614555
case "code_file_apply":
615556
JStoIdea.replaceFileContent(message.content);
616557
break;
617-
case "getUserAccessKey":
618-
JStoIdea.getUserAccessKey();
619-
break;
620558
case "doCommand":
621559
JStoIdea.etcCommand(message);
622560
break;
623561
case "show_diff":
624562
JStoIdea.viewDiff(message.content);
625563
break;
626-
case "updateSetting":
627-
JStoIdea.updateSetting(message);
628-
break;
629564
case "doCommit":
630565
JStoIdea.commit(message.content);
631566
break;
@@ -647,9 +582,6 @@ class IdeaBridge {
647582
case "userInput":
648583
JStoIdea.userInput(message);
649584
break;
650-
case "setLanguage":
651-
JStoIdea.setLanguage(message);
652-
break;
653585
case "setNewTopic":
654586
JStoIdea.setNewTopic();
655587
break;

0 commit comments

Comments
 (0)