newpr 1.0.10 → 1.0.11

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": "newpr",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "AI-powered large PR review tool - understand PRs with 1000+ lines of changes",
5
5
  "module": "src/cli/index.ts",
6
6
  "type": "module",
@@ -953,9 +953,22 @@ Before posting an inline comment, ALWAYS call \`get_file_diff\` first to find th
953
953
  const encoder = new TextEncoder();
954
954
  const stream = new ReadableStream({
955
955
  async start(controller) {
956
+ let closed = false;
956
957
  const send = (eventType: string, data: string) => {
958
+ if (closed) return;
957
959
  controller.enqueue(encoder.encode(`event: ${eventType}\ndata: ${data}\n\n`));
958
960
  };
961
+ const safeClose = () => {
962
+ if (closed) return;
963
+ closed = true;
964
+ clearInterval(heartbeat);
965
+ setTimeout(() => { try { controller.close(); } catch {} }, 50);
966
+ };
967
+ const heartbeat = setInterval(() => {
968
+ if (closed) return;
969
+ try { controller.enqueue(encoder.encode(":keepalive\n\n")); } catch { safeClose(); }
970
+ }, 15_000);
971
+
959
972
  try {
960
973
  if (config.openrouter_api_key) {
961
974
  await chatWithTools(
@@ -999,7 +1012,7 @@ Before posting an inline comment, ALWAYS call \`get_file_diff\` first to find th
999
1012
  } catch (err) {
1000
1013
  send("chat_error", JSON.stringify({ message: err instanceof Error ? err.message : String(err) }));
1001
1014
  } finally {
1002
- controller.close();
1015
+ safeClose();
1003
1016
  }
1004
1017
  },
1005
1018
  });
@@ -1424,9 +1437,21 @@ Before posting an inline comment, ALWAYS call \`get_file_diff\` first to find th
1424
1437
  const encoder = new TextEncoder();
1425
1438
  const stream = new ReadableStream({
1426
1439
  async start(controller) {
1440
+ let closed = false;
1427
1441
  const send = (eventType: string, data: string) => {
1442
+ if (closed) return;
1428
1443
  controller.enqueue(encoder.encode(`event: ${eventType}\ndata: ${data}\n\n`));
1429
1444
  };
1445
+ const safeClose = () => {
1446
+ if (closed) return;
1447
+ closed = true;
1448
+ clearInterval(heartbeat);
1449
+ setTimeout(() => { try { controller.close(); } catch {} }, 50);
1450
+ };
1451
+ const heartbeat = setInterval(() => {
1452
+ if (closed) return;
1453
+ try { controller.enqueue(encoder.encode(":keepalive\n\n")); } catch { safeClose(); }
1454
+ }, 15_000);
1430
1455
 
1431
1456
  let fullText = "";
1432
1457
  const collectedToolCalls: ChatToolCall[] = [];
@@ -1526,7 +1551,7 @@ Before posting an inline comment, ALWAYS call \`get_file_diff\` first to find th
1526
1551
  } catch (err) {
1527
1552
  send("chat_error", JSON.stringify({ message: err instanceof Error ? err.message : String(err) }));
1528
1553
  } finally {
1529
- controller.close();
1554
+ safeClose();
1530
1555
  }
1531
1556
  },
1532
1557
  });