From 34a60014551b9aac8ac4f1806c2560c15f039069 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Mon, 30 Jun 2025 20:25:16 +0800 Subject: [PATCH] support ai-mook --- .../main-panel/chat/chat-box/chat.ts | 2 +- .../chat/chat-box/options/setting.vue | 7 +- .../main-panel/chat/core/task-loop.ts | 25 ++++ .../main-panel/tool/tool-executor.vue | 141 +++++++++++++++--- .../main-panel/tool/tool-logger.vue | 27 +++- renderer/src/i18n/ar.json | 3 +- renderer/src/i18n/de.json | 3 +- renderer/src/i18n/en.json | 3 +- renderer/src/i18n/fr.json | 3 +- renderer/src/i18n/ja.json | 3 +- renderer/src/i18n/ko.json | 3 +- renderer/src/i18n/ru.json | 3 +- renderer/src/i18n/zh-cn.json | 3 +- renderer/src/i18n/zh-tw.json | 3 +- 14 files changed, 192 insertions(+), 37 deletions(-) diff --git a/renderer/src/components/main-panel/chat/chat-box/chat.ts b/renderer/src/components/main-panel/chat/chat-box/chat.ts index d407ba0..3b66e8d 100644 --- a/renderer/src/components/main-panel/chat/chat-box/chat.ts +++ b/renderer/src/components/main-panel/chat/chat-box/chat.ts @@ -58,7 +58,7 @@ export interface EnableToolItem { } export interface ChatSetting { - modelIndex: number + modelIndex?: number systemPrompt: string enableTools: EnableToolItem[] temperature: number diff --git a/renderer/src/components/main-panel/chat/chat-box/options/setting.vue b/renderer/src/components/main-panel/chat/chat-box/options/setting.vue index f7d03d6..71a5fbd 100644 --- a/renderer/src/components/main-panel/chat/chat-box/options/setting.vue +++ b/renderer/src/components/main-panel/chat/chat-box/options/setting.vue @@ -162,16 +162,15 @@ provide('tabStorage', tabStorage); color: var(--el-text-color-secondary); } -.tools-dialog-container .el-switch__core { +.el-switch__core { border: 1px solid var(--main-color) !important; } - -.tools-dialog-container .el-switch .el-switch__action { +.el-switch .el-switch__action { background-color: var(--main-color); } -.tools-dialog-container .el-switch.is-checked .el-switch__action { +.el-switch.is-checked .el-switch__action { background-color: var(--sidebar); } diff --git a/renderer/src/components/main-panel/chat/core/task-loop.ts b/renderer/src/components/main-panel/chat/core/task-loop.ts index fe1627c..00f58da 100644 --- a/renderer/src/components/main-panel/chat/core/task-loop.ts +++ b/renderer/src/components/main-panel/chat/core/task-loop.ts @@ -48,6 +48,7 @@ export class TaskLoop { private bridge: MessageBridge; private streamingContent: Ref; private streamingToolCalls: Ref; + private aborted = false; private currentChatId = ''; private onError: (error: IErrorMssage) => void = (msg) => { }; @@ -318,6 +319,7 @@ export class TaskLoop { }); this.streamingContent.value = ''; this.streamingToolCalls.value = []; + this.aborted = true; } /** @@ -545,6 +547,7 @@ export class TaskLoop { maxEpochs = 50, verbose = 0 } = this.taskOptions || {}; + this.aborted = false; for (let i = 0; i < maxEpochs; ++i) { @@ -570,6 +573,12 @@ export class TaskLoop { // 发送请求 const doConverationResult = await this.doConversation(chatData, toolcallIndexAdapter); + // 如果在调用过程中出发了 abort,则直接中断 + if (this.aborted) { + this.aborted = false; + break; + } + // 如果存在需要调度的工具 if (this.streamingToolCalls.value.length > 0) { @@ -597,8 +606,19 @@ export class TaskLoop { // ready to call tools toolCall = this.consumeToolCalls(toolCall); + + if (this.aborted) { + this.aborted = false; + break; + } + let toolCallResult = await handleToolCalls(toolCall); + if (this.aborted) { + this.aborted = false; + break; + } + // hook : finish call tools toolCallResult = this.consumeToolCalleds(toolCallResult); @@ -656,6 +676,11 @@ export class TaskLoop { } } + if (this.aborted) { + this.aborted = false; + break; + } + } else if (this.streamingContent.value) { tabStorage.messages.push({ role: 'assistant', diff --git a/renderer/src/components/main-panel/tool/tool-executor.vue b/renderer/src/components/main-panel/tool/tool-executor.vue index 082c814..624eb46 100644 --- a/renderer/src/components/main-panel/tool/tool-executor.vue +++ b/renderer/src/components/main-panel/tool/tool-executor.vue @@ -33,9 +33,36 @@ {{ t('reset') }} - + {{ 'mook' }} + + + + +
+ {{ t('edit-ai-mook-prompt') }} +
+ +
+ + XML +
+
+ {{ t('cancel') }} + + {{ t('confirm') }} + +
+
@@ -44,7 +71,7 @@ \ No newline at end of file diff --git a/renderer/src/i18n/ar.json b/renderer/src/i18n/ar.json index bac8a4f..99412c3 100644 --- a/renderer/src/i18n/ar.json +++ b/renderer/src/i18n/ar.json @@ -183,5 +183,6 @@ "export": "تصدير", "export-filename": "اسم ملف التصدير", "how-to-use": "كيفية الاستخدام؟", - "is-required": "هو حقل مطلوب" + "is-required": "هو حقل مطلوب", + "edit-ai-mook-prompt": "تحرير إشارات AI Mook" } \ No newline at end of file diff --git a/renderer/src/i18n/de.json b/renderer/src/i18n/de.json index 8f07aec..5ebcdaa 100644 --- a/renderer/src/i18n/de.json +++ b/renderer/src/i18n/de.json @@ -183,5 +183,6 @@ "export": "Exportieren", "export-filename": "Exportdateiname", "how-to-use": "Wie benutzt man?", - "is-required": "ist ein Pflichtfeld" + "is-required": "ist ein Pflichtfeld", + "edit-ai-mook-prompt": "AI Mook-Prompts bearbeiten" } \ No newline at end of file diff --git a/renderer/src/i18n/en.json b/renderer/src/i18n/en.json index 1f4137b..9decfc6 100644 --- a/renderer/src/i18n/en.json +++ b/renderer/src/i18n/en.json @@ -183,5 +183,6 @@ "export": "Export", "export-filename": "Export filename", "how-to-use": "How to use?", - "is-required": "is a required field" + "is-required": "is a required field", + "edit-ai-mook-prompt": "Edit AI Mook prompts" } \ No newline at end of file diff --git a/renderer/src/i18n/fr.json b/renderer/src/i18n/fr.json index 6354408..bad801d 100644 --- a/renderer/src/i18n/fr.json +++ b/renderer/src/i18n/fr.json @@ -183,5 +183,6 @@ "export": "Exporter", "export-filename": "Nom du fichier d'exportation", "how-to-use": "Comment utiliser ?", - "is-required": "est un champ obligatoire" + "is-required": "est un champ obligatoire", + "edit-ai-mook-prompt": "Modifier les invites AI Mook" } \ No newline at end of file diff --git a/renderer/src/i18n/ja.json b/renderer/src/i18n/ja.json index 2410143..9ffeafa 100644 --- a/renderer/src/i18n/ja.json +++ b/renderer/src/i18n/ja.json @@ -183,5 +183,6 @@ "export": "エクスポート", "export-filename": "エクスポートファイル名", "how-to-use": "使用方法", - "is-required": "は必須フィールドです" + "is-required": "は必須フィールドです", + "edit-ai-mook-prompt": "AI Mookプロンプトを編集" } \ No newline at end of file diff --git a/renderer/src/i18n/ko.json b/renderer/src/i18n/ko.json index 90e49fc..348c653 100644 --- a/renderer/src/i18n/ko.json +++ b/renderer/src/i18n/ko.json @@ -183,5 +183,6 @@ "export": "내보내기", "export-filename": "내보내기 파일 이름", "how-to-use": "사용 방법?", - "is-required": "는 필수 필드입니다" + "is-required": "는 필수 필드입니다", + "edit-ai-mook-prompt": "AI Mook 프롬프트 편집" } \ No newline at end of file diff --git a/renderer/src/i18n/ru.json b/renderer/src/i18n/ru.json index 88298dd..3016027 100644 --- a/renderer/src/i18n/ru.json +++ b/renderer/src/i18n/ru.json @@ -183,5 +183,6 @@ "export": "Экспорт", "export-filename": "Имя файла экспорта", "how-to-use": "Как использовать?", - "is-required": "является обязательным полем" + "is-required": "является обязательным полем", + "edit-ai-mook-prompt": "Редактировать подсказки AI Mook" } \ No newline at end of file diff --git a/renderer/src/i18n/zh-cn.json b/renderer/src/i18n/zh-cn.json index d3f7d2d..10ea2be 100644 --- a/renderer/src/i18n/zh-cn.json +++ b/renderer/src/i18n/zh-cn.json @@ -183,5 +183,6 @@ "export": "导出", "export-filename": "导出文件名", "how-to-use": "如何使用?", - "is-required": "是必填字段" + "is-required": "是必填字段", + "edit-ai-mook-prompt": "编辑 AI Mook 提示词" } \ No newline at end of file diff --git a/renderer/src/i18n/zh-tw.json b/renderer/src/i18n/zh-tw.json index df5dbfd..c5f4abd 100644 --- a/renderer/src/i18n/zh-tw.json +++ b/renderer/src/i18n/zh-tw.json @@ -183,5 +183,6 @@ "export": "導出", "export-filename": "導出文件名", "how-to-use": "如何使用?", - "is-required": "是必填欄位" + "is-required": "是必填欄位", + "edit-ai-mook-prompt": "編輯AI Mook提示詞" } \ No newline at end of file