diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index dfc303166..7001131d7 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -19,6 +19,7 @@ use App\Models\AbstractModel; use App\Models\WebSocketDialog; use App\Models\WebSocketDialogMsg; use App\Models\WebSocketDialogUser; +use App\Models\WebSocketDialogConfig; use App\Models\WebSocketDialogMsgRead; use App\Models\WebSocketDialogMsgTodo; use App\Models\WebSocketDialogMsgTranslate; @@ -2771,4 +2772,86 @@ class DialogController extends AbstractController 'list' => Extranet::sticker($key) ]); } + + /** + * @api {get} api/dialog/config 57. 获取会话配置 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName config + * + * @apiParam {Number} dialog_id 对话ID + * @apiParam {String} type 配置类型 + * + * @apiSuccess {String} value 配置值 + */ + public function config() + { + $user = User::auth(); + + $dialog_id = intval(Request::input('dialog_id')); + $type = Request::input('type'); + + if (!$dialog_id || !$type) { + return Base::retError('参数错误'); + } + + WebSocketDialog::checkDialog($dialog_id); + + $config = WebSocketDialogConfig::where('dialog_id', $dialog_id) + ->where('userid', $user->userid) + ->where('type', $type) + ->first(); + + return Base::retSuccess('success', [ + 'value' => $config?->value + ]); + } + + /** + * @api {post} api/dialog/config/save 58. 保存会话配置 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName config__save + * + * @apiParam {Number} dialog_id 对话ID + * @apiParam {String} type 配置类型 + * @apiParam {String} value 配置值 + * + * @apiSuccess {String} msg 成功提示 + */ + public function config__save() + { + $user = User::auth(); + + $dialog_id = intval(Request::input('dialog_id')); + $type = Request::input('type'); + $value = Request::input('value'); + + if (!$dialog_id || !$type) { + return Base::retError('参数错误'); + } + + WebSocketDialog::checkDialog($dialog_id); + + if (WebSocketDialogConfig::updateOrCreate( + [ + 'dialog_id' => $dialog_id, + 'userid' => $user->userid, + 'type' => $type, + ], + [ + 'value' => $value, + ] + )) { + WebSocketDialogMsg::sendMsg(null, $dialog_id, 'notice', [ + 'notice' => $value ? ("修改提示词:" . $value) : "取消提示词", + ], User::userid(), true, true); + } + + return Base::retSuccess('保存成功'); + } } diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 5bd0d631d..e48815d05 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -54,6 +54,7 @@ class SystemController extends AbstractController if (env("SYSTEM_SETTING") == 'disabled') { return Base::retError('当前环境禁止修改'); } + Base::checkClientVersion('0.41.11'); User::auth('admin'); $all = Request::input(); foreach ($all AS $key => $value) { @@ -296,7 +297,7 @@ class SystemController extends AbstractController if (env("SYSTEM_SETTING") == 'disabled') { return Base::retError('当前环境禁止修改'); } - Base::checkClientVersion('0.40.79'); + Base::checkClientVersion('0.41.11'); $backup = $setting; $all = Request::input(); foreach ($all as $key => $value) { diff --git a/app/Models/WebSocketDialogConfig.php b/app/Models/WebSocketDialogConfig.php new file mode 100644 index 000000000..61ce0a434 --- /dev/null +++ b/app/Models/WebSocketDialogConfig.php @@ -0,0 +1,64 @@ +belongsTo(WebSocketDialog::class, 'dialog_id'); + } + + /** + * 获取关联的用户 + */ + public function user() + { + return $this->belongsTo(User::class, 'userid'); + } +} diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php index 9c2b596ad..250a93024 100644 --- a/app/Tasks/BotReceiveMsgTask.php +++ b/app/Tasks/BotReceiveMsgTask.php @@ -5,6 +5,7 @@ namespace App\Tasks; use App\Models\User; use App\Models\UserBot; use App\Models\WebSocketDialog; +use App\Models\WebSocketDialogConfig; use App\Models\WebSocketDialogMsg; use App\Module\Base; use App\Module\Doo; @@ -429,8 +430,16 @@ class BotReceiveMsgTask extends AbstractTask if (empty($extras['api_key'])) { $errorContent = '机器人未启用。'; } - if (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.29.11", $this->client['version'])) { - $errorContent = '当前客户端版本低(所需版本≥v0.29.11)。'; + if (in_array($this->client['platform'], ['win', 'mac', 'web']) && !Base::judgeClientVersion("0.41.11", $this->client['version'])) { + $errorContent = '当前客户端版本低(所需版本≥v0.41.11)。'; + } + $aiPrompt = WebSocketDialogConfig::where([ + 'dialog_id' => $dialog->id, + 'userid' => $msg->userid, + 'type' => 'ai_prompt', + ])->value('value'); + if ($aiPrompt) { + $extras['system_message'] = $aiPrompt; } $webhookUrl = "{$serverUrl}/ai/chat"; } else { diff --git a/database/migrations/2024_12_03_021701_create_web_socket_dialog_configs_table.php b/database/migrations/2024_12_03_021701_create_web_socket_dialog_configs_table.php new file mode 100644 index 000000000..5a9a4e634 --- /dev/null +++ b/database/migrations/2024_12_03_021701_create_web_socket_dialog_configs_table.php @@ -0,0 +1,37 @@ +id(); + $table->bigInteger('dialog_id')->unsigned()->index()->comment('对话ID'); + $table->bigInteger('userid')->unsigned()->index()->comment('用户ID'); + $table->string('type', 50)->default('')->comment('配置类型'); + $table->text('value')->nullable()->comment('配置值'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('web_socket_dialog_configs'); + } +} diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 435347aae..fb9716948 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -86,6 +86,9 @@
{{$L('修改资料')}}
+ +
{{$L('修改提示词')}}
+
{{$L('创建群组')}}
@@ -438,6 +441,27 @@ + + +
+ + + +
+
+ + +
+
+ { + this.modifyData.value = data.value + }).finally(() => { + this.modifyLoad--; + }) + this.modifyAiShow = true + break; + case "modifyAdmin": this.modifyData = { dialog_id: this.dialogData.id, @@ -2712,6 +2762,23 @@ export default { } }, + onAiModify() { + this.modifyLoad++; + this.$store.dispatch("call", { + url: 'dialog/config/save', + data: this.modifyData + }).then(({data, msg}) => { + $A.messageSuccess(msg); + this.$store.dispatch("saveDialog", data); + this.modifyAiShow = false; + this.modifyData = {}; + }).catch(({msg}) => { + $A.modalError(msg); + }).finally(_ => { + this.modifyLoad--; + }); + }, + onForwardBefore() { return new Promise((resolve, reject) => { this.forwardData = this.$refs.forwardSelect.formatSelect(this.$refs.forwardSelect.selects);