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

address review (codex): extract SSE_HEADERS to dependency-free sseHeaders.js

[._.]/ Adam Eivy9531604ef50e
diff --git a/server/lib/README.md b/server/lib/README.md
index 5d4631304d..d2508e0fef 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -103,7 +103,8 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `hfErrors.js` | Parse huggingface_hub gated-access errors: `extractGatedRepo(text)` → `owner/name` (or null) for the UI's license deep-link. Shared by the image runner and LoRA trainer. Pure. |
| `hfCache.js` | HuggingFace Hub cache inspection (`inspectModelCache(repoId)` → `{cached,sizeBytes,snapshotPath}`, `isModelCached`, `getHfCacheRoot`). Drives the inline "Available / Download" badge on the image + video gen forms. Also `verifyModelCache(repoId,{deep})` (structural safetensors-header + optional sha256 integrity check) and `repairModelCache(repoId,{deep})` (delete corrupt weight files so the download path re-fetches them) — power the "Repair model" banner. |
| `hfDownload.js` | `downloadHfRepo({repo,onEvent})` returning `{promise,kill}` — spawns `scripts/hf_download_repo.py` in the FLUX.2 venv (fallback: mflux pythonPath) and emits SSE-friendly stage/progress/complete events. Powers the inline "Download" button next to the model picker. |
-| `sseDownload.js` | `startHfDownloadStream({req,res,repo,alreadyDownloadedMessage})`, `openSseStream(res)` (`{send,safeEnd}` SSE boilerplate), `SSE_HEADERS` — shared SSE driver used by both image and video gen `/models/:id/download` routes. Owns the cross-route in-flight Map so a double-click (or both pages running) can't spawn two python children against the same repo. |
+| `sseHeaders.js` | `SSE_HEADERS` — the canonical SSE response headers (incl. `X-Accel-Buffering:no`) in a dependency-free module so any producer (`sseDownload.js`, `sseUtils.js`) can share them without pulling in a heavier module's transitive imports. |
+| `sseDownload.js` | `startHfDownloadStream({req,res,repo,alreadyDownloadedMessage})`, `openSseStream(res)` (`{send,safeEnd}` SSE boilerplate; uses `SSE_HEADERS` from `sseHeaders.js`) — shared SSE driver used by both image and video gen `/models/:id/download` routes. Owns the cross-route in-flight Map so a double-click (or both pages running) can't spawn two python children against the same repo. |
## File & I/O
diff --git a/server/lib/index.js b/server/lib/index.js
index 35fb829b23..7475962fdf 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -89,6 +89,7 @@ export * from './hfErrors.js';
export * from './hfCache.js';
export * from './hfDownload.js';
export * from './sseDownload.js';
+export * from './sseHeaders.js';
export * from './mediaModels.js';
export * from './promptPartials.js';
export * from './promptRunner.js';
diff --git a/server/lib/sseDownload.js b/server/lib/sseDownload.js
index 6ecf458e5e..2530a6fbad 100644
--- a/server/lib/sseDownload.js
+++ b/server/lib/sseDownload.js
@@ -8,19 +8,10 @@
import { inspectModelCache } from './hfCache.js';
import { downloadHfRepo } from './hfDownload.js';
+import { SSE_HEADERS } from './sseHeaders.js';
const inFlight = new Map(); // repo -> { promise, kill }
-export const SSE_HEADERS = {
- 'Content-Type': 'text/event-stream',
- 'Cache-Control': 'no-cache',
- Connection: 'keep-alive',
- // Disable proxy (nginx) response buffering so frames reach the client as they
- // are written rather than being held until the buffer fills — without this an
- // SSE stream behind a reverse proxy appears to hang.
- 'X-Accel-Buffering': 'no',
-};
-
/**
* Open an SSE response and return write-safe helpers. Canonical replacement
* for the per-route `writeHead → send → safeEnd` boilerplate: `send` JSON-
diff --git a/server/lib/sseHeaders.js b/server/lib/sseHeaders.js
new file mode 100644
index 0000000000..e65fba4154
--- /dev/null
+++ b/server/lib/sseHeaders.js
@@ -0,0 +1,16 @@
+// The canonical Server-Sent-Events response headers, in their own dependency-free
+// module so any SSE producer can share them without dragging in a heavier module's
+// transitive imports. (sseDownload.js — the other natural home — imports the
+// HuggingFace download stack, so importing SSE_HEADERS from there would load all of
+// that into every consumer; sseUtils.js and its ~15 pipeline/editorial routes must
+// stay light.)
+
+export const SSE_HEADERS = {
+ 'Content-Type': 'text/event-stream',
+ 'Cache-Control': 'no-cache',
+ Connection: 'keep-alive',
+ // Disable proxy (nginx) response buffering so frames reach the client as they
+ // are written rather than being held until the buffer fills — without this an
+ // SSE stream behind a reverse proxy appears to hang.
+ 'X-Accel-Buffering': 'no',
+};
diff --git a/server/lib/sseUtils.js b/server/lib/sseUtils.js
index dc64001fb7..98425551dc 100644
--- a/server/lib/sseUtils.js
+++ b/server/lib/sseUtils.js
@@ -9,7 +9,7 @@
// fire-and-forget coordinator shape.
import { randomUUID } from 'crypto';
-import { SSE_HEADERS } from './sseDownload.js';
+import { SSE_HEADERS } from './sseHeaders.js';
// Filters Python child noise (HF/torch/bitsandbytes/xformers warnings, deprecation
// notices, etc.) that would otherwise drown the user's view of real progress.