#!/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) # 4. Web manifest identity: co-op name + a 512 icon installable as "any". # (theme_color/background_color are fixed by the later Dockerfile sed.) MPATH = "/app/code/librechat/client/dist/manifest.webmanifest" try: import json as _json mf = _json.load(open(MPATH, encoding="utf-8")) mf["name"] = "Inference Co\u2011op" mf["short_name"] = "Inference" mf["description"] = "Member-governed AI inference — private and renewable model choices." # Deterministic icon list: explicit any/maskable entries (no dual-purpose # values — some Firefox Android versions mishandle "any maskable"), and # the launcher-suitable sizes first. mf["icons"] = [ {"src": "assets/icon-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "any"}, {"src": "assets/maskable-icon.png", "sizes": "512x512", "type": "image/png", "purpose": "any"}, {"src": "assets/maskable-icon.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}, {"src": "assets/apple-touch-icon-180x180.png", "sizes": "180x180", "type": "image/png"}, {"src": "assets/favicon-32x32.png", "sizes": "32x32", "type": "image/png"}, {"src": "assets/favicon-16x16.png", "sizes": "16x16", "type": "image/png"}, ] open(MPATH, "w", encoding="utf-8").write(_json.dumps(mf, indent=2)) print("manifest: co-op identity set") except OSError: raise SystemExit(0) print("index.html: co-op branding + build marker injected")