Skip to content

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

refactor: consolidate HF token status UI (#3035)

[._.]/ Adam Eivy5959b642482b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 436244cf8e..710bbeb682 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -117,6 +117,7 @@
## Image generation
+- **[issue-3035] Hugging Face setup now stays consistent across Image Gen and Settings** — gated models use the same saved-token status everywhere, while Settings retains the precise source details you need to manage that token; the access banner now presents one consistent account, terms, and token-entry path for every model.
- **Generate live procedural Three.js models from the image gallery** — the **Three.js Models** page (in the Create sidebar) turns a gallery image into a live procedural scene: pick any image with its built-in gallery picker, choose any configured AI provider/model, generate a validated primitive/custom-geometry scene, orbit and zoom the result live in the browser, refine it with feedback or a different model, and copy/download a standalone Three.js `Group` factory. The implementation is natively owned (inspired by `img2threejs`, with no new module dependency) and renders a bounded declarative spec instead of evaluating model-written JavaScript. (A render's **Send to 3D** shortcut now opens the image-to-3D **3D** page instead — see the 3D section.)
- **[issue-2859] Grok can now generate videos too** — with Grok enabled, the Video Gen page gains a Local/Grok backend switch: Grok renders 6- or 10-second clips via its image-first flow (it generates a base image from your prompt, or animates a source image you pick, then runs its video tool). Clips land in the same render history with thumbnails, run in the parallel cloud queue lane alongside Grok/Codex image jobs, and never require local Python or GPU runtimes.
- **[issue-2859] xAI Grok (Grok Build CLI) is a new image-generation backend** — enable it in Settings → Image Gen → Grok CLI and every image surface (Image Gen page, pipeline renders, character sheets, universe builder batches, avatars, voice `image_generate`) can route through the Grok CLI's built-in `image_gen` tool, including image-to-image editing via `image_edit`. Configuration is just the binary path and an optional default aspect ratio — Grok picks the model internally. Grok renders run in the same parallel queue lane as Codex, and Grok video generation is planned as a follow-up phase.
diff --git a/client/src/components/imageGen/HfTokenBanner.jsx b/client/src/components/imageGen/HfTokenBanner.jsx
index cbbe9557e3..cb1ac3fd59 100644
--- a/client/src/components/imageGen/HfTokenBanner.jsx
+++ b/client/src/components/imageGen/HfTokenBanner.jsx
@@ -81,8 +81,7 @@ export default function HfTokenBanner({ modelLabel, licenseUrl, models, onSaved
onSaved?.();
};
- const licenseLinkText = licenseUrl?.replace(/^https?:\/\//, '');
- const multi = Array.isArray(models) && models.length > 0;
+ const list = models?.length ? models : (modelLabel ? [{ label: modelLabel, url: licenseUrl }] : []);
const tokenLink = (
<a href="https://huggingface.co/settings/tokens" target="_blank" rel="noreferrer" className="underline text-white">
@@ -92,23 +91,11 @@ export default function HfTokenBanner({ modelLabel, licenseUrl, models, onSaved
return (
<div className="rounded-lg border border-port-warning/40 bg-port-warning/10 px-3 py-3 text-xs text-port-warning space-y-2">
- {multi ? (
- <div>
- <div>
- This needs a free Hugging Face account. Accept the terms for each gated model below (signed in to
- Hugging Face), then create a read token at {tokenLink} and paste it here.
- </div>
- <GatedModelList models={models} />
- </div>
- ) : (
- <div>
- {modelLabel} is a gated model. Accept the license at{' '}
- <a href={licenseUrl} target="_blank" rel="noreferrer" className="underline text-white">
- {licenseLinkText}
- </a>
- , then create a read token at {tokenLink} and paste it below.
- </div>
- )}
+ <div>
+ This needs a free Hugging Face account. Accept the terms for each gated model below (signed in to
+ Hugging Face), then create a read token at {tokenLink} and paste it here.
+ <GatedModelList models={list} />
+ </div>
<div className="flex flex-col sm:flex-row gap-2 items-stretch sm:items-center">
<div className="flex items-center gap-1.5 flex-1 bg-port-bg border border-port-border rounded-lg px-2 py-1.5 focus-within:border-port-accent">
<Key size={14} className="text-gray-400 flex-shrink-0" />
diff --git a/client/src/components/imageGen/HfTokenBanner.test.jsx b/client/src/components/imageGen/HfTokenBanner.test.jsx
new file mode 100644
index 0000000000..0ad713891a
--- /dev/null
+++ b/client/src/components/imageGen/HfTokenBanner.test.jsx
@@ -0,0 +1,41 @@
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import HfTokenBanner from './HfTokenBanner';
+
+vi.mock('../ui/Toast', () => ({
+ default: Object.assign(vi.fn(), {
+ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn(),
+ }),
+}));
+
+describe('HfTokenBanner', () => {
+ it('uses the same guidance and model list for one gated model', () => {
+ render(
+ <HfTokenBanner
+ modelLabel="MuScriptor"
+ licenseUrl="https://huggingface.co/MuScriptor/muscriptor-medium"
+ />,
+ );
+
+ expect(screen.getByText(/needs a free Hugging Face account/i)).toBeTruthy();
+ expect(screen.getByRole('link', { name: /MuScriptor/i })).toHaveAttribute(
+ 'href',
+ 'https://huggingface.co/MuScriptor/muscriptor-medium',
+ );
+ expect(screen.queryByText(/MuScriptor is a gated model/i)).toBeNull();
+ });
+
+ it('renders every supplied gated-model link through that same list', () => {
+ render(
+ <HfTokenBanner
+ models={[
+ { label: 'First model', url: 'https://huggingface.co/first' },
+ { label: 'Second model', url: 'https://huggingface.co/second' },
+ ]}
+ />,
+ );
+
+ expect(screen.getByRole('link', { name: /First model/i })).toBeTruthy();
+ expect(screen.getByRole('link', { name: /Second model/i })).toBeTruthy();
+ });
+});
diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsx
index 89639d9bc1..8acbc4126e 100644
--- a/client/src/components/settings/ImageGenTab.jsx
+++ b/client/src/components/settings/ImageGenTab.jsx
@@ -20,11 +20,12 @@ import { isLoopbackHost } from '../../lib/loopbackHost.js';
import {
getSettings, updateSettings, getImageGenStatus, generateImage,
registerTool, updateTool, getToolsList,
- getHfTokenStatus, saveHfToken, clearHfToken,
+ saveHfToken, clearHfToken,
} from '../../services/api';
import { isCloudCliMode, IMAGE_GEN_MODE, CODEX_IMAGEGEN_DEFAULT_EFFORT, GROK_ASPECT_RATIOS } from '../../lib/imageGenBackends';
import { resolveCleanersFromConfig } from '../../lib/imageCleaners';
import { useMediaJobSse } from '../../hooks/useMediaJobSse';
+import { useHfTokenStatus } from '../../hooks/useHfTokenStatus';
import { CODEX_EFFORT_LEVELS } from '../../utils/providers';
const SDAPI_TOOL_ID = 'sdapi';
@@ -161,19 +162,13 @@ export function ImageGenTab() {
// applies to local Flux models regardless of which backend is active.
// `source` is 'stored' | 'env' | 'cli' | 'none'; only 'stored' tokens can be
// cleared from the UI (env/CLI come from outside settings.json).
- const [hfTokenInfo, setHfTokenInfo] = useState({ hfTokenPresent: null, source: null });
+ const { present: hfTokenPresent, source: hfTokenSource, refresh: refreshHfTokenStatus } = useHfTokenStatus();
const [hfTokenInput, setHfTokenInput] = useState('');
// One busy flag covers both save and clear since they're mutually exclusive
// (both disable the form + buttons). `busy` is the in-flight verb so the
// Clear button can still show a Trash icon while the spinner is on Save.
const [hfTokenBusy, setHfTokenBusy] = useState(null); // null | 'saving' | 'clearing'
- useEffect(() => {
- getHfTokenStatus()
- .then((s) => { if (s) setHfTokenInfo({ hfTokenPresent: !!s.hfTokenPresent, source: s.source || null }); })
- .catch((err) => { console.warn(`⚠️ Failed to load HF token status: ${err?.message || err}`); });
- }, []);
-
const handleSaveHfToken = async () => {
const trimmed = hfTokenInput.trim();
if (!trimmed) return;
@@ -182,7 +177,7 @@ export function ImageGenTab() {
setHfTokenBusy(null);
if (!result?.ok) return;
setHfTokenInput('');
- setHfTokenInfo({ hfTokenPresent: true, source: result.source || 'stored' });
+ refreshHfTokenStatus();
toast.success('HuggingFace token saved');
};
@@ -191,7 +186,7 @@ export function ImageGenTab() {
const result = await clearHfToken().catch(() => null);
setHfTokenBusy(null);
if (!result?.ok) return;
- setHfTokenInfo({ hfTokenPresent: !!result.hfTokenPresent, source: result.source || 'none' });
+ refreshHfTokenStatus();
toast.success(result.hfTokenPresent ? 'Stored token cleared (env / CLI token still active)' : 'HuggingFace token cleared');
};
@@ -803,16 +798,16 @@ export function ImageGenTab() {
<code className="text-gray-400">HF_TOKEN</code> env var or <code className="text-gray-400">~/.cache/huggingface/token</code>.
</p>
- {hfTokenInfo.hfTokenPresent === null ? (
+ {hfTokenPresent === null ? (
<div className="text-xs text-gray-500"><BrailleSpinner text="Checking token status" /></div>
- ) : hfTokenInfo.hfTokenPresent ? (
+ ) : hfTokenPresent ? (
<div className="flex items-center gap-2 text-xs text-port-success">
<Check size={14} />
<span>
Token configured
- {hfTokenInfo.source === 'env' && ' (from HF_TOKEN environment variable)'}
- {hfTokenInfo.source === 'cli' && ' (from ~/.cache/huggingface/token — set via `hf auth login`)'}
- {hfTokenInfo.source === 'stored' && ' (stored in settings.json)'}
+ {hfTokenSource === 'env' && ' (from HF_TOKEN environment variable)'}
+ {hfTokenSource === 'cli' && ' (from ~/.cache/huggingface/token — set via `hf auth login`)'}
+ {hfTokenSource === 'stored' && ' (stored in settings.json)'}
</span>
</div>
) : (
@@ -824,7 +819,7 @@ export function ImageGenTab() {
<div>
<label htmlFor="hf-token-input" className="block text-xs font-medium text-gray-400 mb-1">
- {hfTokenInfo.source === 'stored' ? 'Replace stored token' : 'Paste a token'}
+ {hfTokenSource === 'stored' ? 'Replace stored token' : 'Paste a token'}
</label>
<div className="flex flex-col sm:flex-row gap-2">
<input
@@ -851,7 +846,7 @@ export function ImageGenTab() {
</div>
</div>
- {hfTokenInfo.source === 'stored' && (
+ {hfTokenSource === 'stored' && (
<button
type="button"
onClick={handleClearHfToken}
diff --git a/client/src/components/settings/ImageGenTab.test.jsx b/client/src/components/settings/ImageGenTab.test.jsx
index f97470ed37..52ff2df9f4 100644
--- a/client/src/components/settings/ImageGenTab.test.jsx
+++ b/client/src/components/settings/ImageGenTab.test.jsx
@@ -10,10 +10,12 @@ vi.mock('../../services/api', () => ({
registerTool: vi.fn(),
updateTool: vi.fn(),
getToolsList: vi.fn(),
- getHfTokenStatus: vi.fn(),
saveHfToken: vi.fn(),
clearHfToken: vi.fn(),
}));
+vi.mock('../../hooks/useHfTokenStatus', () => ({
+ useHfTokenStatus: vi.fn(),
+}));
vi.mock('../ui/Toast', () => ({
default: Object.assign(vi.fn(), {
success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn(),
@@ -29,8 +31,9 @@ vi.mock('../../hooks/useMediaJobSse', () => ({
}));
import {
- getSettings, getToolsList, getHfTokenStatus, updateSettings,
+ getSettings, getToolsList, updateSettings,
} from '../../services/api';
+import { useHfTokenStatus } from '../../hooks/useHfTokenStatus';
import { ImageGenTab } from './ImageGenTab';
const renderTab = async (initialEntries = ['/media/image']) => {
@@ -55,7 +58,7 @@ beforeEach(() => {
},
});
getToolsList.mockResolvedValue([]);
- getHfTokenStatus.mockResolvedValue({ hfTokenPresent: false, source: 'none' });
+ useHfTokenStatus.mockReturnValue({ present: false, source: 'none', refresh: vi.fn() });
updateSettings.mockResolvedValue({});
});
@@ -113,6 +116,13 @@ describe('ImageGenTab grouped tabs', () => {
expect(tokensTab.getAttribute('aria-selected')).toBe('true');
});
+ it('keeps the detailed managed-token source labels while reading shared status', async () => {
+ useHfTokenStatus.mockReturnValue({ present: true, source: 'cli', refresh: vi.fn() });
+ await renderTab(['/media/image?mediaTab=tokens']);
+
+ expect(screen.getByText(/~\/\.cache\/huggingface\/token — set via `hf auth login`/i)).toBeTruthy();
+ });
+
it('keeps the global Save + Test Connection bar visible on every tab', async () => {
await renderTab();
expect(screen.getByRole('button', { name: /^Save$/ })).toBeTruthy();
diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsx
index 9e31925299..5021c60be6 100644
--- a/client/src/pages/ImageGen.jsx
+++ b/client/src/pages/ImageGen.jsx
@@ -46,11 +46,12 @@ import BrailleSpinner from '../components/BrailleSpinner';
import { useImageGenProgress } from '../hooks/useImageGenProgress';
import { useMediaJobSse } from '../hooks/useMediaJobSse';
import { useModelDownloadStatus } from '../hooks/useModelDownloadStatus';
+import { useHfTokenStatus } from '../hooks/useHfTokenStatus';
import {
getImageGenStatus, generateImage, generateImageMultipart, listImageModels, listLorasFull, listImageGallery,
cancelImageGen, deleteImage, setImageHidden, cleanGalleryImage, getActiveImageJob, getSettings,
buildFormData, listMediaJobs, regenerateGalleryImage, getRegenAvailability, removeImageWatermark,
- getFlux2Status, getHfTokenStatus,
+ getFlux2Status,
} from '../services/api';
// Multi-reference editing (FLUX.2 only) — 4 fixed slots, each carrying an
@@ -132,10 +133,6 @@ export default function ImageGen() {
// user is only using mflux/external/codex.
const [flux2Status, setFlux2Status] = useState(null);
const [flux2InstallOpen, setFlux2InstallOpen] = useState(false);
- // Generic HF-token presence for legacy mflux gated models (FLUX.1-dev).
- // Lazy-fetched when a model with `requiresHfToken: true` is selected.
- const [hfTokenPresent, setHfTokenPresent] = useState(null);
-
const [selectedMode, setSelectedMode] = useState(null);
// Mirror selectedMode in a ref so callbacks (reloadBackends) can read the
// latest value without re-creating themselves on every mode flip.
@@ -625,12 +622,6 @@ export default function ImageGen() {
.catch(() => {});
}, [modelId]);
- const refreshHfTokenStatus = useCallback((signal) => {
- return getHfTokenStatus({ signal })
- .then((s) => { if (s) setHfTokenPresent(!!s.hfTokenPresent); })
- .catch(() => {});
- }, []);
-
// Memoized so Flux2InstallModal's EventSource effect doesn't re-fire on
// every parent re-render (gallery / generating / progress state churn
// would otherwise tear down the SSE connection mid-install).
@@ -657,12 +648,7 @@ export default function ImageGen() {
// so a stale Flux modelId left in state from a prior local session must not
// surface the HF banner under those backends.
const needsHfTokenGate = isLocalMode && !!currentModel?.requiresHfToken && !isFlux2Model;
- useEffect(() => {
- if (!needsHfTokenGate) { setHfTokenPresent(null); return; }
- const controller = new AbortController();
- refreshHfTokenStatus(controller.signal);
- return () => controller.abort();
- }, [needsHfTokenGate, modelId, refreshHfTokenStatus]);
+ const { present: hfTokenPresent, refresh: refreshHfTokenStatus } = useHfTokenStatus({ enabled: needsHfTokenGate });
// While the user has additional renders queued behind the active one, poll
// `/api/media-jobs` to keep `pendingQueued` in sync with the server's