@ian2018cs/agenthub 0.1.18 → 0.1.19

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.
@@ -132,7 +132,7 @@ ${ee}`:ee:Te.push({type:"assistant",content:ee,timestamp:new Date,isStreaming:!0
132
132
  .xterm-screen:focus {
133
133
  outline: none !important;
134
134
  }
135
- `;if(typeof document<"u"){const t=document.createElement("style");t.type="text/css",t.innerText=Xo,document.head.appendChild(t)}function ei({selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:o=!1,onProcessComplete:n,minimal:l=!1,autoConnect:i=!1}){const m=s.useRef(null),x=s.useRef(null),g=s.useRef(null),v=s.useRef(null),[M,j]=s.useState(!1),[w,h]=s.useState(!1),[$,L]=s.useState(!1),[I,C]=s.useState(null),[p,d]=s.useState(!1),k=s.useRef(t),S=s.useRef(r),A=s.useRef(a),W=s.useRef(o),O=s.useRef(n);s.useEffect(()=>{k.current=t,S.current=r,A.current=a,W.current=o,O.current=n});const Q=s.useCallback(async()=>{if(!(p||M))try{let pe;{const ae=localStorage.getItem("auth-token");if(!ae){console.error("No authentication token found for Shell WebSocket connection");return}pe=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/shell?token=${encodeURIComponent(ae)}`}v.current=new WebSocket(pe),v.current.onopen=()=>{j(!0),d(!1),setTimeout(()=>{g.current&&x.current&&(g.current.fit(),v.current.send(JSON.stringify({type:"init",projectPath:k.current.fullPath||k.current.path,sessionId:W.current?null:S.current?.id,hasSession:W.current?!1:!!S.current,provider:W.current?"plain-shell":S.current?.__provider||"claude",cols:x.current.cols,rows:x.current.rows,initialCommand:A.current,isPlainShell:W.current})))},100)},v.current.onmessage=ae=>{try{const G=JSON.parse(ae.data);if(G.type==="output"){let xe=G.data;if(W.current&&O.current){const Ne=xe.replace(/\x1b\[[0-9;]*m/g,"");if(Ne.includes("Process exited with code 0"))O.current(0);else if(Ne.match(/Process exited with code (\d+)/)){const Ce=parseInt(Ne.match(/Process exited with code (\d+)/)[1]);Ce!==0&&O.current(Ce)}}x.current&&x.current.write(xe)}else G.type==="url_open"&&window.open(G.url,"_blank")}catch(G){console.error("[Shell] Error handling WebSocket message:",G,ae.data)}},v.current.onclose=ae=>{j(!1),d(!1),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H"))},v.current.onerror=ae=>{j(!1),d(!1)}}catch{j(!1),d(!1)}},[p,M]),ie=s.useCallback(()=>{!w||M||p||(d(!0),Q())},[w,M,p,Q]),Z=s.useCallback(()=>{v.current&&(v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"terminate"})),v.current.close(),v.current=null),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H")),j(!1),d(!1)},[]),se=s.useMemo(()=>r?r.__provider==="cursor"?r.name||"Untitled Session":r.summary||"New Session":null,[r]),B=s.useMemo(()=>se?se.slice(0,30):null,[se]),T=s.useMemo(()=>se?se.slice(0,50):null,[se]),z=()=>{L(!0),v.current&&(v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"terminate"})),v.current.close(),v.current=null),x.current&&(x.current.dispose(),x.current=null,g.current=null),j(!1),h(!1),setTimeout(()=>{L(!1)},200)};return s.useEffect(()=>{const Y=r?.id||null;I!==null&&I!==Y&&w&&Z(),C(Y)},[r?.id,w,Z]),s.useEffect(()=>{if(!m.current||!t||$||x.current)return;x.current=new ea.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Menlo, Monaco, "Courier New", monospace',allowProposedApi:!0,allowTransparency:!1,convertEol:!0,scrollback:1e4,tabStopWidth:4,windowsMode:!1,macOptionIsMeta:!0,macOptionClickForcesSelection:!1,theme:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#ffffff",cursorAccent:"#1e1e1e",selection:"#264f78",selectionForeground:"#ffffff",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff",extendedAnsi:["#000000","#800000","#008000","#808000","#000080","#800080","#008080","#c0c0c0","#808080","#ff0000","#00ff00","#ffff00","#0000ff","#ff00ff","#00ffff","#ffffff"]}}),g.current=new ta.FitAddon;const Y=new ra.WebglAddon,pe=new sa.WebLinksAddon;x.current.loadAddon(g.current),x.current.loadAddon(pe);try{x.current.loadAddon(Y)}catch{console.warn("[Shell] WebGL renderer unavailable, using Canvas fallback")}x.current.open(m.current),x.current.attachCustomKeyEventHandler(G=>(G.ctrlKey||G.metaKey)&&G.key==="c"&&x.current.hasSelection()?(document.execCommand("copy"),!1):(G.ctrlKey||G.metaKey)&&G.key==="v"?(navigator.clipboard.readText().then(xe=>{v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"input",data:xe}))}).catch(()=>{}),!1):!0),setTimeout(()=>{g.current&&(g.current.fit(),x.current&&v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows})))},100),h(!0),x.current.onData(G=>{v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"input",data:G}))});const ae=new ResizeObserver(()=>{g.current&&x.current&&setTimeout(()=>{g.current.fit(),v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows}))},50)});return m.current&&ae.observe(m.current),()=>{ae.disconnect(),v.current&&(v.current.readyState===WebSocket.OPEN||v.current.readyState===WebSocket.CONNECTING)&&v.current.close(),v.current=null,x.current&&(x.current.dispose(),x.current=null)}},[t?.path||t?.fullPath,$]),s.useEffect(()=>{!i||!w||p||M||ie()},[i,w,p,M,ie]),t?l?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:m,className:"h-full w-full focus:outline-none",style:{outline:"none"}})}):e.jsxs("div",{className:"h-full flex flex-col bg-gray-900 w-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${M?"bg-green-500":"bg-red-500"}`}),r&&e.jsxs("span",{className:"text-xs text-blue-300",children:["(",B,"...)"]}),!r&&e.jsx("span",{className:"text-xs text-gray-400",children:"(新会话)"}),!w&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),$&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[M&&e.jsxs("button",{onClick:Z,className:"px-3 py-1 text-xs bg-red-600 text-white rounded hover:bg-red-700 flex items-center space-x-1",title:"断开 Shell 连接",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),e.jsx("span",{children:"断开连接"})]}),e.jsxs("button",{onClick:z,disabled:$||M,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Shell(先断开连接)",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),e.jsx("span",{children:"重启"})]})]})]})}),e.jsxs("div",{className:"flex-1 p-2 overflow-hidden relative",children:[e.jsx("div",{ref:m,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!w&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90",children:e.jsx("div",{className:"text-white",children:"加载终端中..."})}),w&&!M&&!p&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("button",{onClick:ie,className:"px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center justify-center space-x-2 text-base font-medium w-full sm:w-auto",title:"Connect to shell",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{children:"在 Shell 中继续"})]}),e.jsx("p",{className:"text-gray-400 text-sm mt-3 px-2",children:o?`Run ${a||"command"} in ${t.displayName}`:r?`Resume session: ${T}...`:"Start a new Claude session"})]})}),p&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("div",{className:"flex items-center justify-center space-x-3 text-yellow-400",children:[e.jsx("div",{className:"w-6 h-6 animate-spin rounded-full border-2 border-yellow-400 border-t-transparent"}),e.jsx("span",{className:"text-base font-medium",children:"连接到 Shell..."})]}),e.jsx("p",{className:"text-gray-400 text-sm mt-3 px-2",children:o?`Running ${a||"command"} in ${t.displayName}`:`Starting Claude CLI in ${t.displayName}`})]})})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"选择项目"}),e.jsx("p",{children:"选择一个项目以在该目录中打开交互式 Shell"})]})})}function ti({project:t,session:r=null,command:a=null,isPlainShell:o=null,autoConnect:n=!0,onComplete:l=null,onClose:i=null,title:m=null,className:x="",showHeader:g=!0,compact:v=!1,minimal:M=!1}){const[j,w]=s.useState(!1),h=o!==null?o:a!==null,$=s.useCallback(L=>{w(!0),l&&l(L)},[l]);return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${x}`,children:[!M&&g&&m&&e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-200",children:m}),j&&e.jsx("span",{className:"text-xs text-green-400",children:"(已完成)"})]}),i&&e.jsx("button",{onClick:i,className:"text-gray-400 hover:text-white",title:"关闭",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsx("div",{className:"flex-1 w-full min-h-0",children:e.jsx(ei,{selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:h,onProcessComplete:$,minimal:M,autoConnect:M?!0:n})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${x}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Shell 需要一个项目"})]})})}function ri({selectedProject:t,minimal:r=!1,autoConnect:a=!1}){const o=s.useRef(null),n=s.useRef(null),l=s.useRef(null),i=s.useRef(null),[m,x]=s.useState(!1),[g,v]=s.useState(!1),[M,j]=s.useState(!1),[w,h]=s.useState(!1),$=s.useRef(t);s.useEffect(()=>{$.current=t});const L=s.useCallback(async()=>{if(!(w||m))try{let k;{const S=localStorage.getItem("auth-token");if(!S){console.error("No authentication token found for Codex WebSocket connection");return}k=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/codex?token=${encodeURIComponent(S)}`}i.current=new WebSocket(k),i.current.onopen=()=>{x(!0),h(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:$.current.fullPath||$.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=S=>{try{const A=JSON.parse(S.data);A.type==="output"?n.current&&n.current.write(A.data):A.type==="url_open"&&window.open(A.url,"_blank")}catch(A){console.error("[CodexShell] Error handling WebSocket message:",A)}},i.current.onclose=()=>{x(!1),h(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{x(!1),h(!1)}}catch{x(!1),h(!1)}},[w,m]),I=s.useCallback(()=>{!g||m||w||(h(!0),L())},[g,m,w,L]),C=s.useCallback(()=>{i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H")),x(!1),h(!1)},[]),p=()=>{j(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),x(!1),v(!1),setTimeout(()=>j(!1),200)};return s.useEffect(()=>{if(!o.current||!t||M||n.current)return;n.current=new ea.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Menlo, Monaco, "Courier New", monospace',allowProposedApi:!0,allowTransparency:!1,convertEol:!0,scrollback:1e4,tabStopWidth:4,windowsMode:!1,macOptionIsMeta:!0,macOptionClickForcesSelection:!1,theme:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#ffffff",cursorAccent:"#1e1e1e",selection:"#264f78",selectionForeground:"#ffffff",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"}}),l.current=new ta.FitAddon;const d=new ra.WebglAddon,k=new sa.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(k);try{n.current.loadAddon(d)}catch{console.warn("[CodexShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(A=>(A.ctrlKey||A.metaKey)&&A.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(A.ctrlKey||A.metaKey)&&A.key==="v"?(navigator.clipboard.readText().then(W=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:W}))}).catch(()=>{}),!1):!0),setTimeout(()=>{l.current&&(l.current.fit(),n.current&&i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"resize",cols:n.current.cols,rows:n.current.rows})))},100),v(!0),n.current.onData(A=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:A}))});const S=new ResizeObserver(()=>{l.current&&n.current&&setTimeout(()=>{l.current.fit(),i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"resize",cols:n.current.cols,rows:n.current.rows}))},50)});return o.current&&S.observe(o.current),()=>{S.disconnect(),i.current&&(i.current.readyState===WebSocket.OPEN||i.current.readyState===WebSocket.CONNECTING)&&i.current.close(),i.current=null,n.current&&(n.current.dispose(),n.current=null)}},[t?.path||t?.fullPath,M]),s.useEffect(()=>{!a||!g||w||m||I()},[a,g,w,m,I]),t?r?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}})}):e.jsxs("div",{className:"h-full flex flex-col bg-gray-900 w-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${m?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-300 font-medium",children:"Codex"}),!g&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),M&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[m&&e.jsxs("button",{onClick:C,className:"px-3 py-1 text-xs bg-red-600 text-white rounded hover:bg-red-700 flex items-center space-x-1",title:"断开 Codex 连接",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),e.jsx("span",{children:"断开连接"})]}),e.jsxs("button",{onClick:p,disabled:M||m,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Codex(先断开连接)",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),e.jsx("span",{children:"重启"})]})]})]})}),e.jsxs("div",{className:"flex-1 p-2 overflow-hidden relative",children:[e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!g&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90",children:e.jsx("div",{className:"text-white",children:"加载终端中..."})}),g&&!m&&!w&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("button",{onClick:I,className:"px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center justify-center space-x-2 text-base font-medium w-full sm:w-auto",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{children:"启动 Codex"})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["在 ",t.displayName," 中启动 Codex CLI"]})]})}),w&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("div",{className:"flex items-center justify-center space-x-3 text-yellow-400",children:[e.jsx("div",{className:"w-6 h-6 animate-spin rounded-full border-2 border-yellow-400 border-t-transparent"}),e.jsx("span",{className:"text-base font-medium",children:"连接到 Codex..."})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["正在 ",t.displayName," 中启动 Codex CLI"]})]})})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"选择项目"}),e.jsx("p",{children:"选择一个项目以在该目录中打开 Codex"})]})})}function si({project:t,autoConnect:r=!0,onClose:a=null,className:o="",showHeader:n=!0,minimal:l=!1}){return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${o}`,children:[!l&&n&&a&&e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-200",children:"Codex"}),e.jsx("button",{onClick:a,className:"text-gray-400 hover:text-white",title:"关闭",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsx("div",{className:"flex-1 w-full min-h-0",children:e.jsx(ri,{selectedProject:t,minimal:l,autoConnect:l?!0:r})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${o}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Codex 需要一个项目"})]})})}class ai extends rt.Component{constructor(r){super(r),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0}}componentDidCatch(r,a){console.error("ErrorBoundary caught an error:",r,a),this.setState({error:r,errorInfo:a})}render(){return this.state.hasError?e.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-6 max-w-md",children:[e.jsxs("div",{className:"flex items-center mb-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-red-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})}),e.jsx("h3",{className:"ml-3 text-sm font-medium text-red-800",children:"出现问题"})]}),e.jsxs("div",{className:"text-sm text-red-700",children:[e.jsx("p",{className:"mb-2",children:"加载聊天界面时出现错误。"}),this.props.showDetails&&this.state.error&&e.jsxs("details",{className:"mt-4",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-mono",children:"错误详情"}),e.jsxs("pre",{className:"mt-2 text-xs bg-red-100 p-2 rounded overflow-auto max-h-40",children:[this.state.error.toString(),this.state.errorInfo&&this.state.errorInfo.componentStack]})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:()=>{this.setState({hasError:!1,error:null,errorInfo:null}),this.props.onRetry&&this.props.onRetry()},className:"bg-red-600 text-white px-4 py-2 rounded text-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500",children:"重试"})})]})}):this.props.children}}const sr=({children:t,content:r,position:a="top",className:o="",delay:n=500})=>{const[l,i]=s.useState(!1),[m,x]=s.useState(null),g=()=>{const w=setTimeout(()=>{i(!0)},n);x(w)},v=()=>{m&&(clearTimeout(m),x(null)),i(!1)},M=()=>{switch(a){case"top":return"bottom-full left-1/2 transform -translate-x-1/2 mb-2";case"bottom":return"top-full left-1/2 transform -translate-x-1/2 mt-2";case"left":return"right-full top-1/2 transform -translate-y-1/2 mr-2";case"right":return"left-full top-1/2 transform -translate-y-1/2 ml-2";default:return"bottom-full left-1/2 transform -translate-x-1/2 mb-2"}},j=()=>{switch(a){case"top":return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100";case"bottom":return"bottom-full left-1/2 transform -translate-x-1/2 border-b-gray-900 dark:border-b-gray-100";case"left":return"left-full top-1/2 transform -translate-y-1/2 border-l-gray-900 dark:border-l-gray-100";case"right":return"right-full top-1/2 transform -translate-y-1/2 border-r-gray-900 dark:border-r-gray-100";default:return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100"}};return r?e.jsxs("div",{className:"relative inline-block",onMouseEnter:g,onMouseLeave:v,children:[t,l&&e.jsxs("div",{className:Fe("absolute z-50 px-2 py-1 text-xs font-medium text-white bg-gray-900 dark:bg-gray-100 dark:text-gray-900 rounded shadow-lg whitespace-nowrap pointer-events-none","animate-in fade-in-0 zoom-in-95 duration-200",M(),o),children:[r,e.jsx("div",{className:Fe("absolute w-0 h-0 border-4 border-transparent",j())})]})]}):t};function ni({selectedProject:t,selectedSession:r,activeTab:a,setActiveTab:o,ws:n,sendMessage:l,messages:i,isMobile:m,isPWA:x,onMenuClick:g,isLoading:v,onInputFocusChange:M,onSessionActive:j,onSessionInactive:w,onSessionProcessing:h,onSessionNotProcessing:$,processingSessions:L,onReplaceTemporarySession:I,onNavigateToSession:C,onShowSettings:p,autoExpandTools:d,showRawParameters:k,showThinking:S,autoScrollToBottom:A,sendByCtrlEnter:W,externalMessageUpdate:O,limitStatus:Q,onLimitBlocked:ie,checkLimitStatus:Z}){const[se,B]=s.useState(null),[T,z]=s.useState(600),[Y,pe]=s.useState(!1),[ae,G]=s.useState(!1),xe=s.useRef(null);s.useEffect(()=>{a==="shell"&&Z&&Z()},[a,Z]);const Ne=(he,Se=null)=>{const ke={name:he.split("/").pop(),path:he,projectName:t?.name,diffInfo:Se};B(ke)},Ce=()=>{B(null),G(!1)},je=()=>{G(!ae)},_e=he=>{m||(pe(!0),he.preventDefault())};return s.useEffect(()=>{const he=ke=>{if(!Y)return;const Ee=xe.current?.parentElement;if(!Ee)return;const ve=Ee.getBoundingClientRect(),Pe=ve.right-ke.clientX,Re=300,Me=ve.width*.8;Pe>=Re&&Pe<=Me&&z(Pe)},Se=()=>{pe(!1)};return Y&&(document.addEventListener("mousemove",he),document.addEventListener("mouseup",Se),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",he),document.removeEventListener("mouseup",Se),document.body.style.cursor="",document.body.style.userSelect=""}},[Y]),v?e.jsxs("div",{className:"h-full flex flex-col",children:[m&&e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsx("button",{onClick:g,className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 pwa-menu-button",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-4",children:e.jsx("div",{className:"w-full h-full rounded-full border-4 border-gray-200 border-t-blue-500",style:{animation:"spin 1s linear infinite",WebkitAnimation:"spin 1s linear infinite",MozAnimation:"spin 1s linear infinite"}})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"正在加载 AgentHub"}),e.jsx("p",{children:"正在设置您的工作区..."})]})})]}):t?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between relative",children:[e.jsxs("div",{className:"flex items-center space-x-2 min-w-0 flex-1",children:[m&&e.jsx("button",{onClick:g,onTouchStart:he=>{he.preventDefault(),g()},className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 touch-manipulation active:scale-95 pwa-menu-button flex-shrink-0",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),e.jsxs("div",{className:"min-w-0 flex items-center gap-2 flex-1 overflow-x-auto scrollbar-hide",children:[a==="chat"&&r&&e.jsx("div",{className:"w-5 h-5 flex-shrink-0 flex items-center justify-center",children:e.jsx(ot,{className:"w-4 h-4"})}),e.jsx("div",{className:"min-w-0 flex-1",children:a==="chat"&&r?e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white whitespace-nowrap overflow-x-auto scrollbar-hide",children:r.summary||"新会话"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]}):a==="chat"&&!r?e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white",children:"新会话"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]}):e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white",children:a==="files"?"项目文件":"项目"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]})})]})]}),e.jsx("div",{className:"flex-shrink-0 hidden sm:block",children:e.jsxs("div",{className:"relative flex bg-gray-100 dark:bg-gray-800 rounded-lg p-1",children:[e.jsx(sr,{content:"Chat",position:"bottom",children:e.jsx("button",{onClick:()=>o("chat"),className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md ${a==="chat"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Chat"})]})})}),e.jsx(sr,{content:Q&&!Q.allowed?"使用已达上限":"Shell",position:"bottom",children:e.jsx("button",{onClick:()=>{if(Q&&!Q.allowed){ie?.(Q.reason);return}o("shell")},className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md transition-all duration-200 ${Q&&!Q.allowed?"opacity-50 cursor-not-allowed text-gray-400 dark:text-gray-500":a==="shell"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Shell"})]})})}),e.jsx(sr,{content:"Files",position:"bottom",children:e.jsx("button",{onClick:()=>o("files"),className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md transition-all duration-200 ${a==="files"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-5l-2-2H5a2 2 0 00-2 2z"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Files"})]})})}),e.jsx(sr,{content:"Codex",position:"bottom",children:e.jsx("button",{onClick:()=>o("codex"),className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md transition-all duration-200 ${a==="codex"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Codex"})]})})})]})})]})}),e.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[e.jsxs("div",{className:`flex-1 flex flex-col min-h-0 overflow-hidden ${se?"mr-0":""} ${ae?"hidden":""}`,children:[e.jsx("div",{className:`h-full ${a==="chat"?"block":"hidden"}`,children:e.jsx(ai,{showDetails:!0,children:e.jsx(Yo,{selectedProject:t,selectedSession:r,ws:n,sendMessage:l,messages:i,onFileOpen:Ne,onInputFocusChange:M,onSessionActive:j,onSessionInactive:w,onSessionProcessing:h,onSessionNotProcessing:$,processingSessions:L,onReplaceTemporarySession:I,onNavigateToSession:C,onShowSettings:p,autoExpandTools:d,showRawParameters:k,showThinking:S,autoScrollToBottom:A,sendByCtrlEnter:W,externalMessageUpdate:O,limitStatus:Q,onLimitExceeded:ie,checkLimitStatus:Z})})}),a==="files"&&e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx(Zo,{selectedProject:t})}),a==="shell"&&e.jsxs("div",{className:"h-full w-full overflow-hidden relative",children:[e.jsx(ti,{project:t,session:r,showHeader:!1}),Q&&!Q.allowed&&e.jsx("div",{className:"absolute inset-0 bg-black/60 z-50 flex items-center justify-center",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-xl p-6 mx-4 max-w-md text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-4 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-6 h-6 text-red-600 dark:text-red-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:Q.reason==="total_limit_exceeded"?"使用上限已达到":"今日使用上限已达到"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:Q.reason==="total_limit_exceeded"?"您已达到使用上限,请联系管理员提升额度。":"您已达到今日使用上限,请明日再来或联系管理员提升额度。"}),e.jsx("button",{onClick:()=>o("chat"),className:"px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors",children:"返回 Chat"})]})})]}),a==="codex"&&e.jsx("div",{className:"h-full w-full overflow-hidden relative",children:e.jsx(si,{project:t,showHeader:!1})}),e.jsx("div",{className:`h-full overflow-hidden ${a==="preview"?"block":"hidden"}`})]}),se&&!m&&e.jsxs(e.Fragment,{children:[!ae&&e.jsx("div",{ref:xe,onMouseDown:_e,className:"flex-shrink-0 w-1 bg-gray-200 dark:bg-gray-700 hover:bg-blue-500 dark:hover:bg-blue-600 cursor-col-resize transition-colors relative group",title:"Drag to resize",children:e.jsx("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-1 bg-blue-500 dark:bg-blue-600 opacity-0 group-hover:opacity-100 transition-opacity"})}),e.jsx("div",{className:`flex-shrink-0 border-l border-gray-200 dark:border-gray-700 h-full overflow-hidden ${ae?"flex-1":""}`,style:ae?{}:{width:`${T}px`},children:e.jsx(Ur,{file:se,onClose:Ce,projectPath:t?.path,isSidebar:!0,isExpanded:ae,onToggleExpand:je})})]})]}),se&&m&&e.jsx(Ur,{file:se,onClose:Ce,projectPath:t?.path,isSidebar:!1})]}):e.jsxs("div",{className:"h-full flex flex-col",children:[m&&e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsx("button",{onClick:g,className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 pwa-menu-button",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400 max-w-md mx-auto px-6",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-6 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-5l-2-2H5a2 2 0 00-2 2z"})})}),e.jsx("h2",{className:"text-2xl font-semibold mb-3 text-gray-900 dark:text-white",children:"选择您的项目"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-300 mb-6 leading-relaxed",children:"从侧边栏选择一个项目,开始与 Claude 进行编码。每个项目包含您的聊天会话和文件历史。"}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 rounded-lg p-4 border border-blue-200 dark:border-blue-800",children:e.jsxs("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:["💡 ",e.jsx("strong",{children:"提示:"})," ",m?"点击上方菜单按钮访问项目":"点击侧边栏中的文件夹图标创建新项目"]})})]})})]})}const oi=rt.memo(ni);function ii({activeTab:t,setActiveTab:r,isInputFocused:a}){const o=[{id:"chat",icon:Dt,onClick:()=>r("chat")},{id:"shell",icon:dr,onClick:()=>r("shell")},{id:"files",icon:tt,onClick:()=>r("files")}];return e.jsx("div",{className:`fixed bottom-0 left-0 right-0 bg-background border-t border-border z-50 ios-bottom-safe transform transition-transform duration-300 ease-in-out shadow-lg ${a?"translate-y-full":"translate-y-0"}`,children:e.jsx("div",{className:"flex items-center justify-around py-1",children:o.map(n=>{const l=n.icon,i=t===n.id;return e.jsxs("button",{onClick:n.onClick,onTouchStart:m=>{m.preventDefault(),n.onClick()},className:`flex items-center justify-center p-2 rounded-lg min-h-[40px] min-w-[40px] relative touch-manipulation ${i?"text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white"}`,"aria-label":n.id,children:[e.jsx(l,{className:"w-5 h-5"}),i&&e.jsx("div",{className:"absolute top-0 left-1/2 transform -translate-x-1/2 w-6 h-0.5 bg-blue-600 dark:bg-blue-400 rounded-full"})]},n.id)})})})}const aa=s.createContext(),Yr=()=>{const t=s.useContext(aa);if(!t)throw new Error("useTheme must be used within a ThemeProvider");return t},li=({children:t})=>{const[r,a]=s.useState(()=>{const l=localStorage.getItem("theme");return l?l==="dark":window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches:!1});s.useEffect(()=>{if(r){document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark");const l=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');l&&l.setAttribute("content","black-translucent");const i=document.querySelector('meta[name="theme-color"]');i&&i.setAttribute("content","#0c1117")}else{document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light");const l=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');l&&l.setAttribute("content","default");const i=document.querySelector('meta[name="theme-color"]');i&&i.setAttribute("content","#ffffff")}},[r]),s.useEffect(()=>{if(!window.matchMedia)return;const l=window.matchMedia("(prefers-color-scheme: dark)"),i=m=>{localStorage.getItem("theme")||a(m.matches)};return l.addEventListener("change",i),()=>l.removeEventListener("change",i)},[]);const n={isDarkMode:r,toggleDarkMode:()=>{a(l=>!l)}};return e.jsx(aa.Provider,{value:n,children:t})},na=s.createContext({user:null,token:null,login:()=>{},sendCode:()=>{},verifyCode:()=>{},logout:()=>{},isLoading:!0,needsSetup:!1,smtpConfigured:!1,error:null,isAdmin:!1,limitStatus:{allowed:!0},checkLimitStatus:()=>{},setLimitStatus:()=>{}}),$t=()=>{const t=s.useContext(na);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t},ci=({children:t})=>{const[r,a]=s.useState(null),[o,n]=s.useState(localStorage.getItem("auth-token")),[l,i]=s.useState(!0),[m,x]=s.useState(!1),[g,v]=s.useState(!1),[M,j]=s.useState(null),[w,h]=s.useState({allowed:!0});s.useEffect(()=>{$()},[]);const $=async()=>{try{i(!0),j(null);const A=await(await we.auth.status()).json();if(v(A.smtpConfigured||!1),A.needsSetup){x(!0),i(!1);return}if(o)try{const W=await we.auth.user();if(W.ok){const O=await W.json();a(O.user),x(!1)}else localStorage.removeItem("auth-token"),n(null),a(null)}catch(W){console.error("Token verification failed:",W),localStorage.removeItem("auth-token"),n(null),a(null)}}catch(S){console.error("[AuthContext] Auth status check failed:",S),j("Failed to check authentication status")}finally{i(!1)}},L=async S=>{try{j(null);const A=await we.auth.sendCode(S),W=await A.json();return A.ok?{success:!0,type:W.type}:{success:!1,error:W.error||"发送验证码失败",waitSeconds:W.waitSeconds}}catch(A){return console.error("Send code error:",A),{success:!1,error:"网络错误,请稍后再试"}}},I=async(S,A)=>{try{j(null);const W=await we.auth.verifyCode(S,A),O=await W.json();return W.ok?(n(O.token),a(O.user),x(!1),localStorage.setItem("auth-token",O.token),{success:!0}):(j(O.error||"验证失败"),{success:!1,error:O.error||"验证失败"})}catch(W){return console.error("Verify code error:",W),{success:!1,error:"网络错误,请稍后再试"}}},C=async(S,A)=>{try{j(null);const W=await we.auth.login(S,A),O=await W.json();return W.ok?(n(O.token),a(O.user),localStorage.setItem("auth-token",O.token),{success:!0}):(j(O.error||"登录失败"),{success:!1,error:O.error||"登录失败"})}catch(W){console.error("Login error:",W);const O="网络错误,请稍后再试";return j(O),{success:!1,error:O}}},p=()=>{n(null),a(null),h({allowed:!0}),localStorage.removeItem("auth-token"),o&&we.auth.logout().catch(S=>{console.error("Logout endpoint error:",S)})},d=async()=>{if(!r)return{allowed:!0};try{const S=await we.auth.limitStatus();if(S.ok){const A=await S.json();return h(A),A}}catch(S){console.error("Error checking limit status:",S)}return{allowed:!0}};s.useEffect(()=>{r&&!l&&d()},[r,l]);const k={user:r,token:o,login:C,sendCode:L,verifyCode:I,logout:p,isLoading:l,needsSetup:m,smtpConfigured:g,error:M,isAdmin:r?.role==="admin",limitStatus:w,checkLimitStatus:d,setLimitStatus:h};return e.jsx(na.Provider,{value:k,children:t})},di=["Bash(git log:*)","Bash(git diff:*)","Bash(git status:*)","Write","Read","Edit","Glob","Grep","MultiEdit","Task","TodoWrite","TodoRead","WebFetch","WebSearch"],mi=["Shell(ls)","Shell(mkdir)","Shell(cd)","Shell(cat)","Shell(echo)","Shell(git status)","Shell(git diff)","Shell(git log)","Shell(npm install)","Shell(npm run)","Shell(python)","Shell(node)"];function ui({skipPermissions:t,setSkipPermissions:r,allowedTools:a,setAllowedTools:o,disallowedTools:n,setDisallowedTools:l,newAllowedTool:i,setNewAllowedTool:m,newDisallowedTool:x,setNewDisallowedTool:g}){const v=h=>{h&&!a.includes(h)&&(o([...a,h]),m(""))},M=h=>{o(a.filter($=>$!==h))},j=h=>{h&&!n.includes(h)&&(l([...n,h]),g(""))},w=h=>{l(n.filter($=>$!==h))};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-sky-50 dark:bg-sky-900/20 border border-sky-200 dark:border-sky-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(As,{className:"w-5 h-5 text-sky-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-sky-800 dark:text-sky-200",children:[e.jsx("span",{className:"font-medium",children:"提示:"}),"此权限设置仅对 ",e.jsx("span",{className:"font-medium",children:"Chat(聊天)"})," 中的 Claude Agent 生效,对 ",e.jsx("span",{className:"font-medium",children:"Shell(终端)"})," 无效。Shell 是直接的系统终端,不受此权限控制。"]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-orange-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"权限设置"})]}),e.jsx("div",{className:"bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg p-4",children:e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:t,onChange:h=>r(h.target.checked),className:"w-4 h-4 text-blue-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-blue-500 focus:ring-2"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-orange-900 dark:text-orange-100",children:"跳过权限提示(请谨慎使用)"}),e.jsx("div",{className:"text-sm text-orange-700 dark:text-orange-300",children:"等同于 --dangerously-skip-permissions 标志"})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mr,{className:"w-5 h-5 text-green-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"允许的工具"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动允许而不提示权限的工具"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:i,onChange:h=>m(h.target.value),placeholder:'e.g., "Bash(git log:*)" or "Write"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),v(i))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>v(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"快速添加常用工具:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:di.map(h=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>v(h),disabled:a.includes(h),className:"text-xs h-8",children:h},h))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-green-800 dark:text-green-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>M(h),className:"text-green-600 hover:text-green-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),a.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置允许的工具"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-red-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"阻止的工具"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动阻止而不提示权限的工具"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:x,onChange:h=>g(h.target.value),placeholder:'e.g., "Bash(rm:*)"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),j(x))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>j(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[n.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-red-800 dark:text-red-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>w(h),className:"text-red-600 hover:text-red-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),n.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置阻止的工具"})]})]}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h4",{className:"font-medium text-blue-900 dark:text-blue-100 mb-2",children:"工具模式示例:"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-1",children:[e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Bash(git log:*)"'})," - 允许所有 git log 命令"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Bash(git diff:*)"'})," - 允许所有 git diff 命令"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Write"'})," - 允许所有 Write 工具使用"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Bash(rm:*)"'})," - 阻止所有 rm 命令(危险)"]})]})]})]})}function pi({skipPermissions:t,setSkipPermissions:r,allowedCommands:a,setAllowedCommands:o,disallowedCommands:n,setDisallowedCommands:l,newAllowedCommand:i,setNewAllowedCommand:m,newDisallowedCommand:x,setNewDisallowedCommand:g}){const v=h=>{h&&!a.includes(h)&&(o([...a,h]),m(""))},M=h=>{o(a.filter($=>$!==h))},j=h=>{h&&!n.includes(h)&&(l([...n,h]),g(""))},w=h=>{l(n.filter($=>$!==h))};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-orange-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"权限设置"})]}),e.jsx("div",{className:"bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg p-4",children:e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:t,onChange:h=>r(h.target.checked),className:"w-4 h-4 text-purple-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-purple-500 focus:ring-2"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-orange-900 dark:text-orange-100",children:"跳过权限提示(请谨慎使用)"}),e.jsx("div",{className:"text-sm text-orange-700 dark:text-orange-300",children:"等同于 Cursor CLI 中的 -f 标志"})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mr,{className:"w-5 h-5 text-green-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"允许的 Shell 命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动允许而不提示的 Shell 命令"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:i,onChange:h=>m(h.target.value),placeholder:'e.g., "Shell(ls)" or "Shell(git status)"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),v(i))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>v(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"快速添加常用命令:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:mi.map(h=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>v(h),disabled:a.includes(h),className:"text-xs h-8",children:h},h))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-green-800 dark:text-green-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>M(h),className:"text-green-600 hover:text-green-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),a.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置允许的命令"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-red-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"阻止的 Shell 命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动阻止的 Shell 命令"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:x,onChange:h=>g(h.target.value),placeholder:'e.g., "Shell(rm -rf)" or "Shell(sudo)"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),j(x))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>j(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[n.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-red-800 dark:text-red-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>w(h),className:"text-red-600 hover:text-red-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),n.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置阻止的命令"})]})]}),e.jsxs("div",{className:"bg-purple-50 dark:bg-purple-900/20 border border-purple-200 dark:border-purple-800 rounded-lg p-4",children:[e.jsx("h4",{className:"font-medium text-purple-900 dark:text-purple-100 mb-2",children:"Shell 命令示例:"}),e.jsxs("ul",{className:"text-sm text-purple-800 dark:text-purple-200 space-y-1",children:[e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(ls)"'})," - 允许 ls 命令"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(git status)"'})," - 允许 git status"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(npm install)"'})," - 允许 npm install"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(rm -rf)"'})," - 阻止递归删除"]})]})]})]})}function xi({permissionMode:t,setPermissionMode:r}){return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mr,{className:"w-5 h-5 text-green-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"权限模式"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"控制 Codex 如何处理文件修改和命令执行"}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="default"?"bg-gray-100 dark:bg-gray-800 border-gray-400 dark:border-gray-500":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("default"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="default",onChange:()=>r("default"),className:"mt-1 w-4 h-4 text-green-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"默认"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"仅受信任的命令(ls、cat、grep、git status 等)会自动运行。其他命令将被跳过。可以写入工作区。"})]})]})}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="acceptEdits"?"bg-green-50 dark:bg-green-900/20 border-green-400 dark:border-green-600":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("acceptEdits"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="acceptEdits",onChange:()=>r("acceptEdits"),className:"mt-1 w-4 h-4 text-green-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-green-900 dark:text-green-100",children:"接受编辑"}),e.jsx("div",{className:"text-sm text-green-700 dark:text-green-300",children:"所有命令在工作区内自动运行。沙盒执行的完全自动模式。"})]})]})}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="bypassPermissions"?"bg-orange-50 dark:bg-orange-900/20 border-orange-400 dark:border-orange-600":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("bypassPermissions"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="bypassPermissions",onChange:()=>r("bypassPermissions"),className:"mt-1 w-4 h-4 text-orange-600"}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium text-orange-900 dark:text-orange-100 flex items-center gap-2",children:["跳过权限",e.jsx(Pt,{className:"w-4 h-4"})]}),e.jsx("div",{className:"text-sm text-orange-700 dark:text-orange-300",children:"无限制的完全系统访问。所有命令自动运行,具有完全的磁盘和网络访问权限。请谨慎使用。"})]})]})}),e.jsxs("details",{className:"text-sm",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"技术详情"}),e.jsxs("div",{className:"mt-2 p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg text-xs text-muted-foreground space-y-2",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Default:"})," sandboxMode=workspace-write, approvalPolicy=untrusted. Trusted commands: cat, cd, grep, head, ls, pwd, tail, git status/log/diff/show, find (without -exec), etc."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Accept Edits:"})," sandboxMode=workspace-write, approvalPolicy=never. All commands auto-execute within project directory."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Bypass Permissions:"})," sandboxMode=danger-full-access, approvalPolicy=never. Full system access, use only in trusted environments."]}),e.jsx("p",{className:"text-xs opacity-75",children:"您可以在聊天界面中使用模式按钮为每个会话覆盖此设置。"})]})]})]})})}function hi({agent:t,...r}){return t==="claude"?e.jsx(ui,{...r}):t==="cursor"?e.jsx(pi,{...r}):t==="codex"?e.jsx(xi,{...r}):null}const gi=t=>{switch(t){case"stdio":return e.jsx(dr,{className:"w-4 h-4"});case"sse":return e.jsx(sn,{className:"w-4 h-4"});case"http":return e.jsx(Tr,{className:"w-4 h-4"});default:return e.jsx(ur,{className:"w-4 h-4"})}};function fi({servers:t,onAdd:r,onEdit:a,onDelete:o,onTest:n,onDiscoverTools:l,testResults:i,serverTools:m,toolsLoading:x}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ur,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Claude 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(J,{onClick:r,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]})}),e.jsxs("div",{className:"space-y-2",children:[t.map(g=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[gi(g.type),e.jsx("span",{className:"font-medium text-foreground",children:g.name}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:g.type}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:g.scope==="local"?"local":g.scope==="user"?"user":g.scope})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[g.type==="stdio"&&g.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:g.config.command})]}),(g.type==="sse"||g.type==="http")&&g.config?.url&&e.jsxs("div",{children:["URL:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:g.config.url})]}),g.config?.args&&g.config.args.length>0&&e.jsxs("div",{children:["参数:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:g.config.args.join(" ")})]})]}),i?.[g.id]&&e.jsx("div",{className:`mt-2 p-2 rounded text-xs ${i[g.id].success?"bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200":"bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200"}`,children:e.jsx("div",{className:"font-medium",children:i[g.id].message})}),m?.[g.id]&&m[g.id].tools?.length>0&&e.jsxs("div",{className:"mt-2 p-2 rounded text-xs bg-blue-50 dark:bg-blue-900/20 text-blue-800 dark:text-blue-200",children:[e.jsxs("div",{className:"font-medium",children:["工具(",m[g.id].tools.length,"):"]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[m[g.id].tools.slice(0,5).map((v,M)=>e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:v.name},M)),m[g.id].tools.length>5&&e.jsxs("span",{className:"text-xs opacity-75",children:["+",m[g.id].tools.length-5," 更多"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{onClick:()=>a(g),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(Ut,{className:"w-4 h-4"})}),e.jsx(J,{onClick:()=>o(g.id,g.scope),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},g.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function bi({servers:t,onAdd:r,onEdit:a,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ur,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Cursor 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(J,{onClick:r,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]})}),e.jsxs("div",{className:"space-y-2",children:[t.map(n=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(dr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:"stdio"})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:n.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:n.config.command})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",children:e.jsx(Ut,{className:"w-4 h-4"})}),e.jsx(J,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},n.name||n.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function vi({servers:t,onAdd:r,onEdit:a,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ur,{className:"w-5 h-5 text-gray-700 dark:text-gray-300"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Codex 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(J,{onClick:r,className:"bg-gray-800 hover:bg-gray-900 dark:bg-gray-700 dark:hover:bg-gray-600 text-white",size:"sm",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]})}),e.jsxs("div",{className:"space-y-2",children:[t.map(n=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(dr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:"stdio"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[n.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:n.config.command})]}),n.config?.args&&n.config.args.length>0&&e.jsxs("div",{children:["参数:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:n.config.args.join(" ")})]}),n.config?.env&&Object.keys(n.config.env).length>0&&e.jsxs("div",{children:["环境变量:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:Object.entries(n.config.env).map(([l,i])=>`${l}=${i}`).join(", ")})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(Ut,{className:"w-4 h-4"})}),e.jsx(J,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},n.name)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]}),e.jsxs("div",{className:"bg-gray-100 dark:bg-gray-800/50 border border-gray-300 dark:border-gray-600 rounded-lg p-4",children:[e.jsx("h4",{className:"font-medium text-gray-900 dark:text-gray-100 mb-2",children:"关于 Codex MCP"}),e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Codex 支持基于 stdio 的 MCP 服务器。您可以添加扩展 Codex 功能的服务器,提供额外的工具和资源。"})]})]})}function yi({agent:t,...r}){return t==="claude"?e.jsx(fi,{...r}):t==="cursor"?e.jsx(bi,{...r}):t==="codex"?e.jsx(vi,{...r}):null}const ji=[{key:"ANTHROPIC_DEFAULT_OPUS_MODEL",label:"Opus 模型",placeholder:"例如: claude-opus-4-6",description:"覆盖 opus 别名使用的模型,Plan Mode 激活时也用于 opusplan"},{key:"ANTHROPIC_DEFAULT_SONNET_MODEL",label:"Sonnet 模型",placeholder:"例如: claude-sonnet-4-5-20250929",description:"覆盖 sonnet 别名使用的模型,Plan Mode 未激活时也用于 opusplan"},{key:"ANTHROPIC_DEFAULT_HAIKU_MODEL",label:"Haiku 模型",placeholder:"例如: claude-haiku-4-5-20251001",description:"覆盖 haiku 别名使用的模型,也用于后台功能"},{key:"CLAUDE_CODE_SUBAGENT_MODEL",label:"Subagent 模型",placeholder:"例如: claude-haiku-4-5-20251001",description:"覆盖子代理(subagents)使用的模型"}];function wi(){const[t,r]=s.useState({}),[a,o]=s.useState({}),[n,l]=s.useState(!0),[i,m]=s.useState(!1),[x,g]=s.useState(null),[v,M]=s.useState(null);s.useEffect(()=>{j()},[]),s.useEffect(()=>{if(x){const L=setTimeout(()=>g(null),3e3);return()=>clearTimeout(L)}},[x]);const j=async()=>{try{l(!0),M(null);const L=await ne("/api/settings/models");if(L.ok){const I=await L.json();r(I.models||{}),o(I.models||{})}else{const I=await L.json();M(I.error||"加载模型配置失败")}}catch(L){M(L.message)}finally{l(!1)}},w=async()=>{try{m(!0),g(null);const L=await ne("/api/settings/models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({models:t})});if(L.ok)g("success"),o({...t});else{const I=await L.json();g("error"),M(I.error||"保存失败")}}catch(L){g("error"),M(L.message)}finally{m(!1)}},h=()=>{r({...a}),g(null)},$=JSON.stringify(t)!==JSON.stringify(a);return n?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-500"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"加载模型配置..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-3",children:[e.jsx(As,{className:"w-4 h-4 text-blue-500 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{children:"自定义模型 ID 来覆盖 Claude Code 使用的默认模型。留空表示使用默认模型。"}),e.jsx("p",{className:"mt-1 text-blue-600 dark:text-blue-400",children:"非 Claude 模型将按 Sonnet 定价计费,但统计中会记录实际模型 ID。"})]})]}),v&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-600 dark:text-red-400",children:v}),ji.map(L=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"font-medium text-sm text-foreground",children:L.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:L.description})]}),e.jsx("input",{type:"text",value:t[L.key]||"",onChange:I=>r(C=>({...C,[L.key]:I.target.value})),placeholder:L.placeholder,className:"w-full text-sm bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 px-3 py-2"}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:L.key})]})},L.key)),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("div",{children:[x==="success"&&e.jsx("span",{className:"text-sm text-green-600 dark:text-green-400",children:"模型配置已保存"}),x==="error"&&e.jsx("span",{className:"text-sm text-red-600 dark:text-red-400",children:"保存失败"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:h,disabled:!$,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-lg border border-gray-300 dark:border-gray-600 text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx(an,{className:"w-3.5 h-3.5"}),"重置"]}),e.jsxs("button",{onClick:w,disabled:!$||i,className:"inline-flex items-center gap-1.5 px-4 py-1.5 text-sm rounded-lg bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx(Rs,{className:"w-3.5 h-3.5"}),i?"保存中...":"保存"]})]})]})]})}function ki({onNavigateToUsage:t}){const[r,a]=s.useState([]),[o,n]=s.useState({}),[l,i]=s.useState(!0),[m,x]=s.useState(null),[g,v]=s.useState(!1),[M,j]=s.useState(""),[w,h]=s.useState(""),[$,L]=s.useState(""),[I,C]=s.useState(!1),[p,d]=s.useState(null),[k,S]=s.useState({total_limit_usd:"",daily_limit_usd:""}),[A,W]=s.useState(""),[O,Q]=s.useState(!1),[ie,Z]=s.useState(null),[se,B]=s.useState(""),[T,z]=s.useState(""),[Y,pe]=s.useState(""),[ae,G]=s.useState(!1),xe=async()=>{try{const f=await ne("/api/admin/users");if(f.ok){const b=await f.json();a(b.users)}}catch(f){console.error("Error fetching users:",f)}finally{i(!1)}},Ne=async()=>{try{const f=await ne("/api/admin/usage/summary");if(f.ok){const b=await f.json(),F={};for(const oe of b.users)F[oe.user_uuid]={total_cost:oe.total_cost||0,total_requests:oe.total_requests||0,last_active:oe.last_active};n(F)}}catch(f){console.error("Error fetching usage data:",f)}};s.useEffect(()=>{xe(),Ne()},[]);const Ce=f=>!f||f===0?"$0.00":f<.01?`$${f.toFixed(4)}`:`$${f.toFixed(2)}`,je=async(f,b)=>{const F=b==="active"?"disabled":"active";x(f);try{(await ne(`/api/admin/users/${f}`,{method:"PATCH",body:JSON.stringify({status:F})})).ok&&a(r.map(ue=>ue.id===f?{...ue,status:F}:ue))}catch(oe){console.error("Error updating user status:",oe)}finally{x(null)}},_e=async(f,b)=>{if(confirm(`确定要删除用户 "${b}"?这将删除其所有数据。`)){x(f);try{(await ne(`/api/admin/users/${f}`,{method:"DELETE"})).ok&&a(r.filter(oe=>oe.id!==f))}catch(F){console.error("Error deleting user:",F)}finally{x(null)}}},he=async f=>{if(f.preventDefault(),L(""),!M||!w){L("用户名和密码不能为空");return}if(M.length<3){L("用户名至少3个字符");return}if(w.length<6){L("密码至少6个字符");return}C(!0);try{const b=await we.admin.createUser(M,w),F=await b.json();b.ok?(await xe(),v(!1),j(""),h("")):L(F.error||"创建用户失败")}catch(b){console.error("Error creating user:",b),L("网络错误,请稍后再试")}finally{C(!1)}},Se=()=>{v(!1),j(""),h(""),L("")},ke=f=>{d(f),S({total_limit_usd:f.total_limit_usd!==null&&f.total_limit_usd!==void 0?String(f.total_limit_usd):"",daily_limit_usd:f.daily_limit_usd!==null&&f.daily_limit_usd!==void 0?String(f.daily_limit_usd):""}),W("")},Ee=()=>{d(null),S({total_limit_usd:"",daily_limit_usd:""}),W("")},ve=async f=>{f.preventDefault(),W("");const b=k.total_limit_usd.trim()===""?null:parseFloat(k.total_limit_usd),F=k.daily_limit_usd.trim()===""?null:parseFloat(k.daily_limit_usd);if(b!==null&&(isNaN(b)||b<0)){W("总额度限制必须是正数或留空");return}if(F!==null&&(isNaN(F)||F<0)){W("每日额度限制必须是正数或留空");return}Q(!0);try{const oe=await we.admin.updateUserLimits(p.id,{total_limit_usd:b,daily_limit_usd:F}),ue=await oe.json();oe.ok?(a(r.map(Le=>Le.id===p.id?{...Le,total_limit_usd:b,daily_limit_usd:F}:Le)),Ee()):W(ue.error||"更新限制失败")}catch(oe){console.error("Error updating limits:",oe),W("网络错误,请稍后再试")}finally{Q(!1)}},Pe=f=>f==null?"无限制":`$${f.toFixed(2)}`,Re=f=>{Z(f),B(""),z(""),pe("")},Me=()=>{Z(null),B(""),z(""),pe("")},H=async f=>{if(f.preventDefault(),pe(""),!se){pe("请输入新密码");return}if(se.length<6){pe("密码至少需要6个字符");return}if(se!==T){pe("两次输入的密码不一致");return}G(!0);try{const b=await we.admin.resetUserPassword(ie.id,se),F=await b.json();b.ok?Me():pe(F.error||"重置密码失败")}catch(b){console.error("Error resetting password:",b),pe("网络错误,请稍后再试")}finally{G(!1)}};return l?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"正在加载用户..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"用户管理"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(J,{variant:"default",size:"sm",onClick:()=>v(!0),className:"flex items-center gap-2",children:[e.jsx(nn,{className:"w-4 h-4"}),"创建用户"]}),t&&e.jsxs(J,{variant:"outline",size:"sm",onClick:t,className:"flex items-center gap-2",children:[e.jsx(on,{className:"w-4 h-4"}),"使用量统计"]})]})]}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[700px]",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-900/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-muted-foreground",children:"用户"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-16",children:"角色"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-16",children:"状态"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-20",children:"费用"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-28",children:"额度限制"}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-muted-foreground w-24",children:"创建时间"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-20",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:r.map(f=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-900/30",children:[e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[f.role==="admin"?e.jsx(mr,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(Fs,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground text-sm truncate",children:f.username||f.email}),f.email&&f.username&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:f.email})]})]})}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap ${f.role==="admin"?"bg-blue-500/20 text-blue-400":"bg-gray-500/20 text-gray-400"}`,children:f.role==="admin"?"管理员":"用户"})}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${f.status==="active"?"bg-green-500":"bg-red-500"}`,title:f.status==="active"?"活跃":"已禁用"})}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("span",{className:"font-mono text-xs text-foreground whitespace-nowrap",children:Ce(o[f.uuid]?.total_cost)})}),e.jsx("td",{className:"px-3 py-2 text-right",children:f.role!=="admin"?e.jsx("button",{onClick:()=>ke(f),className:"text-xs text-blue-600 dark:text-blue-400 hover:underline font-mono whitespace-nowrap",title:"点击编辑额度限制",children:f.total_limit_usd!==null||f.daily_limit_usd!==null?e.jsxs("span",{className:"flex flex-col items-end text-[11px] leading-tight",children:[e.jsxs("span",{children:["总:",Pe(f.total_limit_usd)]}),e.jsxs("span",{children:["日:",Pe(f.daily_limit_usd)]})]}):e.jsxs("span",{className:"flex items-center gap-1 justify-end",children:[e.jsx(Os,{className:"w-3 h-3"}),"限额"]})}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"-"})}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground whitespace-nowrap",children:new Date(f.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("div",{className:"flex items-center justify-end gap-1",children:f.role!=="admin"&&e.jsxs(e.Fragment,{children:[f.username&&e.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Re(f),disabled:m===f.id,title:"重置密码",children:e.jsx(Ws,{className:"w-4 h-4 text-blue-500"})}),e.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>je(f.id,f.status),disabled:m===f.id,title:f.status==="active"?"禁用用户":"启用用户",children:f.status==="active"?e.jsx(ln,{className:"w-4 h-4 text-orange-500"}):e.jsx(cn,{className:"w-4 h-4 text-green-500"})}),e.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>_e(f.id,f.username||f.email),disabled:m===f.id,title:"删除用户",children:e.jsx(Ve,{className:"w-4 h-4 text-red-500"})})]})})})]},f.id))})]})}),g&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h4",{className:"text-lg font-semibold text-foreground",children:"创建用户"}),e.jsx("button",{onClick:Se,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:he,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newUsername",className:"block text-sm font-medium text-foreground mb-1",children:"用户名"}),e.jsx("input",{type:"text",id:"newUsername",value:M,onChange:f=>j(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入用户名",disabled:I})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newPassword",className:"block text-sm font-medium text-foreground mb-1",children:"密码"}),e.jsx("input",{type:"password",id:"newPassword",value:w,onChange:f=>h(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入密码",disabled:I})]}),$&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:$})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:Se,disabled:I,children:"取消"}),e.jsx(J,{type:"submit",disabled:I,children:I?"创建中...":"创建"})]})]})]})}),p&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["设置额度限制 - ",p.username||p.email]}),e.jsx("button",{onClick:Ee,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:ve,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"totalLimit",className:"block text-sm font-medium text-foreground mb-1",children:"总额度上限 (USD)"}),e.jsx("input",{type:"number",id:"totalLimit",step:"0.01",min:"0",value:k.total_limit_usd,onChange:f=>S(b=>({...b,total_limit_usd:f.target.value})),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"留空表示不限制",disabled:O}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户累计使用金额达到此限制后,将无法继续使用"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"dailyLimit",className:"block text-sm font-medium text-foreground mb-1",children:"每日额度上限 (USD)"}),e.jsx("input",{type:"number",id:"dailyLimit",step:"0.01",min:"0",value:k.daily_limit_usd,onChange:f=>S(b=>({...b,daily_limit_usd:f.target.value})),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"留空表示不限制",disabled:O}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户每日使用金额达到此限制后,需等待次日重置"})]}),o[p.uuid]&&e.jsx("div",{className:"p-3 bg-gray-100 dark:bg-gray-800 rounded-md",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["当前已使用:",e.jsx("span",{className:"font-mono text-foreground",children:Ce(o[p.uuid]?.total_cost)})]})}),A&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:A})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:Ee,disabled:O,children:"取消"}),e.jsx(J,{type:"submit",disabled:O,children:O?"保存中...":"保存"})]})]})]})}),ie&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["重置密码 - ",ie.username]}),e.jsx("button",{onClick:Me,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"resetNewPassword",className:"block text-sm font-medium text-foreground mb-1",children:"新密码"}),e.jsx("input",{type:"password",id:"resetNewPassword",value:se,onChange:f=>B(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入新密码(至少6个字符)",disabled:ae})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"resetConfirmPassword",className:"block text-sm font-medium text-foreground mb-1",children:"确认新密码"}),e.jsx("input",{type:"password",id:"resetConfirmPassword",value:T,onChange:f=>z(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请再次输入新密码",disabled:ae})]}),Y&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:Y})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:Me,disabled:ae,children:"取消"}),e.jsx(J,{type:"submit",disabled:ae,children:ae?"重置中...":"重置密码"})]})]})]})})]})}function Ni(){const[t,r]=s.useState([]),[a,o]=s.useState(!0),[n,l]=s.useState(null),[i,m]=s.useState(!1),[x,g]=s.useState(""),[v,M]=s.useState(""),[j,w]=s.useState(!1),h=async()=>{try{const C=await we.admin.getEmailDomains();if(C.ok){const p=await C.json();r(p.domains)}}catch(C){console.error("Error fetching email domains:",C)}finally{o(!1)}};s.useEffect(()=>{h()},[]);const $=async C=>{if(C.preventDefault(),M(""),!x){M("域名不能为空");return}if(!/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(x)){M("域名格式无效,例如: example.com");return}w(!0);try{const d=await we.admin.addEmailDomain(x.toLowerCase()),k=await d.json();d.ok?(await h(),m(!1),g("")):M(k.error||"添加域名失败")}catch(d){console.error("Error adding domain:",d),M("网络错误,请稍后再试")}finally{w(!1)}},L=async(C,p)=>{if(confirm(`确定要删除域名 "${p}"?删除后该域名的邮箱将无法注册。`)){l(C);try{(await we.admin.removeEmailDomain(C)).ok&&r(t.filter(k=>k.id!==C))}catch(d){console.error("Error removing domain:",d)}finally{l(null)}}},I=()=>{m(!1),g(""),M("")};return a?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"正在加载..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"邮箱域名白名单"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.length===0?"未设置白名单,所有邮箱域名均可注册":"只有白名单内的域名邮箱可以注册"})]}),e.jsxs(J,{variant:"default",size:"sm",onClick:()=>m(!0),className:"flex items-center gap-2",children:[e.jsx(st,{className:"w-4 h-4"}),"添加域名"]})]}),t.length>0?e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-900/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-muted-foreground",children:"域名"}),e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-muted-foreground",children:"添加时间"}),e.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-muted-foreground",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:t.map(C=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-900/30",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(or,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"font-medium text-foreground",children:C.domain})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground",children:new Date(C.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>L(C.id,C.domain),disabled:n===C.id,title:"删除域名",children:e.jsx(Ve,{className:"w-4 h-4 text-red-500"})})})})]},C.id))})]})}):e.jsxs("div",{className:"border border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-8 text-center",children:[e.jsx(or,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"暂无域名白名单,所有邮箱域名均可注册"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"添加域名后,只有白名单内的域名邮箱可以注册"})]}),i&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h4",{className:"text-lg font-semibold text-foreground",children:"添加域名"}),e.jsx("button",{onClick:I,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:$,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newDomain",className:"block text-sm font-medium text-foreground mb-1",children:"邮箱域名"}),e.jsx("input",{type:"text",id:"newDomain",value:x,onChange:C=>g(C.target.value.toLowerCase()),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"例如: example.com",disabled:j}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入域名后,该域名下的所有邮箱(如 user@example.com)都可以注册"})]}),v&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:v})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:I,disabled:j,children:"取消"}),e.jsx(J,{type:"submit",disabled:j,children:j?"添加中...":"添加"})]})]})]})})]})}function Si({onBack:t}){const[r,a]=s.useState("week"),[o,n]=s.useState(null),[l,i]=s.useState(!0),[m,x]=s.useState(!1),g=async()=>{try{const I=await ne(`/api/admin/usage/dashboard?period=${r}`);if(I.ok){const C=await I.json();n(C)}}catch(I){console.error("Error fetching dashboard data:",I)}finally{i(!1),x(!1)}};s.useEffect(()=>{i(!0),g()},[r]);const v=async()=>{try{x(!0),await ne("/api/admin/usage/scan",{method:"POST"}),await g()}catch(I){console.error("Error triggering scan:",I),x(!1)}},M=I=>!I||I===0?"$0.00":I<.01?`$${I.toFixed(4)}`:`$${I.toFixed(2)}`,j=I=>I?I>=1e6?`${(I/1e6).toFixed(1)}M`:I>=1e3?`${(I/1e3).toFixed(1)}K`:I.toString():"0";if(l)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-muted-foreground",children:"加载仪表板中..."})});const{totals:w,dailyTrend:h,modelDistribution:$,topUsers:L}=o||{};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[t&&e.jsxs(J,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(pr,{className:"w-4 h-4 mr-2"}),"返回"]}),e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"使用情况仪表板"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:["week","month"].map(I=>e.jsx("button",{onClick:()=>a(I),className:`px-4 py-2 text-sm font-medium transition-colors ${r===I?"bg-primary text-primary-foreground":"bg-background text-foreground hover:bg-muted"}`,children:I==="week"?"周":"月"},I))}),e.jsx(J,{variant:"outline",size:"sm",onClick:v,disabled:m,title:"扫描新的使用数据",children:e.jsx(nr,{className:`w-4 h-4 ${m?"animate-spin":""}`})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-green-100 dark:bg-green-900/30 rounded-lg",children:e.jsx(Os,{className:"w-5 h-5 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"总成本"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:M(w?.totalCost)})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/30 rounded-lg",children:e.jsx(dn,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"活跃用户"}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:[w?.activeUsers||0," / ",w?.totalUsers||0]})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-purple-100 dark:bg-purple-900/30 rounded-lg",children:e.jsx(Dt,{className:"w-5 h-5 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"总请求数"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:j(w?.totalRequests)})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-orange-100 dark:bg-orange-900/30 rounded-lg",children:e.jsx(mn,{className:"w-5 h-5 text-orange-600 dark:text-orange-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"会话数"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:j(w?.totalSessions)})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"每日成本趋势"}),h&&h.length>0?e.jsx("div",{className:"space-y-2",children:h.map(I=>{const C=Math.max(...h.map(d=>d.cost||0),.01),p=(I.cost||0)/C*100;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-muted-foreground w-20 shrink-0",children:new Date(I.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsx("div",{className:"flex-1 h-6 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-600 rounded",style:{width:`${p}%`}})}),e.jsx("span",{className:"text-sm font-mono text-foreground w-16 text-right",children:M(I.cost)})]},I.date)})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"模型成本"}),$&&$.length>0?e.jsx("div",{className:"space-y-3",children:$.map(I=>{const C=$.reduce((A,W)=>A+(W.cost||0),0)||1,p=(I.cost||0)/C*100,d=(I.normalized_model||I.model||"").toLowerCase(),S={opus:"bg-purple-500",sonnet:"bg-blue-500",haiku:"bg-green-500"}[d]||"bg-gray-500";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ge,{variant:"secondary",className:"truncate max-w-[200px]",title:I.model,children:I.model}),e.jsxs("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:[j(I.requests)," 请求"]})]}),e.jsx("span",{className:"text-sm font-mono text-foreground whitespace-nowrap ml-2",children:M(I.cost)})]}),e.jsx("div",{className:"h-2 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:`h-full ${S} rounded`,style:{width:`${p}%`}})})]},I.model)})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"用户成本"}),L&&L.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"text-left py-2 text-sm font-medium text-muted-foreground",children:"排名"}),e.jsx("th",{className:"text-left py-2 text-sm font-medium text-muted-foreground",children:"用户名"}),e.jsx("th",{className:"text-right py-2 text-sm font-medium text-muted-foreground",children:"请求数"}),e.jsx("th",{className:"text-right py-2 text-sm font-medium text-muted-foreground",children:"成本"})]})}),e.jsx("tbody",{children:L.map((I,C)=>e.jsxs("tr",{className:"border-b border-gray-100 dark:border-gray-800 last:border-0",children:[e.jsxs("td",{className:"py-2 text-sm text-muted-foreground",children:["#",C+1]}),e.jsx("td",{className:"py-2 text-sm font-medium text-foreground",children:I.username}),e.jsx("td",{className:"py-2 text-sm text-right text-muted-foreground",children:j(I.total_requests)}),e.jsx("td",{className:"py-2 text-sm text-right font-mono text-foreground",children:M(I.total_cost)})]},I.user_uuid))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]})}function Ci({onClose:t,onInstalled:r,onOpenRepoManager:a}){const[o,n]=s.useState([]),[l,i]=s.useState([]),[m,x]=s.useState(!0),[g,v]=s.useState(null),[M,j]=s.useState(""),[w,h]=s.useState("all"),[$,L]=s.useState(null);s.useEffect(()=>{I()},[]);const I=async()=>{try{x(!0),v(null);const[d,k]=await Promise.all([ne("/api/skills/available"),ne("/api/skills/repos")]);if(d.ok){const S=await d.json();n(S.skills||[])}if(k.ok){const S=await k.json();i(S.repos||[])}}catch(d){v(d.message)}finally{x(!1)}},C=async d=>{try{L(d.name);const k=await ne(`/api/skills/install/${d.name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillPath:d.path})});if(k.ok)I(),r?.();else{const S=await k.json();alert(S.error||"Failed to install skill")}}catch(k){alert(k.message)}finally{L(null)}},p=o.filter(d=>{if(M){const k=M.toLowerCase();if(!d.name.toLowerCase().includes(k)&&!d.title?.toLowerCase().includes(k)&&!d.description?.toLowerCase().includes(k))return!1}return!(w!=="all"&&d.repository!==w)});return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Skills 管理"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(J,{variant:"ghost",size:"sm",onClick:I,disabled:m,children:[e.jsx(nr,{className:`w-4 h-4 ${m?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(J,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Tt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(J,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Oe,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2",children:e.jsx("h3",{className:"text-amber-500 font-medium",children:"发现技能"})}),e.jsxs("div",{className:"px-4 pb-4 flex flex-wrap gap-3",children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative",children:[e.jsx(It,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ke,{type:"text",placeholder:"搜索技能名称或描述...",value:M,onChange:d=>j(d.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:w,onChange:d=>h(d.target.value),className:"px-3 py-2 rounded-md border border-border bg-background text-foreground text-sm min-w-[120px]",children:[e.jsx("option",{value:"all",children:"全部"}),l.map(d=>e.jsxs("option",{value:`${d.owner}/${d.repo}`,children:[d.owner,"/",d.repo]},`${d.owner}/${d.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[g&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm mb-4",children:g}),m?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):p.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:o.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的技能"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加技能仓库"}),e.jsxs(J,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Tt,{className:"w-4 h-4 mr-2"}),"管理仓库"]})]}):e.jsx("p",{children:"没有找到匹配的技能"})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:p.map(d=>e.jsx("div",{className:"border border-border rounded-lg p-4 hover:border-amber-500/50 transition-colors",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("h4",{className:"font-medium text-foreground",children:d.title||d.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["skills/",d.name]}),e.jsx(Ge,{variant:"outline",className:"text-xs ml-2",children:d.repository})]})]}),d.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:d.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-auto pt-2",children:[e.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>window.open(`https://github.com/${d.repository}`,"_blank"),children:[e.jsx(Bs,{className:"w-4 h-4 mr-1"}),"查看"]}),d.installed?e.jsx(J,{size:"sm",disabled:!0,variant:"outline",className:"ml-auto",children:"已安装"}):e.jsxs(J,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white ml-auto",onClick:()=>C(d),disabled:$===d.name,children:[e.jsx(qr,{className:"w-4 h-4 mr-1"}),$===d.name?"安装中...":"安装"]})]})]})},`${d.repository}-${d.name}`))})]})]})})}function Ei({onClose:t,onChanged:r}){const[a,o]=s.useState([]),[n,l]=s.useState(!0),[i,m]=s.useState(null),[x,g]=s.useState(""),[v,M]=s.useState("main"),[j,w]=s.useState(!1),[h,$]=s.useState(null);s.useEffect(()=>{L()},[]);const L=async()=>{try{l(!0),m(null);const p=await ne("/api/skills/repos");if(p.ok){const d=await p.json();o(d.repos||[])}else{const d=await p.json();m(d.error||"Failed to fetch repos")}}catch(p){m(p.message)}finally{l(!1)}},I=async p=>{if(p.preventDefault(),!x.trim()){m("请输入仓库 URL");return}try{w(!0),m(null);const d=await ne("/api/skills/repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:x.trim(),branch:v.trim()||"main"})});if(d.ok)g(""),M("main"),L(),r?.();else{const k=await d.json();m(k.error||"Failed to add repo")}}catch(d){m(d.message)}finally{w(!1)}},C=async(p,d)=>{if(confirm(`确定要移除仓库 "${p}/${d}" 吗?`))try{$(`${p}/${d}`);const k=await ne(`/api/skills/repos/${p}/${d}`,{method:"DELETE"});if(k.ok)L(),r?.();else{const S=await k.json();alert(S.error||"Failed to remove repo")}}catch(k){alert(k.message)}finally{$(null)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 border-b border-border",children:[e.jsx(J,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(pr,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"管理技能仓库"})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 rounded-lg p-4 space-y-4",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"添加技能仓库"}),e.jsxs("form",{onSubmit:I,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"仓库 URL"}),e.jsx(Ke,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:x,onChange:p=>g(p.target.value),disabled:j})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"分支"}),e.jsx(Ke,{type:"text",placeholder:"main",value:v,onChange:p=>M(p.target.value),disabled:j})]}),e.jsxs(J,{type:"submit",disabled:j||!x.trim(),className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),j?"添加中...":"添加仓库"]})]})]}),i&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"已添加的仓库"}),n?e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(un,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何仓库"})]}):a.map(p=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"font-medium text-foreground",children:[p.owner,"/",p.repo]})}),e.jsxs("div",{className:"flex items-center gap-3 mt-1 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(pn,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Ge,{variant:"outline",className:"text-xs",children:["识别到 ",p.skillCount," 个技能"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>window.open(p.url,"_blank"),children:e.jsx(Bs,{className:"w-4 h-4"})}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>C(p.owner,p.repo),disabled:h===`${p.owner}/${p.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},`${p.owner}/${p.repo}`))]})]})]})})}function Mi(){const[t,r]=s.useState([]),[a,o]=s.useState(!0),[n,l]=s.useState(null),[i,m]=s.useState(!1),[x,g]=s.useState(!1),[v,M]=s.useState(!1),j=s.useRef(null);s.useEffect(()=>{w()},[]);const w=async()=>{try{o(!0),l(null);const C=await ne("/api/skills");if(C.ok){const p=await C.json();r(p.skills||[])}else{const p=await C.json();l(p.error||"Failed to fetch skills")}}catch(C){l(C.message)}finally{o(!1)}},h=async C=>{if(confirm(`确定要删除技能 "${C}" 吗?`))try{const p=await ne(`/api/skills/${C}`,{method:"DELETE"});if(p.ok)w();else{const d=await p.json();alert(d.error||"Failed to delete skill")}}catch(p){alert(p.message)}},$=()=>{j.current?.click()},L=async C=>{const p=C.target.files?.[0];if(p)try{M(!0);const d=new FormData;d.append("skillZip",p);const k=await ne("/api/skills/import",{method:"POST",body:d});if(k.ok)w();else{const S=await k.json();alert(S.error||"Failed to import skill")}}catch(d){alert(d.message)}finally{M(!1),j.current&&(j.current.value="")}},I=(C,p)=>{switch(C){case"repo":return e.jsx(Ge,{variant:"outline",className:"text-xs bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300",children:p||"仓库"});case"imported":return e.jsx(Ge,{variant:"outline",className:"text-xs bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",children:"导入"});default:return e.jsx(Ge,{variant:"outline",className:"text-xs",children:"本地"})}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pr,{className:"w-5 h-5 text-amber-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"Skills 管理"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Skills 是 Claude Code 的扩展能力,可以通过 SKILLS.md 文件定义自定义指令和工作流程"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["已安装:Claude: ",e.jsx("span",{className:"font-medium text-foreground",children:t.length})," 个技能"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{ref:j,type:"file",accept:".zip",className:"hidden",onChange:L}),e.jsxs(J,{onClick:$,variant:"outline",size:"sm",disabled:v,children:[e.jsx(qr,{className:"w-4 h-4 mr-2"}),v?"导入中...":"导入已有"]}),e.jsxs(J,{onClick:()=>m(!0),className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),"发现技能"]})]})]}),n&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm",children:n}),e.jsx("div",{className:"space-y-2",children:a?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):t.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Pr,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有安装任何技能"}),e.jsx("p",{className:"text-xs mt-2",children:'点击"发现技能"从仓库安装,或"导入已有"上传本地技能'})]}):t.map(C=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"font-medium text-foreground",children:C.title||C.name}),I(C.source,C.repository)]}),C.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:C.description})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4 shrink-0",children:e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>h(C.name),className:"text-red-500 hover:text-red-600",title:"删除技能",children:e.jsx(Ve,{className:"w-4 h-4"})})})]})},C.name))}),i&&e.jsx(Ci,{onClose:()=>m(!1),onInstalled:w,onOpenRepoManager:()=>{m(!1),g(!0)}}),x&&e.jsx(Ei,{onClose:()=>g(!1),onChanged:()=>{}})]})}function Li({isOpen:t,onClose:r,projects:a=[],initialTab:o="agents"}){const n=Is(),{isDarkMode:l,toggleDarkMode:i}=Yr(),{user:m,logout:x}=$t(),g=m?.role==="admin",[v,M]=s.useState([]),[j,w]=s.useState([]),[h,$]=s.useState(""),[L,I]=s.useState(""),[C,p]=s.useState(!1),[d,k]=s.useState(!1),[S,A]=s.useState(null),[W,O]=s.useState("name"),[Q,ie]=s.useState([]),[Z,se]=s.useState(!1),[B,T]=s.useState(null),[z,Y]=s.useState({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),[pe,ae]=s.useState(!1),[G,xe]=s.useState({}),[Ne,Ce]=s.useState({}),[je,_e]=s.useState({}),[he,Se]=s.useState(o),[ke,Ee]=s.useState(""),[ve,Pe]=s.useState("permissions"),[Re,Me]=s.useState(!1),[H,f]=s.useState(""),[b,F]=s.useState(""),[oe,ue]=s.useState(""),[Le,He]=s.useState(""),[Ye,qe]=s.useState(""),[u,_]=s.useState(!1),[X,te]=s.useState(()=>localStorage.getItem("codeEditorTheme")||"dark"),[D,De]=s.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[Be,Ie]=s.useState(()=>localStorage.getItem("codeEditorShowMinimap")!=="false"),[q,me]=s.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[re,le]=s.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),ye=async()=>{try{const R=await ne("/api/mcp/config/read");if(R.ok){const fe=await R.json();if(fe.success&&fe.servers){ie(fe.servers);return}}const V=await ne("/api/mcp/cli/list");if(V.ok){const fe=await V.json();if(fe.success&&fe.servers){const it=fe.servers.map(Qe=>({id:Qe.name,name:Qe.name,type:Qe.type,scope:"user",config:{command:Qe.command||"",args:Qe.args||[],env:Qe.env||{},url:Qe.url||"",headers:Qe.headers||{},timeout:3e4},created:new Date().toISOString(),updated:new Date().toISOString()}));ie(it);return}}const de=await ne("/api/mcp/servers?scope=user");if(de.ok){const fe=await de.json();ie(fe.servers||[])}else console.error("Failed to fetch MCP servers")}catch(R){console.error("Error fetching MCP servers:",R)}},ze=async R=>{try{B&&await ge(B.id,"user");const V=await ne("/api/mcp/cli/add",{method:"POST",body:JSON.stringify({name:R.name,type:R.type,scope:R.scope,projectPath:R.projectPath,command:R.config?.command,args:R.config?.args||[],url:R.config?.url,headers:R.config?.headers||{},env:R.config?.env||{}})});if(V.ok){const de=await V.json();if(de.success)return await ye(),!0;throw new Error(de.error||"Failed to save server via Claude CLI")}else{const de=await V.json();throw new Error(de.error||"Failed to save server")}}catch(V){throw console.error("Error saving MCP server:",V),V}},ge=async(R,V="user")=>{try{const de=await ne(`/api/mcp/cli/remove/${R}?scope=${V}`,{method:"DELETE"});if(de.ok){const fe=await de.json();if(fe.success)return await ye(),!0;throw new Error(fe.error||"Failed to delete server via Claude CLI")}else{const fe=await de.json();throw new Error(fe.error||"Failed to delete server")}}catch(de){throw console.error("Error deleting MCP server:",de),de}},We=async(R,V="user")=>{try{const de=await ne(`/api/mcp/servers/${R}/test?scope=${V}`,{method:"POST"});if(de.ok)return(await de.json()).testResult;{const fe=await de.json();throw new Error(fe.error||"Failed to test server")}}catch(de){throw console.error("Error testing MCP server:",de),de}},zt=async(R,V="user")=>{try{const de=await ne(`/api/mcp/servers/${R}/tools?scope=${V}`,{method:"POST"});if(de.ok)return(await de.json()).toolsResult;{const fe=await de.json();throw new Error(fe.error||"Failed to discover tools")}}catch(de){throw console.error("Error discovering MCP tools:",de),de}};s.useEffect(()=>{t&&(Xe(),Se(o),Me(!1))},[t,o]),s.useEffect(()=>{localStorage.setItem("codeEditorTheme",X),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[X]),s.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",D.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[D]),s.useEffect(()=>{localStorage.setItem("codeEditorShowMinimap",Be.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Be]),s.useEffect(()=>{localStorage.setItem("codeEditorLineNumbers",q.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[q]),s.useEffect(()=>{localStorage.setItem("codeEditorFontSize",re),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[re]);const Xe=async()=>{try{const R=localStorage.getItem("claude-settings");if(R){const V=JSON.parse(R);M(V.allowedTools||[]),w(V.disallowedTools||[]),p(V.skipPermissions||!1),O(V.projectSortOrder||"name")}else M([]),w([]),p(!1),O("name");await ye()}catch(R){console.error("Error loading tool settings:",R),M([]),w([]),p(!1),O("name")}},_t=()=>{k(!0),A(null);try{const R={allowedTools:v,disallowedTools:j,skipPermissions:C,projectSortOrder:W,lastUpdated:new Date().toISOString()};localStorage.setItem("claude-settings",JSON.stringify(R)),A("success"),setTimeout(()=>{r()},1e3)}catch(R){console.error("Error saving tool settings:",R),A("error")}finally{k(!1)}},bt=async R=>{if(R.preventDefault(),He(""),qe(""),!H){He("请输入当前密码");return}if(!b){He("请输入新密码");return}if(b.length<6){He("新密码至少需要6个字符");return}if(b!==oe){He("两次输入的新密码不一致");return}_(!0);try{const V=await we.auth.changePassword(H,b),de=await V.json();V.ok?(qe("密码修改成功"),f(""),F(""),ue("")):He(de.error||"修改密码失败")}catch(V){console.error("Error changing password:",V),He("网络错误,请稍后再试")}finally{_(!1)}},qt=m?.username&&!m.username.includes("@"),vt=()=>{Y({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),T(null),se(!1),Ee("")},et=(R=null)=>{R?(T(R),Y({name:R.name,type:R.type,scope:R.scope,projectPath:R.projectPath||"",config:{...R.config},raw:R.raw,importMode:"form",jsonInput:""})):vt(),se(!0)},xr=async R=>{R.preventDefault(),ae(!0);try{if(z.importMode==="json"){const V=await ne("/api/mcp/cli/add-json",{method:"POST",body:JSON.stringify({name:z.name,jsonConfig:z.jsonInput,scope:z.scope,projectPath:z.projectPath})});if(V.ok){const de=await V.json();if(de.success)await ye(),vt(),A("success");else throw new Error(de.error||"Failed to add server via JSON")}else{const de=await V.json();throw new Error(de.error||"Failed to add server")}}else await ze(z),vt(),A("success")}catch(V){alert(`Error: ${V.message}`),A("error")}finally{ae(!1)}},At=async(R,V)=>{if(confirm("确定要删除此 MCP 服务器吗?"))try{await ge(R,V),A("success")}catch(de){alert(`Error: ${de.message}`),A("error")}},Ft=async(R,V)=>{try{xe({...G,[R]:{loading:!0}});const de=await We(R,V);xe({...G,[R]:de})}catch(de){xe({...G,[R]:{success:!1,message:de.message,details:[]}})}},Jt=async(R,V)=>{try{_e({...je,[R]:!0});const de=await zt(R,V);Ce({...Ne,[R]:de})}catch{Ce({...Ne,[R]:{success:!1,tools:[],resources:[],prompts:[]}})}finally{_e({...je,[R]:!1})}},at=(R,V)=>{Y(de=>({...de,config:{...de.config,[R]:V}}))};return t?e.jsx("div",{className:"modal-backdrop fixed inset-0 flex items-center justify-center z-[9999] md:p-4 bg-background/95",children:e.jsxs("div",{className:"bg-background border border-border md:rounded-lg shadow-xl w-full md:max-w-4xl h-full md:h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 md:p-6 border-b border-border flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Tt,{className:"w-5 h-5 md:w-6 md:h-6 text-blue-600"}),e.jsx("h2",{className:"text-lg md:text-xl font-semibold text-foreground",children:"设置"})]}),e.jsx(J,{variant:"ghost",size:"sm",onClick:r,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx("div",{className:"border-b border-border",children:e.jsxs("div",{className:"flex px-4 md:px-6",children:[e.jsx("button",{onClick:()=>Se("agents"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="agents"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"Agent"}),e.jsx("button",{onClick:()=>Se("appearance"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="appearance"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"外观"}),g&&e.jsx("button",{onClick:()=>Se("users"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="users"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"用户"}),e.jsx("button",{onClick:()=>Se("account"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="account"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"账户"})]})}),e.jsxs("div",{className:"p-4 md:p-6 space-y-6 md:space-y-8 pb-safe-area-inset-bottom",children:[he==="appearance"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:he==="appearance"&&e.jsxs("div",{className:"space-y-6 md:space-y-8",children:[e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"深色模式"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"切换浅色和深色主题"})]}),e.jsxs("button",{onClick:i,className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":l,"aria-label":"Toggle dark mode",children:[e.jsx("span",{className:"sr-only",children:"Toggle dark mode"}),e.jsx("span",{className:`${l?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200 flex items-center justify-center`,children:l?e.jsx(Rr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx($r,{className:"w-3.5 h-3.5 text-yellow-500"})})]})]})})}),e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"项目排序"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"侧边栏中项目的排序方式"})]}),e.jsxs("select",{value:W,onChange:R=>O(R.target.value),className:"text-sm bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2 w-32",children:[e.jsx("option",{value:"name",children:"按字母顺序"}),e.jsx("option",{value:"date",children:"按最近活动"})]})]})})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"代码编辑器"}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"编辑器主题"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"代码编辑器的默认主题"})]}),e.jsxs("button",{onClick:()=>te(X==="dark"?"light":"dark"),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":X==="dark","aria-label":"Toggle editor theme",children:[e.jsx("span",{className:"sr-only",children:"Toggle editor theme"}),e.jsx("span",{className:`${X==="dark"?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200 flex items-center justify-center`,children:X==="dark"?e.jsx(Rr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx($r,{className:"w-3.5 h-3.5 text-yellow-500"})})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"自动换行"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"在编辑器中默认启用自动换行"})]}),e.jsxs("button",{onClick:()=>De(!D),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":D,"aria-label":"Toggle word wrap",children:[e.jsx("span",{className:"sr-only",children:"Toggle word wrap"}),e.jsx("span",{className:`${D?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200`})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"显示小地图"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"在差异视图中显示小地图以便于导航"})]}),e.jsxs("button",{onClick:()=>Ie(!Be),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":Be,"aria-label":"Toggle minimap",children:[e.jsx("span",{className:"sr-only",children:"Toggle minimap"}),e.jsx("span",{className:`${Be?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200`})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"显示行号"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"在编辑器中显示行号"})]}),e.jsxs("button",{onClick:()=>me(!q),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":q,"aria-label":"Toggle line numbers",children:[e.jsx("span",{className:"sr-only",children:"Toggle line numbers"}),e.jsx("span",{className:`${q?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200`})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"字体大小"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"编辑器字体大小(像素)"})]}),e.jsxs("select",{value:re,onChange:R=>le(R.target.value),className:"text-sm bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2 w-24",children:[e.jsx("option",{value:"10",children:"10px"}),e.jsx("option",{value:"11",children:"11px"}),e.jsx("option",{value:"12",children:"12px"}),e.jsx("option",{value:"13",children:"13px"}),e.jsx("option",{value:"14",children:"14px"}),e.jsx("option",{value:"15",children:"15px"}),e.jsx("option",{value:"16",children:"16px"}),e.jsx("option",{value:"18",children:"18px"}),e.jsx("option",{value:"20",children:"20px"})]})]})})]})]})}),he==="agents"&&e.jsx("div",{className:"flex flex-col h-full min-h-[400px] md:min-h-[500px]",children:e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:e.jsxs("div",{className:"flex px-2 md:px-4 overflow-x-auto",children:[e.jsx("button",{onClick:()=>Pe("permissions"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="permissions"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"权限"}),e.jsx("button",{onClick:()=>Pe("mcp"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="mcp"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"MCP 服务器"}),e.jsx("button",{onClick:()=>Pe("skills"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="skills"?"border-amber-600 text-amber-600 dark:text-amber-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"技能"}),e.jsx("button",{onClick:()=>Pe("models"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="models"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"模型"})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 md:p-4",children:[ve==="permissions"&&e.jsx(hi,{agent:"claude",skipPermissions:C,setSkipPermissions:p,allowedTools:v,setAllowedTools:M,disallowedTools:j,setDisallowedTools:w,newAllowedTool:h,setNewAllowedTool:$,newDisallowedTool:L,setNewDisallowedTool:I}),ve==="mcp"&&e.jsx(yi,{agent:"claude",servers:Q,onAdd:()=>et(),onEdit:R=>et(R),onDelete:(R,V)=>At(R,V),onTest:(R,V)=>Ft(R,V),onDiscoverTools:(R,V)=>Jt(R,V),testResults:G,serverTools:Ne,toolsLoading:je}),ve==="skills"&&e.jsx(Mi,{}),ve==="models"&&e.jsx(wi,{})]})]})}),he==="users"&&g&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:Re?e.jsx(Si,{onBack:()=>Me(!1)}):e.jsxs(e.Fragment,{children:[e.jsx(ki,{onNavigateToUsage:()=>Me(!0)}),e.jsx(Ni,{})]})}),he==="account"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"账户"}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/10 rounded-full flex items-center justify-center",children:e.jsx("span",{className:"text-lg font-semibold text-primary",children:m?.username?.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:m?.username}),e.jsx("div",{className:"text-sm text-muted-foreground",children:m?.role==="admin"?"管理员":"用户"})]})]})}),qt&&e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ws,{className:"w-5 h-5 text-blue-600"}),e.jsx("div",{className:"font-medium text-foreground",children:"修改密码"})]}),e.jsxs("form",{onSubmit:bt,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"currentPassword",className:"block text-sm font-medium text-foreground mb-1",children:"当前密码"}),e.jsx("input",{type:"password",id:"currentPassword",value:H,onChange:R=>f(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入当前密码",disabled:u})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newPassword",className:"block text-sm font-medium text-foreground mb-1",children:"新密码"}),e.jsx("input",{type:"password",id:"newPassword",value:b,onChange:R=>F(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入新密码(至少6个字符)",disabled:u})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmNewPassword",className:"block text-sm font-medium text-foreground mb-1",children:"确认新密码"}),e.jsx("input",{type:"password",id:"confirmNewPassword",value:oe,onChange:R=>ue(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请再次输入新密码",disabled:u})]}),Le&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:Le})}),Ye&&e.jsx("div",{className:"p-3 bg-green-100 dark:bg-green-900/20 border border-green-300 dark:border-green-800 rounded-md",children:e.jsx("p",{className:"text-sm text-green-700 dark:text-green-400",children:Ye})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(J,{type:"submit",disabled:u,className:"bg-blue-600 hover:bg-blue-700",children:u?"修改中...":"修改密码"})})]})]}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"退出登录"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"结束当前会话"})]}),e.jsxs(J,{variant:"outline",className:"gap-2 text-red-600 dark:text-red-400 border-red-200 dark:border-red-800 hover:bg-red-50 dark:hover:bg-red-900/20",onClick:()=>{confirm("确定要退出登录吗?")&&(r(),n("/"),x())},children:[e.jsx(xn,{className:"w-4 h-4"}),"退出"]})]})})]})}),Z&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[110] p-4",children:e.jsxs("div",{className:"bg-background border border-border rounded-lg w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[e.jsx("h3",{className:"text-lg font-medium text-foreground",children:B?"编辑 MCP 服务器":"添加 MCP 服务器"}),e.jsx(J,{variant:"ghost",size:"sm",onClick:vt,children:e.jsx(Oe,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:xr,className:"p-4 space-y-4",children:[!B&&e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,importMode:"form"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${z.importMode==="form"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:"表单输入"}),e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,importMode:"json"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${z.importMode==="json"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:"JSON 导入"})]}),z.importMode==="form"&&B&&e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-3",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"作用域"}),e.jsxs("div",{className:"flex items-center gap-2",children:[z.scope==="user"?e.jsx(Tr,{className:"w-4 h-4"}):e.jsx(kt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:z.scope==="user"?"用户(全局)":"项目(本地)"}),z.scope==="local"&&z.projectPath&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",z.projectPath]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"编辑现有服务器时无法更改作用域"})]}),z.importMode==="form"&&!B&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"作用域 *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,scope:"user",projectPath:""})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${z.scope==="user"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(Tr,{className:"w-4 h-4"}),e.jsx("span",{children:"用户(全局)"})]})}),e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,scope:"local"})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${z.scope==="local"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(kt,{className:"w-4 h-4"}),e.jsx("span",{children:"项目(本地)"})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:z.scope==="user"?"用户作用域:在您机器上的所有项目中可用":"本地作用域:仅在选定的项目中可用"})]}),z.scope==="local"&&!B&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"项目 *"}),e.jsxs("select",{value:z.projectPath,onChange:R=>Y(V=>({...V,projectPath:R.target.value})),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500",required:z.scope==="local",children:[e.jsx("option",{value:"",children:"选择项目..."}),a.map(R=>e.jsx("option",{value:R.path||R.fullPath,children:R.displayName||R.name},R.name))]}),z.projectPath&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Path: ",z.projectPath]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:z.importMode==="json"?"md:col-span-2":"",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称 *"}),e.jsx(Ke,{value:z.name,onChange:R=>{Y(V=>({...V,name:R.target.value}))},placeholder:"my-server",required:!0})]}),z.importMode==="form"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"传输类型 *"}),e.jsxs("select",{value:z.type,onChange:R=>{Y(V=>({...V,type:R.target.value}))},className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:"stdio",children:"stdio"}),e.jsx("option",{value:"sse",children:"SSE"}),e.jsx("option",{value:"http",children:"HTTP"})]})]})]}),B&&z.raw&&z.importMode==="form"&&e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsxs("h4",{className:"text-sm font-medium text-foreground mb-2",children:["配置详情 (from ",B.scope==="global"?"~/.claude.json":"project config",")"]}),e.jsx("pre",{className:"text-xs bg-gray-100 dark:bg-gray-800 p-3 rounded overflow-x-auto",children:JSON.stringify(z.raw,null,2)})]}),z.importMode==="json"&&e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"JSON 配置 *"}),e.jsx("textarea",{value:z.jsonInput,onChange:R=>{Y(V=>({...V,jsonInput:R.target.value}));try{if(R.target.value.trim()){const V=JSON.parse(R.target.value);V.type?V.type==="stdio"&&!V.command?Ee("stdio 类型需要 command 字段"):(V.type==="http"||V.type==="sse")&&!V.url?Ee(`${V.type} 类型需要 url 字段`):Ee(""):Ee("缺少必填字段:type")}}catch{R.target.value.trim()?Ee("无效的 JSON 格式"):Ee("")}},className:`w-full px-3 py-2 border ${ke?"border-red-500":"border-gray-300 dark:border-gray-600"} bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 font-mono text-sm`,rows:"8",placeholder:`{
135
+ `;if(typeof document<"u"){const t=document.createElement("style");t.type="text/css",t.innerText=Xo,document.head.appendChild(t)}function ei({selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:o=!1,onProcessComplete:n,minimal:l=!1,autoConnect:i=!1}){const m=s.useRef(null),x=s.useRef(null),g=s.useRef(null),v=s.useRef(null),[M,j]=s.useState(!1),[w,h]=s.useState(!1),[$,L]=s.useState(!1),[I,C]=s.useState(null),[p,d]=s.useState(!1),k=s.useRef(t),S=s.useRef(r),A=s.useRef(a),W=s.useRef(o),O=s.useRef(n);s.useEffect(()=>{k.current=t,S.current=r,A.current=a,W.current=o,O.current=n});const Q=s.useCallback(async()=>{if(!(p||M))try{let pe;{const ae=localStorage.getItem("auth-token");if(!ae){console.error("No authentication token found for Shell WebSocket connection");return}pe=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/shell?token=${encodeURIComponent(ae)}`}v.current=new WebSocket(pe),v.current.onopen=()=>{j(!0),d(!1),setTimeout(()=>{g.current&&x.current&&(g.current.fit(),v.current.send(JSON.stringify({type:"init",projectPath:k.current.fullPath||k.current.path,sessionId:W.current?null:S.current?.id,hasSession:W.current?!1:!!S.current,provider:W.current?"plain-shell":S.current?.__provider||"claude",cols:x.current.cols,rows:x.current.rows,initialCommand:A.current,isPlainShell:W.current})))},100)},v.current.onmessage=ae=>{try{const G=JSON.parse(ae.data);if(G.type==="output"){let xe=G.data;if(W.current&&O.current){const Ne=xe.replace(/\x1b\[[0-9;]*m/g,"");if(Ne.includes("Process exited with code 0"))O.current(0);else if(Ne.match(/Process exited with code (\d+)/)){const Ce=parseInt(Ne.match(/Process exited with code (\d+)/)[1]);Ce!==0&&O.current(Ce)}}x.current&&x.current.write(xe)}else G.type==="url_open"&&window.open(G.url,"_blank")}catch(G){console.error("[Shell] Error handling WebSocket message:",G,ae.data)}},v.current.onclose=ae=>{j(!1),d(!1),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H"))},v.current.onerror=ae=>{j(!1),d(!1)}}catch{j(!1),d(!1)}},[p,M]),ie=s.useCallback(()=>{!w||M||p||(d(!0),Q())},[w,M,p,Q]),Z=s.useCallback(()=>{v.current&&(v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"terminate"})),v.current.close(),v.current=null),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H")),j(!1),d(!1)},[]),se=s.useMemo(()=>r?r.__provider==="cursor"?r.name||"Untitled Session":r.summary||"New Session":null,[r]),B=s.useMemo(()=>se?se.slice(0,30):null,[se]),T=s.useMemo(()=>se?se.slice(0,50):null,[se]),z=()=>{L(!0),v.current&&(v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"terminate"})),v.current.close(),v.current=null),x.current&&(x.current.dispose(),x.current=null,g.current=null),j(!1),h(!1),setTimeout(()=>{L(!1)},200)};return s.useEffect(()=>{const Y=r?.id||null;I!==null&&I!==Y&&w&&Z(),C(Y)},[r?.id,w,Z]),s.useEffect(()=>{if(!m.current||!t||$||x.current)return;x.current=new ea.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Menlo, Monaco, "Courier New", monospace',allowProposedApi:!0,allowTransparency:!1,convertEol:!0,scrollback:1e4,tabStopWidth:4,windowsMode:!1,macOptionIsMeta:!0,macOptionClickForcesSelection:!1,theme:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#ffffff",cursorAccent:"#1e1e1e",selection:"#264f78",selectionForeground:"#ffffff",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff",extendedAnsi:["#000000","#800000","#008000","#808000","#000080","#800080","#008080","#c0c0c0","#808080","#ff0000","#00ff00","#ffff00","#0000ff","#ff00ff","#00ffff","#ffffff"]}}),g.current=new ta.FitAddon;const Y=new ra.WebglAddon,pe=new sa.WebLinksAddon;x.current.loadAddon(g.current),x.current.loadAddon(pe);try{x.current.loadAddon(Y)}catch{console.warn("[Shell] WebGL renderer unavailable, using Canvas fallback")}x.current.open(m.current),x.current.attachCustomKeyEventHandler(G=>(G.ctrlKey||G.metaKey)&&G.key==="c"&&x.current.hasSelection()?(document.execCommand("copy"),!1):(G.ctrlKey||G.metaKey)&&G.key==="v"?(navigator.clipboard.readText().then(xe=>{v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"input",data:xe}))}).catch(()=>{}),!1):!0),setTimeout(()=>{g.current&&(g.current.fit(),x.current&&v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows})))},100),h(!0),x.current.onData(G=>{v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"input",data:G}))});const ae=new ResizeObserver(()=>{g.current&&x.current&&setTimeout(()=>{g.current.fit(),v.current&&v.current.readyState===WebSocket.OPEN&&v.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows}))},50)});return m.current&&ae.observe(m.current),()=>{ae.disconnect(),v.current&&(v.current.readyState===WebSocket.OPEN||v.current.readyState===WebSocket.CONNECTING)&&v.current.close(),v.current=null,x.current&&(x.current.dispose(),x.current=null)}},[t?.path||t?.fullPath,$]),s.useEffect(()=>{!i||!w||p||M||ie()},[i,w,p,M,ie]),t?l?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:m,className:"h-full w-full focus:outline-none",style:{outline:"none"}})}):e.jsxs("div",{className:"h-full flex flex-col bg-gray-900 w-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${M?"bg-green-500":"bg-red-500"}`}),r&&e.jsxs("span",{className:"text-xs text-blue-300",children:["(",B,"...)"]}),!r&&e.jsx("span",{className:"text-xs text-gray-400",children:"(新会话)"}),!w&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),$&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[M&&e.jsxs("button",{onClick:Z,className:"px-3 py-1 text-xs bg-red-600 text-white rounded hover:bg-red-700 flex items-center space-x-1",title:"断开 Shell 连接",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),e.jsx("span",{children:"断开连接"})]}),e.jsxs("button",{onClick:z,disabled:$||M,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Shell(先断开连接)",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),e.jsx("span",{children:"重启"})]})]})]})}),e.jsxs("div",{className:"flex-1 p-2 overflow-hidden relative",children:[e.jsx("div",{ref:m,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!w&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90",children:e.jsx("div",{className:"text-white",children:"加载终端中..."})}),w&&!M&&!p&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("button",{onClick:ie,className:"px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center justify-center space-x-2 text-base font-medium w-full sm:w-auto",title:"Connect to shell",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{children:"在 Shell 中继续"})]}),e.jsx("p",{className:"text-gray-400 text-sm mt-3 px-2",children:o?`Run ${a||"command"} in ${t.displayName}`:r?`Resume session: ${T}...`:"Start a new Claude session"})]})}),p&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("div",{className:"flex items-center justify-center space-x-3 text-yellow-400",children:[e.jsx("div",{className:"w-6 h-6 animate-spin rounded-full border-2 border-yellow-400 border-t-transparent"}),e.jsx("span",{className:"text-base font-medium",children:"连接到 Shell..."})]}),e.jsx("p",{className:"text-gray-400 text-sm mt-3 px-2",children:o?`Running ${a||"command"} in ${t.displayName}`:`Starting Claude CLI in ${t.displayName}`})]})})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"选择项目"}),e.jsx("p",{children:"选择一个项目以在该目录中打开交互式 Shell"})]})})}function ti({project:t,session:r=null,command:a=null,isPlainShell:o=null,autoConnect:n=!0,onComplete:l=null,onClose:i=null,title:m=null,className:x="",showHeader:g=!0,compact:v=!1,minimal:M=!1}){const[j,w]=s.useState(!1),h=o!==null?o:a!==null,$=s.useCallback(L=>{w(!0),l&&l(L)},[l]);return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${x}`,children:[!M&&g&&m&&e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-200",children:m}),j&&e.jsx("span",{className:"text-xs text-green-400",children:"(已完成)"})]}),i&&e.jsx("button",{onClick:i,className:"text-gray-400 hover:text-white",title:"关闭",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsx("div",{className:"flex-1 w-full min-h-0",children:e.jsx(ei,{selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:h,onProcessComplete:$,minimal:M,autoConnect:M?!0:n})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${x}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Shell 需要一个项目"})]})})}function ri({selectedProject:t,minimal:r=!1,autoConnect:a=!1}){const o=s.useRef(null),n=s.useRef(null),l=s.useRef(null),i=s.useRef(null),[m,x]=s.useState(!1),[g,v]=s.useState(!1),[M,j]=s.useState(!1),[w,h]=s.useState(!1),$=s.useRef(t);s.useEffect(()=>{$.current=t});const L=s.useCallback(async()=>{if(!(w||m))try{let k;{const S=localStorage.getItem("auth-token");if(!S){console.error("No authentication token found for Codex WebSocket connection");return}k=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/codex?token=${encodeURIComponent(S)}`}i.current=new WebSocket(k),i.current.onopen=()=>{x(!0),h(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:$.current.fullPath||$.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=S=>{try{const A=JSON.parse(S.data);A.type==="output"?n.current&&n.current.write(A.data):A.type==="url_open"&&window.open(A.url,"_blank")}catch(A){console.error("[CodexShell] Error handling WebSocket message:",A)}},i.current.onclose=()=>{x(!1),h(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{x(!1),h(!1)}}catch{x(!1),h(!1)}},[w,m]),I=s.useCallback(()=>{!g||m||w||(h(!0),L())},[g,m,w,L]),C=s.useCallback(()=>{i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H")),x(!1),h(!1)},[]),p=()=>{j(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),x(!1),v(!1),setTimeout(()=>j(!1),200)};return s.useEffect(()=>{if(!o.current||!t||M||n.current)return;n.current=new ea.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Menlo, Monaco, "Courier New", monospace',allowProposedApi:!0,allowTransparency:!1,convertEol:!0,scrollback:1e4,tabStopWidth:4,windowsMode:!1,macOptionIsMeta:!0,macOptionClickForcesSelection:!1,theme:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#ffffff",cursorAccent:"#1e1e1e",selection:"#264f78",selectionForeground:"#ffffff",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff"}}),l.current=new ta.FitAddon;const d=new ra.WebglAddon,k=new sa.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(k);try{n.current.loadAddon(d)}catch{console.warn("[CodexShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(A=>(A.ctrlKey||A.metaKey)&&A.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(A.ctrlKey||A.metaKey)&&A.key==="v"?(navigator.clipboard.readText().then(W=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:W}))}).catch(()=>{}),!1):!0),setTimeout(()=>{l.current&&(l.current.fit(),n.current&&i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"resize",cols:n.current.cols,rows:n.current.rows})))},100),v(!0),n.current.onData(A=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:A}))});const S=new ResizeObserver(()=>{l.current&&n.current&&setTimeout(()=>{l.current.fit(),i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"resize",cols:n.current.cols,rows:n.current.rows}))},50)});return o.current&&S.observe(o.current),()=>{S.disconnect(),i.current&&(i.current.readyState===WebSocket.OPEN||i.current.readyState===WebSocket.CONNECTING)&&i.current.close(),i.current=null,n.current&&(n.current.dispose(),n.current=null)}},[t?.path||t?.fullPath,M]),s.useEffect(()=>{!a||!g||w||m||I()},[a,g,w,m,I]),t?r?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}})}):e.jsxs("div",{className:"h-full flex flex-col bg-gray-900 w-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${m?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-300 font-medium",children:"Codex"}),!g&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),M&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[m&&e.jsxs("button",{onClick:C,className:"px-3 py-1 text-xs bg-red-600 text-white rounded hover:bg-red-700 flex items-center space-x-1",title:"断开 Codex 连接",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),e.jsx("span",{children:"断开连接"})]}),e.jsxs("button",{onClick:p,disabled:M||m,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Codex(先断开连接)",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),e.jsx("span",{children:"重启"})]})]})]})}),e.jsxs("div",{className:"flex-1 p-2 overflow-hidden relative",children:[e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!g&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90",children:e.jsx("div",{className:"text-white",children:"加载终端中..."})}),g&&!m&&!w&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("button",{onClick:I,className:"px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center justify-center space-x-2 text-base font-medium w-full sm:w-auto",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{children:"启动 Codex"})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["在 ",t.displayName," 中启动 Codex CLI"]})]})}),w&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("div",{className:"flex items-center justify-center space-x-3 text-yellow-400",children:[e.jsx("div",{className:"w-6 h-6 animate-spin rounded-full border-2 border-yellow-400 border-t-transparent"}),e.jsx("span",{className:"text-base font-medium",children:"连接到 Codex..."})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["正在 ",t.displayName," 中启动 Codex CLI"]})]})})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"选择项目"}),e.jsx("p",{children:"选择一个项目以在该目录中打开 Codex"})]})})}function si({project:t,autoConnect:r=!0,onClose:a=null,className:o="",showHeader:n=!0,minimal:l=!1}){return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${o}`,children:[!l&&n&&a&&e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-200",children:"Codex"}),e.jsx("button",{onClick:a,className:"text-gray-400 hover:text-white",title:"关闭",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsx("div",{className:"flex-1 w-full min-h-0",children:e.jsx(ri,{selectedProject:t,minimal:l,autoConnect:l?!0:r})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${o}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Codex 需要一个项目"})]})})}class ai extends rt.Component{constructor(r){super(r),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0}}componentDidCatch(r,a){console.error("ErrorBoundary caught an error:",r,a),this.setState({error:r,errorInfo:a})}render(){return this.state.hasError?e.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-6 max-w-md",children:[e.jsxs("div",{className:"flex items-center mb-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-red-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})}),e.jsx("h3",{className:"ml-3 text-sm font-medium text-red-800",children:"出现问题"})]}),e.jsxs("div",{className:"text-sm text-red-700",children:[e.jsx("p",{className:"mb-2",children:"加载聊天界面时出现错误。"}),this.props.showDetails&&this.state.error&&e.jsxs("details",{className:"mt-4",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-mono",children:"错误详情"}),e.jsxs("pre",{className:"mt-2 text-xs bg-red-100 p-2 rounded overflow-auto max-h-40",children:[this.state.error.toString(),this.state.errorInfo&&this.state.errorInfo.componentStack]})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:()=>{this.setState({hasError:!1,error:null,errorInfo:null}),this.props.onRetry&&this.props.onRetry()},className:"bg-red-600 text-white px-4 py-2 rounded text-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500",children:"重试"})})]})}):this.props.children}}const sr=({children:t,content:r,position:a="top",className:o="",delay:n=500})=>{const[l,i]=s.useState(!1),[m,x]=s.useState(null),g=()=>{const w=setTimeout(()=>{i(!0)},n);x(w)},v=()=>{m&&(clearTimeout(m),x(null)),i(!1)},M=()=>{switch(a){case"top":return"bottom-full left-1/2 transform -translate-x-1/2 mb-2";case"bottom":return"top-full left-1/2 transform -translate-x-1/2 mt-2";case"left":return"right-full top-1/2 transform -translate-y-1/2 mr-2";case"right":return"left-full top-1/2 transform -translate-y-1/2 ml-2";default:return"bottom-full left-1/2 transform -translate-x-1/2 mb-2"}},j=()=>{switch(a){case"top":return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100";case"bottom":return"bottom-full left-1/2 transform -translate-x-1/2 border-b-gray-900 dark:border-b-gray-100";case"left":return"left-full top-1/2 transform -translate-y-1/2 border-l-gray-900 dark:border-l-gray-100";case"right":return"right-full top-1/2 transform -translate-y-1/2 border-r-gray-900 dark:border-r-gray-100";default:return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100"}};return r?e.jsxs("div",{className:"relative inline-block",onMouseEnter:g,onMouseLeave:v,children:[t,l&&e.jsxs("div",{className:Fe("absolute z-50 px-2 py-1 text-xs font-medium text-white bg-gray-900 dark:bg-gray-100 dark:text-gray-900 rounded shadow-lg whitespace-nowrap pointer-events-none","animate-in fade-in-0 zoom-in-95 duration-200",M(),o),children:[r,e.jsx("div",{className:Fe("absolute w-0 h-0 border-4 border-transparent",j())})]})]}):t};function ni({selectedProject:t,selectedSession:r,activeTab:a,setActiveTab:o,ws:n,sendMessage:l,messages:i,isMobile:m,isPWA:x,onMenuClick:g,isLoading:v,onInputFocusChange:M,onSessionActive:j,onSessionInactive:w,onSessionProcessing:h,onSessionNotProcessing:$,processingSessions:L,onReplaceTemporarySession:I,onNavigateToSession:C,onShowSettings:p,autoExpandTools:d,showRawParameters:k,showThinking:S,autoScrollToBottom:A,sendByCtrlEnter:W,externalMessageUpdate:O,limitStatus:Q,onLimitBlocked:ie,checkLimitStatus:Z}){const[se,B]=s.useState(null),[T,z]=s.useState(600),[Y,pe]=s.useState(!1),[ae,G]=s.useState(!1),xe=s.useRef(null);s.useEffect(()=>{a==="shell"&&Z&&Z()},[a,Z]);const Ne=(he,Se=null)=>{const ke={name:he.split("/").pop(),path:he,projectName:t?.name,diffInfo:Se};B(ke)},Ce=()=>{B(null),G(!1)},je=()=>{G(!ae)},_e=he=>{m||(pe(!0),he.preventDefault())};return s.useEffect(()=>{const he=ke=>{if(!Y)return;const Ee=xe.current?.parentElement;if(!Ee)return;const ve=Ee.getBoundingClientRect(),Pe=ve.right-ke.clientX,Re=300,Me=ve.width*.8;Pe>=Re&&Pe<=Me&&z(Pe)},Se=()=>{pe(!1)};return Y&&(document.addEventListener("mousemove",he),document.addEventListener("mouseup",Se),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",he),document.removeEventListener("mouseup",Se),document.body.style.cursor="",document.body.style.userSelect=""}},[Y]),v?e.jsxs("div",{className:"h-full flex flex-col",children:[m&&e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsx("button",{onClick:g,className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 pwa-menu-button",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-4",children:e.jsx("div",{className:"w-full h-full rounded-full border-4 border-gray-200 border-t-blue-500",style:{animation:"spin 1s linear infinite",WebkitAnimation:"spin 1s linear infinite",MozAnimation:"spin 1s linear infinite"}})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"正在加载 AgentHub"}),e.jsx("p",{children:"正在设置您的工作区..."})]})})]}):t?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between relative",children:[e.jsxs("div",{className:"flex items-center space-x-2 min-w-0 flex-1",children:[m&&e.jsx("button",{onClick:g,onTouchStart:he=>{he.preventDefault(),g()},className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 touch-manipulation active:scale-95 pwa-menu-button flex-shrink-0",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),e.jsxs("div",{className:"min-w-0 flex items-center gap-2 flex-1 overflow-x-auto scrollbar-hide",children:[a==="chat"&&r&&e.jsx("div",{className:"w-5 h-5 flex-shrink-0 flex items-center justify-center",children:e.jsx(ot,{className:"w-4 h-4"})}),e.jsx("div",{className:"min-w-0 flex-1",children:a==="chat"&&r?e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white whitespace-nowrap overflow-x-auto scrollbar-hide",children:r.summary||"新会话"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]}):a==="chat"&&!r?e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white",children:"新会话"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]}):e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white",children:a==="files"?"项目文件":"项目"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]})})]})]}),e.jsx("div",{className:"flex-shrink-0 hidden sm:block",children:e.jsxs("div",{className:"relative flex bg-gray-100 dark:bg-gray-800 rounded-lg p-1",children:[e.jsx(sr,{content:"Chat",position:"bottom",children:e.jsx("button",{onClick:()=>o("chat"),className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md ${a==="chat"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Chat"})]})})}),e.jsx(sr,{content:Q&&!Q.allowed?"使用已达上限":"Shell",position:"bottom",children:e.jsx("button",{onClick:()=>{if(Q&&!Q.allowed){ie?.(Q.reason);return}o("shell")},className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md transition-all duration-200 ${Q&&!Q.allowed?"opacity-50 cursor-not-allowed text-gray-400 dark:text-gray-500":a==="shell"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Shell"})]})})}),e.jsx(sr,{content:"Files",position:"bottom",children:e.jsx("button",{onClick:()=>o("files"),className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md transition-all duration-200 ${a==="files"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-5l-2-2H5a2 2 0 00-2 2z"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Files"})]})})}),e.jsx(sr,{content:"Codex",position:"bottom",children:e.jsx("button",{onClick:()=>o("codex"),className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md transition-all duration-200 ${a==="codex"?"bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[e.jsx("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Codex"})]})})})]})})]})}),e.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[e.jsxs("div",{className:`flex-1 flex flex-col min-h-0 overflow-hidden ${se?"mr-0":""} ${ae?"hidden":""}`,children:[e.jsx("div",{className:`h-full ${a==="chat"?"block":"hidden"}`,children:e.jsx(ai,{showDetails:!0,children:e.jsx(Yo,{selectedProject:t,selectedSession:r,ws:n,sendMessage:l,messages:i,onFileOpen:Ne,onInputFocusChange:M,onSessionActive:j,onSessionInactive:w,onSessionProcessing:h,onSessionNotProcessing:$,processingSessions:L,onReplaceTemporarySession:I,onNavigateToSession:C,onShowSettings:p,autoExpandTools:d,showRawParameters:k,showThinking:S,autoScrollToBottom:A,sendByCtrlEnter:W,externalMessageUpdate:O,limitStatus:Q,onLimitExceeded:ie,checkLimitStatus:Z})})}),a==="files"&&e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx(Zo,{selectedProject:t})}),a==="shell"&&e.jsxs("div",{className:"h-full w-full overflow-hidden relative",children:[e.jsx(ti,{project:t,session:r,showHeader:!1}),Q&&!Q.allowed&&e.jsx("div",{className:"absolute inset-0 bg-black/60 z-50 flex items-center justify-center",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-xl p-6 mx-4 max-w-md text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-4 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-6 h-6 text-red-600 dark:text-red-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:Q.reason==="total_limit_exceeded"?"使用上限已达到":"今日使用上限已达到"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:Q.reason==="total_limit_exceeded"?"您已达到使用上限,请联系管理员提升额度。":"您已达到今日使用上限,请明日再来或联系管理员提升额度。"}),e.jsx("button",{onClick:()=>o("chat"),className:"px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors",children:"返回 Chat"})]})})]}),a==="codex"&&e.jsx("div",{className:"h-full w-full overflow-hidden relative",children:e.jsx(si,{project:t,showHeader:!1})}),e.jsx("div",{className:`h-full overflow-hidden ${a==="preview"?"block":"hidden"}`})]}),se&&!m&&e.jsxs(e.Fragment,{children:[!ae&&e.jsx("div",{ref:xe,onMouseDown:_e,className:"flex-shrink-0 w-1 bg-gray-200 dark:bg-gray-700 hover:bg-blue-500 dark:hover:bg-blue-600 cursor-col-resize transition-colors relative group",title:"Drag to resize",children:e.jsx("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-1 bg-blue-500 dark:bg-blue-600 opacity-0 group-hover:opacity-100 transition-opacity"})}),e.jsx("div",{className:`flex-shrink-0 border-l border-gray-200 dark:border-gray-700 h-full overflow-hidden ${ae?"flex-1":""}`,style:ae?{}:{width:`${T}px`},children:e.jsx(Ur,{file:se,onClose:Ce,projectPath:t?.path,isSidebar:!0,isExpanded:ae,onToggleExpand:je})})]})]}),se&&m&&e.jsx(Ur,{file:se,onClose:Ce,projectPath:t?.path,isSidebar:!1})]}):e.jsxs("div",{className:"h-full flex flex-col",children:[m&&e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsx("button",{onClick:g,className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 pwa-menu-button",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400 max-w-md mx-auto px-6",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-6 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-5l-2-2H5a2 2 0 00-2 2z"})})}),e.jsx("h2",{className:"text-2xl font-semibold mb-3 text-gray-900 dark:text-white",children:"选择您的项目"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-300 mb-6 leading-relaxed",children:"从侧边栏选择一个项目,开始与 Claude 进行编码。每个项目包含您的聊天会话和文件历史。"}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 rounded-lg p-4 border border-blue-200 dark:border-blue-800",children:e.jsxs("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:["💡 ",e.jsx("strong",{children:"提示:"})," ",m?"点击上方菜单按钮访问项目":"点击侧边栏中的文件夹图标创建新项目"]})})]})})]})}const oi=rt.memo(ni);function ii({activeTab:t,setActiveTab:r,isInputFocused:a}){const o=[{id:"chat",icon:Dt,onClick:()=>r("chat")},{id:"shell",icon:dr,onClick:()=>r("shell")},{id:"files",icon:tt,onClick:()=>r("files")}];return e.jsx("div",{className:`fixed bottom-0 left-0 right-0 bg-background border-t border-border z-50 ios-bottom-safe transform transition-transform duration-300 ease-in-out shadow-lg ${a?"translate-y-full":"translate-y-0"}`,children:e.jsx("div",{className:"flex items-center justify-around py-1",children:o.map(n=>{const l=n.icon,i=t===n.id;return e.jsxs("button",{onClick:n.onClick,onTouchStart:m=>{m.preventDefault(),n.onClick()},className:`flex items-center justify-center p-2 rounded-lg min-h-[40px] min-w-[40px] relative touch-manipulation ${i?"text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white"}`,"aria-label":n.id,children:[e.jsx(l,{className:"w-5 h-5"}),i&&e.jsx("div",{className:"absolute top-0 left-1/2 transform -translate-x-1/2 w-6 h-0.5 bg-blue-600 dark:bg-blue-400 rounded-full"})]},n.id)})})})}const aa=s.createContext(),Yr=()=>{const t=s.useContext(aa);if(!t)throw new Error("useTheme must be used within a ThemeProvider");return t},li=({children:t})=>{const[r,a]=s.useState(()=>{const l=localStorage.getItem("theme");return l?l==="dark":window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches:!1});s.useEffect(()=>{if(r){document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark");const l=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');l&&l.setAttribute("content","black-translucent");const i=document.querySelector('meta[name="theme-color"]');i&&i.setAttribute("content","#0c1117")}else{document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light");const l=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');l&&l.setAttribute("content","default");const i=document.querySelector('meta[name="theme-color"]');i&&i.setAttribute("content","#ffffff")}},[r]),s.useEffect(()=>{if(!window.matchMedia)return;const l=window.matchMedia("(prefers-color-scheme: dark)"),i=m=>{localStorage.getItem("theme")||a(m.matches)};return l.addEventListener("change",i),()=>l.removeEventListener("change",i)},[]);const n={isDarkMode:r,toggleDarkMode:()=>{a(l=>!l)}};return e.jsx(aa.Provider,{value:n,children:t})},na=s.createContext({user:null,token:null,login:()=>{},sendCode:()=>{},verifyCode:()=>{},logout:()=>{},isLoading:!0,needsSetup:!1,smtpConfigured:!1,error:null,isAdmin:!1,limitStatus:{allowed:!0},checkLimitStatus:()=>{},setLimitStatus:()=>{}}),$t=()=>{const t=s.useContext(na);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t},ci=({children:t})=>{const[r,a]=s.useState(null),[o,n]=s.useState(localStorage.getItem("auth-token")),[l,i]=s.useState(!0),[m,x]=s.useState(!1),[g,v]=s.useState(!1),[M,j]=s.useState(null),[w,h]=s.useState({allowed:!0});s.useEffect(()=>{$()},[]);const $=async()=>{try{i(!0),j(null);const A=await(await we.auth.status()).json();if(v(A.smtpConfigured||!1),A.needsSetup){x(!0),i(!1);return}if(o)try{const W=await we.auth.user();if(W.ok){const O=await W.json();a(O.user),x(!1)}else localStorage.removeItem("auth-token"),n(null),a(null)}catch(W){console.error("Token verification failed:",W),localStorage.removeItem("auth-token"),n(null),a(null)}}catch(S){console.error("[AuthContext] Auth status check failed:",S),j("Failed to check authentication status")}finally{i(!1)}},L=async S=>{try{j(null);const A=await we.auth.sendCode(S),W=await A.json();return A.ok?{success:!0,type:W.type}:{success:!1,error:W.error||"发送验证码失败",waitSeconds:W.waitSeconds}}catch(A){return console.error("Send code error:",A),{success:!1,error:"网络错误,请稍后再试"}}},I=async(S,A)=>{try{j(null);const W=await we.auth.verifyCode(S,A),O=await W.json();return W.ok?(n(O.token),a(O.user),x(!1),localStorage.setItem("auth-token",O.token),{success:!0}):(j(O.error||"验证失败"),{success:!1,error:O.error||"验证失败"})}catch(W){return console.error("Verify code error:",W),{success:!1,error:"网络错误,请稍后再试"}}},C=async(S,A)=>{try{j(null);const W=await we.auth.login(S,A),O=await W.json();return W.ok?(n(O.token),a(O.user),localStorage.setItem("auth-token",O.token),{success:!0}):(j(O.error||"登录失败"),{success:!1,error:O.error||"登录失败"})}catch(W){console.error("Login error:",W);const O="网络错误,请稍后再试";return j(O),{success:!1,error:O}}},p=()=>{n(null),a(null),h({allowed:!0}),localStorage.removeItem("auth-token"),o&&we.auth.logout().catch(S=>{console.error("Logout endpoint error:",S)})},d=async()=>{if(!r)return{allowed:!0};try{const S=await we.auth.limitStatus();if(S.ok){const A=await S.json();return h(A),A}}catch(S){console.error("Error checking limit status:",S)}return{allowed:!0}};s.useEffect(()=>{r&&!l&&d()},[r,l]);const k={user:r,token:o,login:C,sendCode:L,verifyCode:I,logout:p,isLoading:l,needsSetup:m,smtpConfigured:g,error:M,isAdmin:r?.role==="admin",limitStatus:w,checkLimitStatus:d,setLimitStatus:h};return e.jsx(na.Provider,{value:k,children:t})},di=["Bash(git log:*)","Bash(git diff:*)","Bash(git status:*)","Write","Read","Edit","Glob","Grep","MultiEdit","Task","TodoWrite","TodoRead","WebFetch","WebSearch"],mi=["Shell(ls)","Shell(mkdir)","Shell(cd)","Shell(cat)","Shell(echo)","Shell(git status)","Shell(git diff)","Shell(git log)","Shell(npm install)","Shell(npm run)","Shell(python)","Shell(node)"];function ui({skipPermissions:t,setSkipPermissions:r,allowedTools:a,setAllowedTools:o,disallowedTools:n,setDisallowedTools:l,newAllowedTool:i,setNewAllowedTool:m,newDisallowedTool:x,setNewDisallowedTool:g}){const v=h=>{h&&!a.includes(h)&&(o([...a,h]),m(""))},M=h=>{o(a.filter($=>$!==h))},j=h=>{h&&!n.includes(h)&&(l([...n,h]),g(""))},w=h=>{l(n.filter($=>$!==h))};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-sky-50 dark:bg-sky-900/20 border border-sky-200 dark:border-sky-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(As,{className:"w-5 h-5 text-sky-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-sky-800 dark:text-sky-200",children:[e.jsx("span",{className:"font-medium",children:"提示:"}),"此权限设置仅对 ",e.jsx("span",{className:"font-medium",children:"Chat(聊天)"})," 中的 Claude Agent 生效,对 ",e.jsx("span",{className:"font-medium",children:"Shell(终端)"})," 无效。Shell 是直接的系统终端,不受此权限控制。"]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-orange-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"权限设置"})]}),e.jsx("div",{className:"bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg p-4",children:e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:t,onChange:h=>r(h.target.checked),className:"w-4 h-4 text-blue-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-blue-500 focus:ring-2"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-orange-900 dark:text-orange-100",children:"跳过权限提示(请谨慎使用)"}),e.jsx("div",{className:"text-sm text-orange-700 dark:text-orange-300",children:"等同于 --dangerously-skip-permissions 标志"})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mr,{className:"w-5 h-5 text-green-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"允许的工具"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动允许而不提示权限的工具"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:i,onChange:h=>m(h.target.value),placeholder:'e.g., "Bash(git log:*)" or "Write"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),v(i))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>v(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"快速添加常用工具:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:di.map(h=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>v(h),disabled:a.includes(h),className:"text-xs h-8",children:h},h))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-green-800 dark:text-green-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>M(h),className:"text-green-600 hover:text-green-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),a.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置允许的工具"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-red-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"阻止的工具"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动阻止而不提示权限的工具"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:x,onChange:h=>g(h.target.value),placeholder:'e.g., "Bash(rm:*)"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),j(x))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>j(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[n.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-red-800 dark:text-red-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>w(h),className:"text-red-600 hover:text-red-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),n.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置阻止的工具"})]})]}),e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:[e.jsx("h4",{className:"font-medium text-blue-900 dark:text-blue-100 mb-2",children:"工具模式示例:"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-1",children:[e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Bash(git log:*)"'})," - 允许所有 git log 命令"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Bash(git diff:*)"'})," - 允许所有 git diff 命令"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Write"'})," - 允许所有 Write 工具使用"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:'"Bash(rm:*)"'})," - 阻止所有 rm 命令(危险)"]})]})]})]})}function pi({skipPermissions:t,setSkipPermissions:r,allowedCommands:a,setAllowedCommands:o,disallowedCommands:n,setDisallowedCommands:l,newAllowedCommand:i,setNewAllowedCommand:m,newDisallowedCommand:x,setNewDisallowedCommand:g}){const v=h=>{h&&!a.includes(h)&&(o([...a,h]),m(""))},M=h=>{o(a.filter($=>$!==h))},j=h=>{h&&!n.includes(h)&&(l([...n,h]),g(""))},w=h=>{l(n.filter($=>$!==h))};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-orange-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"权限设置"})]}),e.jsx("div",{className:"bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg p-4",children:e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:t,onChange:h=>r(h.target.checked),className:"w-4 h-4 text-purple-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded focus:ring-purple-500 focus:ring-2"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-orange-900 dark:text-orange-100",children:"跳过权限提示(请谨慎使用)"}),e.jsx("div",{className:"text-sm text-orange-700 dark:text-orange-300",children:"等同于 Cursor CLI 中的 -f 标志"})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mr,{className:"w-5 h-5 text-green-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"允许的 Shell 命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动允许而不提示的 Shell 命令"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:i,onChange:h=>m(h.target.value),placeholder:'e.g., "Shell(ls)" or "Shell(git status)"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),v(i))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>v(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"快速添加常用命令:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:mi.map(h=>e.jsx(J,{variant:"outline",size:"sm",onClick:()=>v(h),disabled:a.includes(h),className:"text-xs h-8",children:h},h))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-green-800 dark:text-green-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>M(h),className:"text-green-600 hover:text-green-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),a.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置允许的命令"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pt,{className:"w-5 h-5 text-red-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"阻止的 Shell 命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"自动阻止的 Shell 命令"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(Ke,{value:x,onChange:h=>g(h.target.value),placeholder:'e.g., "Shell(rm -rf)" or "Shell(sudo)"',onKeyPress:h=>{h.key==="Enter"&&(h.preventDefault(),j(x))},className:"flex-1 h-10"}),e.jsxs(J,{onClick:()=>j(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(st,{className:"w-4 h-4 mr-2 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"添加"})]})]}),e.jsxs("div",{className:"space-y-2",children:[n.map(h=>e.jsxs("div",{className:"flex items-center justify-between bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3",children:[e.jsx("span",{className:"font-mono text-sm text-red-800 dark:text-red-200",children:h}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>w(h),className:"text-red-600 hover:text-red-700",children:e.jsx(Oe,{className:"w-4 h-4"})})]},h)),n.length===0&&e.jsx("div",{className:"text-center py-6 text-gray-500 dark:text-gray-400",children:"未配置阻止的命令"})]})]}),e.jsxs("div",{className:"bg-purple-50 dark:bg-purple-900/20 border border-purple-200 dark:border-purple-800 rounded-lg p-4",children:[e.jsx("h4",{className:"font-medium text-purple-900 dark:text-purple-100 mb-2",children:"Shell 命令示例:"}),e.jsxs("ul",{className:"text-sm text-purple-800 dark:text-purple-200 space-y-1",children:[e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(ls)"'})," - 允许 ls 命令"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(git status)"'})," - 允许 git status"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(npm install)"'})," - 允许 npm install"]}),e.jsxs("li",{children:[e.jsx("code",{className:"bg-purple-100 dark:bg-purple-800 px-1 rounded",children:'"Shell(rm -rf)"'})," - 阻止递归删除"]})]})]})]})}function xi({permissionMode:t,setPermissionMode:r}){return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mr,{className:"w-5 h-5 text-green-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"权限模式"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"控制 Codex 如何处理文件修改和命令执行"}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="default"?"bg-gray-100 dark:bg-gray-800 border-gray-400 dark:border-gray-500":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("default"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="default",onChange:()=>r("default"),className:"mt-1 w-4 h-4 text-green-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"默认"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"仅受信任的命令(ls、cat、grep、git status 等)会自动运行。其他命令将被跳过。可以写入工作区。"})]})]})}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="acceptEdits"?"bg-green-50 dark:bg-green-900/20 border-green-400 dark:border-green-600":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("acceptEdits"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="acceptEdits",onChange:()=>r("acceptEdits"),className:"mt-1 w-4 h-4 text-green-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-green-900 dark:text-green-100",children:"接受编辑"}),e.jsx("div",{className:"text-sm text-green-700 dark:text-green-300",children:"所有命令在工作区内自动运行。沙盒执行的完全自动模式。"})]})]})}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="bypassPermissions"?"bg-orange-50 dark:bg-orange-900/20 border-orange-400 dark:border-orange-600":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("bypassPermissions"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="bypassPermissions",onChange:()=>r("bypassPermissions"),className:"mt-1 w-4 h-4 text-orange-600"}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium text-orange-900 dark:text-orange-100 flex items-center gap-2",children:["跳过权限",e.jsx(Pt,{className:"w-4 h-4"})]}),e.jsx("div",{className:"text-sm text-orange-700 dark:text-orange-300",children:"无限制的完全系统访问。所有命令自动运行,具有完全的磁盘和网络访问权限。请谨慎使用。"})]})]})}),e.jsxs("details",{className:"text-sm",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"技术详情"}),e.jsxs("div",{className:"mt-2 p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg text-xs text-muted-foreground space-y-2",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Default:"})," sandboxMode=workspace-write, approvalPolicy=untrusted. Trusted commands: cat, cd, grep, head, ls, pwd, tail, git status/log/diff/show, find (without -exec), etc."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Accept Edits:"})," sandboxMode=workspace-write, approvalPolicy=never. All commands auto-execute within project directory."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Bypass Permissions:"})," sandboxMode=danger-full-access, approvalPolicy=never. Full system access, use only in trusted environments."]}),e.jsx("p",{className:"text-xs opacity-75",children:"您可以在聊天界面中使用模式按钮为每个会话覆盖此设置。"})]})]})]})})}function hi({agent:t,...r}){return t==="claude"?e.jsx(ui,{...r}):t==="cursor"?e.jsx(pi,{...r}):t==="codex"?e.jsx(xi,{...r}):null}const gi=t=>{switch(t){case"stdio":return e.jsx(dr,{className:"w-4 h-4"});case"sse":return e.jsx(sn,{className:"w-4 h-4"});case"http":return e.jsx(Tr,{className:"w-4 h-4"});default:return e.jsx(ur,{className:"w-4 h-4"})}};function fi({servers:t,onAdd:r,onEdit:a,onDelete:o,onTest:n,onDiscoverTools:l,testResults:i,serverTools:m,toolsLoading:x}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ur,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Claude 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(J,{onClick:r,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]})}),e.jsxs("div",{className:"space-y-2",children:[t.map(g=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[gi(g.type),e.jsx("span",{className:"font-medium text-foreground",children:g.name}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:g.type}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:g.scope==="local"?"local":g.scope==="user"?"user":g.scope})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[g.type==="stdio"&&g.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:g.config.command})]}),(g.type==="sse"||g.type==="http")&&g.config?.url&&e.jsxs("div",{children:["URL:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:g.config.url})]}),g.config?.args&&g.config.args.length>0&&e.jsxs("div",{children:["参数:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:g.config.args.join(" ")})]})]}),i?.[g.id]&&e.jsx("div",{className:`mt-2 p-2 rounded text-xs ${i[g.id].success?"bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200":"bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200"}`,children:e.jsx("div",{className:"font-medium",children:i[g.id].message})}),m?.[g.id]&&m[g.id].tools?.length>0&&e.jsxs("div",{className:"mt-2 p-2 rounded text-xs bg-blue-50 dark:bg-blue-900/20 text-blue-800 dark:text-blue-200",children:[e.jsxs("div",{className:"font-medium",children:["工具(",m[g.id].tools.length,"):"]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[m[g.id].tools.slice(0,5).map((v,M)=>e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:v.name},M)),m[g.id].tools.length>5&&e.jsxs("span",{className:"text-xs opacity-75",children:["+",m[g.id].tools.length-5," 更多"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{onClick:()=>a(g),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(Ut,{className:"w-4 h-4"})}),e.jsx(J,{onClick:()=>o(g.id,g.scope),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},g.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function bi({servers:t,onAdd:r,onEdit:a,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ur,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Cursor 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(J,{onClick:r,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]})}),e.jsxs("div",{className:"space-y-2",children:[t.map(n=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(dr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:"stdio"})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:n.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:n.config.command})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",children:e.jsx(Ut,{className:"w-4 h-4"})}),e.jsx(J,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},n.name||n.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function vi({servers:t,onAdd:r,onEdit:a,onDelete:o}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ur,{className:"w-5 h-5 text-gray-700 dark:text-gray-300"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Codex 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(J,{onClick:r,className:"bg-gray-800 hover:bg-gray-900 dark:bg-gray-700 dark:hover:bg-gray-600 text-white",size:"sm",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]})}),e.jsxs("div",{className:"space-y-2",children:[t.map(n=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(dr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:"stdio"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[n.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:n.config.command})]}),n.config?.args&&n.config.args.length>0&&e.jsxs("div",{children:["参数:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:n.config.args.join(" ")})]}),n.config?.env&&Object.keys(n.config.env).length>0&&e.jsxs("div",{children:["环境变量:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:Object.entries(n.config.env).map(([l,i])=>`${l}=${i}`).join(", ")})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(Ut,{className:"w-4 h-4"})}),e.jsx(J,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},n.name)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]}),e.jsxs("div",{className:"bg-gray-100 dark:bg-gray-800/50 border border-gray-300 dark:border-gray-600 rounded-lg p-4",children:[e.jsx("h4",{className:"font-medium text-gray-900 dark:text-gray-100 mb-2",children:"关于 Codex MCP"}),e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300",children:"Codex 支持基于 stdio 的 MCP 服务器。您可以添加扩展 Codex 功能的服务器,提供额外的工具和资源。"})]})]})}function yi({agent:t,...r}){return t==="claude"?e.jsx(fi,{...r}):t==="cursor"?e.jsx(bi,{...r}):t==="codex"?e.jsx(vi,{...r}):null}const ji=[{key:"ANTHROPIC_DEFAULT_OPUS_MODEL",label:"Opus 模型",placeholder:"例如: claude-opus-4-6",description:"覆盖 opus 别名使用的模型,Plan Mode 激活时也用于 opusplan"},{key:"ANTHROPIC_DEFAULT_SONNET_MODEL",label:"Sonnet 模型",placeholder:"例如: claude-sonnet-4-5-20250929",description:"覆盖 sonnet 别名使用的模型,Plan Mode 未激活时也用于 opusplan"},{key:"ANTHROPIC_DEFAULT_HAIKU_MODEL",label:"Haiku 模型",placeholder:"例如: claude-haiku-4-5-20251001",description:"覆盖 haiku 别名使用的模型,也用于后台功能"},{key:"CLAUDE_CODE_SUBAGENT_MODEL",label:"Subagent 模型",placeholder:"例如: claude-haiku-4-5-20251001",description:"覆盖子代理(subagents)使用的模型"}];function wi(){const[t,r]=s.useState({}),[a,o]=s.useState({}),[n,l]=s.useState(!0),[i,m]=s.useState(!1),[x,g]=s.useState(null),[v,M]=s.useState(null);s.useEffect(()=>{j()},[]),s.useEffect(()=>{if(x){const L=setTimeout(()=>g(null),3e3);return()=>clearTimeout(L)}},[x]);const j=async()=>{try{l(!0),M(null);const L=await ne("/api/settings/models");if(L.ok){const I=await L.json();r(I.models||{}),o(I.models||{})}else{const I=await L.json();M(I.error||"加载模型配置失败")}}catch(L){M(L.message)}finally{l(!1)}},w=async()=>{try{m(!0),g(null);const L=await ne("/api/settings/models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({models:t})});if(L.ok)g("success"),o({...t});else{const I=await L.json();g("error"),M(I.error||"保存失败")}}catch(L){g("error"),M(L.message)}finally{m(!1)}},h=()=>{r({...a}),g(null)},$=JSON.stringify(t)!==JSON.stringify(a);return n?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-500"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"加载模型配置..."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-3",children:[e.jsx(As,{className:"w-4 h-4 text-blue-500 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{children:"自定义模型 ID 来覆盖 Claude Code 使用的默认模型。留空表示使用默认模型。"}),e.jsx("p",{className:"mt-1 text-blue-600 dark:text-blue-400",children:"非 Claude 模型将按 Sonnet 定价计费,但统计中会记录实际模型 ID。"})]})]}),v&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-600 dark:text-red-400",children:v}),ji.map(L=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"font-medium text-sm text-foreground",children:L.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:L.description})]}),e.jsx("input",{type:"text",value:t[L.key]||"",onChange:I=>r(C=>({...C,[L.key]:I.target.value})),placeholder:L.placeholder,className:"w-full text-sm bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 px-3 py-2"}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:L.key})]})},L.key)),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("div",{children:[x==="success"&&e.jsx("span",{className:"text-sm text-green-600 dark:text-green-400",children:"模型配置已保存"}),x==="error"&&e.jsx("span",{className:"text-sm text-red-600 dark:text-red-400",children:"保存失败"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:h,disabled:!$,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-lg border border-gray-300 dark:border-gray-600 text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx(an,{className:"w-3.5 h-3.5"}),"重置"]}),e.jsxs("button",{onClick:w,disabled:!$||i,className:"inline-flex items-center gap-1.5 px-4 py-1.5 text-sm rounded-lg bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx(Rs,{className:"w-3.5 h-3.5"}),i?"保存中...":"保存"]})]})]})]})}function ki({onNavigateToUsage:t}){const[r,a]=s.useState([]),[o,n]=s.useState({}),[l,i]=s.useState(!0),[m,x]=s.useState(null),[g,v]=s.useState(!1),[M,j]=s.useState(""),[w,h]=s.useState(""),[$,L]=s.useState(""),[I,C]=s.useState(!1),[p,d]=s.useState(null),[k,S]=s.useState({total_limit_usd:"",daily_limit_usd:""}),[A,W]=s.useState(""),[O,Q]=s.useState(!1),[ie,Z]=s.useState(null),[se,B]=s.useState(""),[T,z]=s.useState(""),[Y,pe]=s.useState(""),[ae,G]=s.useState(!1),xe=async()=>{try{const f=await ne("/api/admin/users");if(f.ok){const b=await f.json();a(b.users)}}catch(f){console.error("Error fetching users:",f)}finally{i(!1)}},Ne=async()=>{try{const f=await ne("/api/admin/usage/summary");if(f.ok){const b=await f.json(),F={};for(const oe of b.users)F[oe.user_uuid]={total_cost:oe.total_cost||0,total_requests:oe.total_requests||0,last_active:oe.last_active};n(F)}}catch(f){console.error("Error fetching usage data:",f)}};s.useEffect(()=>{xe(),Ne()},[]);const Ce=f=>!f||f===0?"$0.00":f<.01?`$${f.toFixed(4)}`:`$${f.toFixed(2)}`,je=async(f,b)=>{const F=b==="active"?"disabled":"active";x(f);try{(await ne(`/api/admin/users/${f}`,{method:"PATCH",body:JSON.stringify({status:F})})).ok&&a(r.map(ue=>ue.id===f?{...ue,status:F}:ue))}catch(oe){console.error("Error updating user status:",oe)}finally{x(null)}},_e=async(f,b)=>{if(confirm(`确定要删除用户 "${b}"?这将删除其所有数据。`)){x(f);try{(await ne(`/api/admin/users/${f}`,{method:"DELETE"})).ok&&a(r.filter(oe=>oe.id!==f))}catch(F){console.error("Error deleting user:",F)}finally{x(null)}}},he=async f=>{if(f.preventDefault(),L(""),!M||!w){L("用户名和密码不能为空");return}if(M.length<3){L("用户名至少3个字符");return}if(w.length<6){L("密码至少6个字符");return}C(!0);try{const b=await we.admin.createUser(M,w),F=await b.json();b.ok?(await xe(),v(!1),j(""),h("")):L(F.error||"创建用户失败")}catch(b){console.error("Error creating user:",b),L("网络错误,请稍后再试")}finally{C(!1)}},Se=()=>{v(!1),j(""),h(""),L("")},ke=f=>{d(f),S({total_limit_usd:f.total_limit_usd!==null&&f.total_limit_usd!==void 0?String(f.total_limit_usd):"",daily_limit_usd:f.daily_limit_usd!==null&&f.daily_limit_usd!==void 0?String(f.daily_limit_usd):""}),W("")},Ee=()=>{d(null),S({total_limit_usd:"",daily_limit_usd:""}),W("")},ve=async f=>{f.preventDefault(),W("");const b=k.total_limit_usd.trim()===""?null:parseFloat(k.total_limit_usd),F=k.daily_limit_usd.trim()===""?null:parseFloat(k.daily_limit_usd);if(b!==null&&(isNaN(b)||b<0)){W("总额度限制必须是正数或留空");return}if(F!==null&&(isNaN(F)||F<0)){W("每日额度限制必须是正数或留空");return}Q(!0);try{const oe=await we.admin.updateUserLimits(p.id,{total_limit_usd:b,daily_limit_usd:F}),ue=await oe.json();oe.ok?(a(r.map(Le=>Le.id===p.id?{...Le,total_limit_usd:b,daily_limit_usd:F}:Le)),Ee()):W(ue.error||"更新限制失败")}catch(oe){console.error("Error updating limits:",oe),W("网络错误,请稍后再试")}finally{Q(!1)}},Pe=f=>f==null?"无限制":`$${f.toFixed(2)}`,Re=f=>{Z(f),B(""),z(""),pe("")},Me=()=>{Z(null),B(""),z(""),pe("")},H=async f=>{if(f.preventDefault(),pe(""),!se){pe("请输入新密码");return}if(se.length<6){pe("密码至少需要6个字符");return}if(se!==T){pe("两次输入的密码不一致");return}G(!0);try{const b=await we.admin.resetUserPassword(ie.id,se),F=await b.json();b.ok?Me():pe(F.error||"重置密码失败")}catch(b){console.error("Error resetting password:",b),pe("网络错误,请稍后再试")}finally{G(!1)}};return l?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"正在加载用户..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"用户管理"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(J,{variant:"default",size:"sm",onClick:()=>v(!0),className:"flex items-center gap-2",children:[e.jsx(nn,{className:"w-4 h-4"}),"创建用户"]}),t&&e.jsxs(J,{variant:"outline",size:"sm",onClick:t,className:"flex items-center gap-2",children:[e.jsx(on,{className:"w-4 h-4"}),"使用量统计"]})]})]}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[700px]",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-900/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-muted-foreground",children:"用户"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-16",children:"角色"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-16",children:"状态"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-20",children:"费用"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-28",children:"额度限制"}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-muted-foreground w-24",children:"创建时间"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-20",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:r.map(f=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-900/30",children:[e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[f.role==="admin"?e.jsx(mr,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(Fs,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground text-sm truncate",children:f.username||f.email}),f.email&&f.username&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:f.email})]})]})}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap ${f.role==="admin"?"bg-blue-500/20 text-blue-400":"bg-gray-500/20 text-gray-400"}`,children:f.role==="admin"?"管理员":"用户"})}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${f.status==="active"?"bg-green-500":"bg-red-500"}`,title:f.status==="active"?"活跃":"已禁用"})}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("span",{className:"font-mono text-xs text-foreground whitespace-nowrap",children:Ce(o[f.uuid]?.total_cost)})}),e.jsx("td",{className:"px-3 py-2 text-right",children:f.role!=="admin"?e.jsx("button",{onClick:()=>ke(f),className:"text-xs text-blue-600 dark:text-blue-400 hover:underline font-mono whitespace-nowrap",title:"点击编辑额度限制",children:f.total_limit_usd!==null||f.daily_limit_usd!==null?e.jsxs("span",{className:"flex flex-col items-end text-[11px] leading-tight",children:[e.jsxs("span",{children:["总:",Pe(f.total_limit_usd)]}),e.jsxs("span",{children:["日:",Pe(f.daily_limit_usd)]})]}):e.jsxs("span",{className:"flex items-center gap-1 justify-end",children:[e.jsx(Os,{className:"w-3 h-3"}),"限额"]})}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"-"})}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground whitespace-nowrap",children:new Date(f.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("div",{className:"flex items-center justify-end gap-1",children:f.role!=="admin"&&e.jsxs(e.Fragment,{children:[f.username&&e.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Re(f),disabled:m===f.id,title:"重置密码",children:e.jsx(Ws,{className:"w-4 h-4 text-blue-500"})}),e.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>je(f.id,f.status),disabled:m===f.id,title:f.status==="active"?"禁用用户":"启用用户",children:f.status==="active"?e.jsx(ln,{className:"w-4 h-4 text-orange-500"}):e.jsx(cn,{className:"w-4 h-4 text-green-500"})}),e.jsx(J,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>_e(f.id,f.username||f.email),disabled:m===f.id,title:"删除用户",children:e.jsx(Ve,{className:"w-4 h-4 text-red-500"})})]})})})]},f.id))})]})}),g&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h4",{className:"text-lg font-semibold text-foreground",children:"创建用户"}),e.jsx("button",{onClick:Se,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:he,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newUsername",className:"block text-sm font-medium text-foreground mb-1",children:"用户名"}),e.jsx("input",{type:"text",id:"newUsername",value:M,onChange:f=>j(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入用户名",disabled:I})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newPassword",className:"block text-sm font-medium text-foreground mb-1",children:"密码"}),e.jsx("input",{type:"password",id:"newPassword",value:w,onChange:f=>h(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入密码",disabled:I})]}),$&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:$})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:Se,disabled:I,children:"取消"}),e.jsx(J,{type:"submit",disabled:I,children:I?"创建中...":"创建"})]})]})]})}),p&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["设置额度限制 - ",p.username||p.email]}),e.jsx("button",{onClick:Ee,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:ve,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"totalLimit",className:"block text-sm font-medium text-foreground mb-1",children:"总额度上限 (USD)"}),e.jsx("input",{type:"number",id:"totalLimit",step:"0.01",min:"0",value:k.total_limit_usd,onChange:f=>S(b=>({...b,total_limit_usd:f.target.value})),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"留空表示不限制",disabled:O}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户累计使用金额达到此限制后,将无法继续使用"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"dailyLimit",className:"block text-sm font-medium text-foreground mb-1",children:"每日额度上限 (USD)"}),e.jsx("input",{type:"number",id:"dailyLimit",step:"0.01",min:"0",value:k.daily_limit_usd,onChange:f=>S(b=>({...b,daily_limit_usd:f.target.value})),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"留空表示不限制",disabled:O}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户每日使用金额达到此限制后,需等待次日重置"})]}),o[p.uuid]&&e.jsx("div",{className:"p-3 bg-gray-100 dark:bg-gray-800 rounded-md",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["当前已使用:",e.jsx("span",{className:"font-mono text-foreground",children:Ce(o[p.uuid]?.total_cost)})]})}),A&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:A})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:Ee,disabled:O,children:"取消"}),e.jsx(J,{type:"submit",disabled:O,children:O?"保存中...":"保存"})]})]})]})}),ie&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["重置密码 - ",ie.username]}),e.jsx("button",{onClick:Me,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"resetNewPassword",className:"block text-sm font-medium text-foreground mb-1",children:"新密码"}),e.jsx("input",{type:"password",id:"resetNewPassword",value:se,onChange:f=>B(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入新密码(至少6个字符)",disabled:ae})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"resetConfirmPassword",className:"block text-sm font-medium text-foreground mb-1",children:"确认新密码"}),e.jsx("input",{type:"password",id:"resetConfirmPassword",value:T,onChange:f=>z(f.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请再次输入新密码",disabled:ae})]}),Y&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:Y})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:Me,disabled:ae,children:"取消"}),e.jsx(J,{type:"submit",disabled:ae,children:ae?"重置中...":"重置密码"})]})]})]})})]})}function Ni(){const[t,r]=s.useState([]),[a,o]=s.useState(!0),[n,l]=s.useState(null),[i,m]=s.useState(!1),[x,g]=s.useState(""),[v,M]=s.useState(""),[j,w]=s.useState(!1),h=async()=>{try{const C=await we.admin.getEmailDomains();if(C.ok){const p=await C.json();r(p.domains)}}catch(C){console.error("Error fetching email domains:",C)}finally{o(!1)}};s.useEffect(()=>{h()},[]);const $=async C=>{if(C.preventDefault(),M(""),!x){M("域名不能为空");return}if(!/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(x)){M("域名格式无效,例如: example.com");return}w(!0);try{const d=await we.admin.addEmailDomain(x.toLowerCase()),k=await d.json();d.ok?(await h(),m(!1),g("")):M(k.error||"添加域名失败")}catch(d){console.error("Error adding domain:",d),M("网络错误,请稍后再试")}finally{w(!1)}},L=async(C,p)=>{if(confirm(`确定要删除域名 "${p}"?删除后该域名的邮箱将无法注册。`)){l(C);try{(await we.admin.removeEmailDomain(C)).ok&&r(t.filter(k=>k.id!==C))}catch(d){console.error("Error removing domain:",d)}finally{l(null)}}},I=()=>{m(!1),g(""),M("")};return a?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"正在加载..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"邮箱域名白名单"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.length===0?"未设置白名单,所有邮箱域名均可注册":"只有白名单内的域名邮箱可以注册"})]}),e.jsxs(J,{variant:"default",size:"sm",onClick:()=>m(!0),className:"flex items-center gap-2",children:[e.jsx(st,{className:"w-4 h-4"}),"添加域名"]})]}),t.length>0?e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-900/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-muted-foreground",children:"域名"}),e.jsx("th",{className:"px-4 py-3 text-left text-sm font-medium text-muted-foreground",children:"添加时间"}),e.jsx("th",{className:"px-4 py-3 text-right text-sm font-medium text-muted-foreground",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:t.map(C=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-900/30",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(or,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"font-medium text-foreground",children:C.domain})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground",children:new Date(C.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>L(C.id,C.domain),disabled:n===C.id,title:"删除域名",children:e.jsx(Ve,{className:"w-4 h-4 text-red-500"})})})})]},C.id))})]})}):e.jsxs("div",{className:"border border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-8 text-center",children:[e.jsx(or,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"暂无域名白名单,所有邮箱域名均可注册"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"添加域名后,只有白名单内的域名邮箱可以注册"})]}),i&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h4",{className:"text-lg font-semibold text-foreground",children:"添加域名"}),e.jsx("button",{onClick:I,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:$,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newDomain",className:"block text-sm font-medium text-foreground mb-1",children:"邮箱域名"}),e.jsx("input",{type:"text",id:"newDomain",value:x,onChange:C=>g(C.target.value.toLowerCase()),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"例如: example.com",disabled:j}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入域名后,该域名下的所有邮箱(如 user@example.com)都可以注册"})]}),v&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:v})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"outline",onClick:I,disabled:j,children:"取消"}),e.jsx(J,{type:"submit",disabled:j,children:j?"添加中...":"添加"})]})]})]})})]})}function Si({onBack:t}){const[r,a]=s.useState("week"),[o,n]=s.useState(null),[l,i]=s.useState(!0),[m,x]=s.useState(!1),g=async()=>{try{const I=await ne(`/api/admin/usage/dashboard?period=${r}`);if(I.ok){const C=await I.json();n(C)}}catch(I){console.error("Error fetching dashboard data:",I)}finally{i(!1),x(!1)}};s.useEffect(()=>{i(!0),g()},[r]);const v=async()=>{try{x(!0),await ne("/api/admin/usage/scan",{method:"POST"}),await g()}catch(I){console.error("Error triggering scan:",I),x(!1)}},M=I=>!I||I===0?"$0.00":I<.01?`$${I.toFixed(4)}`:`$${I.toFixed(2)}`,j=I=>I?I>=1e6?`${(I/1e6).toFixed(1)}M`:I>=1e3?`${(I/1e3).toFixed(1)}K`:I.toString():"0";if(l)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-muted-foreground",children:"加载仪表板中..."})});const{totals:w,dailyTrend:h,modelDistribution:$,topUsers:L}=o||{};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[t&&e.jsxs(J,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(pr,{className:"w-4 h-4 mr-2"}),"返回"]}),e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"使用情况仪表板"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:["week","month"].map(I=>e.jsx("button",{onClick:()=>a(I),className:`px-4 py-2 text-sm font-medium transition-colors ${r===I?"bg-primary text-primary-foreground":"bg-background text-foreground hover:bg-muted"}`,children:I==="week"?"周":"月"},I))}),e.jsx(J,{variant:"outline",size:"sm",onClick:v,disabled:m,title:"扫描新的使用数据",children:e.jsx(nr,{className:`w-4 h-4 ${m?"animate-spin":""}`})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-green-100 dark:bg-green-900/30 rounded-lg",children:e.jsx(Os,{className:"w-5 h-5 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"总成本"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:M(w?.totalCost)})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/30 rounded-lg",children:e.jsx(dn,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"活跃用户"}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:[w?.activeUsers||0," / ",w?.totalUsers||0]})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-purple-100 dark:bg-purple-900/30 rounded-lg",children:e.jsx(Dt,{className:"w-5 h-5 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"总请求数"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:j(w?.totalRequests)})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-orange-100 dark:bg-orange-900/30 rounded-lg",children:e.jsx(mn,{className:"w-5 h-5 text-orange-600 dark:text-orange-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"会话数"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:j(w?.totalSessions)})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"每日成本趋势"}),h&&h.length>0?e.jsx("div",{className:"space-y-2",children:h.map(I=>{const C=Math.max(...h.map(d=>d.cost||0),.01),p=(I.cost||0)/C*100;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-muted-foreground w-20 shrink-0",children:new Date(I.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsx("div",{className:"flex-1 h-6 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-600 rounded",style:{width:`${p}%`}})}),e.jsx("span",{className:"text-sm font-mono text-foreground w-16 text-right",children:M(I.cost)})]},I.date)})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"模型成本"}),$&&$.length>0?e.jsx("div",{className:"space-y-3",children:$.map(I=>{const C=$.reduce((A,W)=>A+(W.cost||0),0)||1,p=(I.cost||0)/C*100,d=(I.normalized_model||I.model||"").toLowerCase(),S=(A=>A.includes("codex")?"bg-orange-500":A.includes("opus")?"bg-purple-500":A.includes("sonnet")?"bg-blue-500":A.includes("haiku")?"bg-green-500":"bg-gray-500")(d);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Ge,{variant:"secondary",className:"truncate max-w-[200px]",title:I.model,children:I.model}),e.jsxs("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:[j(I.requests)," 请求"]})]}),e.jsx("span",{className:"text-sm font-mono text-foreground whitespace-nowrap ml-2",children:M(I.cost)})]}),e.jsx("div",{className:"h-2 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:`h-full ${S} rounded`,style:{width:`${p}%`}})})]},I.model)})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"用户成本"}),L&&L.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[e.jsx("th",{className:"text-left py-2 text-sm font-medium text-muted-foreground",children:"排名"}),e.jsx("th",{className:"text-left py-2 text-sm font-medium text-muted-foreground",children:"用户名"}),e.jsx("th",{className:"text-right py-2 text-sm font-medium text-muted-foreground",children:"请求数"}),e.jsx("th",{className:"text-right py-2 text-sm font-medium text-muted-foreground",children:"成本"})]})}),e.jsx("tbody",{children:L.map((I,C)=>e.jsxs("tr",{className:"border-b border-gray-100 dark:border-gray-800 last:border-0",children:[e.jsxs("td",{className:"py-2 text-sm text-muted-foreground",children:["#",C+1]}),e.jsx("td",{className:"py-2 text-sm font-medium text-foreground",children:I.username}),e.jsx("td",{className:"py-2 text-sm text-right text-muted-foreground",children:j(I.total_requests)}),e.jsx("td",{className:"py-2 text-sm text-right font-mono text-foreground",children:M(I.total_cost)})]},I.user_uuid))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]})}function Ci({onClose:t,onInstalled:r,onOpenRepoManager:a}){const[o,n]=s.useState([]),[l,i]=s.useState([]),[m,x]=s.useState(!0),[g,v]=s.useState(null),[M,j]=s.useState(""),[w,h]=s.useState("all"),[$,L]=s.useState(null);s.useEffect(()=>{I()},[]);const I=async()=>{try{x(!0),v(null);const[d,k]=await Promise.all([ne("/api/skills/available"),ne("/api/skills/repos")]);if(d.ok){const S=await d.json();n(S.skills||[])}if(k.ok){const S=await k.json();i(S.repos||[])}}catch(d){v(d.message)}finally{x(!1)}},C=async d=>{try{L(d.name);const k=await ne(`/api/skills/install/${d.name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillPath:d.path})});if(k.ok)I(),r?.();else{const S=await k.json();alert(S.error||"Failed to install skill")}}catch(k){alert(k.message)}finally{L(null)}},p=o.filter(d=>{if(M){const k=M.toLowerCase();if(!d.name.toLowerCase().includes(k)&&!d.title?.toLowerCase().includes(k)&&!d.description?.toLowerCase().includes(k))return!1}return!(w!=="all"&&d.repository!==w)});return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Skills 管理"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(J,{variant:"ghost",size:"sm",onClick:I,disabled:m,children:[e.jsx(nr,{className:`w-4 h-4 ${m?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(J,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Tt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(J,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Oe,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2",children:e.jsx("h3",{className:"text-amber-500 font-medium",children:"发现技能"})}),e.jsxs("div",{className:"px-4 pb-4 flex flex-wrap gap-3",children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative",children:[e.jsx(It,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ke,{type:"text",placeholder:"搜索技能名称或描述...",value:M,onChange:d=>j(d.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:w,onChange:d=>h(d.target.value),className:"px-3 py-2 rounded-md border border-border bg-background text-foreground text-sm min-w-[120px]",children:[e.jsx("option",{value:"all",children:"全部"}),l.map(d=>e.jsxs("option",{value:`${d.owner}/${d.repo}`,children:[d.owner,"/",d.repo]},`${d.owner}/${d.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[g&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm mb-4",children:g}),m?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):p.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:o.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的技能"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加技能仓库"}),e.jsxs(J,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Tt,{className:"w-4 h-4 mr-2"}),"管理仓库"]})]}):e.jsx("p",{children:"没有找到匹配的技能"})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:p.map(d=>e.jsx("div",{className:"border border-border rounded-lg p-4 hover:border-amber-500/50 transition-colors",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("h4",{className:"font-medium text-foreground",children:d.title||d.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["skills/",d.name]}),e.jsx(Ge,{variant:"outline",className:"text-xs ml-2",children:d.repository})]})]}),d.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:d.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-auto pt-2",children:[e.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>window.open(`https://github.com/${d.repository}`,"_blank"),children:[e.jsx(Bs,{className:"w-4 h-4 mr-1"}),"查看"]}),d.installed?e.jsx(J,{size:"sm",disabled:!0,variant:"outline",className:"ml-auto",children:"已安装"}):e.jsxs(J,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white ml-auto",onClick:()=>C(d),disabled:$===d.name,children:[e.jsx(qr,{className:"w-4 h-4 mr-1"}),$===d.name?"安装中...":"安装"]})]})]})},`${d.repository}-${d.name}`))})]})]})})}function Ei({onClose:t,onChanged:r}){const[a,o]=s.useState([]),[n,l]=s.useState(!0),[i,m]=s.useState(null),[x,g]=s.useState(""),[v,M]=s.useState("main"),[j,w]=s.useState(!1),[h,$]=s.useState(null);s.useEffect(()=>{L()},[]);const L=async()=>{try{l(!0),m(null);const p=await ne("/api/skills/repos");if(p.ok){const d=await p.json();o(d.repos||[])}else{const d=await p.json();m(d.error||"Failed to fetch repos")}}catch(p){m(p.message)}finally{l(!1)}},I=async p=>{if(p.preventDefault(),!x.trim()){m("请输入仓库 URL");return}try{w(!0),m(null);const d=await ne("/api/skills/repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:x.trim(),branch:v.trim()||"main"})});if(d.ok)g(""),M("main"),L(),r?.();else{const k=await d.json();m(k.error||"Failed to add repo")}}catch(d){m(d.message)}finally{w(!1)}},C=async(p,d)=>{if(confirm(`确定要移除仓库 "${p}/${d}" 吗?`))try{$(`${p}/${d}`);const k=await ne(`/api/skills/repos/${p}/${d}`,{method:"DELETE"});if(k.ok)L(),r?.();else{const S=await k.json();alert(S.error||"Failed to remove repo")}}catch(k){alert(k.message)}finally{$(null)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 border-b border-border",children:[e.jsx(J,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(pr,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"管理技能仓库"})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 rounded-lg p-4 space-y-4",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"添加技能仓库"}),e.jsxs("form",{onSubmit:I,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"仓库 URL"}),e.jsx(Ke,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:x,onChange:p=>g(p.target.value),disabled:j})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"分支"}),e.jsx(Ke,{type:"text",placeholder:"main",value:v,onChange:p=>M(p.target.value),disabled:j})]}),e.jsxs(J,{type:"submit",disabled:j||!x.trim(),className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),j?"添加中...":"添加仓库"]})]})]}),i&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"已添加的仓库"}),n?e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(un,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何仓库"})]}):a.map(p=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"font-medium text-foreground",children:[p.owner,"/",p.repo]})}),e.jsxs("div",{className:"flex items-center gap-3 mt-1 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(pn,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Ge,{variant:"outline",className:"text-xs",children:["识别到 ",p.skillCount," 个技能"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>window.open(p.url,"_blank"),children:e.jsx(Bs,{className:"w-4 h-4"})}),e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>C(p.owner,p.repo),disabled:h===`${p.owner}/${p.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},`${p.owner}/${p.repo}`))]})]})]})})}function Mi(){const[t,r]=s.useState([]),[a,o]=s.useState(!0),[n,l]=s.useState(null),[i,m]=s.useState(!1),[x,g]=s.useState(!1),[v,M]=s.useState(!1),j=s.useRef(null);s.useEffect(()=>{w()},[]);const w=async()=>{try{o(!0),l(null);const C=await ne("/api/skills");if(C.ok){const p=await C.json();r(p.skills||[])}else{const p=await C.json();l(p.error||"Failed to fetch skills")}}catch(C){l(C.message)}finally{o(!1)}},h=async C=>{if(confirm(`确定要删除技能 "${C}" 吗?`))try{const p=await ne(`/api/skills/${C}`,{method:"DELETE"});if(p.ok)w();else{const d=await p.json();alert(d.error||"Failed to delete skill")}}catch(p){alert(p.message)}},$=()=>{j.current?.click()},L=async C=>{const p=C.target.files?.[0];if(p)try{M(!0);const d=new FormData;d.append("skillZip",p);const k=await ne("/api/skills/import",{method:"POST",body:d});if(k.ok)w();else{const S=await k.json();alert(S.error||"Failed to import skill")}}catch(d){alert(d.message)}finally{M(!1),j.current&&(j.current.value="")}},I=(C,p)=>{switch(C){case"repo":return e.jsx(Ge,{variant:"outline",className:"text-xs bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300",children:p||"仓库"});case"imported":return e.jsx(Ge,{variant:"outline",className:"text-xs bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",children:"导入"});default:return e.jsx(Ge,{variant:"outline",className:"text-xs",children:"本地"})}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pr,{className:"w-5 h-5 text-amber-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"Skills 管理"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Skills 是 Claude Code 的扩展能力,可以通过 SKILLS.md 文件定义自定义指令和工作流程"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["已安装:Claude: ",e.jsx("span",{className:"font-medium text-foreground",children:t.length})," 个技能"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{ref:j,type:"file",accept:".zip",className:"hidden",onChange:L}),e.jsxs(J,{onClick:$,variant:"outline",size:"sm",disabled:v,children:[e.jsx(qr,{className:"w-4 h-4 mr-2"}),v?"导入中...":"导入已有"]}),e.jsxs(J,{onClick:()=>m(!0),className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),"发现技能"]})]})]}),n&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm",children:n}),e.jsx("div",{className:"space-y-2",children:a?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):t.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Pr,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有安装任何技能"}),e.jsx("p",{className:"text-xs mt-2",children:'点击"发现技能"从仓库安装,或"导入已有"上传本地技能'})]}):t.map(C=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"font-medium text-foreground",children:C.title||C.name}),I(C.source,C.repository)]}),C.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:C.description})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4 shrink-0",children:e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>h(C.name),className:"text-red-500 hover:text-red-600",title:"删除技能",children:e.jsx(Ve,{className:"w-4 h-4"})})})]})},C.name))}),i&&e.jsx(Ci,{onClose:()=>m(!1),onInstalled:w,onOpenRepoManager:()=>{m(!1),g(!0)}}),x&&e.jsx(Ei,{onClose:()=>g(!1),onChanged:()=>{}})]})}function Li({isOpen:t,onClose:r,projects:a=[],initialTab:o="agents"}){const n=Is(),{isDarkMode:l,toggleDarkMode:i}=Yr(),{user:m,logout:x}=$t(),g=m?.role==="admin",[v,M]=s.useState([]),[j,w]=s.useState([]),[h,$]=s.useState(""),[L,I]=s.useState(""),[C,p]=s.useState(!1),[d,k]=s.useState(!1),[S,A]=s.useState(null),[W,O]=s.useState("name"),[Q,ie]=s.useState([]),[Z,se]=s.useState(!1),[B,T]=s.useState(null),[z,Y]=s.useState({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),[pe,ae]=s.useState(!1),[G,xe]=s.useState({}),[Ne,Ce]=s.useState({}),[je,_e]=s.useState({}),[he,Se]=s.useState(o),[ke,Ee]=s.useState(""),[ve,Pe]=s.useState("permissions"),[Re,Me]=s.useState(!1),[H,f]=s.useState(""),[b,F]=s.useState(""),[oe,ue]=s.useState(""),[Le,He]=s.useState(""),[Ye,qe]=s.useState(""),[u,_]=s.useState(!1),[X,te]=s.useState(()=>localStorage.getItem("codeEditorTheme")||"dark"),[D,De]=s.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[Be,Ie]=s.useState(()=>localStorage.getItem("codeEditorShowMinimap")!=="false"),[q,me]=s.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[re,le]=s.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),ye=async()=>{try{const R=await ne("/api/mcp/config/read");if(R.ok){const fe=await R.json();if(fe.success&&fe.servers){ie(fe.servers);return}}const V=await ne("/api/mcp/cli/list");if(V.ok){const fe=await V.json();if(fe.success&&fe.servers){const it=fe.servers.map(Qe=>({id:Qe.name,name:Qe.name,type:Qe.type,scope:"user",config:{command:Qe.command||"",args:Qe.args||[],env:Qe.env||{},url:Qe.url||"",headers:Qe.headers||{},timeout:3e4},created:new Date().toISOString(),updated:new Date().toISOString()}));ie(it);return}}const de=await ne("/api/mcp/servers?scope=user");if(de.ok){const fe=await de.json();ie(fe.servers||[])}else console.error("Failed to fetch MCP servers")}catch(R){console.error("Error fetching MCP servers:",R)}},ze=async R=>{try{B&&await ge(B.id,"user");const V=await ne("/api/mcp/cli/add",{method:"POST",body:JSON.stringify({name:R.name,type:R.type,scope:R.scope,projectPath:R.projectPath,command:R.config?.command,args:R.config?.args||[],url:R.config?.url,headers:R.config?.headers||{},env:R.config?.env||{}})});if(V.ok){const de=await V.json();if(de.success)return await ye(),!0;throw new Error(de.error||"Failed to save server via Claude CLI")}else{const de=await V.json();throw new Error(de.error||"Failed to save server")}}catch(V){throw console.error("Error saving MCP server:",V),V}},ge=async(R,V="user")=>{try{const de=await ne(`/api/mcp/cli/remove/${R}?scope=${V}`,{method:"DELETE"});if(de.ok){const fe=await de.json();if(fe.success)return await ye(),!0;throw new Error(fe.error||"Failed to delete server via Claude CLI")}else{const fe=await de.json();throw new Error(fe.error||"Failed to delete server")}}catch(de){throw console.error("Error deleting MCP server:",de),de}},We=async(R,V="user")=>{try{const de=await ne(`/api/mcp/servers/${R}/test?scope=${V}`,{method:"POST"});if(de.ok)return(await de.json()).testResult;{const fe=await de.json();throw new Error(fe.error||"Failed to test server")}}catch(de){throw console.error("Error testing MCP server:",de),de}},zt=async(R,V="user")=>{try{const de=await ne(`/api/mcp/servers/${R}/tools?scope=${V}`,{method:"POST"});if(de.ok)return(await de.json()).toolsResult;{const fe=await de.json();throw new Error(fe.error||"Failed to discover tools")}}catch(de){throw console.error("Error discovering MCP tools:",de),de}};s.useEffect(()=>{t&&(Xe(),Se(o),Me(!1))},[t,o]),s.useEffect(()=>{localStorage.setItem("codeEditorTheme",X),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[X]),s.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",D.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[D]),s.useEffect(()=>{localStorage.setItem("codeEditorShowMinimap",Be.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Be]),s.useEffect(()=>{localStorage.setItem("codeEditorLineNumbers",q.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[q]),s.useEffect(()=>{localStorage.setItem("codeEditorFontSize",re),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[re]);const Xe=async()=>{try{const R=localStorage.getItem("claude-settings");if(R){const V=JSON.parse(R);M(V.allowedTools||[]),w(V.disallowedTools||[]),p(V.skipPermissions||!1),O(V.projectSortOrder||"name")}else M([]),w([]),p(!1),O("name");await ye()}catch(R){console.error("Error loading tool settings:",R),M([]),w([]),p(!1),O("name")}},_t=()=>{k(!0),A(null);try{const R={allowedTools:v,disallowedTools:j,skipPermissions:C,projectSortOrder:W,lastUpdated:new Date().toISOString()};localStorage.setItem("claude-settings",JSON.stringify(R)),A("success"),setTimeout(()=>{r()},1e3)}catch(R){console.error("Error saving tool settings:",R),A("error")}finally{k(!1)}},bt=async R=>{if(R.preventDefault(),He(""),qe(""),!H){He("请输入当前密码");return}if(!b){He("请输入新密码");return}if(b.length<6){He("新密码至少需要6个字符");return}if(b!==oe){He("两次输入的新密码不一致");return}_(!0);try{const V=await we.auth.changePassword(H,b),de=await V.json();V.ok?(qe("密码修改成功"),f(""),F(""),ue("")):He(de.error||"修改密码失败")}catch(V){console.error("Error changing password:",V),He("网络错误,请稍后再试")}finally{_(!1)}},qt=m?.username&&!m.username.includes("@"),vt=()=>{Y({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),T(null),se(!1),Ee("")},et=(R=null)=>{R?(T(R),Y({name:R.name,type:R.type,scope:R.scope,projectPath:R.projectPath||"",config:{...R.config},raw:R.raw,importMode:"form",jsonInput:""})):vt(),se(!0)},xr=async R=>{R.preventDefault(),ae(!0);try{if(z.importMode==="json"){const V=await ne("/api/mcp/cli/add-json",{method:"POST",body:JSON.stringify({name:z.name,jsonConfig:z.jsonInput,scope:z.scope,projectPath:z.projectPath})});if(V.ok){const de=await V.json();if(de.success)await ye(),vt(),A("success");else throw new Error(de.error||"Failed to add server via JSON")}else{const de=await V.json();throw new Error(de.error||"Failed to add server")}}else await ze(z),vt(),A("success")}catch(V){alert(`Error: ${V.message}`),A("error")}finally{ae(!1)}},At=async(R,V)=>{if(confirm("确定要删除此 MCP 服务器吗?"))try{await ge(R,V),A("success")}catch(de){alert(`Error: ${de.message}`),A("error")}},Ft=async(R,V)=>{try{xe({...G,[R]:{loading:!0}});const de=await We(R,V);xe({...G,[R]:de})}catch(de){xe({...G,[R]:{success:!1,message:de.message,details:[]}})}},Jt=async(R,V)=>{try{_e({...je,[R]:!0});const de=await zt(R,V);Ce({...Ne,[R]:de})}catch{Ce({...Ne,[R]:{success:!1,tools:[],resources:[],prompts:[]}})}finally{_e({...je,[R]:!1})}},at=(R,V)=>{Y(de=>({...de,config:{...de.config,[R]:V}}))};return t?e.jsx("div",{className:"modal-backdrop fixed inset-0 flex items-center justify-center z-[9999] md:p-4 bg-background/95",children:e.jsxs("div",{className:"bg-background border border-border md:rounded-lg shadow-xl w-full md:max-w-4xl h-full md:h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 md:p-6 border-b border-border flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Tt,{className:"w-5 h-5 md:w-6 md:h-6 text-blue-600"}),e.jsx("h2",{className:"text-lg md:text-xl font-semibold text-foreground",children:"设置"})]}),e.jsx(J,{variant:"ghost",size:"sm",onClick:r,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(Oe,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx("div",{className:"border-b border-border",children:e.jsxs("div",{className:"flex px-4 md:px-6",children:[e.jsx("button",{onClick:()=>Se("agents"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="agents"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"Agent"}),e.jsx("button",{onClick:()=>Se("appearance"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="appearance"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"外观"}),g&&e.jsx("button",{onClick:()=>Se("users"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="users"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"用户"}),e.jsx("button",{onClick:()=>Se("account"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${he==="account"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"账户"})]})}),e.jsxs("div",{className:"p-4 md:p-6 space-y-6 md:space-y-8 pb-safe-area-inset-bottom",children:[he==="appearance"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:he==="appearance"&&e.jsxs("div",{className:"space-y-6 md:space-y-8",children:[e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"深色模式"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"切换浅色和深色主题"})]}),e.jsxs("button",{onClick:i,className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":l,"aria-label":"Toggle dark mode",children:[e.jsx("span",{className:"sr-only",children:"Toggle dark mode"}),e.jsx("span",{className:`${l?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200 flex items-center justify-center`,children:l?e.jsx(Rr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx($r,{className:"w-3.5 h-3.5 text-yellow-500"})})]})]})})}),e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"项目排序"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"侧边栏中项目的排序方式"})]}),e.jsxs("select",{value:W,onChange:R=>O(R.target.value),className:"text-sm bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2 w-32",children:[e.jsx("option",{value:"name",children:"按字母顺序"}),e.jsx("option",{value:"date",children:"按最近活动"})]})]})})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"代码编辑器"}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"编辑器主题"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"代码编辑器的默认主题"})]}),e.jsxs("button",{onClick:()=>te(X==="dark"?"light":"dark"),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":X==="dark","aria-label":"Toggle editor theme",children:[e.jsx("span",{className:"sr-only",children:"Toggle editor theme"}),e.jsx("span",{className:`${X==="dark"?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200 flex items-center justify-center`,children:X==="dark"?e.jsx(Rr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx($r,{className:"w-3.5 h-3.5 text-yellow-500"})})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"自动换行"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"在编辑器中默认启用自动换行"})]}),e.jsxs("button",{onClick:()=>De(!D),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":D,"aria-label":"Toggle word wrap",children:[e.jsx("span",{className:"sr-only",children:"Toggle word wrap"}),e.jsx("span",{className:`${D?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200`})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"显示小地图"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"在差异视图中显示小地图以便于导航"})]}),e.jsxs("button",{onClick:()=>Ie(!Be),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":Be,"aria-label":"Toggle minimap",children:[e.jsx("span",{className:"sr-only",children:"Toggle minimap"}),e.jsx("span",{className:`${Be?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200`})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"显示行号"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"在编辑器中显示行号"})]}),e.jsxs("button",{onClick:()=>me(!q),className:"relative inline-flex h-8 w-14 items-center rounded-full bg-gray-200 dark:bg-gray-700 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900",role:"switch","aria-checked":q,"aria-label":"Toggle line numbers",children:[e.jsx("span",{className:"sr-only",children:"Toggle line numbers"}),e.jsx("span",{className:`${q?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200`})]})]})}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"字体大小"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"编辑器字体大小(像素)"})]}),e.jsxs("select",{value:re,onChange:R=>le(R.target.value),className:"text-sm bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2 w-24",children:[e.jsx("option",{value:"10",children:"10px"}),e.jsx("option",{value:"11",children:"11px"}),e.jsx("option",{value:"12",children:"12px"}),e.jsx("option",{value:"13",children:"13px"}),e.jsx("option",{value:"14",children:"14px"}),e.jsx("option",{value:"15",children:"15px"}),e.jsx("option",{value:"16",children:"16px"}),e.jsx("option",{value:"18",children:"18px"}),e.jsx("option",{value:"20",children:"20px"})]})]})})]})]})}),he==="agents"&&e.jsx("div",{className:"flex flex-col h-full min-h-[400px] md:min-h-[500px]",children:e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:e.jsxs("div",{className:"flex px-2 md:px-4 overflow-x-auto",children:[e.jsx("button",{onClick:()=>Pe("permissions"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="permissions"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"权限"}),e.jsx("button",{onClick:()=>Pe("mcp"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="mcp"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"MCP 服务器"}),e.jsx("button",{onClick:()=>Pe("skills"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="skills"?"border-amber-600 text-amber-600 dark:text-amber-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"技能"}),e.jsx("button",{onClick:()=>Pe("models"),className:`px-3 md:px-4 py-2 md:py-3 text-xs md:text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${ve==="models"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"模型"})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 md:p-4",children:[ve==="permissions"&&e.jsx(hi,{agent:"claude",skipPermissions:C,setSkipPermissions:p,allowedTools:v,setAllowedTools:M,disallowedTools:j,setDisallowedTools:w,newAllowedTool:h,setNewAllowedTool:$,newDisallowedTool:L,setNewDisallowedTool:I}),ve==="mcp"&&e.jsx(yi,{agent:"claude",servers:Q,onAdd:()=>et(),onEdit:R=>et(R),onDelete:(R,V)=>At(R,V),onTest:(R,V)=>Ft(R,V),onDiscoverTools:(R,V)=>Jt(R,V),testResults:G,serverTools:Ne,toolsLoading:je}),ve==="skills"&&e.jsx(Mi,{}),ve==="models"&&e.jsx(wi,{})]})]})}),he==="users"&&g&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:Re?e.jsx(Si,{onBack:()=>Me(!1)}):e.jsxs(e.Fragment,{children:[e.jsx(ki,{onNavigateToUsage:()=>Me(!0)}),e.jsx(Ni,{})]})}),he==="account"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"账户"}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/10 rounded-full flex items-center justify-center",children:e.jsx("span",{className:"text-lg font-semibold text-primary",children:m?.username?.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:m?.username}),e.jsx("div",{className:"text-sm text-muted-foreground",children:m?.role==="admin"?"管理员":"用户"})]})]})}),qt&&e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ws,{className:"w-5 h-5 text-blue-600"}),e.jsx("div",{className:"font-medium text-foreground",children:"修改密码"})]}),e.jsxs("form",{onSubmit:bt,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"currentPassword",className:"block text-sm font-medium text-foreground mb-1",children:"当前密码"}),e.jsx("input",{type:"password",id:"currentPassword",value:H,onChange:R=>f(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入当前密码",disabled:u})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newPassword",className:"block text-sm font-medium text-foreground mb-1",children:"新密码"}),e.jsx("input",{type:"password",id:"newPassword",value:b,onChange:R=>F(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入新密码(至少6个字符)",disabled:u})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmNewPassword",className:"block text-sm font-medium text-foreground mb-1",children:"确认新密码"}),e.jsx("input",{type:"password",id:"confirmNewPassword",value:oe,onChange:R=>ue(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请再次输入新密码",disabled:u})]}),Le&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:Le})}),Ye&&e.jsx("div",{className:"p-3 bg-green-100 dark:bg-green-900/20 border border-green-300 dark:border-green-800 rounded-md",children:e.jsx("p",{className:"text-sm text-green-700 dark:text-green-400",children:Ye})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(J,{type:"submit",disabled:u,className:"bg-blue-600 hover:bg-blue-700",children:u?"修改中...":"修改密码"})})]})]}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"退出登录"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"结束当前会话"})]}),e.jsxs(J,{variant:"outline",className:"gap-2 text-red-600 dark:text-red-400 border-red-200 dark:border-red-800 hover:bg-red-50 dark:hover:bg-red-900/20",onClick:()=>{confirm("确定要退出登录吗?")&&(r(),n("/"),x())},children:[e.jsx(xn,{className:"w-4 h-4"}),"退出"]})]})})]})}),Z&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[110] p-4",children:e.jsxs("div",{className:"bg-background border border-border rounded-lg w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[e.jsx("h3",{className:"text-lg font-medium text-foreground",children:B?"编辑 MCP 服务器":"添加 MCP 服务器"}),e.jsx(J,{variant:"ghost",size:"sm",onClick:vt,children:e.jsx(Oe,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:xr,className:"p-4 space-y-4",children:[!B&&e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,importMode:"form"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${z.importMode==="form"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:"表单输入"}),e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,importMode:"json"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${z.importMode==="json"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:"JSON 导入"})]}),z.importMode==="form"&&B&&e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-3",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"作用域"}),e.jsxs("div",{className:"flex items-center gap-2",children:[z.scope==="user"?e.jsx(Tr,{className:"w-4 h-4"}):e.jsx(kt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:z.scope==="user"?"用户(全局)":"项目(本地)"}),z.scope==="local"&&z.projectPath&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",z.projectPath]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"编辑现有服务器时无法更改作用域"})]}),z.importMode==="form"&&!B&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"作用域 *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,scope:"user",projectPath:""})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${z.scope==="user"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(Tr,{className:"w-4 h-4"}),e.jsx("span",{children:"用户(全局)"})]})}),e.jsx("button",{type:"button",onClick:()=>Y(R=>({...R,scope:"local"})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${z.scope==="local"?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700"}`,children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(kt,{className:"w-4 h-4"}),e.jsx("span",{children:"项目(本地)"})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:z.scope==="user"?"用户作用域:在您机器上的所有项目中可用":"本地作用域:仅在选定的项目中可用"})]}),z.scope==="local"&&!B&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"项目 *"}),e.jsxs("select",{value:z.projectPath,onChange:R=>Y(V=>({...V,projectPath:R.target.value})),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500",required:z.scope==="local",children:[e.jsx("option",{value:"",children:"选择项目..."}),a.map(R=>e.jsx("option",{value:R.path||R.fullPath,children:R.displayName||R.name},R.name))]}),z.projectPath&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Path: ",z.projectPath]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:z.importMode==="json"?"md:col-span-2":"",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称 *"}),e.jsx(Ke,{value:z.name,onChange:R=>{Y(V=>({...V,name:R.target.value}))},placeholder:"my-server",required:!0})]}),z.importMode==="form"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"传输类型 *"}),e.jsxs("select",{value:z.type,onChange:R=>{Y(V=>({...V,type:R.target.value}))},className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:"stdio",children:"stdio"}),e.jsx("option",{value:"sse",children:"SSE"}),e.jsx("option",{value:"http",children:"HTTP"})]})]})]}),B&&z.raw&&z.importMode==="form"&&e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsxs("h4",{className:"text-sm font-medium text-foreground mb-2",children:["配置详情 (from ",B.scope==="global"?"~/.claude.json":"project config",")"]}),e.jsx("pre",{className:"text-xs bg-gray-100 dark:bg-gray-800 p-3 rounded overflow-x-auto",children:JSON.stringify(z.raw,null,2)})]}),z.importMode==="json"&&e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"JSON 配置 *"}),e.jsx("textarea",{value:z.jsonInput,onChange:R=>{Y(V=>({...V,jsonInput:R.target.value}));try{if(R.target.value.trim()){const V=JSON.parse(R.target.value);V.type?V.type==="stdio"&&!V.command?Ee("stdio 类型需要 command 字段"):(V.type==="http"||V.type==="sse")&&!V.url?Ee(`${V.type} 类型需要 url 字段`):Ee(""):Ee("缺少必填字段:type")}}catch{R.target.value.trim()?Ee("无效的 JSON 格式"):Ee("")}},className:`w-full px-3 py-2 border ${ke?"border-red-500":"border-gray-300 dark:border-gray-600"} bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 font-mono text-sm`,rows:"8",placeholder:`{
136
136
  "type": "stdio",
137
137
  "command": "/path/to/server",
138
138
  "args": ["--api-key", "abc123"],