From a71a95f5e35060c2bade74bd1f05bdc086ad020c Mon Sep 17 00:00:00 2001 From: ShineKOT <1917095344@qq.com> Date: Fri, 7 Mar 2025 18:27:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=20=E4=BF=AE=E5=A4=8DAI=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E8=AF=9D=E9=A2=98=E6=97=B6=E6=8F=90=E9=97=AE=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=88=E7=BB=B4=E6=8A=A4=E8=AF=9D=E9=A2=98map?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/ai-chat/ai-chat.controller.ts | 3 ++ src/controller/chat/chat.controller.ts | 37 ++++++++++++++----- .../i-chat-options/i-chat-options.ts | 2 + 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/controller/ai-chat/ai-chat.controller.ts b/src/controller/ai-chat/ai-chat.controller.ts index 97e8afd..4e1ffe9 100644 --- a/src/controller/ai-chat/ai-chat.controller.ts +++ b/src/controller/ai-chat/ai-chat.controller.ts @@ -270,6 +270,7 @@ export class AiChatController { content: inputText, }); await this.opts.question( + this, this.context, this.params, { appDataEntityId: this.appDataEntityId }, @@ -330,6 +331,7 @@ export class AiChatController { this.messages.value.splice(i + 1, this.messages.value.length - i - 1); this.messages.value = [...this.messages.value]; await this.opts.question( + this, this.context, this.params, { appDataEntityId: this.appDataEntityId }, @@ -341,6 +343,7 @@ export class AiChatController { this.messages.value.pop(); this.messages.value = [...this.messages.value]; await this.opts.question( + this, this.context, this.params, { appDataEntityId: this.appDataEntityId }, diff --git a/src/controller/chat/chat.controller.ts b/src/controller/chat/chat.controller.ts index d064cfe..26a2377 100644 --- a/src/controller/chat/chat.controller.ts +++ b/src/controller/chat/chat.controller.ts @@ -69,12 +69,22 @@ export class ChatController { /** * 聊天控制器 * - * @author tony001 - * @date 2025-02-23 16:02:09 - * @public + * @readonly * @type {(AiChatController | undefined)} + * @memberof ChatController + */ + public get aiChat(): AiChatController | undefined { + return this.aiTopicMap.get(`${this.aiTopic.activedTopic.value?.id}`); + } + + /** + * 话题map + * + * @private + * @type {Map} + * @memberof ChatController */ - public aiChat: AiChatController | undefined = undefined; + private aiTopicMap: Map = new Map(); /** * Creates an instance of ChatController. @@ -149,12 +159,15 @@ export class ChatController { } Object.assign(chatOptions, { topicId: topicOptions?.id }); - this.aiChat = new AiChatController(chatOptions); + + const aiChat = new AiChatController(chatOptions); + + this.aiTopicMap.set(`${topicOptions?.id}`, aiChat); render( h(ChatContainer, { + aiChat, aiTopic: this.aiTopic, - aiChat: this.aiChat, mode: opts.mode ? opts.mode : 'DEFAULT', containerOptions: opts.containerOptions, caption: @@ -189,7 +202,7 @@ export class ChatController { }), this.container, ); - return this.aiChat; + return aiChat; } /** @@ -215,13 +228,19 @@ export class ChatController { topicId: topic.id, }); } - this.aiChat = new AiChatController(opts); + let aiChat: AiChatController; + if (this.aiTopicMap.has(`${topic.id}`)) { + aiChat = this.aiTopicMap.get(`${topic.id}`)!; + } else { + aiChat = new AiChatController(opts); + this.aiTopicMap.set(`${topic.id}`, aiChat); + } if (this.container) { render(null, this.container); render( h(ChatContainer, { + aiChat, aiTopic: this.aiTopic, - aiChat: this.aiChat, mode: this.backupChatOptions?.mode ? this.backupChatOptions.mode : 'DEFAULT', diff --git a/src/interface/i-chat-options/i-chat-options.ts b/src/interface/i-chat-options/i-chat-options.ts index b6d5d09..b5a8f09 100644 --- a/src/interface/i-chat-options/i-chat-options.ts +++ b/src/interface/i-chat-options/i-chat-options.ts @@ -1,3 +1,4 @@ +import { AiChatController } from '../../controller'; import { IChatMessage } from '../i-chat-message/i-chat-message'; import { IChatToolbarItem } from '../i-chat-toolbar-item/i-chat-toolbar-item'; import { FileUploaderOptions } from '../i-file-uploader-options/i-file-uploader-options'; @@ -111,6 +112,7 @@ export interface IChatOptions extends IChat { * @return {*} {Promise} 等待回答,用于显示 loading 并获取最终成功与否 */ question( + aiChat: AiChatController, context: object, params: object, otherParams: object, -- Gitee