PWA, one send/stop button, audio in and out, web search as a tool
Four pieces of work.
**Installable.** A manifest carrying the instance name, PWA icons rasterised
from the existing mark at design time, a service worker and a themed offline
page. The worker caches the shell only and bails out on /api/, /auth/, /admin/
and anything accepting text/event-stream -- passing a reply stream through a
worker turns it into one delivery at the end, or nothing. It is served from
GET /sw.js rather than the static mount because a worker's scope is the path it
came from.
**Send and Stop are one button.** They were two, and the hidden one was never
hidden: `.btn` is display: inline-flex, which outranks the browser's own
`[hidden] { display: none }`, so Stop sat permanently beside Send. app.css now
forces the attribute to win -- every control toggled with `hidden` depended on
that -- and the composer renders one button carrying both icons, with ui.js
flipping data-composer-action and the type with it.
**Audio.** Speech to text and text to speech against any OpenAI-shaped
/v1/audio/* endpoint: dictate into the composer, have a reply read out.
Instance settings in Admin, per-reader overrides in Settings, with the voice
list discovered from the server where it offers one. Recorded audio is capped
and never written to disk -- it is not an attachment, it has no owner, and
nothing would ever sweep it.
**Web search, as a tool.** This is the tool loop PLAN.md described as the real
work: one reply is now a bounded sequence of requests rather than one. The model
asks, the tool runs, the result goes back and it is asked again, up to three
rounds. Providers are DuckDuckGo (no setup), SearXNG and Firecrawl.
Two decisions worth stating. Tools are only offered to models flagged `tools`,
because an endpoint without support rejects the whole request rather than
ignoring the array -- the same reason images only reach models flagged
`vision`. And tool results are not replayed as context on the next turn, for the
same reasons reasoning is not: the answer already contains what the model made
of them, and replaying stale results into every later request wastes the window
and reliably sends a small model into a search loop. The sources stay visible in
the transcript instead.
Search results are untrusted third-party text and are treated as such: escaped,
and only http/https URLs rendered as links.
338 tests, ruff clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,14 @@ are extracted, as a static drawing -- no font binary is redistributed.
|
||||
This is a design-time tool. The application never imports it, and the generated
|
||||
files are committed. Re-run it only when the artwork itself changes:
|
||||
|
||||
pip install fonttools
|
||||
pip install fonttools cairosvg
|
||||
python scripts/build_artwork.py
|
||||
|
||||
cairosvg is needed only for the PWA icons, which have to be PNG: an installed
|
||||
web app's icon is drawn by the operating system's launcher, and neither
|
||||
Android's adaptive-icon masking nor iOS's home screen will take an SVG. The
|
||||
rasterisation happens here, once, and the PNGs are committed like everything
|
||||
else -- the running application still has no build step and no rasteriser.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -39,7 +45,15 @@ STATIC_IMG = ROOT / "src" / "lembas" / "web" / "static" / "img"
|
||||
|
||||
# assets/ holds the design masters; the application serves its own copies from
|
||||
# static/. These are the few the running app actually needs.
|
||||
SERVED_BY_APP = ("favicon.svg", "logo-mark.svg", "banner.svg")
|
||||
SERVED_BY_APP = (
|
||||
"favicon.svg",
|
||||
"logo-mark.svg",
|
||||
"banner.svg",
|
||||
"icon-192.png",
|
||||
"icon-512.png",
|
||||
"icon-maskable-512.png",
|
||||
"apple-touch-icon-180.png",
|
||||
)
|
||||
|
||||
FONT_SEMIBOLD = Path("/usr/share/fonts/adobe-source-serif/SourceSerif4Display-Semibold.otf")
|
||||
FONT_ITALIC = Path("/usr/share/fonts/adobe-source-serif/SourceSerif4Display-It.otf")
|
||||
@@ -321,6 +335,66 @@ def build_lockup() -> str:
|
||||
"""
|
||||
|
||||
|
||||
# --- PWA icons ---------------------------------------------------------------
|
||||
# Same geometry as everything else, rasterised because a launcher icon has to
|
||||
# be a bitmap. Two shapes are needed, not one:
|
||||
#
|
||||
# "any" -- drawn as supplied, so the wafer's own rounded square is the
|
||||
# silhouette and the corners stay transparent.
|
||||
# "maskable" -- Android crops it to a circle, squircle or rounded square of
|
||||
# the launcher's choosing, so the art must be full-bleed and
|
||||
# the mark must sit inside the central safe zone. An "any"
|
||||
# icon used as maskable gets its corners sliced off.
|
||||
#
|
||||
# The Apple icon is opaque for a different reason: iOS composites a home screen
|
||||
# icon onto black, so transparency reads as a black tile rather than as the
|
||||
# wallpaper showing through.
|
||||
def _framed_mark(prefix: str, *, background: str | None = None, inset: float = 0.0) -> str:
|
||||
"""The mark on a 64x64 canvas, optionally opaque and inset from the edges."""
|
||||
size = 64.0
|
||||
offset = size * inset
|
||||
scale = 1.0 - inset * 2
|
||||
plate = f' <rect width="{size:.0f}" height="{size:.0f}" fill="{background}"/>\n'
|
||||
return f"""{HEADER} viewBox="0 0 64 64" width="64" height="64"
|
||||
role="img" aria-label="LLeMbas">
|
||||
{mark_defs(prefix)}
|
||||
{plate if background else ""} <g transform="translate({offset:.3f} {offset:.3f}) \
|
||||
scale({scale:.4f})">
|
||||
{mark_body(prefix)}
|
||||
</g>
|
||||
</svg>
|
||||
"""
|
||||
|
||||
|
||||
def _rasterise(svg: str, size: int) -> bytes:
|
||||
try:
|
||||
import cairosvg
|
||||
except ImportError: # pragma: no cover - design-time tool
|
||||
sys.exit("cairosvg is required for the PWA icons: pip install cairosvg")
|
||||
return cairosvg.svg2png(
|
||||
bytestring=svg.encode("utf-8"), output_width=size, output_height=size
|
||||
)
|
||||
|
||||
|
||||
def build_icon_192() -> bytes:
|
||||
return _rasterise(_framed_mark("i192"), 192)
|
||||
|
||||
|
||||
def build_icon_512() -> bytes:
|
||||
return _rasterise(_framed_mark("i512"), 512)
|
||||
|
||||
|
||||
def build_icon_maskable() -> bytes:
|
||||
# 20% inset leaves the mark inside the central 60%, comfortably within the
|
||||
# 80% safe circle every launcher mask respects.
|
||||
return _rasterise(_framed_mark("imask", background=NIGHT_MID, inset=0.20), 512)
|
||||
|
||||
|
||||
def build_apple_touch_icon() -> bytes:
|
||||
# iOS rounds the corners itself, so only a hairline of padding is wanted.
|
||||
return _rasterise(_framed_mark("iios", background=NIGHT_MID, inset=0.06), 180)
|
||||
|
||||
|
||||
def _mountains(width: float, base_y: float, seed: int, height: float, colour: str) -> str:
|
||||
"""One jagged ridge line spanning the full width."""
|
||||
rng = random.Random(seed)
|
||||
@@ -458,6 +532,10 @@ BUILDERS = {
|
||||
"wordmark.svg": build_wordmark,
|
||||
"logo-lockup.svg": build_lockup,
|
||||
"banner.svg": build_banner,
|
||||
"icon-192.png": build_icon_192,
|
||||
"icon-512.png": build_icon_512,
|
||||
"icon-maskable-512.png": build_icon_maskable,
|
||||
"apple-touch-icon-180.png": build_apple_touch_icon,
|
||||
}
|
||||
|
||||
|
||||
@@ -472,13 +550,16 @@ def main() -> None:
|
||||
|
||||
for filename in args.only or BUILDERS:
|
||||
content = BUILDERS[filename]()
|
||||
# The PNG builders return bytes; everything else returns SVG source.
|
||||
data = content if isinstance(content, bytes) else content.encode("utf-8")
|
||||
|
||||
path = args.out / filename
|
||||
path.write_text(content, encoding="utf-8")
|
||||
print(f"wrote {path.relative_to(ROOT)} ({len(content.encode()):,} bytes)")
|
||||
path.write_bytes(data)
|
||||
print(f"wrote {path.relative_to(ROOT)} ({len(data):,} bytes)")
|
||||
|
||||
if filename in SERVED_BY_APP:
|
||||
served = STATIC_IMG / filename
|
||||
served.write_text(content, encoding="utf-8")
|
||||
served.write_bytes(data)
|
||||
print(f" -> {served.relative_to(ROOT)}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user