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

feat(image-gen): one-click LoRA trigger-word insertion + bigger preview cards

Adam Eivyaf829a51af9f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index eda0e0d8f3..bf23b760e1 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,7 @@
## Added
+- **One-click LoRA trigger-word insertion.** Each selected LoRA in the Image Gen picker now exposes a small `+ trigger` button next to its scale input — click it to append the LoRA's trigger words to the prompt, comma-separated, deduped (case-insensitive substring match against the existing prompt so re-clicking is a no-op). The "Test" deep-link from the LoRAs manager page (`/media/image?lora=<filename>`) also auto-inserts the trigger words on preselect — when a user clicks "Test this LoRA," they want to actually see the LoRA fire, which most LoRAs only do once the trigger is in the prompt. Helper `appendTriggerWords()` lives in `ImageGen.jsx` for now; would extract to `genUtils.js` if reused elsewhere.
- **Suggested LoRAs panel on the manager page.** `/media/loras` now leads with a "Suggested LoRAs" section that surfaces (1) a hand-curated list of picks that work well across the family — initially `hyperdetailed-colored-pencil`, `anime-art`, `dark-ghibli-fairytales`, `ars-midjourney-watercolor` — and (2) per-runner-family top-N from Civitai's "Most Downloaded" endpoint (Flux 1 / Flux 2 / Z-Image). Each card shows the preview thumbnail, runner-compat badges (derived from the model's actual `modelVersions[].baseModel`, so a multi-base-model upload shows all the badges it deserves), creator, downloads count, and an expandable "Sample prompt" section pulled from `images[0].meta.prompt`. **Quick install** routes through the same path as URL-paste, so the auth-prompt modal still fires for gated LoRAs and the same lockfile-collision protection applies. Cards already installed render as a green "Installed ✓" pill instead of the install button. Server: new `server/services/civitaiSuggestions.js` (in-memory 1-hour TTL cache per family, independent caches so a Z-Image search returning zero doesn't poison Flux), new `searchCivitaiLoras()` + `extractSamplePrompt()` helpers in `civitai.js`, new `GET /api/loras/suggestions` route (with `?force=1` to bust cache). 5 new tests cover the curated/runners shape, partial-failure tolerance, cache hit/miss, force-refresh, and runner-family derivation from multi-version models.
- **In-UI Civitai API key prompt.** When a Civitai install fails because the LoRA is gated (HTTP 401/403 from either the metadata or download endpoint), PortOS now opens an inline modal asking for an API key — paste it, click "Save key & retry install", and the same install fires again with the freshly-saved key in scope. The Manager page also surfaces a green "Key saved" / blue "Key (env)" / grey "Add API key" pill in the install form so users see at a glance whether a key is configured, and the modal includes a "Clear" button to remove a settings-level key (with a hint that the env-var key, if set, takes over after clearing). New endpoints: `GET /api/loras/auth/civitai` (returns `{ hasKey, source }` — the key itself never round-trips), `POST /api/loras/auth/civitai`, `DELETE /api/loras/auth/civitai`. Client API: `getCivitaiAuth`, `setCivitaiAuth`, `clearCivitaiAuth`. The install client now also takes `silent: true` so the auth-error path bypasses the auto-toast and reaches the modal cleanly.
- **Civitai LoRA manager.** A new `Media Gen → LoRAs` tab (`/media/loras`) lets you paste any Civitai model URL — `https://civitai.com/models/...`, `https://civitai.red/...`, a numeric model id, or `civitai:<id>` shortcut — and PortOS fetches the metadata, picks the primary `.safetensors`, streams the download into `data/loras/`, and writes a sidecar JSON next to it with trigger words, recommended scale, base model, creator, preview image URL, and the Civitai version id. Each card shows the preview thumbnail, a runner-family badge (Flux 1 / Flux 2 / Z-Image / Unsupported), trigger words, recommended scale, file size, and three actions: **Test** (deep-links into `/media/image?lora=<filename>` which preselects the LoRA and seeds its scale from the recommended value), **Open on Civitai**, and **Delete**. The Image Gen LoRA picker now reads the same registry, filters down to LoRAs whose `runnerFamily` matches the selected model's runner (or has no family — legacy/unknown), shows trigger words inline, and applies the recommended scale by default when you tick a LoRA. Restricted/adult LoRAs that need a logged-in download work via either the `CIVITAI_API_KEY` env var or `civitai.apiKey` in `data/settings.json`. New endpoints: `GET /api/loras`, `POST /api/loras/install`, `GET /api/loras/:filename`, `PATCH /api/loras/:filename`, `DELETE /api/loras/:filename`. Server: `server/lib/civitai.js` (URL parsing, version/file picking, sidecar shape) + `server/services/loras.js` (install/list/patch/delete with stream-to-disk + .partial finalizer). The runner side gets a best-effort `apply_loras()` helper added to `scripts/flux2_macos.py` and `scripts/z_image_turbo.py` (calls diffusers' `pipe.load_lora_weights()` + `pipe.set_adapters()` and logs+continues on shape mismatch rather than aborting the render); `mflux` continues to receive LoRAs through its existing `--lora-paths` / `--lora-scales` CLI surface. The `IMAGE_GEN_FLUX2_LORA_UNSUPPORTED` guard is removed — flux2 and z-image runners now plumb LoRAs through too. 45 new tests cover the Civitai URL-shape parser, version/file/preview picking, the auth header / download token plumbing, sidecar shape, and the install/list/delete service path (using a fake fetchImpl + temp loras dir).
diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsx
index 1f8055d4e9..c664ffc99e 100644
--- a/client/src/pages/ImageGen.jsx
+++ b/client/src/pages/ImageGen.jsx
@@ -39,6 +39,21 @@ import { safeParseJSON } from '../lib/genUtils';
const DEFAULT_NEGATIVE = 'blurry, low quality, distorted, deformed, ugly, watermark, text, signature';
+// Append LoRA trigger words to a prompt comma-separated, skipping any
+// already present (case-insensitive substring match — Civitai triggers are
+// often phrases, so we don't tokenize). Returns the updated prompt or the
+// original if every trigger is already in.
+const appendTriggerWords = (prompt, words) => {
+ const list = (Array.isArray(words) ? words : []).filter((w) => typeof w === 'string' && w.trim());
+ if (!list.length) return prompt;
+ const haystack = String(prompt || '').toLowerCase();
+ const fresh = list.filter((w) => !haystack.includes(w.toLowerCase()));
+ if (!fresh.length) return prompt;
+ const trimmed = String(prompt || '').trim();
+ const sep = !trimmed ? '' : trimmed.endsWith(',') ? ' ' : ', ';
+ return `${trimmed}${sep}${fresh.join(', ')}`;
+};
+
// User-facing labels for STAGE markers emitted by FLUX.2 (and any future
// runner). The keys match what `flux2_macos.py` prints; unknown stages fall
// through to the prettified id so adding a new STAGE in Python doesn't
@@ -253,8 +268,11 @@ export default function ImageGen() {
// ?lora=<filename> preselects a LoRA when the user clicks "Test" on the
// /media/loras manager page. Defers until availableLoras has loaded so the
- // metadata (recommendedScale, name) is available; once applied, strip the
- // param so a refresh doesn't keep re-adding the LoRA.
+ // metadata (recommendedScale, name, triggerWords) is available; once applied,
+ // strip the param so a refresh doesn't keep re-adding the LoRA. Also
+ // auto-appends the LoRA's trigger words to the prompt — the user came from
+ // "Test this" so the intent is "show me what this LoRA does," and most
+ // LoRAs only fire correctly when their trigger words are in the prompt.
useEffect(() => {
const fromUrl = searchParams.get('lora');
if (!fromUrl || !availableLoras.length) return;
@@ -265,6 +283,9 @@ export default function ImageGen() {
name: match.name,
scale: typeof match.recommendedScale === 'number' ? match.recommendedScale : 1.0,
}]);
+ if (match.triggerWords?.length) {
+ setPrompt((p) => appendTriggerWords(p, match.triggerWords));
+ }
setSearchParams((prev) => { const next = new URLSearchParams(prev); next.delete('lora'); return next; }, { replace: true });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchParams, availableLoras]);
@@ -834,6 +855,17 @@ export default function ImageGen() {
</label>
{selected && (
<div className="flex items-center gap-2">
+ {(lora.triggerWords || []).length > 0 && (
+ <button
+ type="button"
+ onClick={() => setPrompt((p) => appendTriggerWords(p, lora.triggerWords))}
+ disabled={statusLoading}
+ title={`Append to prompt: ${lora.triggerWords.join(', ')}`}
+ className="text-[11px] px-2 py-1 rounded bg-port-accent/10 text-port-accent border border-port-accent/30 hover:bg-port-accent/20 disabled:opacity-50 whitespace-nowrap"
+ >
+ + trigger
+ </button>
+ )}
<span className="text-xs text-gray-500" title={`Recommended: ${recommended.toFixed(2)}`}>Scale</span>
<input
type="number" min={0} max={2} step={0.1}
diff --git a/client/src/pages/Loras.jsx b/client/src/pages/Loras.jsx
index 4101a23d95..38edbe79ac 100644
--- a/client/src/pages/Loras.jsx
+++ b/client/src/pages/Loras.jsx
@@ -296,10 +296,10 @@ function SuggestionCard({ card, installed, installing, onInstall }) {
return (
<div className="bg-port-card border border-port-border rounded-lg overflow-hidden flex flex-col">
{card.previewImageUrl ? (
- <img src={card.previewImageUrl} alt="" className="w-full h-32 object-cover bg-port-bg" loading="lazy" />
+ <img src={card.previewImageUrl} alt="" className="w-full h-56 object-cover bg-port-bg" loading="lazy" />
) : (
- <div className="w-full h-32 bg-port-bg flex items-center justify-center text-gray-700">
- <Sparkles size={24} />
+ <div className="w-full h-56 bg-port-bg flex items-center justify-center text-gray-700">
+ <Sparkles size={32} />
</div>
)}
<div className="p-3 flex-1 flex flex-col gap-2">
diff --git a/server/services/civitaiSuggestions.js b/server/services/civitaiSuggestions.js
index eba8d1e6c0..aefa10986b 100644
--- a/server/services/civitaiSuggestions.js
+++ b/server/services/civitaiSuggestions.js
@@ -32,6 +32,7 @@ const CURATED_SUGGESTIONS = [
{ modelId: 832858, note: 'Stylized anime-art rendering.' },
{ modelId: 1349631, note: 'Dark Ghibli-fairytale aesthetic — moody storybook scenes.' },
{ modelId: 551903, note: 'Ars Midjourney watercolor — soft, painterly fills with bleeding edges.' },
+ { modelId: 816857, note: 'Neon Retrowave by ChronoKnight — Flux 2 Klein 9B + Flux + Illustrious versions.' },
];
// runnerFamily -> { fetchedAt: number, items: SuggestionCard[] }