Skip to content

Commit 2028a1b

Browse files
authored
Merge pull request #15 from devchat-ai/feat/text
Feat/text
2 parents d527f20 + 7011040 commit 2028a1b

9 files changed

Lines changed: 123 additions & 88 deletions

File tree

src/util/ideaBridge.ts

Lines changed: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,6 @@ class IdeaBridge {
303303
case "listCommands/response":
304304
this.resviceCommandList(res);
305305
break;
306-
// 这里暂时不用,因为获取到的只有 key,信息不全
307-
// 所以用 resviceSettings 来获取
308-
// case "getKey/response":
309-
// this.resviceAccessKey(res.payload.key);
310-
// break;
311306
case "addContext/notify":
312307
this.resviesContext(res);
313308
break;
@@ -331,15 +326,18 @@ class IdeaBridge {
331326
}
332327

333328
resviceSendUserMessage(res) {
334-
this.handle.chatWithDevChat({
329+
this.executeHandlers("chatWithDevChat", {
335330
command: "chatWithDevChat",
336331
message: res.payload.message || "",
337332
});
338333
}
339334

340335
resviceDeleteMessage(res) {
341336
const hash = res?.payload?.promptHash || "";
342-
this.handle.deletedChatMessage({
337+
// this.handle.deletedChatMessage({
338+
// hash,
339+
// });
340+
this.executeHandlers("deletedChatMessage", {
343341
hash,
344342
});
345343
}
@@ -354,8 +352,11 @@ class IdeaBridge {
354352
});
355353
});
356354
}
357-
358-
this.handle.reloadMessage({
355+
// this.handle.reloadMessage({
356+
// entries: list.reverse(),
357+
// pageIndex: 0,
358+
// });
359+
this.executeHandlers("reloadMessage", {
359360
entries: list.reverse(),
360361
pageIndex: 0,
361362
});
@@ -371,7 +372,10 @@ class IdeaBridge {
371372

372373
resviceTopicList(res) {
373374
const list = res.payload.topics;
374-
this.handle.listTopics(list);
375+
// this.handle.listTopics(list);
376+
this.executeHandlers("listTopics", {
377+
list,
378+
});
375379
}
376380

377381
resviesContext(res) {
@@ -385,7 +389,8 @@ class IdeaBridge {
385389
command: "",
386390
};
387391
params.result = JSON.stringify(contextObj);
388-
this.handle.contextDetailResponse(params);
392+
// this.handle.contextDetailResponse(params);
393+
this.executeHandlers("contextDetailResponse", params);
389394
}
390395

391396
resviceSettings(res) {
@@ -399,76 +404,93 @@ class IdeaBridge {
399404
}
400405

401406
// 当前的默认模型
402-
this.handle.getSetting({
407+
// this.handle.getSetting({});
408+
409+
this.executeHandlers("getSetting", {
403410
value: setting.currentModel,
404411
key2: "defaultModel",
405412
});
406413

407-
this.handle.getUserAccessKey({
414+
// this.handle.getUserAccessKey({
415+
// endPoint: setting.apiBase,
416+
// accessKey: key,
417+
// keyType: key.startsWith("DC") ? "DevChat" : "OpenAi",
418+
// });
419+
420+
this.executeHandlers("getUserAccessKey", {
408421
endPoint: setting.apiBase,
409422
accessKey: key,
410423
keyType: key.startsWith("DC") ? "DevChat" : "OpenAi",
411424
});
412-
this.handle.getSetting({
425+
426+
// this.handle.getSetting({
427+
// value: setting.language,
428+
// key2: "Language",
429+
// });
430+
431+
this.executeHandlers("getSetting", {
413432
value: setting.language,
414433
key2: "Language",
415434
});
416435
}
417436

418-
resviceAccessKey(res: string = "") {
419-
const params = {
420-
endPoint: "",
421-
accessKey: res,
422-
keyType: res.startsWith("DC") ? "DevChat" : "OpenAi",
423-
};
424-
this.handle.getUserAccessKey(params);
425-
}
426-
427437
resviceCommandList(res) {
428438
const result = res.payload.commands.map((item) => ({
429439
name: item.name,
430440
pattern: item.name,
431441
description: item.description,
432442
}));
433-
this.handle.regCommandList({
443+
// this.handle.regCommandList({
444+
// result,
445+
// });
446+
this.executeHandlers("regCommandList", {
434447
result,
435448
});
436449
}
437450

438451
resviceContextList(res) {
439452
// 接受到的上下文列表
440-
441453
const result = res.payload.contexts.map((item) => ({
442454
name: item.command,
443455
pattern: item.command,
444456
description: item.description,
445457
}));
446458

447-
this.handle.regContextList({ result });
459+
// this.handle.regContextList({ result });
460+
this.executeHandlers("regContextList", {
461+
result,
462+
});
448463
}
449464

450465
resviceModelList(response: any) {
451466
// 接受到模型列表
452-
this.handle["regModelList"]({
467+
// this.handle["regModelList"]({
468+
// result: response.payload.models,
469+
// });
470+
this.executeHandlers("regModelList", {
453471
result: response.payload.models,
454472
});
455473
}
456474

457475
resviceMessage(response: any) {
458-
console.log(
459-
"response.metadata.isFinalChunk: ",
460-
response.metadata.isFinalChunk
461-
);
462476
// 接受到消息
463477
if (response.metadata?.isFinalChunk) {
464478
// 结束对话
465-
this.handle["receiveMessage"]({
479+
// this.handle["receiveMessage"]({
480+
// text: response.payload?.message || response.metadata?.error || "",
481+
// isError: response.metadata?.error.length > 0,
482+
// hash: response.payload?.promptHash || "",
483+
// });
484+
this.executeHandlers("receiveMessage", {
466485
text: response.payload?.message || response.metadata?.error || "",
467486
isError: response.metadata?.error.length > 0,
468487
hash: response.payload?.promptHash || "",
469488
});
470489
} else {
471-
this.handle["receiveMessagePartial"]({
490+
// this.handle["receiveMessagePartial"]({
491+
// text: response?.payload?.message || "",
492+
// });
493+
this.executeHandlers("receiveMessagePartial", {
472494
text: response?.payload?.message || "",
473495
});
474496
}
@@ -482,8 +504,18 @@ class IdeaBridge {
482504
}
483505

484506
registerHandler(messageType: string, handler: any) {
485-
// 注册回调函数
486-
this.handle[messageType] = handler;
507+
if (!this.handle[messageType]) {
508+
this.handle[messageType] = [];
509+
}
510+
this.handle[messageType].push(handler);
511+
}
512+
513+
executeHandlers(messageType: string, data: any) {
514+
if (this.handle[messageType]) {
515+
this.handle[messageType].forEach((handler) => {
516+
handler(data);
517+
});
518+
}
487519
}
488520

489521
sendMessage(message: any) {

src/views/App.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import * as React from "react";
2-
import { AppShell } from "@mantine/core";
2+
import { AppShell, LoadingOverlay } from "@mantine/core";
33
import ChatPanel from "@/views/pages/ChatPanel";
44
import Head from "@/views/components/Header";
55
import "./App.css";
66
import "./i18n";
77

88
export default function App() {
9+
const [ready, setReady] = React.useState(false);
10+
11+
React.useEffect(() => {
12+
if (process.env.platform === "vscode") {
13+
setReady(true);
14+
return;
15+
}
16+
const checkReady = () => {
17+
console.log("window.JSJavaBridge: ", window.JSJavaBridge);
18+
if (window.JSJavaBridge) {
19+
setReady(true);
20+
} else {
21+
setTimeout(checkReady, 200);
22+
}
23+
};
24+
checkReady();
25+
}, []);
26+
927
return (
1028
<AppShell
11-
header={<Head />}
29+
header={ready ? <Head /> : <div></div>}
1230
styles={{
1331
main: {
1432
padding: "40px 0 0 0",
@@ -17,7 +35,7 @@ export default function App() {
1735
},
1836
}}
1937
>
20-
<ChatPanel />
38+
{ready ? <ChatPanel /> : <LoadingOverlay visible />}
2139
</AppShell>
2240
);
2341
}

src/views/components/BalanceTip/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ export default function WechatTip() {
8888
messageUtil.registerHandler(
8989
"getUserAccessKey",
9090
(message: { endPoint: string; accessKey: string; keyType: string }) => {
91-
console.log("message: ", message);
92-
if (message.keyType === "DevChat" && message.accessKey) {
91+
if (message.accessKey) {
9392
if (message.endPoint.includes("api-test.devchat.ai")) {
9493
setEnv("dev");
9594
} else {

src/views/components/Header/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default function Head() {
3333
messageUtil.registerHandler(
3434
"getSetting",
3535
(data: { key2: string; value: string }) => {
36+
console.log("data: ", data);
3637
if (data.key2 === "Language") {
3738
if (data.value && data.value.toLocaleLowerCase() === "en") {
3839
i18n.changeLanguage("en");

src/views/components/InputMessage/Topic.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export default function Topic({ styleName }) {
1414
messageUtil.sendMessage({
1515
command: "listTopics",
1616
});
17-
messageUtil.registerHandler("listTopics", (data) => {
18-
setTopicList(data);
17+
messageUtil.registerHandler("listTopics", ({ list }: { list: any }) => {
18+
setTopicList(list);
1919
});
2020
}, []);
2121

src/views/components/MessageMarkdown/index.tsx

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const MessageMarkdown = observer((props: MessageMarkdownProps) => {
7575
const platform = process.env.platform;
7676

7777
const handleExplain = (value: string | undefined) => {
78-
console.log(value);
7978
switch (value) {
8079
case "#ask_code":
8180
chat.addMessages([
@@ -114,21 +113,6 @@ Use this DevChat workflow to request code writing. Please input your specific re
114113
}),
115114
]);
116115
break;
117-
case "#commit_message":
118-
chat.addMessages([
119-
Message.create({
120-
type: "user",
121-
message: "Explain /commit_message",
122-
}),
123-
Message.create({
124-
type: "bot",
125-
message: `***/commit_message***
126-
127-
Use this DevChat workflow to request a commit message. Generally, you don't need to type anything else, but please give me the output of \`git diff\`. Of course, you don't need to manually execute the command and copy & paste its output. Simply click the "+" button and select \`git diff —cached\` to include only the staged changes, or \`git diff HEAD\` to include all changes.
128-
`,
129-
}),
130-
]);
131-
break;
132116
case "#release_note":
133117
chat.addMessages([
134118
Message.create({
@@ -239,24 +223,33 @@ Generate a professionally written and formatted release note in markdown with th
239223
if (children.includes("You can configure DevChat from")) {
240224
return t("devchat.help");
241225
}
242-
// DevChat key is missing from your environment or settings
243226
if (
244-
children.includes("DevChat key is missing from your environment ")
227+
children.includes(
228+
"Devchat key is missing from your environment or settings"
229+
)
245230
) {
246231
return t("devchat.setkey");
247232
}
248233
if (
249234
children.includes(
250-
"OPENAI_API_KEY is missing from your environment or settings"
235+
"DevChat intelligently navigates your codebase using GPT-4."
251236
)
252237
) {
253-
// vscode 用
254-
if (children.includes("Set OpenAI key")) {
255-
return t("devchat.setOpenAIkey");
256-
} else {
257-
// idea 用
258-
return t("devchat.setkey");
259-
}
238+
return t("ask-code-explain");
239+
}
240+
if (
241+
children.includes(
242+
"Use this DevChat workflow to request code writing. Please input your specific requirement"
243+
)
244+
) {
245+
return t("code-explain");
246+
}
247+
if (
248+
children.includes(
249+
"Generate a professionally written and formatted release note in markdown with this workflow. I just need some basic information"
250+
)
251+
) {
252+
return t("note-explain");
260253
}
261254
}
262255
}
@@ -323,7 +316,7 @@ Generate a professionally written and formatted release note in markdown with th
323316
if (lanugage === "step" || lanugage === "Step") {
324317
const status =
325318
activeStep &&
326-
Number(index) === codes.length - 1 &&
319+
Number(index) === codes.length &&
327320
lastNode.type === "code"
328321
? "running"
329322
: "done";

src/views/i18n/zh.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88
"Ask DevChat a question or type ‘/’ for workflow": "向 DevChat 直接提问或输入 '/' 以查看可用的工作流",
99
"How do I use DevChat?": "如何使用 DevChat?",
1010
"balance": "你的账户余额为 {{formatedCurrency}},登录 <4>web.devchat.ai</4> 获得更多 tokens",
11-
"devchat.help": "你想生成一些代码还是对这个项目有疑问?请首先右键单击相关的文件或代码片段,将它们添加到 DevChat 中作为上下文,然后在输入框中写下你的请求或问题,我将基于添加的上下文生成代码或回答你的问题。<br> <br> 你还可以点击输入框左侧的“+”按钮,查看更多添加上下文的快捷方法。此外,在输入框中键入“/”,DevChat 会列出可供使用的各类工作流,按 Tab 键或输入完整命令触发你需要的工作流。聊天愉快! <br> <br>下面是一些工作流的示例:<br> <br> [/code: 基于你的提示词和上下文生成代码](#code) <br> <br> [/commit_message: 根据加入上下文中的代码变更生成提交消息](#commit_message) <br> <br> [/release_note: 根据加入上下文中的提交历史生成提交说明](#release_note) <br> <br> [/ask-code: 询问任何关于当前代码库的信息,并从这位人工智能代理那里获得答案](#ask_code) <br> <br>你可以点击[设置](#settings)来配置 DevChat",
12-
"devchat.setkey": "你的环境或设置中缺少 DevChat 访问密钥。请输入你的 DevChat 访问密钥,这样我就可以开始正常工作了。<br> <br> <button value=\"get_devchat_key\" href=\"https://web.devchat.ai\" component=\"a\">注册获取 DevChat 访问密钥</button> <button value=\"setting_devchat_key\">设置 DevChat 访问密钥</button>",
13-
"devchat.setOpenAIkey": "你的环境或设置中缺少 OpenAI 访问密钥。请输入你的 OpenAI 或者 DevChat 访问密钥,这样我就可以开始正常工作了。<br> <br> <button value=\"get_devchat_key\" href=\"https://web.devchat.ai\" component=\"a\">注册获取 DevChat 密钥</button> <button value=\"setting_devchat_key\">设置 DevChat 密钥</button> <button value=\"setting_devchat_key\">设置 OpenAI 密钥</button>",
11+
"devchat.help": "你想生成一些代码还是对这个项目有疑问?请首先右键单击相关的文件或代码片段,将它们添加到 DevChat 中作为上下文,然后在输入框中写下你的请求或问题,我将基于添加的上下文生成代码或回答你的问题。<br> <br> 你还可以点击输入框左侧的“+”按钮,查看更多添加上下文的快捷方法。此外,在输入框中键入“/”,DevChat 会列出可供使用的各类工作流,按 Tab 键或输入完整命令触发你需要的工作流。聊天愉快! <br> <br>下面是一些工作流的示例:<br> <br> [/code: 基于你的提示词和上下文生成代码](#code) <br> <br> [/release_note: 根据加入上下文中的提交历史生成提交说明](#release_note) <br> <br> [/ask-code: 询问任何关于当前代码库的信息,并从这位人工智能代理那里获得答案](#ask_code) <br> <br>你可以点击[设置](#settings)来配置 DevChat",
12+
"devchat.setkey": "你的环境或设置中缺少 DevChat 访问密钥。请输入你的 DevChat 访问密钥,这样我就可以开始正常工作了。<br> <br> <button value=\"get_devchat_key\">注册获取 DevChat 访问密钥</button> <button value=\"setting_devchat_key\">设置 DevChat 访问密钥</button>",
1413
"Is DevChat Access Key ready?": "DevChat 访问密钥是否已经设置好?",
1514
"Ask questions about the current project's codebase, which requires proactive acquisition of additional context information to answer.": "询问关于当前项目代码库的问题,我将主动获取相关的上下文信息来回答。",
1615
"Generate code with a general template embedded into the prompt.": "使用隐式嵌入到提示词中的通用模板生成代码。",
1716
"Generate code with a Python-specific template embedded into the prompt.": "使用隐式嵌入到提示词中的 Python 特定模板生成代码。",
1817
"commit changes with commit message in english.": "选择要提交的代码变更,总结英文提交消息,并提交到代码库。",
1918
"Generate a commit message for the given git diff.": "为给定的 git diff 生成提交消息。",
20-
"Generate a release note for the given commit log.": "为给定的提交日志生成发布说明。"
19+
"Generate a release note for the given commit log.": "为给定的提交日志生成发布说明。",
20+
"Explain /ask-code": "解释 /ask-code",
21+
"ask-code-explain": "向我们的 AI 代理提出有关您代码库的任何问题,并获得答案。<br> <br>DevChat 利用 GPT-4 智能地导航您的代码库。它会自动选择和分析最多十个与您的问题最相关的源文件来提供答案。敬请期待 — 我们即将整合更高效的 LLama 2 - 70B 模型。<br> <br> 示例问题:<br> -为什么更改的引导时间有时会显示为 null?<br> -store.findAllAccounts 是如何实现的?<br> -当前的递归检索器会丢弃所有 TextNodes,只查询 IndexNodes。这是一个 bug。我们该如何修复它?",
22+
"Explain /release_note": "解释 /release_note",
23+
"note-explain": "使用这个工作流程,您可以生成专业的、格式化的发布说明(markdown格式)。我只需要关于本次发布的提交的一些基本信息。通过点击“+”按钮并选择 git_log_releasenote 将这些信息添加到上下文中。如果提交的范围与默认命令不同,您还可以选择 <custom command> 并输入如 git log 579398b^..HEAD --pretty=format:\"%h - %B\" 的命令行来包含从提交 579398b(包括此提交)到最新提交的所有变更。",
24+
"Explain /code": "解释 /code",
25+
"code-explain": "使用 DevChat 工作流程来请求编写代码。请输入您的具体需求,并提供适当的实施上下文。您可以选择相关的代码或文件,然后右键点击“添加到 DevChat”。如果您发现上下文仍然不足以解释清楚,您可以通过提供所选代码的类/函数定义来增强我对您代码的理解。要做到这一点,请点击所选代码旁边的“+”按钮,然后选择“符号定义”。请注意,这些信息显示在 DevChat 中可能需要几秒钟时间。"
2126
}

src/views/pages/ChatPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const chatPanel = observer(() => {
122122
messageUtil.registerHandler(
123123
"getSetting",
124124
(message: { value: string; key2: string }) => {
125+
console.log("message: ", message);
125126
if (message.key2 === "defaultModel") {
126127
chat.changeChatModel(message.value);
127128
}

0 commit comments

Comments
 (0)