From 6bcc7b6c49eb2918cb5699f2e3383964cbb1e29d Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 7 Feb 2025 16:42:42 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20AI=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/UserBot.php | 16 +++- app/Models/WebSocketDialogMsg.php | 2 + app/Models/WebSocketDialogSession.php | 61 +++++++++++++ ...329_web_socket_dialog_msgs_add_session.php | 34 +++++++ ...reate_web_socket_dialog_sessions_table.php | 36 ++++++++ .../pages/manage/components/DialogWrapper.vue | 28 +++++- .../manage/setting/components/SystemAibot.vue | 78 ++++------------ resources/assets/js/store/utils.js | 88 +++++++++++++++++++ 8 files changed, 276 insertions(+), 67 deletions(-) create mode 100644 app/Models/WebSocketDialogSession.php create mode 100644 database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session.php create mode 100644 database/migrations/2025_02_07_163701_create_web_socket_dialog_sessions_table.php diff --git a/app/Models/UserBot.php b/app/Models/UserBot.php index 86570078a..a16d3e653 100644 --- a/app/Models/UserBot.php +++ b/app/Models/UserBot.php @@ -189,10 +189,22 @@ class UserBot extends AbstractModel default: if (preg_match('/^ai-(.*?)@bot\.system$/', $email)) { - return [ - [ + if (!Base::judgeClientVersion('0.42.62')) { + return [ 'key' => '%3A.clear', 'label' => Doo::translate('清空上下文') + ]; + } + return [ + [ + 'key' => 'ai-newchat', + 'label' => Doo::translate('开启新对话'), + 'config' => [] + ], + [ + 'key' => 'ai-historychat', + 'label' => Doo::translate('历史对话'), + 'config' => [] ] ]; } diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 06181e775..c95f215ca 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -27,6 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property int|null $read 已阅数量 * @property int|null $send 发送数量 * @property int|null $tag 标注会员ID + * @property string|null $session 会话标识符 * @property int|null $todo 设为待办会员ID * @property int|null $link 是否存在链接 * @property int|null $modify 是否编辑 @@ -69,6 +70,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereReplyId($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereReplyNum($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereSend($value) + * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereSession($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereTag($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereTodo($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereType($value) diff --git a/app/Models/WebSocketDialogSession.php b/app/Models/WebSocketDialogSession.php new file mode 100644 index 000000000..f94a13612 --- /dev/null +++ b/app/Models/WebSocketDialogSession.php @@ -0,0 +1,61 @@ +belongsTo(WebSocketDialog::class, 'dialog_id'); + } + + /** + * 获取关联的用户 + */ + public function user() + { + return $this->belongsTo(User::class, 'userid'); + } +} diff --git a/database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session.php b/database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session.php new file mode 100644 index 000000000..9ed726398 --- /dev/null +++ b/database/migrations/2025_02_07_163329_web_socket_dialog_msgs_add_session.php @@ -0,0 +1,34 @@ +string('session', 36)->nullable()->default('')->after('tag')->comment('会话标识符'); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('web_socket_dialog_msgs', function (Blueprint $table) { + $table->dropColumn('session'); + }); + } +} diff --git a/database/migrations/2025_02_07_163701_create_web_socket_dialog_sessions_table.php b/database/migrations/2025_02_07_163701_create_web_socket_dialog_sessions_table.php new file mode 100644 index 000000000..39c7845f8 --- /dev/null +++ b/database/migrations/2025_02_07_163701_create_web_socket_dialog_sessions_table.php @@ -0,0 +1,36 @@ +id(); + $table->bigInteger('dialog_id')->unsigned()->index()->comment('对话ID'); + $table->bigInteger('userid')->unsigned()->index()->comment('用户ID'); + $table->string('title', 255)->default('')->comment('会话标题'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('web_socket_dialog_sessions'); + } +} diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 34755b204..cbd013a0e 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -255,7 +255,7 @@
@@ -707,6 +707,7 @@ import touchclick from "../../../directives/touchclick"; import {languageList} from "../../../language"; import {isLocalResourcePath} from "../../../components/Replace/utils"; import emitter from "../../../store/events"; +import {AIModelList} from "../../../store/utils"; export default { name: "DialogWrapper", @@ -1801,8 +1802,9 @@ export default { /** * 发送快捷消息 * @param item + * @param event */ - sendQuick(item) { + sendQuick(item, event = undefined) { switch (item.key) { // 位置签到 case "locat-checkin": @@ -1854,6 +1856,28 @@ export default { }); break; + // 开启新对话 + case "ai-newchat": + if (!this.isAiBot) { + return + } + this.$store.state.menuOperation = { + event, + list: AIModelList(this.dialogData.email).map(value => ({label: value, value: value})), + scrollHide: true, + onUpdate: async (model) => { + + } + } + break; + + // 历史对话 + case "ai-historychat": + if (!this.isAiBot) { + return + } + break; + // 发送快捷指令 default: this.sendMsg(`

${item.label}

`) diff --git a/resources/assets/js/pages/manage/setting/components/SystemAibot.vue b/resources/assets/js/pages/manage/setting/components/SystemAibot.vue index 489d0fc38..3d1f9604c 100644 --- a/resources/assets/js/pages/manage/setting/components/SystemAibot.vue +++ b/resources/assets/js/pages/manage/setting/components/SystemAibot.vue @@ -65,6 +65,7 @@