feat(activity,api,settings): activity panel v0 over conversation events sse

This commit is contained in:
hh
2026-08-28 17:01:02 +02:00
parent 755a475f27
commit a1bf4db905
12 changed files with 1179 additions and 153 deletions
+50 -10
View File
@@ -1,15 +1,17 @@
import { App, Notice, PluginSettingTab, Setting } from "obsidian";
import { listAgents, BeaverApiError } from "./api";
import { BeaverApiError, apiBase, listAgents, listApiAgents } from "./api";
import type BeaverPlugin from "./main";
export interface BeaverSettings {
baseUrl: string;
apiBaseUrl: string;
token: string;
vaultSubpath: string;
}
export const DEFAULT_SETTINGS: BeaverSettings = {
baseUrl: "http://localhost:62993",
apiBaseUrl: "",
token: "",
vaultSubpath: "",
};
@@ -18,6 +20,14 @@ export function normalizeSubpath(raw: string): string {
return raw.trim().replace(/^\/+|\/+$/g, "");
}
function errorText(err: unknown): string {
return err instanceof BeaverApiError
? `${err.status}: ${err.message}`
: err instanceof Error
? err.message
: String(err);
}
export class BeaverSettingsTab extends PluginSettingTab {
plugin: BeaverPlugin;
@@ -43,9 +53,29 @@ export class BeaverSettingsTab extends PluginSettingTab {
}),
);
new Setting(containerEl)
.setName("API origin")
.setDesc(
"Origin of the conversations API; `/api/…` is appended to it. " +
"Leave empty to derive from Base URL (`…/md` → `…`, port 62993 → 62994). " +
"Example: https://beaver.example.com or http://localhost:62994.",
)
.addText((text) =>
text
.setPlaceholder("(derived)")
.setValue(this.plugin.settings.apiBaseUrl)
.onChange(async (value) => {
this.plugin.settings.apiBaseUrl = value.trim().replace(/\/+$/, "");
await this.plugin.saveSettings();
}),
);
new Setting(containerEl)
.setName("Bearer token")
.setDesc("Token with the `messages` scope.")
.setDesc(
"Token with the `messages` scope for sending and the `api` scope " +
"for the activity panel (or a `*` bootstrap token).",
)
.addText((text) => {
text.inputEl.type = "password";
text
@@ -75,7 +105,7 @@ export class BeaverSettingsTab extends PluginSettingTab {
new Setting(containerEl)
.setName("Test connection")
.setDesc("Calls GET /agents and reports the count.")
.setDesc("Calls GET /agents on the markdown frontend and reports the count.")
.addButton((btn) =>
btn.setButtonText("Test").onClick(async () => {
try {
@@ -83,13 +113,23 @@ export class BeaverSettingsTab extends PluginSettingTab {
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);
new Notice(`Beaver: ${errorText(err)}`, 8000);
}
}),
);
new Setting(containerEl)
.setName("Test API")
.setDesc("Calls GET /api/agents on the API origin (needs the `api` scope).")
.addButton((btn) =>
btn.setButtonText("Test").onClick(async () => {
try {
const agents = await listApiAgents(this.plugin.settings);
new Notice(
`Beaver: API at ${apiBase(this.plugin.settings)} - ${agents.length} agents`,
);
} catch (err) {
new Notice(`Beaver: ${errorText(err)}`, 8000);
}
}),
);