修复Dify对话记录加载问题:移除user参数,由后端自动管理

问题描述:
- 用户登录后无法加载历史对话记录
- 根本原因:前端传递的user值与实际用户不一致,导致Dify无法找到对应的对话

解决方案:
- 后端已实现user字段自动填充功能(v1.2.7-post2)
- 前端采用方案A:完全移除user参数传递
- 让后端从JWT中自动提取username并管理user字段

修改内容:
1. dify-client.server.ts
   - 移除所有方法的user参数
   - GET请求移除user查询参数
   - POST/DELETE请求移除user字段
   - 移除generateUserId工具函数

2. 所有API路由
   - 移除getSessionInfo中的user解构
   - 移除difyClient方法调用中的user参数传递
   - 日志中移除user信息输出

影响接口:
- GET /dify/conversations - 会话列表
- GET /dify/messages - 消息历史
- POST /dify/chat-messages - 发送消息
- POST /dify/conversations/{id}/name - 重命名会话
- DELETE /dify/conversations/{id} - 删除会话
- POST /dify/messages/{id}/feedbacks - 消息反馈

参考文档:docs/dify-frontend-user-field-guide.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-30 10:37:45 +08:00
parent 05cc992c78
commit 3254cec5ca
8 changed files with 395 additions and 40 deletions
+2 -3
View File
@@ -7,7 +7,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
// 获取用户会话信息和 JWT
const { getUserSession } = await import("~/api/login/auth.server");
const { frontendJWT } = await getUserSession(request);
const { user, session } = await getSessionInfo(request);
const { session } = await getSessionInfo(request);
const { id } = params;
if (!id) {
@@ -32,13 +32,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
if (method === 'DELETE') {
console.log('🗑️ [API] Delete Conversation API - 删除会话:', {
user,
id,
hasJWT: !!frontendJWT
});
// 调用服务端API删除会话
const data = await difyClient.deleteConversation(id, user, frontendJWT);
const data = await difyClient.deleteConversation(id, frontendJWT);
console.log('✅ [API] Delete Conversation API - Success');