M7-07 P0 | listSessions 支持 scopeType + scopeId 过滤 #75

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

目标

GET /rag-chat/sessions 新增 scopeType + scopeId 查询参数,按学习对象精确过滤。

接口变更

GET /rag-chat/sessions?scopeType=knowledge_item&scopeId=ki_123

行为

  • 不传 scopeType/scopeId → 返回用户所有会话(兼容旧行为)
  • 传 scopeType + scopeId → 只返回该 scope 的会话
  • 传 parentKnowledgeBaseId → 返回该 KB 下所有 scope 的会话
  • 排序:isPinned DESC, lastMessageAt DESC
  • 默认过滤 isDeleted + isArchived
## 目标 GET /rag-chat/sessions 新增 scopeType + scopeId 查询参数,按学习对象精确过滤。 ## 接口变更 ``` GET /rag-chat/sessions?scopeType=knowledge_item&scopeId=ki_123 ``` ## 行为 - 不传 scopeType/scopeId → 返回用户所有会话(兼容旧行为) - 传 scopeType + scopeId → 只返回该 scope 的会话 - 传 parentKnowledgeBaseId → 返回该 KB 下所有 scope 的会话 - 排序:isPinned DESC, lastMessageAt DESC - 默认过滤 isDeleted + isArchived
wangdl added this to the M7:ChatScope 会话系统 — 学习对象绑定的上下文会话 milestone 2026-06-06 16:21:27 +08:00
Author
Owner

完成情况

交付物

Service 层listSessions 重构:

async listSessions(userId: string, opts?: {
  scopeType?: string;
  scopeId?: string;
  parentKnowledgeBaseId?: string;
  kbId?: string;
  isArchived?: boolean;
  page?: number;
  limit?: number;
}): Promise<ChatSession[]>

过滤逻辑:

  1. scopeType + scopeId 精确 → 同一 scope 的历史
  2. parentKnowledgeBaseId → 该 KB 下所有会话
  3. kbId → 向后兼容旧 API
  4. 无过滤 → 全局列表

Controller 层:

GET /rag-chat/sessions?scopeType=material&scopeId=xxx&parentKnowledgeBaseId=xxx&page=1&limit=20

涉及文件

文件 变更
src/modules/rag-chat/rag-chat.service.ts listSessions 支持 scope 过滤 + 分页
src/modules/rag-chat/rag-chat.controller.ts GET /sessions query params 更新
## 完成情况 ### 交付物 **Service 层** — `listSessions` 重构: ```typescript async listSessions(userId: string, opts?: { scopeType?: string; scopeId?: string; parentKnowledgeBaseId?: string; kbId?: string; isArchived?: boolean; page?: number; limit?: number; }): Promise<ChatSession[]> ``` **过滤逻辑**: 1. `scopeType + scopeId` 精确 → 同一 scope 的历史 2. `parentKnowledgeBaseId` → 该 KB 下所有会话 3. `kbId` → 向后兼容旧 API 4. 无过滤 → 全局列表 **Controller 层**: ``` GET /rag-chat/sessions?scopeType=material&scopeId=xxx&parentKnowledgeBaseId=xxx&page=1&limit=20 ``` ### 涉及文件 | 文件 | 变更 | |------|------| | src/modules/rag-chat/rag-chat.service.ts | listSessions 支持 scope 过滤 + 分页 | | src/modules/rag-chat/rag-chat.controller.ts | GET /sessions query params 更新 |
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

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