teapot-coding-agent 0.34.10 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1568,6 +1568,85 @@ export function buildApp(master) {
1568
1568
  return c.notFound();
1569
1569
  }
1570
1570
  });
1571
+ /**
1572
+ * Theme background images, stored SERVER-side.
1573
+ *
1574
+ * These used to live in `localStorage` as a data URI, which forced a hard 1.5MB cap: the quota
1575
+ * is ~5MB for the WHOLE origin, so one wallpaper could brick every other setting the UI keeps
1576
+ * there (themes, panel state, session history). A 1.5MB limit is also absurdly small for a
1577
+ * photograph — the operator hits it with anything from a phone camera.
1578
+ *
1579
+ * Now the file is a FILE: uploaded once, referenced by name from the theme, and served back.
1580
+ * No quota, so no cap; the only limit is what the upload route is willing to read.
1581
+ *
1582
+ * Written by hand rather than with `serveStatic` because the API is awkward and this needs
1583
+ * three things it does not obviously give: a traversal-proof path, an immutable cache header,
1584
+ * and a name→file mapping that cannot escape the assets dir.
1585
+ */
1586
+ const assetsDir = path.join(master.config.dataDir, "assets");
1587
+ const assetName = (raw) => {
1588
+ // only the shapes we mint: hex + a known extension. Anything else cannot name a file here.
1589
+ const m = /^([a-f0-9]{32})\.(png|jpg|jpeg|gif|webp|avif)$/i.exec(raw);
1590
+ return m ? `${m[1].toLowerCase()}.${m[2].toLowerCase()}` : null;
1591
+ };
1592
+ const assetMime = {
1593
+ png: "image/png",
1594
+ jpg: "image/jpeg",
1595
+ jpeg: "image/jpeg",
1596
+ gif: "image/gif",
1597
+ webp: "image/webp",
1598
+ avif: "image/avif",
1599
+ };
1600
+ app.get("/api/assets/:name", async (c) => {
1601
+ const name = assetName(c.req.param("name") ?? "");
1602
+ if (!name)
1603
+ return c.notFound();
1604
+ const ext = name.split(".").pop();
1605
+ try {
1606
+ const buf = await fs.readFile(path.join(assetsDir, name));
1607
+ return c.body(buf, 200, {
1608
+ "content-type": assetMime[ext] ?? "application/octet-stream",
1609
+ // the name is a content hash-ish id and never reused, so it can be cached forever
1610
+ "cache-control": "public, max-age=31536000, immutable",
1611
+ });
1612
+ }
1613
+ catch {
1614
+ return c.notFound();
1615
+ }
1616
+ });
1617
+ app.post("/api/assets", async (c) => {
1618
+ /**
1619
+ * Accepts the raw image body, not a multipart form.
1620
+ *
1621
+ * The client already holds a `File`; `fetch(url, {body: file})` sends its bytes directly, so
1622
+ * there is no parser, no boundary handling and no temp file. The extension comes from the
1623
+ * content type, which keeps the stored name within `assetName`'s accepted set.
1624
+ */
1625
+ const type = (c.req.header("content-type") ?? "").split(";")[0].trim().toLowerCase();
1626
+ const ext = Object.entries(assetMime).find(([, m]) => m === type)?.[0];
1627
+ if (!ext) {
1628
+ return c.json({ error: `unsupported image type: ${type || "(none)"}` }, 415);
1629
+ }
1630
+ const buf = Buffer.from(await c.req.arrayBuffer());
1631
+ if (!buf.length)
1632
+ return c.json({ error: "empty body" }, 400);
1633
+ // a sanity ceiling, not a UX limit: it exists so one request cannot fill the disk
1634
+ const MAX_UPLOAD = 64 * 1024 * 1024;
1635
+ if (buf.length > MAX_UPLOAD) {
1636
+ return c.json({ error: `image is larger than ${MAX_UPLOAD / 1024 / 1024}MB` }, 413);
1637
+ }
1638
+ await fs.mkdir(assetsDir, { recursive: true });
1639
+ const name = `${crypto.randomUUID().replace(/-/g, "")}.${ext}`;
1640
+ await fs.writeFile(path.join(assetsDir, name), buf);
1641
+ return c.json({ name, url: `/api/assets/${name}`, bytes: buf.length });
1642
+ });
1643
+ app.delete("/api/assets/:name", async (c) => {
1644
+ const name = assetName(c.req.param("name") ?? "");
1645
+ if (!name)
1646
+ return c.notFound();
1647
+ await fs.rm(path.join(assetsDir, name), { force: true }).catch(() => { });
1648
+ return c.json({ ok: true });
1649
+ });
1571
1650
  return app;
1572
1651
  }
1573
1652
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.34.10",
3
+ "version": "0.35.0",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",