@ian2018cs/agenthub 0.1.38 → 0.1.42

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.
@@ -0,0 +1,151 @@
1
+ import{j as e,s as _a,R as Fa,o as Wa,E as Ba,m as Ua,b as Ha,c as qa,h as Ja,p as Ka,d as Ga}from"./vendor-codemirror-C_VWDoZS.js";import{b as Va,g as Zr,a as r,d as bs,R as rt,u as Hs,B as Ya,e as Qa,f as ys,h as Za}from"./vendor-react-BeVl62c0.js";import{t as Xa,c as en,a as qs,F as tn}from"./vendor-utils-00TdZexr.js";import{F as Ar,X as Je,C as rn,L as jt,T as Ve,R as Tt,S as Pt,a as ct,b as It,c as hr,d as vs,P as sr,e as Ir,f as Ht,g as _r,h as sn,i as st,j as wt,k as an,l as nn,M as gr,B as Js,D as Dt,m as Ks,n as on,o as Gs,U as js,p as ln,E as Vs,q as cn,r as dn,s as Ys,t as ws,u as Xr,v as nr,I as Qs,w as qt,x as wr,y as or,G as es,z as fr,Z as Zs,A as mn,H as un,J as Xs,K as ea,N as Fr,O as pn,Q as xn,V as br,W as ir,Y as hn,_ as gn,$ as ta,a0 as ra,a1 as Wr,a2 as Br,a3 as Ur,a4 as fn,a5 as bn,a6 as yn,a7 as vn,a8 as jn,a9 as wn,aa as kn,ab as Nn}from"./vendor-icons-CDkQcAKw.js";import{r as Sn,a as Cn,b as En,M as Mn}from"./vendor-markdown-VwNYkg_0.js";import{h as Ln}from"./vendor-syntax-CdGaPJRS.js";import{r as In,a as Dn,b as Tn,c as Pn}from"./vendor-xterm-CvdiG4-n.js";import"./vendor-katex-DK8hFnhL.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))o(n);new MutationObserver(n=>{for(const l of n)if(l.type==="childList")for(const i of l.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&o(i)}).observe(document,{childList:!0,subtree:!0});function a(n){const l={};return n.integrity&&(l.integrity=n.integrity),n.referrerPolicy&&(l.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?l.credentials="include":n.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function o(n){if(n.ep)return;n.ep=!0;const l=a(n);fetch(n.href,l)}})();var mr={},ks;function Rn(){if(ks)return mr;ks=1;var t=Va();return mr.createRoot=t.createRoot,mr.hydrateRoot=t.hydrateRoot,mr}var $n=Rn();const zn=Zr($n);function qe(...t){return Xa(en(t))}function On(t){if(!t||typeof t!="string")return null;try{return JSON.parse(t)}catch{return null}}const ts=r.forwardRef(({className:t,children:s,...a},o)=>e.jsx("div",{ref:o,className:qe("relative overflow-hidden",t),...a,children:e.jsx("div",{className:"h-full w-full rounded-[inherit] overflow-auto",style:{WebkitOverflowScrolling:"touch",touchAction:"pan-y"},children:s})}));ts.displayName="ScrollArea";const An=qs("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),B=r.forwardRef(({className:t,variant:s,size:a,...o},n)=>e.jsx("button",{className:qe(An({variant:s,size:a,className:t})),ref:n,...o}));B.displayName="Button";const _n=qs("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",success:"border-transparent bg-green-500 text-white shadow hover:bg-green-500/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Ge({className:t,variant:s,...a}){return e.jsx("div",{className:qe(_n({variant:s}),t),...a})}const Ye=r.forwardRef(({className:t,type:s,...a},o)=>e.jsx("input",{type:s,className:qe("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",t),ref:o,...a}));Ye.displayName="Input";const mt=({className:t="w-5 h-5"})=>e.jsx("img",{src:"/icons/claude-ai-icon.svg",alt:"Claude",className:t}),Q=(t,s={})=>{const a=localStorage.getItem("auth-token"),o={};return s.body instanceof FormData||(o["Content-Type"]="application/json"),a&&(o.Authorization=`Bearer ${a}`),fetch(t,{...s,headers:{...o,...s.headers}})},ye={auth:{status:()=>fetch("/api/auth/status"),login:(t,s)=>fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:t,password:s})}),sendCode:t=>fetch("/api/auth/send-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t})}),verifyCode:(t,s)=>fetch("/api/auth/verify-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,code:s})}),user:()=>Q("/api/auth/user"),logout:()=>Q("/api/auth/logout",{method:"POST"}),limitStatus:()=>Q("/api/auth/limit-status"),changePassword:(t,s)=>Q("/api/auth/change-password",{method:"PATCH",body:JSON.stringify({current_password:t,new_password:s})}),feishuBindToken:()=>Q("/api/auth/feishu-bind-token",{method:"POST"})},admin:{getUsers:()=>Q("/api/admin/users"),createUser:(t,s)=>Q("/api/admin/users",{method:"POST",body:JSON.stringify({username:t,password:s})}),updateUserStatus:(t,s)=>Q(`/api/admin/users/${t}`,{method:"PATCH",body:JSON.stringify({status:s})}),deleteUser:t=>Q(`/api/admin/users/${t}`,{method:"DELETE"}),getEmailDomains:()=>Q("/api/admin/email-domains"),addEmailDomain:t=>Q("/api/admin/email-domains",{method:"POST",body:JSON.stringify({domain:t})}),removeEmailDomain:t=>Q(`/api/admin/email-domains/${t}`,{method:"DELETE"}),getUserLimits:t=>Q(`/api/admin/users/${t}/limits`),updateUserLimits:(t,s)=>Q(`/api/admin/users/${t}/limits`,{method:"PATCH",body:JSON.stringify(s)}),resetUserPassword:(t,s)=>Q(`/api/admin/users/${t}/password`,{method:"PATCH",body:JSON.stringify({new_password:s})}),getDefaultLimits:()=>Q("/api/admin/settings/default-limits"),updateDefaultLimits:t=>Q("/api/admin/settings/default-limits",{method:"PUT",body:JSON.stringify(t)})},projects:()=>Q("/api/projects"),sessions:(t,s=5,a=0)=>Q(`/api/projects/${t}/sessions?limit=${s}&offset=${a}`),sessionMessages:(t,s,a=null,o=0)=>{const n=new URLSearchParams;a!==null&&(n.append("limit",a),n.append("offset",o));const l=n.toString(),i=`/api/projects/${t}/sessions/${s}/messages${l?`?${l}`:""}`;return Q(i)},renameProject:(t,s)=>Q(`/api/projects/${t}/rename`,{method:"PUT",body:JSON.stringify({displayName:s})}),deleteSession:(t,s)=>Q(`/api/projects/${t}/sessions/${s}`,{method:"DELETE"}),deleteProject:(t,s=!0)=>Q(`/api/projects/${t}?deleteFolder=${s}`,{method:"DELETE"}),createProject:t=>Q("/api/projects/create",{method:"POST",body:JSON.stringify({path:t})}),createWorkspace:t=>Q("/api/projects/create-workspace",{method:"POST",body:JSON.stringify(t)}),readFile:(t,s)=>Q(`/api/projects/${t}/file?filePath=${encodeURIComponent(s)}`),saveFile:(t,s,a)=>Q(`/api/projects/${t}/file`,{method:"PUT",body:JSON.stringify({filePath:s,content:a})}),getFiles:(t,s={})=>{const a=new URLSearchParams;s.dirPath&&a.set("dirPath",s.dirPath),s.depth&&a.set("depth",s.depth.toString());const o=a.toString();return Q(`/api/projects/${t}/files${o?"?"+o:""}`)},uploadFiles:(t,s)=>Q(`/api/projects/${t}/upload-files`,{method:"POST",body:s,headers:{}}),deleteFile:(t,s)=>Q(`/api/projects/${t}/files?filePath=${encodeURIComponent(s)}`,{method:"DELETE"}),getFileContent:(t,s)=>Q(`/api/projects/${t}/files/content?path=${encodeURIComponent(s)}`),transcribe:t=>Q("/api/transcribe",{method:"POST",body:t,headers:{}}),settings:{getAgentPermissions:()=>Q("/api/settings/agent-permissions"),saveAgentPermissions:t=>Q("/api/settings/agent-permissions",{method:"PUT",body:JSON.stringify({agentPermissions:t})})},get:t=>Q(`/api${t}`)},Fn=/^[a-zA-Z0-9_-]+$/,Wn=({onClose:t,onProjectCreated:s})=>{const[a,o]=r.useState(""),[n,l]=r.useState(""),[i,d]=r.useState(!1),[h,g]=r.useState(null),p=y=>y.trim()?Fn.test(y.trim())?null:"项目名称只能包含字母、数字、连字符和下划线":"项目名称为必填项",w=async()=>{g(null);const y=p(a);if(y){g(y);return}d(!0);try{const x={name:a.trim()};n.trim()&&(x.githubUrl=n.trim());const P=await ye.createWorkspace(x),R=await P.json();if(!P.ok)throw new Error(R.error||"Failed to create project");s&&s(R.project),t()}catch(x){console.error("Error creating project:",x),g(x.message||"Failed to create project")}finally{d(!1)}},v=y=>{y.key==="Enter"&&!i&&w()};return e.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-[60] p-0 sm:p-4",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-none sm:rounded-lg shadow-xl w-full h-full sm:h-auto sm:max-w-md border-0 sm:border border-gray-200 dark:border-gray-700 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-blue-100 dark:bg-blue-900/50 rounded-lg flex items-center justify-center",children:e.jsx(Ar,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"创建新项目"})]}),e.jsx("button",{onClick:t,className:"p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 rounded-md hover:bg-gray-100 dark:hover:bg-gray-700",disabled:i,children:e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[h&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-start gap-3",children:[e.jsx(rn,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5"}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-sm text-red-800 dark:text-red-200",children:h})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:["项目名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Ye,{type:"text",value:a,onChange:y=>o(y.target.value),onKeyDown:v,placeholder:"my-awesome-project",className:"w-full",autoFocus:!0}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"仅允许字母、数字、连字符和下划线"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"GitHub 链接(可选)"}),e.jsx(Ye,{type:"text",value:n,onChange:y=>l(y.target.value),onKeyDown:v,placeholder:"https://github.com/user/repo",className:"w-full"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"留空以创建空项目,或输入公共仓库链接以克隆"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 p-6 border-t border-gray-200 dark:border-gray-700",children:[e.jsx(B,{variant:"outline",onClick:t,disabled:i,children:"取消"}),e.jsx(B,{onClick:w,disabled:i||!a.trim(),children:i?e.jsxs(e.Fragment,{children:[e.jsx(jt,{className:"w-4 h-4 mr-2 animate-spin"}),"创建中..."]}):"创建项目"})]})]})})},Ns=(t,s)=>{const a=new Date(t),o=s;if(isNaN(a.getTime()))return"Unknown";const n=o-a,l=Math.floor(n/1e3),i=Math.floor(n/(1e3*60)),d=Math.floor(n/(1e3*60*60)),h=Math.floor(n/(1e3*60*60*24));return l<60?"Just now":i===1?"1 min ago":i<60?`${i} mins ago`:d===1?"1 hour ago":d<24?`${d} hours ago`:h===1?"1 day ago":h<7?`${h} days ago`:a.toLocaleDateString()};function Ss({projects:t,selectedProject:s,selectedSession:a,onProjectSelect:o,onSessionSelect:n,onNewSession:l,onSessionDelete:i,onProjectDelete:d,isLoading:h,onRefresh:g,onShowSettings:p,isPWA:w,isMobile:v,onToggleSidebar:y}){const[x,P]=r.useState(new Set),[R,C]=r.useState(null),[k,u]=r.useState(!1),[m,N]=r.useState(""),[S,f]=r.useState({}),[A,F]=r.useState({}),[Z,le]=r.useState(new Set),[ee,ne]=r.useState(new Date),[U,D]=r.useState("name"),[X,se]=r.useState(!1),[ve,oe]=r.useState(null),[z,ue]=r.useState(""),[Le,Te]=r.useState({}),[ke,Fe]=r.useState(""),[we,Se]=r.useState(null),[ze,Ue]=r.useState(()=>{try{const j=localStorage.getItem("starredProjects");return j?new Set(JSON.parse(j)):new Set}catch(j){return console.error("Error loading starred projects:",j),new Set}}),xe=j=>V=>{V.target.closest(".overflow-y-auto")||V.target.closest("[data-scroll-container]")||(V.preventDefault(),V.stopPropagation(),j())};r.useEffect(()=>{const j=setInterval(()=>{ne(new Date)},6e4);return()=>clearInterval(j)},[]),r.useEffect(()=>{F({}),le(new Set)},[t]),r.useEffect(()=>{a&&s&&P(j=>new Set([...j,s.name]))},[a,s]),r.useEffect(()=>{if(t.length>0&&!h){const j=new Set;t.forEach(V=>{V.sessions&&V.sessions.length>=0&&j.add(V.name)}),le(j)}},[t,h]),r.useEffect(()=>{const j=()=>{try{const ce=localStorage.getItem("claude-settings");if(ce){const $=JSON.parse(ce);D($.projectSortOrder||"name")}}catch(ce){console.error("Error loading sort order:",ce)}};j();const V=ce=>{ce.key==="claude-settings"&&j()};window.addEventListener("storage",V);const de=setInterval(()=>{document.hasFocus()&&j()},1e3);return()=>{window.removeEventListener("storage",V),clearInterval(de)}},[]);const Ce=j=>{const V=new Set;x.has(j)||V.add(j),P(V)},Ie=(j,V)=>{n({...j,__projectName:V})},Pe=j=>{const V=new Set(ze);V.has(j)?V.delete(j):V.add(j),Ue(V);try{localStorage.setItem("starredProjects",JSON.stringify([...V]))}catch(de){console.error("Error saving starred projects:",de)}},De=j=>ze.has(j),T=j=>[...j.sessions||[],...A[j.name]||[]].map(de=>({...de,__provider:"claude"})).sort((de,ce)=>new Date(ce.lastActivity)-new Date(de.lastActivity)),_=j=>{const V=T(j);return V.length===0?new Date(0):V.reduce((ce,$)=>{const $e=new Date($.lastActivity);return $e>ce?$e:ce},new Date(0))},W=[...t].sort((j,V)=>{const de=De(j.name),ce=De(V.name);if(de&&!ce)return-1;if(!de&&ce)return 1;if(U==="date")return _(V)-_(j);{const $=j.displayName||j.name,$e=V.displayName||V.name;return $.localeCompare($e)}}),b=j=>{C(j.name),N(j.displayName)},H=()=>{C(null),N("")},pe=async j=>{try{(await ye.renameProject(j,m)).ok?window.refreshProjects?window.refreshProjects():window.location.reload():console.error("Failed to rename project")}catch(V){console.error("Error renaming project:",V)}C(null),N("")},Ne=async(j,V,de="claude")=>{if(confirm("Are you sure you want to delete this session? This action cannot be undone."))try{console.log("[Sidebar] Deleting session:",{projectName:j,sessionId:V,provider:de});const ce=await ye.deleteSession(j,V);if(console.log("[Sidebar] Delete response:",{ok:ce.ok,status:ce.status}),ce.ok)console.log("[Sidebar] Session deleted successfully, calling callback"),i?i(V):console.warn("[Sidebar] No onSessionDelete callback provided");else{const $=await ce.text();console.error("[Sidebar] Failed to delete session:",{status:ce.status,error:$}),alert("Failed to delete session. Please try again.")}}catch(ce){console.error("[Sidebar] Error deleting session:",ce),alert("Error deleting session. Please try again.")}},Oe=async j=>{if(we)try{const V=await ye.deleteProject(j,!0);if(V.ok)Se(null),d&&d(j);else{const de=await V.json();console.error("Failed to delete project"),alert(de.error||"Failed to delete project. Please try again.")}}catch(V){console.error("Error deleting project:",V),alert("Error deleting project. Please try again.")}},at=async j=>{if(!(!(j.sessionMeta?.hasMore!==!1)||S[j.name])){f(de=>({...de,[j.name]:!0}));try{const de=(j.sessions?.length||0)+(A[j.name]?.length||0),ce=await ye.sessions(j.name,5,de);if(ce.ok){const $=await ce.json();F($e=>({...$e,[j.name]:[...$e[j.name]||[],...$.sessions]})),$.hasMore===!1&&(j.sessionMeta={...j.sessionMeta,hasMore:!1})}}catch(de){console.error("Error loading more sessions:",de)}finally{f(de=>({...de,[j.name]:!1}))}}},K=W.filter(j=>{if(!ke.trim())return!0;const V=ke.toLowerCase(),de=(j.displayName||j.name).toLowerCase(),ce=j.name.toLowerCase();return de.includes(V)||ce.includes(V)}),ae=j=>{o(j)};return e.jsxs(e.Fragment,{children:[k&&bs.createPortal(e.jsx(Wn,{onClose:()=>u(!1),onProjectCreated:j=>{window.refreshProjects?window.refreshProjects():window.location.reload()}}),document.body),we&&bs.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl w-full max-w-sm p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center flex-shrink-0",children:e.jsx(Ve,{className:"w-5 h-5 text-red-600 dark:text-red-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-foreground",children:"删除项目"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"此操作不可撤销"})]})]}),e.jsxs("p",{className:"text-sm text-foreground",children:["确定要删除项目 ",e.jsxs("span",{className:"font-medium text-red-600 dark:text-red-400",children:['"',we.displayName||we.name,'"']})," 吗?"]}),e.jsx("p",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3",children:"将同时删除:所有会话记录(JSONL 文件)和项目文件夹及其所有内容。"}),e.jsxs("div",{className:"flex gap-3 pt-1",children:[e.jsx("button",{className:"flex-1 px-4 py-2 rounded-lg border border-border text-sm font-medium hover:bg-accent transition-colors",onClick:()=>Se(null),children:"取消"}),e.jsx("button",{className:"flex-1 px-4 py-2 rounded-lg bg-red-600 hover:bg-red-700 text-white text-sm font-medium transition-colors",onClick:()=>Oe(we.name),children:"确认删除"})]})]})}),document.body),e.jsxs("div",{className:"h-full flex flex-col bg-card md:select-none",style:w&&v?{paddingTop:"44px"}:{},children:[e.jsxs("div",{className:"md:p-4 md:border-b md:border-border",children:[e.jsxs("div",{className:"hidden md:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:"/logo.svg",className:"w-8 h-8",alt:"AgentHub"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold text-foreground",children:"AgentHub"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"你的 AI 助手"})]})]}),y&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200",onClick:y,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:"M15 19l-7-7 7-7"})})})]}),e.jsx("div",{className:"md:hidden p-3 border-b border-border",style:w&&v?{paddingTop:"16px"}:{},children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:"/logo.svg",className:"w-8 h-8",alt:"AgentHub"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"AgentHub"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"项目"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:"w-8 h-8 rounded-md bg-background border border-border flex items-center justify-center active:scale-95 transition-all duration-150",onClick:async()=>{se(!0);try{await g()}finally{se(!1)}},disabled:X,children:e.jsx(Tt,{className:`w-4 h-4 text-foreground ${X?"animate-spin":""}`})}),e.jsx("button",{className:"w-8 h-8 rounded-md bg-primary text-primary-foreground flex items-center justify-center active:scale-95 transition-all duration-150",onClick:()=>u(!0),children:e.jsx(Ar,{className:"w-4 h-4"})})]})]})})]}),!h&&!v&&e.jsx("div",{className:"px-3 md:px-4 py-2 border-b border-border",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(B,{variant:"default",size:"sm",className:"flex-1 h-8 text-xs bg-primary hover:bg-primary/90 transition-all duration-200",onClick:()=>u(!0),title:"创建新项目",children:[e.jsx(Ar,{className:"w-3.5 h-3.5 mr-1.5"}),"新建项目"]}),e.jsx(B,{variant:"outline",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200 group",onClick:async()=>{se(!0);try{await g()}finally{se(!1)}},disabled:X,title:"刷新项目和会话 (Ctrl+R)",children:e.jsx(Tt,{className:`w-3.5 h-3.5 ${X?"animate-spin":""} group-hover:rotate-180 transition-transform duration-300`})})]})}),t.length>0&&!h&&e.jsx("div",{className:"px-3 md:px-4 py-2 border-b border-border",children:e.jsxs("div",{className:"relative",children:[e.jsx(Pt,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ye,{type:"text",placeholder:"搜索项目...",value:ke,onChange:j=>Fe(j.target.value),className:"pl-9 h-9 text-sm bg-muted/50 border-0 focus:bg-background focus:ring-1 focus:ring-primary/20"}),ke&&e.jsx("button",{onClick:()=>Fe(""),className:"absolute right-2 top-1/2 transform -translate-y-1/2 p-1 hover:bg-accent rounded",children:e.jsx(Je,{className:"w-3 h-3 text-muted-foreground"})})]})}),e.jsx(ts,{className:"flex-1 md:px-2 md:py-3 overflow-y-auto overscroll-contain",children:e.jsx("div",{className:"md:space-y-1 pb-safe-area-inset-bottom",children:h?e.jsxs("div",{className:"text-center py-12 md:py-8 px-4",children:[e.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center mx-auto mb-4 md:mb-3",children:e.jsx("div",{className:"w-6 h-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent"})}),e.jsx("h3",{className:"text-base font-medium text-foreground mb-2 md:mb-1",children:"加载项目中..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"正在获取您的 Claude 项目和会话"})]}):t.length===0?e.jsxs("div",{className:"text-center py-12 md:py-8 px-4",children:[e.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center mx-auto mb-4 md:mb-3",children:e.jsx(ct,{className:"w-6 h-6 text-muted-foreground"})}),e.jsx("h3",{className:"text-base font-medium text-foreground mb-2 md:mb-1",children:"未找到项目"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"在项目目录中运行 Claude CLI 以开始使用"})]}):K.length===0?e.jsxs("div",{className:"text-center py-12 md:py-8 px-4",children:[e.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center mx-auto mb-4 md:mb-3",children:e.jsx(Pt,{className:"w-6 h-6 text-muted-foreground"})}),e.jsx("h3",{className:"text-base font-medium text-foreground mb-2 md:mb-1",children:"无匹配的项目"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"尝试调整搜索条件"})]}):K.map(j=>{const V=x.has(j.name),de=s?.name===j.name,ce=De(j.name);return e.jsxs("div",{className:"md:space-y-1",children:[e.jsxs("div",{className:"group md:group",children:[e.jsx("div",{className:"md:hidden",children:e.jsx("div",{className:qe("p-3 mx-3 my-1 rounded-lg bg-card border border-border/50 active:scale-[0.98] transition-all duration-150",de&&"bg-primary/5 border-primary/20",ce&&!de&&"bg-yellow-50/50 dark:bg-yellow-900/5 border-yellow-200/30 dark:border-yellow-800/30"),onClick:()=>{Ce(j.name)},onTouchEnd:xe(()=>Ce(j.name)),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:qe("w-8 h-8 rounded-lg flex items-center justify-center transition-colors",V?"bg-primary/10":"bg-muted"),children:V?e.jsx(It,{className:"w-4 h-4 text-primary"}):e.jsx(ct,{className:"w-4 h-4 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0 flex-1",children:R===j.name?e.jsx("input",{type:"text",value:m,onChange:$=>N($.target.value),className:"w-full px-3 py-2 text-sm border-2 border-primary/40 focus:border-primary rounded-lg bg-background text-foreground shadow-sm focus:shadow-md transition-all duration-200 focus:outline-none",placeholder:"项目名称",autoFocus:!0,autoComplete:"off",onClick:$=>$.stopPropagation(),onKeyDown:$=>{$.key==="Enter"&&pe(j.name),$.key==="Escape"&&H()},style:{fontSize:"16px",WebkitAppearance:"none",borderRadius:"8px"}}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-between min-w-0 flex-1",children:e.jsx("h3",{className:"text-sm font-medium text-foreground truncate",children:j.displayName})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(()=>{const $=T(j).length;return`${j.sessionMeta?.hasMore!==!1&&$>=5?`${$}+`:$} 会话`})()})]})})]}),e.jsx("div",{className:"flex items-center gap-1",children:R===j.name?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"w-8 h-8 rounded-lg bg-green-500 dark:bg-green-600 flex items-center justify-center active:scale-90 transition-all duration-150 shadow-sm active:shadow-none",onClick:$=>{$.stopPropagation(),pe(j.name)},children:e.jsx(hr,{className:"w-4 h-4 text-white"})}),e.jsx("button",{className:"w-8 h-8 rounded-lg bg-gray-500 dark:bg-gray-600 flex items-center justify-center active:scale-90 transition-all duration-150 shadow-sm active:shadow-none",onClick:$=>{$.stopPropagation(),H()},children:e.jsx(Je,{className:"w-4 h-4 text-white"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:qe("w-8 h-8 rounded-lg flex items-center justify-center active:scale-90 transition-all duration-150 border",ce?"bg-yellow-500/10 dark:bg-yellow-900/30 border-yellow-200 dark:border-yellow-800":"bg-gray-500/10 dark:bg-gray-900/30 border-gray-200 dark:border-gray-800"),onClick:$=>{$.stopPropagation(),Pe(j.name)},onTouchEnd:xe(()=>Pe(j.name)),title:ce?"从收藏中移除":"添加到收藏",children:e.jsx(vs,{className:qe("w-4 h-4 transition-colors",ce?"text-yellow-600 dark:text-yellow-400 fill-current":"text-gray-600 dark:text-gray-400")})}),e.jsx("button",{className:"w-8 h-8 rounded-lg bg-red-500/10 dark:bg-red-900/30 flex items-center justify-center active:scale-90 border border-red-200 dark:border-red-800",onClick:$=>{$.stopPropagation(),Se({name:j.name,displayName:j.displayName})},onTouchEnd:xe(()=>Se({name:j.name,displayName:j.displayName})),children:e.jsx(Ve,{className:"w-4 h-4 text-red-600 dark:text-red-400"})}),e.jsx("button",{className:"w-8 h-8 rounded-lg bg-primary/10 dark:bg-primary/20 flex items-center justify-center active:scale-90 border border-primary/20 dark:border-primary/30",onClick:$=>{$.stopPropagation(),b(j)},onTouchEnd:xe(()=>b(j)),children:e.jsx(sr,{className:"w-4 h-4 text-primary"})}),e.jsx("div",{className:"w-6 h-6 rounded-md bg-muted/30 flex items-center justify-center",children:V?e.jsx(Ir,{className:"w-3 h-3 text-muted-foreground"}):e.jsx(Ht,{className:"w-3 h-3 text-muted-foreground"})})]})})]})})}),e.jsxs(B,{variant:"ghost",className:qe("hidden md:flex w-full justify-between p-2 h-auto font-normal hover:bg-accent/50",de&&"bg-accent text-accent-foreground",ce&&!de&&"bg-yellow-50/50 dark:bg-yellow-900/10 hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20"),onClick:()=>{s?.name!==j.name&&ae(j),Ce(j.name)},onTouchEnd:xe(()=>{s?.name!==j.name&&ae(j),Ce(j.name)}),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[V?e.jsx(It,{className:"w-4 h-4 text-primary flex-shrink-0"}):e.jsx(ct,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"min-w-0 flex-1 text-left",children:R===j.name?e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{type:"text",value:m,onChange:$=>N($.target.value),className:"w-full px-2 py-1 text-sm border border-border rounded bg-background text-foreground focus:ring-2 focus:ring-primary/20",placeholder:"项目名称",autoFocus:!0,onKeyDown:$=>{$.key==="Enter"&&pe(j.name),$.key==="Escape"&&H()}}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",title:j.fullPath,children:j.fullPath})]}):e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold truncate text-foreground",title:j.displayName,children:j.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[(()=>{const $=T(j).length;return j.sessionMeta?.hasMore!==!1&&$>=5?`${$}+`:$})(),j.fullPath!==j.displayName&&e.jsxs("span",{className:"ml-1 opacity-60",title:j.fullPath,children:["• ",j.fullPath.length>25?"..."+j.fullPath.slice(-22):j.fullPath]})]})]})})]}),e.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:R===j.name?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-6 h-6 text-green-600 hover:text-green-700 hover:bg-green-50 dark:hover:bg-green-900/20 flex items-center justify-center rounded cursor-pointer transition-colors",onClick:$=>{$.stopPropagation(),pe(j.name)},children:e.jsx(hr,{className:"w-3 h-3"})}),e.jsx("div",{className:"w-6 h-6 text-gray-500 hover:text-gray-700 hover:bg-gray-50 dark:hover:bg-gray-800 flex items-center justify-center rounded cursor-pointer transition-colors",onClick:$=>{$.stopPropagation(),H()},children:e.jsx(Je,{className:"w-3 h-3"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:qe("w-6 h-6 opacity-0 group-hover:opacity-100 transition-all duration-200 flex items-center justify-center rounded cursor-pointer touch:opacity-100",ce?"hover:bg-yellow-50 dark:hover:bg-yellow-900/20 opacity-100":"hover:bg-accent"),onClick:$=>{$.stopPropagation(),Pe(j.name)},title:ce?"从收藏中移除":"添加到收藏",children:e.jsx(vs,{className:qe("w-3 h-3 transition-colors",ce?"text-yellow-600 dark:text-yellow-400 fill-current":"text-muted-foreground")})}),e.jsx("div",{className:"w-6 h-6 opacity-0 group-hover:opacity-100 transition-all duration-200 hover:bg-accent flex items-center justify-center rounded cursor-pointer touch:opacity-100",onClick:$=>{$.stopPropagation(),b(j)},title:"重命名项目 (F2)",children:e.jsx(sr,{className:"w-3 h-3"})}),e.jsx("div",{className:"w-6 h-6 opacity-0 group-hover:opacity-100 transition-all duration-200 hover:bg-red-50 dark:hover:bg-red-900/20 flex items-center justify-center rounded cursor-pointer touch:opacity-100",onClick:$=>{$.stopPropagation(),Se({name:j.name,displayName:j.displayName})},title:"删除项目",children:e.jsx(Ve,{className:"w-3 h-3 text-red-600 dark:text-red-400"})}),V?e.jsx(Ir,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"}):e.jsx(Ht,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"})]})})]})]}),V&&e.jsxs("div",{className:"ml-3 space-y-1 border-l border-border pl-3",children:[Z.has(j.name)?T(j).length===0&&!S[j.name]?e.jsx("div",{className:"py-2 px-3 text-left",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"还没有会话"})}):T(j).map($=>{const $e=new Date($.lastActivity),re=Math.floor((ee-$e)/(1e3*60))<10,ie=$.summary||"新会话",be=$.lastActivity,fe=$.messageCount||0;return e.jsxs("div",{className:"group relative",children:[re&&e.jsx("div",{className:"absolute left-0 top-1/2 transform -translate-y-1/2 -translate-x-1",children:e.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full animate-pulse"})}),e.jsx("div",{className:"md:hidden",children:e.jsx("div",{className:qe("p-2 mx-3 my-0.5 rounded-md bg-card border active:scale-[0.98] transition-all duration-150 relative",a?.id===$.id?"bg-primary/5 border-primary/20":re?"border-green-500/30 bg-green-50/5 dark:bg-green-900/5":"border-border/30"),onClick:()=>{ae(j),Ie($,j.name)},onTouchEnd:xe(()=>{ae(j),Ie($,j.name)}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:qe("w-5 h-5 rounded-md flex items-center justify-center flex-shrink-0",a?.id===$.id?"bg-primary/10":"bg-muted/50"),children:e.jsx(mt,{className:"w-3 h-3"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-medium truncate text-foreground",children:ie}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(_r,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Ns(be,ee)}),fe>0&&e.jsx(Ge,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:fe}),e.jsx("span",{className:"ml-1 opacity-70",children:e.jsx(mt,{className:"w-3 h-3"})})]})]}),e.jsx("button",{className:"w-5 h-5 rounded-md bg-red-50 dark:bg-red-900/20 flex items-center justify-center active:scale-95 transition-transform opacity-70 ml-1",onClick:je=>{je.stopPropagation(),Ne(j.name,$.id)},onTouchEnd:xe(()=>Ne(j.name,$.id)),children:e.jsx(Ve,{className:"w-2.5 h-2.5 text-red-600 dark:text-red-400"})})]})})}),e.jsxs("div",{className:"hidden md:block",children:[e.jsx(B,{variant:"ghost",className:qe("w-full justify-start p-2 h-auto font-normal text-left hover:bg-accent/50 transition-colors duration-200",a?.id===$.id&&"bg-accent text-accent-foreground"),onClick:()=>Ie($,j.name),onTouchEnd:xe(()=>Ie($,j.name)),children:e.jsxs("div",{className:"flex items-start gap-2 min-w-0 w-full",children:[e.jsx(mt,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-medium truncate text-foreground",children:ie}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(_r,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Ns(be,ee)}),fe>0&&e.jsx(Ge,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:fe}),e.jsx("span",{className:"ml-1 opacity-70",children:e.jsx(mt,{className:"w-3 h-3"})})]})]})]})}),e.jsx("div",{className:"absolute right-2 top-1/2 transform -translate-y-1/2 flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-all duration-200",children:ve===$.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:z,onChange:je=>ue(je.target.value),onKeyDown:je=>{je.stopPropagation(),je.key==="Enter"?updateSessionSummary(j.name,$.id,z):je.key==="Escape"&&(oe(null),ue(""))},onClick:je=>je.stopPropagation(),className:"w-32 px-2 py-1 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary",autoFocus:!0}),e.jsx("button",{className:"w-6 h-6 bg-green-50 hover:bg-green-100 dark:bg-green-900/20 dark:hover:bg-green-900/40 rounded flex items-center justify-center",onClick:je=>{je.stopPropagation(),updateSessionSummary(j.name,$.id,z)},title:"Save",children:e.jsx(hr,{className:"w-3 h-3 text-green-600 dark:text-green-400"})}),e.jsx("button",{className:"w-6 h-6 bg-gray-50 hover:bg-gray-100 dark:bg-gray-900/20 dark:hover:bg-gray-900/40 rounded flex items-center justify-center",onClick:je=>{je.stopPropagation(),oe(null),ue("")},title:"Cancel",children:e.jsx(Je,{className:"w-3 h-3 text-gray-600 dark:text-gray-400"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"w-6 h-6 bg-gray-50 hover:bg-gray-100 dark:bg-gray-900/20 dark:hover:bg-gray-900/40 rounded flex items-center justify-center",onClick:je=>{je.stopPropagation(),oe($.id),ue($.summary||"新会话")},title:"手动编辑会话名称",children:e.jsx(sn,{className:"w-3 h-3 text-gray-600 dark:text-gray-400"})}),e.jsx("button",{className:"w-6 h-6 bg-red-50 hover:bg-red-100 dark:bg-red-900/20 dark:hover:bg-red-900/40 rounded flex items-center justify-center",onClick:je=>{je.stopPropagation(),Ne(j.name,$.id)},title:"永久删除此会话",children:e.jsx(Ve,{className:"w-3 h-3 text-red-600 dark:text-red-400"})})]})})]})]},$.id)}):Array.from({length:3}).map(($,$e)=>e.jsx("div",{className:"p-2 rounded-md",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"w-3 h-3 bg-muted rounded-full animate-pulse mt-0.5"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"h-3 bg-muted rounded animate-pulse",style:{width:`${60+$e*15}%`}}),e.jsx("div",{className:"h-2 bg-muted rounded animate-pulse w-1/2"})]})]})},$e)),T(j).length>0&&j.sessionMeta?.hasMore!==!1&&e.jsx(B,{variant:"ghost",size:"sm",className:"w-full justify-center gap-2 mt-2 text-muted-foreground",onClick:()=>at(j),disabled:S[j.name],children:S[j.name]?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-3 h-3 animate-spin rounded-full border border-muted-foreground border-t-transparent"}),"加载中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ir,{className:"w-3 h-3"}),"显示更多会话"]})}),e.jsx("div",{className:"md:hidden px-3 pb-2",children:e.jsxs("button",{className:"w-full h-8 bg-primary hover:bg-primary/90 text-primary-foreground rounded-md flex items-center justify-center gap-2 font-medium text-xs active:scale-[0.98] transition-all duration-150",onClick:()=>{ae(j),l(j)},children:[e.jsx(st,{className:"w-3 h-3"}),"新会话"]})}),e.jsxs(B,{variant:"default",size:"sm",className:"hidden md:flex w-full justify-start gap-2 mt-1 h-8 text-xs font-medium bg-primary hover:bg-primary/90 text-primary-foreground transition-colors",onClick:()=>l(j),children:[e.jsx(st,{className:"w-3 h-3"}),"新会话"]})]})]},j.name)})})}),e.jsxs("div",{className:"md:p-2 md:border-t md:border-border flex-shrink-0",children:[e.jsx("div",{className:"md:hidden p-4 pb-20 border-t border-border/50",children:e.jsxs("button",{className:"w-full h-14 bg-muted/50 hover:bg-muted/70 rounded-2xl flex items-center justify-start gap-4 px-4 active:scale-[0.98] transition-all duration-150",onClick:p,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx(wt,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"设置"})]})}),e.jsxs(B,{variant:"ghost",className:"hidden md:flex w-full justify-start gap-2 p-2 h-auto font-normal text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-200",onClick:p,children:[e.jsx(wt,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"设置"})]})]})]})]})}const Bn={'code[class*="language-"]':{background:"hsl(220, 13%, 18%)",color:"hsl(220, 14%, 71%)",textShadow:"0 1px rgba(0, 0, 0, 0.3)",fontFamily:'"Fira Code", "Fira Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace',direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"2",OTabSize:"2",tabSize:"2",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"},'pre[class*="language-"]':{background:"hsl(220, 13%, 18%)",color:"hsl(220, 14%, 71%)",textShadow:"0 1px rgba(0, 0, 0, 0.3)",fontFamily:'"Fira Code", "Fira Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace',direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"2",OTabSize:"2",tabSize:"2",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",padding:"1em",margin:"0.5em 0",overflow:"auto",borderRadius:"0.3em"},'code[class*="language-"]::-moz-selection':{background:"hsl(220, 13%, 28%)",color:"inherit",textShadow:"none"},'code[class*="language-"] *::-moz-selection':{background:"hsl(220, 13%, 28%)",color:"inherit",textShadow:"none"},'pre[class*="language-"] *::-moz-selection':{background:"hsl(220, 13%, 28%)",color:"inherit",textShadow:"none"},'code[class*="language-"]::selection':{background:"hsl(220, 13%, 28%)",color:"inherit",textShadow:"none"},'code[class*="language-"] *::selection':{background:"hsl(220, 13%, 28%)",color:"inherit",textShadow:"none"},'pre[class*="language-"] *::selection':{background:"hsl(220, 13%, 28%)",color:"inherit",textShadow:"none"},':not(pre) > code[class*="language-"]':{padding:"0.2em 0.3em",borderRadius:"0.3em",whiteSpace:"normal"},comment:{color:"hsl(220, 10%, 40%)",fontStyle:"italic"},prolog:{color:"hsl(220, 10%, 40%)"},cdata:{color:"hsl(220, 10%, 40%)"},doctype:{color:"hsl(220, 14%, 71%)"},punctuation:{color:"hsl(220, 14%, 71%)"},entity:{color:"hsl(220, 14%, 71%)",cursor:"help"},"attr-name":{color:"hsl(29, 54%, 61%)"},"class-name":{color:"hsl(29, 54%, 61%)"},boolean:{color:"hsl(29, 54%, 61%)"},constant:{color:"hsl(29, 54%, 61%)"},number:{color:"hsl(29, 54%, 61%)"},atrule:{color:"hsl(29, 54%, 61%)"},keyword:{color:"hsl(286, 60%, 67%)"},property:{color:"hsl(355, 65%, 65%)"},tag:{color:"hsl(355, 65%, 65%)"},symbol:{color:"hsl(355, 65%, 65%)"},deleted:{color:"hsl(355, 65%, 65%)"},important:{color:"hsl(355, 65%, 65%)"},selector:{color:"hsl(95, 38%, 62%)"},string:{color:"hsl(95, 38%, 62%)"},char:{color:"hsl(95, 38%, 62%)"},builtin:{color:"hsl(95, 38%, 62%)"},inserted:{color:"hsl(95, 38%, 62%)"},regex:{color:"hsl(95, 38%, 62%)"},"attr-value":{color:"hsl(95, 38%, 62%)"},"attr-value > .token.punctuation":{color:"hsl(95, 38%, 62%)"},variable:{color:"hsl(207, 82%, 66%)"},operator:{color:"hsl(207, 82%, 66%)"},function:{color:"hsl(207, 82%, 66%)"},url:{color:"hsl(187, 47%, 55%)"},"attr-value > .token.punctuation.attr-equals":{color:"hsl(220, 14%, 71%)"},"special-attr > .token.attr-value > .token.value.css":{color:"hsl(220, 14%, 71%)"},".language-css .token.selector":{color:"hsl(355, 65%, 65%)"},".language-css .token.property":{color:"hsl(220, 14%, 71%)"},".language-css .token.function":{color:"hsl(187, 47%, 55%)"},".language-css .token.url > .token.function":{color:"hsl(187, 47%, 55%)"},".language-css .token.url > .token.string.url":{color:"hsl(95, 38%, 62%)"},".language-css .token.important":{color:"hsl(286, 60%, 67%)"},".language-css .token.atrule .token.rule":{color:"hsl(286, 60%, 67%)"},".language-javascript .token.operator":{color:"hsl(286, 60%, 67%)"},".language-javascript .token.template-string > .token.interpolation > .token.interpolation-punctuation.punctuation":{color:"hsl(5, 48%, 51%)"},".language-json .token.operator":{color:"hsl(220, 14%, 71%)"},".language-json .token.null.keyword":{color:"hsl(29, 54%, 61%)"},".language-markdown .token.url":{color:"hsl(220, 14%, 71%)"},".language-markdown .token.url > .token.operator":{color:"hsl(220, 14%, 71%)"},".language-markdown .token.url-reference.url > .token.string":{color:"hsl(220, 14%, 71%)"},".language-markdown .token.url > .token.content":{color:"hsl(207, 82%, 66%)"},".language-markdown .token.url > .token.url":{color:"hsl(187, 47%, 55%)"},".language-markdown .token.url-reference.url":{color:"hsl(187, 47%, 55%)"},".language-markdown .token.blockquote.punctuation":{color:"hsl(220, 10%, 40%)",fontStyle:"italic"},".language-markdown .token.hr.punctuation":{color:"hsl(220, 10%, 40%)",fontStyle:"italic"},".language-markdown .token.code-snippet":{color:"hsl(95, 38%, 62%)"},".language-markdown .token.bold .token.content":{color:"hsl(29, 54%, 61%)"},".language-markdown .token.italic .token.content":{color:"hsl(286, 60%, 67%)"},".language-markdown .token.strike .token.content":{color:"hsl(355, 65%, 65%)"},".language-markdown .token.strike .token.punctuation":{color:"hsl(355, 65%, 65%)"},".language-markdown .token.list.punctuation":{color:"hsl(355, 65%, 65%)"},".language-markdown .token.title.important > .token.punctuation":{color:"hsl(355, 65%, 65%)"},bold:{fontWeight:"bold"},italic:{fontStyle:"italic"},namespace:{Opacity:"0.8"},"token.tab:not(:empty):before":{color:"hsla(220, 14%, 71%, 0.15)",textShadow:"none"},"token.cr:before":{color:"hsla(220, 14%, 71%, 0.15)",textShadow:"none"},"token.lf:before":{color:"hsla(220, 14%, 71%, 0.15)",textShadow:"none"},"token.space:before":{color:"hsla(220, 14%, 71%, 0.15)",textShadow:"none"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item":{marginRight:"0.4em"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > button":{background:"hsl(220, 13%, 26%)",color:"hsl(220, 9%, 55%)",padding:"0.1em 0.4em",borderRadius:"0.3em"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > a":{background:"hsl(220, 13%, 26%)",color:"hsl(220, 9%, 55%)",padding:"0.1em 0.4em",borderRadius:"0.3em"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > span":{background:"hsl(220, 13%, 26%)",color:"hsl(220, 9%, 55%)",padding:"0.1em 0.4em",borderRadius:"0.3em"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > button:hover":{background:"hsl(220, 13%, 28%)",color:"hsl(220, 14%, 71%)"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > button:focus":{background:"hsl(220, 13%, 28%)",color:"hsl(220, 14%, 71%)"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > a:hover":{background:"hsl(220, 13%, 28%)",color:"hsl(220, 14%, 71%)"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > a:focus":{background:"hsl(220, 13%, 28%)",color:"hsl(220, 14%, 71%)"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > span:hover":{background:"hsl(220, 13%, 28%)",color:"hsl(220, 14%, 71%)"},"div.code-toolbar > .toolbar.toolbar > .toolbar-item > span:focus":{background:"hsl(220, 13%, 28%)",color:"hsl(220, 14%, 71%)"},".line-highlight.line-highlight":{background:"hsla(220, 100%, 80%, 0.04)"},".line-highlight.line-highlight:before":{background:"hsl(220, 13%, 26%)",color:"hsl(220, 14%, 71%)",padding:"0.1em 0.6em",borderRadius:"0.3em",boxShadow:"0 2px 0 0 rgba(0, 0, 0, 0.2)"},".line-highlight.line-highlight[data-end]:after":{background:"hsl(220, 13%, 26%)",color:"hsl(220, 14%, 71%)",padding:"0.1em 0.6em",borderRadius:"0.3em",boxShadow:"0 2px 0 0 rgba(0, 0, 0, 0.2)"},"pre[id].linkable-line-numbers.linkable-line-numbers span.line-numbers-rows > span:hover:before":{backgroundColor:"hsla(220, 100%, 80%, 0.04)"},".line-numbers.line-numbers .line-numbers-rows":{borderRightColor:"hsla(220, 14%, 71%, 0.15)"},".command-line .command-line-prompt":{borderRightColor:"hsla(220, 14%, 71%, 0.15)"},".line-numbers .line-numbers-rows > span:before":{color:"hsl(220, 14%, 45%)"},".command-line .command-line-prompt > span:before":{color:"hsl(220, 14%, 45%)"},".rainbow-braces .token.token.punctuation.brace-level-1":{color:"hsl(355, 65%, 65%)"},".rainbow-braces .token.token.punctuation.brace-level-5":{color:"hsl(355, 65%, 65%)"},".rainbow-braces .token.token.punctuation.brace-level-9":{color:"hsl(355, 65%, 65%)"},".rainbow-braces .token.token.punctuation.brace-level-2":{color:"hsl(95, 38%, 62%)"},".rainbow-braces .token.token.punctuation.brace-level-6":{color:"hsl(95, 38%, 62%)"},".rainbow-braces .token.token.punctuation.brace-level-10":{color:"hsl(95, 38%, 62%)"},".rainbow-braces .token.token.punctuation.brace-level-3":{color:"hsl(207, 82%, 66%)"},".rainbow-braces .token.token.punctuation.brace-level-7":{color:"hsl(207, 82%, 66%)"},".rainbow-braces .token.token.punctuation.brace-level-11":{color:"hsl(207, 82%, 66%)"},".rainbow-braces .token.token.punctuation.brace-level-4":{color:"hsl(286, 60%, 67%)"},".rainbow-braces .token.token.punctuation.brace-level-8":{color:"hsl(286, 60%, 67%)"},".rainbow-braces .token.token.punctuation.brace-level-12":{color:"hsl(286, 60%, 67%)"},"pre.diff-highlight > code .token.token.deleted:not(.prefix)":{backgroundColor:"hsla(353, 100%, 66%, 0.15)"},"pre > code.diff-highlight .token.token.deleted:not(.prefix)":{backgroundColor:"hsla(353, 100%, 66%, 0.15)"},"pre.diff-highlight > code .token.token.deleted:not(.prefix)::-moz-selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre.diff-highlight > code .token.token.deleted:not(.prefix) *::-moz-selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre > code.diff-highlight .token.token.deleted:not(.prefix)::-moz-selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre > code.diff-highlight .token.token.deleted:not(.prefix) *::-moz-selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre.diff-highlight > code .token.token.deleted:not(.prefix)::selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre.diff-highlight > code .token.token.deleted:not(.prefix) *::selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre > code.diff-highlight .token.token.deleted:not(.prefix)::selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre > code.diff-highlight .token.token.deleted:not(.prefix) *::selection":{backgroundColor:"hsla(353, 95%, 66%, 0.25)"},"pre.diff-highlight > code .token.token.inserted:not(.prefix)":{backgroundColor:"hsla(137, 100%, 55%, 0.15)"},"pre > code.diff-highlight .token.token.inserted:not(.prefix)":{backgroundColor:"hsla(137, 100%, 55%, 0.15)"},"pre.diff-highlight > code .token.token.inserted:not(.prefix)::-moz-selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},"pre.diff-highlight > code .token.token.inserted:not(.prefix) *::-moz-selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},"pre > code.diff-highlight .token.token.inserted:not(.prefix)::-moz-selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},"pre > code.diff-highlight .token.token.inserted:not(.prefix) *::-moz-selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},"pre.diff-highlight > code .token.token.inserted:not(.prefix)::selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},"pre.diff-highlight > code .token.token.inserted:not(.prefix) *::selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},"pre > code.diff-highlight .token.token.inserted:not(.prefix)::selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},"pre > code.diff-highlight .token.token.inserted:not(.prefix) *::selection":{backgroundColor:"hsla(135, 73%, 55%, 0.25)"},".prism-previewer.prism-previewer:before":{borderColor:"hsl(224, 13%, 17%)"},".prism-previewer-gradient.prism-previewer-gradient div":{borderColor:"hsl(224, 13%, 17%)",borderRadius:"0.3em"},".prism-previewer-color.prism-previewer-color:before":{borderRadius:"0.3em"},".prism-previewer-easing.prism-previewer-easing:before":{borderRadius:"0.3em"},".prism-previewer.prism-previewer:after":{borderTopColor:"hsl(224, 13%, 17%)"},".prism-previewer-flipped.prism-previewer-flipped.after":{borderBottomColor:"hsl(224, 13%, 17%)"},".prism-previewer-angle.prism-previewer-angle:before":{background:"hsl(219, 13%, 22%)"},".prism-previewer-time.prism-previewer-time:before":{background:"hsl(219, 13%, 22%)"},".prism-previewer-easing.prism-previewer-easing":{background:"hsl(219, 13%, 22%)"},".prism-previewer-angle.prism-previewer-angle circle":{stroke:"hsl(220, 14%, 71%)",strokeOpacity:"1"},".prism-previewer-time.prism-previewer-time circle":{stroke:"hsl(220, 14%, 71%)",strokeOpacity:"1"},".prism-previewer-easing.prism-previewer-easing circle":{stroke:"hsl(220, 14%, 71%)",fill:"transparent"},".prism-previewer-easing.prism-previewer-easing path":{stroke:"hsl(220, 14%, 71%)"},".prism-previewer-easing.prism-previewer-easing line":{stroke:"hsl(220, 14%, 71%)"}};var Dr={exports:{}},Tr,Cs;function Un(){if(Cs)return Tr;Cs=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Tr=t,Tr}var Pr,Es;function Hn(){if(Es)return Pr;Es=1;var t=Un();function s(){}function a(){}return a.resetWarningCache=s,Pr=function(){function o(i,d,h,g,p,w){if(w!==t){var v=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw v.name="Invariant Violation",v}}o.isRequired=o;function n(){return o}var l={array:o,bigint:o,bool:o,func:o,number:o,object:o,string:o,symbol:o,any:o,arrayOf:n,element:o,elementType:o,instanceOf:n,node:o,objectOf:n,oneOf:n,oneOfType:n,shape:n,exact:n,checkPropTypes:a,resetWarningCache:s};return l.PropTypes=l,l},Pr}var Ms;function qn(){return Ms||(Ms=1,Dr.exports=Hn()()),Dr.exports}var Jn=qn();const Ae=Zr(Jn);function Rt(t,s,a,o){function n(l){return l instanceof a?l:new a(function(i){i(l)})}return new(a||(a=Promise))(function(l,i){function d(p){try{g(o.next(p))}catch(w){i(w)}}function h(p){try{g(o.throw(p))}catch(w){i(w)}}function g(p){p.done?l(p.value):n(p.value).then(d,h)}g((o=o.apply(t,s||[])).next())})}const Kn=new Map([["1km","application/vnd.1000minds.decision-model+xml"],["3dml","text/vnd.in3d.3dml"],["3ds","image/x-3ds"],["3g2","video/3gpp2"],["3gp","video/3gp"],["3gpp","video/3gpp"],["3mf","model/3mf"],["7z","application/x-7z-compressed"],["7zip","application/x-7z-compressed"],["123","application/vnd.lotus-1-2-3"],["aab","application/x-authorware-bin"],["aac","audio/x-acc"],["aam","application/x-authorware-map"],["aas","application/x-authorware-seg"],["abw","application/x-abiword"],["ac","application/vnd.nokia.n-gage.ac+xml"],["ac3","audio/ac3"],["acc","application/vnd.americandynamics.acc"],["ace","application/x-ace-compressed"],["acu","application/vnd.acucobol"],["acutc","application/vnd.acucorp"],["adp","audio/adpcm"],["aep","application/vnd.audiograph"],["afm","application/x-font-type1"],["afp","application/vnd.ibm.modcap"],["ahead","application/vnd.ahead.space"],["ai","application/pdf"],["aif","audio/x-aiff"],["aifc","audio/x-aiff"],["aiff","audio/x-aiff"],["air","application/vnd.adobe.air-application-installer-package+zip"],["ait","application/vnd.dvb.ait"],["ami","application/vnd.amiga.ami"],["amr","audio/amr"],["apk","application/vnd.android.package-archive"],["apng","image/apng"],["appcache","text/cache-manifest"],["application","application/x-ms-application"],["apr","application/vnd.lotus-approach"],["arc","application/x-freearc"],["arj","application/x-arj"],["asc","application/pgp-signature"],["asf","video/x-ms-asf"],["asm","text/x-asm"],["aso","application/vnd.accpac.simply.aso"],["asx","video/x-ms-asf"],["atc","application/vnd.acucorp"],["atom","application/atom+xml"],["atomcat","application/atomcat+xml"],["atomdeleted","application/atomdeleted+xml"],["atomsvc","application/atomsvc+xml"],["atx","application/vnd.antix.game-component"],["au","audio/x-au"],["avi","video/x-msvideo"],["avif","image/avif"],["aw","application/applixware"],["azf","application/vnd.airzip.filesecure.azf"],["azs","application/vnd.airzip.filesecure.azs"],["azv","image/vnd.airzip.accelerator.azv"],["azw","application/vnd.amazon.ebook"],["b16","image/vnd.pco.b16"],["bat","application/x-msdownload"],["bcpio","application/x-bcpio"],["bdf","application/x-font-bdf"],["bdm","application/vnd.syncml.dm+wbxml"],["bdoc","application/x-bdoc"],["bed","application/vnd.realvnc.bed"],["bh2","application/vnd.fujitsu.oasysprs"],["bin","application/octet-stream"],["blb","application/x-blorb"],["blorb","application/x-blorb"],["bmi","application/vnd.bmi"],["bmml","application/vnd.balsamiq.bmml+xml"],["bmp","image/bmp"],["book","application/vnd.framemaker"],["box","application/vnd.previewsystems.box"],["boz","application/x-bzip2"],["bpk","application/octet-stream"],["bpmn","application/octet-stream"],["bsp","model/vnd.valve.source.compiled-map"],["btif","image/prs.btif"],["buffer","application/octet-stream"],["bz","application/x-bzip"],["bz2","application/x-bzip2"],["c","text/x-c"],["c4d","application/vnd.clonk.c4group"],["c4f","application/vnd.clonk.c4group"],["c4g","application/vnd.clonk.c4group"],["c4p","application/vnd.clonk.c4group"],["c4u","application/vnd.clonk.c4group"],["c11amc","application/vnd.cluetrust.cartomobile-config"],["c11amz","application/vnd.cluetrust.cartomobile-config-pkg"],["cab","application/vnd.ms-cab-compressed"],["caf","audio/x-caf"],["cap","application/vnd.tcpdump.pcap"],["car","application/vnd.curl.car"],["cat","application/vnd.ms-pki.seccat"],["cb7","application/x-cbr"],["cba","application/x-cbr"],["cbr","application/x-cbr"],["cbt","application/x-cbr"],["cbz","application/x-cbr"],["cc","text/x-c"],["cco","application/x-cocoa"],["cct","application/x-director"],["ccxml","application/ccxml+xml"],["cdbcmsg","application/vnd.contact.cmsg"],["cda","application/x-cdf"],["cdf","application/x-netcdf"],["cdfx","application/cdfx+xml"],["cdkey","application/vnd.mediastation.cdkey"],["cdmia","application/cdmi-capability"],["cdmic","application/cdmi-container"],["cdmid","application/cdmi-domain"],["cdmio","application/cdmi-object"],["cdmiq","application/cdmi-queue"],["cdr","application/cdr"],["cdx","chemical/x-cdx"],["cdxml","application/vnd.chemdraw+xml"],["cdy","application/vnd.cinderella"],["cer","application/pkix-cert"],["cfs","application/x-cfs-compressed"],["cgm","image/cgm"],["chat","application/x-chat"],["chm","application/vnd.ms-htmlhelp"],["chrt","application/vnd.kde.kchart"],["cif","chemical/x-cif"],["cii","application/vnd.anser-web-certificate-issue-initiation"],["cil","application/vnd.ms-artgalry"],["cjs","application/node"],["cla","application/vnd.claymore"],["class","application/octet-stream"],["clkk","application/vnd.crick.clicker.keyboard"],["clkp","application/vnd.crick.clicker.palette"],["clkt","application/vnd.crick.clicker.template"],["clkw","application/vnd.crick.clicker.wordbank"],["clkx","application/vnd.crick.clicker"],["clp","application/x-msclip"],["cmc","application/vnd.cosmocaller"],["cmdf","chemical/x-cmdf"],["cml","chemical/x-cml"],["cmp","application/vnd.yellowriver-custom-menu"],["cmx","image/x-cmx"],["cod","application/vnd.rim.cod"],["coffee","text/coffeescript"],["com","application/x-msdownload"],["conf","text/plain"],["cpio","application/x-cpio"],["cpp","text/x-c"],["cpt","application/mac-compactpro"],["crd","application/x-mscardfile"],["crl","application/pkix-crl"],["crt","application/x-x509-ca-cert"],["crx","application/x-chrome-extension"],["cryptonote","application/vnd.rig.cryptonote"],["csh","application/x-csh"],["csl","application/vnd.citationstyles.style+xml"],["csml","chemical/x-csml"],["csp","application/vnd.commonspace"],["csr","application/octet-stream"],["css","text/css"],["cst","application/x-director"],["csv","text/csv"],["cu","application/cu-seeme"],["curl","text/vnd.curl"],["cww","application/prs.cww"],["cxt","application/x-director"],["cxx","text/x-c"],["dae","model/vnd.collada+xml"],["daf","application/vnd.mobius.daf"],["dart","application/vnd.dart"],["dataless","application/vnd.fdsn.seed"],["davmount","application/davmount+xml"],["dbf","application/vnd.dbf"],["dbk","application/docbook+xml"],["dcr","application/x-director"],["dcurl","text/vnd.curl.dcurl"],["dd2","application/vnd.oma.dd2+xml"],["ddd","application/vnd.fujixerox.ddd"],["ddf","application/vnd.syncml.dmddf+xml"],["dds","image/vnd.ms-dds"],["deb","application/x-debian-package"],["def","text/plain"],["deploy","application/octet-stream"],["der","application/x-x509-ca-cert"],["dfac","application/vnd.dreamfactory"],["dgc","application/x-dgc-compressed"],["dic","text/x-c"],["dir","application/x-director"],["dis","application/vnd.mobius.dis"],["disposition-notification","message/disposition-notification"],["dist","application/octet-stream"],["distz","application/octet-stream"],["djv","image/vnd.djvu"],["djvu","image/vnd.djvu"],["dll","application/octet-stream"],["dmg","application/x-apple-diskimage"],["dmn","application/octet-stream"],["dmp","application/vnd.tcpdump.pcap"],["dms","application/octet-stream"],["dna","application/vnd.dna"],["doc","application/msword"],["docm","application/vnd.ms-word.template.macroEnabled.12"],["docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],["dot","application/msword"],["dotm","application/vnd.ms-word.template.macroEnabled.12"],["dotx","application/vnd.openxmlformats-officedocument.wordprocessingml.template"],["dp","application/vnd.osgi.dp"],["dpg","application/vnd.dpgraph"],["dra","audio/vnd.dra"],["drle","image/dicom-rle"],["dsc","text/prs.lines.tag"],["dssc","application/dssc+der"],["dtb","application/x-dtbook+xml"],["dtd","application/xml-dtd"],["dts","audio/vnd.dts"],["dtshd","audio/vnd.dts.hd"],["dump","application/octet-stream"],["dvb","video/vnd.dvb.file"],["dvi","application/x-dvi"],["dwd","application/atsc-dwd+xml"],["dwf","model/vnd.dwf"],["dwg","image/vnd.dwg"],["dxf","image/vnd.dxf"],["dxp","application/vnd.spotfire.dxp"],["dxr","application/x-director"],["ear","application/java-archive"],["ecelp4800","audio/vnd.nuera.ecelp4800"],["ecelp7470","audio/vnd.nuera.ecelp7470"],["ecelp9600","audio/vnd.nuera.ecelp9600"],["ecma","application/ecmascript"],["edm","application/vnd.novadigm.edm"],["edx","application/vnd.novadigm.edx"],["efif","application/vnd.picsel"],["ei6","application/vnd.pg.osasli"],["elc","application/octet-stream"],["emf","image/emf"],["eml","message/rfc822"],["emma","application/emma+xml"],["emotionml","application/emotionml+xml"],["emz","application/x-msmetafile"],["eol","audio/vnd.digital-winds"],["eot","application/vnd.ms-fontobject"],["eps","application/postscript"],["epub","application/epub+zip"],["es","application/ecmascript"],["es3","application/vnd.eszigno3+xml"],["esa","application/vnd.osgi.subsystem"],["esf","application/vnd.epson.esf"],["et3","application/vnd.eszigno3+xml"],["etx","text/x-setext"],["eva","application/x-eva"],["evy","application/x-envoy"],["exe","application/octet-stream"],["exi","application/exi"],["exp","application/express"],["exr","image/aces"],["ext","application/vnd.novadigm.ext"],["ez","application/andrew-inset"],["ez2","application/vnd.ezpix-album"],["ez3","application/vnd.ezpix-package"],["f","text/x-fortran"],["f4v","video/mp4"],["f77","text/x-fortran"],["f90","text/x-fortran"],["fbs","image/vnd.fastbidsheet"],["fcdt","application/vnd.adobe.formscentral.fcdt"],["fcs","application/vnd.isac.fcs"],["fdf","application/vnd.fdf"],["fdt","application/fdt+xml"],["fe_launch","application/vnd.denovo.fcselayout-link"],["fg5","application/vnd.fujitsu.oasysgp"],["fgd","application/x-director"],["fh","image/x-freehand"],["fh4","image/x-freehand"],["fh5","image/x-freehand"],["fh7","image/x-freehand"],["fhc","image/x-freehand"],["fig","application/x-xfig"],["fits","image/fits"],["flac","audio/x-flac"],["fli","video/x-fli"],["flo","application/vnd.micrografx.flo"],["flv","video/x-flv"],["flw","application/vnd.kde.kivio"],["flx","text/vnd.fmi.flexstor"],["fly","text/vnd.fly"],["fm","application/vnd.framemaker"],["fnc","application/vnd.frogans.fnc"],["fo","application/vnd.software602.filler.form+xml"],["for","text/x-fortran"],["fpx","image/vnd.fpx"],["frame","application/vnd.framemaker"],["fsc","application/vnd.fsc.weblaunch"],["fst","image/vnd.fst"],["ftc","application/vnd.fluxtime.clip"],["fti","application/vnd.anser-web-funds-transfer-initiation"],["fvt","video/vnd.fvt"],["fxp","application/vnd.adobe.fxp"],["fxpl","application/vnd.adobe.fxp"],["fzs","application/vnd.fuzzysheet"],["g2w","application/vnd.geoplan"],["g3","image/g3fax"],["g3w","application/vnd.geospace"],["gac","application/vnd.groove-account"],["gam","application/x-tads"],["gbr","application/rpki-ghostbusters"],["gca","application/x-gca-compressed"],["gdl","model/vnd.gdl"],["gdoc","application/vnd.google-apps.document"],["geo","application/vnd.dynageo"],["geojson","application/geo+json"],["gex","application/vnd.geometry-explorer"],["ggb","application/vnd.geogebra.file"],["ggt","application/vnd.geogebra.tool"],["ghf","application/vnd.groove-help"],["gif","image/gif"],["gim","application/vnd.groove-identity-message"],["glb","model/gltf-binary"],["gltf","model/gltf+json"],["gml","application/gml+xml"],["gmx","application/vnd.gmx"],["gnumeric","application/x-gnumeric"],["gpg","application/gpg-keys"],["gph","application/vnd.flographit"],["gpx","application/gpx+xml"],["gqf","application/vnd.grafeq"],["gqs","application/vnd.grafeq"],["gram","application/srgs"],["gramps","application/x-gramps-xml"],["gre","application/vnd.geometry-explorer"],["grv","application/vnd.groove-injector"],["grxml","application/srgs+xml"],["gsf","application/x-font-ghostscript"],["gsheet","application/vnd.google-apps.spreadsheet"],["gslides","application/vnd.google-apps.presentation"],["gtar","application/x-gtar"],["gtm","application/vnd.groove-tool-message"],["gtw","model/vnd.gtw"],["gv","text/vnd.graphviz"],["gxf","application/gxf"],["gxt","application/vnd.geonext"],["gz","application/gzip"],["gzip","application/gzip"],["h","text/x-c"],["h261","video/h261"],["h263","video/h263"],["h264","video/h264"],["hal","application/vnd.hal+xml"],["hbci","application/vnd.hbci"],["hbs","text/x-handlebars-template"],["hdd","application/x-virtualbox-hdd"],["hdf","application/x-hdf"],["heic","image/heic"],["heics","image/heic-sequence"],["heif","image/heif"],["heifs","image/heif-sequence"],["hej2","image/hej2k"],["held","application/atsc-held+xml"],["hh","text/x-c"],["hjson","application/hjson"],["hlp","application/winhlp"],["hpgl","application/vnd.hp-hpgl"],["hpid","application/vnd.hp-hpid"],["hps","application/vnd.hp-hps"],["hqx","application/mac-binhex40"],["hsj2","image/hsj2"],["htc","text/x-component"],["htke","application/vnd.kenameaapp"],["htm","text/html"],["html","text/html"],["hvd","application/vnd.yamaha.hv-dic"],["hvp","application/vnd.yamaha.hv-voice"],["hvs","application/vnd.yamaha.hv-script"],["i2g","application/vnd.intergeo"],["icc","application/vnd.iccprofile"],["ice","x-conference/x-cooltalk"],["icm","application/vnd.iccprofile"],["ico","image/x-icon"],["ics","text/calendar"],["ief","image/ief"],["ifb","text/calendar"],["ifm","application/vnd.shana.informed.formdata"],["iges","model/iges"],["igl","application/vnd.igloader"],["igm","application/vnd.insors.igm"],["igs","model/iges"],["igx","application/vnd.micrografx.igx"],["iif","application/vnd.shana.informed.interchange"],["img","application/octet-stream"],["imp","application/vnd.accpac.simply.imp"],["ims","application/vnd.ms-ims"],["in","text/plain"],["ini","text/plain"],["ink","application/inkml+xml"],["inkml","application/inkml+xml"],["install","application/x-install-instructions"],["iota","application/vnd.astraea-software.iota"],["ipfix","application/ipfix"],["ipk","application/vnd.shana.informed.package"],["irm","application/vnd.ibm.rights-management"],["irp","application/vnd.irepository.package+xml"],["iso","application/x-iso9660-image"],["itp","application/vnd.shana.informed.formtemplate"],["its","application/its+xml"],["ivp","application/vnd.immervision-ivp"],["ivu","application/vnd.immervision-ivu"],["jad","text/vnd.sun.j2me.app-descriptor"],["jade","text/jade"],["jam","application/vnd.jam"],["jar","application/java-archive"],["jardiff","application/x-java-archive-diff"],["java","text/x-java-source"],["jhc","image/jphc"],["jisp","application/vnd.jisp"],["jls","image/jls"],["jlt","application/vnd.hp-jlyt"],["jng","image/x-jng"],["jnlp","application/x-java-jnlp-file"],["joda","application/vnd.joost.joda-archive"],["jp2","image/jp2"],["jpe","image/jpeg"],["jpeg","image/jpeg"],["jpf","image/jpx"],["jpg","image/jpeg"],["jpg2","image/jp2"],["jpgm","video/jpm"],["jpgv","video/jpeg"],["jph","image/jph"],["jpm","video/jpm"],["jpx","image/jpx"],["js","application/javascript"],["json","application/json"],["json5","application/json5"],["jsonld","application/ld+json"],["jsonl","application/jsonl"],["jsonml","application/jsonml+json"],["jsx","text/jsx"],["jxr","image/jxr"],["jxra","image/jxra"],["jxrs","image/jxrs"],["jxs","image/jxs"],["jxsc","image/jxsc"],["jxsi","image/jxsi"],["jxss","image/jxss"],["kar","audio/midi"],["karbon","application/vnd.kde.karbon"],["kdb","application/octet-stream"],["kdbx","application/x-keepass2"],["key","application/x-iwork-keynote-sffkey"],["kfo","application/vnd.kde.kformula"],["kia","application/vnd.kidspiration"],["kml","application/vnd.google-earth.kml+xml"],["kmz","application/vnd.google-earth.kmz"],["kne","application/vnd.kinar"],["knp","application/vnd.kinar"],["kon","application/vnd.kde.kontour"],["kpr","application/vnd.kde.kpresenter"],["kpt","application/vnd.kde.kpresenter"],["kpxx","application/vnd.ds-keypoint"],["ksp","application/vnd.kde.kspread"],["ktr","application/vnd.kahootz"],["ktx","image/ktx"],["ktx2","image/ktx2"],["ktz","application/vnd.kahootz"],["kwd","application/vnd.kde.kword"],["kwt","application/vnd.kde.kword"],["lasxml","application/vnd.las.las+xml"],["latex","application/x-latex"],["lbd","application/vnd.llamagraphics.life-balance.desktop"],["lbe","application/vnd.llamagraphics.life-balance.exchange+xml"],["les","application/vnd.hhe.lesson-player"],["less","text/less"],["lgr","application/lgr+xml"],["lha","application/octet-stream"],["link66","application/vnd.route66.link66+xml"],["list","text/plain"],["list3820","application/vnd.ibm.modcap"],["listafp","application/vnd.ibm.modcap"],["litcoffee","text/coffeescript"],["lnk","application/x-ms-shortcut"],["log","text/plain"],["lostxml","application/lost+xml"],["lrf","application/octet-stream"],["lrm","application/vnd.ms-lrm"],["ltf","application/vnd.frogans.ltf"],["lua","text/x-lua"],["luac","application/x-lua-bytecode"],["lvp","audio/vnd.lucent.voice"],["lwp","application/vnd.lotus-wordpro"],["lzh","application/octet-stream"],["m1v","video/mpeg"],["m2a","audio/mpeg"],["m2v","video/mpeg"],["m3a","audio/mpeg"],["m3u","text/plain"],["m3u8","application/vnd.apple.mpegurl"],["m4a","audio/x-m4a"],["m4p","application/mp4"],["m4s","video/iso.segment"],["m4u","application/vnd.mpegurl"],["m4v","video/x-m4v"],["m13","application/x-msmediaview"],["m14","application/x-msmediaview"],["m21","application/mp21"],["ma","application/mathematica"],["mads","application/mads+xml"],["maei","application/mmt-aei+xml"],["mag","application/vnd.ecowin.chart"],["maker","application/vnd.framemaker"],["man","text/troff"],["manifest","text/cache-manifest"],["map","application/json"],["mar","application/octet-stream"],["markdown","text/markdown"],["mathml","application/mathml+xml"],["mb","application/mathematica"],["mbk","application/vnd.mobius.mbk"],["mbox","application/mbox"],["mc1","application/vnd.medcalcdata"],["mcd","application/vnd.mcd"],["mcurl","text/vnd.curl.mcurl"],["md","text/markdown"],["mdb","application/x-msaccess"],["mdi","image/vnd.ms-modi"],["mdx","text/mdx"],["me","text/troff"],["mesh","model/mesh"],["meta4","application/metalink4+xml"],["metalink","application/metalink+xml"],["mets","application/mets+xml"],["mfm","application/vnd.mfmp"],["mft","application/rpki-manifest"],["mgp","application/vnd.osgeo.mapguide.package"],["mgz","application/vnd.proteus.magazine"],["mid","audio/midi"],["midi","audio/midi"],["mie","application/x-mie"],["mif","application/vnd.mif"],["mime","message/rfc822"],["mj2","video/mj2"],["mjp2","video/mj2"],["mjs","application/javascript"],["mk3d","video/x-matroska"],["mka","audio/x-matroska"],["mkd","text/x-markdown"],["mks","video/x-matroska"],["mkv","video/x-matroska"],["mlp","application/vnd.dolby.mlp"],["mmd","application/vnd.chipnuts.karaoke-mmd"],["mmf","application/vnd.smaf"],["mml","text/mathml"],["mmr","image/vnd.fujixerox.edmics-mmr"],["mng","video/x-mng"],["mny","application/x-msmoney"],["mobi","application/x-mobipocket-ebook"],["mods","application/mods+xml"],["mov","video/quicktime"],["movie","video/x-sgi-movie"],["mp2","audio/mpeg"],["mp2a","audio/mpeg"],["mp3","audio/mpeg"],["mp4","video/mp4"],["mp4a","audio/mp4"],["mp4s","application/mp4"],["mp4v","video/mp4"],["mp21","application/mp21"],["mpc","application/vnd.mophun.certificate"],["mpd","application/dash+xml"],["mpe","video/mpeg"],["mpeg","video/mpeg"],["mpg","video/mpeg"],["mpg4","video/mp4"],["mpga","audio/mpeg"],["mpkg","application/vnd.apple.installer+xml"],["mpm","application/vnd.blueice.multipass"],["mpn","application/vnd.mophun.application"],["mpp","application/vnd.ms-project"],["mpt","application/vnd.ms-project"],["mpy","application/vnd.ibm.minipay"],["mqy","application/vnd.mobius.mqy"],["mrc","application/marc"],["mrcx","application/marcxml+xml"],["ms","text/troff"],["mscml","application/mediaservercontrol+xml"],["mseed","application/vnd.fdsn.mseed"],["mseq","application/vnd.mseq"],["msf","application/vnd.epson.msf"],["msg","application/vnd.ms-outlook"],["msh","model/mesh"],["msi","application/x-msdownload"],["msl","application/vnd.mobius.msl"],["msm","application/octet-stream"],["msp","application/octet-stream"],["msty","application/vnd.muvee.style"],["mtl","model/mtl"],["mts","model/vnd.mts"],["mus","application/vnd.musician"],["musd","application/mmt-usd+xml"],["musicxml","application/vnd.recordare.musicxml+xml"],["mvb","application/x-msmediaview"],["mvt","application/vnd.mapbox-vector-tile"],["mwf","application/vnd.mfer"],["mxf","application/mxf"],["mxl","application/vnd.recordare.musicxml"],["mxmf","audio/mobile-xmf"],["mxml","application/xv+xml"],["mxs","application/vnd.triscape.mxs"],["mxu","video/vnd.mpegurl"],["n-gage","application/vnd.nokia.n-gage.symbian.install"],["n3","text/n3"],["nb","application/mathematica"],["nbp","application/vnd.wolfram.player"],["nc","application/x-netcdf"],["ncx","application/x-dtbncx+xml"],["nfo","text/x-nfo"],["ngdat","application/vnd.nokia.n-gage.data"],["nitf","application/vnd.nitf"],["nlu","application/vnd.neurolanguage.nlu"],["nml","application/vnd.enliven"],["nnd","application/vnd.noblenet-directory"],["nns","application/vnd.noblenet-sealer"],["nnw","application/vnd.noblenet-web"],["npx","image/vnd.net-fpx"],["nq","application/n-quads"],["nsc","application/x-conference"],["nsf","application/vnd.lotus-notes"],["nt","application/n-triples"],["ntf","application/vnd.nitf"],["numbers","application/x-iwork-numbers-sffnumbers"],["nzb","application/x-nzb"],["oa2","application/vnd.fujitsu.oasys2"],["oa3","application/vnd.fujitsu.oasys3"],["oas","application/vnd.fujitsu.oasys"],["obd","application/x-msbinder"],["obgx","application/vnd.openblox.game+xml"],["obj","model/obj"],["oda","application/oda"],["odb","application/vnd.oasis.opendocument.database"],["odc","application/vnd.oasis.opendocument.chart"],["odf","application/vnd.oasis.opendocument.formula"],["odft","application/vnd.oasis.opendocument.formula-template"],["odg","application/vnd.oasis.opendocument.graphics"],["odi","application/vnd.oasis.opendocument.image"],["odm","application/vnd.oasis.opendocument.text-master"],["odp","application/vnd.oasis.opendocument.presentation"],["ods","application/vnd.oasis.opendocument.spreadsheet"],["odt","application/vnd.oasis.opendocument.text"],["oga","audio/ogg"],["ogex","model/vnd.opengex"],["ogg","audio/ogg"],["ogv","video/ogg"],["ogx","application/ogg"],["omdoc","application/omdoc+xml"],["onepkg","application/onenote"],["onetmp","application/onenote"],["onetoc","application/onenote"],["onetoc2","application/onenote"],["opf","application/oebps-package+xml"],["opml","text/x-opml"],["oprc","application/vnd.palm"],["opus","audio/ogg"],["org","text/x-org"],["osf","application/vnd.yamaha.openscoreformat"],["osfpvg","application/vnd.yamaha.openscoreformat.osfpvg+xml"],["osm","application/vnd.openstreetmap.data+xml"],["otc","application/vnd.oasis.opendocument.chart-template"],["otf","font/otf"],["otg","application/vnd.oasis.opendocument.graphics-template"],["oth","application/vnd.oasis.opendocument.text-web"],["oti","application/vnd.oasis.opendocument.image-template"],["otp","application/vnd.oasis.opendocument.presentation-template"],["ots","application/vnd.oasis.opendocument.spreadsheet-template"],["ott","application/vnd.oasis.opendocument.text-template"],["ova","application/x-virtualbox-ova"],["ovf","application/x-virtualbox-ovf"],["owl","application/rdf+xml"],["oxps","application/oxps"],["oxt","application/vnd.openofficeorg.extension"],["p","text/x-pascal"],["p7a","application/x-pkcs7-signature"],["p7b","application/x-pkcs7-certificates"],["p7c","application/pkcs7-mime"],["p7m","application/pkcs7-mime"],["p7r","application/x-pkcs7-certreqresp"],["p7s","application/pkcs7-signature"],["p8","application/pkcs8"],["p10","application/x-pkcs10"],["p12","application/x-pkcs12"],["pac","application/x-ns-proxy-autoconfig"],["pages","application/x-iwork-pages-sffpages"],["pas","text/x-pascal"],["paw","application/vnd.pawaafile"],["pbd","application/vnd.powerbuilder6"],["pbm","image/x-portable-bitmap"],["pcap","application/vnd.tcpdump.pcap"],["pcf","application/x-font-pcf"],["pcl","application/vnd.hp-pcl"],["pclxl","application/vnd.hp-pclxl"],["pct","image/x-pict"],["pcurl","application/vnd.curl.pcurl"],["pcx","image/x-pcx"],["pdb","application/x-pilot"],["pde","text/x-processing"],["pdf","application/pdf"],["pem","application/x-x509-user-cert"],["pfa","application/x-font-type1"],["pfb","application/x-font-type1"],["pfm","application/x-font-type1"],["pfr","application/font-tdpfr"],["pfx","application/x-pkcs12"],["pgm","image/x-portable-graymap"],["pgn","application/x-chess-pgn"],["pgp","application/pgp"],["php","application/x-httpd-php"],["php3","application/x-httpd-php"],["php4","application/x-httpd-php"],["phps","application/x-httpd-php-source"],["phtml","application/x-httpd-php"],["pic","image/x-pict"],["pkg","application/octet-stream"],["pki","application/pkixcmp"],["pkipath","application/pkix-pkipath"],["pkpass","application/vnd.apple.pkpass"],["pl","application/x-perl"],["plb","application/vnd.3gpp.pic-bw-large"],["plc","application/vnd.mobius.plc"],["plf","application/vnd.pocketlearn"],["pls","application/pls+xml"],["pm","application/x-perl"],["pml","application/vnd.ctc-posml"],["png","image/png"],["pnm","image/x-portable-anymap"],["portpkg","application/vnd.macports.portpkg"],["pot","application/vnd.ms-powerpoint"],["potm","application/vnd.ms-powerpoint.presentation.macroEnabled.12"],["potx","application/vnd.openxmlformats-officedocument.presentationml.template"],["ppa","application/vnd.ms-powerpoint"],["ppam","application/vnd.ms-powerpoint.addin.macroEnabled.12"],["ppd","application/vnd.cups-ppd"],["ppm","image/x-portable-pixmap"],["pps","application/vnd.ms-powerpoint"],["ppsm","application/vnd.ms-powerpoint.slideshow.macroEnabled.12"],["ppsx","application/vnd.openxmlformats-officedocument.presentationml.slideshow"],["ppt","application/powerpoint"],["pptm","application/vnd.ms-powerpoint.presentation.macroEnabled.12"],["pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation"],["pqa","application/vnd.palm"],["prc","application/x-pilot"],["pre","application/vnd.lotus-freelance"],["prf","application/pics-rules"],["provx","application/provenance+xml"],["ps","application/postscript"],["psb","application/vnd.3gpp.pic-bw-small"],["psd","application/x-photoshop"],["psf","application/x-font-linux-psf"],["pskcxml","application/pskc+xml"],["pti","image/prs.pti"],["ptid","application/vnd.pvi.ptid1"],["pub","application/x-mspublisher"],["pvb","application/vnd.3gpp.pic-bw-var"],["pwn","application/vnd.3m.post-it-notes"],["pya","audio/vnd.ms-playready.media.pya"],["pyv","video/vnd.ms-playready.media.pyv"],["qam","application/vnd.epson.quickanime"],["qbo","application/vnd.intu.qbo"],["qfx","application/vnd.intu.qfx"],["qps","application/vnd.publishare-delta-tree"],["qt","video/quicktime"],["qwd","application/vnd.quark.quarkxpress"],["qwt","application/vnd.quark.quarkxpress"],["qxb","application/vnd.quark.quarkxpress"],["qxd","application/vnd.quark.quarkxpress"],["qxl","application/vnd.quark.quarkxpress"],["qxt","application/vnd.quark.quarkxpress"],["ra","audio/x-realaudio"],["ram","audio/x-pn-realaudio"],["raml","application/raml+yaml"],["rapd","application/route-apd+xml"],["rar","application/x-rar"],["ras","image/x-cmu-raster"],["rcprofile","application/vnd.ipunplugged.rcprofile"],["rdf","application/rdf+xml"],["rdz","application/vnd.data-vision.rdz"],["relo","application/p2p-overlay+xml"],["rep","application/vnd.businessobjects"],["res","application/x-dtbresource+xml"],["rgb","image/x-rgb"],["rif","application/reginfo+xml"],["rip","audio/vnd.rip"],["ris","application/x-research-info-systems"],["rl","application/resource-lists+xml"],["rlc","image/vnd.fujixerox.edmics-rlc"],["rld","application/resource-lists-diff+xml"],["rm","audio/x-pn-realaudio"],["rmi","audio/midi"],["rmp","audio/x-pn-realaudio-plugin"],["rms","application/vnd.jcp.javame.midlet-rms"],["rmvb","application/vnd.rn-realmedia-vbr"],["rnc","application/relax-ng-compact-syntax"],["rng","application/xml"],["roa","application/rpki-roa"],["roff","text/troff"],["rp9","application/vnd.cloanto.rp9"],["rpm","audio/x-pn-realaudio-plugin"],["rpss","application/vnd.nokia.radio-presets"],["rpst","application/vnd.nokia.radio-preset"],["rq","application/sparql-query"],["rs","application/rls-services+xml"],["rsa","application/x-pkcs7"],["rsat","application/atsc-rsat+xml"],["rsd","application/rsd+xml"],["rsheet","application/urc-ressheet+xml"],["rss","application/rss+xml"],["rtf","text/rtf"],["rtx","text/richtext"],["run","application/x-makeself"],["rusd","application/route-usd+xml"],["rv","video/vnd.rn-realvideo"],["s","text/x-asm"],["s3m","audio/s3m"],["saf","application/vnd.yamaha.smaf-audio"],["sass","text/x-sass"],["sbml","application/sbml+xml"],["sc","application/vnd.ibm.secure-container"],["scd","application/x-msschedule"],["scm","application/vnd.lotus-screencam"],["scq","application/scvp-cv-request"],["scs","application/scvp-cv-response"],["scss","text/x-scss"],["scurl","text/vnd.curl.scurl"],["sda","application/vnd.stardivision.draw"],["sdc","application/vnd.stardivision.calc"],["sdd","application/vnd.stardivision.impress"],["sdkd","application/vnd.solent.sdkm+xml"],["sdkm","application/vnd.solent.sdkm+xml"],["sdp","application/sdp"],["sdw","application/vnd.stardivision.writer"],["sea","application/octet-stream"],["see","application/vnd.seemail"],["seed","application/vnd.fdsn.seed"],["sema","application/vnd.sema"],["semd","application/vnd.semd"],["semf","application/vnd.semf"],["senmlx","application/senml+xml"],["sensmlx","application/sensml+xml"],["ser","application/java-serialized-object"],["setpay","application/set-payment-initiation"],["setreg","application/set-registration-initiation"],["sfd-hdstx","application/vnd.hydrostatix.sof-data"],["sfs","application/vnd.spotfire.sfs"],["sfv","text/x-sfv"],["sgi","image/sgi"],["sgl","application/vnd.stardivision.writer-global"],["sgm","text/sgml"],["sgml","text/sgml"],["sh","application/x-sh"],["shar","application/x-shar"],["shex","text/shex"],["shf","application/shf+xml"],["shtml","text/html"],["sid","image/x-mrsid-image"],["sieve","application/sieve"],["sig","application/pgp-signature"],["sil","audio/silk"],["silo","model/mesh"],["sis","application/vnd.symbian.install"],["sisx","application/vnd.symbian.install"],["sit","application/x-stuffit"],["sitx","application/x-stuffitx"],["siv","application/sieve"],["skd","application/vnd.koan"],["skm","application/vnd.koan"],["skp","application/vnd.koan"],["skt","application/vnd.koan"],["sldm","application/vnd.ms-powerpoint.slide.macroenabled.12"],["sldx","application/vnd.openxmlformats-officedocument.presentationml.slide"],["slim","text/slim"],["slm","text/slim"],["sls","application/route-s-tsid+xml"],["slt","application/vnd.epson.salt"],["sm","application/vnd.stepmania.stepchart"],["smf","application/vnd.stardivision.math"],["smi","application/smil"],["smil","application/smil"],["smv","video/x-smv"],["smzip","application/vnd.stepmania.package"],["snd","audio/basic"],["snf","application/x-font-snf"],["so","application/octet-stream"],["spc","application/x-pkcs7-certificates"],["spdx","text/spdx"],["spf","application/vnd.yamaha.smaf-phrase"],["spl","application/x-futuresplash"],["spot","text/vnd.in3d.spot"],["spp","application/scvp-vp-response"],["spq","application/scvp-vp-request"],["spx","audio/ogg"],["sql","application/x-sql"],["src","application/x-wais-source"],["srt","application/x-subrip"],["sru","application/sru+xml"],["srx","application/sparql-results+xml"],["ssdl","application/ssdl+xml"],["sse","application/vnd.kodak-descriptor"],["ssf","application/vnd.epson.ssf"],["ssml","application/ssml+xml"],["sst","application/octet-stream"],["st","application/vnd.sailingtracker.track"],["stc","application/vnd.sun.xml.calc.template"],["std","application/vnd.sun.xml.draw.template"],["stf","application/vnd.wt.stf"],["sti","application/vnd.sun.xml.impress.template"],["stk","application/hyperstudio"],["stl","model/stl"],["stpx","model/step+xml"],["stpxz","model/step-xml+zip"],["stpz","model/step+zip"],["str","application/vnd.pg.format"],["stw","application/vnd.sun.xml.writer.template"],["styl","text/stylus"],["stylus","text/stylus"],["sub","text/vnd.dvb.subtitle"],["sus","application/vnd.sus-calendar"],["susp","application/vnd.sus-calendar"],["sv4cpio","application/x-sv4cpio"],["sv4crc","application/x-sv4crc"],["svc","application/vnd.dvb.service"],["svd","application/vnd.svd"],["svg","image/svg+xml"],["svgz","image/svg+xml"],["swa","application/x-director"],["swf","application/x-shockwave-flash"],["swi","application/vnd.aristanetworks.swi"],["swidtag","application/swid+xml"],["sxc","application/vnd.sun.xml.calc"],["sxd","application/vnd.sun.xml.draw"],["sxg","application/vnd.sun.xml.writer.global"],["sxi","application/vnd.sun.xml.impress"],["sxm","application/vnd.sun.xml.math"],["sxw","application/vnd.sun.xml.writer"],["t","text/troff"],["t3","application/x-t3vm-image"],["t38","image/t38"],["taglet","application/vnd.mynfc"],["tao","application/vnd.tao.intent-module-archive"],["tap","image/vnd.tencent.tap"],["tar","application/x-tar"],["tcap","application/vnd.3gpp2.tcap"],["tcl","application/x-tcl"],["td","application/urc-targetdesc+xml"],["teacher","application/vnd.smart.teacher"],["tei","application/tei+xml"],["teicorpus","application/tei+xml"],["tex","application/x-tex"],["texi","application/x-texinfo"],["texinfo","application/x-texinfo"],["text","text/plain"],["tfi","application/thraud+xml"],["tfm","application/x-tex-tfm"],["tfx","image/tiff-fx"],["tga","image/x-tga"],["tgz","application/x-tar"],["thmx","application/vnd.ms-officetheme"],["tif","image/tiff"],["tiff","image/tiff"],["tk","application/x-tcl"],["tmo","application/vnd.tmobile-livetv"],["toml","application/toml"],["torrent","application/x-bittorrent"],["tpl","application/vnd.groove-tool-template"],["tpt","application/vnd.trid.tpt"],["tr","text/troff"],["tra","application/vnd.trueapp"],["trig","application/trig"],["trm","application/x-msterminal"],["ts","video/mp2t"],["tsd","application/timestamped-data"],["tsv","text/tab-separated-values"],["ttc","font/collection"],["ttf","font/ttf"],["ttl","text/turtle"],["ttml","application/ttml+xml"],["twd","application/vnd.simtech-mindmapper"],["twds","application/vnd.simtech-mindmapper"],["txd","application/vnd.genomatix.tuxedo"],["txf","application/vnd.mobius.txf"],["txt","text/plain"],["u8dsn","message/global-delivery-status"],["u8hdr","message/global-headers"],["u8mdn","message/global-disposition-notification"],["u8msg","message/global"],["u32","application/x-authorware-bin"],["ubj","application/ubjson"],["udeb","application/x-debian-package"],["ufd","application/vnd.ufdl"],["ufdl","application/vnd.ufdl"],["ulx","application/x-glulx"],["umj","application/vnd.umajin"],["unityweb","application/vnd.unity"],["uoml","application/vnd.uoml+xml"],["uri","text/uri-list"],["uris","text/uri-list"],["urls","text/uri-list"],["usdz","model/vnd.usdz+zip"],["ustar","application/x-ustar"],["utz","application/vnd.uiq.theme"],["uu","text/x-uuencode"],["uva","audio/vnd.dece.audio"],["uvd","application/vnd.dece.data"],["uvf","application/vnd.dece.data"],["uvg","image/vnd.dece.graphic"],["uvh","video/vnd.dece.hd"],["uvi","image/vnd.dece.graphic"],["uvm","video/vnd.dece.mobile"],["uvp","video/vnd.dece.pd"],["uvs","video/vnd.dece.sd"],["uvt","application/vnd.dece.ttml+xml"],["uvu","video/vnd.uvvu.mp4"],["uvv","video/vnd.dece.video"],["uvva","audio/vnd.dece.audio"],["uvvd","application/vnd.dece.data"],["uvvf","application/vnd.dece.data"],["uvvg","image/vnd.dece.graphic"],["uvvh","video/vnd.dece.hd"],["uvvi","image/vnd.dece.graphic"],["uvvm","video/vnd.dece.mobile"],["uvvp","video/vnd.dece.pd"],["uvvs","video/vnd.dece.sd"],["uvvt","application/vnd.dece.ttml+xml"],["uvvu","video/vnd.uvvu.mp4"],["uvvv","video/vnd.dece.video"],["uvvx","application/vnd.dece.unspecified"],["uvvz","application/vnd.dece.zip"],["uvx","application/vnd.dece.unspecified"],["uvz","application/vnd.dece.zip"],["vbox","application/x-virtualbox-vbox"],["vbox-extpack","application/x-virtualbox-vbox-extpack"],["vcard","text/vcard"],["vcd","application/x-cdlink"],["vcf","text/x-vcard"],["vcg","application/vnd.groove-vcard"],["vcs","text/x-vcalendar"],["vcx","application/vnd.vcx"],["vdi","application/x-virtualbox-vdi"],["vds","model/vnd.sap.vds"],["vhd","application/x-virtualbox-vhd"],["vis","application/vnd.visionary"],["viv","video/vnd.vivo"],["vlc","application/videolan"],["vmdk","application/x-virtualbox-vmdk"],["vob","video/x-ms-vob"],["vor","application/vnd.stardivision.writer"],["vox","application/x-authorware-bin"],["vrml","model/vrml"],["vsd","application/vnd.visio"],["vsf","application/vnd.vsf"],["vss","application/vnd.visio"],["vst","application/vnd.visio"],["vsw","application/vnd.visio"],["vtf","image/vnd.valve.source.texture"],["vtt","text/vtt"],["vtu","model/vnd.vtu"],["vxml","application/voicexml+xml"],["w3d","application/x-director"],["wad","application/x-doom"],["wadl","application/vnd.sun.wadl+xml"],["war","application/java-archive"],["wasm","application/wasm"],["wav","audio/x-wav"],["wax","audio/x-ms-wax"],["wbmp","image/vnd.wap.wbmp"],["wbs","application/vnd.criticaltools.wbs+xml"],["wbxml","application/wbxml"],["wcm","application/vnd.ms-works"],["wdb","application/vnd.ms-works"],["wdp","image/vnd.ms-photo"],["weba","audio/webm"],["webapp","application/x-web-app-manifest+json"],["webm","video/webm"],["webmanifest","application/manifest+json"],["webp","image/webp"],["wg","application/vnd.pmi.widget"],["wgt","application/widget"],["wks","application/vnd.ms-works"],["wm","video/x-ms-wm"],["wma","audio/x-ms-wma"],["wmd","application/x-ms-wmd"],["wmf","image/wmf"],["wml","text/vnd.wap.wml"],["wmlc","application/wmlc"],["wmls","text/vnd.wap.wmlscript"],["wmlsc","application/vnd.wap.wmlscriptc"],["wmv","video/x-ms-wmv"],["wmx","video/x-ms-wmx"],["wmz","application/x-msmetafile"],["woff","font/woff"],["woff2","font/woff2"],["word","application/msword"],["wpd","application/vnd.wordperfect"],["wpl","application/vnd.ms-wpl"],["wps","application/vnd.ms-works"],["wqd","application/vnd.wqd"],["wri","application/x-mswrite"],["wrl","model/vrml"],["wsc","message/vnd.wfa.wsc"],["wsdl","application/wsdl+xml"],["wspolicy","application/wspolicy+xml"],["wtb","application/vnd.webturbo"],["wvx","video/x-ms-wvx"],["x3d","model/x3d+xml"],["x3db","model/x3d+fastinfoset"],["x3dbz","model/x3d+binary"],["x3dv","model/x3d-vrml"],["x3dvz","model/x3d+vrml"],["x3dz","model/x3d+xml"],["x32","application/x-authorware-bin"],["x_b","model/vnd.parasolid.transmit.binary"],["x_t","model/vnd.parasolid.transmit.text"],["xaml","application/xaml+xml"],["xap","application/x-silverlight-app"],["xar","application/vnd.xara"],["xav","application/xcap-att+xml"],["xbap","application/x-ms-xbap"],["xbd","application/vnd.fujixerox.docuworks.binder"],["xbm","image/x-xbitmap"],["xca","application/xcap-caps+xml"],["xcs","application/calendar+xml"],["xdf","application/xcap-diff+xml"],["xdm","application/vnd.syncml.dm+xml"],["xdp","application/vnd.adobe.xdp+xml"],["xdssc","application/dssc+xml"],["xdw","application/vnd.fujixerox.docuworks"],["xel","application/xcap-el+xml"],["xenc","application/xenc+xml"],["xer","application/patch-ops-error+xml"],["xfdf","application/vnd.adobe.xfdf"],["xfdl","application/vnd.xfdl"],["xht","application/xhtml+xml"],["xhtml","application/xhtml+xml"],["xhvml","application/xv+xml"],["xif","image/vnd.xiff"],["xl","application/excel"],["xla","application/vnd.ms-excel"],["xlam","application/vnd.ms-excel.addin.macroEnabled.12"],["xlc","application/vnd.ms-excel"],["xlf","application/xliff+xml"],["xlm","application/vnd.ms-excel"],["xls","application/vnd.ms-excel"],["xlsb","application/vnd.ms-excel.sheet.binary.macroEnabled.12"],["xlsm","application/vnd.ms-excel.sheet.macroEnabled.12"],["xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],["xlt","application/vnd.ms-excel"],["xltm","application/vnd.ms-excel.template.macroEnabled.12"],["xltx","application/vnd.openxmlformats-officedocument.spreadsheetml.template"],["xlw","application/vnd.ms-excel"],["xm","audio/xm"],["xml","application/xml"],["xns","application/xcap-ns+xml"],["xo","application/vnd.olpc-sugar"],["xop","application/xop+xml"],["xpi","application/x-xpinstall"],["xpl","application/xproc+xml"],["xpm","image/x-xpixmap"],["xpr","application/vnd.is-xpr"],["xps","application/vnd.ms-xpsdocument"],["xpw","application/vnd.intercon.formnet"],["xpx","application/vnd.intercon.formnet"],["xsd","application/xml"],["xsl","application/xml"],["xslt","application/xslt+xml"],["xsm","application/vnd.syncml+xml"],["xspf","application/xspf+xml"],["xul","application/vnd.mozilla.xul+xml"],["xvm","application/xv+xml"],["xvml","application/xv+xml"],["xwd","image/x-xwindowdump"],["xyz","chemical/x-xyz"],["xz","application/x-xz"],["yaml","text/yaml"],["yang","application/yang"],["yin","application/yin+xml"],["yml","text/yaml"],["ymp","text/x-suse-ymp"],["z","application/x-compress"],["z1","application/x-zmachine"],["z2","application/x-zmachine"],["z3","application/x-zmachine"],["z4","application/x-zmachine"],["z5","application/x-zmachine"],["z6","application/x-zmachine"],["z7","application/x-zmachine"],["z8","application/x-zmachine"],["zaz","application/vnd.zzazz.deck+xml"],["zip","application/zip"],["zir","application/vnd.zul"],["zirz","application/vnd.zul"],["zmm","application/vnd.handheld-entertainment+xml"],["zsh","text/x-scriptzsh"]]);function Jt(t,s,a){const o=Gn(t),{webkitRelativePath:n}=t,l=typeof s=="string"?s:typeof n=="string"&&n.length>0?n:`./${t.name}`;return typeof o.path!="string"&&Ls(o,"path",l),Ls(o,"relativePath",l),o}function Gn(t){const{name:s}=t;if(s&&s.lastIndexOf(".")!==-1&&!t.type){const o=s.split(".").pop().toLowerCase(),n=Kn.get(o);n&&Object.defineProperty(t,"type",{value:n,writable:!1,configurable:!1,enumerable:!0})}return t}function Ls(t,s,a){Object.defineProperty(t,s,{value:a,writable:!1,configurable:!1,enumerable:!0})}const Vn=[".DS_Store","Thumbs.db"];function Yn(t){return Rt(this,void 0,void 0,function*(){return yr(t)&&Qn(t.dataTransfer)?to(t.dataTransfer,t.type):Zn(t)?Xn(t):Array.isArray(t)&&t.every(s=>"getFile"in s&&typeof s.getFile=="function")?eo(t):[]})}function Qn(t){return yr(t)}function Zn(t){return yr(t)&&yr(t.target)}function yr(t){return typeof t=="object"&&t!==null}function Xn(t){return Hr(t.target.files).map(s=>Jt(s))}function eo(t){return Rt(this,void 0,void 0,function*(){return(yield Promise.all(t.map(a=>a.getFile()))).map(a=>Jt(a))})}function to(t,s){return Rt(this,void 0,void 0,function*(){if(t.items){const a=Hr(t.items).filter(n=>n.kind==="file");if(s!=="drop")return a;const o=yield Promise.all(a.map(ro));return Is(sa(o))}return Is(Hr(t.files).map(a=>Jt(a)))})}function Is(t){return t.filter(s=>Vn.indexOf(s.name)===-1)}function Hr(t){if(t===null)return[];const s=[];for(let a=0;a<t.length;a++){const o=t[a];s.push(o)}return s}function ro(t){if(typeof t.webkitGetAsEntry!="function")return Ds(t);const s=t.webkitGetAsEntry();return s&&s.isDirectory?aa(s):Ds(t,s)}function sa(t){return t.reduce((s,a)=>[...s,...Array.isArray(a)?sa(a):[a]],[])}function Ds(t,s){return Rt(this,void 0,void 0,function*(){var a;if(globalThis.isSecureContext&&typeof t.getAsFileSystemHandle=="function"){const l=yield t.getAsFileSystemHandle();if(l===null)throw new Error(`${t} is not a File`);if(l!==void 0){const i=yield l.getFile();return i.handle=l,Jt(i)}}const o=t.getAsFile();if(!o)throw new Error(`${t} is not a File`);return Jt(o,(a=s?.fullPath)!==null&&a!==void 0?a:void 0)})}function so(t){return Rt(this,void 0,void 0,function*(){return t.isDirectory?aa(t):ao(t)})}function aa(t){const s=t.createReader();return new Promise((a,o)=>{const n=[];function l(){s.readEntries(i=>Rt(this,void 0,void 0,function*(){if(i.length){const d=Promise.all(i.map(so));n.push(d),l()}else try{const d=yield Promise.all(n);a(d)}catch(d){o(d)}}),i=>{o(i)})}l()})}function ao(t){return Rt(this,void 0,void 0,function*(){return new Promise((s,a)=>{t.file(o=>{const n=Jt(o,t.fullPath);s(n)},o=>{a(o)})})})}var ur={},Ts;function no(){return Ts||(Ts=1,ur.__esModule=!0,ur.default=function(t,s){if(t&&s){var a=Array.isArray(s)?s:s.split(",");if(a.length===0)return!0;var o=t.name||"",n=(t.type||"").toLowerCase(),l=n.replace(/\/.*$/,"");return a.some(function(i){var d=i.trim().toLowerCase();return d.charAt(0)==="."?o.toLowerCase().endsWith(d):d.endsWith("/*")?l===d.replace(/\/.*$/,""):n===d})}return!0}),ur}var oo=no();const Rr=Zr(oo);function Ps(t){return co(t)||lo(t)||oa(t)||io()}function io(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
2
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function lo(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function co(t){if(Array.isArray(t))return qr(t)}function Rs(t,s){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);s&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function $s(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Rs(Object(a),!0).forEach(function(o){na(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Rs(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function na(t,s,a){return s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function ar(t,s){return po(t)||uo(t,s)||oa(t,s)||mo()}function mo(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
3
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function oa(t,s){if(t){if(typeof t=="string")return qr(t,s);var a=Object.prototype.toString.call(t).slice(8,-1);if(a==="Object"&&t.constructor&&(a=t.constructor.name),a==="Map"||a==="Set")return Array.from(t);if(a==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a))return qr(t,s)}}function qr(t,s){(s==null||s>t.length)&&(s=t.length);for(var a=0,o=new Array(s);a<s;a++)o[a]=t[a];return o}function uo(t,s){var a=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(a!=null){var o=[],n=!0,l=!1,i,d;try{for(a=a.call(t);!(n=(i=a.next()).done)&&(o.push(i.value),!(s&&o.length===s));n=!0);}catch(h){l=!0,d=h}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw d}}return o}}function po(t){if(Array.isArray(t))return t}var xo=typeof Rr=="function"?Rr:Rr.default,ho="file-invalid-type",go="file-too-large",fo="file-too-small",bo="too-many-files",yo=function(){var s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",a=s.split(","),o=a.length>1?"one of ".concat(a.join(", ")):a[0];return{code:ho,message:"File type must be ".concat(o)}},zs=function(s){return{code:go,message:"File is larger than ".concat(s," ").concat(s===1?"byte":"bytes")}},Os=function(s){return{code:fo,message:"File is smaller than ".concat(s," ").concat(s===1?"byte":"bytes")}},vo={code:bo,message:"Too many files"};function ia(t,s){var a=t.type==="application/x-moz-file"||xo(t,s);return[a,a?null:yo(s)]}function la(t,s,a){if(Lt(t.size))if(Lt(s)&&Lt(a)){if(t.size>a)return[!1,zs(a)];if(t.size<s)return[!1,Os(s)]}else{if(Lt(s)&&t.size<s)return[!1,Os(s)];if(Lt(a)&&t.size>a)return[!1,zs(a)]}return[!0,null]}function Lt(t){return t!=null}function jo(t){var s=t.files,a=t.accept,o=t.minSize,n=t.maxSize,l=t.multiple,i=t.maxFiles,d=t.validator;return!l&&s.length>1||l&&i>=1&&s.length>i?!1:s.every(function(h){var g=ia(h,a),p=ar(g,1),w=p[0],v=la(h,o,n),y=ar(v,1),x=y[0],P=d?d(h):null;return w&&x&&!P})}function vr(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function pr(t){return t.dataTransfer?Array.prototype.some.call(t.dataTransfer.types,function(s){return s==="Files"||s==="application/x-moz-file"}):!!t.target&&!!t.target.files}function As(t){t.preventDefault()}function wo(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function ko(t){return t.indexOf("Edge/")!==-1}function No(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return wo(t)||ko(t)}function dt(){for(var t=arguments.length,s=new Array(t),a=0;a<t;a++)s[a]=arguments[a];return function(o){for(var n=arguments.length,l=new Array(n>1?n-1:0),i=1;i<n;i++)l[i-1]=arguments[i];return s.some(function(d){return!vr(o)&&d&&d.apply(void 0,[o].concat(l)),vr(o)})}}function So(){return"showOpenFilePicker"in window}function Co(t){if(Lt(t)){var s=Object.entries(t).filter(function(a){var o=ar(a,2),n=o[0],l=o[1],i=!0;return ca(n)||(console.warn('Skipped "'.concat(n,'" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.')),i=!1),(!Array.isArray(l)||!l.every(da))&&(console.warn('Skipped "'.concat(n,'" because an invalid file extension was provided.')),i=!1),i}).reduce(function(a,o){var n=ar(o,2),l=n[0],i=n[1];return $s($s({},a),{},na({},l,i))},{});return[{description:"Files",accept:s}]}return t}function Eo(t){if(Lt(t))return Object.entries(t).reduce(function(s,a){var o=ar(a,2),n=o[0],l=o[1];return[].concat(Ps(s),[n],Ps(l))},[]).filter(function(s){return ca(s)||da(s)}).join(",")}function Mo(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function Lo(t){return t instanceof DOMException&&(t.name==="SecurityError"||t.code===t.SECURITY_ERR)}function ca(t){return t==="audio/*"||t==="video/*"||t==="image/*"||t==="text/*"||t==="application/*"||/\w+\/[-+.\w]+/g.test(t)}function da(t){return/^.*\.[\w]+$/.test(t)}var Io=["children"],Do=["open"],To=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],Po=["refKey","onChange","onClick"];function Ro(t){return Oo(t)||zo(t)||ma(t)||$o()}function $o(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
4
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function zo(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Oo(t){if(Array.isArray(t))return Jr(t)}function $r(t,s){return Fo(t)||_o(t,s)||ma(t,s)||Ao()}function Ao(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
5
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ma(t,s){if(t){if(typeof t=="string")return Jr(t,s);var a=Object.prototype.toString.call(t).slice(8,-1);if(a==="Object"&&t.constructor&&(a=t.constructor.name),a==="Map"||a==="Set")return Array.from(t);if(a==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a))return Jr(t,s)}}function Jr(t,s){(s==null||s>t.length)&&(s=t.length);for(var a=0,o=new Array(s);a<s;a++)o[a]=t[a];return o}function _o(t,s){var a=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(a!=null){var o=[],n=!0,l=!1,i,d;try{for(a=a.call(t);!(n=(i=a.next()).done)&&(o.push(i.value),!(s&&o.length===s));n=!0);}catch(h){l=!0,d=h}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw d}}return o}}function Fo(t){if(Array.isArray(t))return t}function _s(t,s){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);s&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function Be(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?_s(Object(a),!0).forEach(function(o){Kr(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):_s(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function Kr(t,s,a){return s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function jr(t,s){if(t==null)return{};var a=Wo(t,s),o,n;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(n=0;n<l.length;n++)o=l[n],!(s.indexOf(o)>=0)&&Object.prototype.propertyIsEnumerable.call(t,o)&&(a[o]=t[o])}return a}function Wo(t,s){if(t==null)return{};var a={},o=Object.keys(t),n,l;for(l=0;l<o.length;l++)n=o[l],!(s.indexOf(n)>=0)&&(a[n]=t[n]);return a}var rs=r.forwardRef(function(t,s){var a=t.children,o=jr(t,Io),n=ss(o),l=n.open,i=jr(n,Do);return r.useImperativeHandle(s,function(){return{open:l}},[l]),rt.createElement(r.Fragment,null,a(Be(Be({},i),{},{open:l})))});rs.displayName="Dropzone";var ua={disabled:!1,getFilesFromEvent:Yn,maxSize:1/0,minSize:0,multiple:!0,maxFiles:0,preventDropOnDocument:!0,noClick:!1,noKeyboard:!1,noDrag:!1,noDragEventsBubbling:!1,validator:null,useFsAccessApi:!1,autoFocus:!1};rs.defaultProps=ua;rs.propTypes={children:Ae.func,accept:Ae.objectOf(Ae.arrayOf(Ae.string)),multiple:Ae.bool,preventDropOnDocument:Ae.bool,noClick:Ae.bool,noKeyboard:Ae.bool,noDrag:Ae.bool,noDragEventsBubbling:Ae.bool,minSize:Ae.number,maxSize:Ae.number,maxFiles:Ae.number,disabled:Ae.bool,getFilesFromEvent:Ae.func,onFileDialogCancel:Ae.func,onFileDialogOpen:Ae.func,useFsAccessApi:Ae.bool,autoFocus:Ae.bool,onDragEnter:Ae.func,onDragLeave:Ae.func,onDragOver:Ae.func,onDrop:Ae.func,onDropAccepted:Ae.func,onDropRejected:Ae.func,onError:Ae.func,validator:Ae.func};var Gr={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function ss(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Be(Be({},ua),t),a=s.accept,o=s.disabled,n=s.getFilesFromEvent,l=s.maxSize,i=s.minSize,d=s.multiple,h=s.maxFiles,g=s.onDragEnter,p=s.onDragLeave,w=s.onDragOver,v=s.onDrop,y=s.onDropAccepted,x=s.onDropRejected,P=s.onFileDialogCancel,R=s.onFileDialogOpen,C=s.useFsAccessApi,k=s.autoFocus,u=s.preventDropOnDocument,m=s.noClick,N=s.noKeyboard,S=s.noDrag,f=s.noDragEventsBubbling,A=s.onError,F=s.validator,Z=r.useMemo(function(){return Eo(a)},[a]),le=r.useMemo(function(){return Co(a)},[a]),ee=r.useMemo(function(){return typeof R=="function"?R:Fs},[R]),ne=r.useMemo(function(){return typeof P=="function"?P:Fs},[P]),U=r.useRef(null),D=r.useRef(null),X=r.useReducer(Bo,Gr),se=$r(X,2),ve=se[0],oe=se[1],z=ve.isFocused,ue=ve.isFileDialogActive,Le=r.useRef(typeof window<"u"&&window.isSecureContext&&C&&So()),Te=function(){!Le.current&&ue&&setTimeout(function(){if(D.current){var ae=D.current.files;ae.length||(oe({type:"closeDialog"}),ne())}},300)};r.useEffect(function(){return window.addEventListener("focus",Te,!1),function(){window.removeEventListener("focus",Te,!1)}},[D,ue,ne,Le]);var ke=r.useRef([]),Fe=function(ae){U.current&&U.current.contains(ae.target)||(ae.preventDefault(),ke.current=[])};r.useEffect(function(){return u&&(document.addEventListener("dragover",As,!1),document.addEventListener("drop",Fe,!1)),function(){u&&(document.removeEventListener("dragover",As),document.removeEventListener("drop",Fe))}},[U,u]),r.useEffect(function(){return!o&&k&&U.current&&U.current.focus(),function(){}},[U,k,o]);var we=r.useCallback(function(K){A?A(K):console.error(K)},[A]),Se=r.useCallback(function(K){K.preventDefault(),K.persist(),pe(K),ke.current=[].concat(Ro(ke.current),[K.target]),pr(K)&&Promise.resolve(n(K)).then(function(ae){if(!(vr(K)&&!f)){var j=ae.length,V=j>0&&jo({files:ae,accept:Z,minSize:i,maxSize:l,multiple:d,maxFiles:h,validator:F}),de=j>0&&!V;oe({isDragAccept:V,isDragReject:de,isDragActive:!0,type:"setDraggedFiles"}),g&&g(K)}}).catch(function(ae){return we(ae)})},[n,g,we,f,Z,i,l,d,h,F]),ze=r.useCallback(function(K){K.preventDefault(),K.persist(),pe(K);var ae=pr(K);if(ae&&K.dataTransfer)try{K.dataTransfer.dropEffect="copy"}catch{}return ae&&w&&w(K),!1},[w,f]),Ue=r.useCallback(function(K){K.preventDefault(),K.persist(),pe(K);var ae=ke.current.filter(function(V){return U.current&&U.current.contains(V)}),j=ae.indexOf(K.target);j!==-1&&ae.splice(j,1),ke.current=ae,!(ae.length>0)&&(oe({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),pr(K)&&p&&p(K))},[U,p,f]),xe=r.useCallback(function(K,ae){var j=[],V=[];K.forEach(function(de){var ce=ia(de,Z),$=$r(ce,2),$e=$[0],Y=$[1],re=la(de,i,l),ie=$r(re,2),be=ie[0],fe=ie[1],je=F?F(de):null;if($e&&be&&!je)j.push(de);else{var Ee=[Y,fe];je&&(Ee=Ee.concat(je)),V.push({file:de,errors:Ee.filter(function(He){return He})})}}),(!d&&j.length>1||d&&h>=1&&j.length>h)&&(j.forEach(function(de){V.push({file:de,errors:[vo]})}),j.splice(0)),oe({acceptedFiles:j,fileRejections:V,isDragReject:V.length>0,type:"setFiles"}),v&&v(j,V,ae),V.length>0&&x&&x(V,ae),j.length>0&&y&&y(j,ae)},[oe,d,Z,i,l,h,v,y,x,F]),Ce=r.useCallback(function(K){K.preventDefault(),K.persist(),pe(K),ke.current=[],pr(K)&&Promise.resolve(n(K)).then(function(ae){vr(K)&&!f||xe(ae,K)}).catch(function(ae){return we(ae)}),oe({type:"reset"})},[n,xe,we,f]),Ie=r.useCallback(function(){if(Le.current){oe({type:"openDialog"}),ee();var K={multiple:d,types:le};window.showOpenFilePicker(K).then(function(ae){return n(ae)}).then(function(ae){xe(ae,null),oe({type:"closeDialog"})}).catch(function(ae){Mo(ae)?(ne(ae),oe({type:"closeDialog"})):Lo(ae)?(Le.current=!1,D.current?(D.current.value=null,D.current.click()):we(new Error("Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided."))):we(ae)});return}D.current&&(oe({type:"openDialog"}),ee(),D.current.value=null,D.current.click())},[oe,ee,ne,C,xe,we,le,d]),Pe=r.useCallback(function(K){!U.current||!U.current.isEqualNode(K.target)||(K.key===" "||K.key==="Enter"||K.keyCode===32||K.keyCode===13)&&(K.preventDefault(),Ie())},[U,Ie]),De=r.useCallback(function(){oe({type:"focus"})},[]),T=r.useCallback(function(){oe({type:"blur"})},[]),_=r.useCallback(function(){m||(No()?setTimeout(Ie,0):Ie())},[m,Ie]),W=function(ae){return o?null:ae},b=function(ae){return N?null:W(ae)},H=function(ae){return S?null:W(ae)},pe=function(ae){f&&ae.stopPropagation()},Ne=r.useMemo(function(){return function(){var K=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ae=K.refKey,j=ae===void 0?"ref":ae,V=K.role,de=K.onKeyDown,ce=K.onFocus,$=K.onBlur,$e=K.onClick,Y=K.onDragEnter,re=K.onDragOver,ie=K.onDragLeave,be=K.onDrop,fe=jr(K,To);return Be(Be(Kr({onKeyDown:b(dt(de,Pe)),onFocus:b(dt(ce,De)),onBlur:b(dt($,T)),onClick:W(dt($e,_)),onDragEnter:H(dt(Y,Se)),onDragOver:H(dt(re,ze)),onDragLeave:H(dt(ie,Ue)),onDrop:H(dt(be,Ce)),role:typeof V=="string"&&V!==""?V:"presentation"},j,U),!o&&!N?{tabIndex:0}:{}),fe)}},[U,Pe,De,T,_,Se,ze,Ue,Ce,N,S,o]),Oe=r.useCallback(function(K){K.stopPropagation()},[]),at=r.useMemo(function(){return function(){var K=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},ae=K.refKey,j=ae===void 0?"ref":ae,V=K.onChange,de=K.onClick,ce=jr(K,Po),$=Kr({accept:Z,multiple:d,type:"file",style:{border:0,clip:"rect(0, 0, 0, 0)",clipPath:"inset(50%)",height:"1px",margin:"0 -1px -1px 0",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"},onChange:W(dt(V,Ce)),onClick:W(dt(de,Oe)),tabIndex:-1},j,D);return Be(Be({},$),ce)}},[D,a,d,Ce,o]);return Be(Be({},ve),{},{isFocused:z&&!o,getRootProps:Ne,getInputProps:at,rootRef:U,inputRef:D,open:W(Ie)})}function Bo(t,s){switch(s.type){case"focus":return Be(Be({},t),{},{isFocused:!0});case"blur":return Be(Be({},t),{},{isFocused:!1});case"openDialog":return Be(Be({},Gr),{},{isFileDialogActive:!0});case"closeDialog":return Be(Be({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Be(Be({},t),{},{isDragActive:s.isDragActive,isDragAccept:s.isDragAccept,isDragReject:s.isDragReject});case"setFiles":return Be(Be({},t),{},{acceptedFiles:s.acceptedFiles,fileRejections:s.fileRejections,isDragReject:s.isDragReject});case"reset":return Be({},Gr);default:return t}}function Fs(){}const zr=({todos:t,isResult:s=!1})=>{if(!t||!Array.isArray(t))return null;const a=l=>{switch(l){case"completed":return e.jsx(nn,{className:"w-4 h-4 text-green-500 dark:text-green-400"});case"in_progress":return e.jsx(_r,{className:"w-4 h-4 text-blue-500 dark:text-blue-400"});case"pending":default:return e.jsx(an,{className:"w-4 h-4 text-gray-400 dark:text-gray-500"})}},o=l=>{switch(l){case"completed":return"bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-200 border-green-200 dark:border-green-800";case"in_progress":return"bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-200 border-blue-200 dark:border-blue-800";case"pending":default:return"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700"}},n=l=>{switch(l){case"high":return"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 border-red-200 dark:border-red-800";case"medium":return"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800";case"low":default:return"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700"}};return e.jsxs("div",{className:"space-y-3",children:[s&&e.jsxs("div",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-3",children:["待办事项列表 (",t.length," 项)"]}),t.map((l,i)=>e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm hover:shadow-md dark:shadow-gray-900/50 transition-shadow",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:a(l.status)}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsx("p",{className:`text-sm font-medium ${l.status==="completed"?"line-through text-gray-500 dark:text-gray-400":"text-gray-900 dark:text-gray-100"}`,children:l.content}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(Ge,{variant:"outline",className:`text-xs px-2 py-0.5 ${n(l.priority)}`,children:l.priority}),e.jsx(Ge,{variant:"outline",className:`text-xs px-2 py-0.5 ${o(l.status)}`,children:l.status.replace("_"," ")})]})]})})]},l.id||`todo-${i}`))]})};function Uo({status:t,onAbort:s,isLoading:a,provider:o="claude"}){const[n,l]=r.useState(0),[i,d]=r.useState(0),[h,g]=r.useState(0);if(r.useEffect(()=>{if(!a){l(0),g(0);return}const C=Date.now(),k=30+Math.random()*20,u=setInterval(()=>{const m=Math.floor((Date.now()-C)/1e3);l(m),g(Math.floor(m*k))},1e3);return()=>clearInterval(u)},[a]),r.useEffect(()=>{if(!a)return;const C=setInterval(()=>{d(k=>(k+1)%4)},500);return()=>clearInterval(C)},[a]),!a)return null;const p=["思考中","处理中","分析中","工作中","计算中","推理中"],w=Math.floor(n/3)%p.length,v=t?.text||p[w],y=t?.tokens||h,x=t?.can_interrupt!==!1,R=["✻","✹","✸","✶"][i];return e.jsx("div",{className:"w-full mb-3 sm:mb-6 animate-in slide-in-from-bottom duration-300",children:e.jsxs("div",{className:"flex items-center justify-between max-w-4xl mx-auto bg-gray-800 dark:bg-gray-900 text-white rounded-lg shadow-lg px-2.5 py-2 sm:px-4 sm:py-3 border border-gray-700 dark:border-gray-800",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx("span",{className:qe("text-base sm:text-xl transition-all duration-500 flex-shrink-0",i%2===0?"text-blue-400 scale-110":"text-blue-300"),children:R}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[e.jsxs("span",{className:"font-medium text-xs sm:text-sm truncate",children:[v,"..."]}),e.jsxs("span",{className:"text-gray-400 text-xs sm:text-sm flex-shrink-0",children:["(",n,"s)"]}),y>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-500 hidden sm:inline",children:"·"}),e.jsxs("span",{className:"text-gray-300 text-xs sm:text-sm hidden sm:inline flex-shrink-0",children:["⚒ ",y.toLocaleString()]})]}),e.jsx("span",{className:"text-gray-500 hidden sm:inline",children:"·"}),e.jsx("span",{className:"text-gray-400 text-xs sm:text-sm hidden sm:inline",children:"按 esc 停止"})]})})]})}),x&&s&&e.jsxs("button",{onClick:s,className:"ml-2 sm:ml-3 text-xs bg-red-600 hover:bg-red-700 active:bg-red-800 text-white px-2 py-1 sm:px-3 sm:py-1.5 rounded-md transition-colors flex items-center gap-1 sm:gap-1.5 flex-shrink-0 font-medium",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",{className:"hidden sm:inline",children:"停止"})]})]})})}async function Ho(t,s){const a=new FormData,o=`recording_${Date.now()}.webm`,n=new File([t],o,{type:t.type});a.append("audio",n);const l=window.localStorage.getItem("whisperMode")||"default";a.append("mode",l);try{const i=await ye.transcribe(a);if(!i.ok){const h=await i.json().catch(()=>({}));throw new Error(h.error||`Transcription error: ${i.status} ${i.statusText}`)}return(await i.json()).text||""}catch(i){throw i.name==="TypeError"&&i.message.includes("fetch")?new Error("Cannot connect to server. Please ensure the backend is running."):i}}function qo({onTranscript:t,className:s=""}){const[a,o]=r.useState("idle"),[n,l]=r.useState(null),[i,d]=r.useState(!0),h=r.useRef(null),g=r.useRef(null),p=r.useRef([]),w=r.useRef(0);r.useEffect(()=>{(()=>{if(!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia){d(!1),l("Microphone not supported. Please use HTTPS or a modern browser.");return}if(location.protocol!=="https:"&&location.hostname!=="localhost"){d(!1),l("Microphone requires HTTPS. Please use a secure connection.");return}d(!0),l(null)})()},[]);const v=async()=>{try{if(console.log("Starting recording..."),l(null),p.current=[],!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)throw new Error("Microphone access not available. Please use HTTPS or a supported browser.");const u=await navigator.mediaDevices.getUserMedia({audio:!0});g.current=u;const m=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",N=new MediaRecorder(u,{mimeType:m});h.current=N,N.ondataavailable=S=>{S.data.size>0&&p.current.push(S.data)},N.onstop=async()=>{console.log("Recording stopped, creating blob...");const S=new Blob(p.current,{type:m});g.current&&(g.current.getTracks().forEach(Z=>Z.stop()),g.current=null),o("transcribing");const f=window.localStorage.getItem("whisperMode")||"default",A=f==="prompt"||f==="vibe"||f==="instructions"||f==="architect";let F;A&&(F=setTimeout(()=>{o("processing")},2e3));try{const Z=await Ho(S);Z&&t&&t(Z)}catch(Z){console.error("Transcription error:",Z),l(Z.message)}finally{F&&clearTimeout(F),o("idle")}},N.start(),o("recording"),console.log("Recording started successfully")}catch(u){console.error("Failed to start recording:",u);let m="Microphone access failed";u.name==="NotAllowedError"?m="Microphone access denied. Please allow microphone permissions.":u.name==="NotFoundError"?m="No microphone found. Please check your audio devices.":u.name==="NotSupportedError"?m="Microphone not supported by this browser.":u.name==="NotReadableError"?m="Microphone is being used by another application.":u.message.includes("HTTPS")&&(m=u.message),l(m),o("idle")}},y=()=>{console.log("Stopping recording..."),h.current&&h.current.state==="recording"?h.current.stop():(console.log("Recorder not in recording state, forcing cleanup"),g.current&&(g.current.getTracks().forEach(u=>u.stop()),g.current=null),o("idle"))},x=u=>{if(u&&(u.preventDefault(),u.stopPropagation()),!i)return;const m=Date.now();if(m-w.current<300){console.log("Ignoring rapid tap");return}w.current=m,console.log("Button clicked, current state:",a),a==="idle"?v():a==="recording"&&y()};r.useEffect(()=>()=>{g.current&&g.current.getTracks().forEach(u=>u.stop())},[]);const P=()=>{if(!i)return{icon:e.jsx(gr,{className:"w-5 h-5"}),className:"bg-gray-400 cursor-not-allowed",disabled:!0};switch(a){case"recording":return{icon:e.jsx(gr,{className:"w-5 h-5 text-white"}),className:"bg-red-500 hover:bg-red-600 animate-pulse",disabled:!1};case"transcribing":return{icon:e.jsx(jt,{className:"w-5 h-5 animate-spin"}),className:"bg-blue-500 hover:bg-blue-600",disabled:!0};case"processing":return{icon:e.jsx(Js,{className:"w-5 h-5 animate-pulse"}),className:"bg-purple-500 hover:bg-purple-600",disabled:!0};default:return{icon:e.jsx(gr,{className:"w-5 h-5"}),className:"bg-gray-700 hover:bg-gray-600",disabled:!1}}},{icon:R,className:C,disabled:k}=P();return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",style:{backgroundColor:a==="recording"?"#ef4444":a==="transcribing"?"#3b82f6":a==="processing"?"#a855f7":"#374151"},className:`
6
+ flex items-center justify-center
7
+ w-12 h-12 rounded-full
8
+ text-white transition-all duration-200
9
+ focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500
10
+ dark:ring-offset-gray-800
11
+ touch-action-manipulation
12
+ ${k?"cursor-not-allowed opacity-75":"cursor-pointer"}
13
+ ${a==="recording"?"animate-pulse":""}
14
+ hover:opacity-90
15
+ ${s}
16
+ `,onClick:x,disabled:k,children:R}),n&&e.jsx("div",{className:`absolute top-full mt-2 left-1/2 transform -translate-x-1/2
17
+ bg-red-500 text-white text-xs px-2 py-1 rounded whitespace-nowrap z-10
18
+ animate-fade-in`,children:n}),a==="recording"&&e.jsx("div",{className:"absolute -inset-1 rounded-full border-2 border-red-500 animate-ping pointer-events-none"}),a==="processing"&&e.jsx("div",{className:"absolute -inset-1 rounded-full border-2 border-purple-500 animate-ping pointer-events-none"})]})}const Jo=({commands:t=[],selectedIndex:s=-1,onSelect:a,onClose:o,position:n={top:0,left:0},isOpen:l=!1,frequentCommands:i=[]})=>{const d=r.useRef(null),h=r.useRef(null),p=(()=>{const k=window.innerWidth<640,u=window.innerHeight;return k?{position:"fixed",bottom:`${n.bottom||90}px`,left:"16px",right:"16px",width:"auto",maxWidth:"calc(100vw - 32px)",maxHeight:"min(50vh, 300px)"}:{position:"fixed",top:`${Math.max(16,Math.min(n.top,u-316))}px`,left:`${n.left}px`,width:"min(400px, calc(100vw - 32px))",maxWidth:"calc(100vw - 32px)",maxHeight:"300px"}})();if(r.useEffect(()=>{const k=u=>{d.current&&!d.current.contains(u.target)&&l&&o()};if(l)return document.addEventListener("mousedown",k),()=>{document.removeEventListener("mousedown",k)}},[l,o]),r.useEffect(()=>{if(h.current&&d.current){const k=d.current.getBoundingClientRect(),u=h.current.getBoundingClientRect();u.bottom>k.bottom?h.current.scrollIntoView({block:"nearest",behavior:"smooth"}):u.top<k.top&&h.current.scrollIntoView({block:"nearest",behavior:"smooth"})}},[s]),!l)return null;if(t.length===0)return e.jsx("div",{ref:d,className:"command-menu command-menu-empty",style:{...p,maxHeight:"300px",borderRadius:"8px",boxShadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",zIndex:1e3,padding:"20px",opacity:1,transform:"translateY(0)",transition:"opacity 150ms ease-in-out, transform 150ms ease-in-out",textAlign:"center"},children:"暂无可用命令"});const w=i.length>0,v=t.reduce((k,u)=>{const m=u.namespace||u.type||"other";return k[m]||(k[m]=[]),k[m].push(u),k},{});w&&(v.frequent=i);const x=(w?["frequent","builtin","project","user","other"]:["builtin","project","user","other"]).filter(k=>v[k]),P={frequent:"⭐ 常用命令",builtin:"内置命令",project:"项目命令",user:"用户命令",other:"其他命令"};let R=0;const C=[];return x.forEach(k=>{v[k].forEach(u=>{C.push({...u,globalIndex:R++,namespace:k})})}),e.jsxs("div",{ref:d,role:"listbox","aria-label":"Available commands",className:"command-menu",style:{...p,maxHeight:"300px",overflowY:"auto",borderRadius:"8px",boxShadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",zIndex:1e3,padding:"8px",opacity:l?1:0,transform:l?"translateY(0)":"translateY(-10px)",transition:"opacity 150ms ease-in-out, transform 150ms ease-in-out"},children:[x.map(k=>e.jsxs("div",{className:"command-group",children:[x.length>1&&e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"#6b7280",padding:"8px 12px 4px",letterSpacing:"0.05em"},children:P[k]||k}),v[k].map(u=>{const m=C.find(S=>S.name===u.name&&S.namespace===k),N=m&&m.globalIndex===s;return e.jsxs("div",{ref:N?h:null,role:"option","aria-selected":N,className:"command-item",onMouseEnter:()=>a&&a(u,m.globalIndex,!0),onClick:()=>a&&a(u,m.globalIndex,!1),style:{display:"flex",alignItems:"flex-start",padding:"10px 12px",borderRadius:"6px",cursor:"pointer",backgroundColor:N?"#eff6ff":"transparent",transition:"background-color 100ms ease-in-out",marginBottom:"2px"},onMouseDown:S=>S.preventDefault(),children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:u.description?"4px":0},children:[e.jsxs("span",{style:{fontSize:"16px",flexShrink:0},children:[k==="builtin"&&"⚡",k==="project"&&"📁",k==="user"&&"👤",k==="other"&&"📝"]}),e.jsx("span",{style:{fontWeight:600,fontSize:"14px",color:"#111827",fontFamily:"monospace"},children:u.name}),u.metadata?.type&&e.jsx("span",{className:"command-metadata-badge",style:{fontSize:"10px",padding:"2px 6px",borderRadius:"4px",backgroundColor:"#f3f4f6",color:"#6b7280",fontWeight:500},children:u.metadata.type})]}),u.description&&e.jsx("div",{style:{fontSize:"13px",color:"#6b7280",marginLeft:"24px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.description})]}),N&&e.jsx("span",{style:{marginLeft:"8px",color:"#3b82f6",fontSize:"12px",fontWeight:600},children:"↵"})]},`${k}-${u.name}`)})]},k)),e.jsx("style",{children:`
19
+ .command-menu {
20
+ background-color: white;
21
+ border: 1px solid #e5e7eb;
22
+ }
23
+ .command-menu-empty {
24
+ color: #6b7280;
25
+ }
26
+
27
+ @media (prefers-color-scheme: dark) {
28
+ .command-menu {
29
+ background-color: #1f2937 !important;
30
+ border: 1px solid #374151 !important;
31
+ }
32
+ .command-menu-empty {
33
+ color: #9ca3af !important;
34
+ }
35
+ .command-item[aria-selected="true"] {
36
+ background-color: #1e40af !important;
37
+ }
38
+ .command-item span:not(.command-metadata-badge) {
39
+ color: #f3f4f6 !important;
40
+ }
41
+ .command-metadata-badge {
42
+ background-color: #f3f4f6 !important;
43
+ color: #6b7280 !important;
44
+ }
45
+ .command-item div {
46
+ color: #d1d5db !important;
47
+ }
48
+ .command-group > div:first-child {
49
+ color: #9ca3af !important;
50
+ }
51
+ }
52
+ `})]})},Ws={OPTIONS:[{value:"sonnet",label:"Sonnet"},{value:"opus",label:"Opus"},{value:"haiku",label:"Haiku"}],DEFAULT:"sonnet"};function Wt(t){return t&&t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&amp;/g,"&")}function Ko(t){if(!t||typeof t!="string")return t;try{return t.replace(/```\s*([^\n\r]+?)\s*```/g,"`$1`")}catch{return t}}function xr(t){if(!t||typeof t!="string")return t;const s=[],a="__MATH_BLOCK_",o="__";let n=t.replace(/\$\$([\s\S]*?)\$\$|\$([^\$\n]+?)\$/g,l=>{const i=s.length;return s.push(l),`${a}${i}${o}`});return n=n.replace(/\\n/g,`
53
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r"),n=n.replace(new RegExp(`${a}(\\d+)${o}`,"g"),(l,i)=>s[parseInt(i)]),n}const Bt=({children:t,className:s})=>{const a=Ko(String(t??"")),o=r.useMemo(()=>[Sn,Cn],[]),n=r.useMemo(()=>[En],[]);return e.jsx("div",{className:s,children:e.jsx(Mn,{remarkPlugins:o,rehypePlugins:n,components:Yo,children:a})})};function Vr(t){try{return typeof t!="string"?t:t.replace(/Claude AI usage limit reached\|(\d{10,13})/g,(s,a)=>{let o=parseInt(a,10);if(!Number.isFinite(o))return s;o<1e12&&(o*=1e3);const n=new Date(o),l=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(n),i=-n.getTimezoneOffset(),d=i>=0?"+":"-",h=Math.abs(i),g=Math.floor(h/60),p=h%60,w=`GMT${d}${g}${p?":"+String(p).padStart(2,"0"):""}`,x=((Intl.DateTimeFormat().resolvedOptions().timeZone||"").split("/").pop()||"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,k=>k.toUpperCase()),P=x?`${w} (${x})`:w,R=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],C=`${n.getDate()} ${R[n.getMonth()]} ${n.getFullYear()}`;return`Claude usage limit reached. Your limit will reset at **${l} ${P}** - ${C}`})}catch{return t}}const Ze={setItem:(t,s)=>{try{if(t.startsWith("chat_messages_")&&typeof s=="string")try{const a=JSON.parse(s);if(Array.isArray(a)&&a.length>50){console.warn(`Truncating chat history for ${t} from ${a.length} to 50 messages`);const o=a.slice(-50);s=JSON.stringify(o)}}catch(a){console.warn("Could not parse chat messages for truncation:",a)}localStorage.setItem(t,s)}catch(a){if(a.name==="QuotaExceededError"){console.warn("localStorage quota exceeded, clearing old data");const o=Object.keys(localStorage),n=o.filter(i=>i.startsWith("chat_messages_")).sort();n.length>3&&n.slice(0,n.length-3).forEach(i=>{localStorage.removeItem(i),console.log(`Removed old chat data: ${i}`)}),o.filter(i=>i.startsWith("draft_input_")).forEach(i=>{localStorage.removeItem(i)});try{localStorage.setItem(t,s)}catch(i){if(console.error("Failed to save to localStorage even after cleanup:",i),t.startsWith("chat_messages_")&&typeof s=="string")try{const d=JSON.parse(s);if(Array.isArray(d)&&d.length>10){const h=d.slice(-10);localStorage.setItem(t,JSON.stringify(h)),console.warn("Saved only last 10 messages due to quota constraints")}}catch(d){console.error("Final save attempt failed:",d)}}}else console.error("localStorage error:",a)}},getItem:t=>{try{return localStorage.getItem(t)}catch(s){return console.error("localStorage getItem error:",s),null}},removeItem:t=>{try{localStorage.removeItem(t)}catch(s){console.error("localStorage removeItem error:",s)}}},pa="claude-settings";function as(){const t=Ze.getItem(pa);if(!t)return{allowedTools:[],disallowedTools:[],skipPermissions:!1,projectSortOrder:"name"};try{const s=JSON.parse(t);return{...s,allowedTools:Array.isArray(s.allowedTools)?s.allowedTools:[],disallowedTools:Array.isArray(s.disallowedTools)?s.disallowedTools:[],skipPermissions:!!s.skipPermissions,projectSortOrder:s.projectSortOrder||"name"}}catch{return{allowedTools:[],disallowedTools:[],skipPermissions:!1,projectSortOrder:"name"}}}function Yr(t,s){if(!t)return null;if(t!=="Bash")return t;const a=On(s),o=typeof a?.command=="string"?a.command.trim():"";if(!o)return t;const n=o.split(/\s+/);return n.length===0?t:n[0]==="git"&&n[1]?`Bash(${n[0]} ${n[1]}:*)`:`Bash(${n[0]}:*)`}function Bs(t){if(t==null)return"";if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function Go(t,s){if(s!=="claude"||!t?.toolResult?.isError)return null;const a=t?.toolName,o=Yr(a,t.toolInput);if(!o)return null;const l=as().allowedTools.includes(o);return{toolName:a,entry:o,isAllowed:l}}function Vo(t){if(!t)return{success:!1};const s=as(),a=s.allowedTools.includes(t),o=a?s.allowedTools:[...s.allowedTools,t],n=s.disallowedTools.filter(i=>i!==t),l={...s,allowedTools:o,disallowedTools:n,lastUpdated:new Date().toISOString()};return Ze.setItem(pa,JSON.stringify(l)),{success:!0,alreadyAllowed:a,updatedSettings:l}}const Yo={code:({node:t,inline:s,className:a,children:o,...n})=>{const[l,i]=rt.useState(!1),d=Array.isArray(o)?o.join(""):String(o??""),h=/[\r\n]/.test(d);if(s||t&&t.type==="inlineCode"||!h)return e.jsx("code",{className:`font-mono text-[0.9em] px-1.5 py-0.5 rounded-md bg-gray-100 text-gray-900 border border-gray-200 dark:bg-gray-800/60 dark:text-gray-100 dark:border-gray-700 whitespace-pre-wrap break-words ${a||""}`,...n,children:o});const w=/language-(\w+)/.exec(a||""),v=w?w[1]:"text",y=d,x=()=>{const P=()=>{i(!0),setTimeout(()=>i(!1),1500)};try{if(navigator&&navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(y).then(P).catch(()=>{const R=document.createElement("textarea");R.value=y,R.style.position="fixed",R.style.opacity="0",document.body.appendChild(R),R.select();try{document.execCommand("copy")}catch{}document.body.removeChild(R),P()});else{const R=document.createElement("textarea");R.value=y,R.style.position="fixed",R.style.opacity="0",document.body.appendChild(R),R.select();try{document.execCommand("copy")}catch{}document.body.removeChild(R),P()}}catch{}};return e.jsxs("div",{className:"relative group my-2",children:[v&&v!=="text"&&e.jsx("div",{className:"absolute top-2 left-3 z-10 text-xs text-gray-400 font-medium uppercase",children:v}),e.jsx("button",{type:"button",onClick:x,className:"absolute top-2 right-2 z-10 opacity-0 group-hover:opacity-100 focus:opacity-100 active:opacity-100 transition-opacity text-xs px-2 py-1 rounded-md bg-gray-700/80 hover:bg-gray-700 text-white border border-gray-600",title:l?"已复制":"复制代码","aria-label":l?"已复制":"复制代码",children:l?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),"已复制"]}):e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsxs("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]}),"复制"]})}),e.jsx(Ln,{language:v,style:Bn,customStyle:{margin:0,borderRadius:"0.5rem",fontSize:"0.875rem",padding:v&&v!=="text"?"2rem 1rem 1rem 1rem":"1rem"},codeTagProps:{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'}},children:d})]})},blockquote:({children:t})=>e.jsx("blockquote",{className:"border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic text-gray-600 dark:text-gray-400 my-2",children:t}),a:({href:t,children:s})=>e.jsx("a",{href:t,className:"text-blue-600 dark:text-blue-400 hover:underline",target:"_blank",rel:"noopener noreferrer",children:s}),p:({children:t})=>e.jsx("div",{className:"mb-2 last:mb-0",children:t}),table:({children:t})=>e.jsx("div",{className:"overflow-x-auto my-2",children:e.jsx("table",{className:"min-w-full border-collapse border border-gray-200 dark:border-gray-700",children:t})}),thead:({children:t})=>e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-800",children:t}),th:({children:t})=>e.jsx("th",{className:"px-3 py-2 text-left text-sm font-semibold border border-gray-200 dark:border-gray-700",children:t}),td:({children:t})=>e.jsx("td",{className:"px-3 py-2 align-top text-sm border border-gray-200 dark:border-gray-700",children:t})};function Qo({request:t,onSubmit:s,onSkip:a}){const o=t.input?.questions||[],[n,l]=rt.useState(()=>Object.fromEntries(o.map(g=>[g.question,[]]))),i=(g,p,w)=>{l(v=>{const y=v[g]||[];return w?{...v,[g]:y.includes(p)?y.filter(x=>x!==p):[...y,p]}:{...v,[g]:[p]}})},d=o.every(g=>(n[g.question]||[]).length>0),h=()=>{const g={};o.forEach(p=>{g[p.question]=(n[p.question]||[]).join(", ")}),s(g)};return e.jsxs("div",{className:"rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 p-3 shadow-sm",children:[e.jsx("div",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100 mb-3",children:"Claude 需要您的回答"}),o.map((g,p)=>e.jsxs("div",{className:p<o.length-1?"mb-4":"mb-0",children:[e.jsxs("div",{className:"text-sm font-medium text-blue-800 dark:text-blue-200 mb-2",children:[g.question,g.multiSelect&&e.jsx("span",{className:"ml-2 text-xs font-normal opacity-60",children:"(可多选)"})]}),e.jsx("div",{className:"space-y-1",children:g.options.map((w,v)=>{const y=(n[g.question]||[]).includes(w.label);return e.jsxs("button",{type:"button",onClick:()=>i(g.question,w.label,g.multiSelect),className:`w-full text-left px-3 py-2 rounded-md text-xs border transition-colors ${y?"bg-blue-600 text-white border-blue-600":"bg-white dark:bg-gray-800 border-blue-200 dark:border-blue-700 text-blue-800 dark:text-blue-200 hover:bg-blue-50 dark:hover:bg-blue-900/30"}`,children:[e.jsx("span",{className:"font-medium",children:w.label}),w.description&&e.jsxs("span",{className:"ml-1 opacity-70",children:[" — ",w.description]})]},v)})})]},p)),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx("button",{type:"button",onClick:h,disabled:!d,className:"inline-flex items-center gap-2 rounded-md bg-blue-600 text-white text-xs font-medium px-3 py-1.5 hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:"提交答案"}),e.jsx("button",{type:"button",onClick:a,className:"inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border border-gray-300 text-gray-600 hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800/30 transition-colors",children:"跳过"})]})]})}const Zo=r.memo(({message:t,index:s,prevMessage:a,createDiff:o,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,autoExpandTools:d,showRawParameters:h,showThinking:g,selectedProject:p,provider:w})=>{const v=a&&a.type===t.type&&(a.type==="assistant"||a.type==="user"||a.type==="tool"||a.type==="error"),y=rt.useRef(null),[x,P]=rt.useState(!1),R=Go(t,w),[C,k]=rt.useState("idle");return rt.useEffect(()=>{k("idle")},[R?.entry,t.toolId]),rt.useEffect(()=>{if(!d||!y.current||!t.isToolUse)return;const u=new IntersectionObserver(m=>{m.forEach(N=>{N.isIntersecting&&!x&&(P(!0),y.current.querySelectorAll("details").forEach(f=>{f.open=!0}))})},{threshold:.1});return u.observe(y.current),()=>{y.current&&u.unobserve(y.current)}},[d,x,t.isToolUse]),e.jsx("div",{ref:y,className:`chat-message ${t.type} ${v?"grouped":""} ${t.type==="user"?"flex justify-end px-3 sm:px-0":"px-3 sm:px-0"}`,children:t.type==="user"?e.jsxs("div",{className:"flex items-end space-x-0 sm:space-x-3 w-full sm:w-auto sm:max-w-[85%] md:max-w-md lg:max-w-lg xl:max-w-xl",children:[e.jsxs("div",{className:"bg-blue-600 text-white rounded-2xl rounded-br-md px-3 sm:px-4 py-2 shadow-sm flex-1 sm:flex-initial",children:[e.jsx("div",{className:"text-sm whitespace-pre-wrap break-words",children:t.content}),t.images&&t.images.length>0&&e.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:t.images.map((u,m)=>e.jsx("img",{src:u.data,alt:u.name,className:"rounded-lg max-w-full h-auto cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(u.data,"_blank")},m))}),e.jsx("div",{className:"text-xs text-blue-100 mt-1 text-right",children:new Date(t.timestamp).toLocaleTimeString()})]}),!v&&e.jsx("div",{className:"hidden sm:flex w-8 h-8 bg-blue-600 rounded-full items-center justify-center text-white text-sm flex-shrink-0",children:"U"})]}):e.jsxs("div",{className:"w-full",children:[!v&&e.jsxs("div",{className:"flex items-center space-x-3 mb-2",children:[t.type==="error"?e.jsx("div",{className:"w-8 h-8 bg-red-600 rounded-full flex items-center justify-center text-white text-sm flex-shrink-0",children:"!"}):t.type==="tool"?e.jsx("div",{className:"w-8 h-8 bg-gray-600 dark:bg-gray-700 rounded-full flex items-center justify-center text-white text-sm flex-shrink-0",children:"🔧"}):e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-white text-sm flex-shrink-0 p-1",children:e.jsx(mt,{className:"w-full h-full"})}),e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:t.type==="error"?"错误":t.type==="tool"?"工具":"Claude"})]}),e.jsxs("div",{className:"w-full",children:[t.isToolUse&&!["Read","TodoWrite","TodoRead"].includes(t.toolName)?["Grep","Glob"].includes(t.toolName)?e.jsx(e.Fragment,{children:e.jsx("div",{className:"group relative bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-blue-400 dark:border-blue-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400 flex-1 min-w-0",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-blue-500 dark:text-blue-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),e.jsx("span",{className:"font-medium flex-shrink-0",children:t.toolName}),e.jsx("span",{className:"text-gray-400 dark:text-gray-500 flex-shrink-0",children:"•"}),t.toolInput&&(()=>{try{const m=JSON.parse(t.toolInput);return e.jsxs("span",{className:"font-mono truncate flex-1 min-w-0",children:[m.pattern&&e.jsxs("span",{children:["pattern: ",e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:m.pattern})]}),m.path&&e.jsxs("span",{className:"ml-2",children:["in: ",m.path]})]})}catch{return null}})()]}),t.toolResult&&e.jsxs("a",{href:`#tool-result-${t.toolId}`,className:"flex-shrink-0 text-xs text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 font-medium transition-colors flex items-center gap-1",children:[e.jsx("span",{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:"M19 9l-7 7-7-7"})})]})]})})}):e.jsxs("div",{className:"group relative bg-gradient-to-br from-blue-50/50 to-indigo-50/50 dark:from-blue-950/20 dark:to-indigo-950/20 border border-blue-100/30 dark:border-blue-800/30 rounded-lg p-3 mb-2",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500/3 to-indigo-500/3 dark:from-blue-400/3 dark:to-indigo-400/3 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity duration-300"}),e.jsxs("div",{className:"relative flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative w-8 h-8 bg-gradient-to-br from-blue-500 to-indigo-600 dark:from-blue-400 dark:to-indigo-500 rounded-lg flex items-center justify-center shadow-lg shadow-blue-500/20 dark:shadow-blue-400/20",children:[e.jsxs("svg",{className:"w-4 h-4 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),e.jsx("div",{className:"absolute inset-0 rounded-lg bg-blue-500 dark:bg-blue-400 animate-pulse opacity-20"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-semibold text-gray-900 dark:text-white text-sm",children:t.toolName}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-mono",children:t.toolId})]})]}),l&&e.jsx("button",{onClick:m=>{m.stopPropagation(),l()},className:"p-2 rounded-lg hover:bg-white/60 dark:hover:bg-gray-800/60 transition-all duration-200 group/btn backdrop-blur-sm",title:"工具设置",children:e.jsxs("svg",{className:"w-4 h-4 text-gray-600 dark:text-gray-400 group-hover/btn:text-blue-600 dark:group-hover/btn:text-blue-400 transition-colors",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]}),t.toolInput&&t.toolName==="Edit"&&(()=>{try{const m=JSON.parse(t.toolInput);if(m.file_path&&m.old_string&&m.new_string)return e.jsxs("details",{className:"relative mt-3 group/details",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/details:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),e.jsx("span",{className:"flex items-center gap-2",children:e.jsx("span",{children:"查看编辑差异"})}),e.jsx("button",{onClick:async N=>{if(N.preventDefault(),N.stopPropagation(),!!n)try{const S=await ye.readFile(p?.name,m.file_path),f=await S.json();if(!S.ok||f.error){console.error("Failed to fetch file:",f.error),n(m.file_path);return}const A=f.content||"",F=A.replace(m.new_string,m.old_string);n(m.file_path,{old_string:F,new_string:A})}catch(S){console.error("Error preparing diff:",S),n(m.file_path)}},className:"px-2.5 py-1 rounded-md bg-white/60 dark:bg-gray-800/60 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/30 font-mono text-xs font-medium transition-all duration-200 shadow-sm",children:m.file_path.split("/").pop()})]}),e.jsxs("div",{className:"mt-3 pl-6",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-900/50 border border-gray-200/60 dark:border-gray-700/60 rounded-lg overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 bg-gradient-to-r from-gray-50 to-gray-100/50 dark:from-gray-800/80 dark:to-gray-800/40 border-b border-gray-200/60 dark:border-gray-700/60 backdrop-blur-sm",children:[e.jsx("button",{onClick:async()=>{if(n)try{const N=await ye.readFile(p?.name,m.file_path),S=await N.json();if(!N.ok||S.error){console.error("Failed to fetch file:",S.error),n(m.file_path);return}const f=S.content||"",A=f.replace(m.new_string,m.old_string);n(m.file_path,{old_string:A,new_string:f})}catch(N){console.error("Error preparing diff:",N),n(m.file_path)}},className:"text-xs font-mono text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 truncate cursor-pointer font-medium transition-colors",children:m.file_path}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-medium px-2 py-0.5 bg-gray-100 dark:bg-gray-700/50 rounded",children:"Diff"})]}),e.jsx("div",{className:"text-xs font-mono",children:o(m.old_string,m.new_string).map((N,S)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${N.type==="removed"?"bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 border-red-200 dark:border-red-800":"bg-green-50 dark:bg-green-900/20 text-green-600 dark:text-green-400 border-green-200 dark:border-green-800"}`,children:N.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${N.type==="removed"?"bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200":"bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200"}`,children:N.content})]},S))})]}),h&&e.jsxs("details",{className:"relative mt-3 pl-6 group/raw",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-xs font-medium text-gray-600 dark:text-gray-400 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-3 h-3 transition-transform duration-200 group-open/raw:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看原始参数"]}),e.jsx("pre",{className:"mt-2 text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-3 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-700 dark:text-gray-300 font-mono",children:t.toolInput})]})]})]})}catch{}return e.jsxs("details",{className:"relative mt-3 group/params",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/params:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看输入参数"]}),e.jsx("pre",{className:"mt-3 text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-3 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-700 dark:text-gray-300 font-mono",children:t.toolInput})]})})(),t.toolInput&&t.toolName!=="Edit"&&(()=>{if(t.toolName==="Write")try{let m;if(typeof t.toolInput=="string"?m=JSON.parse(t.toolInput):m=t.toolInput,m.file_path&&m.content!==void 0)return e.jsxs("details",{className:"relative mt-3 group/details",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/details:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg leading-none",children:"📄"}),e.jsx("span",{children:"创建新文件:"})]}),e.jsx("button",{onClick:async N=>{if(N.preventDefault(),N.stopPropagation(),!!n)try{const S=await ye.readFile(p?.name,m.file_path),f=await S.json(),A=S.ok&&!f.error?f.content||"":m.content||"";n(m.file_path,{old_string:"",new_string:A})}catch(S){console.error("Error preparing diff:",S),n(m.file_path,{old_string:"",new_string:m.content||""})}},className:"px-2.5 py-1 rounded-md bg-white/60 dark:bg-gray-800/60 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/30 font-mono text-xs font-medium transition-all duration-200 shadow-sm",children:m.file_path.split("/").pop()})]}),e.jsxs("div",{className:"mt-3 pl-6",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-900/50 border border-gray-200/60 dark:border-gray-700/60 rounded-lg overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 bg-gradient-to-r from-gray-50 to-gray-100/50 dark:from-gray-800/80 dark:to-gray-800/40 border-b border-gray-200/60 dark:border-gray-700/60 backdrop-blur-sm",children:[e.jsx("button",{onClick:async()=>{if(n)try{const N=await ye.readFile(p?.name,m.file_path),S=await N.json(),f=N.ok&&!S.error?S.content||"":m.content||"";n(m.file_path,{old_string:"",new_string:f})}catch(N){console.error("Error preparing diff:",N),n(m.file_path,{old_string:"",new_string:m.content||""})}},className:"text-xs font-mono text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 truncate cursor-pointer font-medium transition-colors",children:m.file_path}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-medium px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded",children:"新文件"})]}),e.jsx("div",{className:"text-xs font-mono",children:o("",m.content).map((N,S)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${N.type==="removed"?"bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 border-red-200 dark:border-red-800":"bg-green-50 dark:bg-green-900/20 text-green-600 dark:text-green-400 border-green-200 dark:border-green-800"}`,children:N.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${N.type==="removed"?"bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200":"bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200"}`,children:N.content})]},S))})]}),h&&e.jsxs("details",{className:"relative mt-3 pl-6 group/raw",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-xs font-medium text-gray-600 dark:text-gray-400 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-3 h-3 transition-transform duration-200 group-open/raw:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看原始参数"]}),e.jsx("pre",{className:"mt-2 text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-3 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-700 dark:text-gray-300 font-mono",children:t.toolInput})]})]})]})}catch{}if(t.toolName==="TodoWrite")try{const m=JSON.parse(t.toolInput);if(m.todos&&Array.isArray(m.todos))return e.jsxs("details",{className:"relative mt-3 group/todo",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/todo:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg leading-none",children:"✓"}),e.jsx("span",{children:"更新待办列表"})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx(zr,{todos:m.todos}),h&&e.jsxs("details",{className:"relative mt-3 group/raw",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-xs font-medium text-gray-600 dark:text-gray-400 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-3 h-3 transition-transform duration-200 group-open/raw:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看原始参数"]}),e.jsx("pre",{className:"mt-2 text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-3 rounded-lg overflow-x-auto text-gray-700 dark:text-gray-300 font-mono",children:t.toolInput})]})]})]})}catch{}if(t.toolName==="Bash")try{const m=JSON.parse(t.toolInput);return e.jsxs("div",{className:"my-2",children:[e.jsxs("div",{className:"bg-gray-900 dark:bg-gray-950 rounded-md px-3 py-2 font-mono text-sm",children:[e.jsx("span",{className:"text-green-400",children:"$"}),e.jsx("span",{className:"text-gray-100 ml-2",children:m.command})]}),m.description&&e.jsx("div",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400 italic ml-1",children:m.description})]})}catch{}if(t.toolName==="Read")try{const m=JSON.parse(t.toolInput);if(m.file_path){const N=m.file_path.split("/").pop();return e.jsxs("div",{className:"mt-2 text-sm text-blue-700 dark:text-blue-300",children:["Read"," ",e.jsx("button",{onClick:()=>n&&n(m.file_path),className:"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline font-mono",children:N})]})}}catch{}if(t.toolName==="exit_plan_mode")try{const m=JSON.parse(t.toolInput);if(m.plan){const N=m.plan.replace(/\\n/g,`
54
+ `);return e.jsxs("details",{className:"mt-2",open:d,children:[e.jsxs("summary",{className:"text-sm text-blue-700 dark:text-blue-300 cursor-pointer hover:text-blue-800 dark:hover:text-blue-200 flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform details-chevron",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"📋 查看实现计划"]}),e.jsx(Bt,{className:"mt-3 prose prose-sm max-w-none dark:prose-invert",children:N})]})}}catch{}return e.jsxs("details",{className:"relative mt-3 group/params",open:d,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/params:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看输入参数"]}),e.jsx("pre",{className:"mt-3 text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-3 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-700 dark:text-gray-300 font-mono",children:t.toolInput})]})})(),t.toolResult&&(!t.toolResult.isError&&(t.toolName==="Edit"||t.toolName==="Write"||t.toolName==="ApplyPatch"||t.toolName==="Bash")?null:e.jsxs("div",{id:`tool-result-${t.toolId}`,className:`relative mt-4 p-4 rounded-lg border backdrop-blur-sm scroll-mt-4 ${t.toolResult.isError?"bg-gradient-to-br from-red-50 to-rose-50 dark:from-red-950/20 dark:to-rose-950/20 border-red-200/60 dark:border-red-800/60":"bg-gradient-to-br from-green-50 to-emerald-50 dark:from-green-950/20 dark:to-emerald-950/20 border-green-200/60 dark:border-green-800/60"}`,children:[e.jsx("div",{className:`absolute inset-0 rounded-lg opacity-50 ${t.toolResult.isError?"bg-gradient-to-br from-red-500/5 to-rose-500/5 dark:from-red-400/5 dark:to-rose-400/5":"bg-gradient-to-br from-green-500/5 to-emerald-500/5 dark:from-green-400/5 dark:to-emerald-400/5"}`}),e.jsxs("div",{className:"relative flex items-center gap-2.5 mb-3",children:[e.jsx("div",{className:`w-6 h-6 rounded-lg flex items-center justify-center shadow-md ${t.toolResult.isError?"bg-gradient-to-br from-red-500 to-rose-600 dark:from-red-400 dark:to-rose-500 shadow-red-500/20":"bg-gradient-to-br from-green-500 to-emerald-600 dark:from-green-400 dark:to-emerald-500 shadow-green-500/20"}`,children:e.jsx("svg",{className:"w-3.5 h-3.5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.toolResult.isError?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M6 18L18 6M6 6l12 12"}):e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:`text-sm font-semibold ${t.toolResult.isError?"text-red-800 dark:text-red-200":"text-green-800 dark:text-green-200"}`,children:t.toolResult.isError?"工具错误":"工具结果"})]}),e.jsxs("div",{className:`relative text-sm ${t.toolResult.isError?"text-red-900 dark:text-red-100":"text-green-900 dark:text-green-100"}`,children:[(()=>{const N=String(t.toolResult.content||"");if((t.toolName==="TodoWrite"||t.toolName==="TodoRead")&&(N.includes("Todos have been modified successfully")||N.includes("Todo list")||N.startsWith("[")&&N.includes('"content"')&&N.includes('"status"')))try{let A=null;if(N.startsWith("["))A=JSON.parse(N);else if(N.includes("Todos have been modified successfully"))return e.jsx("div",{children:e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"font-medium",children:"待办列表已更新成功"})})});if(A&&Array.isArray(A))return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("span",{className:"font-medium",children:"当前待办列表"})}),e.jsx(zr,{todos:A,isResult:!0})]})}catch{}if(t.toolName==="exit_plan_mode")try{const A=JSON.parse(N);if(A.plan){const F=A.plan.replace(/\\n/g,`
55
+ `);return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("span",{className:"font-medium",children:"实现计划"})}),e.jsx(Bt,{className:"prose prose-sm max-w-none dark:prose-invert",children:F})]})}}catch{}if((t.toolName==="Grep"||t.toolName==="Glob")&&t.toolResult?.toolUseResult){const A=t.toolResult.toolUseResult;if(A.filenames&&Array.isArray(A.filenames)&&A.filenames.length>0)return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsxs("span",{className:"font-medium",children:["找到 ",A.numFiles||A.filenames.length," 个文件"]})}),e.jsx("div",{className:"space-y-1 max-h-96 overflow-y-auto",children:A.filenames.map((F,Z)=>{const le=F.split("/").pop(),ee=F.substring(0,F.lastIndexOf("/"));return e.jsxs("div",{onClick:()=>{n&&n(F)},className:"group flex items-center gap-2 px-2 py-1.5 rounded hover:bg-green-100/50 dark:hover:bg-green-800/20 cursor-pointer transition-colors",children:[e.jsx("svg",{className:"w-4 h-4 text-green-600 dark:text-green-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-mono text-sm font-medium text-green-800 dark:text-green-200 truncate group-hover:text-green-900 dark:group-hover:text-green-100",children:le}),e.jsx("div",{className:"font-mono text-xs text-green-600/70 dark:text-green-400/70 truncate",children:ee})]}),e.jsx("svg",{className:"w-4 h-4 text-green-600 dark:text-green-400 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},Z)})})]})}if(N.includes("Do you want to proceed?")&&t.toolName==="Bash"){const A=N.split(`
56
+ `),F=A.findIndex(X=>X.includes("Do you want to proceed?")),Z=A.slice(0,F).join(`
57
+ `),le=A.slice(F),ee=le.find(X=>X.includes("Do you want to proceed?"))||"",ne=[];le.forEach(X=>{const se=X.match(/^\s*(\d+)\.\s+(.+)$/);se&&ne.push({number:se[1],text:se[2].trim()})});const U=N.match(/>\s*(\d+)/),D=U?U[1]:null;return e.jsxs("div",{className:"space-y-3",children:[Z&&e.jsx("div",{className:"bg-gray-900 dark:bg-gray-950 text-gray-100 rounded-lg p-3 font-mono text-xs overflow-x-auto",children:e.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Z})}),e.jsx("div",{className:"bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-amber-500 rounded-full flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-amber-900 dark:text-amber-100 text-base mb-2",children:"交互式提示"}),e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200 mb-4",children:ee}),e.jsx("div",{className:"space-y-2 mb-4",children:ne.map(X=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${D===X.number?"bg-amber-600 dark:bg-amber-700 text-white border-amber-600 dark:border-amber-700 shadow-md":"bg-white dark:bg-gray-800 text-amber-900 dark:text-amber-100 border-amber-300 dark:border-amber-700 hover:border-amber-400 dark:hover:border-amber-600 hover:shadow-sm"} ${D?"cursor-default":"cursor-not-allowed opacity-75"}`,disabled:!0,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold ${D===X.number?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:X.number}),e.jsx("span",{className:"text-sm sm:text-base font-medium flex-1",children:X.text}),D===X.number&&e.jsx("svg",{className:"w-5 h-5 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]})},X.number))}),D&&e.jsxs("div",{className:"bg-amber-100 dark:bg-amber-800/30 rounded-lg p-3",children:[e.jsxs("p",{className:"text-amber-900 dark:text-amber-100 text-sm font-medium mb-1",children:["✓ Claude 选择了选项 ",D]}),e.jsx("p",{className:"text-amber-800 dark:text-amber-200 text-xs",children:"在 CLI 中,您可以使用方向键或输入数字来交互式地选择此选项。"})]})]})]})})]})}const S=N.match(/The file (.+?) has been updated\./);if(S)return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"font-medium",children:"文件更新成功"})}),e.jsx("button",{onClick:()=>{n&&n(S[1])},className:"text-xs font-mono bg-green-100 dark:bg-green-800/30 px-2 py-1 rounded text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline cursor-pointer",children:S[1]})]});const f=N.match(/(?:The file|File) (.+?) has been (?:created|written)(?: successfully)?\.?/);return f?e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"font-medium",children:"文件创建成功"})}),e.jsx("button",{onClick:()=>{n&&n(f[1])},className:"text-xs font-mono bg-green-100 dark:bg-green-800/30 px-2 py-1 rounded text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline cursor-pointer",children:f[1]})]}):t.toolName==="Write"&&!t.toolResult.isError?e.jsxs("div",{className:"text-green-700 dark:text-green-300",children:[e.jsxs("div",{className:"flex items-center gap-2",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:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("span",{className:"font-medium",children:"文件写入成功"})]}),e.jsx("p",{className:"text-xs mt-1 text-green-600 dark:text-green-400",children:"文件内容显示在上方的差异视图中"})]}):N.includes("cat -n")&&N.includes("→")?e.jsxs("details",{open:d,children:[e.jsxs("summary",{className:"text-sm text-green-700 dark:text-green-300 cursor-pointer hover:text-green-800 dark:hover:text-green-200 mb-2 flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform details-chevron",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看文件内容"]}),e.jsx("div",{className:"mt-2 bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:e.jsx("div",{className:"text-xs font-mono p-3 whitespace-pre-wrap break-words overflow-hidden",children:N})})]}):N.length>300?e.jsxs("details",{open:d,children:[e.jsxs("summary",{className:"text-sm text-green-700 dark:text-green-300 cursor-pointer hover:text-green-800 dark:hover:text-green-200 mb-2 flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform details-chevron",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看完整输出 (",N.length," 字符)"]}),e.jsx(Bt,{className:"mt-2 prose prose-sm max-w-none prose-green dark:prose-invert",children:N})]}):e.jsx(Bt,{className:"prose prose-sm max-w-none prose-green dark:prose-invert",children:N})})(),R&&e.jsxs("div",{className:"mt-4 border-t border-red-200/60 dark:border-red-800/60 pt-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{if(!i)return;i(R)?.success?k("granted"):k("error")},disabled:R.isAllowed||C==="granted",className:`inline-flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-medium border transition-colors ${R.isAllowed||C==="granted"?"bg-green-100 dark:bg-green-900/30 border-green-300/70 dark:border-green-800/60 text-green-800 dark:text-green-200 cursor-default":"bg-white/80 dark:bg-gray-900/40 border-red-300/70 dark:border-red-800/60 text-red-700 dark:text-red-200 hover:bg-white dark:hover:bg-gray-900/70"}`,children:R.isAllowed||C==="granted"?"权限已添加":`授予权限 ${R.toolName}`}),l&&e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),l()},className:"text-xs text-red-700 dark:text-red-200 underline hover:text-red-800 dark:hover:text-red-100",children:"打开设置"})]}),e.jsxs("div",{className:"mt-2 text-xs text-red-700/90 dark:text-red-200/80",children:["添加 ",e.jsx("span",{className:"font-mono",children:R.entry})," 到允许的工具列表。"]}),C==="error"&&e.jsx("div",{className:"mt-2 text-xs text-red-700 dark:text-red-200",children:"无法更新权限。请重试。"}),(R.isAllowed||C==="granted")&&e.jsx("div",{className:"mt-2 text-xs text-green-700 dark:text-green-200",children:"权限已保存。请重试请求以使用该工具。"})]})]})]}))]}):t.isInteractivePrompt?e.jsx("div",{className:"bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-amber-500 rounded-full flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-amber-900 dark:text-amber-100 text-base mb-3",children:"交互式提示"}),(()=>{const u=t.content.split(`
58
+ `).filter(S=>S.trim()),m=u.find(S=>S.includes("?"))||u[0]||"",N=[];return u.forEach(S=>{const f=S.match(/[❯\s]*(\d+)\.\s+(.+)/);if(f){const A=S.includes("❯");N.push({number:f[1],text:f[2].trim(),isSelected:A})}}),e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200 mb-4",children:m}),e.jsx("div",{className:"space-y-2 mb-4",children:N.map(S=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${S.isSelected?"bg-amber-600 dark:bg-amber-700 text-white border-amber-600 dark:border-amber-700 shadow-md":"bg-white dark:bg-gray-800 text-amber-900 dark:text-amber-100 border-amber-300 dark:border-amber-700"} cursor-not-allowed opacity-75`,disabled:!0,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold ${S.isSelected?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:S.number}),e.jsx("span",{className:"text-sm sm:text-base font-medium flex-1",children:S.text}),S.isSelected&&e.jsx("span",{className:"text-lg",children:"❯"})]})},S.number))}),e.jsxs("div",{className:"bg-amber-100 dark:bg-amber-800/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-amber-900 dark:text-amber-100 text-sm font-medium mb-1",children:"⏳ 等待您在 CLI 中的响应"}),e.jsx("p",{className:"text-amber-800 dark:text-amber-200 text-xs",children:"请在运行 Claude 的终端中选择一个选项。"})]})]})})()]})]})}):t.isToolUse&&t.toolName==="Read"?(()=>{try{const u=JSON.parse(t.toolInput);if(u.file_path){const m=u.file_path.split("/").pop();return e.jsx("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"})}),e.jsx("span",{className:"font-medium",children:"Read"}),e.jsx("button",{onClick:()=>n&&n(u.file_path),className:"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 font-mono transition-colors",children:m})]})})}}catch{return e.jsx("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"})}),e.jsx("span",{className:"font-medium",children:"读取文件"})]})})}})():t.isToolUse&&t.toolName==="TodoWrite"?(()=>{try{const u=JSON.parse(t.toolInput);if(u.todos&&Array.isArray(u.todos))return e.jsxs("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400 mb-2",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),e.jsx("span",{className:"font-medium",children:"更新待办列表"})]}),e.jsx(zr,{todos:u.todos})]})}catch{return e.jsx("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),e.jsx("span",{className:"font-medium",children:"更新待办列表"})]})})}})():t.isToolUse&&t.toolName==="TodoRead"?e.jsx("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),e.jsx("span",{className:"font-medium",children:"读取待办列表"})]})}):t.isThinking?e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300",children:e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"cursor-pointer text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 font-medium flex items-center gap-2",children:[e.jsx("svg",{className:"w-3 h-3 transition-transform group-open:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),e.jsx("span",{children:"💭 思考中..."})]}),e.jsx("div",{className:"mt-2 pl-4 border-l-2 border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-400 text-sm",children:e.jsx(Bt,{className:"prose prose-sm max-w-none dark:prose-invert prose-gray",children:t.content})})]})}):e.jsxs("div",{className:"text-sm text-gray-700 dark:text-gray-300",children:[g&&t.reasoning&&e.jsxs("details",{className:"mb-3",children:[e.jsx("summary",{className:"cursor-pointer text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 font-medium",children:"💭 思考中..."}),e.jsx("div",{className:"mt-2 pl-4 border-l-2 border-gray-300 dark:border-gray-600 italic text-gray-600 dark:text-gray-400 text-sm",children:e.jsx("div",{className:"whitespace-pre-wrap",children:t.reasoning})})]}),(()=>{const u=Vr(String(t.content||"")),m=u.trim();if((m.startsWith("{")||m.startsWith("["))&&(m.endsWith("}")||m.endsWith("]")))try{const N=JSON.parse(m),S=JSON.stringify(N,null,2);return e.jsxs("div",{className:"my-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 text-sm text-gray-600 dark:text-gray-400",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:"M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"})}),e.jsx("span",{className:"font-medium",children:"JSON 响应"})]}),e.jsx("div",{className:"bg-gray-800 dark:bg-gray-900 border border-gray-600/30 dark:border-gray-700 rounded-lg overflow-hidden",children:e.jsx("pre",{className:"p-4 overflow-x-auto",children:e.jsx("code",{className:"text-gray-100 dark:text-gray-200 text-sm font-mono block whitespace-pre",children:S})})})]})}catch{}return t.type==="assistant"?e.jsx(Bt,{className:"prose prose-sm max-w-none dark:prose-invert prose-gray",children:u}):e.jsx("div",{className:"whitespace-pre-wrap",children:u})})()]}),e.jsx("div",{className:`text-xs text-gray-500 dark:text-gray-400 mt-1 ${v?"opacity-0 group-hover:opacity-100":""}`,children:new Date(t.timestamp).toLocaleTimeString()})]})]})})}),Xo=({file:t,onRemove:s,uploadProgress:a,error:o})=>{const[n,l]=r.useState(null);return r.useEffect(()=>{const i=URL.createObjectURL(t);return l(i),()=>URL.revokeObjectURL(i)},[t]),e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:n,alt:t.name,className:"w-20 h-20 object-cover rounded"}),a!==void 0&&a<100&&e.jsx("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center",children:e.jsxs("div",{className:"text-white text-xs",children:[a,"%"]})}),o&&e.jsx("div",{className:"absolute inset-0 bg-red-500/50 flex items-center justify-center",children:e.jsx("svg",{className:"w-6 h-6 text-white",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("button",{onClick:s,className:"absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-1 opacity-0 group-hover:opacity-100",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"})})})]})};function ei({selectedProject:t,selectedSession:s,ws:a,sendMessage:o,messages:n,onFileOpen:l,onInputFocusChange:i,onSessionActive:d,onSessionInactive:h,onSessionProcessing:g,onSessionNotProcessing:p,processingSessions:w,onReplaceTemporarySession:v,onNavigateToSession:y,onShowSettings:x,autoExpandTools:P,showRawParameters:R,showThinking:C,autoScrollToBottom:k,sendByCtrlEnter:u,externalMessageUpdate:m,onTaskClick:N,limitStatus:S,onLimitExceeded:f,checkLimitStatus:A}){const[F,Z]=r.useState(()=>typeof window<"u"&&t&&Ze.getItem(`draft_input_${t.name}`)||""),[le,ee]=r.useState(()=>{if(typeof window<"u"&&t){const c=Ze.getItem(`chat_messages_${t.name}`);return c?JSON.parse(c):[]}return[]}),[ne,U]=r.useState(!1),[D,X]=r.useState(s?.id||null),[se,ve]=r.useState(!1),[oe,z]=r.useState([]),[ue,Le]=r.useState(!1),[Te,ke]=r.useState(!1),[Fe,we]=r.useState(0),[Se,ze]=r.useState(!1),[Ue,xe]=r.useState(0),Ce=20,Ie=r.useCallback(c=>{Ee.current=c,we(c)},[]),[Pe,De]=r.useState(!1),[T,_]=r.useState("default"),[W,b]=r.useState([]),H=r.useRef(new Map),pe=r.useRef(s?.id||null),[Ne,Oe]=r.useState([]),[at,K]=r.useState(new Map),[ae,j]=r.useState(new Map),[V,de]=r.useState(!1),ce=r.useRef(null),$=r.useRef(null),$e=r.useRef(null),Y=r.useRef(null),re=r.useRef(null),ie=r.useRef(!1),be=r.useRef(!1),fe=r.useRef(!1),je=r.useRef(null),Ee=r.useRef(0),He=r.useRef(""),Xe=r.useRef(null),We=r.useRef(null),[kt,kr]=r.useState(""),[ut,Nt]=r.useState(!1),[gt,Nr]=r.useState([]),[et,Sr]=r.useState([]),[St,Gt]=r.useState(-1),[ft,$t]=r.useState(0),[Vt,zt]=r.useState(-1),[Cr,nt]=r.useState(!1),[Yt,Ot]=r.useState(!1),Qt=r.useRef({height:0,top:0}),[Ct,ot]=r.useState(!1),[Ke,At]=r.useState([]),[pt,_t]=r.useState([]),[Ft,it]=r.useState(""),[Et,I]=r.useState(!1),[q,te]=r.useState(null),[Me,Qe]=r.useState(-1),[lt,bt]=r.useState(-1),[Zt,fa]=r.useState(100),[ba,yt]=r.useState(null),[vt,ds]=r.useState(()=>localStorage.getItem("claude-model")||Ws.DEFAULT),xt="claude";r.useEffect(()=>{if(s?.id){const c=localStorage.getItem(`permissionMode-${s.id}`);_(c||"default")}},[s?.id]),r.useEffect(()=>{const c=pe.current,M=s?.id;pe.current=M,b(c&&c!==M?L=>(H.current.set(c,L),H.current.get(M)||[]):L=>L.filter(E=>!E.sessionId||E.sessionId===M))},[s?.id]),r.useEffect(()=>{(async()=>{if(t)try{const M=await Q("/api/commands/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPath:t.path})});if(!M.ok)throw new Error("Failed to fetch commands");const L=await M.json(),E=[...(L.builtIn||[]).map(ge=>({...ge,type:"built-in"})),...(L.custom||[]).map(ge=>({...ge,type:"custom"}))];At(E);const O=`command_history_${t.name}`,G=Ze.getItem(O);if(G)try{const ge=JSON.parse(G),he=E.sort((J,me)=>{const Re=ge[J.name]||0;return(ge[me.name]||0)-Re});At(he)}catch(ge){console.error("Error parsing command history:",ge)}}catch(M){console.error("Error fetching slash commands:",M),At([])}})()},[t]);const Er=r.useMemo(()=>Ke.length?new tn(Ke,{keys:[{name:"name",weight:2},{name:"description",weight:1}],threshold:.4,includeScore:!0,minMatchCharLength:1}):null,[Ke]);r.useEffect(()=>{if(!Ft){_t(Ke);return}if(!Er){_t([]);return}const c=Er.search(Ft);_t(c.map(M=>M.item))},[Ft,Ke,Er]);const ya=r.useMemo(()=>{if(!t||Ke.length===0)return[];const c=`command_history_${t.name}`,M=Ze.getItem(c);if(!M)return[];try{const L=JSON.parse(M);return Ke.map(O=>({...O,usageCount:L[O.name]||0})).filter(O=>O.usageCount>0).sort((O,G)=>G.usageCount-O.usageCount).slice(0,5)}catch(L){return console.error("Error parsing command history:",L),[]}},[t,Ke]),va=r.useCallback((c,M,L)=>{if(!c||!t)return;if(L){Qe(M);return}const E=`command_history_${t.name}`,O=Ze.getItem(E);let G={};try{G=O?JSON.parse(O):{}}catch(ge){console.error("Error parsing command history:",ge)}G[c.name]=(G[c.name]||0)+1,Ze.setItem(E,JSON.stringify(G)),lr(c)},[t]),ja=r.useCallback(c=>{const{action:M,data:L}=c;switch(M){case"help":ee(E=>[...E,{type:"assistant",content:L.content,timestamp:Date.now()}]);break;case"model":{const E=L.available.claude,O=L.message?.includes("Switching to model:")?L.message.replace("Switching to model: ","").trim():null;O&&E.includes(O)?(ds(O),localStorage.setItem("claude-model",O),ee(G=>[...G,{type:"assistant",content:`已切换到模型: **${O}**`,timestamp:Date.now()}])):ee(O?G=>[...G,{type:"assistant",content:`无效的模型: ${O}
59
+
60
+ **可用模型**: ${E.join(", ")}`,timestamp:Date.now()}]:G=>[...G,{type:"assistant",content:`**当前模型**: ${vt}
61
+
62
+ **可用模型**: ${E.join(", ")}
63
+
64
+ 使用 \`/model <模型名>\` 切换模型,例如 \`/model opus\``,timestamp:Date.now()}]);break}case"cost":{let E;L.usage?E=`**Token 使用量**: ${L.usage.used.toLocaleString()} / ${L.usage.total.toLocaleString()} (${L.usage.percentage}%)
65
+
66
+ **剩余**: ${L.usage.remaining.toLocaleString()} tokens`:E=L.message||"无可用的 Token 使用数据。",ee(O=>[...O,{type:"assistant",content:E,timestamp:Date.now()}]);break}case"memory":L.error?ee(E=>[...E,{type:"assistant",content:`⚠️ ${L.message}`,timestamp:Date.now()}]):(ee(E=>[...E,{type:"assistant",content:`📝 ${L.message}
67
+
68
+ Path: \`${L.path}\``,timestamp:Date.now()}]),L.exists&&l&&l(L.path));break;case"config":x&&x();break;default:console.warn("Unknown built-in command action:",M)}},[l,x,vt]),Mr=r.useRef(null),wa=r.useCallback(async(c,M)=>{const{content:L,hasBashCommands:E,hasFileIncludes:O}=c;if(E&&!window.confirm("此命令包含将被执行的 bash 命令。是否继续?")){ee(ge=>[...ge,{type:"assistant",content:"❌ 命令执行已取消",timestamp:Date.now()}]);return}Z(L),setTimeout(()=>{if(Mr.current){const G={preventDefault:()=>{}};Mr.current(G)}},50)},[]),lr=r.useCallback(async c=>{if(!(!c||!t))try{const M=F.match(new RegExp(`${c.name}\\s*(.*)`)),L=M&&M[1]?M[1].trim().split(/\s+/):[],E={projectPath:t.path,projectName:t.name,sessionId:D,provider:xt,model:vt,tokenUsage:q},O=await Q("/api/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandName:c.name,commandPath:c.path,args:L,context:E})});if(!O.ok)throw new Error("Failed to execute command");const G=await O.json();G.type==="builtin"?ja(G):G.type==="custom"&&await wa(G,L),Z(""),ot(!1),bt(-1),it(""),Qe(-1)}catch(M){console.error("Error executing command:",M),ee(L=>[...L,{type:"assistant",content:`Error executing command: ${M.message}`,timestamp:Date.now()}])}},[F,t,D,xt,vt,q]),ka=r.useMemo(()=>{const c=new Map;return(M,L)=>{const E=`${M.length}-${L.length}-${M.slice(0,50)}`;if(c.has(E))return c.get(E);const O=Na(M,L);if(c.set(E,O),c.size>100){const G=c.keys().next().value;c.delete(G)}return O}},[]),Xt=r.useCallback(async(c,M,L=!1,E="claude")=>{if(!c||!M)return[];const O=!L;O?Le(!0):ke(!0);try{const G=L?Ee.current:0,ge=await ye.sessionMessages(c,M,Ce,G,E);if(!ge.ok)throw new Error("Failed to load session messages");const he=await ge.json();if(O&&he.tokenUsage&&te(he.tokenUsage),he.hasMore!==void 0)return ze(he.hasMore),xe(he.total),Ie(G+(he.messages?.length||0)),he.messages||[];{const J=he.messages||[];return ze(!1),xe(J.length),J}}catch(G){return console.error("Error loading session messages:",G),[]}finally{O?Le(!1):ke(!1)}},[Ie]),Na=(c,M)=>{const L=c.split(`
69
+ `),E=M.split(`
70
+ `),O=[];let G=0,ge=0;for(;G<L.length||ge<E.length;){const he=L[G],J=E[ge];G>=L.length?(O.push({type:"added",content:J,lineNum:ge+1}),ge++):ge>=E.length?(O.push({type:"removed",content:he,lineNum:G+1}),G++):he===J?(G++,ge++):(O.push({type:"removed",content:he,lineNum:G+1}),O.push({type:"added",content:J,lineNum:ge+1}),G++,ge++)}return O},ms=c=>{const M=[],L=new Map;for(const E of c)if(E.message?.role==="user"&&Array.isArray(E.message?.content))for(const O of E.message.content)O.type==="tool_result"&&L.set(O.tool_use_id,{content:O.content,isError:O.is_error,timestamp:new Date(E.timestamp||Date.now()),toolUseResult:E.toolUseResult||null});for(const E of c)if(!E.isMeta){if(E.message?.role==="user"&&E.message?.content){let O="",G="user";if(Array.isArray(E.message.content)){const J=[];for(const me of E.message.content)me.type==="text"&&J.push(Wt(me.text));O=J.join(`
71
+ `)}else typeof E.message.content=="string"?O=Wt(E.message.content):O=Wt(String(E.message.content));const ge=O.match(/<command-name>(\/[^<]+)<\/command-name>/);ge&&(O=ge[1]),!O||O.startsWith("<command-args>")||O.startsWith("<local-command-stdout>")||O.startsWith("<system-reminder>")||O.startsWith("Caveat:")||O.startsWith("This session is being continued from a previous")||O.startsWith("[Request interrupted")||(O=xr(O),M.push({type:G,content:O,timestamp:E.timestamp||new Date().toISOString()}))}else if(E.type==="thinking"&&E.message?.content)M.push({type:"assistant",content:xr(E.message.content),timestamp:E.timestamp||new Date().toISOString(),isThinking:!0});else if(E.type==="tool_use"&&E.toolName)M.push({type:"assistant",content:"",timestamp:E.timestamp||new Date().toISOString(),isToolUse:!0,toolName:E.toolName,toolInput:E.toolInput||"",toolCallId:E.toolCallId});else if(E.type==="tool_result"){for(let O=M.length-1;O>=0;O--)if(M[O].isToolUse&&!M[O].toolResult&&(!E.toolCallId||M[O].toolCallId===E.toolCallId)){M[O].toolResult={content:E.output||"",isError:!1};break}}else if(E.message?.role==="assistant"&&E.message?.content){if(Array.isArray(E.message.content)){for(const O of E.message.content)if(O.type==="text"){let G=O.text;typeof G=="string"&&(G=xr(G)),M.push({type:"assistant",content:G,timestamp:E.timestamp||new Date().toISOString()})}else if(O.type==="tool_use"){const G=L.get(O.id);M.push({type:"assistant",content:"",timestamp:E.timestamp||new Date().toISOString(),isToolUse:!0,toolName:O.name,toolInput:JSON.stringify(O.input),toolResult:G?{content:typeof G.content=="string"?G.content:JSON.stringify(G.content),isError:G.isError,toolUseResult:G.toolUseResult}:null,toolError:G?.isError||!1,toolResultTimestamp:G?.timestamp||new Date})}}else if(typeof E.message.content=="string"){let O=E.message.content;O=xr(O),M.push({type:"assistant",content:O,timestamp:E.timestamp||new Date().toISOString()})}}}return M},us=r.useMemo(()=>ms(oe),[oe]),ht=r.useCallback(()=>{re.current&&(re.current.scrollTop=re.current.scrollHeight)},[]),cr=r.useCallback(()=>{if(!re.current)return!1;const{scrollTop:c,scrollHeight:M,clientHeight:L}=re.current;return M-c-L<50},[]),ps=r.useCallback(async c=>{if(!c||be.current||Te||!Se||!s||!t)return!1;be.current=!0;const M=c.scrollHeight,L=c.scrollTop;try{const E=await Xt(t.name,s.id,!0,"claude");return E.length>0?(je.current={height:M,top:L},z(O=>[...E,...O]),!0):!1}finally{be.current=!1}},[Se,Te,s,t,Xt]),er=r.useCallback(async()=>{if(re.current){const c=re.current,M=cr();Ot(!M),c.scrollTop<100?fe.current||await ps(c)&&(fe.current=!0):fe.current=!1}},[cr,ps]);r.useLayoutEffect(()=>{if(!je.current||!re.current)return;const{height:c,top:M}=je.current,L=re.current,O=L.scrollHeight-c;L.scrollTop=M+Math.max(O,0),je.current=null,setTimeout(()=>{re.current&&re.current.scrollTop>=100&&(fe.current=!1)},300)},[le.length]),r.useEffect(()=>{(async()=>{if(s&&t){const M=localStorage.getItem("selected-provider")||"claude";ie.current=!0;const L=D!==null&&D!==s.id;if(L?(Ie(0),ze(!1),xe(0),te(null),U(!1),a&&o&&o({type:"check-session-status",sessionId:s.id,provider:M})):D===null&&(Ie(0),ze(!1),xe(0),a&&o&&o({type:"check-session-status",sessionId:s.id,provider:M})),X(s.id),Pe)De(!1);else{const E=await Xt(t.name,s.id,!1,"claude");z(E),L&&ee(ms(E))}}else!Pe&&!ne&&(ee([]),z([])),X(null),Ie(0),ze(!1),xe(0);setTimeout(()=>{ie.current=!1},250)})()},[s,t,ht,Pe]),r.useEffect(()=>{m>0&&s&&t&&(async()=>{try{const M=await Xt(t.name,s.id,!1,"claude");z(M),k&&cr()&&setTimeout(()=>ht(),200)}catch(M){console.error("Error reloading messages from external update:",M)}})()},[m,s,t,Xt,cr,k,ht]),r.useEffect(()=>{oe.length>0&&!ne&&ee(us)},[us,oe,ne]),r.useEffect(()=>{i&&i(se)},[se,i]),r.useEffect(()=>{t&&F!==""?Ze.setItem(`draft_input_${t.name}`,F):t&&F===""&&Ze.removeItem(`draft_input_${t.name}`)},[F,t]),r.useEffect(()=>{t&&le.length>0&&Ze.setItem(`chat_messages_${t.name}`,JSON.stringify(le))},[le,t]),r.useEffect(()=>{if(t){const c=Ze.getItem(`draft_input_${t.name}`)||"";c!==F&&Z(c)}},[t?.name]),r.useEffect(()=>{D&&ne&&g&&g(D)},[ne,D,g]),r.useEffect(()=>{D&&w&&w.has(D)&&!ne&&(U(!0),nt(!0))},[D,w]),r.useEffect(()=>{if(n.length>0){const c=n[n.length-1];if(!["projects_updated","session-created","claude-complete"].includes(c.type)&&c.sessionId&&D&&c.sessionId!==D){console.log("⏭️ Skipping message for different session:",c.sessionId,"current:",D);return}switch(c.type){case"session-created":c.sessionId&&!D&&(sessionStorage.setItem("pendingSessionId",c.sessionId),De(!0),v&&v(c.sessionId),b(J=>J.map(me=>me.sessionId?me:{...me,sessionId:c.sessionId})));break;case"token-budget":c.data&&te(c.data);break;case"claude-response":if(c.data.isMeta)return;const E=c.data.message||c.data;if(E&&typeof E=="object"&&E.type){if(E.type==="content_block_delta"&&E.delta?.text){const J=Wt(E.delta.text);He.current+=J,Xe.current||(Xe.current=setTimeout(()=>{const me=He.current;He.current="",Xe.current=null,me&&ee(Re=>{const _e=[...Re],tt=_e[_e.length-1];return tt&&tt.type==="assistant"&&!tt.isToolUse&&tt.isStreaming?tt.content=(tt.content||"")+me:_e.push({type:"assistant",content:me,timestamp:new Date,isStreaming:!0}),_e})},100));return}if(E.type==="content_block_stop"){Xe.current&&(clearTimeout(Xe.current),Xe.current=null);const J=He.current;He.current="",J&&ee(me=>{const Re=[...me],_e=Re[Re.length-1];return _e&&_e.type==="assistant"&&!_e.isToolUse&&_e.isStreaming?_e.content=(_e.content||"")+J:Re.push({type:"assistant",content:J,timestamp:new Date,isStreaming:!0}),Re}),ee(me=>{const Re=[...me],_e=Re[Re.length-1];return _e&&_e.type==="assistant"&&_e.isStreaming&&(_e.isStreaming=!1),Re});return}}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&D&&c.data.session_id!==D){console.log("🔄 Claude CLI session duplication detected:",{originalSession:D,newSession:c.data.session_id}),De(!0),y&&y(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&!D){console.log("🔄 New session init detected:",{newSession:c.data.session_id}),De(!0),y&&y(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&D&&c.data.session_id===D){console.log("🔄 System init message for current session, ignoring");return}const O=E.role==="user"||c.data.type==="user";if(Array.isArray(E.content)&&!O){for(const J of E.content)if(J.type==="tool_use"){const me=J.input?JSON.stringify(J.input,null,2):"";ee(Re=>[...Re,{type:"assistant",content:"",timestamp:new Date,isToolUse:!0,toolName:J.name,toolInput:me,toolId:J.id,toolResult:null}])}else if(J.type==="text"&&J.text?.trim()){let me=Wt(J.text);me=Vr(me),ee(Re=>[...Re,{type:"assistant",content:me,timestamp:new Date}])}}else if(typeof E.content=="string"&&E.content.trim()&&!O){let J=Wt(E.content);J=Vr(J),ee(me=>[...me,{type:"assistant",content:J,timestamp:new Date}])}if(E.role==="user"&&Array.isArray(E.content))for(const J of E.content)J.type==="tool_result"&&ee(me=>me.map(Re=>Re.isToolUse&&Re.toolId===J.tool_use_id?{...Re,toolResult:{content:J.content,isError:J.is_error,timestamp:new Date}}:Re));break;case"claude-output":{const J=String(c.data||"");J.trim()&&(He.current+=He.current?`
72
+ ${J}`:J,Xe.current||(Xe.current=setTimeout(()=>{const me=He.current;He.current="",Xe.current=null,me&&ee(Re=>{const _e=[...Re],tt=_e[_e.length-1];return tt&&tt.type==="assistant"&&!tt.isToolUse&&tt.isStreaming?tt.content=tt.content?`${tt.content}
73
+ ${me}`:me:_e.push({type:"assistant",content:me,timestamp:new Date,isStreaming:!0}),_e})},100)))}break;case"claude-interactive-prompt":ee(J=>[...J,{type:"assistant",content:c.data,timestamp:new Date,isInteractivePrompt:!0}]);break;case"claude-permission-request":{if(!c.requestId)break;b(J=>J.some(me=>me.requestId===c.requestId)?J:[...J,{requestId:c.requestId,toolName:c.toolName||"UnknownTool",input:c.input,context:c.context,sessionId:c.sessionId||null,receivedAt:new Date}]),U(!0),nt(!0),yt({text:"等待权限",tokens:0,can_interrupt:!0});break}case"claude-permission-cancelled":{if(!c.requestId)break;b(J=>J.filter(me=>me.requestId!==c.requestId));break}case"claude-error":ee(J=>[...J,{type:"error",content:`错误: ${c.error}`,timestamp:new Date}]),U(!1),nt(!1),yt(null),b([]),D&&(h&&h(D),p&&p(D));break;case"claude-complete":const G=c.sessionId||D||sessionStorage.getItem("pendingSessionId");(G===D||!D)&&(U(!1),nt(!1),yt(null)),G&&(h&&h(G),p&&p(G));const ge=sessionStorage.getItem("pendingSessionId");ge&&!D&&c.exitCode===0&&(X(ge),sessionStorage.removeItem("pendingSessionId"),console.log("✅ New session complete, ID set to:",ge)),t&&c.exitCode===0&&Ze.removeItem(`chat_messages_${t.name}`),G===D&&b([]),H.current.delete(G);break;case"session-aborted":{const J=c.sessionId||D;J===D&&(U(!1),nt(!1),yt(null)),J&&(h&&h(J),p&&p(J)),b([]),ee(me=>[...me,{type:"assistant",content:"会话已被用户中断。",timestamp:new Date}]);break}case"session-status":{const J=c.sessionId;(J===D||s&&J===s.id)&&c.isProcessing&&(U(!0),nt(!0),g&&g(J));break}case"claude-status":const he=c.data;if(he){let J={text:"处理中...",tokens:0,can_interrupt:!0};he.message?J.text=he.message:he.status?J.text=he.status:typeof he=="string"&&(J.text=he),he.tokens?J.tokens=he.tokens:he.token_count&&(J.tokens=he.token_count),he.can_interrupt!==void 0&&(J.can_interrupt=he.can_interrupt),yt(J),U(!0),nt(J.can_interrupt)}break}}},[n]),r.useEffect(()=>{t&&Sa()},[t]);const Sa=async()=>{try{const c=await ye.getFiles(t.name);if(c.ok){const M=await c.json(),L=xs(M);Nr(L)}}catch(c){console.error("Error fetching files:",c)}},xs=(c,M="")=>{let L=[];for(const E of c){const O=M?`${M}/${E.name}`:E.name;E.type==="directory"&&E.children?L=L.concat(xs(E.children,O)):E.type==="file"&&L.push({name:E.name,path:O,relativePath:E.path})}return L};r.useEffect(()=>{const c=F.slice(0,ft),M=c.lastIndexOf("@");if(M!==-1){const L=c.slice(M+1);if(L.includes(" "))Nt(!1),zt(-1);else{zt(M),Nt(!0);const E=gt.filter(O=>O.name.toLowerCase().includes(L.toLowerCase())||O.path.toLowerCase().includes(L.toLowerCase())).slice(0,10);Sr(E),Gt(-1)}}else Nt(!1),zt(-1)},[F,ft,gt]),r.useEffect(()=>{const c=setTimeout(()=>{kr(F)},150);return()=>clearTimeout(c)},[F]);const hs=r.useMemo(()=>le.length<=Zt?le:le.slice(-Zt),[le,Zt]);r.useEffect(()=>{if(!k&&re.current){const c=re.current;Qt.current={height:c.scrollHeight,top:c.scrollTop}}}),r.useEffect(()=>{if(re.current&&le.length>0)if(k)Yt||setTimeout(()=>ht(),50);else{const c=re.current,M=Qt.current.height,L=Qt.current.top,O=c.scrollHeight-M;O>0&&L>0&&(c.scrollTop=L+O)}},[le.length,Yt,ht,k]),r.useEffect(()=>{re.current&&le.length>0&&!ie.current&&(Ot(!1),setTimeout(()=>{ht()},200))},[s?.id,t?.name]),r.useEffect(()=>{const c=re.current;if(c)return c.addEventListener("scroll",er),()=>c.removeEventListener("scroll",er)},[er]),r.useEffect(()=>{if($.current){$.current.style.height="auto",$.current.style.height=$.current.scrollHeight+"px";const c=parseInt(window.getComputedStyle($.current).lineHeight),M=$.current.scrollHeight>c*2;I(M)}},[]),r.useEffect(()=>{$.current&&!F.trim()&&($.current.style.height="auto",I(!1))},[F]),r.useEffect(()=>{if(!t||!s?.id||s.id.startsWith("new-session-")){te(null);return}(async()=>{try{const M=`/api/projects/${t.name}/sessions/${s.id}/token-usage`,L=await Q(M);if(L.ok){const E=await L.json();te(E)}else te(null)}catch(M){console.error("Failed to fetch initial token usage:",M)}})()},[s?.id,s?.__provider,t?.path]);const Ca=r.useCallback(c=>{c.trim()&&Z(M=>{const L=M.trim()?`${M} ${c}`:c;return setTimeout(()=>{if($.current){$.current.style.height="auto",$.current.style.height=$.current.scrollHeight+"px";const E=parseInt(window.getComputedStyle($.current).lineHeight),O=$.current.scrollHeight>E*2;I(O)}},0),L})},[]),Ea=r.useCallback(()=>{fa(c=>c+100)},[]),dr=r.useCallback(c=>{const M=c.filter(L=>{try{if(!L||typeof L!="object")return console.warn("Invalid file object:",L),!1;if(!L.type||!L.type.startsWith("image/"))return!1;if(!L.size||L.size>5242880){const E=L.name||"Unknown file";return j(O=>{const G=new Map(O);return G.set(E,"文件太大(最大 5MB)"),G}),!1}return!0}catch(E){return console.error("Error validating file:",E,L),!1}});M.length>0&&Oe(L=>[...L,...M].slice(0,5))},[]),Ma=r.useCallback(async c=>{const M=c.target.files;if(!(!M||M.length===0||!t)){de(!0);try{const L=new FormData;Array.from(M).forEach(G=>{L.append("files",G)});const E=await ye.uploadFiles(t.name,L);if(!E.ok){const G=await E.json();throw new Error(G.error||"上传失败")}const O=await E.json();if(O.files&&O.files.length>0){const G=O.files.map(he=>`@${he.name}`).join(" "),ge=F?`${F} ${G} `:`${G} `;Z(ge),$.current&&$.current.focus()}}catch(L){console.error("File upload failed:",L)}finally{de(!1),$e.current&&($e.current.value="")}}},[t,F]),La=r.useCallback(async c=>{const M=Array.from(c.clipboardData.items);for(const L of M)if(L.type.startsWith("image/")){const E=L.getAsFile();E&&dr([E])}if(M.length===0&&c.clipboardData.files.length>0){const E=Array.from(c.clipboardData.files).filter(O=>O.type.startsWith("image/"));E.length>0&&dr(E)}},[dr]),{getRootProps:Ia,getInputProps:Da,isDragActive:Ta,open:Pa}=ss({accept:{"image/*":[".png",".jpg",".jpeg",".gif",".webp",".svg"]},maxSize:5*1024*1024,maxFiles:5,onDrop:dr,noClick:!0,noKeyboard:!0}),Mt=r.useCallback(async c=>{if(c.preventDefault(),!F.trim()||ne||!t)return;const M=F.trim();if(M.startsWith("/")){const J=M.indexOf(" "),me=J!==-1?M.slice(0,J):M,Re=Ke.find(_e=>_e.name===me&&_e.namespace==="builtin");if(Re){lr(Re);return}}if(A){const J=await A();if(J&&!J.allowed){f?.(J.reason);return}}let L=[];if(Ne.length>0){const J=new FormData;Ne.forEach(me=>{J.append("images",me)});try{const me=await Q(`/api/projects/${t.name}/upload-images`,{method:"POST",headers:{},body:J});if(!me.ok)throw new Error("图片上传失败");L=(await me.json()).images}catch(me){console.error("Image upload failed:",me),ee(Re=>[...Re,{type:"error",content:`图片上传失败: ${me.message}`,timestamp:new Date}]);return}}const E={type:"user",content:F,images:L,timestamp:new Date};ee(J=>[...J,E]),U(!0),nt(!0),yt({text:"处理中",tokens:0,can_interrupt:!0}),Ot(!1),setTimeout(()=>ht(),100);const G=D||s?.id||`new-session-${Date.now()}`;d&&d(G);const he=(()=>{try{const J=Ze.getItem("claude-settings");if(J)return JSON.parse(J)}catch(J){console.error("Error loading tools settings:",J)}return{allowedTools:[],disallowedTools:[],skipPermissions:!1}})();o({type:"claude-command",command:F,options:{projectPath:t.path,cwd:t.fullPath,sessionId:D,resume:!!D,toolsSettings:he,permissionMode:T,model:vt,images:L}}),Z(""),Oe([]),K(new Map),j(new Map),I(!1),$.current&&($.current.style.height="auto"),t&&Ze.removeItem(`draft_input_${t.name}`)},[F,ne,t,Ne,D,s,xt,T,d,vt,o,Z,Oe,K,j,I,$,ee,U,nt,yt,Ot,ht,A,f,lr,Ke]),gs=r.useCallback(c=>!c||xt!=="claude"?{success:!1}:Vo(c.entry),[xt]),tr=r.useCallback((c,M)=>{const E=(Array.isArray(c)?c:[c]).filter(Boolean);E.length!==0&&(E.forEach(O=>{o({type:"claude-permission-response",requestId:O,allow:!!M?.allow,updatedInput:M?.updatedInput,message:M?.message,rememberEntry:M?.rememberEntry})}),b(O=>{const G=O.filter(ge=>!E.includes(ge.requestId));return G.length===0&&yt(null),G}))},[o]);r.useEffect(()=>{Mr.current=Mt},[Mt]);const fs=c=>{if(!c)return;const M=F.slice(0,lt),L=F.slice(lt),E=L.indexOf(" "),O=E!==-1?L.slice(E):"",G=M+c.name+" "+O;Z(G),ot(!1),bt(-1),it(""),Qe(-1),We.current&&clearTimeout(We.current),lr(c)},Ra=c=>{if(Ct&&pt.length>0){if(c.key==="ArrowDown"){c.preventDefault(),Qe(M=>M<pt.length-1?M+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),Qe(M=>M>0?M-1:pt.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),Me>=0?fs(pt[Me]):pt.length>0&&fs(pt[0]);return}if(c.key==="Escape"){c.preventDefault(),ot(!1),bt(-1),it(""),Qe(-1),We.current&&clearTimeout(We.current);return}}if(ut&&et.length>0){if(c.key==="ArrowDown"){c.preventDefault(),Gt(M=>M<et.length-1?M+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),Gt(M=>M>0?M-1:et.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),St>=0?Lr(et[St]):et.length>0&&Lr(et[0]);return}if(c.key==="Escape"){c.preventDefault(),Nt(!1);return}}if(c.key==="Tab"&&!ut&&!Ct){c.preventDefault();const M=["default","acceptEdits","bypassPermissions","plan"],E=(M.indexOf(T)+1)%M.length,O=M[E];_(O),s?.id&&localStorage.setItem(`permissionMode-${s.id}`,O);return}if(c.key==="Enter"){if(c.nativeEvent.isComposing)return;(c.ctrlKey||c.metaKey)&&!c.shiftKey?(c.preventDefault(),Mt(c)):!c.shiftKey&&!c.ctrlKey&&!c.metaKey&&(u||(c.preventDefault(),Mt(c)))}},Lr=c=>{const M=F.slice(0,Vt),L=F.slice(Vt),E=L.indexOf(" "),O=E!==-1?L.slice(E):"",G=M+"@"+c.path+" "+O,ge=M.length+1+c.path.length+1;$.current&&!$.current.matches(":focus")&&$.current.focus(),Z(G),$t(ge),Nt(!1),zt(-1),$.current&&requestAnimationFrame(()=>{$.current&&($.current.setSelectionRange(ge,ge),$.current.matches(":focus")||$.current.focus())})},$a=c=>{const M=c.target.value,L=c.target.selectionStart;if(!D&&M.trim(),Z(M),$t(L),!M.trim()){c.target.style.height="auto",I(!1),ot(!1),bt(-1),it("");return}const E=M.slice(0,L);if((E.match(/```/g)||[]).length%2===1){ot(!1),bt(-1),it("");return}const ge=/(^|\s)\/(\S*)$/,he=E.match(ge);if(he){const J=he.index+he[1].length,me=he[2];bt(J),ot(!0),Qe(-1),We.current&&clearTimeout(We.current),We.current=setTimeout(()=>{it(me)},150)}else ot(!1),bt(-1),it(""),We.current&&clearTimeout(We.current)},za=c=>{$t(c.target.selectionStart)},Oa=()=>{D&&Cr&&o({type:"abort-session",sessionId:D,provider:xt})},Aa=()=>{const c=["default","acceptEdits","bypassPermissions","plan"],L=(c.indexOf(T)+1)%c.length,E=c[L];_(E),s?.id&&localStorage.setItem(`permissionMode-${s.id}`,E)};return t?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
74
+ details[open] .details-chevron {
75
+ transform: rotate(180deg);
76
+ }
77
+ `}),e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{ref:re,onWheel:er,onTouchMove:er,className:"flex-1 overflow-y-auto overflow-x-hidden px-0 py-3 sm:p-4 space-y-3 sm:space-y-4 relative",children:[ue&&le.length===0?e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400 mt-8",children:e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"}),e.jsx("p",{children:"正在加载会话消息..."})]})}):le.length===0?e.jsxs("div",{className:"flex items-center justify-center h-full",children:[!s&&!D&&e.jsxs("div",{className:"text-center px-6 sm:px-4 py-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-3",children:"开始新对话"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-8",children:"与 Claude 对话以获取代码帮助"}),e.jsx("div",{className:"flex flex-col items-center justify-center mb-8",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(mt,{className:"w-10 h-10"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:"Claude"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"by Anthropic"})]})]})}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"选择模型"}),e.jsx("select",{value:vt,onChange:c=>{const M=c.target.value;ds(M),localStorage.setItem("claude-model",M)},className:"pl-4 pr-10 py-2 text-sm bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500 min-w-[140px]",children:Ws.OPTIONS.map(({value:c,label:M})=>e.jsx("option",{value:c,children:M},c))})]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["已准备好使用 Claude ",vt,"。请在下方输入您的消息。"]})]}),s&&e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400 px-6 sm:px-4",children:[e.jsx("p",{className:"font-bold text-lg sm:text-xl mb-3",children:"继续您的对话"}),e.jsx("p",{className:"text-sm sm:text-base leading-relaxed",children:"询问代码问题、请求修改或获取开发任务帮助"})]})]}):e.jsxs(e.Fragment,{children:[Te&&e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400 py-3",children:e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"}),e.jsx("p",{className:"text-sm",children:"正在加载历史消息..."})]})}),Se&&!Te&&e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400 text-sm py-2 border-b border-gray-200 dark:border-gray-700",children:Ue>0&&e.jsxs("span",{children:["显示 ",oe.length," 条 / 共 ",Ue," 条消息 •",e.jsx("span",{className:"text-xs",children:"向上滚动加载更多"})]})}),!Se&&le.length>Zt&&e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400 text-sm py-2 border-b border-gray-200 dark:border-gray-700",children:["显示最近 ",Zt," 条消息(共 ",le.length," 条) •",e.jsx("button",{className:"ml-1 text-blue-600 hover:text-blue-700 underline",onClick:Ea,children:"加载更早的消息"})]}),hs.map((c,M)=>{const L=M>0?hs[M-1]:null,E=c.id||`${c.type}-${c.timestamp?.getTime?.()||M}-${M}`;return e.jsx(Zo,{message:c,index:M,prevMessage:L,createDiff:ka,onFileOpen:l,onShowSettings:x,onGrantToolPermission:gs,autoExpandTools:P,showRawParameters:R,showThinking:C,selectedProject:t,provider:xt},E)})]}),ne&&e.jsx("div",{className:"chat-message assistant",children:e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"flex items-center space-x-3 mb-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-white text-sm flex-shrink-0 p-1 bg-transparent",children:e.jsx(mt,{className:"w-full h-full"})}),e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"Claude"})]}),e.jsx("div",{className:"w-full text-sm text-gray-500 dark:text-gray-400 pl-3 sm:pl-0",children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx("div",{className:"animate-pulse",children:"●"}),e.jsx("div",{className:"animate-pulse",style:{animationDelay:"0.2s"},children:"●"}),e.jsx("div",{className:"animate-pulse",style:{animationDelay:"0.4s"},children:"●"}),e.jsx("span",{className:"ml-2",children:"思考中..."})]})})]})}),e.jsx("div",{ref:ce})]}),e.jsxs("div",{className:"p-2 sm:p-4 md:p-4 flex-shrink-0 pb-2 sm:pb-4 md:pb-6",children:[e.jsx("div",{className:"flex-1",children:e.jsx(Uo,{status:ba,isLoading:ne,onAbort:Oa,provider:xt,showThinking:C})}),e.jsxs("div",{ref:Y,className:"max-w-4xl mx-auto mb-3",children:[W.length>0&&e.jsx("div",{className:"mb-3 space-y-2",children:W.map(c=>{const M=Bs(c.input),L=Yr(c.toolName,M),E=as(),O=L?E.allowedTools.includes(L):!1,G=O?"已允许(已保存)":"允许并记住",ge=L?W.filter(he=>Yr(he.toolName,Bs(he.input))===L).map(he=>he.requestId):[c.requestId];return c.toolName==="AskUserQuestion"?e.jsx(Qo,{request:c,onSubmit:he=>{tr(c.requestId,{allow:!0,updatedInput:{...c.input,answers:he}})},onSkip:()=>tr(c.requestId,{allow:!1,message:"用户跳过问题"})},c.requestId):e.jsxs("div",{className:"rounded-lg border border-amber-200 dark:border-amber-800 bg-amber-50 dark:bg-amber-900/20 p-3 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-amber-900 dark:text-amber-100",children:"需要权限"}),e.jsxs("div",{className:"text-xs text-amber-800 dark:text-amber-200",children:["工具: ",e.jsx("span",{className:"font-mono",children:c.toolName})]})]}),L&&e.jsxs("div",{className:"text-xs text-amber-700 dark:text-amber-300",children:["允许规则: ",e.jsx("span",{className:"font-mono",children:L})]})]}),M&&e.jsxs("details",{className:"mt-2",children:[e.jsx("summary",{className:"cursor-pointer text-xs text-amber-800 dark:text-amber-200 hover:text-amber-900 dark:hover:text-amber-100",children:"查看工具输入"}),e.jsx("pre",{className:"mt-2 max-h-40 overflow-auto rounded-md bg-white/80 dark:bg-gray-900/60 border border-amber-200/60 dark:border-amber-800/60 p-2 text-xs text-amber-900 dark:text-amber-100 whitespace-pre-wrap",children:M})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>tr(c.requestId,{allow:!0}),className:"inline-flex items-center gap-2 rounded-md bg-amber-600 text-white text-xs font-medium px-3 py-1.5 hover:bg-amber-700 transition-colors",children:"允许一次"}),e.jsx("button",{type:"button",onClick:()=>{L&&!O&&gs({entry:L,toolName:c.toolName}),tr(ge,{allow:!0,rememberEntry:L})},className:`inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border transition-colors ${L?"border-amber-300 text-amber-800 hover:bg-amber-100 dark:border-amber-700 dark:text-amber-100 dark:hover:bg-amber-900/30":"border-gray-300 text-gray-400 cursor-not-allowed"}`,disabled:!L,children:G}),e.jsx("button",{type:"button",onClick:()=>tr(c.requestId,{allow:!1,message:"用户拒绝工具使用"}),className:"inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border border-red-300 text-red-700 hover:bg-red-50 dark:border-red-800 dark:text-red-200 dark:hover:bg-red-900/30 transition-colors",children:"拒绝"})]})]},c.requestId)})}),e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[e.jsx("button",{type:"button",onClick:Aa,className:`px-3 py-1.5 rounded-lg text-sm font-medium border transition-all duration-200 ${T==="default"?"bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 border-gray-300 dark:border-gray-600 hover:bg-gray-200 dark:hover:bg-gray-600":T==="acceptEdits"?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-300 border-green-300 dark:border-green-600 hover:bg-green-100 dark:hover:bg-green-900/30":T==="bypassPermissions"?"bg-orange-50 dark:bg-orange-900/20 text-orange-700 dark:text-orange-300 border-orange-300 dark:border-orange-600 hover:bg-orange-100 dark:hover:bg-orange-900/30":"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 border-blue-300 dark:border-blue-600 hover:bg-blue-100 dark:hover:bg-blue-900/30"}`,title:"点击切换权限模式(或在输入框中按 Tab)",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${T==="default"?"bg-gray-500":T==="acceptEdits"?"bg-green-500":T==="bypassPermissions"?"bg-orange-500":"bg-blue-500"}`}),e.jsxs("span",{children:[T==="default"&&"默认模式",T==="acceptEdits"&&"接受编辑",T==="bypassPermissions"&&"跳过权限",T==="plan"&&"计划模式"]})]})}),e.jsxs("button",{type:"button",onClick:()=>{const c=!Ct;ot(c),it(""),Qe(-1),c&&_t(Ke),$.current&&$.current.focus()},disabled:S&&!S.allowed,className:"relative w-8 h-8 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 rounded-full flex items-center justify-center transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:ring-offset-gray-800 disabled:opacity-50 disabled:cursor-not-allowed",title:S&&!S.allowed?"使用上限已达到":"显示所有命令",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:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),Ke.length>0&&e.jsx("span",{className:"absolute -top-1 -right-1 bg-blue-600 text-white text-xs font-bold rounded-full w-5 h-5 flex items-center justify-center",style:{fontSize:"10px"},children:Ke.length})]}),F.trim()&&e.jsx("button",{type:"button",onClick:c=>{c.preventDefault(),c.stopPropagation(),Z(""),$.current&&($.current.style.height="auto",$.current.focus()),I(!1)},className:"w-8 h-8 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-full flex items-center justify-center transition-all duration-200 group shadow-sm",title:"清除输入",children:e.jsx("svg",{className:"w-4 h-4 text-gray-600 dark:text-gray-300 group-hover:text-gray-800 dark:group-hover:text-gray-100 transition-colors",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"})})}),Yt&&le.length>0&&e.jsx("button",{onClick:ht,className:"w-8 h-8 bg-blue-600 hover:bg-blue-700 text-white rounded-full shadow-lg flex items-center justify-center transition-all duration-200 hover:scale-105 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:ring-offset-gray-800",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:"M19 14l-7 7m0 0l-7-7m7 7V3"})})})]})]}),e.jsxs("form",{onSubmit:Mt,className:"relative max-w-4xl mx-auto",children:[Ta&&e.jsx("div",{className:"absolute inset-0 bg-blue-500/20 border-2 border-dashed border-blue-500 rounded-lg flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg p-4 shadow-lg",children:[e.jsx("svg",{className:"w-8 h-8 text-blue-500 mx-auto mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"})}),e.jsx("p",{className:"text-sm font-medium",children:"将图片拖放到这里"})]})}),Ne.length>0&&e.jsx("div",{className:"mb-2 p-2 bg-gray-50 dark:bg-gray-800 rounded-lg",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:Ne.map((c,M)=>e.jsx(Xo,{file:c,onRemove:()=>{Oe(L=>L.filter((E,O)=>O!==M))},uploadProgress:at.get(c.name),error:ae.get(c.name)},M))})}),ut&&et.length>0&&e.jsx("div",{className:"absolute bottom-full left-0 right-0 mb-2 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg shadow-lg max-h-48 overflow-y-auto z-50 backdrop-blur-sm",children:et.map((c,M)=>e.jsxs("div",{className:`px-4 py-3 cursor-pointer border-b border-gray-100 dark:border-gray-700 last:border-b-0 touch-manipulation ${M===St?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"hover:bg-gray-50 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300"}`,onMouseDown:L=>{L.preventDefault(),L.stopPropagation()},onClick:L=>{L.preventDefault(),L.stopPropagation(),Lr(c)},children:[e.jsx("div",{className:"font-medium text-sm",children:c.name}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 font-mono",children:c.path})]},c.path))}),e.jsx(Jo,{commands:pt,selectedIndex:Me,onSelect:va,onClose:()=>{ot(!1),bt(-1),it(""),Qe(-1)},position:{top:$.current?Math.max(16,$.current.getBoundingClientRect().top-316):0,left:$.current?$.current.getBoundingClientRect().left:16,bottom:$.current?window.innerHeight-$.current.getBoundingClientRect().top+8:90},isOpen:Ct,frequentCommands:Ft?[]:ya}),e.jsxs("div",{...Ia(),className:`relative bg-white dark:bg-gray-800 rounded-2xl shadow-lg border border-gray-200 dark:border-gray-600 focus-within:ring-2 focus-within:ring-blue-500 dark:focus-within:ring-blue-500 focus-within:border-blue-500 transition-all duration-200 overflow-hidden ${Et?"chat-input-expanded":""}`,children:[e.jsx("input",{...Da()}),e.jsx("textarea",{ref:$,value:F,onChange:$a,onClick:za,onKeyDown:Ra,onPaste:La,onFocus:()=>ve(!0),onBlur:()=>ve(!1),onInput:c=>{c.target.style.height="auto",c.target.style.height=c.target.scrollHeight+"px",$t(c.target.selectionStart);const M=parseInt(window.getComputedStyle(c.target).lineHeight),L=c.target.scrollHeight>M*2;I(L)},placeholder:S&&!S.allowed?S.reason==="total_limit_exceeded"?"使用上限已达到,请联系管理员":"今日使用上限已达到":"输入 / 使用命令,@ 引用文件,或向 Claude 提问...",disabled:ne||S&&!S.allowed,className:"chat-input-placeholder block w-full pl-20 pr-20 sm:pr-40 py-1.5 sm:py-4 bg-transparent rounded-2xl focus:outline-none text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 disabled:opacity-50 resize-none min-h-[50px] sm:min-h-[80px] max-h-[40vh] sm:max-h-[300px] overflow-y-auto text-sm sm:text-base leading-[21px] sm:leading-6 transition-all duration-200",style:{height:"50px"}}),e.jsx("button",{type:"button",onClick:Pa,disabled:S&&!S.allowed,className:"absolute left-2 top-1/2 transform -translate-y-1/2 p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:S&&!S.allowed?"使用上限已达到":"添加图片",children:e.jsx("svg",{className:"w-5 h-5 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})})}),e.jsx("input",{type:"file",ref:$e,onChange:Ma,className:"hidden",multiple:!0}),e.jsx("button",{type:"button",onClick:()=>$e.current?.click(),disabled:V||!t||S&&!S.allowed,className:"absolute left-10 top-1/2 transform -translate-y-1/2 p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:S&&!S.allowed?"使用上限已达到":"上传文件并引用",children:V?e.jsxs("svg",{className:"w-5 h-5 text-gray-500 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}):e.jsx("svg",{className:"w-5 h-5 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})})}),e.jsx("div",{className:"absolute right-16 sm:right-16 top-1/2 transform -translate-y-1/2",style:{display:"none"},children:e.jsx(qo,{onTranscript:Ca,className:"w-10 h-10 sm:w-10 sm:h-10"})}),e.jsx("button",{type:"submit",disabled:!F.trim()||ne,onMouseDown:c=>{c.preventDefault(),Mt(c)},onTouchStart:c=>{c.preventDefault(),Mt(c)},className:"absolute right-2 top-1/2 transform -translate-y-1/2 w-12 h-12 sm:w-12 sm:h-12 bg-blue-600 hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed rounded-full flex items-center justify-center transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:ring-offset-gray-800",children:e.jsx("svg",{className:"w-4 h-4 sm:w-5 sm:h-5 text-white transform rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})}),e.jsx("div",{className:`absolute bottom-1 left-20 right-14 sm:right-40 text-xs text-gray-400 dark:text-gray-500 pointer-events-none hidden sm:block transition-opacity duration-200 ${F.trim()?"opacity-0":"opacity-100"}`,children:u?"Ctrl+Enter 发送 • Shift+Enter 换行 • Tab 切换模式 • / 使用命令":"Enter 发送 • Shift+Enter 换行 • Tab 切换模式 • / 使用命令"})]})]})]})]})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400",children:e.jsx("p",{children:"选择一个项目开始与 Claude 对话"})})})}const ti=rt.memo(ei);function Qr({file:t,onClose:s,projectPath:a,isSidebar:o=!1,isExpanded:n=!1,onToggleExpand:l=null}){const[i,d]=r.useState(""),[h,g]=r.useState(!0),[p,w]=r.useState(!1),[v,y]=r.useState(!1),[x,P]=r.useState(()=>{const U=localStorage.getItem("codeEditorTheme");return U?U==="dark":!0}),[R,C]=r.useState(!1),[k,u]=r.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[m,N]=r.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[S,f]=r.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),A=r.useRef(null),F=r.useMemo(()=>{const U=()=>{const D=document.createElement("div");D.className="cm-editor-toolbar-panel";const X=()=>{let se='<div style="display: flex; align-items: center; justify-content: flex-end; width: 100%;">';se+='<div style="display: flex; align-items: center; gap: 4px;">',se+=`
78
+ <button class="cm-toolbar-btn cm-settings-btn" title="Editor Settings">
79
+ <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
80
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
81
+ </svg>
82
+ </button>
83
+ `,o&&l&&(se+=`
84
+ <button class="cm-toolbar-btn cm-expand-btn" title="${n?"Collapse editor":"Expand editor to full width"}">
85
+ <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
86
+ ${n?'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25" />':'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4" />'}
87
+ </svg>
88
+ </button>
89
+ `),se+="</div>",se+="</div>",D.innerHTML=se,D.querySelector(".cm-settings-btn")?.addEventListener("click",()=>{window.openSettings&&window.openSettings("appearance")}),o&&l&&D.querySelector(".cm-expand-btn")?.addEventListener("click",()=>{l()})};return X(),{top:!0,dom:D,update:X}};return[_a.of(U)]},[o,n,l]),Z=U=>{const D=U.split(".").pop()?.toLowerCase();switch(D){case"js":case"jsx":case"ts":case"tsx":return[Ga({jsx:!0,typescript:D.includes("ts")})];case"py":return[Ka()];case"html":case"htm":return[Ja()];case"css":case"scss":case"less":return[qa()];case"json":return[Ha()];case"md":case"markdown":return[Ua()];default:return[]}};r.useEffect(()=>{(async()=>{try{g(!0);const D=await ye.readFile(t.projectName,t.path);if(!D.ok)throw new Error(`Failed to load file: ${D.status} ${D.statusText}`);const X=await D.json();d(X.content)}catch(D){console.error("Error loading file:",D),d(`// Error loading file: ${D.message}
90
+ // File: ${t.name}
91
+ // Path: ${t.path}`)}finally{g(!1)}})()},[t,a]);const le=async()=>{w(!0);try{console.log("Saving file:",{projectName:t.projectName,path:t.path,contentLength:i?.length});const U=await ye.saveFile(t.projectName,t.path,i);if(console.log("Save response:",{status:U.status,ok:U.ok,contentType:U.headers.get("content-type")}),!U.ok){const X=U.headers.get("content-type");if(X&&X.includes("application/json")){const se=await U.json();throw new Error(se.error||`Save failed: ${U.status}`)}else{const se=await U.text();throw console.error("Non-JSON error response:",se),new Error(`Save failed: ${U.status} ${U.statusText}`)}}const D=await U.json();console.log("Save successful:",D),C(!0),setTimeout(()=>C(!1),2e3)}catch(U){console.error("Error saving file:",U),alert(`Error saving file: ${U.message}`)}finally{w(!1)}},ee=()=>{const U=new Blob([i],{type:"text/plain"}),D=URL.createObjectURL(U),X=document.createElement("a");X.href=D,X.download=t.name,document.body.appendChild(X),X.click(),document.body.removeChild(X),URL.revokeObjectURL(D)},ne=()=>{y(!v)};return r.useEffect(()=>{localStorage.setItem("codeEditorTheme",x?"dark":"light")},[x]),r.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",k.toString())},[k]),r.useEffect(()=>{const U=()=>{const D=localStorage.getItem("codeEditorTheme");D&&P(D==="dark");const X=localStorage.getItem("codeEditorWordWrap");X!==null&&u(X==="true");const se=localStorage.getItem("codeEditorLineNumbers");se!==null&&N(se!=="false");const ve=localStorage.getItem("codeEditorFontSize");ve&&f(ve)};return window.addEventListener("storage",U),window.addEventListener("codeEditorSettingsChanged",U),()=>{window.removeEventListener("storage",U),window.removeEventListener("codeEditorSettingsChanged",U)}},[]),r.useEffect(()=>{const U=D=>{(D.ctrlKey||D.metaKey)&&(D.key==="s"?(D.preventDefault(),le()):D.key==="Escape"&&(D.preventDefault(),s()))};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},[i]),h?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
92
+ .code-editor-loading {
93
+ background-color: ${x?"#111827":"#ffffff"} !important;
94
+ }
95
+ .code-editor-loading:hover {
96
+ background-color: ${x?"#111827":"#ffffff"} !important;
97
+ }
98
+ `}),o?e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-background",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"}),e.jsxs("span",{className:"text-gray-900 dark:text-white",children:["Loading ",t.name,"..."]})]})}):e.jsx("div",{className:"fixed inset-0 z-40 md:bg-black/50 md:flex md:items-center md:justify-center",children:e.jsx("div",{className:"code-editor-loading w-full h-full md:rounded-lg md:w-auto md:h-auto p-8 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"}),e.jsxs("span",{className:"text-gray-900 dark:text-white",children:["Loading ",t.name,"..."]})]})})})]}):e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
99
+ /* Editor toolbar panel styling */
100
+ .cm-editor-toolbar-panel {
101
+ padding: 8px 12px;
102
+ background-color: ${x?"#1f2937":"#ffffff"};
103
+ border-bottom: 1px solid ${x?"#374151":"#e5e7eb"};
104
+ color: ${x?"#d1d5db":"#374151"};
105
+ font-size: 14px;
106
+ }
107
+
108
+ .cm-toolbar-btn {
109
+ padding: 4px;
110
+ background: transparent;
111
+ border: none;
112
+ cursor: pointer;
113
+ border-radius: 4px;
114
+ display: inline-flex;
115
+ align-items: center;
116
+ justify-content: center;
117
+ color: inherit;
118
+ transition: background-color 0.2s;
119
+ }
120
+
121
+ .cm-toolbar-btn:hover {
122
+ background-color: ${x?"#374151":"#f3f4f6"};
123
+ }
124
+ `}),e.jsx("div",{className:o?"w-full h-full flex flex-col":`fixed inset-0 z-40 md:bg-black/50 md:flex md:items-center md:justify-center md:p-4 ${v?"md:p-0":""}`,children:e.jsxs("div",{className:o?"bg-background flex flex-col w-full h-full":`bg-background shadow-2xl flex flex-col ${"w-full h-full md:rounded-lg md:shadow-2xl"+(v?" md:w-full md:h-full md:rounded-none":" md:w-full md:max-w-6xl md:h-[80vh] md:max-h-[80vh]")}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border flex-shrink-0 min-w-0",children:[e.jsx("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-2 min-w-0",children:e.jsx("h3",{className:"font-medium text-gray-900 dark:text-white truncate",children:t.name})}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 truncate",children:t.path})]})}),e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:ee,className:"p-2 md: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-800 min-w-[44px] min-h-[44px] md:min-w-0 md:min-h-0 flex items-center justify-center",title:"Download file",children:e.jsx(Dt,{className:"w-5 h-5 md:w-4 md:h-4"})}),e.jsx("button",{onClick:le,disabled:p,className:`px-3 py-2 text-white rounded-md disabled:opacity-50 flex items-center gap-2 transition-colors min-h-[44px] md:min-h-0 ${R?"bg-green-600 hover:bg-green-700":"bg-blue-600 hover:bg-blue-700"}`,children:R?e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-5 h-5 md:w-4 md:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("span",{className:"hidden sm:inline",children:"Saved!"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ks,{className:"w-5 h-5 md:w-4 md:h-4"}),e.jsx("span",{className:"hidden sm:inline",children:p?"Saving...":"Save"})]})}),!o&&e.jsx("button",{onClick:ne,className:"hidden md:flex 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-800 items-center justify-center",title:v?"Exit fullscreen":"Fullscreen",children:v?e.jsx(on,{className:"w-4 h-4"}):e.jsx(Gs,{className:"w-4 h-4"})}),e.jsx("button",{onClick:s,className:"p-2 md: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-800 min-w-[44px] min-h-[44px] md:min-w-0 md:min-h-0 flex items-center justify-center",title:"Close",children:e.jsx(Je,{className:"w-6 h-6 md:w-4 md:h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Fa,{ref:A,value:i,onChange:d,extensions:[...Z(t.name),...F,...k?[Ba.lineWrapping]:[]],theme:x?Wa:void 0,height:"100%",style:{fontSize:`${S}px`,height:"100%"},basicSetup:{lineNumbers:m,foldGutter:!0,dropCursor:!1,allowMultipleSelections:!1,indentOnInput:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!0,highlightSelectionMatches:!0,searchKeymap:!0}})}),e.jsxs("div",{className:"flex items-center justify-between p-3 border-t border-border bg-muted flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-4 text-sm text-gray-600 dark:text-gray-400",children:[e.jsxs("span",{children:["Lines: ",i.split(`
125
+ `).length]}),e.jsxs("span",{children:["Characters: ",i.length]})]}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Press Ctrl+S to save • Esc to close"})]})]})})]})}function ri({file:t,onClose:s}){const a=`/api/projects/${t.projectName}/files/content?path=${encodeURIComponent(t.path)}`,[o,n]=r.useState(null),[l,i]=r.useState(null),[d,h]=r.useState(!0);return r.useEffect(()=>{let g;const p=new AbortController;return(async()=>{try{h(!0),i(null),n(null);const v=await Q(a,{signal:p.signal});if(!v.ok)throw new Error(`Request failed with status ${v.status}`);const y=await v.blob();g=URL.createObjectURL(y),n(g)}catch(v){if(v.name==="AbortError")return;console.error("Error loading image:",v),i("无法加载图像")}finally{h(!1)}})(),()=>{p.abort(),g&&URL.revokeObjectURL(g)}},[a]),e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-4xl max-h-[90vh] w-full mx-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:t.name}),e.jsx(B,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0",children:e.jsx(Je,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-4 flex justify-center items-center bg-gray-50 dark:bg-gray-900 min-h-[400px]",children:[d&&e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400",children:e.jsx("p",{children:"加载图像中…"})}),!d&&o&&e.jsx("img",{src:o,alt:t.name,className:"max-w-full max-h-[70vh] object-contain rounded-lg shadow-md"}),!d&&!o&&e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("p",{children:l||"无法加载图像"}),e.jsx("p",{className:"text-sm mt-2 break-all",children:t.path})]})]}),e.jsx("div",{className:"p-4 border-t bg-gray-50 dark:bg-gray-800",children:e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t.path})})]})})}function si({selectedProject:t}){const[s,a]=r.useState([]),[o,n]=r.useState(!1),[l,i]=r.useState(new Set),[d,h]=r.useState(new Set),[g,p]=r.useState(new Set),[w,v]=r.useState(null),[y,x]=r.useState(null),[P,R]=r.useState("detailed"),[C,k]=r.useState(""),[u,m]=r.useState([]),[N,S]=r.useState(!1),[f,A]=r.useState(!1),[F,Z]=r.useState(null),[le,ee]=r.useState({}),[ne,U]=r.useState(null);r.useEffect(()=>{t&&(i(new Set),p(new Set),h(new Set),X())},[t]),r.useEffect(()=>{const _=localStorage.getItem("file-tree-view-mode");_&&["simple","detailed","compact"].includes(_)&&R(_)},[]),r.useEffect(()=>{if(!C.trim())m(s);else{const _=D(s,C.toLowerCase());m(_);const W=b=>{b.forEach(H=>{H.type==="directory"&&H.children&&H.children.length>0&&(i(pe=>new Set(pe.add(H.path))),W(H.children))})};W(_)}},[s,C]);const D=(_,W)=>_.reduce((b,H)=>{const pe=H.name.toLowerCase().includes(W);let Ne=[];return H.type==="directory"&&H.children&&(Ne=D(H.children,W)),(pe||Ne.length>0)&&b.push({...H,children:Ne}),b},[]),X=async()=>{n(!0);try{const _=await ye.getFiles(t.name,{depth:1});if(!_.ok){const b=await _.text();console.error("❌ File fetch failed:",_.status,b),a([]);return}const W=await _.json();a(W)}catch(_){console.error("❌ Error fetching files:",_),a([])}finally{n(!1)}},se=async _=>{if(!(g.has(_)||d.has(_))){h(W=>new Set([...W,_]));try{const W=await ye.getFiles(t.name,{dirPath:_,depth:1});if(!W.ok){console.error("Failed to load directory:",_);return}const b=await W.json();a(H=>ve(H,_,b)),p(H=>new Set([...H,_]))}catch(W){console.error("Error loading directory:",W)}finally{h(W=>{const b=new Set(W);return b.delete(_),b})}}},ve=(_,W,b)=>_.map(H=>H.path===W?{...H,children:b}:H.type==="directory"&&H.children&&H.children.length>0?{...H,children:ve(H.children,W,b)}:H),oe=r.useCallback(async _=>{if(!t||_.length===0)return;A(!0),Z(null);const W=new FormData;_.forEach(H=>{W.append("files",H)});const b={};_.forEach(H=>{b[H.name]=0}),ee(b);try{const H=await ye.uploadFiles(t.name,W);if(!H.ok){const Ne=await H.json();throw new Error(Ne.error||"Upload failed")}const pe={};_.forEach(Ne=>{pe[Ne.name]=100}),ee(pe),await X(),setTimeout(()=>{S(!1),ee({})},1e3)}catch(H){console.error("Upload failed:",H),Z(H.message)}finally{A(!1)}},[t]),{getRootProps:z,getInputProps:ue,isDragActive:Le,open:Te}=ss({onDrop:oe,noClick:!0,noKeyboard:!0}),ke=async _=>{if(t)try{const W=await ye.deleteFile(t.name,_);if(!W.ok){const b=await W.json();throw new Error(b.error||"Delete failed")}await X(),U(null)}catch(W){console.error("Delete failed:",W),alert(`Failed to delete: ${W.message}`)}},Fe=async(_,W)=>{const b=new Set(l);b.has(_)?b.delete(_):(b.add(_),W&&!g.has(_)&&await se(_)),i(b)},we=_=>{R(_),localStorage.setItem("file-tree-view-mode",_)},Se=_=>{if(!_||_===0)return"0 B";const W=1024,b=["B","KB","MB","GB"],H=Math.floor(Math.log(_)/Math.log(W));return parseFloat((_/Math.pow(W,H)).toFixed(1))+" "+b[H]},ze=_=>{if(!_)return"-";const W=new Date,b=new Date(_),H=Math.floor((W-b)/1e3);return H<60?"just now":H<3600?`${Math.floor(H/60)} min ago`:H<86400?`${Math.floor(H/3600)} hours ago`:H<2592e3?`${Math.floor(H/86400)} days ago`:b.toLocaleDateString()},Ue=(_,W=0)=>_.map(b=>{const H=d.has(b.path),pe=l.has(b.path),Ne=b.hasChildren||b.children&&b.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:qe("w-full flex items-center justify-between p-2 hover:bg-accent",b.type==="directory"||xe(b.name)||Ce(b.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${W*16+12}px`},onClick:()=>{b.type==="directory"?Fe(b.path,Ne):xe(b.name)?x({name:b.name,path:b.path,projectPath:t.path,projectName:t.name}):Ce(b.name)&&v({name:b.name,path:b.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[b.type==="directory"?H?e.jsx(jt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):pe?e.jsx(It,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):Ne?e.jsx(ct,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(ct,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Pe(b.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:b.name}),b.type==="directory"&&Ne&&!pe&&!H&&e.jsx(Ht,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[b.type==="file"&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity flex-shrink-0",onClick:Oe=>{Oe.stopPropagation(),Ie(b)},title:"下载文件",children:e.jsx(Dt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity flex-shrink-0",onClick:Oe=>{Oe.stopPropagation(),U({path:b.path,name:b.name,type:b.type})},title:`删除${b.type==="directory"?"文件夹":"文件"}`,children:e.jsx(Ve,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),b.type==="directory"&&pe&&e.jsx("div",{children:H?e.jsxs("div",{className:"flex items-center gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(W+1)*16+12}px`},children:[e.jsx(jt,{className:"w-3 h-3 animate-spin"}),"加载中..."]}):b.children&&b.children.length>0?Ue(b.children,W+1):e.jsx("div",{className:"p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(W+1)*16+12}px`},children:"空文件夹"})})]},b.path)}),xe=_=>{const W=_.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","svg","webp","ico","bmp"].includes(W)},Ce=_=>{const W=_.toLowerCase(),b=["dockerfile","makefile","gemfile","rakefile","procfile","vagrantfile","jenkinsfile"];if(!_.includes("."))return b.includes(W);const H=_.split(".").pop()?.toLowerCase();return new Set(["js","jsx","ts","tsx","mjs","cjs","py","pyw","pyi","java","kt","kts","scala","groovy","cpp","cxx","cc","c","h","hpp","hxx","cs","fs","fsx","go","rs","swift","php","rb","lua","pl","pm","r","dart","elm","clj","cljs","ex","exs","sh","bash","zsh","fish","ps1","bat","cmd","html","htm","xhtml","css","scss","sass","less","vue","svelte","astro","json","json5","jsonc","yaml","yml","toml","ini","cfg","conf","config","env","properties","xml","xsd","xsl","csv","tsv","graphql","gql","proto","sql","md","mdx","markdown","txt","text","rst","adoc","tex","log","lock","gitignore","gitattributes","gitmodules","editorconfig","prettierrc","eslintrc","babelrc","htaccess"]).has(H)},Ie=async _=>{try{const W=await ye.getFileContent(t.name,_.path);if(!W.ok)throw new Error("Download failed");const b=await W.blob(),H=URL.createObjectURL(b),pe=document.createElement("a");pe.href=H,pe.download=_.name,document.body.appendChild(pe),pe.click(),document.body.removeChild(pe),URL.revokeObjectURL(H)}catch(W){console.error("Download failed:",W)}},Pe=_=>{const W=_.split(".").pop()?.toLowerCase(),b=["js","jsx","ts","tsx","py","java","cpp","c","php","rb","go","rs"],H=["md","txt","doc","pdf"],pe=["png","jpg","jpeg","gif","svg","webp","ico","bmp"];return b.includes(W)?e.jsx(dn,{className:"w-4 h-4 text-green-500 flex-shrink-0"}):H.includes(W)?e.jsx(Ys,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):pe.includes(W)?e.jsx(ws,{className:"w-4 h-4 text-purple-500 flex-shrink-0"}):e.jsx(ws,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"})},De=(_,W=0)=>_.map(b=>{const H=d.has(b.path),pe=l.has(b.path),Ne=b.hasChildren||b.children&&b.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:qe("grid grid-cols-12 gap-2 p-2 hover:bg-accent items-center",b.type==="directory"||xe(b.name)||Ce(b.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${W*16+12}px`},onClick:()=>{b.type==="directory"?Fe(b.path,Ne):xe(b.name)?x({name:b.name,path:b.path,projectPath:t.path,projectName:t.name}):Ce(b.name)&&v({name:b.name,path:b.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"col-span-4 flex items-center gap-2 min-w-0",children:[b.type==="directory"?H?e.jsx(jt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):pe?e.jsx(It,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):Ne?e.jsx(ct,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(ct,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Pe(b.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:b.name}),b.type==="directory"&&Ne&&!pe&&!H&&e.jsx(Ht,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground",children:b.type==="file"?Se(b.size):"-"}),e.jsx("div",{className:"col-span-3 text-sm text-muted-foreground",children:ze(b.modified)}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground font-mono",children:b.permissionsRwx||"-"}),e.jsxs("div",{className:"col-span-1 flex justify-end items-center gap-0.5",children:[b.type==="file"&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Oe=>{Oe.stopPropagation(),Ie(b)},title:"下载文件",children:e.jsx(Dt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Oe=>{Oe.stopPropagation(),U({path:b.path,name:b.name,type:b.type})},title:`删除${b.type==="directory"?"文件夹":"文件"}`,children:e.jsx(Ve,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),b.type==="directory"&&pe&&e.jsx("div",{children:H?e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground items-center",style:{paddingLeft:`${(W+1)*16+12}px`},children:e.jsxs("div",{className:"col-span-4 flex items-center gap-2",children:[e.jsx(jt,{className:"w-3 h-3 animate-spin"}),"加载中..."]})}):b.children&&b.children.length>0?De(b.children,W+1):e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(W+1)*16+12}px`},children:e.jsx("div",{className:"col-span-4",children:"空文件夹"})})})]},b.path)}),T=(_,W=0)=>_.map(b=>{const H=d.has(b.path),pe=l.has(b.path),Ne=b.hasChildren||b.children&&b.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:qe("flex items-center justify-between p-2 hover:bg-accent",b.type==="directory"||xe(b.name)||Ce(b.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${W*16+12}px`},onClick:()=>{b.type==="directory"?Fe(b.path,Ne):xe(b.name)?x({name:b.name,path:b.path,projectPath:t.path,projectName:t.name}):Ce(b.name)&&v({name:b.name,path:b.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[b.type==="directory"?H?e.jsx(jt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):pe?e.jsx(It,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):Ne?e.jsx(ct,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(ct,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Pe(b.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:b.name}),b.type==="directory"&&Ne&&!pe&&!H&&e.jsx(Ht,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[b.type==="file"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:Se(b.size)}),e.jsx("span",{className:"font-mono",children:b.permissionsRwx})]}),b.type==="file"&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Oe=>{Oe.stopPropagation(),Ie(b)},title:"下载文件",children:e.jsx(Dt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Oe=>{Oe.stopPropagation(),U({path:b.path,name:b.name,type:b.type})},title:`删除${b.type==="directory"?"文件夹":"文件"}`,children:e.jsx(Ve,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),b.type==="directory"&&pe&&e.jsx("div",{children:H?e.jsxs("div",{className:"flex items-center gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(W+1)*16+12}px`},children:[e.jsx(jt,{className:"w-3 h-3 animate-spin"}),"加载中..."]}):b.children&&b.children.length>0?T(b.children,W+1):e.jsx("div",{className:"p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(W+1)*16+12}px`},children:"空文件夹"})})]},b.path)});return o?e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx("div",{className:"text-gray-500 dark:text-gray-400",children:"加载文件中..."})}):e.jsxs("div",{...z(),className:qe("h-full flex flex-col bg-card relative",Le&&"ring-2 ring-primary ring-inset"),children:[e.jsx("input",{...ue()}),Le&&e.jsx("div",{className:"absolute inset-0 bg-primary/10 flex items-center justify-center z-10 pointer-events-none",children:e.jsx("div",{className:"text-primary font-medium",children:"拖放文件以上传"})}),e.jsxs("div",{className:"p-4 border-b border-border space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:"文件"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>S(!0),title:"上传文件",children:e.jsx(js,{className:"w-4 h-4"})}),e.jsx(B,{variant:P==="simple"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>we("simple"),title:"简单视图",children:e.jsx(ln,{className:"w-4 h-4"})}),e.jsx(B,{variant:P==="compact"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>we("compact"),title:"紧凑视图",children:e.jsx(Vs,{className:"w-4 h-4"})}),e.jsx(B,{variant:P==="detailed"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>we("detailed"),title:"详细视图",children:e.jsx(cn,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Pt,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ye,{type:"text",placeholder:"搜索文件和文件夹...",value:C,onChange:_=>k(_.target.value),className:"pl-8 pr-8 h-8 text-sm"}),C&&e.jsx(B,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 transform -translate-y-1/2 h-6 w-6 p-0 hover:bg-accent",onClick:()=>k(""),title:"清除搜索",children:e.jsx(Je,{className:"w-3 h-3"})})]})]}),P==="detailed"&&u.length>0&&e.jsx("div",{className:"px-4 pt-2 pb-1 border-b border-border",children:e.jsxs("div",{className:"grid grid-cols-12 gap-2 px-2 text-xs font-medium text-muted-foreground",children:[e.jsx("div",{className:"col-span-4",children:"名称"}),e.jsx("div",{className:"col-span-2",children:"大小"}),e.jsx("div",{className:"col-span-3",children:"修改时间"}),e.jsx("div",{className:"col-span-2",children:"权限"}),e.jsx("div",{className:"col-span-1"})]})}),e.jsx(ts,{className:"flex-1 p-4",children:s.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center mx-auto mb-3",children:e.jsx(ct,{className:"w-6 h-6 text-muted-foreground"})}),e.jsx("h4",{className:"font-medium text-foreground mb-1",children:"未找到文件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"检查项目路径是否可访问"})]}):u.length===0&&C?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center mx-auto mb-3",children:e.jsx(Pt,{className:"w-6 h-6 text-muted-foreground"})}),e.jsx("h4",{className:"font-medium text-foreground mb-1",children:"无匹配结果"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"尝试不同的搜索条件或清除搜索"})]}):e.jsxs("div",{className:P==="detailed"?"":"space-y-1",children:[P==="simple"&&Ue(u),P==="compact"&&T(u),P==="detailed"&&De(u)]})}),w&&e.jsx(Qr,{file:w,onClose:()=>v(null),projectPath:w.projectPath}),y&&e.jsx(ri,{file:y,onClose:()=>x(null)}),N&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-xl p-6 w-full max-w-md mx-4 border border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"上传文件"}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{S(!1),Z(null),ee({})},children:e.jsx(Je,{className:"w-4 h-4"})})]}),e.jsxs("div",{onClick:Te,className:qe("border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors","border-border hover:border-primary/50"),children:[e.jsx(js,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-foreground",children:"将文件拖到此处或点击浏览"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"每次上传最多 20 个文件"})]}),Object.keys(le).length>0&&e.jsx("div",{className:"mt-4 space-y-2 max-h-40 overflow-y-auto",children:Object.entries(le).map(([_,W])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm truncate flex-1 text-foreground",children:_}),e.jsx("div",{className:"w-20 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${W}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10",children:[W,"%"]})]},_))}),F&&e.jsx("div",{className:"mt-4 p-3 bg-destructive/10 border border-destructive/20 rounded-lg",children:e.jsx("p",{className:"text-sm text-destructive",children:F})}),f&&e.jsx("div",{className:"mt-4 text-center text-sm text-muted-foreground",children:"上传中..."})]})}),ne&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-xl p-6 w-full max-w-sm mx-4 border border-border",children:[e.jsx("h3",{className:"text-lg font-medium text-foreground mb-2",children:"确认删除"}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["确定要删除",ne.type==="directory"?"文件夹":"文件"," ",e.jsxs("span",{className:"font-medium text-foreground",children:['"',ne.name,'"']}),"?",ne.type==="directory"&&e.jsx("span",{className:"block mt-1 text-destructive",children:"这将删除内部的所有内容。"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{variant:"outline",size:"sm",onClick:()=>U(null),children:"取消"}),e.jsx(B,{variant:"destructive",size:"sm",onClick:()=>ke(ne.path),children:"删除"})]})]})})]})}var ns=In(),os=Dn(),is=Tn(),ls=Pn();const ai=`
126
+ .xterm .xterm-screen {
127
+ outline: none !important;
128
+ }
129
+ .xterm:focus .xterm-screen {
130
+ outline: none !important;
131
+ }
132
+ .xterm-screen:focus {
133
+ outline: none !important;
134
+ }
135
+ `;if(typeof document<"u"){const t=document.createElement("style");t.type="text/css",t.innerText=ai,document.head.appendChild(t)}function ni({selectedProject:t,selectedSession:s,initialCommand:a,isPlainShell:o=!1,onProcessComplete:n,minimal:l=!1,autoConnect:i=!1}){const d=r.useRef(null),h=r.useRef(null),g=r.useRef(null),p=r.useRef(null),[w,v]=r.useState(!1),[y,x]=r.useState(!1),[P,R]=r.useState(!1),[C,k]=r.useState(null),[u,m]=r.useState(!1),N=r.useRef(t),S=r.useRef(s),f=r.useRef(a),A=r.useRef(o),F=r.useRef(n);r.useEffect(()=>{N.current=t,S.current=s,f.current=a,A.current=o,F.current=n});const Z=r.useCallback(async()=>{if(!(u||w))try{let ve;{const oe=localStorage.getItem("auth-token");if(!oe){console.error("No authentication token found for Shell WebSocket connection");return}ve=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/shell?token=${encodeURIComponent(oe)}`}p.current=new WebSocket(ve),p.current.onopen=()=>{v(!0),m(!1),setTimeout(()=>{g.current&&h.current&&(g.current.fit(),p.current.send(JSON.stringify({type:"init",projectPath:N.current.fullPath||N.current.path,sessionId:A.current?null:S.current?.id,hasSession:A.current?!1:!!S.current,provider:A.current?"plain-shell":S.current?.__provider||"claude",cols:h.current.cols,rows:h.current.rows,initialCommand:f.current,isPlainShell:A.current})))},100)},p.current.onmessage=oe=>{try{const z=JSON.parse(oe.data);if(z.type==="output"){let ue=z.data;if(A.current&&F.current){const Le=ue.replace(/\x1b\[[0-9;]*m/g,"");if(Le.includes("Process exited with code 0"))F.current(0);else if(Le.match(/Process exited with code (\d+)/)){const Te=parseInt(Le.match(/Process exited with code (\d+)/)[1]);Te!==0&&F.current(Te)}}h.current&&h.current.write(ue)}else z.type==="url_open"&&window.open(z.url,"_blank")}catch(z){console.error("[Shell] Error handling WebSocket message:",z,oe.data)}},p.current.onclose=oe=>{v(!1),m(!1),h.current&&(h.current.clear(),h.current.write("\x1B[2J\x1B[H"))},p.current.onerror=oe=>{v(!1),m(!1)}}catch{v(!1),m(!1)}},[u,w]),le=r.useCallback(()=>{!y||w||u||(m(!0),Z())},[y,w,u,Z]),ee=r.useCallback(()=>{p.current&&(p.current.readyState===WebSocket.OPEN&&p.current.send(JSON.stringify({type:"terminate"})),p.current.close(),p.current=null),h.current&&(h.current.clear(),h.current.write("\x1B[2J\x1B[H")),v(!1),m(!1)},[]),ne=r.useMemo(()=>s?s.__provider==="cursor"?s.name||"Untitled Session":s.summary||"New Session":null,[s]),U=r.useMemo(()=>ne?ne.slice(0,30):null,[ne]),D=r.useMemo(()=>ne?ne.slice(0,50):null,[ne]),X=()=>{R(!0),p.current&&(p.current.readyState===WebSocket.OPEN&&p.current.send(JSON.stringify({type:"terminate"})),p.current.close(),p.current=null),h.current&&(h.current.dispose(),h.current=null,g.current=null),v(!1),x(!1),setTimeout(()=>{R(!1)},200)};return r.useEffect(()=>{const se=s?.id||null;C!==null&&C!==se&&y&&ee(),k(se)},[s?.id,y,ee]),r.useEffect(()=>{if(!d.current||!t||P||h.current)return;h.current=new ns.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 os.FitAddon;const se=new is.WebglAddon,ve=new ls.WebLinksAddon;h.current.loadAddon(g.current),h.current.loadAddon(ve);try{h.current.loadAddon(se)}catch{console.warn("[Shell] WebGL renderer unavailable, using Canvas fallback")}h.current.open(d.current),h.current.attachCustomKeyEventHandler(z=>(z.ctrlKey||z.metaKey)&&z.key==="c"&&h.current.hasSelection()?(document.execCommand("copy"),!1):(z.ctrlKey||z.metaKey)&&z.key==="v"?(navigator.clipboard.readText().then(ue=>{p.current&&p.current.readyState===WebSocket.OPEN&&p.current.send(JSON.stringify({type:"input",data:ue}))}).catch(()=>{}),!1):!0),setTimeout(()=>{g.current&&(g.current.fit(),h.current&&p.current&&p.current.readyState===WebSocket.OPEN&&p.current.send(JSON.stringify({type:"resize",cols:h.current.cols,rows:h.current.rows})))},100),x(!0),h.current.onData(z=>{p.current&&p.current.readyState===WebSocket.OPEN&&p.current.send(JSON.stringify({type:"input",data:z}))});const oe=new ResizeObserver(()=>{g.current&&h.current&&setTimeout(()=>{g.current.fit(),p.current&&p.current.readyState===WebSocket.OPEN&&p.current.send(JSON.stringify({type:"resize",cols:h.current.cols,rows:h.current.rows}))},50)});return d.current&&oe.observe(d.current),()=>{oe.disconnect(),p.current&&(p.current.readyState===WebSocket.OPEN||p.current.readyState===WebSocket.CONNECTING)&&p.current.close(),p.current=null,h.current&&(h.current.dispose(),h.current=null)}},[t?.path||t?.fullPath,P]),r.useEffect(()=>{!i||!y||u||w||le()},[i,y,u,w,le]),t?l?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:d,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 ${w?"bg-green-500":"bg-red-500"}`}),s&&e.jsxs("span",{className:"text-xs text-blue-300",children:["(",U,"...)"]}),!s&&e.jsx("span",{className:"text-xs text-gray-400",children:"(新会话)"}),!y&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),P&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[w&&e.jsxs("button",{onClick:ee,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:X,disabled:P||w,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:d,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!y&&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:"加载终端中..."})}),y&&!w&&!u&&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:le,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}`:s?`Resume session: ${D}...`:"Start a new Claude session"})]})}),u&&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 oi({project:t,session:s=null,command:a=null,isPlainShell:o=null,autoConnect:n=!0,onComplete:l=null,onClose:i=null,title:d=null,className:h="",showHeader:g=!0,compact:p=!1,minimal:w=!1}){const[v,y]=r.useState(!1),x=o!==null?o:a!==null,P=r.useCallback(R=>{y(!0),l&&l(R)},[l]);return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${h}`,children:[!w&&g&&d&&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:d}),v&&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(ni,{selectedProject:t,selectedSession:s,initialCommand:a,isPlainShell:x,onProcessComplete:P,minimal:w,autoConnect:w?!0:n})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${h}`,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 ii({selectedProject:t,minimal:s=!1,autoConnect:a=!1}){const o=r.useRef(null),n=r.useRef(null),l=r.useRef(null),i=r.useRef(null),[d,h]=r.useState(!1),[g,p]=r.useState(!1),[w,v]=r.useState(!1),[y,x]=r.useState(!1),P=r.useRef(t);r.useEffect(()=>{P.current=t});const R=r.useCallback(async()=>{if(!(y||d))try{let N;{const S=localStorage.getItem("auth-token");if(!S){console.error("No authentication token found for Codex WebSocket connection");return}N=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/codex?token=${encodeURIComponent(S)}`}i.current=new WebSocket(N),i.current.onopen=()=>{h(!0),x(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:P.current.fullPath||P.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=S=>{try{const f=JSON.parse(S.data);f.type==="output"?n.current&&n.current.write(f.data):f.type==="url_open"&&window.open(f.url,"_blank")}catch(f){console.error("[CodexShell] Error handling WebSocket message:",f)}},i.current.onclose=()=>{h(!1),x(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{h(!1),x(!1)}}catch{h(!1),x(!1)}},[y,d]),C=r.useCallback(()=>{!g||d||y||(x(!0),R())},[g,d,y,R]),k=r.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")),h(!1),x(!1)},[]),u=()=>{v(!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),h(!1),p(!1),setTimeout(()=>v(!1),200)};return r.useEffect(()=>{if(!o.current||!t||w||n.current)return;n.current=new ns.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 os.FitAddon;const m=new is.WebglAddon,N=new ls.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(N);try{n.current.loadAddon(m)}catch{console.warn("[CodexShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(f=>(f.ctrlKey||f.metaKey)&&f.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(f.ctrlKey||f.metaKey)&&f.key==="v"?(navigator.clipboard.readText().then(A=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:A}))}).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),p(!0),n.current.onData(f=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:f}))});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,w]),r.useEffect(()=>{!a||!g||y||d||C()},[a,g,y,d,C]),t?s?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 ${d?"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:"(正在初始化...)"}),w&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[d&&e.jsxs("button",{onClick:k,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:u,disabled:w||d,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&&!d&&!y&&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:C,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"]})]})}),y&&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 li({project:t,autoConnect:s=!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(ii,{selectedProject:t,minimal:l,autoConnect:l?!0:s})})]}):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 需要一个项目"})]})})}function ci({selectedProject:t,minimal:s=!1,autoConnect:a=!1}){const o=r.useRef(null),n=r.useRef(null),l=r.useRef(null),i=r.useRef(null),[d,h]=r.useState(!1),[g,p]=r.useState(!1),[w,v]=r.useState(!1),[y,x]=r.useState(!1),P=r.useRef(t);r.useEffect(()=>{P.current=t});const R=r.useCallback(async()=>{if(!(y||d))try{let N;{const S=localStorage.getItem("auth-token");if(!S){console.error("No authentication token found for Gemini WebSocket connection");return}N=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/gemini?token=${encodeURIComponent(S)}`}i.current=new WebSocket(N),i.current.onopen=()=>{h(!0),x(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:P.current.fullPath||P.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=S=>{try{const f=JSON.parse(S.data);f.type==="output"?n.current&&n.current.write(f.data):f.type==="url_open"&&window.open(f.url,"_blank")}catch(f){console.error("[GeminiShell] Error handling WebSocket message:",f)}},i.current.onclose=()=>{h(!1),x(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{h(!1),x(!1)}}catch{h(!1),x(!1)}},[y,d]),C=r.useCallback(()=>{!g||d||y||(x(!0),R())},[g,d,y,R]),k=r.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")),h(!1),x(!1)},[]),u=()=>{v(!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),h(!1),p(!1),setTimeout(()=>v(!1),200)};return r.useEffect(()=>{if(!o.current||!t||w||n.current)return;n.current=new ns.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 os.FitAddon;const m=new is.WebglAddon,N=new ls.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(N);try{n.current.loadAddon(m)}catch{console.warn("[GeminiShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(f=>(f.ctrlKey||f.metaKey)&&f.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(f.ctrlKey||f.metaKey)&&f.key==="v"?(navigator.clipboard.readText().then(A=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:A}))}).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),p(!0),n.current.onData(f=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:f}))});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,w]),r.useEffect(()=>{!a||!g||y||d||C()},[a,g,y,d,C]),t?s?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 ${d?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-300 font-medium",children:"Gemini"}),!g&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),w&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[d&&e.jsxs("button",{onClick:k,className:"px-3 py-1 text-xs bg-red-600 text-white rounded hover:bg-red-700 flex items-center space-x-1",title:"断开 Gemini 连接",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:u,disabled:w||d,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Gemini(先断开连接)",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&&!d&&!y&&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:C,className:"px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-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:"启动 Gemini"})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["在 ",t.displayName," 中启动 Gemini CLI"]})]})}),y&&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:"连接到 Gemini..."})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["正在 ",t.displayName," 中启动 Gemini 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:"选择一个项目以在该目录中打开 Gemini"})]})})}function di({project:t,autoConnect:s=!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:"Gemini"}),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(ci,{selectedProject:t,minimal:l,autoConnect:l?!0:s})})]}):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:"打开 Gemini 需要一个项目"})]})})}class mi extends rt.Component{constructor(s){super(s),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(s){return{hasError:!0}}componentDidCatch(s,a){console.error("ErrorBoundary caught an error:",s,a),this.setState({error:s,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 rr=({children:t,content:s,position:a="top",className:o="",delay:n=500})=>{const[l,i]=r.useState(!1),[d,h]=r.useState(null),g=()=>{const y=setTimeout(()=>{i(!0)},n);h(y)},p=()=>{d&&(clearTimeout(d),h(null)),i(!1)},w=()=>{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"}},v=()=>{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 s?e.jsxs("div",{className:"relative inline-block",onMouseEnter:g,onMouseLeave:p,children:[t,l&&e.jsxs("div",{className:qe("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",w(),o),children:[s,e.jsx("div",{className:qe("absolute w-0 h-0 border-4 border-transparent",v())})]})]}):t};function ui({selectedProject:t,selectedSession:s,activeTab:a,setActiveTab:o,ws:n,sendMessage:l,messages:i,isMobile:d,isPWA:h,onMenuClick:g,isLoading:p,onInputFocusChange:w,onSessionActive:v,onSessionInactive:y,onSessionProcessing:x,onSessionNotProcessing:P,processingSessions:R,onReplaceTemporarySession:C,onNavigateToSession:k,onShowSettings:u,autoExpandTools:m,showRawParameters:N,showThinking:S,autoScrollToBottom:f,sendByCtrlEnter:A,externalMessageUpdate:F,limitStatus:Z,onLimitBlocked:le,checkLimitStatus:ee}){const[ne,U]=r.useState(null),[D,X]=r.useState(600),[se,ve]=r.useState(!1),[oe,z]=r.useState(!1),ue=r.useRef(null);r.useEffect(()=>{a==="shell"&&ee&&ee()},[a,ee]);const Le=(we,Se=null)=>{const ze={name:we.split("/").pop(),path:we,projectName:t?.name,diffInfo:Se};U(ze)},Te=()=>{U(null),z(!1)},ke=()=>{z(!oe)},Fe=we=>{d||(ve(!0),we.preventDefault())};return r.useEffect(()=>{const we=ze=>{if(!se)return;const Ue=ue.current?.parentElement;if(!Ue)return;const xe=Ue.getBoundingClientRect(),Ce=xe.right-ze.clientX,Ie=300,Pe=xe.width*.8;Ce>=Ie&&Ce<=Pe&&X(Ce)},Se=()=>{ve(!1)};return se&&(document.addEventListener("mousemove",we),document.addEventListener("mouseup",Se),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",we),document.removeEventListener("mouseup",Se),document.body.style.cursor="",document.body.style.userSelect=""}},[se]),p?e.jsxs("div",{className:"h-full flex flex-col",children:[d&&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:[d&&e.jsx("button",{onClick:g,onTouchStart:we=>{we.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"&&s&&e.jsx("div",{className:"w-5 h-5 flex-shrink-0 flex items-center justify-center",children:e.jsx(mt,{className:"w-4 h-4"})}),e.jsx("div",{className:"min-w-0 flex-1",children:a==="chat"&&s?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:s.summary||"新会话"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]}):a==="chat"&&!s?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(rr,{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(rr,{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(rr,{content:Z&&!Z.allowed?"使用已达上限":"Claude Code",position:"bottom",children:e.jsx("button",{onClick:()=>{if(Z&&!Z.allowed){le?.(Z.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 ${Z&&!Z.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",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z",fill:"#D97757",fillRule:"nonzero"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Claude Code"})]})})}),e.jsx(rr,{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:"currentColor",fillRule:"evenodd",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z"})}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Codex"})]})})}),e.jsx(rr,{content:"Gemini CLI",position:"bottom",children:e.jsx("button",{onClick:()=>o("gemini"),className:`relative px-2 sm:px-3 py-1.5 text-xs sm:text-sm font-medium rounded-md transition-all duration-200 ${a==="gemini"?"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.jsxs("svg",{className:"w-3 sm:w-3.5 h-3 sm:h-3.5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"#3186FF"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#gemini-tab-fill-0)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#gemini-tab-fill-1)"}),e.jsx("path",{d:"M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z",fill:"url(#gemini-tab-fill-2)"}),e.jsxs("defs",{children:[e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"gemini-tab-fill-0",x1:"7",x2:"11",y1:"15.5",y2:"12",children:[e.jsx("stop",{stopColor:"#08B962"}),e.jsx("stop",{offset:"1",stopColor:"#08B962",stopOpacity:"0"})]}),e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"gemini-tab-fill-1",x1:"8",x2:"11.5",y1:"5.5",y2:"11",children:[e.jsx("stop",{stopColor:"#F94543"}),e.jsx("stop",{offset:"1",stopColor:"#F94543",stopOpacity:"0"})]}),e.jsxs("linearGradient",{gradientUnits:"userSpaceOnUse",id:"gemini-tab-fill-2",x1:"3.5",x2:"17.5",y1:"13.5",y2:"12",children:[e.jsx("stop",{stopColor:"#FABC12"}),e.jsx("stop",{offset:".46",stopColor:"#FABC12",stopOpacity:"0"})]})]})]}),e.jsx("span",{className:"hidden md:hidden lg:inline",children:"Gemini CLI"})]})})})]})})]})}),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 ${ne?"mr-0":""} ${oe?"hidden":""}`,children:[e.jsx("div",{className:`h-full ${a==="chat"?"block":"hidden"}`,children:e.jsx(mi,{showDetails:!0,children:e.jsx(ti,{selectedProject:t,selectedSession:s,ws:n,sendMessage:l,messages:i,onFileOpen:Le,onInputFocusChange:w,onSessionActive:v,onSessionInactive:y,onSessionProcessing:x,onSessionNotProcessing:P,processingSessions:R,onReplaceTemporarySession:C,onNavigateToSession:k,onShowSettings:u,autoExpandTools:m,showRawParameters:N,showThinking:S,autoScrollToBottom:f,sendByCtrlEnter:A,externalMessageUpdate:F,limitStatus:Z,onLimitExceeded:le,checkLimitStatus:ee})})}),a==="files"&&e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx(si,{selectedProject:t})}),a==="shell"&&e.jsxs("div",{className:"h-full w-full overflow-hidden relative",children:[e.jsx(oi,{project:t,session:s,showHeader:!1}),Z&&!Z.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:Z.reason==="total_limit_exceeded"?"使用上限已达到":"今日使用上限已达到"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:Z.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(li,{project:t,showHeader:!1})}),a==="gemini"&&e.jsx("div",{className:"h-full w-full overflow-hidden relative",children:e.jsx(di,{project:t,showHeader:!1})}),e.jsx("div",{className:`h-full overflow-hidden ${a==="preview"?"block":"hidden"}`})]}),ne&&!d&&e.jsxs(e.Fragment,{children:[!oe&&e.jsx("div",{ref:ue,onMouseDown:Fe,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 ${oe?"flex-1":""}`,style:oe?{}:{width:`${D}px`},children:e.jsx(Qr,{file:ne,onClose:Te,projectPath:t?.path,isSidebar:!0,isExpanded:oe,onToggleExpand:ke})})]})]}),ne&&d&&e.jsx(Qr,{file:ne,onClose:Te,projectPath:t?.path,isSidebar:!1})]}):e.jsxs("div",{className:"h-full flex flex-col",children:[d&&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:"提示:"})," ",d?"点击上方菜单按钮访问项目":"点击侧边栏中的文件夹图标创建新项目"]})})]})})]})}const pi=rt.memo(ui);function xi({activeTab:t,setActiveTab:s,isInputFocused:a}){const o=[{id:"chat",icon:Xr,onClick:()=>s("chat")},{id:"shell",icon:nr,onClick:()=>s("shell")},{id:"files",icon:ct,onClick:()=>s("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:d=>{d.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 xa=r.createContext(),cs=()=>{const t=r.useContext(xa);if(!t)throw new Error("useTheme must be used within a ThemeProvider");return t},hi=({children:t})=>{const[s,a]=r.useState(()=>{const l=localStorage.getItem("theme");return l?l==="dark":window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches:!1});r.useEffect(()=>{if(s){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")}},[s]),r.useEffect(()=>{if(!window.matchMedia)return;const l=window.matchMedia("(prefers-color-scheme: dark)"),i=d=>{localStorage.getItem("theme")||a(d.matches)};return l.addEventListener("change",i),()=>l.removeEventListener("change",i)},[]);const n={isDarkMode:s,toggleDarkMode:()=>{a(l=>!l)}};return e.jsx(xa.Provider,{value:n,children:t})},ha=r.createContext({user:null,token:null,login:()=>{},sendCode:()=>{},verifyCode:()=>{},logout:()=>{},isLoading:!0,needsSetup:!1,smtpConfigured:!1,error:null,isAdmin:!1,limitStatus:{allowed:!0},checkLimitStatus:()=>{},setLimitStatus:()=>{}}),Kt=()=>{const t=r.useContext(ha);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t};async function Or(){try{const t=await ye.settings.getAgentPermissions();if(t.ok){const s=await t.json();s.agentPermissions&&localStorage.setItem("claude-settings",JSON.stringify(s.agentPermissions))}}catch{}}const gi=({children:t})=>{const[s,a]=r.useState(null),[o,n]=r.useState(localStorage.getItem("auth-token")),[l,i]=r.useState(!0),[d,h]=r.useState(!1),[g,p]=r.useState(!1),[w,v]=r.useState(null),[y,x]=r.useState({allowed:!0});r.useEffect(()=>{P()},[]);const P=async()=>{try{i(!0),v(null);const f=await(await ye.auth.status()).json();if(p(f.smtpConfigured||!1),f.needsSetup){h(!0),i(!1);return}if(o)try{const A=await ye.auth.user();if(A.ok){const F=await A.json();a(F.user),h(!1),await Or()}else localStorage.removeItem("auth-token"),n(null),a(null)}catch(A){console.error("Token verification failed:",A),localStorage.removeItem("auth-token"),n(null),a(null)}}catch(S){console.error("[AuthContext] Auth status check failed:",S),v("Failed to check authentication status")}finally{i(!1)}},R=async S=>{try{v(null);const f=await ye.auth.sendCode(S),A=await f.json();return f.ok?{success:!0,type:A.type}:{success:!1,error:A.error||"发送验证码失败",waitSeconds:A.waitSeconds}}catch(f){return console.error("Send code error:",f),{success:!1,error:"网络错误,请稍后再试"}}},C=async(S,f)=>{try{v(null);const A=await ye.auth.verifyCode(S,f),F=await A.json();return A.ok?(n(F.token),a(F.user),h(!1),localStorage.setItem("auth-token",F.token),await Or(),{success:!0}):(v(F.error||"验证失败"),{success:!1,error:F.error||"验证失败"})}catch(A){return console.error("Verify code error:",A),{success:!1,error:"网络错误,请稍后再试"}}},k=async(S,f)=>{try{v(null);const A=await ye.auth.login(S,f),F=await A.json();return A.ok?(n(F.token),a(F.user),localStorage.setItem("auth-token",F.token),await Or(),{success:!0}):(v(F.error||"登录失败"),{success:!1,error:F.error||"登录失败"})}catch(A){console.error("Login error:",A);const F="网络错误,请稍后再试";return v(F),{success:!1,error:F}}},u=()=>{n(null),a(null),x({allowed:!0}),localStorage.removeItem("auth-token"),o&&ye.auth.logout().catch(S=>{console.error("Logout endpoint error:",S)})},m=async()=>{if(!s)return{allowed:!0};try{const S=await ye.auth.limitStatus();if(S.ok){const f=await S.json();return x(f),f}}catch(S){console.error("Error checking limit status:",S)}return{allowed:!0}};r.useEffect(()=>{s&&!l&&m()},[s,l]);const N={user:s,token:o,login:k,sendCode:R,verifyCode:C,logout:u,isLoading:l,needsSetup:d,smtpConfigured:g,error:w,isAdmin:s?.role==="admin",limitStatus:y,checkLimitStatus:m,setLimitStatus:x};return e.jsx(ha.Provider,{value:N,children:t})},fi=["Bash(git log:*)","Bash(git diff:*)","Bash(git status:*)","Write","Read","Edit","Glob","Grep","MultiEdit","Task","TodoWrite","TodoRead","WebFetch","WebSearch"],bi=["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 yi({skipPermissions:t,setSkipPermissions:s,allowedTools:a,setAllowedTools:o,disallowedTools:n,setDisallowedTools:l,newAllowedTool:i,setNewAllowedTool:d,newDisallowedTool:h,setNewDisallowedTool:g}){const p=x=>{x&&!a.includes(x)&&(o([...a,x]),d(""))},w=x=>{o(a.filter(P=>P!==x))},v=x=>{x&&!n.includes(x)&&(l([...n,x]),g(""))},y=x=>{l(n.filter(P=>P!==x))};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(Qs,{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(qt,{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:x=>s(x.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(wr,{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(Ye,{value:i,onChange:x=>d(x.target.value),placeholder:'e.g., "Bash(git log:*)" or "Write"',onKeyPress:x=>{x.key==="Enter"&&(x.preventDefault(),p(i))},className:"flex-1 h-10"}),e.jsxs(B,{onClick:()=>p(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:fi.map(x=>e.jsx(B,{variant:"outline",size:"sm",onClick:()=>p(x),disabled:a.includes(x),className:"text-xs h-8",children:x},x))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(x=>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:x}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>w(x),className:"text-green-600 hover:text-green-700",children:e.jsx(Je,{className:"w-4 h-4"})})]},x)),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(qt,{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(Ye,{value:h,onChange:x=>g(x.target.value),placeholder:'e.g., "Bash(rm:*)"',onKeyPress:x=>{x.key==="Enter"&&(x.preventDefault(),v(h))},className:"flex-1 h-10"}),e.jsxs(B,{onClick:()=>v(h),disabled:!h,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(x=>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:x}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>y(x),className:"text-red-600 hover:text-red-700",children:e.jsx(Je,{className:"w-4 h-4"})})]},x)),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 vi({skipPermissions:t,setSkipPermissions:s,allowedCommands:a,setAllowedCommands:o,disallowedCommands:n,setDisallowedCommands:l,newAllowedCommand:i,setNewAllowedCommand:d,newDisallowedCommand:h,setNewDisallowedCommand:g}){const p=x=>{x&&!a.includes(x)&&(o([...a,x]),d(""))},w=x=>{o(a.filter(P=>P!==x))},v=x=>{x&&!n.includes(x)&&(l([...n,x]),g(""))},y=x=>{l(n.filter(P=>P!==x))};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(qt,{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:x=>s(x.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(wr,{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(Ye,{value:i,onChange:x=>d(x.target.value),placeholder:'e.g., "Shell(ls)" or "Shell(git status)"',onKeyPress:x=>{x.key==="Enter"&&(x.preventDefault(),p(i))},className:"flex-1 h-10"}),e.jsxs(B,{onClick:()=>p(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:bi.map(x=>e.jsx(B,{variant:"outline",size:"sm",onClick:()=>p(x),disabled:a.includes(x),className:"text-xs h-8",children:x},x))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(x=>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:x}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>w(x),className:"text-green-600 hover:text-green-700",children:e.jsx(Je,{className:"w-4 h-4"})})]},x)),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(qt,{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(Ye,{value:h,onChange:x=>g(x.target.value),placeholder:'e.g., "Shell(rm -rf)" or "Shell(sudo)"',onKeyPress:x=>{x.key==="Enter"&&(x.preventDefault(),v(h))},className:"flex-1 h-10"}),e.jsxs(B,{onClick:()=>v(h),disabled:!h,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(x=>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:x}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>y(x),className:"text-red-600 hover:text-red-700",children:e.jsx(Je,{className:"w-4 h-4"})})]},x)),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 ji({permissionMode:t,setPermissionMode:s}){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(wr,{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:()=>s("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:()=>s("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:()=>s("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:()=>s("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:()=>s("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:()=>s("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(qt,{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 wi({agent:t,...s}){return t==="claude"?e.jsx(yi,{...s}):t==="cursor"?e.jsx(vi,{...s}):t==="codex"?e.jsx(ji,{...s}):null}const ki=t=>{switch(t){case"stdio":return e.jsx(nr,{className:"w-4 h-4"});case"sse":return e.jsx(Zs,{className:"w-4 h-4"});case"http":return e.jsx(fr,{className:"w-4 h-4"});default:return e.jsx(or,{className:"w-4 h-4"})}};function Ni({servers:t,onAdd:s,onEdit:a,onDelete:o,onTest:n,onDiscoverTools:l,testResults:i,serverTools:d,toolsLoading:h,onDiscoverRepo:g}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(or,{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.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs(B,{onClick:s,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.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(B,{onClick:g,variant:"outline",size:"sm",children:[e.jsx(es,{className:"w-4 h-4 mr-2"}),"MCP 商店"]})})]}),e.jsxs("div",{className:"space-y-2",children:[t.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-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[ki(p.type),e.jsx("span",{className:"font-medium text-foreground",children:p.name}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:p.type}),e.jsx(Ge,{variant:"outline",className:"text-xs",children:p.scope==="local"?"local":p.scope==="user"?"user":p.scope})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[p.type==="stdio"&&p.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:p.config.command})]}),(p.type==="sse"||p.type==="http")&&p.config?.url&&e.jsxs("div",{children:["URL:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:p.config.url})]}),p.config?.args&&p.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:p.config.args.join(" ")})]})]}),i?.[p.id]&&e.jsx("div",{className:`mt-2 p-2 rounded text-xs ${i[p.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[p.id].message})}),d?.[p.id]&&d[p.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:["工具(",d[p.id].tools.length,"):"]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[d[p.id].tools.slice(0,5).map((w,v)=>e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:w.name},v)),d[p.id].tools.length>5&&e.jsxs("span",{className:"text-xs opacity-75",children:["+",d[p.id].tools.length-5," 更多"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(B,{onClick:()=>a(p),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(sr,{className:"w-4 h-4"})}),e.jsx(B,{onClick:()=>o(p.id,p.scope),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},p.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function Si({servers:t,onAdd:s,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(or,{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(B,{onClick:s,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(nr,{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(B,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",children:e.jsx(sr,{className:"w-4 h-4"})}),e.jsx(B,{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 Ci({servers:t,onAdd:s,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(or,{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(B,{onClick:s,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(nr,{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(B,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(sr,{className:"w-4 h-4"})}),e.jsx(B,{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 Ei({agent:t,...s}){return t==="claude"?e.jsx(Ni,{...s}):t==="cursor"?e.jsx(Si,{...s}):t==="codex"?e.jsx(Ci,{...s}):null}const Mi=[{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)使用的模型"}],Li=r.forwardRef(function({onStatusChange:s},a){const[o,n]=r.useState({}),[l,i]=r.useState({}),[d,h]=r.useState(!0),[g,p]=r.useState(!1),[w,v]=r.useState(null),[y,x]=r.useState(null),P=JSON.stringify(o)!==JSON.stringify(l);r.useEffect(()=>{s?.({saving:g,hasChanges:P})},[g,P,s]),r.useEffect(()=>{R()},[]),r.useEffect(()=>{if(w){const u=setTimeout(()=>v(null),3e3);return()=>clearTimeout(u)}},[w]);const R=async()=>{try{h(!0),x(null);const u=await Q("/api/settings/models");if(u.ok){const m=await u.json();n(m.models||{}),i(m.models||{})}else{const m=await u.json();x(m.error||"加载模型配置失败")}}catch(u){x(u.message)}finally{h(!1)}},C=async()=>{try{p(!0),v(null);const u=await Q("/api/settings/models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({models:o})});if(u.ok)return v("success"),i({...o}),!0;{const m=await u.json();return v("error"),x(m.error||"保存失败"),!1}}catch(u){return v("error"),x(u.message),!1}finally{p(!1)}},k=()=>{n({...l}),v(null)};return r.useImperativeHandle(a,()=>({save:C,reset:k,get hasChanges(){return P},get saving(){return g}}),[P,g,o,l]),d?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(Qs,{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。"})]})]}),y&&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:y}),w==="success"&&e.jsx("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3 text-sm text-green-600 dark:text-green-400",children:"模型配置已保存"}),Mi.map(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:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"font-medium text-sm text-foreground",children:u.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:u.description})]}),e.jsx("input",{type:"text",value:o[u.key]||"",onChange:m=>n(N=>({...N,[u.key]:m.target.value})),placeholder:u.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:u.key})]})},u.key))]})});function Ii({onNavigateToUsage:t}){const[s,a]=r.useState([]),[o,n]=r.useState({}),[l,i]=r.useState(!0),[d,h]=r.useState(null),[g,p]=r.useState(!1),[w,v]=r.useState(""),[y,x]=r.useState(""),[P,R]=r.useState(""),[C,k]=r.useState(!1),[u,m]=r.useState(null),[N,S]=r.useState({total_limit_usd:"",daily_limit_usd:""}),[f,A]=r.useState(""),[F,Z]=r.useState(!1),[le,ee]=r.useState(null),[ne,U]=r.useState(""),[D,X]=r.useState(""),[se,ve]=r.useState(""),[oe,z]=r.useState(!1),ue=async()=>{try{const T=await Q("/api/admin/users");if(T.ok){const _=await T.json();a(_.users)}}catch(T){console.error("Error fetching users:",T)}finally{i(!1)}},Le=async()=>{try{const T=await Q("/api/admin/usage/summary");if(T.ok){const _=await T.json(),W={};for(const b of _.users)W[b.user_uuid]={total_cost:b.total_cost||0,total_requests:b.total_requests||0,last_active:b.last_active};n(W)}}catch(T){console.error("Error fetching usage data:",T)}};r.useEffect(()=>{ue(),Le()},[]);const Te=T=>!T||T===0?"$0.00":T<.01?`$${T.toFixed(4)}`:`$${T.toFixed(2)}`,ke=async(T,_)=>{const W=_==="active"?"disabled":"active";h(T);try{(await Q(`/api/admin/users/${T}`,{method:"PATCH",body:JSON.stringify({status:W})})).ok&&a(s.map(H=>H.id===T?{...H,status:W}:H))}catch(b){console.error("Error updating user status:",b)}finally{h(null)}},Fe=async(T,_)=>{if(confirm(`确定要删除用户 "${_}"?这将删除其所有数据。`)){h(T);try{(await Q(`/api/admin/users/${T}`,{method:"DELETE"})).ok&&a(s.filter(b=>b.id!==T))}catch(W){console.error("Error deleting user:",W)}finally{h(null)}}},we=async T=>{if(T.preventDefault(),R(""),!w||!y){R("用户名和密码不能为空");return}if(w.length<3){R("用户名至少3个字符");return}if(y.length<6){R("密码至少6个字符");return}k(!0);try{const _=await ye.admin.createUser(w,y),W=await _.json();_.ok?(await ue(),p(!1),v(""),x("")):R(W.error||"创建用户失败")}catch(_){console.error("Error creating user:",_),R("网络错误,请稍后再试")}finally{k(!1)}},Se=()=>{p(!1),v(""),x(""),R("")},ze=T=>{m(T),S({total_limit_usd:T.total_limit_usd!==null&&T.total_limit_usd!==void 0?String(T.total_limit_usd):"",daily_limit_usd:T.daily_limit_usd!==null&&T.daily_limit_usd!==void 0?String(T.daily_limit_usd):""}),A("")},Ue=()=>{m(null),S({total_limit_usd:"",daily_limit_usd:""}),A("")},xe=async T=>{T.preventDefault(),A("");const _=N.total_limit_usd.trim()===""?null:parseFloat(N.total_limit_usd),W=N.daily_limit_usd.trim()===""?null:parseFloat(N.daily_limit_usd);if(_!==null&&(isNaN(_)||_<0)){A("总额度限制必须是正数或留空");return}if(W!==null&&(isNaN(W)||W<0)){A("每日额度限制必须是正数或留空");return}Z(!0);try{const b=await ye.admin.updateUserLimits(u.id,{total_limit_usd:_,daily_limit_usd:W}),H=await b.json();b.ok?(a(s.map(pe=>pe.id===u.id?{...pe,total_limit_usd:_,daily_limit_usd:W}:pe)),Ue()):A(H.error||"更新限制失败")}catch(b){console.error("Error updating limits:",b),A("网络错误,请稍后再试")}finally{Z(!1)}},Ce=T=>T==null?"无限制":`$${T.toFixed(2)}`,Ie=T=>{ee(T),U(""),X(""),ve("")},Pe=()=>{ee(null),U(""),X(""),ve("")},De=async T=>{if(T.preventDefault(),ve(""),!ne){ve("请输入新密码");return}if(ne.length<6){ve("密码至少需要6个字符");return}if(ne!==D){ve("两次输入的密码不一致");return}z(!0);try{const _=await ye.admin.resetUserPassword(le.id,ne),W=await _.json();_.ok?Pe():ve(W.error||"重置密码失败")}catch(_){console.error("Error resetting password:",_),ve("网络错误,请稍后再试")}finally{z(!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(B,{variant:"default",size:"sm",onClick:()=>p(!0),className:"flex items-center gap-2",children:[e.jsx(mn,{className:"w-4 h-4"}),"创建用户"]}),t&&e.jsxs(B,{variant:"outline",size:"sm",onClick:t,className:"flex items-center gap-2",children:[e.jsx(un,{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:s.map(T=>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:[T.role==="admin"?e.jsx(wr,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(Xs,{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:T.username||T.email}),T.email&&T.username&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:T.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 ${T.role==="admin"?"bg-blue-500/20 text-blue-400":"bg-gray-500/20 text-gray-400"}`,children:T.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 ${T.status==="active"?"bg-green-500":"bg-red-500"}`,title:T.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:Te(o[T.uuid]?.total_cost)})}),e.jsx("td",{className:"px-3 py-2 text-right",children:T.role!=="admin"?e.jsx("button",{onClick:()=>ze(T),className:"text-xs text-blue-600 dark:text-blue-400 hover:underline font-mono whitespace-nowrap",title:"点击编辑额度限制",children:T.total_limit_usd!==null||T.daily_limit_usd!==null?e.jsxs("span",{className:"flex flex-col items-end text-[11px] leading-tight",children:[e.jsxs("span",{children:["总:",Ce(T.total_limit_usd)]}),e.jsxs("span",{children:["日:",Ce(T.daily_limit_usd)]})]}):e.jsxs("span",{className:"flex items-center gap-1 justify-end",children:[e.jsx(ea,{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(T.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("div",{className:"flex items-center justify-end gap-1",children:T.role!=="admin"&&e.jsxs(e.Fragment,{children:[T.username&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Ie(T),disabled:d===T.id,title:"重置密码",children:e.jsx(Fr,{className:"w-4 h-4 text-blue-500"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>ke(T.id,T.status),disabled:d===T.id,title:T.status==="active"?"禁用用户":"启用用户",children:T.status==="active"?e.jsx(pn,{className:"w-4 h-4 text-orange-500"}):e.jsx(xn,{className:"w-4 h-4 text-green-500"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Fe(T.id,T.username||T.email),disabled:d===T.id,title:"删除用户",children:e.jsx(Ve,{className:"w-4 h-4 text-red-500"})})]})})})]},T.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(Je,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:we,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:w,onChange:T=>v(T.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:C})]}),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:y,onChange:T=>x(T.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:C})]}),P&&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:P})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:Se,disabled:C,children:"取消"}),e.jsx(B,{type:"submit",disabled:C,children:C?"创建中...":"创建"})]})]})]})}),u&&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:["设置额度限制 - ",u.username||u.email]}),e.jsx("button",{onClick:Ue,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:xe,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:N.total_limit_usd,onChange:T=>S(_=>({..._,total_limit_usd:T.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:F}),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:N.daily_limit_usd,onChange:T=>S(_=>({..._,daily_limit_usd:T.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:F}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户每日使用金额达到此限制后,需等待次日重置"})]}),o[u.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:Te(o[u.uuid]?.total_cost)})]})}),f&&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:f})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:Ue,disabled:F,children:"取消"}),e.jsx(B,{type:"submit",disabled:F,children:F?"保存中...":"保存"})]})]})]})}),le&&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:["重置密码 - ",le.username]}),e.jsx("button",{onClick:Pe,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:De,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:ne,onChange:T=>U(T.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:oe})]}),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:D,onChange:T=>X(T.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:oe})]}),se&&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:se})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:Pe,disabled:oe,children:"取消"}),e.jsx(B,{type:"submit",disabled:oe,children:oe?"重置中...":"重置密码"})]})]})]})})]})}function Di(){const[t,s]=r.useState([]),[a,o]=r.useState(!0),[n,l]=r.useState(null),[i,d]=r.useState(!1),[h,g]=r.useState(""),[p,w]=r.useState(""),[v,y]=r.useState(!1),x=async()=>{try{const k=await ye.admin.getEmailDomains();if(k.ok){const u=await k.json();s(u.domains)}}catch(k){console.error("Error fetching email domains:",k)}finally{o(!1)}};r.useEffect(()=>{x()},[]);const P=async k=>{if(k.preventDefault(),w(""),!h){w("域名不能为空");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(h)){w("域名格式无效,例如: example.com");return}y(!0);try{const m=await ye.admin.addEmailDomain(h.toLowerCase()),N=await m.json();m.ok?(await x(),d(!1),g("")):w(N.error||"添加域名失败")}catch(m){console.error("Error adding domain:",m),w("网络错误,请稍后再试")}finally{y(!1)}},R=async(k,u)=>{if(confirm(`确定要删除域名 "${u}"?删除后该域名的邮箱将无法注册。`)){l(k);try{(await ye.admin.removeEmailDomain(k)).ok&&s(t.filter(N=>N.id!==k))}catch(m){console.error("Error removing domain:",m)}finally{l(null)}}},C=()=>{d(!1),g(""),w("")};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(B,{variant:"default",size:"sm",onClick:()=>d(!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(k=>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(br,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"font-medium text-foreground",children:k.domain})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground",children:new Date(k.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>R(k.id,k.domain),disabled:n===k.id,title:"删除域名",children:e.jsx(Ve,{className:"w-4 h-4 text-red-500"})})})})]},k.id))})]})}):e.jsxs("div",{className:"border border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-8 text-center",children:[e.jsx(br,{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:C,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:P,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:h,onChange:k=>g(k.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:v}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入域名后,该域名下的所有邮箱(如 user@example.com)都可以注册"})]}),p&&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:p})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:C,disabled:v,children:"取消"}),e.jsx(B,{type:"submit",disabled:v,children:v?"添加中...":"添加"})]})]})]})})]})}function Ti(){const[t,s]=r.useState(""),[a,o]=r.useState(!0),[n,l]=r.useState(!1),[i,d]=r.useState(null);r.useEffect(()=>{h()},[]);const h=async()=>{try{const p=await ye.admin.getDefaultLimits();if(p.ok){const w=await p.json();s(w.default_total_limit_usd!==null?String(w.default_total_limit_usd):"")}}catch(p){console.error("Error fetching default limits:",p)}finally{o(!1)}},g=async p=>{p.preventDefault(),l(!0),d(null);const w=t.trim()===""?null:parseFloat(t);if(w!==null&&(isNaN(w)||w<0)){d("error"),l(!1);return}try{(await ye.admin.updateDefaultLimits({default_total_limit_usd:w})).ok?(d("success"),setTimeout(()=>d(null),2e3)):d("error")}catch(v){console.error("Error updating default limits:",v),d("error")}finally{l(!1)}};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",{children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"新用户默认额度"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"新注册用户将自动应用此总额度限制,留空表示不限制。管理员账户不受此限制。"})]}),e.jsxs("form",{onSubmit:g,className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1 max-w-xs",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-1",children:"默认总额度上限 (USD)"}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:t,onChange:p=>s(p.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:n})]}),e.jsxs(B,{type:"submit",variant:"default",size:"sm",disabled:n,className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"w-4 h-4"}),n?"保存中...":"保存"]}),i==="success"&&e.jsx("span",{className:"text-sm text-green-600",children:"已保存"}),i==="error"&&e.jsx("span",{className:"text-sm text-red-600",children:"请输入有效的正数"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"此设置仅影响新注册的用户,不会修改已有用户的额度。"})]})}function Pi({onBack:t}){const[s,a]=r.useState("week"),[o,n]=r.useState(null),[l,i]=r.useState(!0),[d,h]=r.useState(!1),g=async()=>{try{const C=await Q(`/api/admin/usage/dashboard?period=${s}`);if(C.ok){const k=await C.json();n(k)}}catch(C){console.error("Error fetching dashboard data:",C)}finally{i(!1),h(!1)}};r.useEffect(()=>{i(!0),g()},[s]);const p=async()=>{try{h(!0),await Q("/api/admin/usage/scan",{method:"POST"}),await g()}catch(C){console.error("Error triggering scan:",C),h(!1)}},w=C=>!C||C===0?"$0.00":C<.01?`$${C.toFixed(4)}`:`$${C.toFixed(2)}`,v=C=>C?C>=1e6?`${(C/1e6).toFixed(1)}M`:C>=1e3?`${(C/1e3).toFixed(1)}K`:C.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:y,dailyTrend:x,modelDistribution:P,topUsers:R}=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(B,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(ir,{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(C=>e.jsx("button",{onClick:()=>a(C),className:`px-4 py-2 text-sm font-medium transition-colors ${s===C?"bg-primary text-primary-foreground":"bg-background text-foreground hover:bg-muted"}`,children:C==="week"?"周":"月"},C))}),e.jsx(B,{variant:"outline",size:"sm",onClick:p,disabled:d,title:"扫描新的使用数据",children:e.jsx(Tt,{className:`w-4 h-4 ${d?"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(ea,{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:w(y?.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(hn,{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:[y?.activeUsers||0," / ",y?.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(Xr,{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:v(y?.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(gn,{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:v(y?.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:"每日成本趋势"}),x&&x.length>0?e.jsx("div",{className:"space-y-2",children:x.map(C=>{const k=Math.max(...x.map(m=>m.cost||0),.01),u=(C.cost||0)/k*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(C.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:`${u}%`}})}),e.jsx("span",{className:"text-sm font-mono text-foreground w-16 text-right",children:w(C.cost)})]},C.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:"模型成本"}),P&&P.length>0?e.jsx("div",{className:"space-y-3",children:P.map(C=>{const k=P.reduce((f,A)=>f+(A.cost||0),0)||1,u=(C.cost||0)/k*100,m=(C.normalized_model||C.model||"").toLowerCase(),S=(f=>f.includes("codex")?"bg-orange-500":f.includes("opus")?"bg-purple-500":f.includes("sonnet")?"bg-blue-500":f.includes("haiku")?"bg-green-500":"bg-gray-500")(m);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:C.model,children:C.model}),e.jsxs("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:[v(C.requests)," 请求"]})]}),e.jsx("span",{className:"text-sm font-mono text-foreground whitespace-nowrap ml-2",children:w(C.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:`${u}%`}})})]},C.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:"用户成本"}),R&&R.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:R.map((C,k)=>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:["#",k+1]}),e.jsx("td",{className:"py-2 text-sm font-medium text-foreground",children:C.username}),e.jsx("td",{className:"py-2 text-sm text-right text-muted-foreground",children:v(C.total_requests)}),e.jsx("td",{className:"py-2 text-sm text-right font-mono text-foreground",children:w(C.total_cost)})]},C.user_uuid))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]})}function Ri({onClose:t,onInstalled:s,onOpenRepoManager:a}){const[o,n]=r.useState([]),[l,i]=r.useState([]),[d,h]=r.useState(!0),[g,p]=r.useState(null),[w,v]=r.useState(""),[y,x]=r.useState("all"),[P,R]=r.useState(null);r.useEffect(()=>{C()},[]);const C=async(m=!1)=>{try{h(!0),p(null),m&&await Q("/api/skills/repos/refresh",{method:"POST"});const[N,S]=await Promise.all([Q("/api/skills/available"),Q("/api/skills/repos")]);if(N.ok){const f=await N.json();n(f.skills||[])}if(S.ok){const f=await S.json();i(f.repos||[])}}catch(N){p(N.message)}finally{h(!1)}},k=async m=>{try{R(m.name);const N=await Q(`/api/skills/install/${m.name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillPath:m.path})});if(N.ok)C(),s?.();else{const S=await N.json();alert(S.error||"Failed to install skill")}}catch(N){alert(N.message)}finally{R(null)}},u=o.filter(m=>{if(w){const N=w.toLowerCase();if(!m.name.toLowerCase().includes(N)&&!m.title?.toLowerCase().includes(N)&&!m.description?.toLowerCase().includes(N))return!1}return!(y!=="all"&&m.repository!==y)});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(B,{variant:"ghost",size:"sm",onClick:()=>C(!0),disabled:d,children:[e.jsx(Tt,{className:`w-4 h-4 ${d?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(B,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(wt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Je,{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(Pt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ye,{type:"text",placeholder:"搜索技能名称或描述...",value:w,onChange:m=>v(m.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:y,onChange:m=>x(m.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(m=>e.jsxs("option",{value:`${m.owner}/${m.repo}`,children:[m.owner,"/",m.repo]},`${m.owner}/${m.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}),d?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):u.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(B,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(wt,{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:u.map(m=>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:m.title||m.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["skills/",m.name]}),e.jsx(Ge,{variant:"outline",className:"text-xs ml-2",children:m.repository})]})]}),m.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:m.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-auto pt-2",children:[e.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>window.open(`https://github.com/${m.repository}`,"_blank"),children:[e.jsx(ta,{className:"w-4 h-4 mr-1"}),"查看"]}),m.installed?e.jsx(B,{size:"sm",disabled:!0,variant:"outline",className:"ml-auto",children:"已安装"}):e.jsxs(B,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white ml-auto",onClick:()=>k(m),disabled:P===m.name,children:[e.jsx(Dt,{className:"w-4 h-4 mr-1"}),P===m.name?"安装中...":"安装"]})]})]})},`${m.repository}-${m.name}`))})]})]})})}function $i({onClose:t,onChanged:s}){const[a,o]=r.useState([]),[n,l]=r.useState(!0),[i,d]=r.useState(null),[h,g]=r.useState(""),[p,w]=r.useState("main"),[v,y]=r.useState(!1),[x,P]=r.useState(null);r.useEffect(()=>{R()},[]);const R=async()=>{try{l(!0),d(null);const u=await Q("/api/skills/repos");if(u.ok){const m=await u.json();o(m.repos||[])}else{const m=await u.json();d(m.error||"Failed to fetch repos")}}catch(u){d(u.message)}finally{l(!1)}},C=async u=>{if(u.preventDefault(),!h.trim()){d("请输入仓库 URL");return}try{y(!0),d(null);const m=await Q("/api/skills/repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:h.trim(),branch:p.trim()||"main"})});if(m.ok)g(""),w("main"),R(),s?.();else{const N=await m.json();d(N.error||"Failed to add repo")}}catch(m){d(m.message)}finally{y(!1)}},k=async(u,m)=>{if(confirm(`确定要移除仓库 "${u}/${m}" 吗?`))try{P(`${u}/${m}`);const N=await Q(`/api/skills/repos/${u}/${m}`,{method:"DELETE"});if(N.ok)R(),s?.();else{const S=await N.json();alert(S.error||"Failed to remove repo")}}catch(N){alert(N.message)}finally{P(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(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(ir,{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:C,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(Ye,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:h,onChange:u=>g(u.target.value),disabled:v})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"分支"}),e.jsx(Ye,{type:"text",placeholder:"main",value:p,onChange:u=>w(u.target.value),disabled:v})]}),e.jsxs(B,{type:"submit",disabled:v||!h.trim(),className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),v?"添加中...":"添加仓库"]})]})]}),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(ra,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何仓库"})]}):a.map(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",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium text-foreground",children:[u.owner,"/",u.repo]}),u.isSystem&&e.jsx(Ge,{variant:"outline",className:"text-xs bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300",children:"内置"})]}),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(es,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Ge,{variant:"outline",className:"text-xs",children:["识别到 ",u.skillCount," 个技能"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[!u.isSystem&&u.url&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>window.open(u.url,"_blank"),children:e.jsx(ta,{className:"w-4 h-4"})}),!u.isSystem&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>k(u.owner,u.repo),disabled:x===`${u.owner}/${u.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(Ve,{className:"w-4 h-4"})})]})]})},`${u.owner}/${u.repo}`))]})]})]})})}function zi(){const[t,s]=r.useState([]),[a,o]=r.useState(!0),[n,l]=r.useState(null),[i,d]=r.useState(!1),[h,g]=r.useState(!1),[p,w]=r.useState(!1),v=r.useRef(null);r.useEffect(()=>{y()},[]);const y=async()=>{try{o(!0),l(null);const k=await Q("/api/skills");if(k.ok){const u=await k.json();s(u.skills||[])}else{const u=await k.json();l(u.error||"Failed to fetch skills")}}catch(k){l(k.message)}finally{o(!1)}},x=async k=>{if(confirm(`确定要删除技能 "${k}" 吗?`))try{const u=await Q(`/api/skills/${k}`,{method:"DELETE"});if(u.ok)y();else{const m=await u.json();alert(m.error||"Failed to delete skill")}}catch(u){alert(u.message)}},P=()=>{v.current?.click()},R=async k=>{const u=k.target.files?.[0];if(u)try{w(!0);const m=new FormData;m.append("skillZip",u);const N=await Q("/api/skills/import",{method:"POST",body:m});if(N.ok)y();else{const S=await N.json();alert(S.error||"Failed to import skill")}}catch(m){alert(m.message)}finally{w(!1),v.current&&(v.current.value="")}},C=(k,u)=>{switch(k){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:u||"仓库"});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(Wr,{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:v,type:"file",accept:".zip",className:"hidden",onChange:R}),e.jsxs(B,{onClick:P,variant:"outline",size:"sm",disabled:p,children:[e.jsx(Dt,{className:"w-4 h-4 mr-2"}),p?"导入中...":"导入已有"]}),e.jsxs(B,{onClick:()=>d(!0),className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:[e.jsx(Pt,{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(Wr,{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(k=>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:k.title||k.name}),C(k.source,k.repository)]}),k.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:k.description})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4 shrink-0",children:e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>x(k.name),className:"text-red-500 hover:text-red-600",title:"删除技能",children:e.jsx(Ve,{className:"w-4 h-4"})})})]})},k.name))}),i&&e.jsx(Ri,{onClose:()=>d(!1),onInstalled:y,onOpenRepoManager:()=>{d(!1),g(!0)}}),h&&e.jsx($i,{onClose:()=>g(!1),onChanged:()=>{}})]})}function Oi({onClose:t,onChanged:s}){const[a,o]=r.useState([]),[n,l]=r.useState(!0),[i,d]=r.useState(null),[h,g]=r.useState(""),[p,w]=r.useState(!1),[v,y]=r.useState(null);r.useEffect(()=>{x()},[]);const x=async()=>{try{l(!0),d(null);const C=await Q("/api/mcp-repos");if(C.ok){const k=await C.json();o(k.repos||[])}else{const k=await C.json();d(k.error||"Failed to fetch repos")}}catch(C){d(C.message)}finally{l(!1)}},P=async C=>{if(C.preventDefault(),!h.trim()){d("请输入仓库 URL");return}try{w(!0),d(null);const k=await Q("/api/mcp-repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:h.trim()})});if(k.ok)g(""),x(),s?.();else{const u=await k.json();d(u.error||"Failed to add repo")}}catch(k){d(k.message)}finally{w(!1)}},R=async(C,k)=>{if(confirm(`确定要移除仓库 "${C}/${k}" 吗?`))try{y(`${C}/${k}`);const u=await Q(`/api/mcp-repos/${C}/${k}`,{method:"DELETE"});if(u.ok)x(),s?.();else{const m=await u.json();alert(m.error||"Failed to remove repo")}}catch(u){alert(u.message)}finally{y(null)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[10000] 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(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(ir,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"管理 MCP 仓库"})]}),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:"添加 MCP 仓库"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["仓库中每个文件夹代表一个 MCP 服务,需包含 ",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:"mcp.json"}),"(配置)和 ",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:"mcp.yaml"}),"(说明)。"]}),e.jsxs("form",{onSubmit:P,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(Ye,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:h,onChange:C=>g(C.target.value),disabled:p})]}),e.jsxs(B,{type:"submit",disabled:p||!h.trim(),className:"bg-purple-600 hover:bg-purple-700 text-white",children:[e.jsx(st,{className:"w-4 h-4 mr-2"}),p?"添加中...":"添加仓库"]})]})]}),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(ra,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何 MCP 仓库"})]}):a.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-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium text-foreground",children:[C.owner,"/",C.repo]}),C.isSystem&&e.jsx(Ge,{variant:"outline",className:"text-xs bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",children:"内置"})]}),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(es,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Ge,{variant:"outline",className:"text-xs",children:[C.serviceCount," 个 MCP 服务"]})]})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4",children:!C.isSystem&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>R(C.owner,C.repo),disabled:v===`${C.owner}/${C.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(Ve,{className:"w-4 h-4"})})})]})},`${C.owner}/${C.repo}`))]})]})]})})}const Ai=t=>{switch(t){case"stdio":return e.jsx(nr,{className:"w-3 h-3"});case"sse":return e.jsx(Zs,{className:"w-3 h-3"});case"http":return e.jsx(fr,{className:"w-3 h-3"});default:return e.jsx(or,{className:"w-3 h-3"})}};function _i({onClose:t,onInstalled:s,onOpenRepoManager:a}){const[o,n]=r.useState([]),[l,i]=r.useState([]),[d,h]=r.useState(!0),[g,p]=r.useState(null),[w,v]=r.useState(""),[y,x]=r.useState("all"),[P,R]=r.useState(null),[C,k]=r.useState(null);r.useEffect(()=>{u()},[]);const u=async(f=!1)=>{try{h(!0),p(null),f&&await Q("/api/mcp-repos/refresh",{method:"POST"});const[A,F]=await Promise.all([Q("/api/mcp-repos/available"),Q("/api/mcp-repos")]);if(A.ok){const Z=await A.json();n(Z.services||[])}if(F.ok){const Z=await F.json();i(Z.repos||[])}}catch(A){p(A.message)}finally{h(!1)}},m=async f=>{try{R(f.dirName+f.repository);const A=await Q("/api/mcp-repos/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({servicePath:f.path})});if(A.ok)u(),s?.();else{const F=await A.json();alert(F.error||"Failed to install MCP service")}}catch(A){alert(A.message)}finally{R(null)}},N=async f=>{if(!(!f.serverNames||f.serverNames.length===0)&&confirm(`确定要卸载 "${f.name}" 吗?这将移除 ${f.serverNames.join(", ")} 的配置。`))try{k(f.dirName+f.repository);for(const A of f.serverNames)await Q(`/api/mcp-repos/uninstall/${encodeURIComponent(A)}`,{method:"DELETE"});u(),s?.()}catch(A){alert(A.message)}finally{k(null)}},S=o.filter(f=>{if(w){const A=w.toLowerCase();if(!f.dirName?.toLowerCase().includes(A)&&!f.name?.toLowerCase().includes(A)&&!f.description?.toLowerCase().includes(A))return!1}return!(y!=="all"&&f.repository!==y)});return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[10000] 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:"MCP 仓库"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>u(!0),disabled:d,children:[e.jsx(Tt,{className:`w-4 h-4 ${d?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(B,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(wt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Je,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2",children:e.jsx("h3",{className:"text-purple-500 font-medium",children:"发现 MCP 服务"})}),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(Pt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ye,{type:"text",placeholder:"搜索 MCP 服务名称或描述...",value:w,onChange:f=>v(f.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:y,onChange:f=>x(f.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(f=>e.jsxs("option",{value:`${f.owner}/${f.repo}`,children:[f.owner,"/",f.repo]},`${f.owner}/${f.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}),d?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):S.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:"没有可用的 MCP 服务"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加 MCP 仓库"}),e.jsxs(B,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(wt,{className:"w-4 h-4 mr-2"}),"管理仓库"]})]}):e.jsx("p",{children:"没有找到匹配的 MCP 服务"})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:S.map(f=>{const A=`${f.repository}-${f.dirName}`,F=P===f.dirName+f.repository,Z=C===f.dirName+f.repository;return e.jsx("div",{className:"border border-border rounded-lg p-4 hover:border-purple-500/50 transition-colors",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-medium text-foreground",children:f.name||f.dirName}),e.jsxs(Ge,{variant:"outline",className:"text-xs flex items-center gap-1",children:[Ai(f.type),f.type]})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:f.repository}),f.serverNames?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:["· ",f.serverNames.join(", ")]})]})]}),f.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:f.description}),e.jsx("div",{className:"flex items-center gap-2 mt-auto pt-2",children:f.installed?e.jsxs(B,{size:"sm",variant:"outline",className:"ml-auto text-red-600 hover:text-red-700 border-red-200 hover:border-red-300",onClick:()=>N(f),disabled:Z,children:[e.jsx(Ve,{className:"w-4 h-4 mr-1"}),Z?"卸载中...":"卸载"]}):e.jsxs(B,{size:"sm",className:"bg-purple-600 hover:bg-purple-700 text-white ml-auto",onClick:()=>m(f),disabled:F,children:[e.jsx(Dt,{className:"w-4 h-4 mr-1"}),F?"安装中...":"安装"]})})]})},A)})})]})]})})}function Fi({isOpen:t,onClose:s,projects:a=[],initialTab:o="agents"}){const n=Hs(),{isDarkMode:l,toggleDarkMode:i}=cs(),{user:d,logout:h}=Kt(),g=d?.role==="admin",[p,w]=r.useState([]),[v,y]=r.useState([]),[x,P]=r.useState(""),[R,C]=r.useState(""),[k,u]=r.useState(!1),[m,N]=r.useState(!1),[S,f]=r.useState(null),[A,F]=r.useState("name"),[Z,le]=r.useState([]),[ee,ne]=r.useState(!1),[U,D]=r.useState(null),[X,se]=r.useState(!1),[ve,oe]=r.useState(!1),[z,ue]=r.useState({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),[Le,Te]=r.useState(!1),[ke,Fe]=r.useState({}),[we,Se]=r.useState({}),[ze,Ue]=r.useState({}),[xe,Ce]=r.useState(o),[Ie,Pe]=r.useState(""),[De,T]=r.useState("permissions"),[_,W]=r.useState(!1),b=r.useRef(null),[H,pe]=r.useState({saving:!1,hasChanges:!1}),Ne=r.useCallback(I=>pe(I),[]),[Oe,at]=r.useState(""),[K,ae]=r.useState(""),[j,V]=r.useState(""),[de,ce]=r.useState(""),[$,$e]=r.useState(""),[Y,re]=r.useState(!1),[ie,be]=r.useState(""),[fe,je]=r.useState(!1),[Ee,He]=r.useState(""),[Xe,We]=r.useState(!1),[kt,kr]=r.useState(()=>localStorage.getItem("codeEditorTheme")||"dark"),[ut,Nt]=r.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[gt,Nr]=r.useState(()=>localStorage.getItem("codeEditorShowMinimap")!=="false"),[et,Sr]=r.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[St,Gt]=r.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),ft=async()=>{try{const I=await Q("/api/mcp/config/read");if(I.ok){const Me=await I.json();if(Me.success&&Me.servers){le(Me.servers);return}}const q=await Q("/api/mcp/cli/list");if(q.ok){const Me=await q.json();if(Me.success&&Me.servers){const Qe=Me.servers.map(lt=>({id:lt.name,name:lt.name,type:lt.type,scope:"user",config:{command:lt.command||"",args:lt.args||[],env:lt.env||{},url:lt.url||"",headers:lt.headers||{},timeout:3e4},created:new Date().toISOString(),updated:new Date().toISOString()}));le(Qe);return}}const te=await Q("/api/mcp/servers?scope=user");if(te.ok){const Me=await te.json();le(Me.servers||[])}else console.error("Failed to fetch MCP servers")}catch(I){console.error("Error fetching MCP servers:",I)}},$t=async I=>{try{U&&await Vt(U.id,"user");const q=await Q("/api/mcp/cli/add",{method:"POST",body:JSON.stringify({name:I.name,type:I.type,scope:I.scope,projectPath:I.projectPath,command:I.config?.command,args:I.config?.args||[],url:I.config?.url,headers:I.config?.headers||{},env:I.config?.env||{}})});if(q.ok){const te=await q.json();if(te.success)return await ft(),!0;throw new Error(te.error||"Failed to save server via Claude CLI")}else{const te=await q.json();throw new Error(te.error||"Failed to save server")}}catch(q){throw console.error("Error saving MCP server:",q),q}},Vt=async(I,q="user")=>{try{const te=await Q(`/api/mcp/cli/remove/${I}?scope=${q}`,{method:"DELETE"});if(te.ok){const Me=await te.json();if(Me.success)return await ft(),!0;throw new Error(Me.error||"Failed to delete server via Claude CLI")}else{const Me=await te.json();throw new Error(Me.error||"Failed to delete server")}}catch(te){throw console.error("Error deleting MCP server:",te),te}},zt=async(I,q="user")=>{try{const te=await Q(`/api/mcp/servers/${I}/test?scope=${q}`,{method:"POST"});if(te.ok)return(await te.json()).testResult;{const Me=await te.json();throw new Error(Me.error||"Failed to test server")}}catch(te){throw console.error("Error testing MCP server:",te),te}},Cr=async(I,q="user")=>{try{const te=await Q(`/api/mcp/servers/${I}/tools?scope=${q}`,{method:"POST"});if(te.ok)return(await te.json()).toolsResult;{const Me=await te.json();throw new Error(Me.error||"Failed to discover tools")}}catch(te){throw console.error("Error discovering MCP tools:",te),te}};r.useEffect(()=>{t&&(nt(),Ce(o),W(!1))},[t,o]),r.useEffect(()=>{localStorage.setItem("codeEditorTheme",kt),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[kt]),r.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",ut.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[ut]),r.useEffect(()=>{localStorage.setItem("codeEditorShowMinimap",gt.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[gt]),r.useEffect(()=>{localStorage.setItem("codeEditorLineNumbers",et.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[et]),r.useEffect(()=>{localStorage.setItem("codeEditorFontSize",St),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[St]);const nt=async()=>{try{let I=null;try{const q=await ye.settings.getAgentPermissions();q.ok&&(I=(await q.json()).agentPermissions)}catch{}if(I)w(I.allowedTools||[]),y(I.disallowedTools||[]),u(I.skipPermissions||!1),F(I.projectSortOrder||"name"),localStorage.setItem("claude-settings",JSON.stringify(I));else{const q=localStorage.getItem("claude-settings");if(q){const te=JSON.parse(q);w(te.allowedTools||[]),y(te.disallowedTools||[]),u(te.skipPermissions||!1),F(te.projectSortOrder||"name")}else w([]),y([]),u(!1),F("name")}await ft()}catch(I){console.error("Error loading tool settings:",I),w([]),y([]),u(!1),F("name")}},Yt=async()=>{N(!0),f(null);try{const I={allowedTools:p,disallowedTools:v,skipPermissions:k,projectSortOrder:A,lastUpdated:new Date().toISOString()};localStorage.setItem("claude-settings",JSON.stringify(I));try{await ye.settings.saveAgentPermissions(I)}catch(q){console.warn("Failed to sync agent permissions to server:",q)}f("success"),setTimeout(()=>{s()},1e3)}catch(I){console.error("Error saving tool settings:",I),f("error")}finally{N(!1)}},Ot=async I=>{if(I.preventDefault(),ce(""),$e(""),!Oe){ce("请输入当前密码");return}if(!K){ce("请输入新密码");return}if(K.length<6){ce("新密码至少需要6个字符");return}if(K!==j){ce("两次输入的新密码不一致");return}re(!0);try{const q=await ye.auth.changePassword(Oe,K),te=await q.json();q.ok?($e("密码修改成功"),at(""),ae(""),V("")):ce(te.error||"修改密码失败")}catch(q){console.error("Error changing password:",q),ce("网络错误,请稍后再试")}finally{re(!1)}},Qt=d?.username&&!d.username.includes("@"),Ct=async()=>{je(!0),He(""),be(""),We(!1);try{const I=await ye.auth.feishuBindToken(),q=await I.json();I.ok&&q.token?be(q.token):He(q.error||"生成失败,请重试")}catch{He("网络错误,请稍后再试")}finally{je(!1)}},ot=()=>{if(!ie)return;const I=`/auth ${ie}`;if(navigator.clipboard&&window.isSecureContext)navigator.clipboard.writeText(I).then(()=>{We(!0),setTimeout(()=>We(!1),2e3)});else{const q=document.createElement("textarea");q.value=I,q.style.position="fixed",q.style.opacity="0",document.body.appendChild(q),q.focus(),q.select();try{document.execCommand("copy"),We(!0),setTimeout(()=>We(!1),2e3)}finally{document.body.removeChild(q)}}},Ke=()=>{ue({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),D(null),ne(!1),Pe("")},At=(I=null)=>{I?(D(I),ue({name:I.name,type:I.type,scope:I.scope,projectPath:I.projectPath||"",config:{...I.config},raw:I.raw,importMode:"form",jsonInput:""})):Ke(),ne(!0)},pt=async I=>{I.preventDefault(),Te(!0);try{if(z.importMode==="json"){const q=await Q("/api/mcp/cli/add-json",{method:"POST",body:JSON.stringify({name:z.name,jsonConfig:z.jsonInput,scope:z.scope,projectPath:z.projectPath})});if(q.ok){const te=await q.json();if(te.success)await ft(),Ke(),f("success");else throw new Error(te.error||"Failed to add server via JSON")}else{const te=await q.json();throw new Error(te.error||"Failed to add server")}}else await $t(z),Ke(),f("success")}catch(q){alert(`Error: ${q.message}`),f("error")}finally{Te(!1)}},_t=async(I,q)=>{if(confirm("确定要删除此 MCP 服务器吗?"))try{await Vt(I,q),f("success")}catch(te){alert(`Error: ${te.message}`),f("error")}},Ft=async(I,q)=>{try{Fe({...ke,[I]:{loading:!0}});const te=await zt(I,q);Fe({...ke,[I]:te})}catch(te){Fe({...ke,[I]:{success:!1,message:te.message,details:[]}})}},it=async(I,q)=>{try{Ue({...ze,[I]:!0});const te=await Cr(I,q);Se({...we,[I]:te})}catch{Se({...we,[I]:{success:!1,tools:[],resources:[],prompts:[]}})}finally{Ue({...ze,[I]:!1})}},Et=(I,q)=>{ue(te=>({...te,config:{...te.config,[I]:q}}))};return t?e.jsxs(e.Fragment,{children:[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(wt,{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(B,{variant:"ghost",size:"sm",onClick:s,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(Je,{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:()=>Ce("agents"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${xe==="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:()=>Ce("appearance"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${xe==="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:()=>Ce("users"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${xe==="users"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"用户"}),e.jsx("button",{onClick:()=>Ce("account"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${xe==="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:[xe==="appearance"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:xe==="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(Br,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Ur,{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:A,onChange:I=>F(I.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:()=>kr(kt==="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":kt==="dark","aria-label":"Toggle editor theme",children:[e.jsx("span",{className:"sr-only",children:"Toggle editor theme"}),e.jsx("span",{className:`${kt==="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:kt==="dark"?e.jsx(Br,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Ur,{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:()=>Nt(!ut),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":ut,"aria-label":"Toggle word wrap",children:[e.jsx("span",{className:"sr-only",children:"Toggle word wrap"}),e.jsx("span",{className:`${ut?"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:()=>Nr(!gt),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":gt,"aria-label":"Toggle minimap",children:[e.jsx("span",{className:"sr-only",children:"Toggle minimap"}),e.jsx("span",{className:`${gt?"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:()=>Sr(!et),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":et,"aria-label":"Toggle line numbers",children:[e.jsx("span",{className:"sr-only",children:"Toggle line numbers"}),e.jsx("span",{className:`${et?"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:St,onChange:I=>Gt(I.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"})]})]})})]})]})}),xe==="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:()=>T("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 ${De==="permissions"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"权限"}),e.jsx("button",{onClick:()=>T("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 ${De==="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:()=>T("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 ${De==="skills"?"border-amber-600 text-amber-600 dark:text-amber-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"技能"}),e.jsx("button",{onClick:()=>T("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 ${De==="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:[De==="permissions"&&e.jsx(wi,{agent:"claude",skipPermissions:k,setSkipPermissions:u,allowedTools:p,setAllowedTools:w,disallowedTools:v,setDisallowedTools:y,newAllowedTool:x,setNewAllowedTool:P,newDisallowedTool:R,setNewDisallowedTool:C}),De==="mcp"&&e.jsx(Ei,{agent:"claude",servers:Z,onAdd:()=>At(),onEdit:I=>At(I),onDelete:(I,q)=>_t(I,q),onTest:(I,q)=>Ft(I,q),onDiscoverTools:(I,q)=>it(I,q),testResults:ke,serverTools:we,toolsLoading:ze,onDiscoverRepo:()=>se(!0)}),De==="skills"&&e.jsx(zi,{}),De==="models"&&e.jsx(Li,{ref:b,onStatusChange:Ne})]})]})}),xe==="users"&&g&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:_?e.jsx(Pi,{onBack:()=>W(!1)}):e.jsxs(e.Fragment,{children:[e.jsx(Ii,{onNavigateToUsage:()=>W(!0)}),e.jsx(Ti,{}),e.jsx(Di,{})]})}),xe==="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:d?.username?.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:d?.username}),e.jsx("div",{className:"text-sm text-muted-foreground",children:d?.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(Fr,{className:"w-5 h-5 text-blue-600"}),e.jsx("div",{className:"font-medium text-foreground",children:"修改密码"})]}),e.jsxs("form",{onSubmit:Ot,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:Oe,onChange:I=>at(I.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:Y})]}),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:K,onChange:I=>ae(I.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:Y})]}),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:j,onChange:I=>V(I.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:Y})]}),de&&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:de})}),$&&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:$})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(B,{type:"submit",disabled:Y,className:"bg-blue-600 hover:bg-blue-700",children:Y?"修改中...":"修改密码"})})]})]}),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-3",children:[e.jsx("img",{src:"/feishu-logo.svg",alt:"飞书",className:"h-4"}),e.jsx("div",{className:"font-medium text-foreground",children:"飞书账号绑定"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-3",children:["生成绑定 Token,在飞书中向机器人发送 ",e.jsx("code",{className:"bg-gray-200 dark:bg-gray-700 px-1 rounded text-xs",children:"/auth <token>"})," 即可完成绑定,Token 有效期 24 小时。"]}),ie?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-background border border-border rounded-md",children:[e.jsxs("code",{className:"flex-1 text-xs text-foreground font-mono break-all select-all",children:["/auth ",ie]}),e.jsx("button",{onClick:ot,className:"shrink-0 p-1.5 rounded hover:bg-gray-100 dark:hover:bg-gray-800 text-muted-foreground hover:text-foreground transition-colors",title:"复制命令",children:Xe?e.jsx(hr,{className:"w-4 h-4 text-green-500"}):e.jsx(fn,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"复制上方命令,在飞书私聊机器人中发送"}),e.jsxs("button",{onClick:Ct,disabled:fe,className:"flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 hover:underline disabled:opacity-50",children:[e.jsx(Tt,{className:"w-3 h-3"}),"重新生成"]})]})]}):e.jsxs("div",{className:"space-y-2",children:[Ee&&e.jsx("p",{className:"text-sm text-red-500",children:Ee}),e.jsxs(B,{onClick:Ct,disabled:fe,variant:"outline",className:"gap-2",children:[fe?e.jsx(Tt,{className:"w-4 h-4 animate-spin"}):e.jsx(Fr,{className:"w-4 h-4"}),fe?"生成中...":"生成绑定 Token"]})]})]}),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(B,{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("确定要退出登录吗?")&&(s(),n("/"),h())},children:[e.jsx(bn,{className:"w-4 h-4"}),"退出"]})]})})]})}),ee&&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:U?"编辑 MCP 服务器":"添加 MCP 服务器"}),e.jsx(B,{variant:"ghost",size:"sm",onClick:Ke,children:e.jsx(Je,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:pt,className:"p-4 space-y-4",children:[!U&&e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>ue(I=>({...I,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:()=>ue(I=>({...I,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"&&U&&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(fr,{className:"w-4 h-4"}):e.jsx(It,{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"&&!U&&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:()=>ue(I=>({...I,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(fr,{className:"w-4 h-4"}),e.jsx("span",{children:"用户(全局)"})]})}),e.jsx("button",{type:"button",onClick:()=>ue(I=>({...I,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(It,{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"&&!U&&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:I=>ue(q=>({...q,projectPath:I.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(I=>e.jsx("option",{value:I.path||I.fullPath,children:I.displayName||I.name},I.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(Ye,{value:z.name,onChange:I=>{ue(q=>({...q,name:I.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:I=>{ue(q=>({...q,type:I.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"})]})]})]}),U&&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 ",U.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:I=>{ue(q=>({...q,jsonInput:I.target.value}));try{if(I.target.value.trim()){const q=JSON.parse(I.target.value);q.type?q.type==="stdio"&&!q.command?Pe("stdio 类型需要 command 字段"):(q.type==="http"||q.type==="sse")&&!q.url?Pe(`${q.type} 类型需要 url 字段`):Pe(""):Pe("缺少必填字段:type")}}catch{I.target.value.trim()?Pe("无效的 JSON 格式"):Pe("")}},className:`w-full px-3 py-2 border ${Ie?"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
+ "type": "stdio",
137
+ "command": "/path/to/server",
138
+ "args": ["--api-key", "abc123"],
139
+ "env": {
140
+ "CACHE_DIR": "/tmp"
141
+ }
142
+ }`,required:!0}),Ie&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:Ie}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["以 JSON 格式粘贴您的 MCP 服务器配置。示例格式:",e.jsx("br",{}),"• stdio: ",'{"type":"stdio","command":"npx","args":["@upstash/context7-mcp"]}',e.jsx("br",{}),"• http/sse: ",'{"type":"http","url":"https://api.example.com/mcp"}']})]})}),z.importMode==="form"&&z.type==="stdio"&&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.jsx(Ye,{value:z.config.command,onChange:I=>Et("command",I.target.value),placeholder:"/path/to/mcp-server",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"参数(每行一个)"}),e.jsx("textarea",{value:Array.isArray(z.config.args)?z.config.args.join(`
143
+ `):"",onChange:I=>Et("args",I.target.value.split(`
144
+ `).filter(q=>q.trim())),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",rows:"3",placeholder:`--api-key
145
+ abc123`})]})]}),z.importMode==="form"&&(z.type==="sse"||z.type==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"URL *"}),e.jsx(Ye,{value:z.config.url,onChange:I=>Et("url",I.target.value),placeholder:"https://api.example.com/mcp",type:"url",required:!0})]}),z.importMode==="form"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"环境变量(KEY=value,每行一个)"}),e.jsx("textarea",{value:Object.entries(z.config.env||{}).map(([I,q])=>`${I}=${q}`).join(`
146
+ `),onChange:I=>{const q={};I.target.value.split(`
147
+ `).forEach(te=>{const[Me,...Qe]=te.split("=");Me&&Me.trim()&&(q[Me.trim()]=Qe.join("=").trim())}),Et("env",q)},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",rows:"3",placeholder:`API_KEY=your-key
148
+ DEBUG=true`})]}),z.importMode==="form"&&(z.type==="sse"||z.type==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"请求头(KEY=value,每行一个)"}),e.jsx("textarea",{value:Object.entries(z.config.headers||{}).map(([I,q])=>`${I}=${q}`).join(`
149
+ `),onChange:I=>{const q={};I.target.value.split(`
150
+ `).forEach(te=>{const[Me,...Qe]=te.split("=");Me&&Me.trim()&&(q[Me.trim()]=Qe.join("=").trim())}),Et("headers",q)},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",rows:"3",placeholder:`Authorization=Bearer token
151
+ X-API-Key=your-key`})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(B,{type:"button",variant:"outline",onClick:Ke,children:"取消"}),e.jsx(B,{type:"submit",disabled:Le,className:"bg-purple-600 hover:bg-purple-700 disabled:opacity-50",children:Le?"保存中...":U?"更新服务器":"添加服务器"})]})]})]})})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between p-4 md:p-6 border-t border-border flex-shrink-0 gap-3 pb-safe-area-inset-bottom",children:[e.jsx("div",{className:"flex items-center justify-center sm:justify-start gap-2 order-2 sm:order-1",children:xe==="agents"&&De==="models"?H.saving?e.jsx("span",{className:"text-sm text-muted-foreground",children:"保存中..."}):null:e.jsxs(e.Fragment,{children:[S==="success"&&e.jsxs("div",{className:"text-green-600 dark:text-green-400 text-sm flex items-center gap-1",children:[e.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),"设置保存成功!"]}),S==="error"&&e.jsxs("div",{className:"text-red-600 dark:text-red-400 text-sm flex items-center gap-1",children:[e.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),"保存设置失败"]})]})}),e.jsxs("div",{className:"flex items-center gap-3 order-1 sm:order-2",children:[xe==="agents"&&De==="models"&&H.hasChanges&&e.jsx(B,{variant:"outline",onClick:()=>b.current?.reset(),disabled:H.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"重置"}),e.jsx(B,{variant:"outline",onClick:s,disabled:m||H.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"取消"}),e.jsx(B,{onClick:xe==="agents"&&De==="models"?()=>b.current?.save():Yt,disabled:xe==="agents"&&De==="models"?H.saving||!H.hasChanges:m,className:"flex-1 sm:flex-none h-10 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 touch-manipulation",children:m||H.saving?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 animate-spin rounded-full border-2 border-white border-t-transparent"}),"保存中..."]}):"保存设置"})]})]})]})}),X&&e.jsx(_i,{onClose:()=>se(!1),onInstalled:()=>ft(),onOpenRepoManager:()=>{se(!1),oe(!0)}}),ve&&e.jsx(Oi,{onClose:()=>oe(!1),onChanged:()=>{}})]}):null}function Wi(){const{isDarkMode:t,toggleDarkMode:s}=cs();return e.jsxs("button",{onClick:s,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":t,"aria-label":"Toggle dark mode",children:[e.jsx("span",{className:"sr-only",children:"Toggle dark mode"}),e.jsx("span",{className:`${t?"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:t?e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-700",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})}):e.jsx("svg",{className:"w-3.5 h-3.5 text-yellow-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})})})]})}const Bi=({isOpen:t,onToggle:s,autoExpandTools:a,onAutoExpandChange:o,showRawParameters:n,onShowRawParametersChange:l,showThinking:i,onShowThinkingChange:d,autoScrollToBottom:h,onAutoScrollChange:g,sendByCtrlEnter:p,onSendByCtrlEnterChange:w,isMobile:v})=>{const[y,x]=r.useState(t),[P,R]=r.useState(()=>localStorage.getItem("whisperMode")||"default"),{isDarkMode:C}=cs(),[k,u]=r.useState(()=>{const z=localStorage.getItem("quickSettingsHandlePosition");if(z)try{return JSON.parse(z).y??50}catch{return localStorage.removeItem("quickSettingsHandlePosition"),50}return 50}),[m,N]=r.useState(!1),[S,f]=r.useState(0),[A,F]=r.useState(0),[Z,le]=r.useState(!1),ee=r.useRef(null),ne=r.useRef({min:10,max:90}),U=5;r.useEffect(()=>{x(t)},[t]),r.useEffect(()=>{localStorage.setItem("quickSettingsHandlePosition",JSON.stringify({y:k}))},[k]);const D=r.useCallback(()=>v?{bottom:`${window.innerHeight*k/100}px`}:{top:`${k}%`,transform:"translateY(-50%)"},[k,v]),X=r.useCallback(z=>{z.stopPropagation();const ue=z.type.includes("touch")?z.touches[0].clientY:z.clientY;f(ue),F(k),le(!1),N(!1)},[k]),se=r.useCallback(z=>{if(S===0)return;const ue=z.type.includes("touch")?z.touches[0].clientY:z.clientY,Le=Math.abs(ue-S);if(!m&&Le>U&&(N(!0),le(!0),document.body.style.cursor="grabbing",document.body.style.userSelect="none",z.type.includes("touch")&&(document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.width="100%")),!m)return;z.type.includes("touch")&&z.preventDefault();const Te=ue-S;let ke;v?ke=-(Te/window.innerHeight)*100:ke=Te/window.innerHeight*100;let Fe=A+ke;Fe=Math.max(ne.current.min,Math.min(ne.current.max,Fe)),u(Fe)},[m,S,A,v,U]),ve=r.useCallback(()=>{N(!1),f(0),document.body.style.cursor="",document.body.style.userSelect="",document.body.style.overflow="",document.body.style.position="",document.body.style.width=""},[]);r.useEffect(()=>()=>{document.body.style.cursor="",document.body.style.userSelect="",document.body.style.overflow="",document.body.style.position="",document.body.style.width=""},[]),r.useEffect(()=>{if(S!==0){const z=ke=>se(ke),ue=()=>ve(),Le=ke=>se(ke),Te=()=>ve();return document.addEventListener("mousemove",z),document.addEventListener("mouseup",ue),document.addEventListener("touchmove",Le,{passive:!1}),document.addEventListener("touchend",Te),()=>{document.removeEventListener("mousemove",z),document.removeEventListener("mouseup",ue),document.removeEventListener("touchmove",Le),document.removeEventListener("touchend",Te)}}},[S,se,ve]);const oe=z=>{if(Z){z.preventDefault(),le(!1);return}const ue=!y;x(ue),s(ue)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:ee,onClick:oe,onMouseDown:z=>{X(z)},onTouchStart:z=>{X(z)},className:`fixed ${y?"right-64":"right-0"} z-50 ${m?"":"transition-all duration-150 ease-out"} bg-white dark:bg-gray-800 border ${m?"border-blue-500 dark:border-blue-400":"border-gray-200 dark:border-gray-700"} rounded-l-md p-2 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors shadow-lg ${m?"cursor-grabbing":"cursor-pointer"} touch-none`,style:{...D(),touchAction:"none",WebkitTouchCallout:"none",WebkitUserSelect:"none"},"aria-label":m?"拖动手柄":y?"关闭设置面板":"打开设置面板",title:m?"拖动中...":"点击切换,拖动移动",children:m?e.jsx(yn,{className:"h-5 w-5 text-blue-500 dark:text-blue-400"}):y?e.jsx(Ht,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"}):e.jsx(vn,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"})}),e.jsx("div",{className:`fixed top-0 right-0 h-full w-64 bg-background border-l border-border shadow-xl transform transition-transform duration-150 ease-out z-40 ${y?"translate-x-0":"translate-x-full"} ${v?"h-screen":""}`,children:e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"p-4 border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900",children:e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(jn,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"}),"快速设置"]})}),e.jsxs("div",{className:`flex-1 overflow-y-auto overflow-x-hidden p-4 space-y-6 bg-background ${v?"pb-mobile-nav":""}`,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400 mb-2",children:"外观"}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-gray-900 dark:text-white",children:[C?e.jsx(Br,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}):e.jsx(Ur,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"深色模式"]}),e.jsx(Wi,{})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400 mb-2",children:"工具显示"}),e.jsxs("label",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-gray-900 dark:text-white",children:[e.jsx(Gs,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"自动展开工具"]}),e.jsx("input",{type:"checkbox",checked:a,onChange:z=>o(z.target.checked),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 focus:ring-2 dark:focus:ring-blue-400 bg-gray-100 dark:bg-gray-800 checked:bg-blue-600 dark:checked:bg-blue-600"})]}),e.jsxs("label",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-gray-900 dark:text-white",children:[e.jsx(Vs,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"显示原始参数"]}),e.jsx("input",{type:"checkbox",checked:n,onChange:z=>l(z.target.checked),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 focus:ring-2 dark:focus:ring-blue-400 bg-gray-100 dark:bg-gray-800 checked:bg-blue-600 dark:checked:bg-blue-600"})]}),e.jsxs("label",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-gray-900 dark:text-white",children:[e.jsx(Js,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"显示思考过程"]}),e.jsx("input",{type:"checkbox",checked:i,onChange:z=>d(z.target.checked),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 focus:ring-2 dark:focus:ring-blue-400 bg-gray-100 dark:bg-gray-800 checked:bg-blue-600 dark:checked:bg-blue-600"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400 mb-2",children:"视图选项"}),e.jsxs("label",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-gray-900 dark:text-white",children:[e.jsx(wn,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"自动滚动到底部"]}),e.jsx("input",{type:"checkbox",checked:h,onChange:z=>g(z.target.checked),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 focus:ring-2 dark:focus:ring-blue-400 bg-gray-100 dark:bg-gray-800 checked:bg-blue-600 dark:checked:bg-blue-600"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400 mb-2",children:"输入设置"}),e.jsxs("label",{className:"flex items-center justify-between p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-gray-900 dark:text-white",children:[e.jsx(kn,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"使用 Ctrl+Enter 发送"]}),e.jsx("input",{type:"checkbox",checked:p,onChange:z=>w(z.target.checked),className:"h-4 w-4 rounded border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 focus:ring-2 dark:focus:ring-blue-400 bg-gray-100 dark:bg-gray-800 checked:bg-blue-600 dark:checked:bg-blue-600"})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ml-3",children:"启用后,按 Ctrl+Enter 发送消息而不是 Enter。这对于输入法用户很有用,可以避免误发送。"})]}),e.jsxs("div",{className:"space-y-2",style:{display:"none"},children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400 mb-2",children:"语音输入"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-start p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsx("input",{type:"radio",name:"whisperMode",value:"default",checked:P==="default",onChange:()=>{R("default"),localStorage.setItem("whisperMode","default"),window.dispatchEvent(new Event("whisperModeChanged"))},className:"mt-0.5 h-4 w-4 border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 dark:focus:ring-blue-400 dark:bg-gray-800 dark:checked:bg-blue-600"}),e.jsxs("div",{className:"ml-3 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm font-medium text-gray-900 dark:text-white",children:[e.jsx(gr,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"默认模式"]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:"直接转录您的语音"})]})]}),e.jsxs("label",{className:"flex items-start p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsx("input",{type:"radio",name:"whisperMode",value:"prompt",checked:P==="prompt",onChange:()=>{R("prompt"),localStorage.setItem("whisperMode","prompt"),window.dispatchEvent(new Event("whisperModeChanged"))},className:"mt-0.5 h-4 w-4 border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 dark:focus:ring-blue-400 dark:bg-gray-800 dark:checked:bg-blue-600"}),e.jsxs("div",{className:"ml-3 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm font-medium text-gray-900 dark:text-white",children:[e.jsx(Wr,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"提示词增强"]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:"将粗略的想法转化为清晰、详细的 AI 提示词"})]})]}),e.jsxs("label",{className:"flex items-start p-3 rounded-lg bg-gray-50 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer transition-colors border border-transparent hover:border-gray-300 dark:hover:border-gray-600",children:[e.jsx("input",{type:"radio",name:"whisperMode",value:"vibe",checked:P==="vibe"||P==="instructions"||P==="architect",onChange:()=>{R("vibe"),localStorage.setItem("whisperMode","vibe"),window.dispatchEvent(new Event("whisperModeChanged"))},className:"mt-0.5 h-4 w-4 border-gray-300 dark:border-gray-600 text-blue-600 dark:text-blue-500 focus:ring-blue-500 dark:focus:ring-blue-400 dark:bg-gray-800 dark:checked:bg-blue-600"}),e.jsxs("div",{className:"ml-3 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm font-medium text-gray-900 dark:text-white",children:[e.jsx(Ys,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"氛围模式"]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:"将想法格式化为带有详细说明的代理指令"})]})]})]})]})]})]})}),y&&e.jsx("div",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm z-30 transition-opacity duration-150 ease-out",onClick:oe})]})};function Ui({isOpen:t,limitType:s,onClose:a}){if(!t)return null;const o=s==="total_limit_exceeded";return e.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[100]",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-xl w-full max-w-md p-6 mx-4 animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center flex-shrink-0",children:e.jsx(qt,{className:"w-6 h-6 text-red-600 dark:text-red-400"})}),e.jsx("div",{children:e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:o?"使用上限已达到":"今日使用上限已达到"})})]}),e.jsx("button",{onClick:a,className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:e.jsx(Je,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"mb-6 text-muted-foreground space-y-3",children:o?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"您的账户已达到使用总额度上限。"}),e.jsx("p",{className:"text-sm",children:"请联系管理员提升您的额度限制,以继续使用 Claude 服务。"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"您已达到今日使用额度上限。"}),e.jsx("p",{className:"text-sm",children:"您可以等待明日额度重置后继续使用,或联系管理员提升您的每日额度限制。"})]})}),e.jsx("div",{className:"mb-6 p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg",children:e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:o?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"提示:"}),"请联系您的管理员,申请提升使用额度。"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"提示:"}),"每日额度将在次日 00:00 自动重置,您也可以联系管理员调整限额。"]})})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(B,{variant:"default",onClick:a,children:"我知道了"})})]})})}function Hi(){const[t,s]=r.useState(null),[a,o]=r.useState([]),[n,l]=r.useState(!1),i=r.useRef(null),d=r.useRef(null),{token:h}=Kt();r.useEffect(()=>(i.current&&(clearTimeout(i.current),i.current=null),d.current&&(d.current.close(),d.current=null),h||!1?g():(l(!1),s(null)),()=>{i.current&&clearTimeout(i.current),d.current&&d.current.close()}),[h]);const g=()=>{try{let v;{const x=h||localStorage.getItem("auth-token");if(!x){console.warn("No authentication token found for WebSocket connection");return}v=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws?token=${encodeURIComponent(x)}`}const y=new WebSocket(v);d.current=y,y.onopen=()=>{l(!0),s(y)},y.onmessage=x=>{try{const P=JSON.parse(x.data);o(R=>[...R,P])}catch(P){console.error("Error parsing WebSocket message:",P)}},y.onclose=()=>{l(!1),s(null),d.current=null,localStorage.getItem("auth-token")&&(i.current=setTimeout(()=>{g()},3e3))},y.onerror=x=>{console.error("WebSocket error:",x)}}catch(w){console.error("Error creating WebSocket connection:",w)}};return{ws:t,sendMessage:w=>{t&&n?t.send(JSON.stringify(w)):console.warn("WebSocket not connected")},messages:a,isConnected:n}}const ga=r.createContext({ws:null,sendMessage:()=>{},messages:[],isConnected:!1}),qi=()=>{const t=r.useContext(ga);if(!t)throw new Error("useWebSocketContext must be used within a WebSocketProvider");return t},Ji=({children:t})=>{const s=Hi();return e.jsx(ga.Provider,{value:s,children:t})},Ki=()=>{const[t,s]=r.useState("email"),[a,o]=r.useState(""),[n,l]=r.useState(""),[i,d]=r.useState(!1),[h,g]=r.useState(""),[p,w]=r.useState(0),{sendCode:v,verifyCode:y,smtpConfigured:x}=Kt();r.useEffect(()=>{if(p>0){const u=setTimeout(()=>w(p-1),1e3);return()=>clearTimeout(u)}},[p]);const P=async u=>{if(u.preventDefault(),g(""),!a||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)){g("请输入有效的邮箱地址");return}d(!0);const N=await v(a);N.success?(s("code"),w(60)):(g(N.error),N.waitSeconds&&w(N.waitSeconds)),d(!1)},R=async u=>{if(u.preventDefault(),g(""),!n||n.length!==6){g("请输入6位验证码");return}d(!0);const m=await y(a,n);m.success||g(m.error),d(!1)},C=async()=>{if(p>0)return;g(""),d(!0);const u=await v(a);u.success?w(60):g(u.error),d(!1)},k=()=>{s("email"),l(""),g("")};return x?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx("div",{className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-lg border border-border p-8 space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(mt,{size:64})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:t==="email"?"欢迎使用 AgentHub":"创建管理员账户"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?"输入邮箱创建管理员账户":`验证码已发送至 ${a}`})]}),t==="email"&&e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-foreground mb-1",children:"邮箱地址"}),e.jsxs("div",{className:"relative",children:[e.jsx(br,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),e.jsx("input",{type:"email",id:"email",value:a,onChange:u=>o(u.target.value),className:"w-full pl-10 pr-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入邮箱地址",required:!0,disabled:i,autoComplete:"email"})]})]}),h&&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:h})}),e.jsx("button",{type:"submit",disabled:i||p>0,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:i?"发送中...":p>0?`${p}秒后可重新发送`:"获取验证码"})]}),t==="code"&&e.jsxs("form",{onSubmit:R,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:k,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(ir,{className:"w-4 h-4 mr-1"}),"返回修改邮箱"]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"code",className:"block text-sm font-medium text-foreground mb-1",children:"验证码"}),e.jsx("input",{type:"text",id:"code",value:n,onChange:u=>l(u.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground text-center text-2xl tracking-widest focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"000000",required:!0,disabled:i,maxLength:6,autoComplete:"one-time-code"})]}),h&&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:h})}),e.jsx("button",{type:"submit",disabled:i||n.length!==6,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:i?"创建中...":"创建管理员账户"}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:C,disabled:p>0||i,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:p>0?`${p}秒后可重新发送`:"重新发送验证码"})})]}),e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"首个注册的用户将成为管理员"})})]})})}):e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx("div",{className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-lg border border-border p-8 space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(mt,{size:64})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"欢迎使用 AgentHub"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"系统初始化"})]}),e.jsxs("div",{className:"p-4 bg-yellow-100 dark:bg-yellow-900/20 border border-yellow-300 dark:border-yellow-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-400",children:"SMTP 邮件服务未配置。请联系管理员配置以下环境变量后重启服务:"}),e.jsxs("ul",{className:"mt-2 text-sm text-yellow-700 dark:text-yellow-400 list-disc list-inside",children:[e.jsx("li",{children:"SMTP_SERVER"}),e.jsx("li",{children:"SMTP_PORT"}),e.jsx("li",{children:"SMTP_USERNAME"}),e.jsx("li",{children:"SMTP_PASSWORD"})]})]})]})})})},Gi=()=>{const[t,s]=r.useState("email"),[a,o]=r.useState("email"),[n,l]=r.useState(""),[i,d]=r.useState(""),[h,g]=r.useState(""),[p,w]=r.useState(""),[v,y]=r.useState(!1),[x,P]=r.useState(""),[R,C]=r.useState(0),[k,u]=r.useState(!1),{login:m,sendCode:N,verifyCode:S,smtpConfigured:f}=Kt();r.useEffect(()=>{if(R>0){const D=setTimeout(()=>C(R-1),1e3);return()=>clearTimeout(D)}},[R]),r.useEffect(()=>{f||s("password")},[f]);const A=async D=>{if(D.preventDefault(),P(""),!n||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)){P("请输入有效的邮箱地址");return}y(!0);const se=await N(n);se.success?(o("code"),C(60),u(se.type==="register")):(P(se.error),se.waitSeconds&&C(se.waitSeconds)),y(!1)},F=async D=>{if(D.preventDefault(),P(""),!i||i.length!==6){P("请输入6位验证码");return}y(!0);const X=await S(n,i);X.success||P(X.error),y(!1)},Z=async()=>{if(R>0)return;P(""),y(!0);const D=await N(n);D.success?C(60):P(D.error),y(!1)},le=async D=>{if(D.preventDefault(),P(""),!h||!p){P("请输入用户名和密码");return}y(!0);const X=await m(h,p);X.success||P(X.error),y(!1)},ee=()=>{o("email"),d(""),P("")},ne=()=>{s("email"),o("email"),P("")},U=()=>{s("password"),P("")};return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx("div",{className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-lg border border-border p-8 space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("img",{src:"/logo.svg",className:"w-16 h-16",alt:"AgentHub"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:t==="email"?a==="email"?"欢迎使用 AgentHub":k?"创建您的账户":"验证您的身份":"欢迎回来"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?a==="email"?"输入邮箱以接收验证码":`验证码已发送至 ${n}`:"使用账号密码登录"})]}),t==="email"&&a==="email"&&e.jsxs("form",{onSubmit:A,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-foreground mb-1",children:"邮箱地址"}),e.jsxs("div",{className:"relative",children:[e.jsx(br,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),e.jsx("input",{type:"email",id:"email",value:n,onChange:D=>l(D.target.value),className:"w-full pl-10 pr-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入邮箱地址",required:!0,disabled:v,autoComplete:"email"})]})]}),x&&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:x})}),e.jsx("button",{type:"submit",disabled:v||R>0,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:v?"发送中...":R>0?`${R}秒后可重新发送`:"获取验证码"})]}),t==="email"&&a==="code"&&e.jsxs("form",{onSubmit:F,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:ee,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(ir,{className:"w-4 h-4 mr-1"}),"返回修改邮箱"]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"code",className:"block text-sm font-medium text-foreground mb-1",children:"验证码"}),e.jsx("input",{type:"text",id:"code",value:i,onChange:D=>d(D.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground text-center text-2xl tracking-widest focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"000000",required:!0,disabled:v,maxLength:6,autoComplete:"one-time-code"})]}),x&&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:x})}),e.jsx("button",{type:"submit",disabled:v||i.length!==6,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:v?"验证中...":k?"创建账户并登录":"登录"}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:Z,disabled:R>0||v,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:R>0?`${R}秒后可重新发送`:"重新发送验证码"})})]}),t==="password"&&e.jsxs("form",{onSubmit:le,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"username",className:"block text-sm font-medium text-foreground mb-1",children:"用户名"}),e.jsxs("div",{className:"relative",children:[e.jsx(Xs,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),e.jsx("input",{type:"text",id:"username",value:h,onChange:D=>g(D.target.value),className:"w-full pl-10 pr-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入用户名",required:!0,disabled:v})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-foreground mb-1",children:"密码"}),e.jsxs("div",{className:"relative",children:[e.jsx(Nn,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-muted-foreground"}),e.jsx("input",{type:"password",id:"password",value:p,onChange:D=>w(D.target.value),className:"w-full pl-10 pr-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入密码",required:!0,disabled:v})]})]}),x&&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:x})}),e.jsx("button",{type:"submit",disabled:v,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:v?"登录中...":"登录"})]}),e.jsx("div",{className:"text-center pt-4 border-t border-border",children:t==="email"&&f?e.jsx("button",{type:"button",onClick:U,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用账号密码登录"}):t==="password"&&f?e.jsx("button",{type:"button",onClick:ne,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用邮箱验证码登录"}):null})]})})})},Vi=()=>e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("div",{className:"w-16 h-16 bg-primary rounded-lg flex items-center justify-center shadow-sm",children:e.jsx(Xr,{className:"w-8 h-8 text-primary-foreground"})})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground mb-2",children:"AgentHub"}),e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),e.jsx("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"加载中..."})]})}),Yi=({children:t})=>{const{user:s,isLoading:a,needsSetup:o}=Kt();return a?e.jsx(Vi,{}):o?e.jsx(Ki,{}):s?t:e.jsx(Gi,{})};function Ut(t,s){const[a,o]=r.useState(()=>{if(typeof window>"u")return s;try{const l=window.localStorage.getItem(t);return l?JSON.parse(l):s}catch(l){return console.log(l),s}});return[a,l=>{if(!(typeof window>"u"))try{const i=l instanceof Function?l(a):l;window.localStorage.setItem(t,JSON.stringify(i)),o(i)}catch(i){console.log(i)}}]}function Us(){const t=Hs(),{sessionId:s}=Za(),{limitStatus:a,setLimitStatus:o,checkLimitStatus:n}=Kt(),[l,i]=r.useState([]),[d,h]=r.useState(null),[g,p]=r.useState(null),[w,v]=r.useState("chat"),[y,x]=r.useState(!1),[P,R]=r.useState(!1),[C,k]=r.useState(!0),[u,m]=r.useState(!1),[N,S]=r.useState(!1),[f,A]=r.useState("agents"),[F,Z]=r.useState(!1),[le,ee]=Ut("autoExpandTools",!1),[ne,U]=Ut("showRawParameters",!1),[D,X]=Ut("showThinking",!0),[se,ve]=Ut("autoScrollToBottom",!0),[oe,z]=Ut("sendByCtrlEnter",!1),[ue,Le]=Ut("sidebarVisible",!0),[Te,ke]=r.useState(!1),[Fe,we]=r.useState(null),[Se,ze]=r.useState(new Set),[Ue,xe]=r.useState(new Set),[Ce,Ie]=r.useState(0),{ws:Pe,sendMessage:De,messages:T}=qi(),_=r.useCallback(Y=>{we(Y),ke(!0)},[]),[W,b]=r.useState(!1);r.useEffect(()=>{const Y=()=>{const re=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone||document.referrer.includes("android-app://");b(re),document.addEventListener("touchstart",{}),re?(document.documentElement.classList.add("pwa-mode"),document.body.classList.add("pwa-mode")):(document.documentElement.classList.remove("pwa-mode"),document.body.classList.remove("pwa-mode"))};return Y(),window.matchMedia("(display-mode: standalone)").addEventListener("change",Y),()=>{window.matchMedia("(display-mode: standalone)").removeEventListener("change",Y)}},[]),r.useEffect(()=>{const Y=()=>{x(window.innerWidth<768)};return Y(),window.addEventListener("resize",Y),()=>window.removeEventListener("resize",Y)},[]),r.useEffect(()=>{pe()},[]);const H=(Y,re,ie,be)=>{if(!ie||!be)return!0;const fe=Y?.find(We=>We.name===ie.name),je=re?.find(We=>We.name===ie.name);if(!fe||!je)return!1;const Ee=fe.sessions?.find(We=>We.id===be.id),He=je.sessions?.find(We=>We.id===be.id);return!Ee||!He?!1:Ee.id===He.id&&Ee.title===He.title&&Ee.created_at===He.created_at&&Ee.updated_at===He.updated_at};r.useEffect(()=>{if(T.length>0){const Y=T[T.length-1];if(Y.type==="projects_updated"){if(Y.changedFile&&g&&d){const fe=Y.changedFile.replace(/\\/g,"/").split("/");fe.length>=2&&fe[fe.length-1].replace(".jsonl","")===g.id&&(Se.has(g.id)||Ie(Xe=>Xe+1))}if(g&&Se.has(g.id)||Se.size>0&&Array.from(Se).some(be=>be.startsWith("new-session-"))){const be=Y.projects;if(!H(l,be,d,g))return}const ie=Y.projects;if(i(ie),d){const be=ie.find(fe=>fe.name===d.name);be&&(JSON.stringify(be)!==JSON.stringify(d)&&h(be),g&&([...be.sessions||[]].find(Ee=>Ee.id===g.id)||p(null)))}}}},[T,d,g,Se]);const pe=async()=>{try{k(!0);const re=await(await ye.projects()).json();i(ie=>ie.length===0||re.some((fe,je)=>{const Ee=ie[je];return Ee?fe.name!==Ee.name||fe.displayName!==Ee.displayName||fe.fullPath!==Ee.fullPath||JSON.stringify(fe.sessionMeta)!==JSON.stringify(Ee.sessionMeta)||JSON.stringify(fe.sessions)!==JSON.stringify(Ee.sessions):!0})||re.length!==ie.length?re:ie)}catch(Y){console.error("Error fetching projects:",Y)}finally{k(!1)}};window.refreshProjects=pe,window.openSettings=r.useCallback((Y="tools")=>{A(Y),S(!0)},[]),r.useEffect(()=>{if(s&&l.length>0){const Y=!g||g.id!==s;for(const re of l){let ie=re.sessions?.find(be=>be.id===s);if(ie){h(re),p({...ie,__provider:"claude"}),Y&&v("chat");return}}}},[s,l,t]);const Ne=Y=>{h(Y),p(null),t("/"),y&&R(!1)},Oe=Y=>{if(p(Y),w!=="git"&&w!=="preview"&&v("chat"),y){const re=Y.__projectName,ie=d?.name;re!==ie&&R(!1)}t(`/session/${Y.id}`)},at=Y=>{h(Y),p(null),v("chat"),t("/"),y&&R(!1)},K=Y=>{g?.id===Y&&(p(null),t("/")),i(re=>re.map(ie=>({...ie,sessions:ie.sessions?.filter(be=>be.id!==Y)||[],sessionMeta:{...ie.sessionMeta,total:Math.max(0,(ie.sessionMeta?.total||0)-1)}})))},ae=async()=>{try{const re=await(await ye.projects()).json();if(i(ie=>re.some((fe,je)=>{const Ee=ie[je];return Ee?fe.name!==Ee.name||fe.displayName!==Ee.displayName||fe.fullPath!==Ee.fullPath||JSON.stringify(fe.sessionMeta)!==JSON.stringify(Ee.sessionMeta)||JSON.stringify(fe.sessions)!==JSON.stringify(Ee.sessions):!0})||re.length!==ie.length?re:ie),d){const ie=re.find(be=>be.name===d.name);if(ie&&(JSON.stringify(ie)!==JSON.stringify(d)&&h(ie),g)){const be=ie.sessions?.find(fe=>fe.id===g.id);be&&JSON.stringify(be)!==JSON.stringify(g)&&p(be)}}}catch(Y){console.error("Error refreshing sidebar:",Y)}},j=Y=>{d?.name===Y&&(h(null),p(null),t("/")),i(re=>re.filter(ie=>ie.name!==Y))},V=r.useCallback(Y=>{Y&&ze(re=>new Set([...re,Y]))},[]),de=r.useCallback(Y=>{Y&&ze(re=>{const ie=new Set(re);return ie.delete(Y),ie})},[]),ce=r.useCallback(Y=>{Y&&xe(re=>new Set([...re,Y]))},[]),$=r.useCallback(Y=>{Y&&xe(re=>{const ie=new Set(re);return ie.delete(Y),ie})},[]),$e=r.useCallback(Y=>{Y&&ze(re=>{const ie=new Set;for(const be of re)be.startsWith("new-session-")||ie.add(be);return ie.add(Y),ie})},[]);return e.jsxs("div",{className:"fixed inset-0 flex bg-background",children:[!y&&e.jsx("div",{className:`h-full flex-shrink-0 border-r border-border bg-card transition-all duration-300 ${ue?"w-80":"w-14"}`,children:e.jsx("div",{className:"h-full overflow-hidden",children:ue?e.jsx(Ss,{projects:l,selectedProject:d,selectedSession:g,onProjectSelect:Ne,onSessionSelect:Oe,onNewSession:at,onSessionDelete:K,onProjectDelete:j,isLoading:C,onRefresh:ae,onShowSettings:()=>S(!0),isPWA:W,isMobile:y,onToggleSidebar:()=>Le(!1)}):e.jsxs("div",{className:"h-full flex flex-col items-center py-4 gap-4",children:[e.jsx("button",{onClick:()=>Le(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200 group","aria-label":"Show sidebar",title:"Show sidebar",children:e.jsx("svg",{className:"w-5 h-5 text-foreground group-hover:scale-110 transition-transform",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 5l7 7-7 7M5 5l7 7-7 7"})})}),e.jsx("button",{onClick:()=>S(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Settings",title:"Settings",children:e.jsx(wt,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})})]})})}),y&&e.jsxs("div",{className:`fixed inset-0 z-50 flex transition-all duration-150 ease-out ${P?"opacity-100 visible":"opacity-0 invisible"}`,children:[e.jsx("button",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm transition-opacity duration-150 ease-out",onClick:Y=>{Y.stopPropagation(),R(!1)},onTouchStart:Y=>{Y.preventDefault(),Y.stopPropagation(),R(!1)},"aria-label":"Close sidebar"}),e.jsx("div",{className:`relative w-[85vw] max-w-sm sm:w-80 h-full bg-card border-r border-border transform transition-transform duration-150 ease-out ${P?"translate-x-0":"-translate-x-full"}`,onClick:Y=>Y.stopPropagation(),onTouchStart:Y=>Y.stopPropagation(),children:e.jsx(Ss,{projects:l,selectedProject:d,selectedSession:g,onProjectSelect:Ne,onSessionSelect:Oe,onNewSession:at,onSessionDelete:K,onProjectDelete:j,isLoading:C,onRefresh:ae,onShowSettings:()=>S(!0),isPWA:W,isMobile:y,onToggleSidebar:()=>Le(!1)})})]}),e.jsx("div",{className:`flex-1 flex flex-col min-w-0 ${y&&!u?"pb-mobile-nav":""}`,children:e.jsx(pi,{selectedProject:d,selectedSession:g,activeTab:w,setActiveTab:v,ws:Pe,sendMessage:De,messages:T,isMobile:y,isPWA:W,onMenuClick:()=>R(!0),isLoading:C,onInputFocusChange:m,onSessionActive:V,onSessionInactive:de,onSessionProcessing:ce,onSessionNotProcessing:$,processingSessions:Ue,onReplaceTemporarySession:$e,onNavigateToSession:Y=>t(`/session/${Y}`),onShowSettings:()=>S(!0),autoExpandTools:le,showRawParameters:ne,showThinking:D,autoScrollToBottom:se,sendByCtrlEnter:oe,externalMessageUpdate:Ce,limitStatus:a,onLimitBlocked:_,checkLimitStatus:n})}),y&&e.jsx(xi,{activeTab:w,setActiveTab:v,isInputFocused:u}),w==="chat"&&e.jsx(Bi,{isOpen:F,onToggle:Z,autoExpandTools:le,onAutoExpandChange:ee,showRawParameters:ne,onShowRawParametersChange:U,showThinking:D,onShowThinkingChange:X,autoScrollToBottom:se,onAutoScrollChange:ve,sendByCtrlEnter:oe,onSendByCtrlEnterChange:z,isMobile:y}),e.jsx(Fi,{isOpen:N,onClose:()=>S(!1),projects:l,initialTab:f}),e.jsx(Ui,{isOpen:Te,limitType:Fe,onClose:()=>ke(!1)})]})}function Qi(){return e.jsx(hi,{children:e.jsx(gi,{children:e.jsx(Ji,{children:e.jsx(Yi,{children:e.jsx(Ya,{children:e.jsxs(Qa,{children:[e.jsx(ys,{path:"/",element:e.jsx(Us,{})}),e.jsx(ys,{path:"/session/:sessionId",element:e.jsx(Us,{})})]})})})})})})}"serviceWorker"in navigator&&navigator.serviceWorker.getRegistrations().then(t=>{t.forEach(s=>{s.unregister()})}).catch(t=>{console.warn("Failed to unregister service workers:",t)});zn.createRoot(document.getElementById("root")).render(e.jsx(rt.StrictMode,{children:e.jsx(Qi,{})}));