feat: 添加会话标题自动生成功能
- 后端:首次 AI 回复后自动从用户消息提取标题 - 后端:通过 WebSocket 推送 session_updated 事件 - 前端:useChat hook 处理标题更新事件 - 前端:Sidebar 组件实时更新会话标题显示
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* App Component
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
Sidebar,
|
||||
FileBrowser,
|
||||
@@ -19,6 +19,7 @@ export function App() {
|
||||
const [isInitializing, setIsInitializing] = useState(true);
|
||||
const [showFileBrowser, setShowFileBrowser] = useState(false);
|
||||
const [showConfig, setShowConfig] = useState(false);
|
||||
const [sessionTitleUpdate, setSessionTitleUpdate] = useState<{ sessionId: string; name: string } | null>(null);
|
||||
|
||||
// 初始化:加载或创建会话
|
||||
useEffect(() => {
|
||||
@@ -52,6 +53,11 @@ export function App() {
|
||||
setCurrentSessionId(session.id);
|
||||
};
|
||||
|
||||
// 会话标题更新回调
|
||||
const handleSessionUpdated = useCallback((sessionId: string, name: string) => {
|
||||
setSessionTitleUpdate({ sessionId, name });
|
||||
}, []);
|
||||
|
||||
if (isInitializing) {
|
||||
return (
|
||||
<div className="h-screen flex items-center justify-center bg-gray-900">
|
||||
@@ -69,6 +75,7 @@ export function App() {
|
||||
currentSessionId={currentSessionId}
|
||||
onSelectSession={handleSelectSession}
|
||||
onCreateSession={handleCreateSession}
|
||||
sessionTitleUpdate={sessionTitleUpdate}
|
||||
/>
|
||||
|
||||
<div className="flex-1 flex">
|
||||
@@ -78,6 +85,7 @@ export function App() {
|
||||
<ChatPage
|
||||
key={currentSessionId}
|
||||
sessionId={currentSessionId}
|
||||
onSessionUpdated={handleSessionUpdated}
|
||||
showFileBrowser={showFileBrowser}
|
||||
onToggleFileBrowser={() => setShowFileBrowser(!showFileBrowser)}
|
||||
onOpenConfig={() => setShowConfig(true)}
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
|
||||
interface ChatPageProps {
|
||||
sessionId: string;
|
||||
onSessionUpdated?: (sessionId: string, name: string) => void;
|
||||
// 工具栏按钮
|
||||
showFileBrowser?: boolean;
|
||||
onToggleFileBrowser?: () => void;
|
||||
@@ -23,6 +24,7 @@ interface ChatPageProps {
|
||||
|
||||
export function ChatPage({
|
||||
sessionId,
|
||||
onSessionUpdated,
|
||||
showFileBrowser,
|
||||
onToggleFileBrowser,
|
||||
onOpenConfig,
|
||||
@@ -39,6 +41,7 @@ export function ChatPage({
|
||||
onError: (error) => {
|
||||
console.error('Chat error:', error);
|
||||
},
|
||||
onSessionUpdated,
|
||||
});
|
||||
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
Reference in New Issue
Block a user