diff --git a/app/graph_history_manager.py b/app/graph_history_manager.py index 0a27156..2983a79 100644 --- a/app/graph_history_manager.py +++ b/app/graph_history_manager.py @@ -218,12 +218,12 @@ class GraphHistoryManager: """ with self._get_connection() as conn: cursor = conn.cursor() - cursor.execute("SELECT current_node_id FROM graphs WHERE id = ?", + cursor.execute("SELECT current_node_id, title, title_generated FROM graphs WHERE id = ?", # Извлекаем title и title_generated (graph_id, )) result = cursor.fetchone() if result: - db_current_node_id = result[0] + db_current_node_id, graph_title, graph_title_generated = result # Распаковываем полученные значения # Получаем все узлы и ребра graph_nodes = self._get_graph_nodes(conn, graph_id) @@ -237,13 +237,25 @@ class GraphHistoryManager: "graph_nodes": graph_nodes, "graph_edges": graph_edges }, resolved_current_node_id) - + + # Определяем "первое_сообщение" для отображения, если заголовок еще не сгенерирован + first_message_content = None + if messages: + for msg in messages: + if msg.get("role") == "user": + first_message_content = msg.get("content") + break + if not first_message_content and messages: + first_message_content = messages[0].get("content") + return { "id": graph_id, "messages": messages, "graph_nodes": graph_nodes, "graph_edges": graph_edges, - "current_node_id": resolved_current_node_id + "current_node_id": resolved_current_node_id, + "title": graph_title if graph_title_generated else None, # Включаем сгенерированный заголовок + "first_message": first_message_content # Включаем первое сообщение } else: return None