Add NewIndependentChat global action button
This commit is contained in:
parent
c9f6941cd9
commit
fd6e7d12c5
|
|
@ -68,6 +68,7 @@ export class ChatView extends ItemView {
|
|||
this.plugin.eventBus.on('graph-selected', this.handleGraphSelected.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('start-new-independent-chat', this.handleStartNewIndependentChat.bind(this));
|
||||
}
|
||||
|
||||
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('regenerate-message', this.handleRegenerateMessage);
|
||||
this.plugin.eventBus.off('ws-node-type-changed', this.handleNodeTypeChanged);
|
||||
this.plugin.eventBus.off('start-new-independent-chat', this.handleStartNewIndependentChat);
|
||||
}
|
||||
|
||||
// ----------------------------------------------- API Methods ---------------------------------------------------------------
|
||||
|
|
@ -116,7 +118,6 @@ export class ChatView extends ItemView {
|
|||
type: msg.type || msg.role // Используем type, если есть, иначе role как fallback
|
||||
})) || [];
|
||||
|
||||
|
||||
// Уточнение, чтобы после выбора графа мы создавали узлы с не-пустым родителем
|
||||
if (this.chatHistory.length > 0) {
|
||||
// Устанавливаем 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 ---------------------------------------------------------------
|
||||
|
||||
handleNodeTypeChanged(data: { graphId: string; nodeId: string; nodeType: string }): void {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ export class GraphView extends ItemView {
|
|||
// Глобальные кнопки действий
|
||||
copySelectedButton: HTMLButtonElement | null = null;
|
||||
deleteSelectedButton: HTMLButtonElement | null = null;
|
||||
newIndependentChatActionButton: HTMLButtonElement | null = null;
|
||||
|
||||
constructor(leaf: WorkspaceLeaf, plugin: LLMAgentPlugin) {
|
||||
super(leaf);
|
||||
|
|
@ -224,6 +225,17 @@ export class GraphView extends ItemView {
|
|||
text: '🗑️'
|
||||
});
|
||||
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 --------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user