diff --git a/Dockerfile b/Dockerfile index b453783..a36c4b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,12 +41,13 @@ COPY assets/custom2.js /app/code/librechat/client/dist/assets/custom2.js COPY patch_ui_strings.py /app/code/patch_ui_strings.py RUN python3 /app/code/patch_ui_strings.py -# Inject branding into built HTML (dist) before image is packaged +# Inject branding into built HTML (dist) before image is packaged. +# patch_index.py: title, custom.css/custom2.js links, and a per-build +# x-coop-build meta (unique every build → service worker precache revision +# changes → stale clients self-heal on deploy). Non-fatal at build. # rebuild marker 20261019-$(date +%s) -RUN sed -i 's|LibreChat|Inference Co‑op|' /app/code/librechat/client/dist/index.html && \ - sed -i '/Inference Co‑op<\\/title>/a <link rel="stylesheet" href="assets/custom.css">' /app/code/librechat/client/dist/index.html && \ - sed -i '/<link rel="stylesheet" href="assets\\/custom.css">/a <script src="assets/custom2.js"></script>' /app/code/librechat/client/dist/index.html && \ - sed -i "s||\\n |" /app/code/librechat/client/dist/index.html && \ +COPY patch_index.py /app/code/patch_index.py +RUN python3 /app/code/patch_index.py && \ sed -i 's|assets/logo.svg|assets/logo.svg?v=3|g' /app/code/librechat/client/dist/assets/index.*.js && \ rm -f /app/code/librechat/client/dist/assets/index.*.js.gz /app/code/librechat/client/dist/assets/index.*.js.br diff --git a/patch_index.py b/patch_index.py new file mode 100644 index 0000000..675da0c --- /dev/null +++ b/patch_index.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +"""Inject co-op branding + a per-build marker into the built index.html. + +Non-fatal by design: if the file is missing or upstream changes shape, we +exit 0 so a cosmetic patch can never break a version bump. + +The x-coop-build marker makes index.html unique per build, which changes the +service worker's precache revision — otherwise stale clients keep running the +old cached app shell (the "my changes never deploy" class of bug). +""" +import time + +PATH = "/app/code/librechat/client/dist/index.html" + +try: + html = open(PATH, encoding="utf-8").read() +except OSError: + raise SystemExit(0) + +# 1. Title +html = html.replace("LibreChat", "Inference Co\u2011op") + +# 2. Stylesheet + helper script (idempotent — skip if already present) +if "assets/custom.css" not in html: + html = html.replace( + "", + '\n ', + 1, + ) +if "assets/custom2.js" not in html: + html = html.replace( + '', + '\n ', + 1, + ) + +# 3. Per-build marker → forces the service worker to refresh the precache +if "x-coop-build" not in html: + marker = ''.format(int(time.time())) + html = html.replace("", "\n " + marker, 1) + +open(PATH, "w", encoding="utf-8").write(html) +print("index.html: co-op branding + build marker injected")