Download ui/web/src/components/LlamaServerInstallDialog.svelte from localailb/assistant: direct link, hf CLI and curl.
- Browser
- Download file 6.03 kB
-
https://huggingface.co/spaces/localailb/assistant/resolve/main/ui/web/src/components/LlamaServerInstallDialog.svelte
- Command line
-
hf download hf://spaces/localailb/assistant/ui/web/src/components/LlamaServerInstallDialog.svelte
-
curl -L -o LlamaServerInstallDialog.svelte https://huggingface.co/spaces/localailb/assistant/resolve/main/ui/web/src/components/LlamaServerInstallDialog.svelte
6.03 kB
| <script> | |
| import { onMount } from "svelte"; | |
| import { t } from "../lib/stores.svelte.js"; | |
| import { llamaServerInfo } from "../lib/api.js"; | |
| import "./LlamaServerInstallDialog.css"; | |
| /** llama-server download popup β the Settings tab's "llama-server" | |
| * download button opens this instead of silently auto-picking a build. | |
| * Fetches the detection report (/api/settings/llama-server-info), shows | |
| * every build that CAN run on this PC (CPU / CUDA 12.4 / CUDA 13.3) with | |
| * its reason, and lets the user pick. `oninstall(choice)` fires with the | |
| * chosen id (auto / cpu / cuda12 / cuda13) when the user confirms. */ | |
| let { onclose, oninstall } = $props(); | |
| let plan = $state(null); | |
| let loadErr = $state(""); | |
| let selected = $state("auto"); | |
| let rootEl; | |
| let boxEl = $state(null); | |
| // ββ Draggable ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| let dragOffsetX = 0; | |
| let dragOffsetY = 0; | |
| let posX = $state(null); | |
| let posY = $state(null); | |
| let dragging = $state(false); | |
| function onDragStart(e) { | |
| if (!boxEl) return; | |
| if (e.button !== 0) return; | |
| e.preventDefault(); | |
| const rect = boxEl.getBoundingClientRect(); | |
| dragOffsetX = e.clientX - rect.left; | |
| dragOffsetY = e.clientY - rect.top; | |
| if (posX === null) posX = rect.left; | |
| if (posY === null) posY = rect.top; | |
| dragging = true; | |
| } | |
| function onDragMove(e) { | |
| if (!dragging) return; | |
| const w = window.innerWidth; | |
| const h = window.innerHeight; | |
| let x = e.clientX - dragOffsetX; | |
| let y = e.clientY - dragOffsetY; | |
| const bw = boxEl ? boxEl.offsetWidth : 480; | |
| const bh = boxEl ? boxEl.offsetHeight : 350; | |
| x = Math.max(0, Math.min(x, w - bw)); | |
| y = Math.max(0, Math.min(y, h - bh)); | |
| posX = x; | |
| posY = y; | |
| } | |
| function onDragEnd() { | |
| dragging = false; | |
| } | |
| function fmt(key, params) { | |
| const s = t(key); | |
| if (!params) return s; | |
| return s.replace(/\{(\w+)\}/g, (m, k) => (params[k] !== undefined ? String(params[k]) : m)); | |
| } | |
| function close() { | |
| onclose?.(); | |
| } | |
| function confirm() { | |
| oninstall?.(selected); | |
| onclose?.(); | |
| } | |
| function pick(id, available) { | |
| if (available) selected = id; | |
| } | |
| onMount(async () => { | |
| try { | |
| const r = await llamaServerInfo(); | |
| plan = r.plan || r; | |
| const rec = (plan.options || []).find((o) => o.recommended); | |
| if (rec) selected = rec.id; | |
| } catch (e) { | |
| loadErr = e.message || String(e); | |
| } | |
| rootEl?.querySelector(".llsrv-ok")?.focus(); | |
| const onKey = (e) => { | |
| if (e.key === "Escape") { | |
| e.preventDefault(); | |
| close(); | |
| } | |
| }; | |
| document.addEventListener("keydown", onKey, true); | |
| return () => document.removeEventListener("keydown", onKey, true); | |
| }); | |
| const detected = $derived(plan?.detected || {}); | |
| const options = $derived(plan?.options || []); | |
| </script> | |
| <!-- svelte-ignore a11y_no_static_element_interactions --> | |
| <svelte:window | |
| onmousemove={onDragMove} | |
| onmouseup={onDragEnd} | |
| /> | |
| <div | |
| class="llsrv-overlay" | |
| role="presentation" | |
| bind:this={rootEl} | |
| onmousedown={(e) => { | |
| if (e.target === rootEl) close(); | |
| }} | |
| > | |
| <div | |
| class="llsrv-box" | |
| class:dragging | |
| role="dialog" | |
| aria-modal="true" | |
| aria-labelledby="llsrv-title" | |
| bind:this={boxEl} | |
| style="{posX !== null ? `left:${posX}px;top:${posY}px;transform:none` : ''}" | |
| > | |
| <!-- svelte-ignore a11y_no_static_element_interactions --> | |
| <div | |
| class="llsrv-title llsrv-drag-handle" | |
| id="llsrv-title" | |
| role="none" | |
| onmousedown={onDragStart} | |
| >{t("llsrv_dialog_title")}</div> | |
| {#if loadErr} | |
| <div class="llsrv-err">{loadErr}</div> | |
| <div class="llsrv-actions"> | |
| <button type="button" class="llsrv-ok" data-tooltip={t("llsrv_dialog_ok")} onclick={close}> | |
| {t("llsrv_dialog_ok")} | |
| </button> | |
| </div> | |
| {:else if !plan} | |
| <div class="llsrv-loading">{t("web_loading", "β¦")}</div> | |
| {:else} | |
| <div class="llsrv-detect"> | |
| {t("llsrv_detected_gpu")}: <b>{detected.gpu_name || detected.gpu_brand || "β"}</b> | |
| <br /> | |
| {t("llsrv_detected_cpu")}: <b>{detected.cpu_name || "β"}</b> | |
| {#if detected.driver_cuda_version} | |
| <br />{t("llsrv_detected_driver")}: <b>{detected.driver_cuda_version}</b> | |
| {/if} | |
| <br />{t("llsrv_detected_release")}: <b>{detected.release_tag || t("llsrv_release_unknown")}</b> | |
| </div> | |
| <div class="llsrv-pick">{t("llsrv_dialog_ask")}</div> | |
| <div class="llsrv-opts"> | |
| {#each options as o (o.id)} | |
| {@const avail = !!o.available} | |
| <label | |
| class="llsrv-opt" | |
| class:unavail={!avail} | |
| class:sel={avail && selected === o.id} | |
| data-tooltip={t("llsrv_opt_tip")} | |
| > | |
| <input | |
| type="radio" | |
| name="llsrv-choice" | |
| value={o.id} | |
| checked={avail && selected === o.id} | |
| disabled={!avail} | |
| onchange={() => pick(o.id, avail)} | |
| /> | |
| <span class="llsrv-opt-main"> | |
| <span class="llsrv-opt-label"> | |
| {t(o.label_key)} | |
| {#if o.recommended && avail}<span class="llsrv-rec">β {t("llsrv_recommended")}</span>{/if} | |
| {#if !avail}<span class="llsrv-na">β {t("llsrv_not_available")}</span>{/if} | |
| </span> | |
| <span class="llsrv-opt-reason">{fmt(o.reason_key, o.params)}</span> | |
| </span> | |
| </label> | |
| {/each} | |
| </div> | |
| <div class="llsrv-actions"> | |
| <button type="button" class="llsrv-cancel" data-tooltip={t("llsrv_dialog_cancel")} onclick={close}> | |
| {t("llsrv_dialog_cancel")} | |
| </button> | |
| <button type="button" class="llsrv-ok" data-tooltip={t("llsrv_dialog_install")} onclick={confirm}> | |
| {t("llsrv_dialog_install")} | |
| </button> | |
| </div> | |
| {/if} | |
| </div> | |
| </div> | |