cc-viewer 1.9.20 → 1.9.21

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/dist/index.html CHANGED
@@ -21,7 +21,7 @@
21
21
  // 整体显示大小已弃用 CSS zoom:Electron 改用 webFrame.setZoomFactor(首屏抢占见
22
22
  // electron/tab-content-preload.js),纯浏览器交由用户用浏览器自带快捷键缩放,故此处不再设 zoom。
23
23
  </script>
24
- <script type="module" crossorigin src="./assets/index-C8223pn2.js"></script>
24
+ <script type="module" crossorigin src="./assets/index-CocpEURl.js"></script>
25
25
  <link rel="modulepreload" crossorigin href="./assets/vendor-antd-I6I2F7Rv.js">
26
26
  <link rel="modulepreload" crossorigin href="./assets/vendor-codemirror-Zkm6UHQg.js">
27
27
  <link rel="modulepreload" crossorigin href="./assets/vendor-mdxeditor-CC09MDyZ.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-viewer",
3
- "version": "1.9.20",
3
+ "version": "1.9.21",
4
4
  "description": "Claude Code logging, visualization, and management toolkit — launch a web viewer alongside Claude Code with full request/response tracing, proxy, and mobile support",
5
5
  "license": "MIT",
6
6
  "main": "server.js",
package/server/proxy.js CHANGED
@@ -378,12 +378,17 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
378
378
  clientAbort.signal.addEventListener('abort', clearSlowTimer, { once: true });
379
379
  // The timer measures time-to-HEADERS (fetch resolves at headers). Keep it armed
380
380
  // until the first BODY chunk so a headers-fast-then-stalled stream still counts
381
- // as slow (review P2-3); the finally below stays as the cleanup backstop.
381
+ // as slow (review P1-2). markFirstByte is the real settle point: it disarms the
382
+ // timer AND emits resolved; the finally below is only an error-path backstop
383
+ // (executeRequest resolves at headers, so clearing there would defeat this).
382
384
  let slowFirstByteSeen = false;
383
385
  const markFirstByte = () => {
384
386
  if (slowFirstByteSeen) return;
385
387
  slowFirstByteSeen = true;
386
388
  clearSlowTimer();
389
+ if (slowFired) {
390
+ __testing.emit({ type: 'resolved', requestId: slowReqId, cwd: slowCwd, instanceKey: slowInstance });
391
+ }
387
392
  };
388
393
 
389
394
  // 执行带重试的请求
@@ -404,11 +409,15 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
404
409
  },
405
410
  });
406
411
  } finally {
407
- clearSlowTimer();
408
- // If the advisory fired, tell the UI the wait is over so the persistent
409
- // toast is dismissed instead of lingering past completion.
410
- if (slowFired) {
411
- __testing.emit({ type: 'resolved', requestId: slowReqId, cwd: slowCwd, instanceKey: slowInstance });
412
+ // Error-path backstop ONLY: executeRequest resolved at headers, so a success
413
+ // path must NOT clear here — the timer stays armed until the first body chunk
414
+ // (markFirstByte). Clear+resolve only when no usable response came back
415
+ // (network error / aborted / no response object) so the advisory never leaks.
416
+ if (slowFirstByteSeen || !result || !result.response) {
417
+ clearSlowTimer();
418
+ if (slowFired) {
419
+ __testing.emit({ type: 'resolved', requestId: slowReqId, cwd: slowCwd, instanceKey: slowInstance });
420
+ }
412
421
  }
413
422
  }
414
423
 
@@ -463,6 +472,7 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
463
472
 
464
473
  // 网络异常(finalStatus=0)或竞速全失败:返回 502 + Proxy Error,与原 catch 分支一致
465
474
  if (finalStatus === 0) {
475
+ markFirstByte(); // settle the advisory on a hard network failure
466
476
  res.writeHead(502, { 'x-forward-attempts': String(attempts) });
467
477
  res.end('Proxy Error');
468
478
  return;
@@ -474,11 +484,12 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
474
484
  if (response.body) {
475
485
  // @ts-ignore
476
486
  const nodeStream = Readable.fromWeb(response.body);
477
- nodeStream.on('error', () => {});
478
- // First body byte arrived → the upstream is no longer "slow"; stop the
479
- // advisory timer. Headers alone don't count (a headers-fast-then-stalled
480
- // SSE stream is exactly the silent case we want to surface).
487
+ // First body chunk → the wait is over. Also settle if the body errors or
488
+ // closes before any byte (client abort / stalled-then-closed stream), so the
489
+ // advisory never leaks past a terminal stream state.
490
+ nodeStream.on('error', markFirstByte);
481
491
  nodeStream.once('data', markFirstByte);
492
+ nodeStream.once('close', markFirstByte);
482
493
  const streamIdleMs = retryConfig && retryConfig.mode === 'off'
483
494
  ? (retryConfig.streamIdleTimeoutMs ?? 0)
484
495
  : 0;
@@ -530,10 +541,13 @@ async function handleLlmApiRequest(req, res, fullUrl, fetchOptions, body, proxyD
530
541
  });
531
542
  }
532
543
  } else if (response.text) {
533
- // 竞速失败兜底 response:用 text() 取 body
544
+ // 竞速失败兜底 response:用 text() 取 body —— a fully-read non-stream body
545
+ // means the wait is over.
534
546
  const text = await response.text();
547
+ markFirstByte();
535
548
  res.end(text);
536
549
  } else {
550
+ markFirstByte(); // no body at all — settle the advisory
537
551
  res.end();
538
552
  }
539
553
  }
package/server/server.js CHANGED
@@ -524,15 +524,21 @@ setSlowUpstreamListener(({ type, requestId, cwd, instanceKey, waitingMs, model }
524
524
  const sess = instanceKey
525
525
  ? (sessions.find(s => s.instanceKey === instanceKey) || null)
526
526
  : (sessions.find(s => cwd && s.cwd === cwd) || null);
527
- if (!sess) return;
528
527
  if (type === 'resolved') {
529
- // The waited-on request settled — tell the UI to dismiss the toast.
528
+ // The waited-on request settled — tell the UI to dismiss the toast. A
529
+ // request can settle AFTER its session closed (review P2-2): the session
530
+ // lookup then misses and the dismiss would be silently dropped, leaving a
531
+ // stuck toast. Fall back to the request's own self-reported cwd/instanceKey
532
+ // so the dismiss always reaches the workspace that was told to wait.
533
+ const rcwd = sess ? sess.cwd : cwd;
534
+ const rinst = sess ? (sess.instanceKey || null) : (instanceKey || null);
530
535
  broadcastWsMessage({
531
- type: 'sdk-slow-upstream-resolved', cwd: sess.cwd, project: projectKeyForCwd(sess.cwd),
532
- instanceKey: sess.instanceKey || null, requestId: requestId || null, ts: Date.now(),
536
+ type: 'sdk-slow-upstream-resolved', cwd: rcwd, project: projectKeyForCwd(rcwd),
537
+ instanceKey: rinst, requestId: requestId || null, ts: Date.now(),
533
538
  });
534
539
  return;
535
540
  }
541
+ if (!sess) return;
536
542
  broadcastWsMessage({
537
543
  type: 'sdk-slow-upstream', cwd: sess.cwd, project: projectKeyForCwd(sess.cwd),
538
544
  instanceKey: sess.instanceKey || null, requestId: requestId || null, waitingMs, model: model || null, ts: Date.now(),