summaryrefslogtreecommitdiffhomepage
path: root/src/tool-modal.ts
blob: 6a45ae0947c7267e947fa19e7da2c02131e9abf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Modal, Setting } from "obsidian";
import type AIPulse from "./main";
import { TOOL_REGISTRY } from "./tools";

export class ToolModal extends Modal {
	private plugin: AIPulse;

	constructor(plugin: AIPulse) {
		super(plugin.app);
		this.plugin = plugin;
	}

	onOpen(): void {
		const { contentEl } = this;
		contentEl.empty();
		contentEl.addClass("ai-pulse-tool-modal");

		this.setTitle("AI Tools");

		contentEl.createEl("p", {
			text: "Enable tools to give the AI access to your vault. Changes take effect on the next message.",
			cls: "ai-pulse-tool-modal-desc",
		});

		for (const tool of TOOL_REGISTRY) {
			// Batch tools auto-enable with their parent — no separate toggle
			if (tool.batchOf !== undefined) continue;

			new Setting(contentEl)
				.setName(tool.label)
				.setDesc(tool.description)
				.addToggle((toggle) => {
					const current = this.plugin.settings.enabledTools[tool.id] ?? false;
					toggle.setValue(current);
					toggle.onChange(async (value) => {
						this.plugin.settings.enabledTools[tool.id] = value;
						await this.plugin.saveSettings();
					});
				});
		}
	}

	onClose(): void {
		this.contentEl.empty();
	}
}