Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address local review: reuse the shared progress bar and fix a double toast
Adam Eivyfc7c703192f7
diff --git a/client/src/components/settings/LocalLlmTab.jsx b/client/src/components/settings/LocalLlmTab.jsxindex d890207cff..3e77b4a915 100644--- a/client/src/components/settings/LocalLlmTab.jsx+++ b/client/src/components/settings/LocalLlmTab.jsx@@ -680,22 +680,31 @@ export function LocalLlmTab() {() => stopMtplxServer(),(r) => r?.message || 'MTPLX stopped').then(loadMtplxStatus);- // Checkpoint management. The pull resolves only when the weights are on disk;- // byte progress arrives on `mtplx:download` (subscribed below), so the button- // spinner is not the only sign of life during a multi-gigabyte transfer.- // Stable identity: the checkpoint panel keys its initial load on this, and the- // status poll re-renders this component every few seconds.+ // Checkpoint management (search / download / remove), owned by the MTPLX card.+ //+ // `mtplxSearch` keeps a stable identity because the checkpoint panel keys its+ // one-time initial load on it, and the status poll re-renders this component+ // every few seconds. It resolves its own failures into the `{models, error}`+ // shape the panel renders inline, so it is `silent` — no toast.const mtplxSearch = useCallback((params) => searchMtplxModels(params, { silent: true }).catch((err) => ({ models: [], error: err?.message || 'Search failed' })), []);+ // The pull resolves only when the weights are on disk; byte progress arrives+ // on `mtplx:download` (subscribed above), so the button spinner is not the+ // only sign of life during a multi-gigabyte transfer.const mtplxPull = (model) => runAction(model ? `mtplx-pull-${model}` : 'mtplx-pull',- () => pullMtplxModel(model),- (r) => (r?.success ? `${r.model || 'Default checkpoint'} downloaded` : null),- ).then((r) => {+ // A failed download RESOLVES `{success: false, error}` rather than throwing+ // (its progress already streamed), so convert it to the rejection+ // `runAction` routes to `onError` — otherwise the success formatter runs on+ // a failure and toasts an empty success next to the error.+ () => pullMtplxModel(model).then((r) => {+ if (r?.success === false) throw new Error(r.error || 'Download failed');+ return r;+ }),+ (r) => `${r?.model || 'Default checkpoint'} downloaded`,+ { onError: (err) => toast.error(`MTPLX download failed: ${err.message}`) },+ ).then(() => {setMtplxDownload(null);- // A pull that exits non-zero resolves rather than throwing, so its reason- // has to be surfaced here — `runAction`'s success toast can't tell.- if (r && r.success === false) toast.error(`Download failed: ${r.error}`);return loadMtplxStatus();});const mtplxRemove = (model) => runAction(diff --git a/client/src/components/settings/LocalLlmTab.test.jsx b/client/src/components/settings/LocalLlmTab.test.jsxindex f5f217d012..136461adb2 100644--- a/client/src/components/settings/LocalLlmTab.test.jsx+++ b/client/src/components/settings/LocalLlmTab.test.jsx@@ -133,6 +133,38 @@ describe('LocalLlmTab runtime servers', () => {await waitFor(() => expect(startMtplxServer).toHaveBeenCalled());});+ it('reports a failed checkpoint download as one error, not an empty success', async () => {+ // `pullMtplxModel` RESOLVES `{success: false}` for a failed download (its+ // progress already streamed), so a formatter-only success message would fire+ // an empty success toast alongside the real reason.+ const { getMtplxServerStatus, pullMtplxModel } = await import('../../services/api');+ const toast = (await import('../ui/Toast')).default;+ getMtplxServerStatus.mockResolvedValue({+ installed: true, running: false, supported: true, cachedModels: [], cacheError: null,+ });+ pullMtplxModel.mockResolvedValue({ success: false, model: null, error: 'no space left on device' });++ await renderTab();+ fireEvent.click(screen.getByRole('button', { name: /Download default checkpoint/ }));++ await waitFor(() => expect(toast.error).toHaveBeenCalledWith(expect.stringMatching(/no space left on device/)));+ expect(toast.success).not.toHaveBeenCalled();+ });++ it('downloads MTPLX\'s own default checkpoint when the cache is empty', async () => {+ const { getMtplxServerStatus, pullMtplxModel } = await import('../../services/api');+ getMtplxServerStatus.mockResolvedValue({+ installed: true, running: false, supported: true, cachedModels: [], cacheError: null,+ });+ pullMtplxModel.mockResolvedValue({ success: true, model: null, cachedModels: ['Example/Qwen-MTP'] });++ await renderTab();+ fireEvent.click(screen.getByRole('button', { name: /Download default checkpoint/ }));++ // `null` (not a repo id the card invented) = MTPLX's own verified default.+ await waitFor(() => expect(pullMtplxModel).toHaveBeenCalledWith(null));+ });+it('saves the PM2 process list so the managed daemons survive a reboot', async () => {const { saveRuntimeStartupList } = await import('../../services/api');saveRuntimeStartupList.mockResolvedValue({ success: true });diff --git a/client/src/components/settings/MtplxCheckpoints.jsx b/client/src/components/settings/MtplxCheckpoints.jsxindex 29971453bc..2c21eaebbc 100644--- a/client/src/components/settings/MtplxCheckpoints.jsx+++ b/client/src/components/settings/MtplxCheckpoints.jsx@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';import { Download, HardDrive, RefreshCw, Search, Trash2, CheckCircle2, AlertTriangle } from 'lucide-react';import BrailleSpinner from '../BrailleSpinner';import ConfirmButtonPair from '../ui/ConfirmButtonPair';+import ProgressBar from '../ui/ProgressBar';import { useConfirmDelete } from '../../hooks/useConfirmDelete';import { formatBytes } from '../../utils/formatters';@@ -27,22 +28,21 @@ const accentBtn = `${btn} bg-port-accent/20 hover:bg-port-accent/30 text-port-acconst neutralBtn = `${btn} bg-port-border hover:bg-port-border/70 text-white`;const dangerBtn = `${btn} bg-port-error/10 hover:bg-port-error/20 text-port-error`;-/** A pull frame carries bytes only once the transfer starts — show what we have. */-function ProgressBar({ download }) {+/**+ * A pull frame carries byte counters only once the transfer starts — until then+ * (`resolving`, `verifying`) there is no total, which is exactly the shared+ * bar's `percent={null}` indeterminate case rather than a misleading 0%.+ */+function DownloadProgress({ download }) {const { received = 0, total = 0, message } = download;- const pct = total > 0 ? Math.min(100, Math.round((received / total) * 100)) : null;+ const pct = total > 0 ? (received / total) * 100 : null;return (<div className="space-y-1">- <div className="h-1.5 bg-port-border rounded overflow-hidden">- <div- className={`h-full bg-port-accent transition-all ${pct === null ? 'animate-pulse w-1/3' : ''}`}- style={pct === null ? undefined : { width: `${pct}%` }}- />- </div>+ <ProgressBar percent={pct} track="border" label={`Downloading ${download.model || 'MTPLX default checkpoint'}`} /><p className="text-[11px] text-gray-500">{pct === null? (message || 'Downloading…')- : `${formatBytes(received)} of ${formatBytes(total)} (${pct}%)`}+ : `${formatBytes(received)} of ${formatBytes(total)} (${Math.round(pct)}%)`}</p></div>);@@ -176,7 +176,7 @@ export default function MtplxCheckpoints({<p className="text-xs text-gray-300 truncate">Downloading <code className="text-port-accent">{download.model || 'MTPLX default checkpoint'}</code></p>- <ProgressBar download={download} />+ <DownloadProgress download={download} /><p className="text-[11px] text-gray-500">This runs in the background — leaving this page won't cancel it.</p></div>)}diff --git a/server/services/mtplxModelManager.js b/server/services/mtplxModelManager.jsindex 8d8dfaca7a..37d89518b0 100644--- a/server/services/mtplxModelManager.js+++ b/server/services/mtplxModelManager.js@@ -45,9 +45,14 @@ const PULL_TIMEOUT_MS = 6 * 60 * 60 * 1000;* Both accept a bare URL too, but PortOS deliberately does not: the search* results it renders carry repo ids, and refusing everything else keeps a* hand-typed value from becoming a path or a flag (a leading `-` would be read- * as an option by argparse).+ * as an option by argparse). Each segment must START alphanumeric, so `owner/..`+ * cannot reach the cache walk either.+ *+ * Deliberately identical to `localLlmMtplxPullSchema`'s regex in+ * `lib/mediaValidation.js`: the route validates and this re-validates, and a+ * looser guard here would be a hole for any caller that isn't that route.*/-const REPO_ID_RE = /^[A-Za-z0-9][\w.-]*\/[\w.-]+$/;+const REPO_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/;export const isMtplxRepoId = (value) => typeof value === 'string' && REPO_ID_RE.test(value);@@ -156,9 +161,13 @@ export function parseMtplxPullFrame(line, model) {* already streamed progress, so the outcome is a value (`{ success, error }`)* the route reports rather than a rejection mid-stream.*- * @param {{model?: string|null, onProgress?: (frame: object) => void, isCancelled?: () => boolean}} [options]+ * There is deliberately no cancellation hook: a pull is a server-side download+ * the user is told keeps running when they navigate away, so nothing here is+ * tied to the lifetime of the request that started it.+ *+ * @param {{model?: string|null, onProgress?: (frame: object) => void}} [options]*/-export async function pullMtplxModel({ model = null, onProgress = () => {}, isCancelled } = {}) {+export async function pullMtplxModel({ model = null, onProgress = () => {} } = {}) {const binary = requireBinary();const repo = model ? requireRepoId(model) : null;const label = repo || 'MTPLX\'s default verified checkpoint';@@ -177,7 +186,7 @@ export async function pullMtplxModel({ model = null, onProgress = () => {}, isCa// an early one tear the progress bar down before the process exits.if (frame && frame.event !== 'complete' && frame.event !== 'result') onProgress(frame);},- { timeoutMs: PULL_TIMEOUT_MS, isCancelled }+ { timeoutMs: PULL_TIMEOUT_MS });if (!result.success) {diff --git a/server/services/mtplxModelManager.test.js b/server/services/mtplxModelManager.test.jsindex b3bb5734ce..2f1af72155 100644--- a/server/services/mtplxModelManager.test.js+++ b/server/services/mtplxModelManager.test.js@@ -33,6 +33,10 @@ describe('mtplxModelManager', () => {expect(isMtplxRepoId('Qwen-MTP')).toBe(false);expect(isMtplxRepoId('https://huggingface.co/Example/Qwen-MTP')).toBe(false);expect(isMtplxRepoId('../../etc/passwd')).toBe(false);+ // Each segment must START alphanumeric — the same rule the route schema+ // enforces, so the two guards cannot drift apart.+ expect(isMtplxRepoId('Example/..')).toBe(false);+ expect(isMtplxRepoId('Example/-flag')).toBe(false);});});