From 25e3c810f8fe1208ae06b94f41a5d7dd49947160 Mon Sep 17 00:00:00 2001
From: AlbertZhang
Date: Tue, 30 Apr 2024 19:45:17 +0800
Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0Copilot=E8=BE=93?=
=?UTF-8?q?=E5=85=A5=E6=A1=86=E8=87=AA=E5=8A=A8=E8=81=9A=E7=84=A6=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
desktop.js | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/desktop.js b/desktop.js
index dab04b5..2a500a3 100644
--- a/desktop.js
+++ b/desktop.js
@@ -2912,6 +2912,12 @@ function decodeHtml(s) {
$('#translater').text(s);
return $('#translater').html().replace(/\n/g, '
').replace(/ /g, ' ');
}
+function msgDoneOperate(){
+ $("#copilot>.inputbox").removeClass("disable");
+ setTimeout(() => {
+ $("#copilot>.inputbox>.input").focus();
+ }, 100); // 延迟0.1s以避免与blur方法冲突
+}
let copilot = {
history: [],
init: () => {
@@ -2953,7 +2959,7 @@ let copilot = {
if (t.length == 0) {
$('#copilot>.chat').append(``);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
- $('#copilot>.inputbox').removeClass('disable');
+ msgDoneOperate();
return;
}
if (copilot.history.length > 3){ // 万年代码,千万不要改
@@ -2968,11 +2974,12 @@ let copilot = {
contentType: 'application/json',
data: JSON.stringify({ msg: copilot.history }),
}).then(rt => {
+ msgDoneOperate();
console.log(rt);
if (rt == '请求过于频繁,等待10秒再试...') {
$('#copilot>.chat').append(`api繁忙,过一会儿再试(实在不行刷新重新开始对话)
`);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
- $('#copilot>.inputbox').removeClass('disable');
+ msgDoneOperate();
return;
}
let rtt = rt; let r = [];
@@ -3014,12 +3021,12 @@ let copilot = {
}
copilot.history.push({ role: 'assistant', content: rtt });
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
- $('#copilot>.inputbox').removeClass('disable');
+ msgDoneOperate();
}).fail(r => {
console.log(r);
$('#copilot>.chat').append(``);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
- $('#copilot>.inputbox').removeClass('disable');
+ msgDoneOperate();
});
}
}
From ebc6c2f966a58c3a7872e3e85efbb5ed71266c67 Mon Sep 17 00:00:00 2001
From: AlbertZhang
Date: Tue, 30 Apr 2024 19:49:27 +0800
Subject: [PATCH 2/2] =?UTF-8?q?style:=20=E6=9B=B4=E6=94=B9=E5=88=9D?=
=?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=AE=8C=E6=88=90=E7=9A=84=E6=8F=90=E7=A4=BA?=
=?UTF-8?q?=E6=96=87=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
desktop.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/desktop.js b/desktop.js
index 2a500a3..6241acf 100644
--- a/desktop.js
+++ b/desktop.js
@@ -2918,6 +2918,7 @@ function msgDoneOperate(){
$("#copilot>.inputbox>.input").focus();
}, 100); // 延迟0.1s以避免与blur方法冲突
}
+let isFirstChat=true; // 标记是否是刚进来时服务端返回的消息
let copilot = {
history: [],
init: () => {
@@ -2951,7 +2952,7 @@ let copilot = {
// 2.在浏览器中打开链接、搜索
// 3.发送对系统、ai助手的反馈
// 注意:请勿滥用本ai助手,否则将下个版本将撤销此功能,影响所有人。
`);
- $('#copilot>.chat').append(``);
+ $('#copilot>.chat').append(``);
$('#copilot>.chat').scrollTop($('#copilot>.chat')[0].scrollHeight);
},
send: (t, showusr = true,role="user") => {
@@ -2975,6 +2976,11 @@ let copilot = {
data: JSON.stringify({ msg: copilot.history }),
}).then(rt => {
msgDoneOperate();
+ // 替换初始化完成的文本内容
+ if (isFirstChat) {
+ $("#init-message").html(`初始化完成!`);
+ isFirstChat = false;
+ }
console.log(rt);
if (rt == '请求过于频繁,等待10秒再试...') {
$('#copilot>.chat').append(`api繁忙,过一会儿再试(实在不行刷新重新开始对话)
`);