Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 41x 2x 2x 2x 39x 39x 39x 39x 39x 39x 1x 1x 39x 39x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 2x 1x 39x 39x 39x 39x 39x 39x 39x 39x 40x 5x 40x 39x 39x 5x 5x 5x 1x 1x 1x 4x 4x 1x 1x 3x 3x 3x 9x 9x 18x 15x 4x 4x 4x 4x 1x 39x 39x 3x 3x 3x 4x 4x 4x 4x 3x 39x 1x 3x 39x 39x 39x 39x 39x 39x 38x 39x 39x 39x 38x 38x 37x 2x 39x 39x 38x 38x 1x 39x 39x 2x 2x 2x 2x 2x 39x 39x 39x 89x 89x 89x 7x 7x 7x 7x 39x 39x 39x 39x 1x 1x 38x 38x 40x 39x 9x 8x 38x 38x | import { App, Modal, Notice, TFile } from "obsidian";
import type LilbeePlugin from "../main";
import { MANAGED_DOCS_PREFIX, type ModelShowResponse, type StatusResponse } from "../types";
import { DocumentList } from "../components/document-list";
import { MESSAGES } from "../locales/en";
import { bindEscapeToClose, noticeForResultError, ocrModeLabel, revealInFileExplorer } from "../utils";
import { modelShowRows } from "../utils/model-show-rows";
import { remedyForWarning } from "../utils/warning-remedies";
export class StatusModal extends Modal {
private plugin: LilbeePlugin;
constructor(app: App, plugin: LilbeePlugin) {
super(app);
this.plugin = plugin;
bindEscapeToClose(this);
}
onOpen(): void {
const { contentEl } = this;
contentEl.empty();
contentEl.addClass("lilbee-status-modal");
contentEl.createEl("h2", { text: MESSAGES.TITLE_STATUS });
void this.loadStatus(contentEl);
}
private async loadStatus(contentEl: HTMLElement): Promise<void> {
try {
const statusResult = await this.plugin.api.status();
if (statusResult.isErr()) {
new Notice(noticeForResultError(statusResult.error, MESSAGES.ERROR_COULD_NOT_CONNECT));
this.close();
return;
}
const status = statusResult.value;
this.renderWarnings(contentEl);
this.renderDocuments(contentEl, status);
this.renderHeldOut(contentEl, status);
await this.renderModels(contentEl, status);
await this.renderWiki(contentEl);
} catch {
new Notice(MESSAGES.ERROR_COULD_NOT_CONNECT);
this.close();
}
}
/** Degradations the server is reporting. These answer normally and look
* healthy, so the status modal is where an operator checking "why are the
* answers off" can see them. */
private renderWarnings(container: HTMLElement): void {
const warnings = this.plugin.healthWarnings;
if (warnings.length === 0) return;
const section = container.createEl("details", { attr: { open: "" } });
section.createEl("summary", { text: MESSAGES.LABEL_STATUS_WARNINGS });
for (const w of warnings) {
const row = section.createDiv({ cls: "lilbee-status-warning" });
row.createDiv({ cls: "lilbee-status-warning-message", text: w.message });
const remedy = remedyForWarning(w.code, this.plugin);
if (remedy) {
row.createDiv({ cls: "lilbee-status-warning-remedy", text: remedy.text });
const btn = row.createEl("button", {
text: MESSAGES.BUTTON_REBUILD_INDEX,
cls: "lilbee-status-warning-action",
});
btn.addEventListener("click", remedy.action);
} else if (w.remedy) {
row.createDiv({ cls: "lilbee-status-warning-remedy", text: w.remedy });
}
}
}
/** The first document page loads in the background: a slow documents call must not delay the sections below. */
private renderDocuments(container: HTMLElement, status: StatusResponse): void {
const section = container.createEl("details", { attr: { open: "" } });
section.createEl("summary", { text: MESSAGES.LABEL_STATUS_DOCUMENTS });
const table = section.createEl("table", { cls: "lilbee-status-table" });
this.addRow(table, MESSAGES.LABEL_STATUS_DOCUMENTS, String(status.document_count));
this.addRow(table, MESSAGES.LABEL_STATUS_CHUNKS, String(status.total_chunks));
const listEl = section.createDiv({ cls: "lilbee-status-documents" });
const summary = section.createDiv({ cls: "lilbee-status-documents-summary" });
const list = new DocumentList(
listEl,
(limit, offset) => this.plugin.api.listDocuments(undefined, limit, offset),
{
onOpen: (doc) => this.openDocument(doc.filename),
onPage: (loaded) => summary.setText(documentSummaryText(list, loaded)),
},
);
list.bindScroll(listEl);
void list.loadMore();
}
/** Opens the note behind an indexed document, which lives under the managed folder when content is stored in the vault. */
private openDocument(filename: string): void {
const { workspace } = this.app;
const file = this.vaultFile(filename);
if (file) {
this.close();
void workspace.getLeaf(false).openFile(file);
return;
}
// A member of an archive is named archive/member; the archive is the vault file.
// Opening it would hand the archive to the OS, so select it in the explorer instead.
const archive = this.enclosingArchive(filename);
if (!archive) {
new Notice(MESSAGES.NOTICE_DOCUMENT_NOT_IN_VAULT(filename));
return;
}
new Notice(MESSAGES.NOTICE_DOCUMENT_IN_ARCHIVE(filename, archive.file.name));
this.close();
revealInFileExplorer(this.app, archive.file);
}
private vaultFile(sourceName: string): TFile | null {
const { vault } = this.app;
return (
[`${MANAGED_DOCS_PREFIX}${sourceName}`, sourceName]
.map((path) => vault.getAbstractFileByPath(path))
.find((entry): entry is TFile => entry instanceof TFile) ?? null
);
}
private enclosingArchive(sourceName: string): { file: TFile } | null {
const segments = sourceName.split("/");
for (let end = segments.length - 1; end > 0; end -= 1) {
const file = this.vaultFile(segments.slice(0, end).join("/"));
if (file) return { file };
}
return null;
}
private renderHeldOut(container: HTMLElement, status: StatusResponse): void {
const skipped = status.skipped ?? [];
if (skipped.length === 0) return;
const section = container.createEl("details", { cls: "lilbee-status-held-out", attr: { open: "" } });
section.createEl("summary", { text: MESSAGES.LABEL_STATUS_HELD_OUT });
for (const source of skipped) {
const row = section.createDiv({ cls: "lilbee-status-held-out-row" });
const nameEl = row.createDiv({ cls: "lilbee-status-held-out-name", text: source.filename });
nameEl.setAttribute("title", source.filename);
row.createDiv({ cls: "lilbee-status-held-out-reason", text: source.reason });
}
const hidden = (status.skipped_total ?? skipped.length) - skipped.length;
if (hidden > 0) {
section.createDiv({
cls: "lilbee-status-held-out-more",
text: MESSAGES.LABEL_STATUS_HELD_OUT_MORE(hidden),
});
}
section.createDiv({ cls: "lilbee-status-held-out-retry", text: MESSAGES.LABEL_STATUS_HELD_OUT_RETRY });
}
private async renderModels(container: HTMLElement, status: StatusResponse): Promise<void> {
const section = container.createEl("details", { attr: { open: "" } });
section.createEl("summary", { text: MESSAGES.LABEL_MODELS });
const table = section.createEl("table", { cls: "lilbee-status-table" });
const chatModel = status.config.chat_model;
this.addModelRow(table, MESSAGES.LABEL_STATUS_CHAT_MODEL, chatModel);
if (chatModel) {
await this.renderModelDetails(table, chatModel);
}
await this.renderServedContext(table);
const ocrMode = status.config.ocr;
if (ocrMode !== undefined) this.addOcrRow(table, ocrModeLabel(ocrMode), status.ocr_note);
}
private async renderModelDetails(table: HTMLTableElement, model: string): Promise<void> {
try {
const info: ModelShowResponse = await this.plugin.api.showModel(model);
for (const row of modelShowRows(info)) {
this.addRow(table, row.label, row.value);
}
} catch {
// Model details are optional here.
}
}
/** Context window the chat fleet actually serves per slot; absent on older servers or while cold. */
private async renderServedContext(table: HTMLTableElement): Promise<void> {
const health = await this.plugin.api.health();
if (health.isErr()) return;
const ctx = health.value.chat_ctx;
if (ctx === null || ctx === undefined) return;
this.addRow(table, MESSAGES.LABEL_STATUS_SERVED_CONTEXT, String(ctx));
}
/** Wiki counters come from /api/wiki/status; /api/status carries none. */
private async renderWiki(container: HTMLElement): Promise<void> {
const result = await this.plugin.api.wikiStatus();
if (result.isErr()) return;
const wiki = result.value;
const section = container.createEl("details", { attr: { open: "" } });
section.createEl("summary", { text: MESSAGES.LABEL_STATUS_WIKI });
const table = section.createEl("table", { cls: "lilbee-status-table" });
this.addRow(
table,
MESSAGES.LABEL_STATUS_WIKI,
wiki.wiki_enabled ? MESSAGES.LABEL_STATUS_ENABLED : MESSAGES.LABEL_STATUS_DISABLED,
);
this.addRow(table, MESSAGES.LABEL_STATUS_WIKI_PAGES, String(wiki.pages));
this.addRow(table, MESSAGES.LABEL_STATUS_WIKI_DRAFTS, String(wiki.drafts));
this.addRow(
table,
MESSAGES.LABEL_STATUS_WIKI_LINT,
MESSAGES.VALUE_STATUS_WIKI_LINT(wiki.lint_errors, wiki.lint_warnings),
);
}
private addRow(table: HTMLTableElement, label: string, value: string): void {
const row = table.createEl("tr");
row.createEl("td", { text: label, cls: "lilbee-status-label" });
row.createEl("td", { text: value, cls: "lilbee-status-value" });
}
/** The OCR mode, with the server's note on what happens to scanned pages beneath it. */
private addOcrRow(table: HTMLTableElement, mode: string, note: string | undefined): void {
const row = table.createEl("tr");
row.createEl("td", { text: MESSAGES.LABEL_STATUS_OCR, cls: "lilbee-status-label" });
const cell = row.createEl("td", { text: mode, cls: "lilbee-status-value" });
if (note) cell.createDiv({ cls: "lilbee-status-detail", text: note });
}
private addModelRow(table: HTMLTableElement, label: string, model: string): void {
const row = table.createEl("tr");
row.createEl("td", { text: label, cls: "lilbee-status-label" });
const cell = row.createEl("td", { cls: "lilbee-status-value" });
if (!model) {
cell.setText(MESSAGES.LABEL_STATUS_NONE);
return;
}
cell.setText(shortModelLabel(model));
cell.setAttribute("title", model);
}
}
function documentSummaryText(list: DocumentList, loaded: boolean): string {
if (!loaded) return MESSAGES.LABEL_STATUS_DOCUMENTS_FAILED;
if (list.loaded === 0) return MESSAGES.LABEL_STATUS_DOCUMENTS_EMPTY;
if (list.hasMore) return MESSAGES.LABEL_STATUS_DOCUMENTS_SHOWING(list.loaded, list.total);
return MESSAGES.LABEL_STATUS_DOCUMENTS_COMPLETE(list.total);
}
function shortModelLabel(model: string): string {
const slash = model.lastIndexOf("/");
return slash === -1 ? model : model.slice(slash + 1);
}
|