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,