diff --git a/src/controller/ai-chat/ai-chat.controller.ts b/src/controller/ai-chat/ai-chat.controller.ts index 97e8afd568a6d001de7dd3655e814571a941c820..4e1ffe99b3f48da8a166a12806238081e648d6fe 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 d064cfe4becfd36ed0f14e8f7d9e0863b3188a49..26a237725f8c6ab6e1e0500730b99c17ef0f7dbf 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 b6d5d098dbfa9ca4c756310d198ab20c05b92e58..b5a8f09a9a17500d5484cc0c4cfd59328db19bb0 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,