Add NewIndependentChat global action button

This commit is contained in:
dimitrievgs 2025-10-15 00:18:01 +03:00
parent c9f6941cd9
commit fd6e7d12c5
3 changed files with 54 additions and 2 deletions

26
main.js

File diff suppressed because one or more lines are too long

View File

@ -68,6 +68,7 @@ export class ChatView extends ItemView {
this.plugin.eventBus.on('graph-selected', this.handleGraphSelected.bind(this)); this.plugin.eventBus.on('graph-selected', this.handleGraphSelected.bind(this));
this.plugin.eventBus.on('regenerate-message', this.handleRegenerateMessage.bind(this)); // Добавлено this.plugin.eventBus.on('regenerate-message', this.handleRegenerateMessage.bind(this)); // Добавлено
this.plugin.eventBus.on('ws-node-type-changed', this.handleNodeTypeChanged.bind(this)); this.plugin.eventBus.on('ws-node-type-changed', this.handleNodeTypeChanged.bind(this));
this.plugin.eventBus.on('start-new-independent-chat', this.handleStartNewIndependentChat.bind(this));
} }
async onClose(): Promise<void> { async onClose(): Promise<void> {
@ -80,6 +81,7 @@ export class ChatView extends ItemView {
this.plugin.eventBus.off('graph-selected', this.handleGraphSelected); this.plugin.eventBus.off('graph-selected', this.handleGraphSelected);
this.plugin.eventBus.off('regenerate-message', this.handleRegenerateMessage); this.plugin.eventBus.off('regenerate-message', this.handleRegenerateMessage);
this.plugin.eventBus.off('ws-node-type-changed', this.handleNodeTypeChanged); this.plugin.eventBus.off('ws-node-type-changed', this.handleNodeTypeChanged);
this.plugin.eventBus.off('start-new-independent-chat', this.handleStartNewIndependentChat);
} }
// ----------------------------------------------- API Methods --------------------------------------------------------------- // ----------------------------------------------- API Methods ---------------------------------------------------------------
@ -116,7 +118,6 @@ export class ChatView extends ItemView {
type: msg.type || msg.role // Используем type, если есть, иначе role как fallback type: msg.type || msg.role // Используем type, если есть, иначе role как fallback
})) || []; })) || [];
// Уточнение, чтобы после выбора графа мы создавали узлы с не-пустым родителем // Уточнение, чтобы после выбора графа мы создавали узлы с не-пустым родителем
if (this.chatHistory.length > 0) { if (this.chatHistory.length > 0) {
// Устанавливаем currentNode на ID последнего сообщения в загруженной истории // Устанавливаем currentNode на ID последнего сообщения в загруженной истории
@ -433,6 +434,21 @@ export class ChatView extends ItemView {
} }
} }
/**
* Обрабатывает событие начала нового независимого чата.
* Сбрасывает текущее состояние ChatView, но не влияет на GraphView.
*/
async handleStartNewIndependentChat(): Promise<void> {
this.chatHistory = [];
this.currentNode = null;
// Оставляем this.selectedGraphId без изменений
if (this.chatPanel) {
await this.chatPanel.updateHistory(this.chatHistory);
}
// Опционально: можно уведомить пользователя о начале нового чата
new Notice('Начат новый чат. Текущий граф не изменен.', 2000);
}
// ----------------------------------------------- WebSocket Event Handlers --------------------------------------------------------------- // ----------------------------------------------- WebSocket Event Handlers ---------------------------------------------------------------
handleNodeTypeChanged(data: { graphId: string; nodeId: string; nodeType: string }): void { handleNodeTypeChanged(data: { graphId: string; nodeId: string; nodeType: string }): void {

View File

@ -37,6 +37,7 @@ export class GraphView extends ItemView {
// Глобальные кнопки действий // Глобальные кнопки действий
copySelectedButton: HTMLButtonElement | null = null; copySelectedButton: HTMLButtonElement | null = null;
deleteSelectedButton: HTMLButtonElement | null = null; deleteSelectedButton: HTMLButtonElement | null = null;
newIndependentChatActionButton: HTMLButtonElement | null = null;
constructor(leaf: WorkspaceLeaf, plugin: LLMAgentPlugin) { constructor(leaf: WorkspaceLeaf, plugin: LLMAgentPlugin) {
super(leaf); super(leaf);
@ -224,6 +225,17 @@ export class GraphView extends ItemView {
text: '🗑️' text: '🗑️'
}); });
this.deleteSelectedButton.addEventListener('click', this.handleDeleteSelectedNodes.bind(this)); this.deleteSelectedButton.addEventListener('click', this.handleDeleteSelectedNodes.bind(this));
// Кнопка "Новый чат" (сохраняя текущий граф)
this.newIndependentChatActionButton = toolbar.createEl('button', {
cls: 'global-action-button',
attr: { 'aria-label': 'Новый независимый чат', 'data-tooltip': 'Начать новую беседу, формируя отдельный, независимый подграф' },
text: '✨' // Или 'Новый чат'
});
this.newIndependentChatActionButton.addEventListener('click', () => {
// Эмитируем новое событие, которое будет слушать ТОЛЬКО ChatView
this.plugin.eventBus.emit('start-new-independent-chat');
});
} }
// ----------------------------------------------- Graph Panel Integration -------------------------------------------------- // ----------------------------------------------- Graph Panel Integration --------------------------------------------------