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 | 6x 6x 6x 850x 850x 850x 850x 850x 850x 850x 850x 850x 850x 690x 850x 119x 119x 5x 4x 850x 850x 850x 850x 677x 677x 677x 677x 2x 2x 850x 850x 850x 850x 119x 850x 10x 850x 893x 893x 6x 6x 850x 850x 850x 850x 1700x 1698x 1698x 2222x 2222x 1616x 850x 850x 850x 850x 107x 107x 98x 850x 63x 850x 122x 850x 18x 832x 89x 743x 690x 690x 13x 13x 12x 12x 13x 677x 71x 71x 67x 67x 71x 71x 67x 67x 606x 2x 2x 1x 1x 604x 2x 602x 602x 599x 599x | import { setIcon } from "obsidian";
import type { CatalogEntry, HardwareFit, ModelCardOptions } from "../types";
import { HARDWARE_FIT, HOSTED_SOURCES, KEY_STATUS, MODEL_COMPAT, MODEL_TASK } from "../types";
import { MESSAGES } from "../locales/en";
import { formatAbbreviatedCount } from "../utils";
const FIT_RAIL_CLASS: Record<HardwareFit, string> = {
[HARDWARE_FIT.FITS]: "is-fits",
[HARDWARE_FIT.TIGHT]: "is-tight",
[HARDWARE_FIT.WONT_RUN]: "is-wont-run",
};
const FIT_LABEL: Record<HardwareFit, string> = {
[HARDWARE_FIT.FITS]: MESSAGES.LABEL_FIT_FITS,
[HARDWARE_FIT.TIGHT]: MESSAGES.LABEL_FIT_TIGHT,
[HARDWARE_FIT.WONT_RUN]: MESSAGES.LABEL_FIT_WONT_RUN,
};
const TASK_TAG_CLS: Record<string, string> = {
[MODEL_TASK.CHAT]: "is-chat",
[MODEL_TASK.EMBEDDING]: "is-embed",
[MODEL_TASK.VISION]: "is-vision",
[MODEL_TASK.RERANK]: "is-rerank",
};
export function renderModelCard(container: HTMLElement, entry: CatalogEntry, options: ModelCardOptions): HTMLElement {
const card = container.createDiv({ cls: "lilbee-model-card" });
card.dataset.repo = entry.hf_repo;
if (options.isActive || options.isSelected) card.addClass("is-selected");
if (entry.fit && FIT_RAIL_CLASS[entry.fit]) card.addClass(FIT_RAIL_CLASS[entry.fit]);
if (entry.compat === MODEL_COMPAT.UNSUPPORTED) card.addClass("is-unsupported");
renderCardHead(card, entry, options);
renderCardTags(card, entry);
renderCardSpecs(card, entry);
renderCardStatus(card, entry, options);
if (options.showActions) {
renderCardActions(card, entry, options);
}
if (options.onClick) {
const handler = options.onClick;
card.addEventListener("click", (e: Event) => {
if ((e.target as HTMLElement)?.tagName === "BUTTON") return;
handler(entry);
});
}
return card;
}
function renderCardHead(card: HTMLElement, entry: CatalogEntry, options: ModelCardOptions): void {
const head = card.createDiv({ cls: "lilbee-model-card-head" });
head.createDiv({ cls: "lilbee-model-card-name", text: entry.display_name });
if (options.onInfo) {
const onInfo = options.onInfo;
const infoBtn = head.createEl("button", {
cls: "lilbee-model-card-info",
attr: {
type: "button",
"aria-label": MESSAGES.LABEL_MODEL_INFO_BTN,
title: MESSAGES.LABEL_MODEL_INFO_BTN,
},
});
setIcon(infoBtn, "info");
infoBtn.addEventListener("click", (e: Event) => {
e.stopPropagation();
onInfo(entry);
});
}
}
function renderCardTags(card: HTMLElement, entry: CatalogEntry): void {
const tags = card.createDiv({ cls: "lilbee-model-card-tags" });
const taskCls = TASK_TAG_CLS[entry.task] ?? "is-chat";
tags.createSpan({ text: entry.task, cls: `lilbee-tag lilbee-tag-task ${taskCls}` });
if (entry.featured) {
tags.createSpan({ text: MESSAGES.LABEL_PICK, cls: "lilbee-tag lilbee-tag-featured" });
}
if (HOSTED_SOURCES.has(entry.source)) {
tags.createSpan({ text: entry.provider ?? entry.source, cls: "lilbee-tag lilbee-tag-provider" });
}
renderCompatTag(tags, entry);
}
/**
* Render the compatibility badge for a model. Only models the server has
* confirmed it can't run get a badge (Unsupported). `unknown` compat just means
* the architecture wasn't probed — true for the curated "Our picks" (which
* carry no arch metadata) and for un-probed HF search hits — so it renders no
* badge, exactly like a supported model. Badging those "Unverified" was noise
* and made trusted featured models look broken.
*/
export function renderCompatTag(tags: HTMLElement, entry: CatalogEntry): void {
const architecture = entry.architecture ?? "";
if (entry.compat === MODEL_COMPAT.UNSUPPORTED) {
const tag = tags.createSpan({
text: MESSAGES.LABEL_COMPAT_UNSUPPORTED,
cls: "lilbee-tag lilbee-tag-compat is-unsupported",
});
tag.setAttribute("title", MESSAGES.TOOLTIP_COMPAT_UNSUPPORTED(architecture));
}
}
function renderCardSpecs(card: HTMLElement, entry: CatalogEntry): void {
const specs = card.createDiv({ cls: "lilbee-model-card-specs" });
specs.createEl("strong", { text: `${entry.size_gb} GB` });
appendSpecPart(specs, entry.quality_tier);
appendSpecPart(specs, entry.param_count ? `${entry.param_count} params` : "");
}
function appendSpecPart(parent: HTMLElement, text: string): void {
if (!text) return;
parent.createSpan({ cls: "lilbee-model-card-specs-sep" });
parent.createSpan({ text });
}
/** Installed rows missing their provider key are not usable, so they never read as installed. */
function isEffectivelyInstalled(entry: CatalogEntry): boolean {
const hostedMissingKey = HOSTED_SOURCES.has(entry.source) && entry.key_status === KEY_STATUS.MISSING_KEY;
return entry.installed && !hostedMissingKey;
}
/** Hosted models live on the provider, so only a usable native install sits on disk. */
function readsAsLocalInstall(entry: CatalogEntry): boolean {
return isEffectivelyInstalled(entry) && !HOSTED_SOURCES.has(entry.source);
}
function renderCardStatus(card: HTMLElement, entry: CatalogEntry, options: ModelCardOptions): void {
const status = card.createDiv({ cls: "lilbee-model-card-status" });
const { tone, label } = statusTone(entry, options);
status.createSpan({ cls: `lilbee-model-card-status-dot ${tone}`.trim() });
if (label) {
const labelEl = status.createSpan({
text: label,
cls: `lilbee-model-card-status-label ${tone}`,
});
if (readsAsLocalInstall(entry)) {
labelEl.setAttribute("title", MESSAGES.TOOLTIP_MODEL_INSTALLED_SHARED);
}
}
if (entry.downloads > 0) {
status.createSpan({
text: MESSAGES.LABEL_DOWNLOADS_COUNT(formatAbbreviatedCount(entry.downloads)),
cls: "lilbee-model-card-downloads",
});
}
if (entry.fit && FIT_LABEL[entry.fit]) {
status.createSpan({
text: FIT_LABEL[entry.fit],
cls: "lilbee-model-card-fit-text",
});
}
}
type StatusTone = "is-active" | "is-installed" | "";
function statusTone(entry: CatalogEntry, options: ModelCardOptions): { tone: StatusTone; label: string } {
if (options.isActive) {
return { tone: "is-active", label: MESSAGES.LABEL_ACTIVE };
}
if (readsAsLocalInstall(entry)) {
return { tone: "is-installed", label: MESSAGES.LABEL_INSTALLED };
}
// The bare dot already carries the neutral tone, so an unlabelled state needs no modifier.
return { tone: "", label: "" };
}
function renderCardActions(card: HTMLElement, entry: CatalogEntry, options: ModelCardOptions): void {
const actions = card.createDiv({ cls: "lilbee-model-card-actions" });
if (options.isActive) {
const btn = actions.createEl("button", {
text: MESSAGES.LABEL_ACTIVE,
cls: "lilbee-btn lilbee-btn-active",
attr: { disabled: "true" },
});
if (options.onUse) {
const handler = options.onUse;
btn.addEventListener("click", () => handler(entry, btn));
}
return;
}
// Only a model on disk can be removed, so a hosted one gets Use without Remove.
if (readsAsLocalInstall(entry)) {
const useBtn = actions.createEl("button", {
text: MESSAGES.BUTTON_USE,
cls: "lilbee-btn lilbee-btn-primary lilbee-catalog-use",
});
if (options.onUse) {
const handler = options.onUse;
useBtn.addEventListener("click", () => handler(entry, useBtn));
}
const removeBtn = actions.createEl("button", {
text: MESSAGES.BUTTON_REMOVE,
cls: "lilbee-btn lilbee-btn-danger lilbee-catalog-remove",
});
if (options.onRemove) {
const handler = options.onRemove;
removeBtn.addEventListener("click", () => handler(entry, removeBtn));
}
} else if (isEffectivelyInstalled(entry)) {
const useBtn = actions.createEl("button", {
text: MESSAGES.BUTTON_USE,
cls: "lilbee-btn lilbee-btn-primary lilbee-catalog-use",
});
if (options.onUse) {
const handler = options.onUse;
useBtn.addEventListener("click", () => handler(entry, useBtn));
}
} else if (entry.compat === MODEL_COMPAT.UNSUPPORTED) {
// Unsupported models can't run on this server — render the pull action
// gated (disabled, secondary look) rather than letting a download that
// can never load go through.
actions.createEl("button", {
text: MESSAGES.BUTTON_PULL,
cls: "lilbee-btn lilbee-catalog-pull is-gated",
attr: { disabled: "true", title: MESSAGES.TOOLTIP_PULL_UNSUPPORTED },
});
} else {
const pullBtn = actions.createEl("button", {
text: MESSAGES.BUTTON_PULL,
cls: "lilbee-btn lilbee-btn-primary lilbee-catalog-pull",
});
if (options.onPull) {
const handler = options.onPull;
pullBtn.addEventListener("click", () => handler(entry, pullBtn));
}
}
}
|