teapot-coding-agent 0.15.3 → 0.15.4

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.
@@ -45,6 +45,43 @@ async function listModels(baseUrl, apiKey) {
45
45
  import path from "node:path";
46
46
  import { bus } from "../bus.js";
47
47
  import { readEvents } from "../log/events.js";
48
+ /** media categories the file tree can preview inline */
49
+ const IMAGE_EXT = new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "bmp", "ico", "avif"]);
50
+ const VIDEO_EXT = new Set(["mp4", "webm", "mov", "mkv", "avi", "m4v"]);
51
+ const AUDIO_EXT = new Set(["mp3", "wav", "ogg", "m4a", "flac", "aac", "opus"]);
52
+ function mediaKind(p) {
53
+ const ext = p.split(".").pop()?.toLowerCase() ?? "";
54
+ if (IMAGE_EXT.has(ext))
55
+ return "image";
56
+ if (VIDEO_EXT.has(ext))
57
+ return "video";
58
+ if (AUDIO_EXT.has(ext))
59
+ return "audio";
60
+ return null;
61
+ }
62
+ /** extension → MIME (used for the media preview endpoint) */
63
+ export const MEDIA_MIME = (() => {
64
+ const m = {};
65
+ for (const e of IMAGE_EXT)
66
+ m[e] = `image/${e === "jpg" ? "jpeg" : e}`;
67
+ Object.assign(m, { svg: "image/svg+xml", ico: "image/x-icon", avif: "image/avif" });
68
+ for (const e of VIDEO_EXT)
69
+ m[e] = `video/${e === "mov" ? "quicktime" : e === "mkv" ? "x-matroska" : e}`;
70
+ for (const e of AUDIO_EXT)
71
+ m[e] = `audio/${e}`;
72
+ Object.assign(m, { m4a: "audio/mp4", mp3: "audio/mpeg" });
73
+ return m;
74
+ })();
75
+ /** category → generic fallback when no specific extension match exists */
76
+ const KIND_MIME = {
77
+ image: "application/octet-stream",
78
+ video: "application/octet-stream",
79
+ audio: "application/octet-stream",
80
+ };
81
+ function mimeFor(rel, kind) {
82
+ const ext = rel.split(".").pop()?.toLowerCase() ?? "";
83
+ return MEDIA_MIME[ext] ?? KIND_MIME[kind];
84
+ }
48
85
  export function buildApp(master) {
49
86
  const app = new Hono();
50
87
  // Optional bearer auth for LAN exposure — TEAPOT_API_TOKEN env wins, else
@@ -328,6 +365,44 @@ export function buildApp(master) {
328
365
  path: rel,
329
366
  truncated: buf.length > 100_000,
330
367
  content: buf.subarray(0, 100_000).toString("utf8"),
368
+ media: mediaKind(rel),
369
+ });
370
+ }
371
+ catch (err) {
372
+ return c.json({ error: err.message }, 400);
373
+ }
374
+ });
375
+ // raw bytes for media previews (images / video / audio) — auth-gated like
376
+ // every other agent route, workspace-confined, served with the right MIME
377
+ app.get("/api/agents/:id/raw", async (c) => {
378
+ const a = master.agents.get(c.req.param("id"));
379
+ if (!a)
380
+ return c.json({ error: "not found" }, 404);
381
+ const rel = c.req.query("path") ?? "";
382
+ if (!rel.trim())
383
+ return c.json({ error: "path required" }, 400);
384
+ let abs;
385
+ try {
386
+ abs = safeJoin(a.workspace, rel);
387
+ }
388
+ catch (err) {
389
+ return c.json({ error: err.message }, 400);
390
+ }
391
+ try {
392
+ const buf = await fs.readFile(abs);
393
+ const kind = mediaKind(rel);
394
+ if (!kind)
395
+ return c.json({ error: "not a previewable media file" }, 400);
396
+ if (buf.length > 200 * 1024 * 1024)
397
+ return c.json({ error: "file too large to preview (>200MB)" }, 413);
398
+ // hono-native body API — a raw `new Response(...)` returned here lost
399
+ // its headers somewhere in the middleware chain (content-type arrived
400
+ // as undefined), while c.body() passes them through correctly
401
+ return c.body(new Uint8Array(buf), 200, {
402
+ "content-type": mimeFor(rel, kind),
403
+ // previews only; the browser shouldn't cache stale workspace files
404
+ "cache-control": "no-store",
405
+ "content-disposition": `inline; filename="${encodeURIComponent(path.basename(rel))}"`,
331
406
  });
332
407
  }
333
408
  catch (err) {
@@ -781,7 +856,8 @@ export function buildApp(master) {
781
856
  const a = master.agents.get(c.req.param("id"));
782
857
  if (!a)
783
858
  return c.json({ error: "not found" }, 404);
784
- const events = await readEvents(a.log.filePath);
859
+ // cached like /events — this used to bypass it and re-read the whole log
860
+ const events = await readEventsCached(a.log.filePath);
785
861
  const branches = new Map();
786
862
  for (const e of events) {
787
863
  const b = branches.get(e.branch) ?? { branch: e.branch, events: 0 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.15.3",
3
+ "version": "0.15.4",
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",