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