CHAT-204 P0 | ChatSession scope 字段创建后不可修改 #85

Closed
opened 2026-06-06 16:23:22 +08:00 by wangdl · 1 comment
Owner

目标

PATCH /chat/sessions/:id 不允许修改 scopeType/scopeId/parentKnowledgeBaseId 等 scope 字段。

禁止修改的字段

  • scopeType
  • scopeId
  • parentKnowledgeBaseId
  • parentMaterialId
  • parentFolderId

允许修改的字段

  • title
  • isPinned
  • isArchived

原因

切换知识库/资料/知识点必须通过 open-or-create 打开新会话,不能修改旧会话 scope。

## 目标 PATCH /chat/sessions/:id 不允许修改 scopeType/scopeId/parentKnowledgeBaseId 等 scope 字段。 ## 禁止修改的字段 - scopeType - scopeId - parentKnowledgeBaseId - parentMaterialId - parentFolderId ## 允许修改的字段 - title - isPinned - isArchived ## 原因 切换知识库/资料/知识点必须通过 open-or-create 打开新会话,不能修改旧会话 scope。
wangdl added this to the M7:ChatScope 会话系统 — 学习对象绑定的上下文会话 milestone 2026-06-06 16:23:22 +08:00
Author
Owner

完成情况

交付物

Service 层updateSession 方法:

async updateSession(sessionId: string, dto: {
  title?: string;
  isPinned?: boolean;
  isArchived?: boolean;
  modelMode?: string;
  modelId?: string | null;
}) {
  // 只允许更新 title / isPinned / isArchived / modelMode / modelId
  // scopeType / scopeId / parentKnowledgeBaseId / createdFrom 不可修改
  const data: any = {};
  if (dto.title !== undefined) data.title = dto.title;
  if (dto.isPinned !== undefined) data.isPinned = dto.isPinned;
  // ... scope 字段不在白名单中,不被写入
}

不可变字段

以下字段通过 PATCH /sessions/:id 无法修改(不在白名单中):

  • scopeType
  • scopeId
  • parentKnowledgeBaseId
  • createdFrom
  • userId
  • knowledgeBaseId(旧字段,迁移后移除)

前端若传了这些字段,会被静默忽略(不报错,不修改)。

涉及文件

文件 变更
src/modules/rag-chat/rag-chat.service.ts updateSession 白名单机制
src/modules/rag-chat/rag-chat.controller.ts PATCH /sessions/:id
## 完成情况 ### 交付物 **Service 层** — `updateSession` 方法: ```typescript async updateSession(sessionId: string, dto: { title?: string; isPinned?: boolean; isArchived?: boolean; modelMode?: string; modelId?: string | null; }) { // 只允许更新 title / isPinned / isArchived / modelMode / modelId // scopeType / scopeId / parentKnowledgeBaseId / createdFrom 不可修改 const data: any = {}; if (dto.title !== undefined) data.title = dto.title; if (dto.isPinned !== undefined) data.isPinned = dto.isPinned; // ... scope 字段不在白名单中,不被写入 } ``` ### 不可变字段 以下字段通过 `PATCH /sessions/:id` 无法修改(不在白名单中): - `scopeType` - `scopeId` - `parentKnowledgeBaseId` - `createdFrom` - `userId` - `knowledgeBaseId`(旧字段,迁移后移除) 前端若传了这些字段,会被静默忽略(不报错,不修改)。 ### 涉及文件 | 文件 | 变更 | |------|------| | src/modules/rag-chat/rag-chat.service.ts | updateSession 白名单机制 | | src/modules/rag-chat/rag-chat.controller.ts | PATCH /sessions/:id |
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#85
No description provided.