From d4482116dd7052119d60e7bf07385a4c569ae87b Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Sun, 30 Aug 2026 08:38:17 +0200 Subject: [PATCH] ui : mark llama-app-reusable code with a LLAMA-APP-REUSE tag Tag the pure-logic files and functions that llama.app (llama-pages) can reuse as-is: model id parsing, HF name and quant conventions, hardware compatibility estimation, chat-template capability detectors, and the HF formatting and metadata helpers. App-specific code is left unmarked. The LLAMA-APP-REUSE prefix makes the reusable surface greppable and distinguishable from regular comments: grep -rn LLAMA-APP-REUSE. Assisted-by: pi --- tools/ui/src/lib/constants/huggingface.constants.ts | 1 + tools/ui/src/lib/constants/model-id.constants.ts | 1 + tools/ui/src/lib/enums/huggingface.enums.ts | 1 + tools/ui/src/lib/enums/model.enums.ts | 1 + tools/ui/src/lib/enums/server.enums.ts | 8 ++++---- tools/ui/src/lib/services/huggingface.service.ts | 11 +++++++++++ tools/ui/src/lib/services/models.service.ts | 2 ++ tools/ui/src/lib/types/huggingface.d.ts | 1 + tools/ui/src/lib/types/models.d.ts | 1 + .../src/lib/utils/chat-template-thinking-detector.ts | 1 + tools/ui/src/lib/utils/chat-template-tool-detector.ts | 1 + tools/ui/src/lib/utils/model-compatibility.ts | 1 + tools/ui/src/lib/utils/model-names.ts | 1 + 13 files changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/ui/src/lib/constants/huggingface.constants.ts b/tools/ui/src/lib/constants/huggingface.constants.ts index b742c0a86e..7ac956ee9e 100644 --- a/tools/ui/src/lib/constants/huggingface.constants.ts +++ b/tools/ui/src/lib/constants/huggingface.constants.ts @@ -4,6 +4,7 @@ * URLs, parsing regexes and formatting units for the HuggingFaceService. * Reference: https://huggingface.co/docs/huggingface_hub/package_reference/hf_api */ +// LLAMA-APP-REUSE: HF Hub endpoints and filename conventions // API endpoints diff --git a/tools/ui/src/lib/constants/model-id.constants.ts b/tools/ui/src/lib/constants/model-id.constants.ts index 9fe87d1cc4..73a2c5fde4 100644 --- a/tools/ui/src/lib/constants/model-id.constants.ts +++ b/tools/ui/src/lib/constants/model-id.constants.ts @@ -1,6 +1,7 @@ /** * Parsing of `org/ModelName[-tag][:quant]` style model IDs. */ +// LLAMA-APP-REUSE: model id grammar: sidecars, quants, segments import { ModelAuxSidecar, ModelDraftSidecar } from '$lib/enums'; diff --git a/tools/ui/src/lib/enums/huggingface.enums.ts b/tools/ui/src/lib/enums/huggingface.enums.ts index 5518e2312e..61dede48aa 100644 --- a/tools/ui/src/lib/enums/huggingface.enums.ts +++ b/tools/ui/src/lib/enums/huggingface.enums.ts @@ -5,6 +5,7 @@ * (https://huggingface.co/docs/huggingface_hub/package_reference/hf_api) * so they can be sent and compared directly. */ +// LLAMA-APP-REUSE: HF sort and sidecar-form enums /** Sort field for /api/models search queries. */ export enum HfModelSort { diff --git a/tools/ui/src/lib/enums/model.enums.ts b/tools/ui/src/lib/enums/model.enums.ts index ea799b6977..b0b7906f08 100644 --- a/tools/ui/src/lib/enums/model.enums.ts +++ b/tools/ui/src/lib/enums/model.enums.ts @@ -1,3 +1,4 @@ +// LLAMA-APP-REUSE: model modality / capability / sidecar enums export enum ModelModality { AUDIO = 'AUDIO', TEXT = 'TEXT', diff --git a/tools/ui/src/lib/enums/server.enums.ts b/tools/ui/src/lib/enums/server.enums.ts index a8ce93cba7..b558b51236 100644 --- a/tools/ui/src/lib/enums/server.enums.ts +++ b/tools/ui/src/lib/enums/server.enums.ts @@ -13,14 +13,14 @@ export enum ServerRole { * Used as the `value` field in the status object from /models endpoint */ export enum ServerModelStatus { + DOWNLOAD_FAILED = 'download_failed', + DOWNLOAD_FINISHED = 'download_finished', + DOWNLOADED = 'downloaded', + DOWNLOADING = 'downloading', FAILED = 'failed', LOADED = 'loaded', LOADING = 'loading', SLEEPING = 'sleeping', - DOWNLOADED = 'downloaded', - DOWNLOADING = 'downloading', - DOWNLOAD_FAILED = 'download_failed', - DOWNLOAD_FINISHED = 'download_finished', UNLOADED = 'unloaded' } diff --git a/tools/ui/src/lib/services/huggingface.service.ts b/tools/ui/src/lib/services/huggingface.service.ts index ee4ae94b20..3890b8947a 100644 --- a/tools/ui/src/lib/services/huggingface.service.ts +++ b/tools/ui/src/lib/services/huggingface.service.ts @@ -126,6 +126,7 @@ export class HuggingFaceService { * quant. Non-sharded files pass through unchanged. Downloads are tag-based * (`repo:quant`), so the first shard is enough to represent the set. */ + // LLAMA-APP-REUSE: shard-set collapsing static collapseGgufShards(siblings: HfModelSibling[]): HfModelSibling[] { const sizeByPath = new Map(siblings.map((f) => [f.path, f.size ?? 0])); const result: HfModelSibling[] = []; @@ -175,6 +176,7 @@ export class HuggingFaceService { * (e.g. `*-BF16.gguf`); `sidecar` is `null` if no sidecar flag is present. * Returns `null` only when the filename doesn't end in `.gguf`. */ + // LLAMA-APP-REUSE: quant + sidecar filename parser static extractQuantMeta(filename: string): { quant: string | null; sidecar: ModelSidecar | null; @@ -231,6 +233,7 @@ export class HuggingFaceService { /** * Filter raw siblings by file extension and sort by size descending. */ + // LLAMA-APP-REUSE: sibling filtering static filterByExtension(siblings: HfModelSibling[], ext: string): HfModelSibling[] { return siblings .filter((f) => f.path.toLowerCase().endsWith(ext.toLowerCase()) && (f.size ?? 0) > 0) @@ -240,6 +243,7 @@ export class HuggingFaceService { /** * Format model downloads count with K/M/B suffix */ + // LLAMA-APP-REUSE: compact download counts static formatDownloads(downloads: number): string { if (downloads >= MEGABYTE) { return `${(downloads / MEGABYTE).toFixed(1)}${MEGA_LABEL}`; @@ -255,6 +259,7 @@ export class HuggingFaceService { /** * Format file size in bytes to human-readable string */ + // LLAMA-APP-REUSE: human-readable file sizes static formatFileSize(bytes: number): string { if (bytes >= GIGABYTE) { return `${(bytes / GIGABYTE).toFixed(1)} ${GIGABYTE_LABEL}`; @@ -274,6 +279,7 @@ export class HuggingFaceService { /** * Format likes count with K suffix if applicable */ + // LLAMA-APP-REUSE: compact like counts static formatLikes(likes: number): string { if (likes >= KILOBYTE) { return `${(likes / KILOBYTE).toFixed(1)}${KILO_LABEL}`; @@ -285,6 +291,7 @@ export class HuggingFaceService { /** * Format timestamp to relative time */ + // LLAMA-APP-REUSE: relative timestamps static formatRelativeTime(timestamp: string): string { const date = new Date(timestamp); const now = new Date(); @@ -312,6 +319,7 @@ export class HuggingFaceService { * Format a min-max size range with a single shared unit and no spaces * around the dash, e.g. `19.0-28.6 GB`. */ + // LLAMA-APP-REUSE: min-max size ranges static formatSizeRange(min: number, max: number): string { const unit = max >= GIGABYTE @@ -398,6 +406,7 @@ export class HuggingFaceService { * Look up the average bit-depth for a known GGUF quantization. * Returns `null` for unrecognized tokens. */ + // LLAMA-APP-REUSE: quant bit depths static getBitDepth(quant: string): number | null { // Strip a leading `UD-` (Unsloth Dynamic) prefix before lookup. const base = quant.replace(HF_UD_QUANT_PREFIX_REGEX, ''); @@ -581,6 +590,7 @@ export class HuggingFaceService { * `Qwen3.8-27B-GGUF` or `300M` from `embeddinggemma-300M-GGUF`. Returns null * when no size token is present. */ + // LLAMA-APP-REUSE: parameter-count parsing static parseParamCount(name: string): string | null { const match = HF_PARAM_COUNT_REGEX.exec(name); @@ -592,6 +602,7 @@ export class HuggingFaceService { /** * Parse model tags to extract useful information */ + // LLAMA-APP-REUSE: tag parsing static parseTags(tags: string[]): { license: string | null; isGated: boolean; diff --git a/tools/ui/src/lib/services/models.service.ts b/tools/ui/src/lib/services/models.service.ts index 0f1e34f800..bccda35c2b 100644 --- a/tools/ui/src/lib/services/models.service.ts +++ b/tools/ui/src/lib/services/models.service.ts @@ -33,6 +33,7 @@ export class ModelsService { * @param sidecar - Sidecar type, uppercased into the tag (e.g. `MTP`) * @returns Repo id possibly suffixed with `:tag` */ + // LLAMA-APP-REUSE: repo:tag id builder static buildDownloadTag( repoId: string, quant: string | null, @@ -154,6 +155,7 @@ export class ModelsService { * @param modelId - Raw model identifier string * @returns Structured {@link ParsedModelId} with all detected fields */ + // LLAMA-APP-REUSE: model id parser static parseModelId(modelId: string): ParsedModelId { const result: ParsedModelId = { activatedParams: null, diff --git a/tools/ui/src/lib/types/huggingface.d.ts b/tools/ui/src/lib/types/huggingface.d.ts index a0de5d8598..0b9e558413 100644 --- a/tools/ui/src/lib/types/huggingface.d.ts +++ b/tools/ui/src/lib/types/huggingface.d.ts @@ -4,6 +4,7 @@ * Types for the HuggingFace REST API (/api/models) * Reference: https://huggingface.co/docs/huggingface_hub/package_reference/hf_api */ +// LLAMA-APP-REUSE: HF API response shapes // Search Options diff --git a/tools/ui/src/lib/types/models.d.ts b/tools/ui/src/lib/types/models.d.ts index 4b27b8f5af..77935dcaba 100644 --- a/tools/ui/src/lib/types/models.d.ts +++ b/tools/ui/src/lib/types/models.d.ts @@ -45,6 +45,7 @@ export interface ModelDownloadProgress { totalBytes: number; } +// LLAMA-APP-REUSE: parsed model id shape export interface ParsedModelId { raw: string; orgName: string | null; diff --git a/tools/ui/src/lib/utils/chat-template-thinking-detector.ts b/tools/ui/src/lib/utils/chat-template-thinking-detector.ts index 33e9b4fb54..2a357f5ead 100644 --- a/tools/ui/src/lib/utils/chat-template-thinking-detector.ts +++ b/tools/ui/src/lib/utils/chat-template-thinking-detector.ts @@ -10,6 +10,7 @@ * 2. Thinking-control Jinja2 conditionals === template-native on/off logic * 3. Paired thinking-content tag pairs === models that output special tags */ +// LLAMA-APP-REUSE: thinking-support detection from a chat template const THINKING_KWARG_VARS = ['enable_thinking', 'reasoning_effort', 'thinking_budget']; /** diff --git a/tools/ui/src/lib/utils/chat-template-tool-detector.ts b/tools/ui/src/lib/utils/chat-template-tool-detector.ts index a90ee24c63..22cd99726a 100644 --- a/tools/ui/src/lib/utils/chat-template-tool-detector.ts +++ b/tools/ui/src/lib/utils/chat-template-tool-detector.ts @@ -5,6 +5,7 @@ * template. A template that accepts a `tools` array or emits tool-call tokens * is treated as tool-capable. */ +// LLAMA-APP-REUSE: tool-use support detection from a chat template /** Tool-call tokens emitted by the template for assistant tool calls. */ const TOOL_CALL_TOKENS = [ diff --git a/tools/ui/src/lib/utils/model-compatibility.ts b/tools/ui/src/lib/utils/model-compatibility.ts index 3761e53c9b..eb0928c30e 100644 --- a/tools/ui/src/lib/utils/model-compatibility.ts +++ b/tools/ui/src/lib/utils/model-compatibility.ts @@ -6,6 +6,7 @@ * device-specific budgets are deliberately ignored - callers present the * requirement and let the user judge. */ +// LLAMA-APP-REUSE: hardware compatibility estimation /** Overhead multiplier applied to the file size when estimating weight memory. */ const WEIGHT_OVERHEAD_MULTIPLIER = 1.05; diff --git a/tools/ui/src/lib/utils/model-names.ts b/tools/ui/src/lib/utils/model-names.ts index 209f0f2ff5..e20e897738 100644 --- a/tools/ui/src/lib/utils/model-names.ts +++ b/tools/ui/src/lib/utils/model-names.ts @@ -1,3 +1,4 @@ +// LLAMA-APP-REUSE: model name / HF repo path normalization import { FILE_PATH_SEPARATOR_REGEX } from '$lib/constants'; /**