Change to show graph title in graph panel

This commit is contained in:
dimitrievgs 2025-10-05 19:10:52 +03:00
parent 56751ebc1c
commit 7bd9fc92f7

View File

@ -218,12 +218,12 @@ class GraphHistoryManager:
""" """
with self._get_connection() as conn: with self._get_connection() as conn:
cursor = conn.cursor() 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, )) (graph_id, ))
result = cursor.fetchone() result = cursor.fetchone()
if result: 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) graph_nodes = self._get_graph_nodes(conn, graph_id)
@ -238,12 +238,24 @@ class GraphHistoryManager:
"graph_edges": graph_edges "graph_edges": graph_edges
}, resolved_current_node_id) }, 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 { return {
"id": graph_id, "id": graph_id,
"messages": messages, "messages": messages,
"graph_nodes": graph_nodes, "graph_nodes": graph_nodes,
"graph_edges": graph_edges, "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: else:
return None return None