vanspod 0.1.2 → 0.2.0

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.proxyError = proxyError;
4
4
  exports.isCodexSearch = isCodexSearch;
5
5
  exports.sendRouter = sendRouter;
6
+ exports.forwardRouter = forwardRouter;
6
7
  exports.relayResponse = relayResponse;
7
8
  const adapters_1 = require("./adapters");
8
9
  const types_1 = require("./adapters/types");
@@ -19,7 +20,18 @@ function proxyError(client, message, status) {
19
20
  function isCodexSearch(client, path) {
20
21
  return client === "codex" && (path ?? "").split("?")[0].endsWith("/alpha/search");
21
22
  }
22
- async function sendRouter(upstream, baseUrl) {
23
+ function redact(text, apiKey) {
24
+ return apiKey ? text.split(apiKey).join("[redacted]") : text;
25
+ }
26
+ function redactBody(body, apiKey) {
27
+ return apiKey ? JSON.parse(redact(JSON.stringify(body), apiKey)) : body;
28
+ }
29
+ // Prompt Capture sees the body each request sends to Router, never its headers or the Classroom API Key.
30
+ function recordUpstream(capture, upstream, adapter, raw) {
31
+ return (path, sent, options) => capture.record({ client: upstream.client, adapter, path,
32
+ sent: redactBody(sent, upstream.apiKey), raw: redactBody(raw, upstream.apiKey), ...options });
33
+ }
34
+ async function sendRouter(upstream, baseUrl, capture) {
23
35
  const client = upstream.client === "claude" ? "claude" : "codex";
24
36
  try {
25
37
  const path = upstream.path ?? "";
@@ -42,6 +54,8 @@ async function sendRouter(upstream, baseUrl) {
42
54
  const request = { client, model: upstream.model, body: parsed,
43
55
  apiKey: upstream.apiKey ?? "", routerBaseUrl: baseUrl.replace(/\/+$/, ""), headers: upstream.headers,
44
56
  signal: upstream.signal ?? new AbortController().signal };
57
+ if (capture)
58
+ request.record = recordUpstream(capture, upstream, adapter.id, parsed);
45
59
  // Claude Code searches inside a model request: Router runs the searches, not the model upstream.
46
60
  const response = (0, claudeWebSearch_1.declaresWebSearch)(request) ? await (0, claudeWebSearch_1.claudeWebSearch)(adapter, request) : await adapter.send(request);
47
61
  if (response.ok)
@@ -54,9 +68,7 @@ async function sendRouter(upstream, baseUrl) {
54
68
  message += ` ${error.message}`;
55
69
  }
56
70
  catch { /* HTTP status remains useful without exposing an arbitrary upstream body. */ }
57
- if (upstream.apiKey)
58
- message = message.split(upstream.apiKey).join("[redacted]");
59
- return proxyError(client, message, response.status);
71
+ return proxyError(client, redact(message, upstream.apiKey), response.status);
60
72
  }
61
73
  catch (error) {
62
74
  if (upstream.signal?.aborted)
@@ -64,6 +76,34 @@ async function sendRouter(upstream, baseUrl) {
64
76
  return proxyError(client, error instanceof types_1.AdapterError ? error.message : "上游沒有回應或回應格式無效。", error instanceof types_1.AdapterError ? error.status : 502);
65
77
  }
66
78
  }
79
+ // VS Code Chat already speaks the protocol Router expects: its body goes to Router as is,
80
+ // with only the model swapped for the Class Session model.
81
+ async function forwardRouter(upstream, baseUrl, capture) {
82
+ const path = upstream.path ?? "";
83
+ let raw;
84
+ try {
85
+ raw = JSON.parse(upstream.body ?? "");
86
+ }
87
+ catch {
88
+ raw = undefined;
89
+ }
90
+ const sent = raw && typeof raw === "object" && !Array.isArray(raw) ? { ...raw, model: upstream.model } : undefined;
91
+ const markFailed = capture && sent ? recordUpstream(capture, upstream, upstream.adapter ?? "chat", raw)(path, sent) : undefined;
92
+ try {
93
+ const response = await fetch(`${baseUrl.replace(/\/+$/, "")}${path}`, {
94
+ method: upstream.method ?? "POST",
95
+ headers: { "Content-Type": "application/json", ...(upstream.apiKey ? { Authorization: `Bearer ${upstream.apiKey}` } : {}) },
96
+ body: sent ? JSON.stringify(sent) : upstream.body,
97
+ signal: upstream.signal,
98
+ });
99
+ if (!response.ok)
100
+ markFailed?.(response.status);
101
+ return response;
102
+ }
103
+ catch {
104
+ return Response.json({ error: { message: "上游沒有回應。" } }, { status: 502 });
105
+ }
106
+ }
67
107
  async function relayResponse(response, res, client, signal) {
68
108
  const type = response.headers.get("content-type") ?? "application/json; charset=utf-8";
69
109
  res.writeHead(response.status, { "Content-Type": type, "Cache-Control": "no-store" });
@@ -1,42 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.modelStatusScript = void 0;
4
- exports.modelStatusScript = `
5
- async function refreshModelStatus() {
6
- try {
7
- if (!document.hidden && !settingsBusy) {
8
- var response = await fetch("/model-status", { cache: "no-store" });
9
- if (!response.ok) throw new Error("status unavailable");
10
- var status = await response.json();
11
- // A settings action redraws the whole page; never paint an older answer over it.
12
- if (!settingsBusy) applyModelStatus(status);
13
- }
14
- } catch (error) {}
15
- setTimeout(refreshModelStatus, 1000);
16
- }
17
- function applyModelStatus(status) {
18
- document.querySelectorAll("[data-client-light]").forEach(function (light) {
19
- var next = status.lights[light.getAttribute("data-client-light")];
20
- if (!next || (light.className === next.className && light.title === next.status)) return;
21
- light.className = next.className;
22
- light.title = next.status;
23
- light.setAttribute("aria-label", next.status);
24
- });
25
- if (status.traffic) document.querySelectorAll("[data-client-flow]").forEach(function (flow) {
26
- flow.classList.toggle("flowing", status.traffic[flow.getAttribute("data-client-flow")] === true);
27
- });
28
- var card = document.querySelector('[data-setting="模型"]');
29
- if (!card) return;
30
- var banner = card.querySelector(".model-update");
31
- var holder = document.createElement("template");
32
- holder.innerHTML = status.restart;
33
- var updated = holder.content.firstElementChild;
34
- if (typeof refreshClassroomRestart === 'function') refreshClassroomRestart(status.restart);
35
- if (document.querySelector('[data-classroom-restart]')) return;
36
- if (banner?.getAttribute("data-restart-clients") === updated?.getAttribute("data-restart-clients")) return;
37
- if (banner && updated) banner.replaceWith(updated);
38
- else if (banner) banner.remove();
39
- else if (updated) card.querySelector(".settings-actions").before(updated);
40
- }
41
- setTimeout(refreshModelStatus, 1000);
4
+ exports.modelStatusScript = `
5
+ async function refreshModelStatus() {
6
+ try {
7
+ if (!document.hidden && !settingsBusy) {
8
+ var response = await fetch("/model-status", { cache: "no-store" });
9
+ if (!response.ok) throw new Error("status unavailable");
10
+ var status = await response.json();
11
+ // A settings action redraws the whole page; never paint an older answer over it.
12
+ if (!settingsBusy) applyModelStatus(status);
13
+ }
14
+ } catch (error) {}
15
+ setTimeout(refreshModelStatus, 1000);
16
+ }
17
+ function applyModelStatus(status) {
18
+ document.querySelectorAll("[data-client-light]").forEach(function (light) {
19
+ var next = status.lights[light.getAttribute("data-client-light")];
20
+ if (!next || (light.className === next.className && light.title === next.status)) return;
21
+ light.className = next.className;
22
+ light.title = next.status;
23
+ light.setAttribute("aria-label", next.status);
24
+ });
25
+ if (status.traffic) document.querySelectorAll("[data-client-flow]").forEach(function (flow) {
26
+ flow.classList.toggle("flowing", status.traffic[flow.getAttribute("data-client-flow")] === true);
27
+ });
28
+ var card = document.querySelector('[data-setting="模型"]');
29
+ if (!card) return;
30
+ var banner = card.querySelector(".model-update");
31
+ var holder = document.createElement("template");
32
+ holder.innerHTML = status.restart;
33
+ var updated = holder.content.firstElementChild;
34
+ if (typeof refreshClassroomRestart === 'function') refreshClassroomRestart(status.restart);
35
+ if (document.querySelector('[data-classroom-restart]')) return;
36
+ if (banner?.getAttribute("data-restart-clients") === updated?.getAttribute("data-restart-clients")) return;
37
+ if (banner && updated) banner.replaceWith(updated);
38
+ else if (banner) banner.remove();
39
+ else if (updated) card.querySelector(".settings-actions").before(updated);
40
+ }
41
+ setTimeout(refreshModelStatus, 1000);
42
42
  `;
package/dist/page.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.modelStatus = modelStatus;
4
4
  exports.classroomBlocks = classroomBlocks;
5
5
  exports.renderPage = renderPage;
6
+ exports.renderInspectorPage = renderInspectorPage;
6
7
  const version_1 = require("./version");
7
8
  const appearance_1 = require("./appearance");
8
9
  const installProgress_1 = require("./installProgress");
@@ -12,6 +13,8 @@ const classroomUpdate_1 = require("./classroomUpdate");
12
13
  const connectionMascot_1 = require("./connectionMascot");
13
14
  const clientIcons_1 = require("./clientIcons");
14
15
  const environmentIcons_1 = require("./environmentIcons");
16
+ const promptCapture_1 = require("./promptCapture");
17
+ const inspectorView_1 = require("./inspectorView");
15
18
  const courseCatalog_1 = require("./courseCatalog");
16
19
  const PRODUCT = "VansPod";
17
20
  const VERSION = `v${version_1.VERSION}`;
@@ -556,7 +559,72 @@ function classroomBlocks(view) {
556
559
  stop: stopForm(),
557
560
  };
558
561
  }
559
- function basePage(view) {
562
+ const SIDE_PAGES = [
563
+ {
564
+ id: "settings",
565
+ href: "/",
566
+ label: "教室設定",
567
+ icon: `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m9.5 3-.6 2.3-2 .9-2.1-.6-2.5 4.3 1.5 1.7v2.3l-1.5 1.7 2.5 4.3 2.1-.6 2 .9.6 2.3h5l.6-2.3 2-.9 2.1.6 2.5-4.3-1.5-1.7v-2.3l1.5-1.7-2.5-4.3-2.1.6-2-.9L14.5 3z"/><circle cx="12" cy="12" r="3"/></svg>`,
568
+ },
569
+ {
570
+ id: "inspector",
571
+ href: "/prompt-inspector",
572
+ label: "Prompt 觀察室",
573
+ icon: `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="6.5"/><path d="m20 20-4.4-4.4M8 9.5h6M8 12.5h4"/></svg>`,
574
+ },
575
+ ];
576
+ const BRAND = `<div class="brand"><div class="logo-badge"><img src="/brand-logo.png" alt=""></div><h1 class="brand-title">${PRODUCT}</h1><span class="ver">${VERSION}</span></div>`;
577
+ /** 兩頁共用的側欄:行動版頂列、抽屜遮罩、選單與外觀切換。 */
578
+ function sideMenu(current) {
579
+ const items = SIDE_PAGES.map((page) => `<a class="side-item" href="${page.href}"${page.id === current ? ' aria-current="page"' : ""}>${page.icon}<span>${page.label}</span></a>`).join("");
580
+ return `<div class="mobile-top"><button type="button" class="menu-toggle" aria-label="開啟選單" aria-expanded="false" aria-controls="side-menu"><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7h16M4 12h16M4 17h16"/></svg></button>${BRAND}</div><button type="button" class="drawer-scrim" aria-label="關閉選單"></button><header class="bar" id="side-menu">${BRAND}<nav aria-label="選單">${items}</nav><button type="button" data-appearance-toggle aria-label="切換外觀"></button></header>`;
581
+ }
582
+ /** 兩頁共用的頁殼版面:側欄、行動版抽屜。 */
583
+ const SHELL_LAYOUT_STYLES = `
584
+ .tile { border: 1px solid light-dark(#e6e6e6, #3d3d3d); }
585
+ body { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
586
+ .bar { position: sticky; top: 0; align-self: start; height: 100dvh; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 4px; padding: 18px 14px; border-bottom: 0; border-right: 1px solid var(--line); }
587
+ .bar .brand { padding: 6px 8px 14px; }
588
+ .bar .logo-badge { width: 28px; height: 28px; }
589
+ .bar .brand-title, .mobile-top .brand-title { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0; line-height: 26px; color: light-dark(#0d0d0d, #ececec); background: none; -webkit-text-fill-color: currentColor; white-space: nowrap; }
590
+ .brand .ver { align-self: center; flex: 0 0 auto; font-family: Consolas, "Cascadia Mono", monospace; font-size: 10px; line-height: 1.2; color: var(--muted); background: light-dark(#f4f4f4, #303030); border: 1px solid light-dark(#e6e6e6, #3d3d3d); padding: 2px 6px; border-radius: 999px; white-space: nowrap; }
591
+ .bar nav { display: flex; flex-direction: column; gap: 2px; }
592
+ .side-item { display: flex; align-items: center; gap: 8px; align-self: stretch; justify-content: flex-start; min-height: 36px; padding: 8px 10px; border-radius: 8px; background: transparent; color: var(--text); font-size: 13px; font-weight: 500; text-align: left; text-decoration: none; }
593
+ .side-item:hover { background: light-dark(rgba(13, 13, 13, 0.04), rgba(255, 255, 255, 0.05)); }
594
+ .side-item[aria-current="page"] { background: light-dark(rgba(13, 13, 13, 0.06), rgba(255, 255, 255, 0.09)); font-weight: 600; }
595
+ .side-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
596
+ .side-item svg { width: 18px; height: 18px; flex-shrink: 0; }
597
+ .bar [data-appearance-toggle] { margin-top: auto; align-self: flex-start; }
598
+ .mobile-top, .drawer-scrim, .menu-toggle { display: none; }
599
+ main { justify-self: center; width: min(52rem, 100%); }
600
+ @media (max-width: 760px) {
601
+ body { display: block; }
602
+ .mobile-top { display: flex; position: sticky; top: 0; z-index: 20; align-items: center; gap: 4px; padding: 4px 10px; border-bottom: 1px solid var(--line); background: var(--bar); backdrop-filter: blur(24px) saturate(160%); }
603
+ .mobile-top .brand { flex: 1; min-width: 0; padding: 4px; }
604
+ .mobile-top .logo-badge { width: 32px; height: 32px; }
605
+ .mobile-top .brand-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
606
+ .menu-toggle { display: grid; place-items: center; width: 44px; height: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--text); }
607
+ .menu-toggle svg { width: 20px; height: 20px; }
608
+ .bar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 40; width: min(280px, 84vw); height: 100dvh; transform: translateX(-100%); visibility: hidden; border-right: 1px solid var(--line); background: light-dark(rgba(242, 242, 247, 0.97), rgba(12, 12, 14, 0.96)); }
609
+ .bar.open { transform: translateX(0); visibility: visible; }
610
+ .bar .brand { display: none; }
611
+ .drawer-scrim.show { display: block; position: fixed; inset: 0; z-index: 30; border: 0; padding: 0; background: light-dark(rgba(20, 20, 20, 0.32), rgba(0, 0, 0, 0.52)); }
612
+ main { width: min(52rem, 100%); margin: 0 auto; }
613
+ }
614
+ .tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
615
+ .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
616
+ [data-appearance="dark"] { --bg: #212121; }
617
+ @media (prefers-color-scheme: dark) {
618
+ :root:not([data-appearance="light"]) { --bg: #212121; }
619
+ }`;
620
+ /** 兩頁共用的頁首與按鈕樣式。 */
621
+ const SHELL_CONTROL_STYLES = `
622
+ .page-head { margin: 0.75rem 0 0.15rem; }
623
+ .page-head h2 { font-size: 20px; font-weight: 600; color: var(--text); letter-spacing: 0; }
624
+ .page-head p { margin-top: 4px; color: var(--muted); font-size: 14px; font-weight: 400; }
625
+ main button { min-height: 34px; padding: 8px 16px; border-radius: 999px; border: 1px solid transparent; background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 500; }
626
+ main button.quiet { background: light-dark(#ffffff, #212121); color: light-dark(#0d0d0d, #ececec); border-color: light-dark(#e6e6e6, #3d3d3d); padding: 8px 16px; }`;
627
+ function documentHead() {
560
628
  return `<!DOCTYPE html>
561
629
  <html lang="zh-Hant">
562
630
  <head>
@@ -566,7 +634,10 @@ function basePage(view) {
566
634
  <link rel="icon" href="/favicon.ico" sizes="any">
567
635
  <style>${CSS}</style>
568
636
  <script>${appearanceScript()}</script>
569
- </head>
637
+ </head>`;
638
+ }
639
+ function basePage(view) {
640
+ return `${documentHead()}
570
641
  <body>
571
642
  <header class="bar">
572
643
  <div class="brand">
@@ -794,8 +865,7 @@ function renderPage(view) {
794
865
  ? `<span class="badge">已連線</span>`
795
866
  : `<span class="badge off">未連線</span>`;
796
867
  let html = basePage(view).replace(`<section class="tile"><h2>連線</h2>`, `<section class="tile"><div class="tile-head"><h2>連線</h2>${tag}</div>`);
797
- html = html.replace(`<header class="bar">`, `<div class="mobile-top"><button type="button" class="menu-toggle" aria-label="開啟選單" aria-expanded="false" aria-controls="side-menu"><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7h16M4 12h16M4 17h16"/></svg></button><div class="brand"><div class="logo-badge"><img src="/brand-logo.png" alt=""></div><h1 class="gradient-text">VansPod</h1></div></div><button type="button" class="drawer-scrim" aria-label="關閉選單"></button><header class="bar" id="side-menu">`);
798
- html = html.replace(`<button type="button" data-appearance-toggle aria-label="切換外觀"></button>`, `<nav aria-label="選單"><button type="button" class="side-item" aria-current="page"><svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m9.5 3-.6 2.3-2 .9-2.1-.6-2.5 4.3 1.5 1.7v2.3l-1.5 1.7 2.5 4.3 2.1-.6 2 .9.6 2.3h5l.6-2.3 2-.9 2.1.6 2.5-4.3-1.5-1.7v-2.3l1.5-1.7-2.5-4.3-2.1.6-2-.9L14.5 3z"/><circle cx="12" cy="12" r="3"/></svg><span>教室設定</span></button></nav><button type="button" data-appearance-toggle aria-label="切換外觀"></button>`);
868
+ html = html.replace(/<header class="bar">[\s\S]*?<\/header>/, sideMenu("settings"));
799
869
  html = html.replace(/<section class="tile"><h2>資料夾<\/h2>[\s\S]*?<\/section>/, "");
800
870
  const modelCount = view.allowedModels?.length ?? (view.modelId ? 1 : 0);
801
871
  const modelTag = modelCount
@@ -832,7 +902,6 @@ function renderPage(view) {
832
902
  html = html.replace(/<p class="class-label">[\s\S]*?<\/p>/, "");
833
903
  html = html.replace(`<p class="detail">Classroom API Key 已設定。</p>`, "");
834
904
  }
835
- html = html.replaceAll(`<h1 class="gradient-text">${PRODUCT}</h1>`, `<h1 class="brand-title">VansPod</h1><span class="ver">${VERSION}</span>`);
836
905
  html = html.replace(`<div class="modules">`, `<header class="page-head"><h2>教室設定</h2><p>連線、模型與開發環境。</p></header><div class="modules">`);
837
906
  if (view.catalog?.actions.length) {
838
907
  html = html.replace(/<table>[\s\S]*?<\/table>/, installActionCards(view));
@@ -840,35 +909,8 @@ function renderPage(view) {
840
909
  html = organizeSettings(html, view);
841
910
  html = splitCourseCards(html, view);
842
911
  const extra = `<style>
843
- .tile { border: 1px solid light-dark(#e6e6e6, #3d3d3d); }
844
912
  .display { display: none; }
845
- body { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
846
- .bar { position: sticky; top: 0; align-self: start; height: 100dvh; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 4px; padding: 18px 14px; border-bottom: 0; border-right: 1px solid var(--line); }
847
- .bar .brand { padding: 6px 8px 14px; }
848
- .bar .logo-badge { width: 28px; height: 28px; }
849
- .bar .brand-title, .mobile-top .brand-title { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0; line-height: 26px; color: light-dark(#0d0d0d, #ececec); background: none; -webkit-text-fill-color: currentColor; white-space: nowrap; }
850
- .brand .ver { align-self: center; flex: 0 0 auto; font-family: Consolas, "Cascadia Mono", monospace; font-size: 10px; line-height: 1.2; color: var(--muted); background: light-dark(#f4f4f4, #303030); border: 1px solid light-dark(#e6e6e6, #3d3d3d); padding: 2px 6px; border-radius: 999px; white-space: nowrap; }
851
- .bar nav { display: flex; flex-direction: column; }
852
- .side-item { display: flex; align-items: center; gap: 8px; align-self: stretch; justify-content: flex-start; min-height: 36px; padding: 8px 10px; border-radius: 8px; background: light-dark(rgba(13, 13, 13, 0.06), rgba(255, 255, 255, 0.09)); color: var(--text); font-size: 13px; font-weight: 600; text-align: left; }
853
- .side-item svg { width: 18px; height: 18px; flex-shrink: 0; }
854
- .bar [data-appearance-toggle] { margin-top: auto; align-self: flex-start; }
855
- .mobile-top, .drawer-scrim, .menu-toggle { display: none; }
856
- main { justify-self: center; width: min(52rem, 100%); }
857
- @media (max-width: 760px) {
858
- body { display: block; }
859
- .mobile-top { display: flex; position: sticky; top: 0; z-index: 20; align-items: center; gap: 4px; padding: 4px 10px; border-bottom: 1px solid var(--line); background: var(--bar); backdrop-filter: blur(24px) saturate(160%); }
860
- .mobile-top .brand { flex: 1; min-width: 0; padding: 4px; }
861
- .mobile-top .logo-badge { width: 32px; height: 32px; }
862
- .mobile-top .brand-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
863
- .menu-toggle { display: grid; place-items: center; width: 44px; height: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--text); }
864
- .menu-toggle svg { width: 20px; height: 20px; }
865
- .bar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 40; width: min(280px, 84vw); height: 100dvh; transform: translateX(-100%); visibility: hidden; border-right: 1px solid var(--line); background: light-dark(rgba(242, 242, 247, 0.97), rgba(12, 12, 14, 0.96)); }
866
- .bar.open { transform: translateX(0); visibility: visible; }
867
- .bar .brand { display: none; }
868
- .drawer-scrim.show { display: block; position: fixed; inset: 0; z-index: 30; border: 0; padding: 0; background: light-dark(rgba(20, 20, 20, 0.32), rgba(0, 0, 0, 0.52)); }
869
- main { width: min(52rem, 100%); margin: 0 auto; }
870
- }
871
- .tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
913
+ ${SHELL_LAYOUT_STYLES}
872
914
  .course-section > summary { cursor: pointer; list-style: none; border-radius: 6px; }
873
915
  .course-section > summary::-webkit-details-marker { display: none; }
874
916
  .course-section > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
@@ -916,7 +958,6 @@ function renderPage(view) {
916
958
  main .snippet-card > button { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
917
959
  .snippet-card > button svg { width: 14px; height: 14px; }
918
960
  .snippet-card.copied > button svg { display: none; }
919
- .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
920
961
  .confirm-dialog { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; background: light-dark(rgba(20, 20, 20, 0.32), rgba(0, 0, 0, 0.52)); }
921
962
  .confirm-panel { width: min(36rem, 100%); max-height: min(70dvh, 32rem); overflow: hidden; display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: 16px; background: var(--tile); border: 1px solid var(--line); }
922
963
  .confirm-panel > :not(pre) { flex-shrink: 0; }
@@ -929,10 +970,6 @@ function renderPage(view) {
929
970
  .confirm-panel button { min-height: 34px; padding: 8px 16px; border-radius: 999px; border: 1px solid transparent; background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 500; }
930
971
  .confirm-panel button.quiet { background: light-dark(#ffffff, #212121); color: light-dark(#0d0d0d, #ececec); border-color: light-dark(#e6e6e6, #3d3d3d); }
931
972
  .restart { color: light-dark(#9a4a08, #fbbf24); }
932
- [data-appearance="dark"] { --bg: #212121; }
933
- @media (prefers-color-scheme: dark) {
934
- :root:not([data-appearance="light"]) { --bg: #212121; }
935
- }
936
973
  .settings-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
937
974
  .settings-card { gap: 16px; padding: 18px; }
938
975
  .settings-card .tile-head { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
@@ -994,11 +1031,7 @@ function renderPage(view) {
994
1031
  .key-row p { color: var(--muted); font-size: 13px; }
995
1032
  .key-row form { flex-shrink: 0; }
996
1033
  ${connectionMascot_1.connectionMascotStyles}
997
- .page-head { margin: 0.75rem 0 0.15rem; }
998
- .page-head h2 { font-size: 20px; font-weight: 600; color: var(--text); letter-spacing: 0; }
999
- .page-head p { margin-top: 4px; color: var(--muted); font-size: 14px; font-weight: 400; }
1000
- main button { min-height: 34px; padding: 8px 16px; border-radius: 999px; border: 1px solid transparent; background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 500; }
1001
- main button.quiet { background: light-dark(#ffffff, #212121); color: light-dark(#0d0d0d, #ececec); border-color: light-dark(#e6e6e6, #3d3d3d); padding: 8px 16px; }
1034
+ ${SHELL_CONTROL_STYLES}
1002
1035
  main button.stop { background: transparent; color: light-dark(#b91c1c, #f87171); border-color: light-dark(rgba(185, 28, 28, 0.35), rgba(248, 113, 113, 0.35)); }
1003
1036
  main .modes { border-radius: 999px; padding: 2px; background: light-dark(#f4f4f4, #303030); border: 1px solid light-dark(#e6e6e6, #3d3d3d); }
1004
1037
  main .modes button { background: transparent; color: var(--text); border-color: transparent; }
@@ -1014,3 +1047,75 @@ function renderPage(view) {
1014
1047
  </script>`;
1015
1048
  return html.replace("</body>", `${extra}</body>`);
1016
1049
  }
1050
+ function recorderBar(recording) {
1051
+ const state = recording
1052
+ ? `<span class="pi-rec-dot" aria-hidden="true"></span><div><strong>錄製中</strong>`
1053
+ : `<div><strong>未錄製</strong>`;
1054
+ const toggle = recording
1055
+ ? `<form method="post" action="/prompt-capture/pause"><button type="submit" class="quiet">暫停</button></form>`
1056
+ : `<form method="post" action="/prompt-capture/start"><button type="submit">開始錄製</button></form>`;
1057
+ return `<section class="tile pi-recorder"><div class="pi-rec-state">${state}<p class="hint">只記在這台電腦的記憶體,最多 ${promptCapture_1.CAPTURE_LIMIT} 筆,關掉 VansPod 就清除。只有切到「課堂」的客戶端會被記錄。</p></div></div><div class="pi-rec-actions">${toggle}<form method="post" action="/prompt-capture/clear"><button type="submit" class="quiet">清除</button></form></div></section>`;
1058
+ }
1059
+ // 法鬥超人在頁首標題右邊巡邏,一圈的時間依寬度重算。
1060
+ const headPatrol = (0, connectionMascot_1.fittedPatrol)(".pi-head");
1061
+ // 錄製列的按鈕改用 fetch 換掉錄製列,整頁不重載,法鬥才不會每按一次就重新進場。
1062
+ const recorderActionsScript = `
1063
+ document.addEventListener("submit", async function (event) {
1064
+ var form = event.target;
1065
+ if (!form?.matches?.('form[action^="/prompt-capture/"]')) return;
1066
+ event.preventDefault();
1067
+ var bar = form.closest(".pi-recorder");
1068
+ bar.querySelectorAll("button").forEach(function (button) { button.disabled = true; });
1069
+ try {
1070
+ var response = await fetch(form.action, { method: "POST" });
1071
+ if (!response.ok) throw new Error("recorder action failed");
1072
+ var next = new DOMParser().parseFromString(await response.text(), "text/html").querySelector(".pi-recorder");
1073
+ if (!next) throw new Error("recorder bar unavailable");
1074
+ bar.replaceWith(next);
1075
+ document.dispatchEvent(new Event("pi-refresh"));
1076
+ } catch (error) {
1077
+ bar.querySelectorAll("button").forEach(function (button) { button.disabled = false; });
1078
+ }
1079
+ });
1080
+ `;
1081
+ /** Prompt 觀察室:與教室設定共用頁殼、側欄、主題與行動版抽屜。 */
1082
+ function renderInspectorPage(view) {
1083
+ const list = { captures: view.captures, dropped: view.dropped };
1084
+ // 頁面腳本拿同一份資料接手重繪;JSON 裡的 < 不能結束 script 元素。
1085
+ const data = JSON.stringify(list).replace(/</g, "\\u003c");
1086
+ return `${documentHead()}
1087
+ <body>
1088
+ ${sideMenu("inspector")}
1089
+ <main class="inspector-main">
1090
+ <header class="page-head pi-head"><div class="pi-head-text"><h2>Prompt 觀察室</h2><p>看看 Coding Agent 每次送給模型的完整內容。</p></div>${connectionMascot_1.connectionMascot}</header>
1091
+ ${recorderBar(view.recording)}
1092
+ <div id="pi-app">${(0, inspectorView_1.inspectorBody)(list, { selected: null, view: "parts", raw: "sent" })}</div>
1093
+ </main>
1094
+ <script type="application/json" id="pi-data">${data}</script>
1095
+ <style>
1096
+ ${SHELL_LAYOUT_STYLES}
1097
+ ${SHELL_CONTROL_STYLES}
1098
+ main.inspector-main { width: min(72rem, 100%); }
1099
+ #pi-app { margin-top: 12px; }
1100
+ .inspector-main .tile { gap: 12px; padding: 18px; min-width: 0; }
1101
+ .inspector-main .hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
1102
+ .pi-recorder { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; }
1103
+ .pi-rec-state { display: flex; align-items: flex-start; gap: 10px; min-width: 0; flex: 1 1 22rem; }
1104
+ .pi-rec-state strong { font-size: 14px; }
1105
+ .pi-rec-dot { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 4px rgba(229, 72, 77, 0.15); flex-shrink: 0; animation: pi-pulse 1.6s ease-in-out infinite; }
1106
+ @keyframes pi-pulse { 50% { opacity: 0.35; } }
1107
+ @media (prefers-reduced-motion: reduce) { .pi-rec-dot { animation: none; } }
1108
+ .pi-rec-actions { display: flex; gap: 8px; }
1109
+ .pi-head { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0 16px; }
1110
+ .pi-head-text { flex: 0 1 auto; padding-bottom: 12px; }
1111
+ /* 巡邏範圍撐滿標題右邊;一圈的時間依寬度重算,步速與教室設定一致。 */
1112
+ .pi-head .connection-mascot { flex: 1 1 260px; height: 144px; }
1113
+ ${connectionMascot_1.connectionMascotStyles}
1114
+ ${headPatrol.styles}
1115
+ ${inspectorView_1.INSPECTOR_STYLES}
1116
+ </style>
1117
+ ${headPatrol.sheet}
1118
+ <script>${drawerScript()}${connectionMascot_1.connectionMascotScript}${headPatrol.script}${recorderActionsScript}${(0, inspectorView_1.inspectorScript)()}</script>
1119
+ </body>
1120
+ </html>`;
1121
+ }