From 55e25f347e1e21606e65fbb6220b43b4c96ec223 Mon Sep 17 00:00:00 2001 From: wangdl Date: Sat, 6 Jun 2026 17:58:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20M-CHAT-A3=20createSession=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20forceCreate=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit forceCreate=true 时跳过 open-or-create 查找,强制创建新会话。 Co-Authored-By: Claude Opus 4.7 --- src/modules/rag-chat/rag-chat.service.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/rag-chat/rag-chat.service.ts b/src/modules/rag-chat/rag-chat.service.ts index c2d3f9a..b740f94 100644 --- a/src/modules/rag-chat/rag-chat.service.ts +++ b/src/modules/rag-chat/rag-chat.service.ts @@ -15,6 +15,7 @@ export interface CreateSessionParams { parentKnowledgeBaseId?: string | null; createdFrom?: string; title?: string; + forceCreate?: boolean; } export interface CreateSessionResult { @@ -33,7 +34,7 @@ export class RagChatService { ) {} async createSession(userId: string, params: CreateSessionParams): Promise { - const { scopeType, scopeId, parentKnowledgeBaseId, createdFrom, title } = params; + const { scopeType, scopeId, parentKnowledgeBaseId, createdFrom, title, forceCreate } = params; if (!VALID_SCOPE_TYPES.includes(scopeType)) { throw new BadRequestException(`scopeType must be one of: ${VALID_SCOPE_TYPES.join(', ')}`); @@ -44,8 +45,8 @@ export class RagChatService { const derivedKbId = this.deriveParentKbId(scopeType, scopeId, parentKnowledgeBaseId); - // open-or-create: for non-global scopes, try to find an existing active session - if (scopeType !== 'global' && scopeId) { + // open-or-create: for non-global scopes, skip lookup when forceCreate + if (!forceCreate && scopeType !== 'global' && scopeId) { const existing = await this.prisma.chatSession.findFirst({ where: { userId,