fix: M-CHAT-A3 createSession 支持 forceCreate 参数
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 42s

forceCreate=true 时跳过 open-or-create 查找,强制创建新会话。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-06 17:58:33 +08:00
parent fe44dec567
commit 55e25f347e

View File

@ -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<CreateSessionResult> {
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,