19 Commits

Author SHA1 Message Date
wangdl
1abc89be23 fix: add enrichWithNames to chat sessions API
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
2026-06-19 13:30:09 +08:00
wangdl
55e25f347e 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>
2026-06-06 17:58:33 +08:00
wangdl
fe44dec567 feat: M-CHAT ChatScope 会话系统完整实现
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
## 数据模型
- ChatSession +13 字段 (scopeType/scopeId/parentKnowledgeBaseId/createdFrom/isPinned/isArchived/isDeleted/modelMode/modelId/lastMessageAt)
- ChatMessage +scopeSnapshot (消息级 scope 快照)
- ChatCitation +lineStart/lineEnd +sourceId 索引
- 5 个新查询索引

## 核心能力
- open-or-create: 同 scope 继续会话 (200) / 新建 (201)
- scope 级检索: global/knowledge_base/material/knowledge_item/folder
- listSessions: scope 过滤 + isDeleted 排除 + isPinned 排序 + 分页元数据
- 自动标题: 首条消息截取 + 词边界处理
- 软删除 + 置顶/归档
- scope 字段创建后不可修改
- 全部端点 userId 鉴权

## 文档
- docs/chat-scope-design.md (设计文档 + 决策表)
- docs/chat-scope-api-contract.md (API 契约)
- docs/chat-scope-test-plan.md (33 条测试用例)
- prisma/migrations/backfill_chat_scope.sql (旧数据回填)

## Bug 修复
- #104: KnowledgeItem.sourceRef 填充 (material scope 检索修复)
- #102: sendMessageStream aiGateway null 保护
- listSessions isDeleted/isArchived 过滤 + 分页

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 17:27:40 +08:00
wangdl
17f16cea67 feat: #70 ChatSession 新增 knowledgeItemIds 字段,限定 AI 检索范围
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 46s
- Prisma schema: ChatSession 加 knowledgeItemIds Json? 字段
- createSession: 接受可选 knowledgeItemIds 参数
- loadContext: 支持 itemIds 过滤,传入时只检索指定知识点
- sendMessage/sendMessageStream: 读取 session.knowledgeItemIds 传入 loadContext

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 16:02:38 +08:00
wangdl
6d0cc9b6dc fix: GET /sessions @Body → @Query, 修复对话列表获取失败
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 44s
GET 请求不应使用 @Body 装饰器(NestJS 默认不解析 GET body)。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 15:45:03 +08:00
wangdl
dc5948a2cd fix: chat session auto-title + delete + remove double drag indicator
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 44s
- 首条用户消息自动设为会话标题(仅当 title 为空或为新对话时)
- 对话列表新增左滑删除
- 移除 duplicate drag indicator

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 15:15:00 +08:00
wangdl
35f2cd6e59 fix: SSE charset utf-8 + 服务端 charset header
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 43s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 15:01:16 +08:00
wangdl
aea071e4c9 fix: rag-chat controller Response 改为 import type 修复 isolatedModules 编译错误
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 43s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:56:13 +08:00
wangdl
6f77162cf8 feat: #71 RAG Chat SSE 流式输出 + DeepSeek V4 Pro 思考过程
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 20s
- AiProvider 接口新增 StreamChunk 类型 + generateStream() 方法
- DeepSeekProvider 实现 generateStream():stream=true,读 reader 逐 chunk yield
- AiGatewayService 新增 generateStream():透传 provider stream + 记录用量
- RagChatService 新增 sendMessageStream():流式调用 + 保存最终 AI 回复到 DB
- POST /api/rag-chat/sessions/:id/stream 新 SSE endpoint
- thinking chunk:DeepSeek V4 Pro reasoning_content → type: "thinking"
- 流式模式下禁用 response_format json_object,不阻塞思考过程

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:49:20 +08:00
wangdl
f4de598d96 fix: rag-chat 传入 outputSchema= RagChatOutputSchema,修复 parsed 为空对象
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 42s
parseJson 无 schema 时直接返回 {},导致 resp.parsed?.answer 始终为 null。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:30:53 +08:00
wangdl
69bcd07a0f debug: rag-chat 日志输出 AI parsed 结构
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 43s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:28:35 +08:00
wangdl
55221116b7 debug: rag-chat 日志增加 kbId
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 42s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:12:44 +08:00
wangdl
07f2786ab9 fix: 移除 rag-chat 调试日志中的 rawText 引用 (GatewayResponse 无此字段)
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 41s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:04:17 +08:00
wangdl
ce43256690 debug: rag-chat sendMessage 添加详细日志定位 AI Gateway 调用失败原因
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 21s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 13:56:28 +08:00
wangdl
78e21c4c4c fix: RagChatModule 导入 AiModule,修复 AiGatewayService 未注入
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 43s
AiGatewayService 使用了 @Optional() 导致不报错但始终为 null,
sendMessage 永远走 fallbackReply。现在导入 AiModule 正确注入。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 13:40:03 +08:00
wangdl
d7a7611b36 fix: ChatCitation 字段 + BigInt 类型修复
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 48s
- ChatCitation.content → excerptText(对齐 Prisma schema)
- ChatCitation.score 不存在→ 移除
- UploadedFile.sizeBytes BigInt → Number() 转换

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-30 08:42:07 +08:00
wangdl
6ab54be309 feat: H0-11 RAG Chat 接入真实检索 + AI 生成管道
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 19s
- sendMessage 从 KB 加载知识点内容作为上下文(最多 30 条/4000 字符)
- 通过 AiGatewayService 调用 DeepSeek 生成回答
- AI 回复附带引用来源(ChatCitation)
- AI Gateway 不可用时降级提示
- 知识库为空时引导用户先添加内容

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 19:31:33 +08:00
0c07b59765 fix: add @Optional() to ContentSafetyService in RagChatService
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 41s
Same issue as KnowledgeBaseService — NestJS can't resolve
ContentSafetyService in RagChatModule without @Optional().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 13:46:30 +08:00
98bc9961ba feat: M2-07 — RAG Chat module with sessions, messages, citations
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 33s
- ChatSession/ChatMessage/ChatCitation Prisma models
- CAPI: create/list sessions, send message, get history, delete
- Admin AAPI: view user sessions and messages
- Content safety integration on user input
- Placeholder RAG pipeline (real pipeline in M3)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 13:39:14 +08:00