refactor(ui): 优化 AI聊天功能

- 在打开聊天时增加对空消息的检查,避免发送无效请求
- 在发送消息时添加来源标识,以便服务端区分消息来源
- 在任务视图中增加对空日志的检查,避免触发空指针异常
pull/409/head
xiaojunnuo 2025-05-14 15:46:41 +08:00
parent 61a19d694b
commit b8edd14f39
2 changed files with 13 additions and 2 deletions

View File

@ -123,6 +123,9 @@ onMounted(() => {
});
async function openChat(req: { q: string }) {
if (!req.q) {
return;
}
chatVisible.value = true;
const iframeId = "maxkb-chat";
@ -132,7 +135,13 @@ async function openChat(req: { q: string }) {
throw new Error("iframe not found");
return;
}
iframe.contentWindow?.postMessage(req, "*");
iframe.contentWindow?.postMessage(
{
...req,
from: "certd",
},
"*"
);
}
defineExpose({

View File

@ -62,8 +62,10 @@ export default {
});
function onAiChat() {
debugger;
const logs = currentHistory.value?.logs[activeKey.value];
if (!logs || logs.length === 0) {
return;
}
let logText = "";
for (let log of logs) {
logText += log + "\n";