@bivy/bivy 0.18.9-staging.7 → 0.18.9-staging.9

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.
@@ -13,13 +13,7 @@ import { displayViewer, DISPLAY_MENU_PATH, DISPLAY_SOCKET_PATH, DISPLAY_STATS_PA
13
13
  import { pressMenu, readMenuPath, readMenus } from "./menu.js";
14
14
  import { inspectorScript } from "./inspector.js";
15
15
  import { readStrokes, readElementScrolls } from "./annotate.js";
16
- const MIME = {
17
- ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8",
18
- ".css": "text/css; charset=utf-8", ".json": "application/json", ".svg": "image/svg+xml", ".png": "image/png",
19
- ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp", ".ico": "image/x-icon",
20
- ".woff": "font/woff", ".woff2": "font/woff2", ".ttf": "font/ttf", ".wasm": "application/wasm",
21
- ".txt": "text/plain; charset=utf-8", ".pdf": "application/pdf", ".mp4": "video/mp4", ".webm": "video/webm",
22
- };
16
+ import { contentType } from "./mime.js";
23
17
  const COOKIE = "__Host-bivy-preview";
24
18
  const OPEN_PATH = "/__bivy/open";
25
19
  const REDEEM_PATH = "/__bivy/redeem";
@@ -534,7 +528,7 @@ fetch('${REDEEM_PATH}',{method:'POST',headers:{'Content-Type':'text/plain'},body
534
528
  return;
535
529
  }
536
530
  const headers = responseHeaders({}, this.ancestors(id));
537
- headers["content-type"] = MIME[path.extname(file).toLowerCase()] || "application/octet-stream";
531
+ headers["content-type"] = contentType(file);
538
532
  if (inspect && path.extname(file).toLowerCase() === ".html" && data.length <= MAX_INJECT_BYTES)
539
533
  data = withInspector(data);
540
534
  sendBytes(req, res, status, headers, data);
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 Petter André Sjulstad
3
+ import path from "node:path";
4
+ /** Content types for files a static app view serves. Browsers refuse module
5
+ * scripts (and some stylesheets) without the right one, so every server of a
6
+ * static snapshot — the preview gateway and the screenshot loopback — uses this. */
7
+ const MIME = {
8
+ ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8",
9
+ ".css": "text/css; charset=utf-8", ".json": "application/json", ".svg": "image/svg+xml", ".png": "image/png",
10
+ ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp", ".ico": "image/x-icon",
11
+ ".woff": "font/woff", ".woff2": "font/woff2", ".ttf": "font/ttf", ".wasm": "application/wasm",
12
+ ".txt": "text/plain; charset=utf-8", ".pdf": "application/pdf", ".mp4": "video/mp4", ".webm": "video/webm",
13
+ };
14
+ export function contentType(file) {
15
+ return MIME[path.extname(file).toLowerCase()] || "application/octet-stream";
16
+ }
@@ -7,6 +7,7 @@ import http from "node:http";
7
7
  import { once } from "node:events";
8
8
  import { spawn, execFileSync } from "node:child_process";
9
9
  import { WebSocket } from "ws";
10
+ import { contentType } from "./mime.js";
10
11
  import { captureFrame, encodePng } from "./rfb.js";
11
12
  /** Browsers tried in order; BIVY_CHROME overrides. Any Chromium works. */
12
13
  const CANDIDATES = [
@@ -45,12 +46,14 @@ async function serveSnapshot(files) {
45
46
  let file = decodeURIComponent((req.url ?? "/").split("?")[0]);
46
47
  if (file.endsWith("/"))
47
48
  file += "index.html";
48
- const data = files.get(file) ?? (path.extname(file) ? undefined : files.get("/index.html"));
49
+ const name = files.has(file) || path.extname(file) ? file : "/index.html";
50
+ const data = files.get(name);
49
51
  if (!data) {
50
52
  res.writeHead(404);
51
53
  res.end();
52
54
  return;
53
55
  }
56
+ res.writeHead(200, { "content-type": contentType(name) });
54
57
  res.end(data);
55
58
  });
56
59
  server.listen(0, "127.0.0.1");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bivy/bivy",
3
- "version": "0.18.9-staging.7",
3
+ "version": "0.18.9-staging.9",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0-only",
6
6
  "description": "Run coding agents on machines you own. Open-source, self-hostable agent workspace.",