feat: init

This commit is contained in:
hh
2026-05-21 10:23:01 +02:00
commit 2b00fa44d5
13 changed files with 1189 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
import { App, Notice, PluginSettingTab, Setting } from "obsidian";
import { listAgents, BeaverApiError } from "./api";
import type BeaverPlugin from "./main";
export interface BeaverSettings {
baseUrl: string;
token: string;
}
export const DEFAULT_SETTINGS: BeaverSettings = {
baseUrl: "http://localhost:62993",
token: "",
};
export class BeaverSettingsTab extends PluginSettingTab {
plugin: BeaverPlugin;
constructor(app: App, plugin: BeaverPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName("Base URL")
.setDesc("Markdown frontend root, e.g. http://localhost:62993")
.addText((text) =>
text
.setPlaceholder("http://localhost:62993")
.setValue(this.plugin.settings.baseUrl)
.onChange(async (value) => {
this.plugin.settings.baseUrl = value.trim().replace(/\/+$/, "");
await this.plugin.saveSettings();
}),
);
new Setting(containerEl)
.setName("Bearer token")
.setDesc("Token with the `messages` scope.")
.addText((text) => {
text.inputEl.type = "password";
text
.setPlaceholder("paste token")
.setValue(this.plugin.settings.token)
.onChange(async (value) => {
this.plugin.settings.token = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName("Test connection")
.setDesc("Calls GET /agents and reports the count.")
.addButton((btn) =>
btn.setButtonText("Test").onClick(async () => {
try {
const agents = await listAgents(this.plugin.settings);
this.plugin.cacheAgents(agents);
new Notice(`Beaver: found ${agents.length} agents`);
} catch (err) {
const msg =
err instanceof BeaverApiError
? `${err.status}: ${err.message}`
: err instanceof Error
? err.message
: String(err);
new Notice(`Beaver: ${msg}`, 8000);
}
}),
);
}
}