添加对话记录保存详细日志,诊断conversation_id传递问题
添加日志位置: 1. chat/index.tsx: 发送消息、接收会话ID变更、初始化读取localStorage 2. use-chat-message.ts: 发送消息、接收新会话ID、处理新会话 3. use-conversation.ts: setCurrConversationId保存到localStorage 帮助诊断为什么对话记录没有固定(每次都创建新会话) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -60,7 +60,11 @@ export default function Chat() {
|
||||
} = useChatMessage({
|
||||
onUpdateConversationList: updateConversationInList,
|
||||
onConversationIdChange: async (conversationId: string) => {
|
||||
// console.log('🔄 收到会话ID变更通知:', conversationId);
|
||||
console.log('🔄 [Chat] 收到会话ID变更通知:', {
|
||||
oldConversationId: currConversationId,
|
||||
newConversationId: conversationId,
|
||||
willUpdateLocalStorage: true
|
||||
});
|
||||
|
||||
// 设置当前会话ID(这会触发localStorage更新)
|
||||
setCurrConversationId(conversationId, CHAT_CONFIG.APP_ID);
|
||||
@@ -302,7 +306,12 @@ export default function Chat() {
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log('📤 发送消息:', { message, conversationId: currConversationId });
|
||||
console.log('📤 [Chat] 发送消息:', {
|
||||
message: message.substring(0, 50) + (message.length > 50 ? '...' : ''),
|
||||
currConversationId,
|
||||
isNewConversation,
|
||||
willSendConversationId: isNewConversation ? null : currConversationId
|
||||
});
|
||||
|
||||
try {
|
||||
// 准备输入数据
|
||||
@@ -414,8 +423,12 @@ export default function Chat() {
|
||||
const _conversationId = getConversationIdFromStorage(CHAT_CONFIG.APP_ID);
|
||||
const isNotNewConversation = conversations.some((item: ConversationItem) => item.id === _conversationId);
|
||||
|
||||
// console.log('💾 本地存储的会话ID:', _conversationId);
|
||||
// console.log('🔍 是否为已存在的会话:', isNotNewConversation);
|
||||
console.log('💾 [Chat] 初始化 - 本地存储的会话ID:', {
|
||||
conversationId: _conversationId,
|
||||
isNotNewConversation,
|
||||
conversationsCount: conversations.length,
|
||||
conversationIds: conversations.map((c: ConversationItem) => c.id)
|
||||
});
|
||||
|
||||
// 获取新会话信息
|
||||
const { user_input_form, opening_statement: introduction } = (appParams as any).data || {};
|
||||
@@ -436,11 +449,11 @@ export default function Chat() {
|
||||
|
||||
// 如果存在有效的会话ID,则设置为当前会话
|
||||
if (isNotNewConversation) {
|
||||
// console.log('🎯 设置当前会话ID:', _conversationId);
|
||||
console.log('🎯 [Chat] 初始化 - 设置当前会话ID:', _conversationId);
|
||||
setCurrConversationId(_conversationId, CHAT_CONFIG.APP_ID, false);
|
||||
} else {
|
||||
// 如果localStorage为空或会话不存在,自动创建新会话
|
||||
console.log('🆕 localStorage为空或会话不存在,创建新会话');
|
||||
console.log('🆕 [Chat] 初始化 - localStorage为空或会话不存在,创建新会话');
|
||||
setCurrConversationId('-1', CHAT_CONFIG.APP_ID, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user