Related to title generation
This commit is contained in:
parent
32f55ab086
commit
d65996539a
|
|
@ -37,8 +37,12 @@ import { Handle, Position } from 'reactflow';
|
|||
// Простой компонент для узла типа 'user'
|
||||
// Это базовый пример. Ты можешь стилизовать его по своему усмотрению.
|
||||
const UserNode: React.FC<any> = ({ data, isConnectable }) => {
|
||||
const displayLabel = data.title || data.label || 'Пользователь';
|
||||
const titleGenerated = data.title_generated;
|
||||
|
||||
return React.createElement(
|
||||
React.Fragment,
|
||||
// className: `custom-node user-node ${titleGenerated ? 'title-generated' : 'title-pending'}`,
|
||||
null, // Используем React.Fragment для возврата нескольких элементов без лишнего div
|
||||
React.createElement(Handle, {
|
||||
type: 'source',
|
||||
|
|
@ -50,12 +54,15 @@ const UserNode: React.FC<any> = ({ data, isConnectable }) => {
|
|||
position: Position.Top,
|
||||
isConnectable: isConnectable
|
||||
}),
|
||||
data.label
|
||||
displayLabel
|
||||
);
|
||||
};
|
||||
|
||||
// Простой компонент для узла типа 'llm'
|
||||
const LLMNode: React.FC<any> = ({ data, isConnectable }) => {
|
||||
const displayLabel = data.title || data.label || 'LLM';
|
||||
const titleGenerated = data.title_generated;
|
||||
|
||||
return React.createElement(
|
||||
React.Fragment,
|
||||
null,
|
||||
|
|
@ -69,12 +76,15 @@ const LLMNode: React.FC<any> = ({ data, isConnectable }) => {
|
|||
position: Position.Top,
|
||||
isConnectable: isConnectable
|
||||
}),
|
||||
data.label
|
||||
displayLabel
|
||||
);
|
||||
};
|
||||
|
||||
// Простой компонент для узла типа 'tool'
|
||||
const ToolNode: React.FC<any> = ({ data, isConnectable }) => {
|
||||
const displayLabel = data.title || data.label || 'Инструмент';
|
||||
const titleGenerated = data.title_generated;
|
||||
|
||||
return React.createElement(
|
||||
React.Fragment,
|
||||
null,
|
||||
|
|
@ -88,12 +98,15 @@ const ToolNode: React.FC<any> = ({ data, isConnectable }) => {
|
|||
position: Position.Top,
|
||||
isConnectable: isConnectable
|
||||
}),
|
||||
data.label
|
||||
displayLabel
|
||||
);
|
||||
};
|
||||
|
||||
// Простой компонент для узла типа 'error'
|
||||
const ErrorNode: React.FC<any> = ({ data, isConnectable }) => {
|
||||
const displayLabel = data.title || data.label || 'Ошибка';
|
||||
const titleGenerated = data.title_generated;
|
||||
|
||||
return React.createElement(
|
||||
React.Fragment,
|
||||
null,
|
||||
|
|
@ -107,7 +120,7 @@ const ErrorNode: React.FC<any> = ({ data, isConnectable }) => {
|
|||
position: Position.Top,
|
||||
isConnectable: isConnectable
|
||||
}),
|
||||
data.label
|
||||
displayLabel
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -242,7 +255,11 @@ export const GraphPanelComponent: React.FC<GraphPanelProps> = ({ graphData, onNo
|
|||
const initialNodesForLayout = graphData.nodes.map((node) => ({
|
||||
id: node.id,
|
||||
type: node.type || 'default',
|
||||
data: { label: node.data?.label || `Node ${node.id}` },
|
||||
data: {
|
||||
label: node.data?.label || `Node ${node.id}`,
|
||||
title: node.data?.title,
|
||||
title_generated: node.data?.title_generated || false
|
||||
},
|
||||
position: { x: 0, y: 0 }
|
||||
}));
|
||||
|
||||
|
|
@ -259,10 +276,7 @@ export const GraphPanelComponent: React.FC<GraphPanelProps> = ({ graphData, onNo
|
|||
|
||||
// Применяем layout с задержкой, чтобы DOM успел отрендерить узлы
|
||||
setTimeout(() => {
|
||||
const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements(
|
||||
initialNodesForLayout,
|
||||
initialEdgesForLayout
|
||||
);
|
||||
const { nodes: layoutedNodes, edges: layoutedEdges } = getLayoutedElements(initialNodesForLayout, initialEdgesForLayout);
|
||||
setNodes(layoutedNodes);
|
||||
setEdges(layoutedEdges);
|
||||
}, 100); // Задержка 100ms для рендеринга DOM
|
||||
|
|
|
|||
|
|
@ -76,13 +76,16 @@ export class HistoryPanel {
|
|||
|
||||
renderGraphs(): void {
|
||||
this.chatList.innerHTML = this.graphs
|
||||
.map(
|
||||
(graph) => `
|
||||
.map((graph) => {
|
||||
const titleClass = graph.title_generated ? 'graph-title-generated' : 'graph-title-pending';
|
||||
const displayTitle = graph.title || graph.first_message || `Граф ${graph.id}`;
|
||||
|
||||
return `
|
||||
<div class="chat-list-item" data-graph-id="${graph.id}">
|
||||
<div class="chat-item-content">
|
||||
<div class="chat-item-text">
|
||||
<span class="truncate">
|
||||
${graph.first_message || `Граф ${graph.id}`}
|
||||
<span class="truncate ${titleClass}">
|
||||
${displayTitle}
|
||||
</span>
|
||||
</div>
|
||||
<div class="chat-item-actions">
|
||||
|
|
@ -92,8 +95,8 @@ export class HistoryPanel {
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
)
|
||||
`;
|
||||
})
|
||||
.join('');
|
||||
|
||||
// Добавляем обработчики событий
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ export class ChatView extends ItemView {
|
|||
chatContainer: HTMLDivElement;
|
||||
chatPanel: ChatPanel | null;
|
||||
availableModels: string[];
|
||||
// TODO: сделать аккуратнее - добавлен таймер для обновления заголовков
|
||||
titleUpdateTimer: NodeJS.Timeout | null;
|
||||
|
||||
constructor(leaf: WorkspaceLeaf, plugin: LLMAgentPlugin) {
|
||||
super(leaf);
|
||||
|
|
@ -28,6 +30,7 @@ export class ChatView extends ItemView {
|
|||
this.currentNode = null;
|
||||
this.chatPanel = null;
|
||||
this.availableModels = [];
|
||||
this.titleUpdateTimer = null;
|
||||
}
|
||||
|
||||
getViewType(): string {
|
||||
|
|
@ -174,6 +177,18 @@ export class ChatView extends ItemView {
|
|||
// Вместо того, чтобы отправлять частичные данные, мы запрашиваем полный граф у бэкенда.
|
||||
this.plugin.eventBus.emit('graph-selected', { graphId: this.selectedGraphId, currentNode: this.currentNode });
|
||||
|
||||
// TODO: сделать аккуратнее - устанавливаем таймер на 30 секунд для обновления заголовков
|
||||
this.titleUpdateTimer = setTimeout(() => {
|
||||
console.log('Обновление графа для получения сгенерированных заголовков...');
|
||||
if (this.selectedGraphId && this.currentNode) {
|
||||
this.plugin.eventBus.emit('graph-selected', {
|
||||
graphId: this.selectedGraphId,
|
||||
currentNode: this.currentNode
|
||||
});
|
||||
}
|
||||
this.titleUpdateTimer = null;
|
||||
}, 20000); // 20 секунд, эмпирически
|
||||
|
||||
// Затем обновим ChatView, загрузив историю до нового current_node_id
|
||||
if (newCurrentNodeId) {
|
||||
await this.fetchMessagesFromRootToNode(newCurrentNodeId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user