// ----------------------------------------------- Obsidian Imports ---------------------------------------------------------- import { App, Modal, Setting } from 'obsidian'; // ----------------------------------------------- Interfaces ---------------------------------------------------------------- /** * Интерфейс для свойств, передаваемых в модальное окно GraphSettingsModal. */ interface GraphSettingsModalProps { app: App; graphId: string; graphTitle: string; initialCustomSystemPrompt: string | null; onSave: (graphId: string, customSystemPrompt: string | null) => Promise; } // ----------------------------------------------- GraphSettingsModal -------------------------------------------------------- /** * Модальное окно для настройки специфического системного промпта для конкретного графа. */ export class GraphSettingsModal extends Modal { private graphId: string; private graphTitle: string; private customSystemPrompt: string | null; private initialCustomSystemPrompt: string | null; private onSave: (graphId: string, customSystemPrompt: string | null) => Promise; constructor(app: App, props: GraphSettingsModalProps) { super(app); this.graphId = props.graphId; this.graphTitle = props.graphTitle; this.customSystemPrompt = props.initialCustomSystemPrompt; this.initialCustomSystemPrompt = props.initialCustomSystemPrompt; this.onSave = props.onSave; this.titleEl.setText(`Настройки графа: ${this.graphTitle}`); this.modalEl.addClass('llm-agent-graph-settings-modal'); } onOpen(): void { const { contentEl } = this; contentEl.empty(); // ----------------------------------------------- System Prompt Setting ------------------------------------------------ new Setting(contentEl) .setName('Пользовательский системный промпт') .setDesc('Этот промпт будет использоваться для данного графа вместо глобального системного промпта. Оставьте пустым, чтобы использовать глобальный промпт.') .addTextArea(textArea => { textArea .setPlaceholder('Введите пользовательский системный промпт для этого графа...') .setValue(this.customSystemPrompt || '') .onChange(value => { this.customSystemPrompt = value.trim() === '' ? null : value.trim(); }); textArea.inputEl.rows = 6; textArea.inputEl.style.minWidth = '400px'; textArea.inputEl.style.width = '100%'; }); // ----------------------------------------------- Action Buttons ------------------------------------------------------- new Setting(contentEl) .addButton(button => { button .setButtonText('Сохранить') .setCta() .onClick(async () => { await this.onSave(this.graphId, this.customSystemPrompt); this.close(); }); }) .addButton(button => { button .setButtonText('Сбросить на глобальный') .setClass('mod-warning') .onClick(async () => { await this.onSave(this.graphId, null); // Отправляем null для сброса this.close(); }); }) .addButton(button => { button .setButtonText('Отмена') .onClick(() => { this.close(); }); }); } onClose(): void { const { contentEl } = this; contentEl.empty(); } }