fix: 第四轮调试 — 回复去重/消息时序/UI布局/自主思考深度优化 + 文档重整
后端修复: - main.go: 恢复 /api/v1/chat 路由中丢失的 handleChat 调用 (空响应回归) - orchestrator.go: splitChatByLines 改为双换行分割, 避免单换行误拆 - chat_handler.go: multi_message 增加 !hasReview 守卫, 消息延迟 200→800ms - thinker.go: RecordUserMessage 追踪活跃会话ID, 推送主动消息到正确会话 - thinker.go: 增强思考提示词 — 禁止在用户休息/离开时发送主动消息 前端修复: - useWebSocket.ts: stream_segments 不再创建消息气泡, 消除重复回复 - MessageBubble.tsx: 动作消息居左对齐无头像, 时间戳移至气泡外侧 hover 显示 - ChatInput.tsx: 昔涟输入提示移至输入框上方, 波点动画效果 - MessageList/TypingIndicator/ChatContainer: 清理冗余 isTyping 传递 - MemoryPanel.tsx: 新增记忆面板组件 文档重整: - docs/debug/ → docs/debug_log/ 重命名统一 - 新增 debug_log/README.md 索引 - .gitignore: 新增 android/ 排除规则 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -300,4 +300,8 @@ export async function addMemory(content: string, category?: string, priority?: n
|
||||
return request('/memory', { method: 'POST', body: { content, category, priority } });
|
||||
}
|
||||
|
||||
export async function deleteMemory(id: string) {
|
||||
return request(`/memory?id=${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export { request, type ApiResponse };
|
||||
|
||||
@@ -3,4 +3,5 @@ export {
|
||||
searchMemory,
|
||||
listMemories,
|
||||
addMemory,
|
||||
deleteMemory,
|
||||
} from './client';
|
||||
|
||||
@@ -5,7 +5,6 @@ import { IoTStatusBar } from './IoTStatusBar';
|
||||
|
||||
export function ChatContainer() {
|
||||
const messages = useChatStore((s) => s.messages);
|
||||
const isTyping = useChatStore((s) => s.isTyping);
|
||||
const continuousMode = useChatStore((s) => s.continuousMode);
|
||||
const backgroundThinkingStatus = useChatStore((s) => s.backgroundThinkingStatus);
|
||||
|
||||
@@ -46,7 +45,6 @@ export function ChatContainer() {
|
||||
<div className="flex flex-col flex-1 min-h-0">
|
||||
<MessageList
|
||||
messages={messages}
|
||||
isTyping={isTyping}
|
||||
hasMoreMessages={useChatStore((s) => s.hasMoreMessages)}
|
||||
isLoadingHistory={useChatStore((s) => s.isLoadingHistory)}
|
||||
onLoadMore={() => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, useRef, useCallback, useEffect } from 'react';
|
||||
import type { ChatMode, MessageAttachment } from '@/types/chat';
|
||||
import { useSpeechRecognition } from '@/hooks/useSpeechRecognition';
|
||||
import { uploadFile } from '@/api/files';
|
||||
import { useChatStore } from '@/store/chatStore';
|
||||
|
||||
interface ChatInputProps {
|
||||
onSend: (content: string, mode: ChatMode, attachments?: MessageAttachment[]) => void;
|
||||
@@ -26,6 +27,7 @@ export function ChatInput({ onSend, disabled }: ChatInputProps) {
|
||||
const [uploadError, setUploadError] = useState('');
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const isTyping = useChatStore((s) => s.isTyping);
|
||||
|
||||
const {
|
||||
isListening,
|
||||
@@ -98,6 +100,7 @@ export function ChatInput({ onSend, disabled }: ChatInputProps) {
|
||||
setUploading(false);
|
||||
}
|
||||
|
||||
useChatStore.getState().setTyping(true);
|
||||
onSend(trimmed, mode, attachments);
|
||||
setContent('');
|
||||
setPendingImages([]);
|
||||
@@ -221,6 +224,27 @@ export function ChatInput({ onSend, disabled }: ChatInputProps) {
|
||||
return (
|
||||
<div className="border-t border-pink-100 dark:border-pink-900 bg-white/80 dark:bg-gray-900/80 backdrop-blur-sm px-4 py-3">
|
||||
<div className="flex flex-col gap-2 max-w-3xl mx-auto">
|
||||
{/* 昔涟正在输入指示器 */}
|
||||
{isTyping && (
|
||||
<div className="flex items-center gap-2 px-1 animate-fadeIn">
|
||||
<div className="flex gap-1">
|
||||
<span
|
||||
className="w-2 h-2 rounded-full bg-pink-400 animate-bounce"
|
||||
style={{ animationDelay: '0ms' }}
|
||||
/>
|
||||
<span
|
||||
className="w-2 h-2 rounded-full bg-pink-400 animate-bounce"
|
||||
style={{ animationDelay: '150ms' }}
|
||||
/>
|
||||
<span
|
||||
className="w-2 h-2 rounded-full bg-pink-400 animate-bounce"
|
||||
style={{ animationDelay: '300ms' }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-xs text-pink-400 font-medium">昔涟正在输入...</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 实时识别文本提示 */}
|
||||
{isListening && interimText && (
|
||||
<div
|
||||
|
||||
@@ -173,10 +173,17 @@ export function MessageBubble({
|
||||
const imageAttachments = attachments?.filter((a) => a.type === 'image') ?? [];
|
||||
|
||||
return (
|
||||
<div className={`flex px-4 py-2 gap-3 ${isUser ? 'justify-end' : ''}`}>
|
||||
<div className={`flex px-4 py-2 gap-2 items-end group ${isUser ? 'justify-end' : ''}`}>
|
||||
{/* 用户消息:时间在左侧(气泡外侧) */}
|
||||
{isUser && !isStreaming && (
|
||||
<p className="text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0 mb-1 hidden md:block md:opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||
{time}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* 头像 */}
|
||||
{!isUser && (
|
||||
<CyreneAvatar size="sm" className="flex-shrink-0 mt-1" />
|
||||
<CyreneAvatar size="sm" className="flex-shrink-0 mb-0.5" />
|
||||
)}
|
||||
|
||||
{/* 消息气泡 */}
|
||||
@@ -249,22 +256,15 @@ export function MessageBubble({
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isStreaming && (
|
||||
<>
|
||||
{/* AI 消息操作栏(朗读按钮)— 暂时禁用 */}
|
||||
{/* !isUser && <AIMessageActions content={content} /> */}
|
||||
<p
|
||||
className={`text-xs mt-1 ${
|
||||
isUser ? 'text-pink-100' : 'text-gray-400'
|
||||
}`}
|
||||
>
|
||||
{time}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 昔涟消息:时间在右侧(气泡外侧) */}
|
||||
{!isUser && !isStreaming && (
|
||||
<p className="text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0 mb-1 hidden md:block md:opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||
{time}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* 用户头像 */}
|
||||
{isUser && <UserAvatar />}
|
||||
|
||||
@@ -280,7 +280,7 @@ export function MessageBubble({
|
||||
);
|
||||
}
|
||||
|
||||
/** 动作消息气泡 — 灰色/斜体/居中,视觉上与聊天消息区分 */
|
||||
/** 动作消息气泡 — 居左,与昔涟头像对齐,灰色/斜体与聊天消息区分 */
|
||||
function ActionMessageBubble({ content, timestamp }: { content: string; timestamp: number }) {
|
||||
const time = new Date(timestamp).toLocaleTimeString('zh-CN', {
|
||||
hour: '2-digit',
|
||||
@@ -288,15 +288,16 @@ function ActionMessageBubble({ content, timestamp }: { content: string; timestam
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex justify-center px-4 py-1 animate-fadeIn">
|
||||
<div className="max-w-[70%] text-center">
|
||||
<p className="text-xs text-gray-400 dark:text-gray-500 italic leading-relaxed whitespace-pre-wrap break-words">
|
||||
<span className="select-none text-gray-300 dark:text-gray-600">~ </span>
|
||||
<div className="flex px-4 py-0.5 gap-1.5 items-end group animate-fadeIn">
|
||||
<div className="w-8 flex-shrink-0" />
|
||||
<div className="max-w-[70%]">
|
||||
<p className="text-xs text-gray-400 dark:text-gray-500 italic leading-snug whitespace-pre-wrap break-words">
|
||||
{content}
|
||||
<span className="select-none text-gray-300 dark:text-gray-600"> ~</span>
|
||||
</p>
|
||||
<p className="text-[10px] text-gray-300 dark:text-gray-600 mt-0.5">{time}</p>
|
||||
</div>
|
||||
<p className="text-[10px] text-gray-400 dark:text-gray-500 flex-shrink-0 mb-0.5 hidden md:block md:opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||
{time}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { MessageBubble } from './MessageBubble';
|
||||
import { TypingIndicator } from './TypingIndicator';
|
||||
import type { Message } from '@/types/chat';
|
||||
|
||||
interface MessageListProps {
|
||||
messages: Message[];
|
||||
isTyping: boolean;
|
||||
hasMoreMessages?: boolean;
|
||||
isLoadingHistory?: boolean;
|
||||
onLoadMore?: () => void;
|
||||
@@ -13,7 +11,6 @@ interface MessageListProps {
|
||||
|
||||
export function MessageList({
|
||||
messages,
|
||||
isTyping,
|
||||
hasMoreMessages = false,
|
||||
isLoadingHistory = false,
|
||||
onLoadMore,
|
||||
@@ -26,7 +23,7 @@ export function MessageList({
|
||||
if (!isLoadingHistory) {
|
||||
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}, [messages, isTyping, isLoadingHistory]);
|
||||
}, [messages, isLoadingHistory]);
|
||||
|
||||
if (messages.length === 0 && !isLoadingHistory) {
|
||||
return (
|
||||
@@ -77,7 +74,6 @@ export function MessageList({
|
||||
msgType={msg.msgType}
|
||||
/>
|
||||
))}
|
||||
{isTyping && !messages.some((m) => m.isStreaming) && <TypingIndicator />}
|
||||
<div ref={bottomRef} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ export function TypingIndicator() {
|
||||
<div className="flex px-4 py-2 gap-3">
|
||||
<CyreneAvatar size="sm" className="flex-shrink-0 mt-1" />
|
||||
<div className="bg-white dark:bg-gray-800 rounded-2xl rounded-bl-md px-4 py-3 shadow-sm border border-pink-100 dark:border-pink-900">
|
||||
<p className="text-xs text-pink-400 mb-1.5 font-medium">昔涟正在输入...</p>
|
||||
<div className="flex gap-1.5">
|
||||
<span
|
||||
className="w-2 h-2 rounded-full bg-pink-300 animate-bounce"
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState } from 'react';
|
||||
import { Sidebar } from './Sidebar';
|
||||
import { Header } from './Header';
|
||||
import { SearchModal } from './SearchModal';
|
||||
import { MemoryPanel } from './MemoryPanel';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
|
||||
interface AppLayoutProps {
|
||||
@@ -11,6 +12,7 @@ interface AppLayoutProps {
|
||||
export function AppLayout({ children }: AppLayoutProps) {
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||
const [searchOpen, setSearchOpen] = useState(false);
|
||||
const [memoryOpen, setMemoryOpen] = useState(false);
|
||||
const { isLoggedIn } = useAuth();
|
||||
|
||||
return (
|
||||
@@ -31,7 +33,7 @@ export function AppLayout({ children }: AppLayoutProps) {
|
||||
${sidebarOpen ? 'translate-x-0' : '-translate-x-full lg:translate-x-0'}
|
||||
`}
|
||||
>
|
||||
<Sidebar onClose={() => setSidebarOpen(false)} />
|
||||
<Sidebar onClose={() => setSidebarOpen(false)} onMemoryClick={() => setMemoryOpen(true)} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
@@ -49,6 +51,8 @@ export function AppLayout({ children }: AppLayoutProps) {
|
||||
|
||||
{/* 搜索弹窗 */}
|
||||
<SearchModal isOpen={searchOpen} onClose={() => setSearchOpen(false)} />
|
||||
{/* 记忆管理弹窗 */}
|
||||
<MemoryPanel isOpen={memoryOpen} onClose={() => setMemoryOpen(false)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { listMemories, deleteMemory } from '@/api/memory';
|
||||
|
||||
interface MemoryEntry {
|
||||
id: string;
|
||||
user_id: string;
|
||||
content: string;
|
||||
category: string;
|
||||
importance: number;
|
||||
session_id?: string;
|
||||
created_at: number | string;
|
||||
}
|
||||
|
||||
interface MemoryPanelProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const CATEGORY_LABELS: Record<string, string> = {
|
||||
user_preference: '偏好',
|
||||
personal_info: '个人信息',
|
||||
conversation: '对话',
|
||||
knowledge: '知识',
|
||||
event: '事件',
|
||||
task: '任务',
|
||||
relationship: '关系',
|
||||
};
|
||||
|
||||
const CATEGORY_COLORS: Record<string, string> = {
|
||||
user_preference: 'bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400',
|
||||
personal_info: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400',
|
||||
conversation: 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400',
|
||||
knowledge: 'bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400',
|
||||
event: 'bg-pink-100 text-pink-700 dark:bg-pink-900/30 dark:text-pink-400',
|
||||
task: 'bg-cyan-100 text-cyan-700 dark:bg-cyan-900/30 dark:text-cyan-400',
|
||||
relationship: 'bg-rose-100 text-rose-700 dark:bg-rose-900/30 dark:text-rose-400',
|
||||
};
|
||||
|
||||
function formatTime(ts: number | string): string {
|
||||
const date = new Date(typeof ts === 'string' ? parseInt(ts, 10) : ts);
|
||||
if (isNaN(date.getTime())) return '';
|
||||
const now = new Date();
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMin = Math.floor(diffMs / 60000);
|
||||
if (diffMin < 1) return '刚刚';
|
||||
if (diffMin < 60) return `${diffMin}分钟前`;
|
||||
const diffHour = Math.floor(diffMin / 60);
|
||||
if (diffHour < 24) return `${diffHour}小时前`;
|
||||
const diffDay = Math.floor(diffHour / 24);
|
||||
if (diffDay < 7) return `${diffDay}天前`;
|
||||
return date.toLocaleDateString('zh-CN');
|
||||
}
|
||||
|
||||
export function MemoryPanel({ isOpen, onClose }: MemoryPanelProps) {
|
||||
const [memories, setMemories] = useState<MemoryEntry[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||
const [confirmId, setConfirmId] = useState<string | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const fetchMemories = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
const resp: any = await listMemories();
|
||||
// 后端可能返回 { memories: [...] } 或直接是数组
|
||||
const list = Array.isArray(resp) ? resp : (resp.memories || resp.data || []);
|
||||
setMemories(list);
|
||||
} catch (err) {
|
||||
setError('加载记忆失败,请检查记忆服务是否运行');
|
||||
console.error('[MemoryPanel] 加载记忆失败:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
fetchMemories();
|
||||
setConfirmId(null);
|
||||
}
|
||||
}, [isOpen, fetchMemories]);
|
||||
|
||||
// ESC 关闭
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && isOpen && !confirmId) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
document.addEventListener('keydown', handleKeyDown);
|
||||
return () => document.removeEventListener('keydown', handleKeyDown);
|
||||
}, [isOpen, onClose, confirmId]);
|
||||
|
||||
const handleDelete = useCallback(async (id: string) => {
|
||||
setDeletingId(id);
|
||||
setConfirmId(null);
|
||||
try {
|
||||
await deleteMemory(id);
|
||||
setMemories((prev) => prev.filter((m) => m.id !== id));
|
||||
} catch (err) {
|
||||
console.error('[MemoryPanel] 删除记忆失败:', err);
|
||||
} finally {
|
||||
setDeletingId(null);
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-start justify-center pt-[10vh]">
|
||||
{/* 背景遮罩 */}
|
||||
<div className="absolute inset-0 bg-black/30 backdrop-blur-sm" onClick={onClose} />
|
||||
|
||||
{/* 面板 */}
|
||||
<div className="relative w-full max-w-lg mx-4 bg-white dark:bg-gray-850 rounded-2xl shadow-2xl border border-pink-100 dark:border-pink-800 flex flex-col max-h-[75vh]">
|
||||
{/* 标题栏 */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-pink-100 dark:border-pink-800">
|
||||
<h2 className="text-base font-semibold text-gray-800 dark:text-gray-200">
|
||||
🧠 记忆管理
|
||||
</h2>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={fetchMemories}
|
||||
disabled={loading}
|
||||
className="text-xs px-2 py-1 text-gray-400 hover:text-pink-500 hover:bg-pink-50 dark:hover:bg-pink-900/20 rounded-lg transition-colors"
|
||||
>
|
||||
{loading ? '刷新中…' : '🔄 刷新'}
|
||||
</button>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 内容区域 */}
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
{loading && memories.length === 0 && (
|
||||
<div className="py-12 text-center">
|
||||
<div className="h-5 w-5 mx-auto animate-spin rounded-full border-2 border-pink-400 border-t-transparent" />
|
||||
<p className="text-sm text-gray-400 mt-3">加载中…</p>
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
<div className="py-12 text-center text-sm text-red-400">{error}</div>
|
||||
)}
|
||||
{!loading && !error && memories.length === 0 && (
|
||||
<div className="py-12 text-center text-sm text-gray-400">
|
||||
还没有记忆哦,和昔涟多聊聊吧 ♪
|
||||
</div>
|
||||
)}
|
||||
{memories.length > 0 && (
|
||||
<>
|
||||
<div className="px-4 py-2 text-xs text-gray-400 border-b border-pink-50 dark:border-pink-900">
|
||||
共 {memories.length} 条记忆
|
||||
</div>
|
||||
{memories.map((mem) => {
|
||||
const categoryLabel = CATEGORY_LABELS[mem.category] || mem.category || '其他';
|
||||
const colorClass = CATEGORY_COLORS[mem.category] || 'bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400';
|
||||
|
||||
return (
|
||||
<div
|
||||
key={mem.id}
|
||||
className="px-4 py-3 border-b border-pink-50 dark:border-pink-900/50 last:border-b-0 hover:bg-pink-50/50 dark:hover:bg-pink-900/10 transition-colors group"
|
||||
>
|
||||
<div className="flex items-start gap-2">
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm text-gray-700 dark:text-gray-200 break-words">
|
||||
{mem.content}
|
||||
</p>
|
||||
<div className="flex items-center gap-2 mt-1.5">
|
||||
<span className={`text-xs px-1.5 py-0.5 rounded-full font-medium ${colorClass}`}>
|
||||
{categoryLabel}
|
||||
</span>
|
||||
<span className="text-xs text-gray-400">
|
||||
重要度 {mem.importance}/10
|
||||
</span>
|
||||
<span className="text-xs text-gray-400">
|
||||
{formatTime(mem.created_at)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 删除按钮 */}
|
||||
<div className="shrink-0">
|
||||
{confirmId === mem.id ? (
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => handleDelete(mem.id)}
|
||||
disabled={deletingId === mem.id}
|
||||
className="text-xs px-2 py-1 bg-red-400 hover:bg-red-500 text-white rounded-lg transition-colors"
|
||||
>
|
||||
{deletingId === mem.id ? '…' : '确认'}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setConfirmId(null)}
|
||||
className="text-xs px-2 py-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 rounded-lg transition-colors"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setConfirmId(mem.id)}
|
||||
className="opacity-0 group-hover:opacity-100 p-1 text-gray-400 hover:text-red-400 transition-all"
|
||||
title="删除记忆"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 底部 */}
|
||||
<div className="px-4 py-2 border-t border-pink-100 dark:border-pink-800 text-xs text-gray-400 text-center">
|
||||
<kbd className="px-1.5 py-0.5 bg-gray-100 dark:bg-gray-700 rounded text-xs">ESC</kbd> 关闭
|
||||
{' · '}
|
||||
点击垃圾桶图标删除记忆
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,9 +7,10 @@ import type { Session } from '@/types/session';
|
||||
|
||||
interface SidebarProps {
|
||||
onClose?: () => void;
|
||||
onMemoryClick?: () => void;
|
||||
}
|
||||
|
||||
export function Sidebar({ onClose }: SidebarProps) {
|
||||
export function Sidebar({ onClose, onMemoryClick }: SidebarProps) {
|
||||
const {
|
||||
sessions,
|
||||
createSession,
|
||||
@@ -277,8 +278,17 @@ export function Sidebar({ onClose }: SidebarProps) {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 底部:一键清空所有对话 */}
|
||||
<div className="p-3 border-t border-pink-100 dark:border-pink-900">
|
||||
{/* 底部:记忆管理 + 一键清空所有对话 */}
|
||||
<div className="p-3 border-t border-pink-100 dark:border-pink-900 space-y-2">
|
||||
{onMemoryClick && (
|
||||
<button
|
||||
onClick={onMemoryClick}
|
||||
className="w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-purple-50 hover:bg-purple-100 dark:bg-purple-900/20 dark:hover:bg-purple-900/30 text-purple-500 hover:text-purple-600 rounded-xl text-xs font-medium transition-colors border border-purple-200 dark:border-purple-800"
|
||||
>
|
||||
<span>🧠</span>
|
||||
<span>记忆管理</span>
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => setConfirmAction({ type: 'deleteAll' })}
|
||||
className="w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-red-50 hover:bg-red-100 dark:bg-red-900/20 dark:hover:bg-red-900/30 text-red-400 hover:text-red-500 rounded-xl text-xs font-medium transition-colors border border-red-200 dark:border-red-800"
|
||||
|
||||
@@ -201,6 +201,10 @@ function handleServerMessage(msg: WSServerMessage) {
|
||||
const chatState = useChatStore.getState();
|
||||
|
||||
switch (msg.type) {
|
||||
case 'stream_start':
|
||||
setTyping(true);
|
||||
break;
|
||||
|
||||
case 'response':
|
||||
// 支持两种格式: 旧版 (text 字段) 和 审查消息版 (content + role + msg_type 字段)
|
||||
if (msg.text || msg.content) {
|
||||
@@ -285,8 +289,7 @@ function handleServerMessage(msg: WSServerMessage) {
|
||||
break;
|
||||
|
||||
case 'multi_message':
|
||||
case 'stream_segments':
|
||||
// 多段消息 / 流式片段 — 已通过 stream_chunk 处理,这里作为兜底
|
||||
// 多段消息 — 仅在后端未发送 response 时作为兜底
|
||||
if (msg.multi_messages && msg.multi_messages.length > 0) {
|
||||
for (const item of msg.multi_messages) {
|
||||
addMessage({
|
||||
@@ -298,20 +301,14 @@ function handleServerMessage(msg: WSServerMessage) {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (msg.stream_segments && msg.stream_segments.length > 0) {
|
||||
for (const seg of msg.stream_segments) {
|
||||
addMessage({
|
||||
id: `seg_${Date.now()}_${seg.index}`,
|
||||
role: 'assistant',
|
||||
content: seg.text,
|
||||
timestamp: msg.timestamp || Date.now(),
|
||||
isStreaming: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
setTyping(false);
|
||||
break;
|
||||
|
||||
case 'stream_segments':
|
||||
// 流式片段 — 语音合成辅助数据,不创建新消息气泡
|
||||
// response/multi_message 已负责创建聊天消息
|
||||
break;
|
||||
|
||||
case 'device_update':
|
||||
if (msg.devices && msg.devices.length > 0) {
|
||||
chatState.setIoTDevices(msg.devices);
|
||||
|
||||
@@ -122,7 +122,7 @@ export interface AppNotification extends NotificationData {
|
||||
|
||||
/** WebSocket 服务端消息 */
|
||||
export interface WSServerMessage {
|
||||
type: 'response' | 'segment' | 'audio' | 'error' | 'device_update' | 'pong' | 'history_response' | 'stream_chunk' | 'stream_end' | 'background_thinking' | 'notification' | 'multi_message' | 'stream_segments' | 'review';
|
||||
type: 'stream_start' | 'response' | 'segment' | 'audio' | 'error' | 'device_update' | 'pong' | 'history_response' | 'stream_chunk' | 'stream_end' | 'background_thinking' | 'notification' | 'multi_message' | 'stream_segments' | 'review';
|
||||
message_id?: string;
|
||||
text?: string;
|
||||
content?: string;
|
||||
|
||||
Reference in New Issue
Block a user