@jamiexiongr/panda-hub 0.1.2 → 0.1.4

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.
@@ -12726,7 +12726,7 @@ var startPandaSessionService = async ({
12726
12726
  if (managedTimeline) {
12727
12727
  return mergeTimelineEntries(managedTimeline, readTimelineOverlay(sessionId, managedTimeline));
12728
12728
  }
12729
- const { readCodexTimeline: readCodexTimeline2 } = await import("./src-LEEO2YLS.mjs");
12729
+ const { readCodexTimeline: readCodexTimeline2 } = await import("./src-A2O4IXQ2.mjs");
12730
12730
  const discoveredTimeline = await readCodexTimeline2(sessionId, {
12731
12731
  codexHome,
12732
12732
  sessionFiles: discoveredSessionFiles
@@ -13411,7 +13411,7 @@ var startPandaSessionService = async ({
13411
13411
  lastSnapshotRefreshAt = Date.now();
13412
13412
  return snapshot;
13413
13413
  }
13414
- const { discoverLocalCodexData: discoverLocalCodexData2 } = await import("./src-LEEO2YLS.mjs");
13414
+ const { discoverLocalCodexData: discoverLocalCodexData2 } = await import("./src-A2O4IXQ2.mjs");
13415
13415
  const discovery = await discoverLocalCodexData2({
13416
13416
  agentId: localAgentId,
13417
13417
  agentName: localAgentName,
@@ -15656,6 +15656,25 @@ var parsePort = (value) => {
15656
15656
  }
15657
15657
  return parsed;
15658
15658
  };
15659
+ var trimExecOutput = (value) => {
15660
+ if (typeof value === "string") {
15661
+ const trimmed = value.trim();
15662
+ return trimmed || null;
15663
+ }
15664
+ if (Buffer.isBuffer(value)) {
15665
+ const trimmed = value.toString("utf8").trim();
15666
+ return trimmed || null;
15667
+ }
15668
+ return null;
15669
+ };
15670
+ var describeExecError = (error) => {
15671
+ if (!(error instanceof Error)) {
15672
+ return "tailscale serve failed";
15673
+ }
15674
+ const commandError = error;
15675
+ const output = trimExecOutput(commandError.stderr) ?? trimExecOutput(commandError.stdout);
15676
+ return output ?? error.message;
15677
+ };
15659
15678
  var readTailscaleStatus = () => {
15660
15679
  try {
15661
15680
  const stdout = execFileSync("tailscale", ["status", "--json"], {
@@ -15767,6 +15786,7 @@ var configureTailscaleServe = (options) => {
15767
15786
  "tailscale",
15768
15787
  [
15769
15788
  "serve",
15789
+ "--yes",
15770
15790
  "--bg",
15771
15791
  `--https=${options.servePort}`,
15772
15792
  `http://127.0.0.1:${options.localPort}`
@@ -15779,7 +15799,7 @@ var configureTailscaleServe = (options) => {
15779
15799
  }
15780
15800
  );
15781
15801
  } catch (error) {
15782
- const message = error instanceof Error ? error.message : "tailscale serve failed";
15802
+ const message = describeExecError(error);
15783
15803
  options.logger?.warn?.(
15784
15804
  `Unable to publish ${options.serviceName} via Tailscale Serve: ${message}`
15785
15805
  );
@@ -5,16 +5,17 @@ import {
5
5
  resolveTailscaleServeEnabled,
6
6
  resolveTailscaleServePort,
7
7
  startPandaSessionService
8
- } from "./chunk-GPLVIR3L.mjs";
8
+ } from "./chunk-I3VRWQCP.mjs";
9
9
 
10
10
  // release/panda-hub/src/index.ts
11
+ import fs from "fs";
11
12
  import path from "path";
12
13
  import { fileURLToPath } from "url";
13
14
 
14
15
  // release/panda-hub/package.json
15
16
  var package_default = {
16
17
  name: "@jamiexiongr/panda-hub",
17
- version: "0.1.2",
18
+ version: "0.1.4",
18
19
  type: "module",
19
20
  private: false,
20
21
  description: "Panda hub runtime",
@@ -44,6 +45,14 @@ var package_default = {
44
45
 
45
46
  // release/panda-hub/src/index.ts
46
47
  var currentDirectory = path.dirname(fileURLToPath(import.meta.url));
48
+ var resolveBundledWebUiDir = () => {
49
+ const candidates = [
50
+ path.resolve(currentDirectory, "web"),
51
+ path.resolve(currentDirectory, "../dist/web"),
52
+ path.resolve(currentDirectory, "../web")
53
+ ];
54
+ return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];
55
+ };
47
56
  var startJamiexiongrHub = async (options) => {
48
57
  const port = Number(process.env.PANDA_HUB_PORT ?? 4343);
49
58
  const tailscaleServe = configureTailscaleServe({
@@ -64,7 +73,7 @@ var startJamiexiongrHub = async (options) => {
64
73
  if (hubApiKey.apiKey) {
65
74
  process.env.PANDA_HUB_API_KEY = hubApiKey.apiKey;
66
75
  }
67
- const webUiDir = path.resolve(currentDirectory, "../web");
76
+ const webUiDir = resolveBundledWebUiDir();
68
77
  const app = await startPandaSessionService({
69
78
  serviceName: "panda-hub",
70
79
  mode: "hub",
package/dist/cli.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  startJamiexiongrHub
3
- } from "./chunk-CS7XM33H.mjs";
3
+ } from "./chunk-L4ZJFGL5.mjs";
4
4
  import {
5
5
  resolveTailscaleServeEnabled
6
- } from "./chunk-GPLVIR3L.mjs";
6
+ } from "./chunk-I3VRWQCP.mjs";
7
7
 
8
8
  // release/panda-hub/src/cli.ts
9
9
  void startJamiexiongrHub({
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  startJamiexiongrHub
3
- } from "./chunk-CS7XM33H.mjs";
4
- import "./chunk-GPLVIR3L.mjs";
3
+ } from "./chunk-L4ZJFGL5.mjs";
4
+ import "./chunk-I3VRWQCP.mjs";
5
5
  export {
6
6
  startJamiexiongrHub
7
7
  };
@@ -42,7 +42,7 @@ import {
42
42
  writeCodexGlobalState,
43
43
  writePandaSessionPrefs,
44
44
  writePandaThreadPrefs
45
- } from "./chunk-GPLVIR3L.mjs";
45
+ } from "./chunk-I3VRWQCP.mjs";
46
46
  export {
47
47
  CodexAdapter,
48
48
  appendSessionIndexUpdate,
@@ -1 +1 @@
1
- import{u as j,r as d,j as e}from"./index-DxHRG-hx.js";const v=[{key:"color-mix-oklab",property:"background",value:"color-mix(in oklab, white 50%, black)"},{key:"color-mix-srgb",property:"background",value:"color-mix(in srgb, white 50%, black)"},{key:"backdrop-filter",property:"backdrop-filter",value:"blur(12px)"},{key:"webkit-backdrop-filter",property:"-webkit-backdrop-filter",value:"blur(12px)"},{key:"viewport-dvh",property:"height",value:"100dvh"}],y=["--color-surface-base","--color-surface-panel","--color-surface-floating","--color-surface-border","--color-surface-border-soft","--color-text-primary","--color-text-secondary","--color-accent-primary","--color-accent-primary-soft"],w=[".conversation-topbar",".topbar-menu",".conversation-run-popover",".chat-composer",".chat-composer__input",".composer-utility-menu__popover",".session-run-panel__command-card",".session-run-panel__input",".session-git-panel__summary"],b=["background-color","background-image","backdrop-filter","-webkit-backdrop-filter","border-color","box-shadow","color","display","opacity","position"],x=(t,r=180)=>{const n=(t??"").replace(/\s+/g," ").trim();return n?n.length<=r?n:`${n.slice(0,r-1).trimEnd()}…`:null},h=t=>Number(t.toFixed(2)),k=(t,r)=>{var n;if(typeof window>"u"||typeof((n=window.CSS)==null?void 0:n.supports)!="function")return!1;try{return window.CSS.supports(t,r)}catch{return!1}},_=()=>Object.fromEntries(v.map(t=>[t.key,k(t.property,t.value)])),S=()=>typeof document>"u"?[]:Array.from(document.styleSheets).map(t=>{var n,i;let r=null;try{r=t.cssRules.length}catch{r=null}return{href:t.href??null,owner_node:t.ownerNode instanceof Element?t.ownerNode.tagName.toLowerCase():null,media:((i=(n=t.media)==null?void 0:n.mediaText)==null?void 0:i.trim())||null,disabled:t.disabled,css_rule_count:r}}),N=()=>{if(typeof document>"u"||typeof window>"u")return[];const t=new Map,r=(n,i)=>{const o=n==null?void 0:n.trim();if(o)try{const l=new URL(o,window.location.href);if(!/^https?:$/i.test(l.protocol))return;t.set(l.toString(),i)}catch{return}};for(const n of document.styleSheets)r(n.href,"stylesheet");for(const n of Array.from(document.scripts))r(n.src,"script");for(const n of Array.from(document.querySelectorAll('link[rel~="manifest"]')))r(n.href,"manifest");for(const n of Array.from(document.querySelectorAll('link[rel~="icon"], link[rel="apple-touch-icon"]')))r(n.href,"icon");return Array.from(t.entries()).slice(0,20).map(([n,i])=>({url:n,kind:i}))},E=async t=>{const r=async n=>fetch(t.url,{method:n,cache:"no-store",redirect:"follow"});try{let n=await r("HEAD");return(n.status===405||n.status===501)&&(n=await r("GET")),{url:t.url,kind:t.kind,ok:n.ok,status:n.status,content_type:n.headers.get("content-type"),cache_control:n.headers.get("cache-control"),error:null}}catch(n){return{url:t.url,kind:t.kind,ok:!1,status:null,content_type:null,cache_control:null,error:n instanceof Error?n.message:"Unknown fetch failure"}}},C=()=>typeof performance>"u"||typeof performance.getEntriesByType!="function"?[]:performance.getEntriesByType("resource").map(t=>t).filter(t=>{const r=t.name.toLowerCase();return r.includes(".css")||r.includes(".js")||r.includes("manifest")||t.initiatorType==="link"||t.initiatorType==="script"}).slice(-40).map(t=>({name:t.name,initiator_type:t.initiatorType||null,duration_ms:h(t.duration),transfer_size:typeof t.transferSize=="number"?t.transferSize:null,decoded_body_size:typeof t.decodedBodySize=="number"?t.decodedBodySize:null})),T=()=>{if(typeof document>"u"||typeof window>"u")return{};const t=window.getComputedStyle(document.documentElement);return Object.fromEntries(y.map(r=>[r,t.getPropertyValue(r).trim()||"(empty)"]))},R=t=>{if(typeof document>"u"||typeof window>"u")return{selector:t,found:!1,text_preview:null,rect:null,computed:{}};const r=document.querySelector(t);if(!r)return{selector:t,found:!1,text_preview:null,rect:null,computed:{}};const n=r.getBoundingClientRect(),i=window.getComputedStyle(r);return{selector:t,found:!0,text_preview:x(r.textContent),rect:{x:h(n.x),y:h(n.y),width:h(n.width),height:h(n.height)},computed:Object.fromEntries(b.map(o=>[o,i.getPropertyValue(o).trim()||"(empty)"]))}},A=async()=>{if(typeof navigator>"u"||!("serviceWorker"in navigator))return{supported:!1,controller:!1,registrations:[]};try{const t=await navigator.serviceWorker.getRegistrations();return{supported:!0,controller:!!navigator.serviceWorker.controller,registrations:t.map(r=>{var n,i,o;return{scope:r.scope,active_script_url:((n=r.active)==null?void 0:n.scriptURL)??null,waiting_script_url:((i=r.waiting)==null?void 0:i.scriptURL)??null,installing_script_url:((o=r.installing)==null?void 0:o.scriptURL)??null}})}}catch{return{supported:!0,controller:!!navigator.serviceWorker.controller,registrations:[]}}},O=async()=>{if(typeof window>"u"||!("caches"in window))return{supported:!1,keys:[]};try{return{supported:!0,keys:await window.caches.keys()}}catch{return{supported:!0,keys:[]}}},L=t=>{const r=[];return t.feature_support["color-mix-oklab"]||r.push("当前浏览器不支持 color-mix(in oklab, ...),混色背景会直接失效,常见现象就是输入区或面板背景透明。"),!t.feature_support["backdrop-filter"]&&!t.feature_support["webkit-backdrop-filter"]&&r.push("当前浏览器不支持 backdrop-filter,磨砂浮层会退化成纯色面板。"),t.service_worker.controller&&t.cache.keys.length>0&&r.push(`检测到 ${t.cache.keys.length} 个 Cache Storage 项,若真机页面和桌面不一致,可以先清理缓存再重试。`),t.stylesheets.length===0&&r.push("当前页面没有读取到任何样式表对象,需要重点检查 CSS 是否被正确加载。"),t.resource_probes.some(n=>!n.ok)&&r.push("至少有一个静态资源探测失败,需要继续检查网络、缓存或 Service Worker 拦截。"),r},P=async()=>{var u,p,m,s,a,g;const t=N(),[r,n,i]=await Promise.all([A(),O(),Promise.all(t.map(f=>E(f)))]),o=navigator,l={width:window.innerWidth,height:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,visual_width:((u=window.visualViewport)==null?void 0:u.width)??null,visual_height:((p=window.visualViewport)==null?void 0:p.height)??null,screen_width:((m=window.screen)==null?void 0:m.width)??null,screen_height:((s=window.screen)==null?void 0:s.height)??null},c={captured_at:new Date().toISOString(),page:{href:window.location.href,pathname:window.location.pathname,referrer:x(document.referrer),visibility_state:document.visibilityState??null},environment:{user_agent:navigator.userAgent,language:navigator.language??null,languages:Array.isArray(navigator.languages)?navigator.languages:[],platform:navigator.platform??null,vendor:navigator.vendor??null,online:typeof navigator.onLine=="boolean"?navigator.onLine:null,cookie_enabled:typeof navigator.cookieEnabled=="boolean"?navigator.cookieEnabled:null,secure_context:window.isSecureContext,standalone_display_mode:window.matchMedia("(display-mode: standalone)").matches,hardware_concurrency:typeof navigator.hardwareConcurrency=="number"?navigator.hardwareConcurrency:null,device_memory_gb:typeof o.deviceMemory=="number"?o.deviceMemory:null,max_touch_points:typeof navigator.maxTouchPoints=="number"?navigator.maxTouchPoints:null},viewport:l,feature_support:_(),service_worker:r,cache:n,manifest:{href:((a=document.querySelector('link[rel~="manifest"]'))==null?void 0:a.href)??null,rel:((g=document.querySelector('link[rel~="manifest"]'))==null?void 0:g.rel)??null},stylesheets:S(),resource_probes:i,performance_entries:C(),theme_variables:T(),element_snapshots:w.map(f=>R(f)),notes:[]};return c.notes=L(c),c},W=t=>t?"支持":"不支持",$=t=>t?t.feature_support["color-mix-oklab"]?t.resource_probes.some(r=>!r.ok)?"至少有一个静态资源探测失败,更像是 CSS 或脚本资源没有正确加载,或者被缓存 / Service Worker 干扰。":t.service_worker.controller&&t.cache.keys.length>0?"样式能力本身看起来正常,但页面被 Service Worker 控制且存在缓存,下一步要重点排查缓存是否陈旧。":"浏览器能力和基础资源看起来正常,下一步需要对比具体元素快照与安卓真机截图。":"高概率是安卓浏览器不支持 color-mix(in oklab, ...),导致输入框和面板的混色背景规则整体失效。":"正在采集浏览器能力、样式表、缓存和关键元素快照。",U=t=>{if(!t.found)return"未找到对应元素";const r=t.computed["background-color"]??"(empty)",n=t.computed["background-image"]??"(empty)";return r==="rgba(0, 0, 0, 0)"&&n==="none"?"背景完全透明":`${r} / ${n}`},M=()=>{const t=j(),[r,n]=d.useState(null),[i,o]=d.useState(!0),[l,c]=d.useState(null),u=async()=>{o(!0),c(null);try{const s=await P();d.startTransition(()=>{n(s)})}catch(s){c(s instanceof Error?`采集失败:${s.message}`:"采集失败,请稍后重试。")}finally{o(!1)}};d.useEffect(()=>{u()},[]);const p=async()=>{var s;if(r){if(typeof navigator>"u"||typeof((s=navigator.clipboard)==null?void 0:s.writeText)!="function"){c("当前浏览器不支持直接复制,请手动截图或长按选择。");return}try{await navigator.clipboard.writeText(JSON.stringify(r,null,2)),c("诊断 JSON 已复制,可以直接发给我继续分析。")}catch(a){c(a instanceof Error?`复制失败:${a.message}`:"复制失败,请手动截图或长按选择。")}}},m=d.useMemo(()=>$(r),[r]);return e.jsx("main",{className:"diagnostics-page",children:e.jsxs("div",{className:"diagnostics-shell",children:[e.jsxs("header",{className:"diagnostics-header",children:[e.jsxs("div",{className:"diagnostics-header__copy",children:[e.jsx("button",{type:"button",className:"diagnostics-back",onClick:()=>void t({to:"/settings"}),children:"返回设置"}),e.jsx("h1",{children:"安卓样式诊断"}),e.jsx("p",{children:"在手机上打开本页,可以直接检查浏览器能力、样式加载、缓存和关键面板快照。"})]}),e.jsxs("div",{className:"diagnostics-toolbar",children:[e.jsx("button",{type:"button",className:"diagnostics-button",onClick:()=>void u(),disabled:i,children:i?"采集中…":"刷新诊断"}),e.jsx("button",{type:"button",className:"diagnostics-button diagnostics-button--ghost",onClick:()=>void p(),disabled:!r,children:"复制 JSON"})]})]}),l?e.jsx("p",{className:"diagnostics-status",children:l}):null,e.jsxs("section",{className:"diagnostics-card diagnostics-card--hero",children:[e.jsx("span",{className:"diagnostics-eyebrow",children:"初步判断"}),e.jsx("h2",{children:m}),e.jsx("p",{children:"真机异常而桌面浏览器和 F12 模拟正常,最常见就是浏览器 CSS 能力和缓存状态与桌面环境不同。"}),r!=null&&r.notes.length?e.jsx("ul",{className:"diagnostics-list",children:r.notes.map(s=>e.jsx("li",{children:s},s))}):null]}),r?e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"diagnostics-grid",children:[e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"环境"}),e.jsxs("dl",{className:"diagnostics-kv",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"页面"}),e.jsx("dd",{children:r.page.pathname})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"安全上下文"}),e.jsx("dd",{children:r.environment.secure_context?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"独立窗口"}),e.jsx("dd",{children:r.environment.standalone_display_mode?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"在线状态"}),e.jsx("dd",{children:r.environment.online==null?"未知":r.environment.online?"在线":"离线"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"视口"}),e.jsxs("dd",{children:[r.viewport.width," x ",r.viewport.height," @ ",r.viewport.device_pixel_ratio]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"UA"}),e.jsx("dd",{className:"diagnostics-break",children:r.environment.user_agent})]})]})]}),e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"浏览器能力"}),e.jsx("dl",{className:"diagnostics-kv",children:Object.entries(r.feature_support).map(([s,a])=>e.jsxs("div",{children:[e.jsx("dt",{children:s}),e.jsx("dd",{children:W(a)})]},s))})]}),e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"缓存与 SW"}),e.jsxs("dl",{className:"diagnostics-kv",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Service Worker"}),e.jsx("dd",{children:r.service_worker.supported?"支持":"不支持"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"当前受控"}),e.jsx("dd",{children:r.service_worker.controller?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"注册数量"}),e.jsx("dd",{children:r.service_worker.registrations.length})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Cache Storage"}),e.jsx("dd",{children:r.cache.supported?r.cache.keys.join(", ")||"空":"不支持"})]})]})]}),e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"主题变量"}),e.jsx("dl",{className:"diagnostics-kv",children:Object.entries(r.theme_variables).map(([s,a])=>e.jsxs("div",{children:[e.jsx("dt",{children:s}),e.jsx("dd",{children:a})]},s))})]})]}),e.jsxs("section",{className:"diagnostics-card",children:[e.jsx("h2",{children:"资源探测"}),e.jsx("div",{className:"diagnostics-table-wrap",children:e.jsxs("table",{className:"diagnostics-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"类型"}),e.jsx("th",{children:"URL"}),e.jsx("th",{children:"状态"}),e.jsx("th",{children:"内容类型"}),e.jsx("th",{children:"Cache-Control"})]})}),e.jsx("tbody",{children:r.resource_probes.map(s=>e.jsxs("tr",{children:[e.jsx("td",{children:s.kind}),e.jsx("td",{className:"diagnostics-break",children:s.url}),e.jsx("td",{children:s.ok?`OK (${s.status??"-"})`:`失败 (${s.status??"-"})`}),e.jsx("td",{children:s.content_type??"-"}),e.jsx("td",{children:s.cache_control??s.error??"-"})]},`${s.kind}:${s.url}`))})]})})]}),e.jsxs("section",{className:"diagnostics-card",children:[e.jsx("h2",{children:"关键元素快照"}),e.jsx("div",{className:"diagnostics-element-grid",children:r.element_snapshots.map(s=>e.jsxs("article",{className:"diagnostics-element-card",children:[e.jsx("h3",{children:s.selector}),e.jsx("p",{children:U(s)}),e.jsxs("dl",{className:"diagnostics-kv diagnostics-kv--compact",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"找到元素"}),e.jsx("dd",{children:s.found?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"尺寸"}),e.jsx("dd",{children:s.rect?`${s.rect.width} x ${s.rect.height}`:"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"背景色"}),e.jsx("dd",{children:s.computed["background-color"]??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"背景图"}),e.jsx("dd",{className:"diagnostics-break",children:s.computed["background-image"]??"-"})]})]})]},s.selector))})]}),e.jsxs("section",{className:"diagnostics-card",children:[e.jsx("h2",{children:"原始 JSON"}),e.jsx("pre",{className:"diagnostics-json",children:JSON.stringify(r,null,2)})]})]}):e.jsx("section",{className:"diagnostics-card",children:e.jsx("p",{children:"正在等待诊断结果…"})})]})})};export{M as DiagnosticsPage};
1
+ import{u as j,r as d,j as e}from"./index-CepnER6o.js";const v=[{key:"color-mix-oklab",property:"background",value:"color-mix(in oklab, white 50%, black)"},{key:"color-mix-srgb",property:"background",value:"color-mix(in srgb, white 50%, black)"},{key:"backdrop-filter",property:"backdrop-filter",value:"blur(12px)"},{key:"webkit-backdrop-filter",property:"-webkit-backdrop-filter",value:"blur(12px)"},{key:"viewport-dvh",property:"height",value:"100dvh"}],y=["--color-surface-base","--color-surface-panel","--color-surface-floating","--color-surface-border","--color-surface-border-soft","--color-text-primary","--color-text-secondary","--color-accent-primary","--color-accent-primary-soft"],w=[".conversation-topbar",".topbar-menu",".conversation-run-popover",".chat-composer",".chat-composer__input",".composer-utility-menu__popover",".session-run-panel__command-card",".session-run-panel__input",".session-git-panel__summary"],b=["background-color","background-image","backdrop-filter","-webkit-backdrop-filter","border-color","box-shadow","color","display","opacity","position"],x=(t,r=180)=>{const n=(t??"").replace(/\s+/g," ").trim();return n?n.length<=r?n:`${n.slice(0,r-1).trimEnd()}…`:null},h=t=>Number(t.toFixed(2)),k=(t,r)=>{var n;if(typeof window>"u"||typeof((n=window.CSS)==null?void 0:n.supports)!="function")return!1;try{return window.CSS.supports(t,r)}catch{return!1}},_=()=>Object.fromEntries(v.map(t=>[t.key,k(t.property,t.value)])),S=()=>typeof document>"u"?[]:Array.from(document.styleSheets).map(t=>{var n,i;let r=null;try{r=t.cssRules.length}catch{r=null}return{href:t.href??null,owner_node:t.ownerNode instanceof Element?t.ownerNode.tagName.toLowerCase():null,media:((i=(n=t.media)==null?void 0:n.mediaText)==null?void 0:i.trim())||null,disabled:t.disabled,css_rule_count:r}}),N=()=>{if(typeof document>"u"||typeof window>"u")return[];const t=new Map,r=(n,i)=>{const o=n==null?void 0:n.trim();if(o)try{const l=new URL(o,window.location.href);if(!/^https?:$/i.test(l.protocol))return;t.set(l.toString(),i)}catch{return}};for(const n of document.styleSheets)r(n.href,"stylesheet");for(const n of Array.from(document.scripts))r(n.src,"script");for(const n of Array.from(document.querySelectorAll('link[rel~="manifest"]')))r(n.href,"manifest");for(const n of Array.from(document.querySelectorAll('link[rel~="icon"], link[rel="apple-touch-icon"]')))r(n.href,"icon");return Array.from(t.entries()).slice(0,20).map(([n,i])=>({url:n,kind:i}))},E=async t=>{const r=async n=>fetch(t.url,{method:n,cache:"no-store",redirect:"follow"});try{let n=await r("HEAD");return(n.status===405||n.status===501)&&(n=await r("GET")),{url:t.url,kind:t.kind,ok:n.ok,status:n.status,content_type:n.headers.get("content-type"),cache_control:n.headers.get("cache-control"),error:null}}catch(n){return{url:t.url,kind:t.kind,ok:!1,status:null,content_type:null,cache_control:null,error:n instanceof Error?n.message:"Unknown fetch failure"}}},C=()=>typeof performance>"u"||typeof performance.getEntriesByType!="function"?[]:performance.getEntriesByType("resource").map(t=>t).filter(t=>{const r=t.name.toLowerCase();return r.includes(".css")||r.includes(".js")||r.includes("manifest")||t.initiatorType==="link"||t.initiatorType==="script"}).slice(-40).map(t=>({name:t.name,initiator_type:t.initiatorType||null,duration_ms:h(t.duration),transfer_size:typeof t.transferSize=="number"?t.transferSize:null,decoded_body_size:typeof t.decodedBodySize=="number"?t.decodedBodySize:null})),T=()=>{if(typeof document>"u"||typeof window>"u")return{};const t=window.getComputedStyle(document.documentElement);return Object.fromEntries(y.map(r=>[r,t.getPropertyValue(r).trim()||"(empty)"]))},R=t=>{if(typeof document>"u"||typeof window>"u")return{selector:t,found:!1,text_preview:null,rect:null,computed:{}};const r=document.querySelector(t);if(!r)return{selector:t,found:!1,text_preview:null,rect:null,computed:{}};const n=r.getBoundingClientRect(),i=window.getComputedStyle(r);return{selector:t,found:!0,text_preview:x(r.textContent),rect:{x:h(n.x),y:h(n.y),width:h(n.width),height:h(n.height)},computed:Object.fromEntries(b.map(o=>[o,i.getPropertyValue(o).trim()||"(empty)"]))}},A=async()=>{if(typeof navigator>"u"||!("serviceWorker"in navigator))return{supported:!1,controller:!1,registrations:[]};try{const t=await navigator.serviceWorker.getRegistrations();return{supported:!0,controller:!!navigator.serviceWorker.controller,registrations:t.map(r=>{var n,i,o;return{scope:r.scope,active_script_url:((n=r.active)==null?void 0:n.scriptURL)??null,waiting_script_url:((i=r.waiting)==null?void 0:i.scriptURL)??null,installing_script_url:((o=r.installing)==null?void 0:o.scriptURL)??null}})}}catch{return{supported:!0,controller:!!navigator.serviceWorker.controller,registrations:[]}}},O=async()=>{if(typeof window>"u"||!("caches"in window))return{supported:!1,keys:[]};try{return{supported:!0,keys:await window.caches.keys()}}catch{return{supported:!0,keys:[]}}},L=t=>{const r=[];return t.feature_support["color-mix-oklab"]||r.push("当前浏览器不支持 color-mix(in oklab, ...),混色背景会直接失效,常见现象就是输入区或面板背景透明。"),!t.feature_support["backdrop-filter"]&&!t.feature_support["webkit-backdrop-filter"]&&r.push("当前浏览器不支持 backdrop-filter,磨砂浮层会退化成纯色面板。"),t.service_worker.controller&&t.cache.keys.length>0&&r.push(`检测到 ${t.cache.keys.length} 个 Cache Storage 项,若真机页面和桌面不一致,可以先清理缓存再重试。`),t.stylesheets.length===0&&r.push("当前页面没有读取到任何样式表对象,需要重点检查 CSS 是否被正确加载。"),t.resource_probes.some(n=>!n.ok)&&r.push("至少有一个静态资源探测失败,需要继续检查网络、缓存或 Service Worker 拦截。"),r},P=async()=>{var u,p,m,s,a,g;const t=N(),[r,n,i]=await Promise.all([A(),O(),Promise.all(t.map(f=>E(f)))]),o=navigator,l={width:window.innerWidth,height:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,visual_width:((u=window.visualViewport)==null?void 0:u.width)??null,visual_height:((p=window.visualViewport)==null?void 0:p.height)??null,screen_width:((m=window.screen)==null?void 0:m.width)??null,screen_height:((s=window.screen)==null?void 0:s.height)??null},c={captured_at:new Date().toISOString(),page:{href:window.location.href,pathname:window.location.pathname,referrer:x(document.referrer),visibility_state:document.visibilityState??null},environment:{user_agent:navigator.userAgent,language:navigator.language??null,languages:Array.isArray(navigator.languages)?navigator.languages:[],platform:navigator.platform??null,vendor:navigator.vendor??null,online:typeof navigator.onLine=="boolean"?navigator.onLine:null,cookie_enabled:typeof navigator.cookieEnabled=="boolean"?navigator.cookieEnabled:null,secure_context:window.isSecureContext,standalone_display_mode:window.matchMedia("(display-mode: standalone)").matches,hardware_concurrency:typeof navigator.hardwareConcurrency=="number"?navigator.hardwareConcurrency:null,device_memory_gb:typeof o.deviceMemory=="number"?o.deviceMemory:null,max_touch_points:typeof navigator.maxTouchPoints=="number"?navigator.maxTouchPoints:null},viewport:l,feature_support:_(),service_worker:r,cache:n,manifest:{href:((a=document.querySelector('link[rel~="manifest"]'))==null?void 0:a.href)??null,rel:((g=document.querySelector('link[rel~="manifest"]'))==null?void 0:g.rel)??null},stylesheets:S(),resource_probes:i,performance_entries:C(),theme_variables:T(),element_snapshots:w.map(f=>R(f)),notes:[]};return c.notes=L(c),c},W=t=>t?"支持":"不支持",$=t=>t?t.feature_support["color-mix-oklab"]?t.resource_probes.some(r=>!r.ok)?"至少有一个静态资源探测失败,更像是 CSS 或脚本资源没有正确加载,或者被缓存 / Service Worker 干扰。":t.service_worker.controller&&t.cache.keys.length>0?"样式能力本身看起来正常,但页面被 Service Worker 控制且存在缓存,下一步要重点排查缓存是否陈旧。":"浏览器能力和基础资源看起来正常,下一步需要对比具体元素快照与安卓真机截图。":"高概率是安卓浏览器不支持 color-mix(in oklab, ...),导致输入框和面板的混色背景规则整体失效。":"正在采集浏览器能力、样式表、缓存和关键元素快照。",U=t=>{if(!t.found)return"未找到对应元素";const r=t.computed["background-color"]??"(empty)",n=t.computed["background-image"]??"(empty)";return r==="rgba(0, 0, 0, 0)"&&n==="none"?"背景完全透明":`${r} / ${n}`},M=()=>{const t=j(),[r,n]=d.useState(null),[i,o]=d.useState(!0),[l,c]=d.useState(null),u=async()=>{o(!0),c(null);try{const s=await P();d.startTransition(()=>{n(s)})}catch(s){c(s instanceof Error?`采集失败:${s.message}`:"采集失败,请稍后重试。")}finally{o(!1)}};d.useEffect(()=>{u()},[]);const p=async()=>{var s;if(r){if(typeof navigator>"u"||typeof((s=navigator.clipboard)==null?void 0:s.writeText)!="function"){c("当前浏览器不支持直接复制,请手动截图或长按选择。");return}try{await navigator.clipboard.writeText(JSON.stringify(r,null,2)),c("诊断 JSON 已复制,可以直接发给我继续分析。")}catch(a){c(a instanceof Error?`复制失败:${a.message}`:"复制失败,请手动截图或长按选择。")}}},m=d.useMemo(()=>$(r),[r]);return e.jsx("main",{className:"diagnostics-page",children:e.jsxs("div",{className:"diagnostics-shell",children:[e.jsxs("header",{className:"diagnostics-header",children:[e.jsxs("div",{className:"diagnostics-header__copy",children:[e.jsx("button",{type:"button",className:"diagnostics-back",onClick:()=>void t({to:"/settings"}),children:"返回设置"}),e.jsx("h1",{children:"安卓样式诊断"}),e.jsx("p",{children:"在手机上打开本页,可以直接检查浏览器能力、样式加载、缓存和关键面板快照。"})]}),e.jsxs("div",{className:"diagnostics-toolbar",children:[e.jsx("button",{type:"button",className:"diagnostics-button",onClick:()=>void u(),disabled:i,children:i?"采集中…":"刷新诊断"}),e.jsx("button",{type:"button",className:"diagnostics-button diagnostics-button--ghost",onClick:()=>void p(),disabled:!r,children:"复制 JSON"})]})]}),l?e.jsx("p",{className:"diagnostics-status",children:l}):null,e.jsxs("section",{className:"diagnostics-card diagnostics-card--hero",children:[e.jsx("span",{className:"diagnostics-eyebrow",children:"初步判断"}),e.jsx("h2",{children:m}),e.jsx("p",{children:"真机异常而桌面浏览器和 F12 模拟正常,最常见就是浏览器 CSS 能力和缓存状态与桌面环境不同。"}),r!=null&&r.notes.length?e.jsx("ul",{className:"diagnostics-list",children:r.notes.map(s=>e.jsx("li",{children:s},s))}):null]}),r?e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"diagnostics-grid",children:[e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"环境"}),e.jsxs("dl",{className:"diagnostics-kv",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"页面"}),e.jsx("dd",{children:r.page.pathname})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"安全上下文"}),e.jsx("dd",{children:r.environment.secure_context?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"独立窗口"}),e.jsx("dd",{children:r.environment.standalone_display_mode?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"在线状态"}),e.jsx("dd",{children:r.environment.online==null?"未知":r.environment.online?"在线":"离线"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"视口"}),e.jsxs("dd",{children:[r.viewport.width," x ",r.viewport.height," @ ",r.viewport.device_pixel_ratio]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"UA"}),e.jsx("dd",{className:"diagnostics-break",children:r.environment.user_agent})]})]})]}),e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"浏览器能力"}),e.jsx("dl",{className:"diagnostics-kv",children:Object.entries(r.feature_support).map(([s,a])=>e.jsxs("div",{children:[e.jsx("dt",{children:s}),e.jsx("dd",{children:W(a)})]},s))})]}),e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"缓存与 SW"}),e.jsxs("dl",{className:"diagnostics-kv",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Service Worker"}),e.jsx("dd",{children:r.service_worker.supported?"支持":"不支持"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"当前受控"}),e.jsx("dd",{children:r.service_worker.controller?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"注册数量"}),e.jsx("dd",{children:r.service_worker.registrations.length})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Cache Storage"}),e.jsx("dd",{children:r.cache.supported?r.cache.keys.join(", ")||"空":"不支持"})]})]})]}),e.jsxs("article",{className:"diagnostics-card",children:[e.jsx("h2",{children:"主题变量"}),e.jsx("dl",{className:"diagnostics-kv",children:Object.entries(r.theme_variables).map(([s,a])=>e.jsxs("div",{children:[e.jsx("dt",{children:s}),e.jsx("dd",{children:a})]},s))})]})]}),e.jsxs("section",{className:"diagnostics-card",children:[e.jsx("h2",{children:"资源探测"}),e.jsx("div",{className:"diagnostics-table-wrap",children:e.jsxs("table",{className:"diagnostics-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"类型"}),e.jsx("th",{children:"URL"}),e.jsx("th",{children:"状态"}),e.jsx("th",{children:"内容类型"}),e.jsx("th",{children:"Cache-Control"})]})}),e.jsx("tbody",{children:r.resource_probes.map(s=>e.jsxs("tr",{children:[e.jsx("td",{children:s.kind}),e.jsx("td",{className:"diagnostics-break",children:s.url}),e.jsx("td",{children:s.ok?`OK (${s.status??"-"})`:`失败 (${s.status??"-"})`}),e.jsx("td",{children:s.content_type??"-"}),e.jsx("td",{children:s.cache_control??s.error??"-"})]},`${s.kind}:${s.url}`))})]})})]}),e.jsxs("section",{className:"diagnostics-card",children:[e.jsx("h2",{children:"关键元素快照"}),e.jsx("div",{className:"diagnostics-element-grid",children:r.element_snapshots.map(s=>e.jsxs("article",{className:"diagnostics-element-card",children:[e.jsx("h3",{children:s.selector}),e.jsx("p",{children:U(s)}),e.jsxs("dl",{className:"diagnostics-kv diagnostics-kv--compact",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"找到元素"}),e.jsx("dd",{children:s.found?"是":"否"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"尺寸"}),e.jsx("dd",{children:s.rect?`${s.rect.width} x ${s.rect.height}`:"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"背景色"}),e.jsx("dd",{children:s.computed["background-color"]??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"背景图"}),e.jsx("dd",{className:"diagnostics-break",children:s.computed["background-image"]??"-"})]})]})]},s.selector))})]}),e.jsxs("section",{className:"diagnostics-card",children:[e.jsx("h2",{children:"原始 JSON"}),e.jsx("pre",{className:"diagnostics-json",children:JSON.stringify(r,null,2)})]})]}):e.jsx("section",{className:"diagnostics-card",children:e.jsx("p",{children:"正在等待诊断结果…"})})]})})};export{M as DiagnosticsPage};