Buf fix (emit new chat also for ChatView)

This commit is contained in:
dimitrievgs 2025-09-14 20:37:31 +03:00
parent 04a19b2508
commit dfe27f79ef
5 changed files with 255 additions and 314 deletions

70
main.js

File diff suppressed because one or more lines are too long

View File

@ -30,9 +30,7 @@ import { Handle, Position } from 'reactflow';
// Простой компонент для узла типа 'user' // Простой компонент для узла типа 'user'
// Это базовый пример. Ты можешь стилизовать его по своему усмотрению. // Это базовый пример. Ты можешь стилизовать его по своему усмотрению.
const UserNode: React.FC<any> = ({ data, isConnectable }) => { const UserNode: React.FC<any> = ({ data, isConnectable }) => {
return React.createElement('div', { return React.createElement(React.Fragment, null, // Используем React.Fragment для возврата нескольких элементов без лишнего div
className: 'react-flow__node-user'
},
React.createElement(Handle, { React.createElement(Handle, {
type: "source", type: "source",
position: Position.Bottom, position: Position.Bottom,
@ -49,9 +47,7 @@ const UserNode: React.FC<any> = ({ data, isConnectable }) => {
// Простой компонент для узла типа 'llm' // Простой компонент для узла типа 'llm'
const LLMNode: React.FC<any> = ({ data, isConnectable }) => { const LLMNode: React.FC<any> = ({ data, isConnectable }) => {
return React.createElement('div', { return React.createElement(React.Fragment, null,
className: 'react-flow__node-llm'
},
React.createElement(Handle, { React.createElement(Handle, {
type: "source", type: "source",
position: Position.Bottom, position: Position.Bottom,
@ -68,9 +64,7 @@ const LLMNode: React.FC<any> = ({ data, isConnectable }) => {
// Простой компонент для узла типа 'tool' // Простой компонент для узла типа 'tool'
const ToolNode: React.FC<any> = ({ data, isConnectable }) => { const ToolNode: React.FC<any> = ({ data, isConnectable }) => {
return React.createElement('div', { return React.createElement(React.Fragment, null,
className: 'react-flow__node-tool'
},
React.createElement(Handle, { React.createElement(Handle, {
type: "source", type: "source",
position: Position.Bottom, position: Position.Bottom,
@ -87,27 +81,7 @@ const ToolNode: React.FC<any> = ({ data, isConnectable }) => {
// Простой компонент для узла типа 'error' // Простой компонент для узла типа 'error'
const ErrorNode: React.FC<any> = ({ data, isConnectable }) => { const ErrorNode: React.FC<any> = ({ data, isConnectable }) => {
return React.createElement('div', { return React.createElement(React.Fragment, null,
className: 'react-flow__node-error'
},
React.createElement(Handle, {
type: "source",
position: Position.Bottom,
isConnectable: isConnectable,
}),
React.createElement(Handle, {
type: "target",
position: Position.Top,
isConnectable: isConnectable,
}),
data.label
);
};
const AssistantNode: React.FC<any> = ({ data, isConnectable }) => {
return React.createElement('div', {
className: 'react-flow__node-assistant' // Используем CSS класс для узла assistant
},
React.createElement(Handle, { React.createElement(Handle, {
type: "source", type: "source",
position: Position.Bottom, position: Position.Bottom,
@ -128,7 +102,6 @@ const nodeTypes = {
llm: LLMNode, llm: LLMNode,
tool: ToolNode, tool: ToolNode,
error: ErrorNode, error: ErrorNode,
assistant: AssistantNode,
// Если у тебя есть node.type === 'default', то можешь его тоже определить, // Если у тебя есть node.type === 'default', то можешь его тоже определить,
// либо использовать встроенный 'default' React Flow. // либо использовать встроенный 'default' React Flow.
}; };

View File

@ -3,12 +3,14 @@
* прошлых разговоров, начала новых чатов и удаления записей графов. * прошлых разговоров, начала новых чатов и удаления записей графов.
*/ */
import { EventBus } from '../utils/EventBus';
export class HistoryPanel { export class HistoryPanel {
container: HTMLElement; container: HTMLElement;
props: { props: {
graphs: any[]; graphs: any[];
onGraphSelect: (graphId: string) => void; onGraphSelect: (graphId: string) => void;
onNewChat: () => void; eventBus: EventBus;
}; };
graphs: any[]; graphs: any[];
newChatButton: HTMLButtonElement; newChatButton: HTMLButtonElement;
@ -22,7 +24,7 @@ export class HistoryPanel {
props: { props: {
graphs: any[]; graphs: any[];
onGraphSelect: (graphId: string) => void; onGraphSelect: (graphId: string) => void;
onNewChat: () => void; eventBus: EventBus;
} }
) { ) {
this.container = container; this.container = container;
@ -57,9 +59,7 @@ export class HistoryPanel {
setupEventListeners(): void { setupEventListeners(): void {
this.newChatButton.addEventListener('click', () => { this.newChatButton.addEventListener('click', () => {
if (this.props.onNewChat) { this.props.eventBus.emit('new-chat');
this.props.onNewChat();
}
}); });
this.deleteButton.addEventListener('click', () => { this.deleteButton.addEventListener('click', () => {

View File

@ -13,7 +13,7 @@ export const GRAPH_VIEW_TYPE = 'llm-agent-graph-view';
export class GraphView extends ItemView { export class GraphView extends ItemView {
plugin: LLMAgentPlugin; plugin: LLMAgentPlugin;
graphData: { nodes: any[], edges: any[] }; graphData: { nodes: any[]; edges: any[] };
currentNode: string | null; currentNode: string | null;
graphsList: any[]; graphsList: any[];
selectedGraphId: string | null; selectedGraphId: string | null;
@ -95,7 +95,7 @@ export class GraphView extends ItemView {
this.historyPanel = new HistoryPanel(this.historyContainer, { this.historyPanel = new HistoryPanel(this.historyContainer, {
graphs: this.graphsList, graphs: this.graphsList,
onGraphSelect: this.handleGraphSelect.bind(this), onGraphSelect: this.handleGraphSelect.bind(this),
onNewChat: this.handleNewChat.bind(this) eventBus: this.plugin.eventBus
}); });
// Инициализируем React Flow // Инициализируем React Flow
@ -142,7 +142,6 @@ export class GraphView extends ItemView {
const wrapper = this.graphContainer.createDiv(); const wrapper = this.graphContainer.createDiv();
wrapper.style.cssText = 'width: 100%; height: 100%;'; wrapper.style.cssText = 'width: 100%; height: 100%;';
if (!wrapper) { if (!wrapper) {
console.error('Не удалось создать wrapper для монтирования React Flow.'); console.error('Не удалось создать wrapper для монтирования React Flow.');
return; return;
@ -176,7 +175,7 @@ export class GraphView extends ItemView {
} }
} }
// ... (остальные методы API и Event Handlers без изменений) // ... (остальные методы API и Event Handlers без изменений)
// ----------------------------------------------- API Methods --------------------------------------------------------------- // ----------------------------------------------- API Methods ---------------------------------------------------------------
/** /**
* Загружает список всех графов с бэкенда. * Загружает список всех графов с бэкенда.
@ -223,7 +222,6 @@ export class GraphView extends ItemView {
// Перерендериваем граф // Перерендериваем граф
this.renderGraphPanel(); this.renderGraphPanel();
} catch (error) { } catch (error) {
console.error('Ошибка загрузки данных графа:', error); console.error('Ошибка загрузки данных графа:', error);
// Optionally: show a notice to the user // Optionally: show a notice to the user
@ -248,7 +246,7 @@ export class GraphView extends ItemView {
* Обновляет `graphData` и перерендеривает граф. * Обновляет `graphData` и перерендеривает граф.
* @param {{ graphData: { nodes: any[], edges: any[] }, currentNode: string | null }} data - Обновленные данные графа. * @param {{ graphData: { nodes: any[], edges: any[] }, currentNode: string | null }} data - Обновленные данные графа.
*/ */
handleGraphUpdate(data: { graphData: { nodes: any[], edges: any[] }, currentNode: string | null }): void { handleGraphUpdate(data: { graphData: { nodes: any[]; edges: any[] }; currentNode: string | null }): void {
this.graphData = data.graphData; this.graphData = data.graphData;
this.currentNode = data.currentNode; this.currentNode = data.currentNode;
this.renderGraphPanel(); this.renderGraphPanel();