ework-web 0.10.127 → 0.10.129

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ework-web",
3
- "version": "0.10.127",
3
+ "version": "0.10.129",
4
4
  "type": "module",
5
5
  "description": "ework-web — standalone multi-project issue tracker. Local SQLite-backed, no external API dependency. Bun + TypeScript + SSR HTML.",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -83,6 +83,8 @@ import {
83
83
  type ProjectRole,
84
84
  type UserRow,
85
85
  getIssueAiStatusByNumber,
86
+ getIssue,
87
+ getComment,
86
88
  } from "./store";
87
89
  import { startUpstreamSyncPoller } from "./upstream-sync";
88
90
  import {
@@ -420,6 +422,9 @@ const SESSION_BATCH_RE = /^\/api\/sessions\/([A-Za-z0-9_-]+)\/batch$/;
420
422
  const server = Bun.serve({
421
423
  port: cfg.port,
422
424
  hostname: cfg.host,
425
+ // Streaming routes (translate, live tails) legitimately sit silent past the
426
+ // 10s default while upstream queues; 60s matches their in-route heartbeats.
427
+ idleTimeout: 60,
423
428
  async fetch(req, server) {
424
429
  const url = new URL(req.url);
425
430
  const ip = remoteAddr(req, server);
@@ -986,6 +991,24 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
986
991
  }
987
992
  }
988
993
 
994
+ if (req.method === "GET" && url.pathname === "/api/raw") {
995
+ const commentId = Number(url.searchParams.get("comment") ?? "");
996
+ const issueRef = url.searchParams.get("issue") ?? "";
997
+ if (Number.isInteger(commentId) && commentId > 0) {
998
+ const c = await getComment(commentId);
999
+ if (!c) return json({ error: "not found" }, 404);
1000
+ return json({ body: c.body });
1001
+ }
1002
+ const m = issueRef.match(/^([\w.-]+)\/([\w.-]+)\/(\d+)$/);
1003
+ if (m) {
1004
+ const project = await getProject(m[1] ?? "", m[2] ?? "");
1005
+ if (!project) return json({ error: "not found" }, 404);
1006
+ const issue = await getIssue(project.id, Number(m[3] ?? ""));
1007
+ if (!issue) return json({ error: "not found" }, 404);
1008
+ return json({ body: issue.body ?? "" });
1009
+ }
1010
+ return json({ error: "comment or issue required" }, 400);
1011
+ }
989
1012
  if (req.method === "POST" && url.pathname === "/api/translate") {
990
1013
  if (!rateLimit(`translate:${ip}`, 10, 10 / 60)) return json({ error: "rate limited" }, 429);
991
1014
  try {
@@ -1009,6 +1032,16 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
1009
1032
  async start(controller) {
1010
1033
  const enc = new TextEncoder();
1011
1034
  const send = (obj: unknown) => controller.enqueue(enc.encode(JSON.stringify(obj) + "\n"));
1035
+ // Bun closes connections idle >10s by default; under model-server load
1036
+ // the first translation chunk can queue longer than that. Heartbeat
1037
+ // lines ({"s":1}) keep the connection alive and are ignored by clients.
1038
+ const heartbeat = setInterval(() => {
1039
+ try {
1040
+ send({ s: 1 });
1041
+ } catch {
1042
+ /* client disconnected */
1043
+ }
1044
+ }, 5000);
1012
1045
  try {
1013
1046
  let full = "";
1014
1047
  for await (const chunk of translateTextStream(cfg, text)) {
@@ -1019,6 +1052,7 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
1019
1052
  } catch (e) {
1020
1053
  send({ e: e instanceof Error ? e.message : String(e) });
1021
1054
  } finally {
1055
+ clearInterval(heartbeat);
1022
1056
  controller.close();
1023
1057
  }
1024
1058
  },
package/src/static/app.js CHANGED
@@ -319,11 +319,27 @@
319
319
  });
320
320
  }
321
321
 
322
+ // Raw markdown beats innerText as translation source: the rendered DOM has
323
+ // lost fences/emphasis/list markers, so translating it flattens formatting.
324
+ async function rawSource(btn, root) {
325
+ const item = btn.closest(".item");
326
+ if (item && item.dataset.id) {
327
+ const r = await fetch("/api/raw?comment=" + encodeURIComponent(item.dataset.id));
328
+ if (r.ok) return ((await r.json())?.body ?? "").trim();
329
+ }
330
+ const m = location.pathname.match(/^\/([^/]+)\/([^/]+)\/issues\/(\d+)/);
331
+ if (m) {
332
+ const r = await fetch("/api/raw?issue=" + encodeURIComponent(m[1] + "/" + m[2] + "/" + m[3]));
333
+ if (r.ok) return ((await r.json())?.body ?? "").trim();
334
+ }
335
+ return root.innerText.trim();
336
+ }
337
+
322
338
  async function doTranslate(btn) {
323
339
  const root = actionRoot(btn);
324
340
  if (!root) return;
325
341
  if (btn.dataset.tr === "1") { btn.dataset.tr = "0"; btn.textContent = "翻译"; root.innerHTML = btn.dataset.orig; return; }
326
- const text = root.innerText.trim();
342
+ const text = await rawSource(btn, root);
327
343
  if (!text) return;
328
344
  if (!btn.dataset.orig) btn.dataset.orig = root.innerHTML;
329
345
  btn.textContent = "⏳";