@ian2018cs/agenthub 0.1.48 → 0.1.50

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.
@@ -1,8 +1,8 @@
1
- import{j as e,s as tn,R as rn,o as sn,E as an,m as nn,b as on,c as ln,h as cn,p as dn,d as mn}from"./vendor-codemirror-C_VWDoZS.js";import{b as un,g as cs,a as r,d as pn,R as it,u as sa,B as xn,e as hn,f as Ds,h as gn}from"./vendor-react-BeVl62c0.js";import{t as fn,c as bn,a as aa,F as vn}from"./vendor-utils-00TdZexr.js";import{T as Lt,C as na,I as ds,F as Kr,X as He,L as Mt,R as zt,S as At,a as mt,b as Pt,c as jr,d as Ts,e as et,P as ir,f as _r,g as Vt,h as Gr,i as yn,j as lt,k as It,l as jt,m as jn,n as wn,M as wr,B as oa,D as $t,o as ia,p as kn,q as la,U as Rs,r as Nn,E as ca,s as Sn,t as Cn,u as da,v as Ps,w as Mr,x as cr,y as dr,G as ms,z as kr,Z as ma,A as ua,H as Qt,J as pa,K as Vr,N as Yr,O as Qr,Q as Zr,V as En,W as Mn,Y as Ln,_ as In,$ as us,a0 as Dn,a1 as Tn,a2 as Rn,a3 as Pn,a4 as Xr,a5 as $n,a6 as Nr,a7 as xa,a8 as ha,a9 as zn,aa as An,ab as On,ac as _n,ad as Fn,ae as Wn,af as Bn}from"./vendor-icons-KP5LHo3O.js";import{r as Un,a as Hn,b as qn,M as Jn}from"./vendor-markdown-VwNYkg_0.js";import{h as Kn}from"./vendor-syntax-CdGaPJRS.js";import{r as Gn,a as Vn,b as Yn,c as Qn}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 gr={},$s;function Zn(){if($s)return gr;$s=1;var t=un();return gr.createRoot=t.createRoot,gr.hydrateRoot=t.hydrateRoot,gr}var Xn=Zn();const eo=cs(Xn);function Ve(...t){return fn(bn(t))}function to(t){if(!t||typeof t!="string")return null;try{return JSON.parse(t)}catch{return null}}const ps=r.forwardRef(({className:t,children:s,...a},o)=>e.jsx("div",{ref:o,className:Ve("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})}));ps.displayName="ScrollArea";const ro=aa("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"}}),W=r.forwardRef(({className:t,variant:s,size:a,...o},n)=>e.jsx("button",{className:Ve(ro({variant:s,size:a,className:t})),ref:n,...o}));W.displayName="Button";const so=aa("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 Qe({className:t,variant:s,...a}){return e.jsx("div",{className:Ve(so({variant:s}),t),...a})}const Xe=r.forwardRef(({className:t,type:s,...a},o)=>e.jsx("input",{type:s,className:Ve("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}));Xe.displayName="Input";const ht=({className:t="w-5 h-5"})=>e.jsx("img",{src:"/icons/claude-ai-icon.svg",alt:"Claude",className:t}),ga=r.createContext(null);function ct(){const t=r.useContext(ga);if(!t)throw new Error("useDialog must be used within DialogProvider");return t}function ao({children:t}){const[s,a]=r.useState(null),o=r.useRef(null),n=r.useCallback(d=>{o.current?.(d),o.current=null,a(null)},[]),l=r.useCallback((d,x={})=>new Promise(h=>{o.current=h,a({type:"alert",message:d,title:x.title||"提示",variant:x.variant||"info"})}),[]),i=r.useCallback((d,x={})=>new Promise(h=>{o.current=h,a({type:"confirm",message:d,title:x.title||"确认操作",subtitle:x.subtitle,detail:x.detail,confirmText:x.confirmText||"确认",cancelText:x.cancelText||"取消",variant:x.variant||"warning"})}),[]);return e.jsxs(ga.Provider,{value:{showAlert:l,showConfirm:i},children:[t,s&&pn.createPortal(e.jsx(no,{dialog:s,onClose:n}),document.body)]})}function no({dialog:t,onClose:s}){const a=r.useRef(null),o=r.useRef(null);r.useEffect(()=>{t.type==="confirm"?a.current?.focus():o.current?.focus()},[t.type]),r.useEffect(()=>{const h=m=>{m.key==="Escape"&&s(t.type==="confirm"?!1:void 0)};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t.type,s]);const n={info:e.jsx(ds,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"}),warning:e.jsx(Lt,{className:"w-5 h-5 text-amber-600 dark:text-amber-400"}),error:e.jsx(na,{className:"w-5 h-5 text-red-600 dark:text-red-400"}),danger:e.jsx(Lt,{className:"w-5 h-5 text-red-600 dark:text-red-400"})},l={info:"bg-blue-100 dark:bg-blue-900/30",warning:"bg-amber-100 dark:bg-amber-900/30",error:"bg-red-100 dark:bg-red-900/30",danger:"bg-red-100 dark:bg-red-900/30"},i={warning:"bg-amber-600 hover:bg-amber-700 text-white",danger:"bg-red-600 hover:bg-red-700 text-white",info:"bg-primary hover:bg-primary/90 text-primary-foreground"},d=n[t.variant]||n.info,x=l[t.variant]||l.info;return t.type==="alert"?e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>s(),children:e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl w-full max-w-sm p-6 space-y-4",onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-full ${x} flex items-center justify-center flex-shrink-0`,children:d}),e.jsx("h3",{className:"font-semibold text-foreground",children:t.title})]}),e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:t.message}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx("button",{ref:o,className:"px-4 py-2 rounded-lg bg-primary hover:bg-primary/90 text-primary-foreground text-sm font-medium transition-colors",onClick:()=>s(),children:"确定"})})]})}):e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>s(!1),children:e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl w-full max-w-sm p-6 space-y-4",onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-full ${x} flex items-center justify-center flex-shrink-0`,children:d}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-foreground",children:t.title}),t.subtitle&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.subtitle})]})]}),e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:t.message}),t.detail&&e.jsx("p",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3",children:t.detail}),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:()=>s(!1),children:t.cancelText}),e.jsx("button",{ref:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${i[t.variant]||i.info}`,onClick:()=>s(!0),children:t.confirmText})]})]})})}const X=(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}})},ke={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:()=>X("/api/auth/user"),logout:()=>X("/api/auth/logout",{method:"POST"}),limitStatus:()=>X("/api/auth/limit-status"),changePassword:(t,s)=>X("/api/auth/change-password",{method:"PATCH",body:JSON.stringify({current_password:t,new_password:s})}),feishuBindToken:()=>X("/api/auth/feishu-bind-token",{method:"POST"})},admin:{getUsers:()=>X("/api/admin/users"),createUser:(t,s)=>X("/api/admin/users",{method:"POST",body:JSON.stringify({username:t,password:s})}),updateUserStatus:(t,s)=>X(`/api/admin/users/${t}`,{method:"PATCH",body:JSON.stringify({status:s})}),deleteUser:t=>X(`/api/admin/users/${t}`,{method:"DELETE"}),getEmailDomains:()=>X("/api/admin/email-domains"),addEmailDomain:t=>X("/api/admin/email-domains",{method:"POST",body:JSON.stringify({domain:t})}),removeEmailDomain:t=>X(`/api/admin/email-domains/${t}`,{method:"DELETE"}),getUserLimits:t=>X(`/api/admin/users/${t}/limits`),updateUserLimits:(t,s)=>X(`/api/admin/users/${t}/limits`,{method:"PATCH",body:JSON.stringify(s)}),resetUserPassword:(t,s)=>X(`/api/admin/users/${t}/password`,{method:"PATCH",body:JSON.stringify({new_password:s})}),updateUserRole:(t,s)=>X(`/api/admin/users/${t}/role`,{method:"PATCH",body:JSON.stringify({role:s})}),getDefaultLimits:()=>X("/api/admin/settings/default-limits"),updateDefaultLimits:t=>X("/api/admin/settings/default-limits",{method:"PUT",body:JSON.stringify(t)})},projects:()=>X("/api/projects"),sessions:(t,s=5,a=0)=>X(`/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 X(i)},renameProject:(t,s)=>X(`/api/projects/${t}/rename`,{method:"PUT",body:JSON.stringify({displayName:s})}),deleteSession:(t,s)=>X(`/api/projects/${t}/sessions/${s}`,{method:"DELETE"}),deleteProject:(t,s=!0)=>X(`/api/projects/${t}?deleteFolder=${s}`,{method:"DELETE"}),createProject:t=>X("/api/projects/create",{method:"POST",body:JSON.stringify({path:t})}),createWorkspace:t=>X("/api/projects/create-workspace",{method:"POST",body:JSON.stringify(t)}),readFile:(t,s)=>X(`/api/projects/${t}/file?filePath=${encodeURIComponent(s)}`),saveFile:(t,s,a)=>X(`/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 X(`/api/projects/${t}/files${o?"?"+o:""}`)},uploadFiles:(t,s)=>X(`/api/projects/${t}/upload-files`,{method:"POST",body:s,headers:{}}),deleteFile:(t,s)=>X(`/api/projects/${t}/files?filePath=${encodeURIComponent(s)}`,{method:"DELETE"}),getFileContent:(t,s)=>X(`/api/projects/${t}/files/content?path=${encodeURIComponent(s)}`),transcribe:t=>X("/api/transcribe",{method:"POST",body:t,headers:{}}),settings:{getAgentPermissions:()=>X("/api/settings/agent-permissions"),saveAgentPermissions:t=>X("/api/settings/agent-permissions",{method:"PUT",body:JSON.stringify({agentPermissions:t})})},get:t=>X(`/api${t}`)},fa=r.createContext({user:null,token:null,login:()=>{},sendCode:()=>{},verifyCode:()=>{},logout:()=>{},isLoading:!0,needsSetup:!1,smtpConfigured:!1,error:null,isAdmin:!1,isSuperAdmin:!1,limitStatus:{allowed:!0},checkLimitStatus:()=>{},setLimitStatus:()=>{}}),wt=()=>{const t=r.useContext(fa);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t};async function Fr(){try{const t=await ke.settings.getAgentPermissions();if(t.ok){const s=await t.json();s.agentPermissions&&localStorage.setItem("claude-settings",JSON.stringify(s.agentPermissions))}}catch{}}const oo=({children:t})=>{const[s,a]=r.useState(null),[o,n]=r.useState(localStorage.getItem("auth-token")),[l,i]=r.useState(!0),[d,x]=r.useState(!1),[h,m]=r.useState(!1),[v,b]=r.useState(null),[j,f]=r.useState({allowed:!0});r.useEffect(()=>{E()},[]);const E=async()=>{try{i(!0),b(null);const L=await(await ke.auth.status()).json();if(m(L.smtpConfigured||!1),L.needsSetup){x(!0),i(!1);return}if(o)try{const $=await ke.auth.user();if($.ok){const P=await $.json();a(P.user),x(!1),await Fr()}else localStorage.removeItem("auth-token"),n(null),a(null)}catch($){console.error("Token verification failed:",$),localStorage.removeItem("auth-token"),n(null),a(null)}}catch(y){console.error("[AuthContext] Auth status check failed:",y),b("Failed to check authentication status")}finally{i(!1)}},O=async y=>{try{b(null);const L=await ke.auth.sendCode(y),$=await L.json();return L.ok?{success:!0,type:$.type}:{success:!1,error:$.error||"发送验证码失败",waitSeconds:$.waitSeconds}}catch(L){return console.error("Send code error:",L),{success:!1,error:"网络错误,请稍后再试"}}},T=async(y,L)=>{try{b(null);const $=await ke.auth.verifyCode(y,L),P=await $.json();return $.ok?(n(P.token),a(P.user),x(!1),localStorage.setItem("auth-token",P.token),await Fr(),{success:!0}):(b(P.error||"验证失败"),{success:!1,error:P.error||"验证失败"})}catch($){return console.error("Verify code error:",$),{success:!1,error:"网络错误,请稍后再试"}}},R=async(y,L)=>{try{b(null);const $=await ke.auth.login(y,L),P=await $.json();return $.ok?(n(P.token),a(P.user),localStorage.setItem("auth-token",P.token),await Fr(),{success:!0}):(b(P.error||"登录失败"),{success:!1,error:P.error||"登录失败"})}catch($){console.error("Login error:",$);const P="网络错误,请稍后再试";return b(P),{success:!1,error:P}}},g=()=>{n(null),a(null),f({allowed:!0}),localStorage.removeItem("auth-token"),o&&ke.auth.logout().catch(y=>{console.error("Logout endpoint error:",y)})},p=async()=>{if(!s)return{allowed:!0};try{const y=await ke.auth.limitStatus();if(y.ok){const L=await y.json();return f(L),L}}catch(y){console.error("Error checking limit status:",y)}return{allowed:!0}};r.useEffect(()=>{s&&!l&&p()},[s,l]);const u={user:s,token:o,login:R,sendCode:O,verifyCode:T,logout:g,isLoading:l,needsSetup:d,smtpConfigured:h,error:v,isAdmin:s?.role==="admin"||s?.role==="super_admin",isSuperAdmin:s?.role==="super_admin",limitStatus:j,checkLimitStatus:p,setLimitStatus:f};return e.jsx(fa.Provider,{value:u,children:t})},io=/^[a-zA-Z0-9_-]+$/,lo=({onClose:t,onProjectCreated:s})=>{const[a,o]=r.useState(""),[n,l]=r.useState(""),[i,d]=r.useState(!1),[x,h]=r.useState(null),m=j=>j.trim()?io.test(j.trim())?null:"项目名称只能包含字母、数字、连字符和下划线":"项目名称为必填项",v=async()=>{h(null);const j=m(a);if(j){h(j);return}d(!0);try{const f={name:a.trim()};n.trim()&&(f.githubUrl=n.trim());const E=await ke.createWorkspace(f),O=await E.json();if(!E.ok)throw new Error(O.error||"Failed to create project");s&&s(O.project),t()}catch(f){console.error("Error creating project:",f),h(f.message||"Failed to create project")}finally{d(!1)}},b=j=>{j.key==="Enter"&&!i&&v()};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(Kr,{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(He,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[x&&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(na,{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:x})})]}),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(Xe,{type:"text",value:a,onChange:j=>o(j.target.value),onKeyDown:b,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(Xe,{type:"text",value:n,onChange:j=>l(j.target.value),onKeyDown:b,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(W,{variant:"outline",onClick:t,disabled:i,children:"取消"}),e.jsx(W,{onClick:v,disabled:i||!a.trim(),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Mt,{className:"w-4 h-4 mr-2 animate-spin"}),"创建中..."]}):"创建项目"})]})]})})},zs=(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)),x=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`:x===1?"1 day ago":x<7?`${x} days ago`:a.toLocaleDateString()};function As({projects:t,selectedProject:s,selectedSession:a,onProjectSelect:o,onSessionSelect:n,onNewSession:l,onSessionDelete:i,onProjectDelete:d,isLoading:x,onRefresh:h,onShowSettings:m,onShowAdmin:v,isPWA:b,isMobile:j,onToggleSidebar:f}){const{showAlert:E,showConfirm:O}=ct(),{user:T,isAdmin:R}=wt(),[g,p]=r.useState(new Set),[u,y]=r.useState(null),[L,$]=r.useState(!1),[P,z]=r.useState(""),[me,se]=r.useState({}),[te,de]=r.useState({}),[_,A]=r.useState(new Set),[ae,fe]=r.useState(new Date),[ue,Z]=r.useState("name"),[G,pe]=r.useState(!1),[Pe,Me]=r.useState(null),[Le,Ne]=r.useState(""),[qe,Ke]=r.useState({}),[We,Ie]=r.useState(""),[je,$e]=r.useState(()=>{try{const S=localStorage.getItem("starredProjects");return S?new Set(JSON.parse(S)):new Set}catch(S){return console.error("Error loading starred projects:",S),new Set}}),Fe=S=>ee=>{ee.target.closest(".overflow-y-auto")||ee.target.closest("[data-scroll-container]")||(ee.preventDefault(),ee.stopPropagation(),S())};r.useEffect(()=>{const S=setInterval(()=>{fe(new Date)},6e4);return()=>clearInterval(S)},[]),r.useEffect(()=>{de({}),A(new Set)},[t]),r.useEffect(()=>{a&&s&&p(S=>new Set([...S,s.name]))},[a,s]),r.useEffect(()=>{if(t.length>0&&!x){const S=new Set;t.forEach(ee=>{ee.sessions&&ee.sessions.length>=0&&S.add(ee.name)}),A(S)}},[t,x]),r.useEffect(()=>{const S=()=>{try{const Y=localStorage.getItem("claude-settings");if(Y){const H=JSON.parse(Y);Z(H.projectSortOrder||"name")}}catch(Y){console.error("Error loading sort order:",Y)}};S();const ee=Y=>{Y.key==="claude-settings"&&S()};window.addEventListener("storage",ee);const we=setInterval(()=>{document.hasFocus()&&S()},1e3);return()=>{window.removeEventListener("storage",ee),clearInterval(we)}},[]);const _e=S=>{const ee=new Set;g.has(S)||ee.add(S),p(ee)},ze=(S,ee)=>{n({...S,__projectName:ee})},J=S=>{const ee=new Set(je);ee.has(S)?ee.delete(S):ee.add(S),$e(ee);try{localStorage.setItem("starredProjects",JSON.stringify([...ee]))}catch(we){console.error("Error saving starred projects:",we)}},q=S=>je.has(S),w=S=>[...S.sessions||[],...te[S.name]||[]].map(we=>({...we,__provider:"claude"})).sort((we,Y)=>new Date(Y.lastActivity)-new Date(we.lastActivity)),K=S=>{const ee=w(S);return ee.length===0?new Date(0):ee.reduce((Y,H)=>{const M=new Date(H.lastActivity);return M>Y?M:Y},new Date(0))},he=[...t].sort((S,ee)=>{const we=q(S.name),Y=q(ee.name);if(we&&!Y)return-1;if(!we&&Y)return 1;if(ue==="date")return K(ee)-K(S);{const H=S.displayName||S.name,M=ee.displayName||ee.name;return H.localeCompare(M)}}),ve=S=>{y(S.name),z(S.displayName)},Ae=()=>{y(null),z("")},Ue=async S=>{try{(await ke.renameProject(S,P)).ok?window.refreshProjects?window.refreshProjects():window.location.reload():console.error("Failed to rename project")}catch(ee){console.error("Error renaming project:",ee)}y(null),z("")},V=async(S,ee,we="claude")=>{if(await O("确定要删除此会话吗?此操作不可撤销。",{title:"删除会话",variant:"danger",confirmText:"确认删除"}))try{console.log("[Sidebar] Deleting session:",{projectName:S,sessionId:ee,provider:we});const H=await ke.deleteSession(S,ee);if(console.log("[Sidebar] Delete response:",{ok:H.ok,status:H.status}),H.ok)console.log("[Sidebar] Session deleted successfully, calling callback"),i?i(ee):console.warn("[Sidebar] No onSessionDelete callback provided");else{const M=await H.text();console.error("[Sidebar] Failed to delete session:",{status:H.status,error:M}),E("删除会话失败,请重试。",{variant:"error"})}}catch(H){console.error("[Sidebar] Error deleting session:",H),E("删除会话出错,请重试。",{variant:"error"})}},oe=async(S,ee)=>{if(await O(`确定要删除项目 "${ee||S}" 吗?`,{title:"删除项目",subtitle:"此操作不可撤销",detail:"将同时删除:所有会话记录(JSONL 文件)和项目文件夹及其所有内容。",variant:"danger",confirmText:"确认删除"}))try{const Y=await ke.deleteProject(S,!0);if(Y.ok)d&&d(S);else{const H=await Y.json();console.error("Failed to delete project"),E(H.error||"删除项目失败,请重试。",{variant:"error"})}}catch(Y){console.error("Error deleting project:",Y),E("删除项目出错,请重试。",{variant:"error"})}},Te=async S=>{if(!(!(S.sessionMeta?.hasMore!==!1)||me[S.name])){se(we=>({...we,[S.name]:!0}));try{const we=(S.sessions?.length||0)+(te[S.name]?.length||0),Y=await ke.sessions(S.name,5,we);if(Y.ok){const H=await Y.json();de(M=>({...M,[S.name]:[...M[S.name]||[],...H.sessions]})),H.hasMore===!1&&(S.sessionMeta={...S.sessionMeta,hasMore:!1})}}catch(we){console.error("Error loading more sessions:",we)}finally{se(we=>({...we,[S.name]:!1}))}}},Re=he.filter(S=>{if(!We.trim())return!0;const ee=We.toLowerCase(),we=(S.displayName||S.name).toLowerCase(),Y=S.name.toLowerCase();return we.includes(ee)||Y.includes(ee)}),Ce=S=>{o(S)};return e.jsxs(e.Fragment,{children:[L&&ReactDOM.createPortal(e.jsx(lo,{onClose:()=>$(!1),onProjectCreated:S=>{window.refreshProjects?window.refreshProjects():window.location.reload()}}),document.body),e.jsxs("div",{className:"h-full flex flex-col bg-card md:select-none",style:b&&j?{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 助手"})]})]}),f&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200",onClick:f,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:b&&j?{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()=>{pe(!0);try{await h()}finally{pe(!1)}},disabled:G,children:e.jsx(zt,{className:`w-4 h-4 text-foreground ${G?"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:()=>$(!0),children:e.jsx(Kr,{className:"w-4 h-4"})})]})]})})]}),!x&&!j&&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(W,{variant:"default",size:"sm",className:"flex-1 h-8 text-xs bg-primary hover:bg-primary/90 transition-all duration-200",onClick:()=>$(!0),title:"创建新项目",children:[e.jsx(Kr,{className:"w-3.5 h-3.5 mr-1.5"}),"新建项目"]}),e.jsx(W,{variant:"outline",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200 group",onClick:async()=>{pe(!0);try{await h()}finally{pe(!1)}},disabled:G,title:"刷新项目和会话 (Ctrl+R)",children:e.jsx(zt,{className:`w-3.5 h-3.5 ${G?"animate-spin":""} group-hover:rotate-180 transition-transform duration-300`})})]})}),t.length>0&&!x&&e.jsx("div",{className:"px-3 md:px-4 py-2 border-b border-border",children:e.jsxs("div",{className:"relative",children:[e.jsx(At,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索项目...",value:We,onChange:S=>Ie(S.target.value),className:"pl-9 h-9 text-sm bg-muted/50 border-0 focus:bg-background focus:ring-1 focus:ring-primary/20"}),We&&e.jsx("button",{onClick:()=>Ie(""),className:"absolute right-2 top-1/2 transform -translate-y-1/2 p-1 hover:bg-accent rounded",children:e.jsx(He,{className:"w-3 h-3 text-muted-foreground"})})]})}),e.jsx(ps,{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:x?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(mt,{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 以开始使用"})]}):Re.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(At,{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:"尝试调整搜索条件"})]}):Re.map(S=>{const ee=g.has(S.name),we=s?.name===S.name,Y=q(S.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:Ve("p-3 mx-3 my-1 rounded-lg bg-card border border-border/50 active:scale-[0.98] transition-all duration-150",we&&"bg-primary/5 border-primary/20",Y&&!we&&"bg-yellow-50/50 dark:bg-yellow-900/5 border-yellow-200/30 dark:border-yellow-800/30"),onClick:()=>{_e(S.name)},onTouchEnd:Fe(()=>_e(S.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:Ve("w-8 h-8 rounded-lg flex items-center justify-center transition-colors",ee?"bg-primary/10":"bg-muted"),children:ee?e.jsx(Pt,{className:"w-4 h-4 text-primary"}):e.jsx(mt,{className:"w-4 h-4 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0 flex-1",children:u===S.name?e.jsx("input",{type:"text",value:P,onChange:H=>z(H.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:H=>H.stopPropagation(),onKeyDown:H=>{H.key==="Enter"&&Ue(S.name),H.key==="Escape"&&Ae()},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:S.displayName})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(()=>{const H=w(S).length;return`${S.sessionMeta?.hasMore!==!1&&H>=5?`${H}+`:H} 会话`})()})]})})]}),e.jsx("div",{className:"flex items-center gap-1",children:u===S.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:H=>{H.stopPropagation(),Ue(S.name)},children:e.jsx(jr,{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:H=>{H.stopPropagation(),Ae()},children:e.jsx(He,{className:"w-4 h-4 text-white"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:Ve("w-8 h-8 rounded-lg flex items-center justify-center active:scale-90 transition-all duration-150 border",Y?"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:H=>{H.stopPropagation(),J(S.name)},onTouchEnd:Fe(()=>J(S.name)),title:Y?"从收藏中移除":"添加到收藏",children:e.jsx(Ts,{className:Ve("w-4 h-4 transition-colors",Y?"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:H=>{H.stopPropagation(),oe(S.name,S.displayName)},onTouchEnd:Fe(()=>oe(S.name,S.displayName)),children:e.jsx(et,{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:H=>{H.stopPropagation(),ve(S)},onTouchEnd:Fe(()=>ve(S)),children:e.jsx(ir,{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:ee?e.jsx(_r,{className:"w-3 h-3 text-muted-foreground"}):e.jsx(Vt,{className:"w-3 h-3 text-muted-foreground"})})]})})]})})}),e.jsxs(W,{variant:"ghost",className:Ve("hidden md:flex w-full justify-between p-2 h-auto font-normal hover:bg-accent/50",we&&"bg-accent text-accent-foreground",Y&&!we&&"bg-yellow-50/50 dark:bg-yellow-900/10 hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20"),onClick:()=>{s?.name!==S.name&&Ce(S),_e(S.name)},onTouchEnd:Fe(()=>{s?.name!==S.name&&Ce(S),_e(S.name)}),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[ee?e.jsx(Pt,{className:"w-4 h-4 text-primary flex-shrink-0"}):e.jsx(mt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"min-w-0 flex-1 text-left",children:u===S.name?e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{type:"text",value:P,onChange:H=>z(H.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:H=>{H.key==="Enter"&&Ue(S.name),H.key==="Escape"&&Ae()}}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",title:S.fullPath,children:S.fullPath})]}):e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold truncate text-foreground",title:S.displayName,children:S.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[(()=>{const H=w(S).length;return S.sessionMeta?.hasMore!==!1&&H>=5?`${H}+`:H})(),S.fullPath!==S.displayName&&e.jsxs("span",{className:"ml-1 opacity-60",title:S.fullPath,children:["• ",S.fullPath.length>25?"..."+S.fullPath.slice(-22):S.fullPath]})]})]})})]}),e.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:u===S.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:H=>{H.stopPropagation(),Ue(S.name)},children:e.jsx(jr,{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:H=>{H.stopPropagation(),Ae()},children:e.jsx(He,{className:"w-3 h-3"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:Ve("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",Y?"hover:bg-yellow-50 dark:hover:bg-yellow-900/20 opacity-100":"hover:bg-accent"),onClick:H=>{H.stopPropagation(),J(S.name)},title:Y?"从收藏中移除":"添加到收藏",children:e.jsx(Ts,{className:Ve("w-3 h-3 transition-colors",Y?"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:H=>{H.stopPropagation(),ve(S)},title:"重命名项目 (F2)",children:e.jsx(ir,{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:H=>{H.stopPropagation(),oe(S.name,S.displayName)},title:"删除项目",children:e.jsx(et,{className:"w-3 h-3 text-red-600 dark:text-red-400"})}),ee?e.jsx(_r,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"}):e.jsx(Vt,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"})]})})]})]}),ee&&e.jsxs("div",{className:"ml-3 space-y-1 border-l border-border pl-3",children:[_.has(S.name)?w(S).length===0&&!me[S.name]?e.jsx("div",{className:"py-2 px-3 text-left",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"还没有会话"})}):w(S).map(H=>{const M=new Date(H.lastActivity),B=Math.floor((ae-M)/(1e3*60))<10,re=H.summary||"新会话",ie=H.lastActivity,ye=H.messageCount||0;return e.jsxs("div",{className:"group relative",children:[B&&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:Ve("p-2 mx-3 my-0.5 rounded-md bg-card border active:scale-[0.98] transition-all duration-150 relative",a?.id===H.id?"bg-primary/5 border-primary/20":B?"border-green-500/30 bg-green-50/5 dark:bg-green-900/5":"border-border/30"),onClick:()=>{Ce(S),ze(H,S.name)},onTouchEnd:Fe(()=>{Ce(S),ze(H,S.name)}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:Ve("w-5 h-5 rounded-md flex items-center justify-center flex-shrink-0",a?.id===H.id?"bg-primary/10":"bg-muted/50"),children:e.jsx(ht,{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:re}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Gr,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:zs(ie,ae)}),ye>0&&e.jsx(Qe,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:ye}),e.jsx("span",{className:"ml-1 opacity-70",children:e.jsx(ht,{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:xe=>{xe.stopPropagation(),V(S.name,H.id)},onTouchEnd:Fe(()=>V(S.name,H.id)),children:e.jsx(et,{className:"w-2.5 h-2.5 text-red-600 dark:text-red-400"})})]})})}),e.jsxs("div",{className:"hidden md:block",children:[e.jsx(W,{variant:"ghost",className:Ve("w-full justify-start p-2 h-auto font-normal text-left hover:bg-accent/50 transition-colors duration-200",a?.id===H.id&&"bg-accent text-accent-foreground"),onClick:()=>ze(H,S.name),onTouchEnd:Fe(()=>ze(H,S.name)),children:e.jsxs("div",{className:"flex items-start gap-2 min-w-0 w-full",children:[e.jsx(ht,{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:re}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Gr,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:zs(ie,ae)}),ye>0&&e.jsx(Qe,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:ye}),e.jsx("span",{className:"ml-1 opacity-70",children:e.jsx(ht,{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:Pe===H.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:Le,onChange:xe=>Ne(xe.target.value),onKeyDown:xe=>{xe.stopPropagation(),xe.key==="Enter"?updateSessionSummary(S.name,H.id,Le):xe.key==="Escape"&&(Me(null),Ne(""))},onClick:xe=>xe.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:xe=>{xe.stopPropagation(),updateSessionSummary(S.name,H.id,Le)},title:"Save",children:e.jsx(jr,{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:xe=>{xe.stopPropagation(),Me(null),Ne("")},title:"Cancel",children:e.jsx(He,{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:xe=>{xe.stopPropagation(),Me(H.id),Ne(H.summary||"新会话")},title:"手动编辑会话名称",children:e.jsx(yn,{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:xe=>{xe.stopPropagation(),V(S.name,H.id)},title:"永久删除此会话",children:e.jsx(et,{className:"w-3 h-3 text-red-600 dark:text-red-400"})})]})})]})]},H.id)}):Array.from({length:3}).map((H,M)=>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+M*15}%`}}),e.jsx("div",{className:"h-2 bg-muted rounded animate-pulse w-1/2"})]})]})},M)),w(S).length>0&&S.sessionMeta?.hasMore!==!1&&e.jsx(W,{variant:"ghost",size:"sm",className:"w-full justify-center gap-2 mt-2 text-muted-foreground",onClick:()=>Te(S),disabled:me[S.name],children:me[S.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(_r,{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:()=>{Ce(S),l(S)},children:[e.jsx(lt,{className:"w-3 h-3"}),"新会话"]})}),e.jsxs(W,{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(S),children:[e.jsx(lt,{className:"w-3 h-3"}),"新会话"]})]})]},S.name)})})}),e.jsxs("div",{className:"md:p-2 md:border-t md:border-border flex-shrink-0",children:[e.jsxs("div",{className:"md:hidden p-4 pb-20 border-t border-border/50 space-y-2",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:m,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx(It,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"设置"})]}),R&&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:v,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx(jt,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"管理"})]})]}),e.jsxs(W,{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:m,children:[e.jsx(It,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"设置"})]}),R&&e.jsxs(W,{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:v,children:[e.jsx(jt,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"管理"})]})]})]})]})}const co={'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 Wr={exports:{}},Br,Os;function mo(){if(Os)return Br;Os=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Br=t,Br}var Ur,_s;function uo(){if(_s)return Ur;_s=1;var t=mo();function s(){}function a(){}return a.resetWarningCache=s,Ur=function(){function o(i,d,x,h,m,v){if(v!==t){var b=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 b.name="Invariant Violation",b}}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},Ur}var Fs;function po(){return Fs||(Fs=1,Wr.exports=uo()()),Wr.exports}var xo=po();const Be=cs(xo);function Ot(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(m){try{h(o.next(m))}catch(v){i(v)}}function x(m){try{h(o.throw(m))}catch(v){i(v)}}function h(m){m.done?l(m.value):n(m.value).then(d,x)}h((o=o.apply(t,s||[])).next())})}const ho=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 Yt(t,s,a){const o=go(t),{webkitRelativePath:n}=t,l=typeof s=="string"?s:typeof n=="string"&&n.length>0?n:`./${t.name}`;return typeof o.path!="string"&&Ws(o,"path",l),Ws(o,"relativePath",l),o}function go(t){const{name:s}=t;if(s&&s.lastIndexOf(".")!==-1&&!t.type){const o=s.split(".").pop().toLowerCase(),n=ho.get(o);n&&Object.defineProperty(t,"type",{value:n,writable:!1,configurable:!1,enumerable:!0})}return t}function Ws(t,s,a){Object.defineProperty(t,s,{value:a,writable:!1,configurable:!1,enumerable:!0})}const fo=[".DS_Store","Thumbs.db"];function bo(t){return Ot(this,void 0,void 0,function*(){return Sr(t)&&vo(t.dataTransfer)?ko(t.dataTransfer,t.type):yo(t)?jo(t):Array.isArray(t)&&t.every(s=>"getFile"in s&&typeof s.getFile=="function")?wo(t):[]})}function vo(t){return Sr(t)}function yo(t){return Sr(t)&&Sr(t.target)}function Sr(t){return typeof t=="object"&&t!==null}function jo(t){return es(t.target.files).map(s=>Yt(s))}function wo(t){return Ot(this,void 0,void 0,function*(){return(yield Promise.all(t.map(a=>a.getFile()))).map(a=>Yt(a))})}function ko(t,s){return Ot(this,void 0,void 0,function*(){if(t.items){const a=es(t.items).filter(n=>n.kind==="file");if(s!=="drop")return a;const o=yield Promise.all(a.map(No));return Bs(ba(o))}return Bs(es(t.files).map(a=>Yt(a)))})}function Bs(t){return t.filter(s=>fo.indexOf(s.name)===-1)}function es(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 No(t){if(typeof t.webkitGetAsEntry!="function")return Us(t);const s=t.webkitGetAsEntry();return s&&s.isDirectory?va(s):Us(t,s)}function ba(t){return t.reduce((s,a)=>[...s,...Array.isArray(a)?ba(a):[a]],[])}function Us(t,s){return Ot(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,Yt(i)}}const o=t.getAsFile();if(!o)throw new Error(`${t} is not a File`);return Yt(o,(a=s?.fullPath)!==null&&a!==void 0?a:void 0)})}function So(t){return Ot(this,void 0,void 0,function*(){return t.isDirectory?va(t):Co(t)})}function va(t){const s=t.createReader();return new Promise((a,o)=>{const n=[];function l(){s.readEntries(i=>Ot(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 Co(t){return Ot(this,void 0,void 0,function*(){return new Promise((s,a)=>{t.file(o=>{const n=Yt(o,t.fullPath);s(n)},o=>{a(o)})})})}var fr={},Hs;function Eo(){return Hs||(Hs=1,fr.__esModule=!0,fr.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}),fr}var Mo=Eo();const Hr=cs(Mo);function qs(t){return Do(t)||Io(t)||ja(t)||Lo()}function Lo(){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 Io(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Do(t){if(Array.isArray(t))return ts(t)}function Js(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 Ks(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Js(Object(a),!0).forEach(function(o){ya(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Js(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function ya(t,s,a){return s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function lr(t,s){return Po(t)||Ro(t,s)||ja(t,s)||To()}function To(){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 ja(t,s){if(t){if(typeof t=="string")return ts(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 ts(t,s)}}function ts(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 Ro(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(x){l=!0,d=x}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 $o=typeof Hr=="function"?Hr:Hr.default,zo="file-invalid-type",Ao="file-too-large",Oo="file-too-small",_o="too-many-files",Fo=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:zo,message:"File type must be ".concat(o)}},Gs=function(s){return{code:Ao,message:"File is larger than ".concat(s," ").concat(s===1?"byte":"bytes")}},Vs=function(s){return{code:Oo,message:"File is smaller than ".concat(s," ").concat(s===1?"byte":"bytes")}},Wo={code:_o,message:"Too many files"};function wa(t,s){var a=t.type==="application/x-moz-file"||$o(t,s);return[a,a?null:Fo(s)]}function ka(t,s,a){if(Rt(t.size))if(Rt(s)&&Rt(a)){if(t.size>a)return[!1,Gs(a)];if(t.size<s)return[!1,Vs(s)]}else{if(Rt(s)&&t.size<s)return[!1,Vs(s)];if(Rt(a)&&t.size>a)return[!1,Gs(a)]}return[!0,null]}function Rt(t){return t!=null}function Bo(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(x){var h=wa(x,a),m=lr(h,1),v=m[0],b=ka(x,o,n),j=lr(b,1),f=j[0],E=d?d(x):null;return v&&f&&!E})}function Cr(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function br(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 Ys(t){t.preventDefault()}function Uo(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function Ho(t){return t.indexOf("Edge/")!==-1}function qo(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return Uo(t)||Ho(t)}function xt(){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!Cr(o)&&d&&d.apply(void 0,[o].concat(l)),Cr(o)})}}function Jo(){return"showOpenFilePicker"in window}function Ko(t){if(Rt(t)){var s=Object.entries(t).filter(function(a){var o=lr(a,2),n=o[0],l=o[1],i=!0;return Na(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(Sa))&&(console.warn('Skipped "'.concat(n,'" because an invalid file extension was provided.')),i=!1),i}).reduce(function(a,o){var n=lr(o,2),l=n[0],i=n[1];return Ks(Ks({},a),{},ya({},l,i))},{});return[{description:"Files",accept:s}]}return t}function Go(t){if(Rt(t))return Object.entries(t).reduce(function(s,a){var o=lr(a,2),n=o[0],l=o[1];return[].concat(qs(s),[n],qs(l))},[]).filter(function(s){return Na(s)||Sa(s)}).join(",")}function Vo(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function Yo(t){return t instanceof DOMException&&(t.name==="SecurityError"||t.code===t.SECURITY_ERR)}function Na(t){return t==="audio/*"||t==="video/*"||t==="image/*"||t==="text/*"||t==="application/*"||/\w+\/[-+.\w]+/g.test(t)}function Sa(t){return/^.*\.[\w]+$/.test(t)}var Qo=["children"],Zo=["open"],Xo=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],ei=["refKey","onChange","onClick"];function ti(t){return ai(t)||si(t)||Ca(t)||ri()}function ri(){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 si(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function ai(t){if(Array.isArray(t))return rs(t)}function qr(t,s){return ii(t)||oi(t,s)||Ca(t,s)||ni()}function ni(){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 Ca(t,s){if(t){if(typeof t=="string")return rs(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 rs(t,s)}}function rs(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 oi(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(x){l=!0,d=x}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw d}}return o}}function ii(t){if(Array.isArray(t))return t}function Qs(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 Je(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Qs(Object(a),!0).forEach(function(o){ss(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Qs(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function ss(t,s,a){return s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function Er(t,s){if(t==null)return{};var a=li(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 li(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 xs=r.forwardRef(function(t,s){var a=t.children,o=Er(t,Qo),n=hs(o),l=n.open,i=Er(n,Zo);return r.useImperativeHandle(s,function(){return{open:l}},[l]),it.createElement(r.Fragment,null,a(Je(Je({},i),{},{open:l})))});xs.displayName="Dropzone";var Ea={disabled:!1,getFilesFromEvent:bo,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};xs.defaultProps=Ea;xs.propTypes={children:Be.func,accept:Be.objectOf(Be.arrayOf(Be.string)),multiple:Be.bool,preventDropOnDocument:Be.bool,noClick:Be.bool,noKeyboard:Be.bool,noDrag:Be.bool,noDragEventsBubbling:Be.bool,minSize:Be.number,maxSize:Be.number,maxFiles:Be.number,disabled:Be.bool,getFilesFromEvent:Be.func,onFileDialogCancel:Be.func,onFileDialogOpen:Be.func,useFsAccessApi:Be.bool,autoFocus:Be.bool,onDragEnter:Be.func,onDragLeave:Be.func,onDragOver:Be.func,onDrop:Be.func,onDropAccepted:Be.func,onDropRejected:Be.func,onError:Be.func,validator:Be.func};var as={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function hs(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Je(Je({},Ea),t),a=s.accept,o=s.disabled,n=s.getFilesFromEvent,l=s.maxSize,i=s.minSize,d=s.multiple,x=s.maxFiles,h=s.onDragEnter,m=s.onDragLeave,v=s.onDragOver,b=s.onDrop,j=s.onDropAccepted,f=s.onDropRejected,E=s.onFileDialogCancel,O=s.onFileDialogOpen,T=s.useFsAccessApi,R=s.autoFocus,g=s.preventDropOnDocument,p=s.noClick,u=s.noKeyboard,y=s.noDrag,L=s.noDragEventsBubbling,$=s.onError,P=s.validator,z=r.useMemo(function(){return Go(a)},[a]),me=r.useMemo(function(){return Ko(a)},[a]),se=r.useMemo(function(){return typeof O=="function"?O:Zs},[O]),te=r.useMemo(function(){return typeof E=="function"?E:Zs},[E]),de=r.useRef(null),_=r.useRef(null),A=r.useReducer(ci,as),ae=qr(A,2),fe=ae[0],ue=ae[1],Z=fe.isFocused,G=fe.isFileDialogActive,pe=r.useRef(typeof window<"u"&&window.isSecureContext&&T&&Jo()),Pe=function(){!pe.current&&G&&setTimeout(function(){if(_.current){var oe=_.current.files;oe.length||(ue({type:"closeDialog"}),te())}},300)};r.useEffect(function(){return window.addEventListener("focus",Pe,!1),function(){window.removeEventListener("focus",Pe,!1)}},[_,G,te,pe]);var Me=r.useRef([]),Le=function(oe){de.current&&de.current.contains(oe.target)||(oe.preventDefault(),Me.current=[])};r.useEffect(function(){return g&&(document.addEventListener("dragover",Ys,!1),document.addEventListener("drop",Le,!1)),function(){g&&(document.removeEventListener("dragover",Ys),document.removeEventListener("drop",Le))}},[de,g]),r.useEffect(function(){return!o&&R&&de.current&&de.current.focus(),function(){}},[de,R,o]);var Ne=r.useCallback(function(V){$?$(V):console.error(V)},[$]),qe=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V),Me.current=[].concat(ti(Me.current),[V.target]),br(V)&&Promise.resolve(n(V)).then(function(oe){if(!(Cr(V)&&!L)){var Te=oe.length,Re=Te>0&&Bo({files:oe,accept:z,minSize:i,maxSize:l,multiple:d,maxFiles:x,validator:P}),Ce=Te>0&&!Re;ue({isDragAccept:Re,isDragReject:Ce,isDragActive:!0,type:"setDraggedFiles"}),h&&h(V)}}).catch(function(oe){return Ne(oe)})},[n,h,Ne,L,z,i,l,d,x,P]),Ke=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V);var oe=br(V);if(oe&&V.dataTransfer)try{V.dataTransfer.dropEffect="copy"}catch{}return oe&&v&&v(V),!1},[v,L]),We=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V);var oe=Me.current.filter(function(Re){return de.current&&de.current.contains(Re)}),Te=oe.indexOf(V.target);Te!==-1&&oe.splice(Te,1),Me.current=oe,!(oe.length>0)&&(ue({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),br(V)&&m&&m(V))},[de,m,L]),Ie=r.useCallback(function(V,oe){var Te=[],Re=[];V.forEach(function(Ce){var S=wa(Ce,z),ee=qr(S,2),we=ee[0],Y=ee[1],H=ka(Ce,i,l),M=qr(H,2),ne=M[0],B=M[1],re=P?P(Ce):null;if(we&&ne&&!re)Te.push(Ce);else{var ie=[Y,B];re&&(ie=ie.concat(re)),Re.push({file:Ce,errors:ie.filter(function(ye){return ye})})}}),(!d&&Te.length>1||d&&x>=1&&Te.length>x)&&(Te.forEach(function(Ce){Re.push({file:Ce,errors:[Wo]})}),Te.splice(0)),ue({acceptedFiles:Te,fileRejections:Re,isDragReject:Re.length>0,type:"setFiles"}),b&&b(Te,Re,oe),Re.length>0&&f&&f(Re,oe),Te.length>0&&j&&j(Te,oe)},[ue,d,z,i,l,x,b,j,f,P]),je=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V),Me.current=[],br(V)&&Promise.resolve(n(V)).then(function(oe){Cr(V)&&!L||Ie(oe,V)}).catch(function(oe){return Ne(oe)}),ue({type:"reset"})},[n,Ie,Ne,L]),$e=r.useCallback(function(){if(pe.current){ue({type:"openDialog"}),se();var V={multiple:d,types:me};window.showOpenFilePicker(V).then(function(oe){return n(oe)}).then(function(oe){Ie(oe,null),ue({type:"closeDialog"})}).catch(function(oe){Vo(oe)?(te(oe),ue({type:"closeDialog"})):Yo(oe)?(pe.current=!1,_.current?(_.current.value=null,_.current.click()):Ne(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."))):Ne(oe)});return}_.current&&(ue({type:"openDialog"}),se(),_.current.value=null,_.current.click())},[ue,se,te,T,Ie,Ne,me,d]),Fe=r.useCallback(function(V){!de.current||!de.current.isEqualNode(V.target)||(V.key===" "||V.key==="Enter"||V.keyCode===32||V.keyCode===13)&&(V.preventDefault(),$e())},[de,$e]),_e=r.useCallback(function(){ue({type:"focus"})},[]),ze=r.useCallback(function(){ue({type:"blur"})},[]),J=r.useCallback(function(){p||(qo()?setTimeout($e,0):$e())},[p,$e]),q=function(oe){return o?null:oe},w=function(oe){return u?null:q(oe)},K=function(oe){return y?null:q(oe)},he=function(oe){L&&oe.stopPropagation()},ve=r.useMemo(function(){return function(){var V=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},oe=V.refKey,Te=oe===void 0?"ref":oe,Re=V.role,Ce=V.onKeyDown,S=V.onFocus,ee=V.onBlur,we=V.onClick,Y=V.onDragEnter,H=V.onDragOver,M=V.onDragLeave,ne=V.onDrop,B=Er(V,Xo);return Je(Je(ss({onKeyDown:w(xt(Ce,Fe)),onFocus:w(xt(S,_e)),onBlur:w(xt(ee,ze)),onClick:q(xt(we,J)),onDragEnter:K(xt(Y,qe)),onDragOver:K(xt(H,Ke)),onDragLeave:K(xt(M,We)),onDrop:K(xt(ne,je)),role:typeof Re=="string"&&Re!==""?Re:"presentation"},Te,de),!o&&!u?{tabIndex:0}:{}),B)}},[de,Fe,_e,ze,J,qe,Ke,We,je,u,y,o]),Ae=r.useCallback(function(V){V.stopPropagation()},[]),Ue=r.useMemo(function(){return function(){var V=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},oe=V.refKey,Te=oe===void 0?"ref":oe,Re=V.onChange,Ce=V.onClick,S=Er(V,ei),ee=ss({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:q(xt(Re,je)),onClick:q(xt(Ce,Ae)),tabIndex:-1},Te,_);return Je(Je({},ee),S)}},[_,a,d,je,o]);return Je(Je({},fe),{},{isFocused:Z&&!o,getRootProps:ve,getInputProps:Ue,rootRef:de,inputRef:_,open:q($e)})}function ci(t,s){switch(s.type){case"focus":return Je(Je({},t),{},{isFocused:!0});case"blur":return Je(Je({},t),{},{isFocused:!1});case"openDialog":return Je(Je({},as),{},{isFileDialogActive:!0});case"closeDialog":return Je(Je({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Je(Je({},t),{},{isDragActive:s.isDragActive,isDragAccept:s.isDragAccept,isDragReject:s.isDragReject});case"setFiles":return Je(Je({},t),{},{acceptedFiles:s.acceptedFiles,fileRejections:s.fileRejections,isDragReject:s.isDragReject});case"reset":return Je({},as);default:return t}}function Zs(){}const Jr=({todos:t,isResult:s=!1})=>{if(!t||!Array.isArray(t))return null;const a=l=>{switch(l){case"completed":return e.jsx(wn,{className:"w-4 h-4 text-green-500 dark:text-green-400"});case"in_progress":return e.jsx(Gr,{className:"w-4 h-4 text-blue-500 dark:text-blue-400"});case"pending":default:return e.jsx(jn,{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(Qe,{variant:"outline",className:`text-xs px-2 py-0.5 ${n(l.priority)}`,children:l.priority}),e.jsx(Qe,{variant:"outline",className:`text-xs px-2 py-0.5 ${o(l.status)}`,children:l.status.replace("_"," ")})]})]})})]},l.id||`todo-${i}`))]})};function di({status:t,onAbort:s,isLoading:a,provider:o="claude"}){const[n,l]=r.useState(0),[i,d]=r.useState(0),[x,h]=r.useState(0);if(r.useEffect(()=>{if(!a){l(0),h(0);return}const T=Date.now(),R=30+Math.random()*20,g=setInterval(()=>{const p=Math.floor((Date.now()-T)/1e3);l(p),h(Math.floor(p*R))},1e3);return()=>clearInterval(g)},[a]),r.useEffect(()=>{if(!a)return;const T=setInterval(()=>{d(R=>(R+1)%4)},500);return()=>clearInterval(T)},[a]),!a)return null;const m=["思考中","处理中","分析中","工作中","计算中","推理中"],v=Math.floor(n/3)%m.length,b=t?.text||m[v],j=t?.tokens||x,f=t?.can_interrupt!==!1,O=["✻","✹","✸","✶"][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:Ve("text-base sm:text-xl transition-all duration-500 flex-shrink-0",i%2===0?"text-blue-400 scale-110":"text-blue-300"),children:O}),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:[b,"..."]}),e.jsxs("span",{className:"text-gray-400 text-xs sm:text-sm flex-shrink-0",children:["(",n,"s)"]}),j>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:["⚒ ",j.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 停止"})]})})]})}),f&&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 mi(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 ke.transcribe(a);if(!i.ok){const x=await i.json().catch(()=>({}));throw new Error(x.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 ui({onTranscript:t,className:s=""}){const[a,o]=r.useState("idle"),[n,l]=r.useState(null),[i,d]=r.useState(!0),x=r.useRef(null),h=r.useRef(null),m=r.useRef([]),v=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 b=async()=>{try{if(console.log("Starting recording..."),l(null),m.current=[],!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)throw new Error("Microphone access not available. Please use HTTPS or a supported browser.");const g=await navigator.mediaDevices.getUserMedia({audio:!0});h.current=g;const p=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",u=new MediaRecorder(g,{mimeType:p});x.current=u,u.ondataavailable=y=>{y.data.size>0&&m.current.push(y.data)},u.onstop=async()=>{console.log("Recording stopped, creating blob...");const y=new Blob(m.current,{type:p});h.current&&(h.current.getTracks().forEach(z=>z.stop()),h.current=null),o("transcribing");const L=window.localStorage.getItem("whisperMode")||"default",$=L==="prompt"||L==="vibe"||L==="instructions"||L==="architect";let P;$&&(P=setTimeout(()=>{o("processing")},2e3));try{const z=await mi(y);z&&t&&t(z)}catch(z){console.error("Transcription error:",z),l(z.message)}finally{P&&clearTimeout(P),o("idle")}},u.start(),o("recording"),console.log("Recording started successfully")}catch(g){console.error("Failed to start recording:",g);let p="Microphone access failed";g.name==="NotAllowedError"?p="Microphone access denied. Please allow microphone permissions.":g.name==="NotFoundError"?p="No microphone found. Please check your audio devices.":g.name==="NotSupportedError"?p="Microphone not supported by this browser.":g.name==="NotReadableError"?p="Microphone is being used by another application.":g.message.includes("HTTPS")&&(p=g.message),l(p),o("idle")}},j=()=>{console.log("Stopping recording..."),x.current&&x.current.state==="recording"?x.current.stop():(console.log("Recorder not in recording state, forcing cleanup"),h.current&&(h.current.getTracks().forEach(g=>g.stop()),h.current=null),o("idle"))},f=g=>{if(g&&(g.preventDefault(),g.stopPropagation()),!i)return;const p=Date.now();if(p-v.current<300){console.log("Ignoring rapid tap");return}v.current=p,console.log("Button clicked, current state:",a),a==="idle"?b():a==="recording"&&j()};r.useEffect(()=>()=>{h.current&&h.current.getTracks().forEach(g=>g.stop())},[]);const E=()=>{if(!i)return{icon:e.jsx(wr,{className:"w-5 h-5"}),className:"bg-gray-400 cursor-not-allowed",disabled:!0};switch(a){case"recording":return{icon:e.jsx(wr,{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(Mt,{className:"w-5 h-5 animate-spin"}),className:"bg-blue-500 hover:bg-blue-600",disabled:!0};case"processing":return{icon:e.jsx(oa,{className:"w-5 h-5 animate-pulse"}),className:"bg-purple-500 hover:bg-purple-600",disabled:!0};default:return{icon:e.jsx(wr,{className:"w-5 h-5"}),className:"bg-gray-700 hover:bg-gray-600",disabled:!1}}},{icon:O,className:T,disabled:R}=E();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:`
1
+ import{j as e,s as rn,R as sn,o as an,E as nn,m as on,b as ln,c as cn,h as dn,p as mn,d as un}from"./vendor-codemirror-C_VWDoZS.js";import{b as pn,g as ds,a as r,d as aa,R as it,u as na,B as xn,e as hn,f as Ts,h as gn}from"./vendor-react-BeVl62c0.js";import{t as fn,c as bn,a as oa,F as vn}from"./vendor-utils-00TdZexr.js";import{T as It,C as ia,I as ms,F as Gr,X as He,L as Dt,R as _t,S as Ft,a as pt,b as At,c as wr,d as Rs,e as tt,P as cr,f as Fr,g as Vt,h as Vr,i as yn,j as lt,k as Tt,l as kt,m as jn,n as wn,M as kr,B as la,D as Ot,o as ca,p as kn,q as da,U as Ps,r as Nn,E as ma,s as Sn,t as Cn,u as ua,v as $s,w as Lr,x as mr,y as ur,G as us,z as Nr,Z as pa,A as xa,H as Qt,J as ha,K as Yr,N as Qr,O as Zr,Q as Xr,V as En,W as Mn,Y as Ln,_ as Dn,$ as ps,a0 as In,a1 as Tn,a2 as Rn,a3 as Pn,a4 as es,a5 as $n,a6 as Sr,a7 as ga,a8 as fa,a9 as zn,aa as An,ab as On,ac as _n,ad as Fn,ae as Wn,af as Bn}from"./vendor-icons-KP5LHo3O.js";import{r as Un,a as Hn,b as qn,M as Jn}from"./vendor-markdown-VwNYkg_0.js";import{h as Kn}from"./vendor-syntax-CdGaPJRS.js";import{r as Gn,a as Vn,b as Yn,c as Qn}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 fr={},zs;function Zn(){if(zs)return fr;zs=1;var t=pn();return fr.createRoot=t.createRoot,fr.hydrateRoot=t.hydrateRoot,fr}var Xn=Zn();const eo=ds(Xn);function Ve(...t){return fn(bn(t))}function to(t){if(!t||typeof t!="string")return null;try{return JSON.parse(t)}catch{return null}}const xs=r.forwardRef(({className:t,children:s,...a},o)=>e.jsx("div",{ref:o,className:Ve("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})}));xs.displayName="ScrollArea";const ro=oa("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"}}),W=r.forwardRef(({className:t,variant:s,size:a,...o},n)=>e.jsx("button",{className:Ve(ro({variant:s,size:a,className:t})),ref:n,...o}));W.displayName="Button";const so=oa("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 Qe({className:t,variant:s,...a}){return e.jsx("div",{className:Ve(so({variant:s}),t),...a})}const Xe=r.forwardRef(({className:t,type:s,...a},o)=>e.jsx("input",{type:s,className:Ve("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}));Xe.displayName="Input";const gt=({className:t="w-5 h-5"})=>e.jsx("img",{src:"/icons/claude-ai-icon.svg",alt:"Claude",className:t}),ba=r.createContext(null);function ct(){const t=r.useContext(ba);if(!t)throw new Error("useDialog must be used within DialogProvider");return t}function ao({children:t}){const[s,a]=r.useState(null),o=r.useRef(null),n=r.useCallback(d=>{o.current?.(d),o.current=null,a(null)},[]),l=r.useCallback((d,x={})=>new Promise(h=>{o.current=h,a({type:"alert",message:d,title:x.title||"提示",variant:x.variant||"info"})}),[]),i=r.useCallback((d,x={})=>new Promise(h=>{o.current=h,a({type:"confirm",message:d,title:x.title||"确认操作",subtitle:x.subtitle,detail:x.detail,confirmText:x.confirmText||"确认",cancelText:x.cancelText||"取消",variant:x.variant||"warning"})}),[]);return e.jsxs(ba.Provider,{value:{showAlert:l,showConfirm:i},children:[t,s&&aa.createPortal(e.jsx(no,{dialog:s,onClose:n}),document.body)]})}function no({dialog:t,onClose:s}){const a=r.useRef(null),o=r.useRef(null);r.useEffect(()=>{t.type==="confirm"?a.current?.focus():o.current?.focus()},[t.type]),r.useEffect(()=>{const h=m=>{m.key==="Escape"&&s(t.type==="confirm"?!1:void 0)};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t.type,s]);const n={info:e.jsx(ms,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"}),warning:e.jsx(It,{className:"w-5 h-5 text-amber-600 dark:text-amber-400"}),error:e.jsx(ia,{className:"w-5 h-5 text-red-600 dark:text-red-400"}),danger:e.jsx(It,{className:"w-5 h-5 text-red-600 dark:text-red-400"})},l={info:"bg-blue-100 dark:bg-blue-900/30",warning:"bg-amber-100 dark:bg-amber-900/30",error:"bg-red-100 dark:bg-red-900/30",danger:"bg-red-100 dark:bg-red-900/30"},i={warning:"bg-amber-600 hover:bg-amber-700 text-white",danger:"bg-red-600 hover:bg-red-700 text-white",info:"bg-primary hover:bg-primary/90 text-primary-foreground"},d=n[t.variant]||n.info,x=l[t.variant]||l.info;return t.type==="alert"?e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>s(),children:e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl w-full max-w-sm p-6 space-y-4",onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-full ${x} flex items-center justify-center flex-shrink-0`,children:d}),e.jsx("h3",{className:"font-semibold text-foreground",children:t.title})]}),e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:t.message}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx("button",{ref:o,className:"px-4 py-2 rounded-lg bg-primary hover:bg-primary/90 text-primary-foreground text-sm font-medium transition-colors",onClick:()=>s(),children:"确定"})})]})}):e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>s(!1),children:e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl w-full max-w-sm p-6 space-y-4",onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-full ${x} flex items-center justify-center flex-shrink-0`,children:d}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-foreground",children:t.title}),t.subtitle&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.subtitle})]})]}),e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:t.message}),t.detail&&e.jsx("p",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3",children:t.detail}),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:()=>s(!1),children:t.cancelText}),e.jsx("button",{ref:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${i[t.variant]||i.info}`,onClick:()=>s(!0),children:t.confirmText})]})]})})}const Z=(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}})},ke={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:()=>Z("/api/auth/user"),logout:()=>Z("/api/auth/logout",{method:"POST"}),limitStatus:()=>Z("/api/auth/limit-status"),changePassword:(t,s)=>Z("/api/auth/change-password",{method:"PATCH",body:JSON.stringify({current_password:t,new_password:s})}),feishuBindToken:()=>Z("/api/auth/feishu-bind-token",{method:"POST"}),feishuStatus:()=>Z("/api/auth/feishu-status")},admin:{getUsers:()=>Z("/api/admin/users"),createUser:(t,s)=>Z("/api/admin/users",{method:"POST",body:JSON.stringify({username:t,password:s})}),updateUserStatus:(t,s)=>Z(`/api/admin/users/${t}`,{method:"PATCH",body:JSON.stringify({status:s})}),deleteUser:t=>Z(`/api/admin/users/${t}`,{method:"DELETE"}),getEmailDomains:()=>Z("/api/admin/email-domains"),addEmailDomain:t=>Z("/api/admin/email-domains",{method:"POST",body:JSON.stringify({domain:t})}),removeEmailDomain:t=>Z(`/api/admin/email-domains/${t}`,{method:"DELETE"}),getUserLimits:t=>Z(`/api/admin/users/${t}/limits`),updateUserLimits:(t,s)=>Z(`/api/admin/users/${t}/limits`,{method:"PATCH",body:JSON.stringify(s)}),resetUserPassword:(t,s)=>Z(`/api/admin/users/${t}/password`,{method:"PATCH",body:JSON.stringify({new_password:s})}),updateUserRole:(t,s)=>Z(`/api/admin/users/${t}/role`,{method:"PATCH",body:JSON.stringify({role:s})}),getDefaultLimits:()=>Z("/api/admin/settings/default-limits"),updateDefaultLimits:t=>Z("/api/admin/settings/default-limits",{method:"PUT",body:JSON.stringify(t)})},projects:()=>Z("/api/projects"),sessions:(t,s=5,a=0)=>Z(`/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 Z(i)},renameProject:(t,s)=>Z(`/api/projects/${t}/rename`,{method:"PUT",body:JSON.stringify({displayName:s})}),deleteSession:(t,s)=>Z(`/api/projects/${t}/sessions/${s}`,{method:"DELETE"}),deleteProject:(t,s=!0)=>Z(`/api/projects/${t}?deleteFolder=${s}`,{method:"DELETE"}),createProject:t=>Z("/api/projects/create",{method:"POST",body:JSON.stringify({path:t})}),createWorkspace:t=>Z("/api/projects/create-workspace",{method:"POST",body:JSON.stringify(t)}),readFile:(t,s)=>Z(`/api/projects/${t}/file?filePath=${encodeURIComponent(s)}`),saveFile:(t,s,a)=>Z(`/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 Z(`/api/projects/${t}/files${o?"?"+o:""}`)},uploadFiles:(t,s)=>Z(`/api/projects/${t}/upload-files`,{method:"POST",body:s,headers:{}}),deleteFile:(t,s)=>Z(`/api/projects/${t}/files?filePath=${encodeURIComponent(s)}`,{method:"DELETE"}),getFileContent:(t,s)=>Z(`/api/projects/${t}/files/content?path=${encodeURIComponent(s)}`),transcribe:t=>Z("/api/transcribe",{method:"POST",body:t,headers:{}}),settings:{getAgentPermissions:()=>Z("/api/settings/agent-permissions"),saveAgentPermissions:t=>Z("/api/settings/agent-permissions",{method:"PUT",body:JSON.stringify({agentPermissions:t})})},get:t=>Z(`/api${t}`)},va=r.createContext({user:null,token:null,login:()=>{},sendCode:()=>{},verifyCode:()=>{},logout:()=>{},isLoading:!0,needsSetup:!1,smtpConfigured:!1,error:null,isAdmin:!1,isSuperAdmin:!1,limitStatus:{allowed:!0},checkLimitStatus:()=>{},setLimitStatus:()=>{}}),Nt=()=>{const t=r.useContext(va);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t};async function Wr(){try{const t=await ke.settings.getAgentPermissions();if(t.ok){const s=await t.json();s.agentPermissions&&localStorage.setItem("claude-settings",JSON.stringify(s.agentPermissions))}}catch{}}const oo=({children:t})=>{const[s,a]=r.useState(null),[o,n]=r.useState(localStorage.getItem("auth-token")),[l,i]=r.useState(!0),[d,x]=r.useState(!1),[h,m]=r.useState(!1),[v,b]=r.useState(null),[j,f]=r.useState({allowed:!0});r.useEffect(()=>{E()},[]);const E=async()=>{try{i(!0),b(null);const L=await(await ke.auth.status()).json();if(m(L.smtpConfigured||!1),L.needsSetup){x(!0),i(!1);return}if(o)try{const $=await ke.auth.user();if($.ok){const P=await $.json();a(P.user),x(!1),await Wr()}else localStorage.removeItem("auth-token"),n(null),a(null)}catch($){console.error("Token verification failed:",$),localStorage.removeItem("auth-token"),n(null),a(null)}}catch(y){console.error("[AuthContext] Auth status check failed:",y),b("Failed to check authentication status")}finally{i(!1)}},O=async y=>{try{b(null);const L=await ke.auth.sendCode(y),$=await L.json();return L.ok?{success:!0,type:$.type}:{success:!1,error:$.error||"发送验证码失败",waitSeconds:$.waitSeconds}}catch(L){return console.error("Send code error:",L),{success:!1,error:"网络错误,请稍后再试"}}},T=async(y,L)=>{try{b(null);const $=await ke.auth.verifyCode(y,L),P=await $.json();return $.ok?(n(P.token),a(P.user),x(!1),localStorage.setItem("auth-token",P.token),await Wr(),{success:!0}):(b(P.error||"验证失败"),{success:!1,error:P.error||"验证失败"})}catch($){return console.error("Verify code error:",$),{success:!1,error:"网络错误,请稍后再试"}}},R=async(y,L)=>{try{b(null);const $=await ke.auth.login(y,L),P=await $.json();return $.ok?(n(P.token),a(P.user),localStorage.setItem("auth-token",P.token),await Wr(),{success:!0}):(b(P.error||"登录失败"),{success:!1,error:P.error||"登录失败"})}catch($){console.error("Login error:",$);const P="网络错误,请稍后再试";return b(P),{success:!1,error:P}}},g=()=>{n(null),a(null),f({allowed:!0}),localStorage.removeItem("auth-token"),o&&ke.auth.logout().catch(y=>{console.error("Logout endpoint error:",y)})},p=async()=>{if(!s)return{allowed:!0};try{const y=await ke.auth.limitStatus();if(y.ok){const L=await y.json();return f(L),L}}catch(y){console.error("Error checking limit status:",y)}return{allowed:!0}};r.useEffect(()=>{s&&!l&&p()},[s,l]);const u={user:s,token:o,login:R,sendCode:O,verifyCode:T,logout:g,isLoading:l,needsSetup:d,smtpConfigured:h,error:v,isAdmin:s?.role==="admin"||s?.role==="super_admin",isSuperAdmin:s?.role==="super_admin",limitStatus:j,checkLimitStatus:p,setLimitStatus:f};return e.jsx(va.Provider,{value:u,children:t})},io=/^[a-zA-Z0-9_-]+$/,lo=({onClose:t,onProjectCreated:s})=>{const[a,o]=r.useState(""),[n,l]=r.useState(""),[i,d]=r.useState(!1),[x,h]=r.useState(null),m=j=>j.trim()?io.test(j.trim())?null:"项目名称只能包含字母、数字、连字符和下划线":"项目名称为必填项",v=async()=>{h(null);const j=m(a);if(j){h(j);return}d(!0);try{const f={name:a.trim()};n.trim()&&(f.githubUrl=n.trim());const E=await ke.createWorkspace(f),O=await E.json();if(!E.ok)throw new Error(O.error||"Failed to create project");s&&s(O.project),t()}catch(f){console.error("Error creating project:",f),h(f.message||"Failed to create project")}finally{d(!1)}},b=j=>{j.key==="Enter"&&!i&&v()};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(Gr,{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(He,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[x&&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(ia,{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:x})})]}),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(Xe,{type:"text",value:a,onChange:j=>o(j.target.value),onKeyDown:b,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(Xe,{type:"text",value:n,onChange:j=>l(j.target.value),onKeyDown:b,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(W,{variant:"outline",onClick:t,disabled:i,children:"取消"}),e.jsx(W,{onClick:v,disabled:i||!a.trim(),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Dt,{className:"w-4 h-4 mr-2 animate-spin"}),"创建中..."]}):"创建项目"})]})]})})},As=(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)),x=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`:x===1?"1 day ago":x<7?`${x} days ago`:a.toLocaleDateString()};function Os({projects:t,selectedProject:s,selectedSession:a,onProjectSelect:o,onSessionSelect:n,onNewSession:l,onSessionDelete:i,onProjectDelete:d,isLoading:x,onRefresh:h,onShowSettings:m,onShowAdmin:v,isPWA:b,isMobile:j,onToggleSidebar:f}){const{showAlert:E,showConfirm:O}=ct(),{user:T,isAdmin:R}=Nt(),[g,p]=r.useState(new Set),[u,y]=r.useState(null),[L,$]=r.useState(!1),[P,z]=r.useState(""),[me,se]=r.useState({}),[te,de]=r.useState({}),[_,A]=r.useState(new Set),[ae,fe]=r.useState(new Date),[ue,X]=r.useState("name"),[G,pe]=r.useState(!1),[Pe,Ee]=r.useState(null),[Me,Ne]=r.useState(""),[qe,Ge]=r.useState({}),[We,De]=r.useState(""),[je,$e]=r.useState(()=>{try{const N=localStorage.getItem("starredProjects");return N?new Set(JSON.parse(N)):new Set}catch(N){return console.error("Error loading starred projects:",N),new Set}}),Fe=N=>ee=>{ee.target.closest(".overflow-y-auto")||ee.target.closest("[data-scroll-container]")||(ee.preventDefault(),ee.stopPropagation(),N())};r.useEffect(()=>{const N=setInterval(()=>{fe(new Date)},6e4);return()=>clearInterval(N)},[]),r.useEffect(()=>{de({}),A(new Set)},[t]),r.useEffect(()=>{a&&s&&p(N=>new Set([...N,s.name]))},[a,s]),r.useEffect(()=>{if(t.length>0&&!x){const N=new Set;t.forEach(ee=>{ee.sessions&&ee.sessions.length>=0&&N.add(ee.name)}),A(N)}},[t,x]),r.useEffect(()=>{const N=()=>{try{const Y=localStorage.getItem("claude-settings");if(Y){const U=JSON.parse(Y);X(U.projectSortOrder||"name")}}catch(Y){console.error("Error loading sort order:",Y)}};N();const ee=Y=>{Y.key==="claude-settings"&&N()};window.addEventListener("storage",ee);const we=setInterval(()=>{document.hasFocus()&&N()},1e3);return()=>{window.removeEventListener("storage",ee),clearInterval(we)}},[]);const _e=N=>{const ee=new Set;g.has(N)||ee.add(N),p(ee)},ze=(N,ee)=>{n({...N,__projectName:ee})},J=N=>{const ee=new Set(je);ee.has(N)?ee.delete(N):ee.add(N),$e(ee);try{localStorage.setItem("starredProjects",JSON.stringify([...ee]))}catch(we){console.error("Error saving starred projects:",we)}},q=N=>je.has(N),w=N=>[...N.sessions||[],...te[N.name]||[]].map(we=>({...we,__provider:"claude"})).sort((we,Y)=>new Date(Y.lastActivity)-new Date(we.lastActivity)),K=N=>{const ee=w(N);return ee.length===0?N.lastActivity?new Date(N.lastActivity):N.createdAt?new Date(N.createdAt):new Date(0):ee.reduce((Y,U)=>{const M=new Date(U.lastActivity);return M>Y?M:Y},new Date(0))},he=[...t].sort((N,ee)=>{const we=q(N.name),Y=q(ee.name);if(we&&!Y)return-1;if(!we&&Y)return 1;if(ue==="date")return K(ee)-K(N);{const U=N.displayName||N.name,M=ee.displayName||ee.name;return U.localeCompare(M)}}),ve=N=>{y(N.name),z(N.displayName)},Ae=()=>{y(null),z("")},Ue=async N=>{try{(await ke.renameProject(N,P)).ok?window.refreshProjects?window.refreshProjects():window.location.reload():console.error("Failed to rename project")}catch(ee){console.error("Error renaming project:",ee)}y(null),z("")},V=async(N,ee,we="claude")=>{if(await O("确定要删除此会话吗?此操作不可撤销。",{title:"删除会话",variant:"danger",confirmText:"确认删除"}))try{console.log("[Sidebar] Deleting session:",{projectName:N,sessionId:ee,provider:we});const U=await ke.deleteSession(N,ee);if(console.log("[Sidebar] Delete response:",{ok:U.ok,status:U.status}),U.ok)console.log("[Sidebar] Session deleted successfully, calling callback"),i?i(ee):console.warn("[Sidebar] No onSessionDelete callback provided");else{const M=await U.text();console.error("[Sidebar] Failed to delete session:",{status:U.status,error:M}),E("删除会话失败,请重试。",{variant:"error"})}}catch(U){console.error("[Sidebar] Error deleting session:",U),E("删除会话出错,请重试。",{variant:"error"})}},oe=async(N,ee)=>{if(await O(`确定要删除项目 "${ee||N}" 吗?`,{title:"删除项目",subtitle:"此操作不可撤销",detail:"将同时删除:所有会话记录(JSONL 文件)和项目文件夹及其所有内容。",variant:"danger",confirmText:"确认删除"}))try{const Y=await ke.deleteProject(N,!0);if(Y.ok)d&&d(N);else{const U=await Y.json();console.error("Failed to delete project"),E(U.error||"删除项目失败,请重试。",{variant:"error"})}}catch(Y){console.error("Error deleting project:",Y),E("删除项目出错,请重试。",{variant:"error"})}},Ie=async N=>{if(!(!(N.sessionMeta?.hasMore!==!1)||me[N.name])){se(we=>({...we,[N.name]:!0}));try{const we=(N.sessions?.length||0)+(te[N.name]?.length||0),Y=await ke.sessions(N.name,5,we);if(Y.ok){const U=await Y.json();de(M=>({...M,[N.name]:[...M[N.name]||[],...U.sessions]})),U.hasMore===!1&&(N.sessionMeta={...N.sessionMeta,hasMore:!1})}}catch(we){console.error("Error loading more sessions:",we)}finally{se(we=>({...we,[N.name]:!1}))}}},Te=he.filter(N=>{if(!We.trim())return!0;const ee=We.toLowerCase(),we=(N.displayName||N.name).toLowerCase(),Y=N.name.toLowerCase();return we.includes(ee)||Y.includes(ee)}),Ce=N=>{o(N)};return e.jsxs(e.Fragment,{children:[L&&aa.createPortal(e.jsx(lo,{onClose:()=>$(!1),onProjectCreated:N=>{window.refreshProjects?window.refreshProjects():window.location.reload()}}),document.body),e.jsxs("div",{className:"h-full flex flex-col bg-card md:select-none",style:b&&j?{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 助手"})]})]}),f&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200",onClick:f,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:b&&j?{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()=>{pe(!0);try{await h()}finally{pe(!1)}},disabled:G,children:e.jsx(_t,{className:`w-4 h-4 text-foreground ${G?"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:()=>$(!0),children:e.jsx(Gr,{className:"w-4 h-4"})})]})]})})]}),!x&&!j&&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(W,{variant:"default",size:"sm",className:"flex-1 h-8 text-xs bg-primary hover:bg-primary/90 transition-all duration-200",onClick:()=>$(!0),title:"创建新项目",children:[e.jsx(Gr,{className:"w-3.5 h-3.5 mr-1.5"}),"新建项目"]}),e.jsx(W,{variant:"outline",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200 group",onClick:async()=>{pe(!0);try{await h()}finally{pe(!1)}},disabled:G,title:"刷新项目和会话 (Ctrl+R)",children:e.jsx(_t,{className:`w-3.5 h-3.5 ${G?"animate-spin":""} group-hover:rotate-180 transition-transform duration-300`})})]})}),t.length>0&&!x&&e.jsx("div",{className:"px-3 md:px-4 py-2 border-b border-border",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ft,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索项目...",value:We,onChange:N=>De(N.target.value),className:"pl-9 h-9 text-sm bg-muted/50 border-0 focus:bg-background focus:ring-1 focus:ring-primary/20"}),We&&e.jsx("button",{onClick:()=>De(""),className:"absolute right-2 top-1/2 transform -translate-y-1/2 p-1 hover:bg-accent rounded",children:e.jsx(He,{className:"w-3 h-3 text-muted-foreground"})})]})}),e.jsx(xs,{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:x?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:"正在获取您的项目和会话"})]}):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(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:"请先创建一个项目,开始与 AgentHub 进行交流"})]}):Te.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(Ft,{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:"尝试调整搜索条件"})]}):Te.map(N=>{const ee=g.has(N.name),we=s?.name===N.name,Y=q(N.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:Ve("p-3 mx-3 my-1 rounded-lg bg-card border border-border/50 active:scale-[0.98] transition-all duration-150",we&&"bg-primary/5 border-primary/20",Y&&!we&&"bg-yellow-50/50 dark:bg-yellow-900/5 border-yellow-200/30 dark:border-yellow-800/30"),onClick:()=>{_e(N.name)},onTouchEnd:Fe(()=>_e(N.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:Ve("w-8 h-8 rounded-lg flex items-center justify-center transition-colors",ee?"bg-primary/10":"bg-muted"),children:ee?e.jsx(At,{className:"w-4 h-4 text-primary"}):e.jsx(pt,{className:"w-4 h-4 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0 flex-1",children:u===N.name?e.jsx("input",{type:"text",value:P,onChange:U=>z(U.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:U=>U.stopPropagation(),onKeyDown:U=>{U.key==="Enter"&&Ue(N.name),U.key==="Escape"&&Ae()},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:N.displayName})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(()=>{const U=w(N).length;return`${N.sessionMeta?.hasMore!==!1&&U>=5?`${U}+`:U} 会话`})()})]})})]}),e.jsx("div",{className:"flex items-center gap-1",children:u===N.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:U=>{U.stopPropagation(),Ue(N.name)},children:e.jsx(wr,{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:U=>{U.stopPropagation(),Ae()},children:e.jsx(He,{className:"w-4 h-4 text-white"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:Ve("w-8 h-8 rounded-lg flex items-center justify-center active:scale-90 transition-all duration-150 border",Y?"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:U=>{U.stopPropagation(),J(N.name)},onTouchEnd:Fe(()=>J(N.name)),title:Y?"从收藏中移除":"添加到收藏",children:e.jsx(Rs,{className:Ve("w-4 h-4 transition-colors",Y?"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:U=>{U.stopPropagation(),oe(N.name,N.displayName)},onTouchEnd:Fe(()=>oe(N.name,N.displayName)),children:e.jsx(tt,{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:U=>{U.stopPropagation(),ve(N)},onTouchEnd:Fe(()=>ve(N)),children:e.jsx(cr,{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:ee?e.jsx(Fr,{className:"w-3 h-3 text-muted-foreground"}):e.jsx(Vt,{className:"w-3 h-3 text-muted-foreground"})})]})})]})})}),e.jsxs(W,{variant:"ghost",className:Ve("hidden md:flex w-full justify-between p-2 h-auto font-normal hover:bg-accent/50",we&&"bg-accent text-accent-foreground",Y&&!we&&"bg-yellow-50/50 dark:bg-yellow-900/10 hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20"),onClick:()=>{s?.name!==N.name&&Ce(N),_e(N.name)},onTouchEnd:Fe(()=>{s?.name!==N.name&&Ce(N),_e(N.name)}),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[ee?e.jsx(At,{className:"w-4 h-4 text-primary flex-shrink-0"}):e.jsx(pt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"min-w-0 flex-1 text-left",children:u===N.name?e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{type:"text",value:P,onChange:U=>z(U.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:U=>{U.key==="Enter"&&Ue(N.name),U.key==="Escape"&&Ae()}}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",title:N.fullPath,children:N.fullPath})]}):e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold truncate text-foreground",title:N.displayName,children:N.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[(()=>{const U=w(N).length;return N.sessionMeta?.hasMore!==!1&&U>=5?`${U}+`:U})(),N.fullPath!==N.displayName&&e.jsxs("span",{className:"ml-1 opacity-60",title:N.fullPath,children:["• ",N.fullPath.length>25?"..."+N.fullPath.slice(-22):N.fullPath]})]})]})})]}),e.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:u===N.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:U=>{U.stopPropagation(),Ue(N.name)},children:e.jsx(wr,{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:U=>{U.stopPropagation(),Ae()},children:e.jsx(He,{className:"w-3 h-3"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:Ve("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",Y?"hover:bg-yellow-50 dark:hover:bg-yellow-900/20 opacity-100":"hover:bg-accent"),onClick:U=>{U.stopPropagation(),J(N.name)},title:Y?"从收藏中移除":"添加到收藏",children:e.jsx(Rs,{className:Ve("w-3 h-3 transition-colors",Y?"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:U=>{U.stopPropagation(),ve(N)},title:"重命名项目 (F2)",children:e.jsx(cr,{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:U=>{U.stopPropagation(),oe(N.name,N.displayName)},title:"删除项目",children:e.jsx(tt,{className:"w-3 h-3 text-red-600 dark:text-red-400"})}),ee?e.jsx(Fr,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"}):e.jsx(Vt,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"})]})})]})]}),ee&&e.jsxs("div",{className:"ml-3 space-y-1 border-l border-border pl-3",children:[_.has(N.name)?w(N).length===0&&!me[N.name]?e.jsx("div",{className:"py-2 px-3 text-left",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"还没有会话"})}):w(N).map(U=>{const M=new Date(U.lastActivity),B=Math.floor((ae-M)/(1e3*60))<10,re=U.summary||"新会话",ie=U.lastActivity,ye=U.messageCount||0;return e.jsxs("div",{className:"group relative",children:[B&&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:Ve("p-2 mx-3 my-0.5 rounded-md bg-card border active:scale-[0.98] transition-all duration-150 relative",a?.id===U.id?"bg-primary/5 border-primary/20":B?"border-green-500/30 bg-green-50/5 dark:bg-green-900/5":"border-border/30"),onClick:()=>{Ce(N),ze(U,N.name)},onTouchEnd:Fe(()=>{Ce(N),ze(U,N.name)}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:Ve("w-5 h-5 rounded-md flex items-center justify-center flex-shrink-0",a?.id===U.id?"bg-primary/10":"bg-muted/50"),children:e.jsx(gt,{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:re}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Vr,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:As(ie,ae)}),ye>0&&e.jsx(Qe,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:ye}),e.jsx("span",{className:"ml-1 opacity-70",children:e.jsx(gt,{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:xe=>{xe.stopPropagation(),V(N.name,U.id)},onTouchEnd:Fe(()=>V(N.name,U.id)),children:e.jsx(tt,{className:"w-2.5 h-2.5 text-red-600 dark:text-red-400"})})]})})}),e.jsxs("div",{className:"hidden md:block",children:[e.jsx(W,{variant:"ghost",className:Ve("w-full justify-start p-2 h-auto font-normal text-left hover:bg-accent/50 transition-colors duration-200",a?.id===U.id&&"bg-accent text-accent-foreground"),onClick:()=>ze(U,N.name),onTouchEnd:Fe(()=>ze(U,N.name)),children:e.jsxs("div",{className:"flex items-start gap-2 min-w-0 w-full",children:[e.jsx(gt,{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:re}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Vr,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:As(ie,ae)}),ye>0&&e.jsx(Qe,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:ye}),e.jsx("span",{className:"ml-1 opacity-70",children:e.jsx(gt,{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:Pe===U.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:Me,onChange:xe=>Ne(xe.target.value),onKeyDown:xe=>{xe.stopPropagation(),xe.key==="Enter"?updateSessionSummary(N.name,U.id,Me):xe.key==="Escape"&&(Ee(null),Ne(""))},onClick:xe=>xe.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:xe=>{xe.stopPropagation(),updateSessionSummary(N.name,U.id,Me)},title:"Save",children:e.jsx(wr,{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:xe=>{xe.stopPropagation(),Ee(null),Ne("")},title:"Cancel",children:e.jsx(He,{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:xe=>{xe.stopPropagation(),Ee(U.id),Ne(U.summary||"新会话")},title:"手动编辑会话名称",children:e.jsx(yn,{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:xe=>{xe.stopPropagation(),V(N.name,U.id)},title:"永久删除此会话",children:e.jsx(tt,{className:"w-3 h-3 text-red-600 dark:text-red-400"})})]})})]})]},U.id)}):Array.from({length:3}).map((U,M)=>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+M*15}%`}}),e.jsx("div",{className:"h-2 bg-muted rounded animate-pulse w-1/2"})]})]})},M)),w(N).length>0&&N.sessionMeta?.hasMore!==!1&&e.jsx(W,{variant:"ghost",size:"sm",className:"w-full justify-center gap-2 mt-2 text-muted-foreground",onClick:()=>Ie(N),disabled:me[N.name],children:me[N.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(Fr,{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:()=>{Ce(N),l(N)},children:[e.jsx(lt,{className:"w-3 h-3"}),"新会话"]})}),e.jsxs(W,{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(N),children:[e.jsx(lt,{className:"w-3 h-3"}),"新会话"]})]})]},N.name)})})}),e.jsxs("div",{className:"md:p-2 md:border-t md:border-border flex-shrink-0",children:[e.jsxs("div",{className:"md:hidden p-4 pb-20 border-t border-border/50 space-y-2",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:m,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx(Tt,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"设置"})]}),R&&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:v,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx(kt,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"管理"})]})]}),e.jsxs(W,{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:m,children:[e.jsx(Tt,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"设置"})]}),R&&e.jsxs(W,{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:v,children:[e.jsx(kt,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"管理"})]})]})]})]})}const co={'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 Br={exports:{}},Ur,_s;function mo(){if(_s)return Ur;_s=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Ur=t,Ur}var Hr,Fs;function uo(){if(Fs)return Hr;Fs=1;var t=mo();function s(){}function a(){}return a.resetWarningCache=s,Hr=function(){function o(i,d,x,h,m,v){if(v!==t){var b=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 b.name="Invariant Violation",b}}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},Hr}var Ws;function po(){return Ws||(Ws=1,Br.exports=uo()()),Br.exports}var xo=po();const Be=ds(xo);function Wt(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(m){try{h(o.next(m))}catch(v){i(v)}}function x(m){try{h(o.throw(m))}catch(v){i(v)}}function h(m){m.done?l(m.value):n(m.value).then(d,x)}h((o=o.apply(t,s||[])).next())})}const ho=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 Yt(t,s,a){const o=go(t),{webkitRelativePath:n}=t,l=typeof s=="string"?s:typeof n=="string"&&n.length>0?n:`./${t.name}`;return typeof o.path!="string"&&Bs(o,"path",l),Bs(o,"relativePath",l),o}function go(t){const{name:s}=t;if(s&&s.lastIndexOf(".")!==-1&&!t.type){const o=s.split(".").pop().toLowerCase(),n=ho.get(o);n&&Object.defineProperty(t,"type",{value:n,writable:!1,configurable:!1,enumerable:!0})}return t}function Bs(t,s,a){Object.defineProperty(t,s,{value:a,writable:!1,configurable:!1,enumerable:!0})}const fo=[".DS_Store","Thumbs.db"];function bo(t){return Wt(this,void 0,void 0,function*(){return Cr(t)&&vo(t.dataTransfer)?ko(t.dataTransfer,t.type):yo(t)?jo(t):Array.isArray(t)&&t.every(s=>"getFile"in s&&typeof s.getFile=="function")?wo(t):[]})}function vo(t){return Cr(t)}function yo(t){return Cr(t)&&Cr(t.target)}function Cr(t){return typeof t=="object"&&t!==null}function jo(t){return ts(t.target.files).map(s=>Yt(s))}function wo(t){return Wt(this,void 0,void 0,function*(){return(yield Promise.all(t.map(a=>a.getFile()))).map(a=>Yt(a))})}function ko(t,s){return Wt(this,void 0,void 0,function*(){if(t.items){const a=ts(t.items).filter(n=>n.kind==="file");if(s!=="drop")return a;const o=yield Promise.all(a.map(No));return Us(ya(o))}return Us(ts(t.files).map(a=>Yt(a)))})}function Us(t){return t.filter(s=>fo.indexOf(s.name)===-1)}function ts(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 No(t){if(typeof t.webkitGetAsEntry!="function")return Hs(t);const s=t.webkitGetAsEntry();return s&&s.isDirectory?ja(s):Hs(t,s)}function ya(t){return t.reduce((s,a)=>[...s,...Array.isArray(a)?ya(a):[a]],[])}function Hs(t,s){return Wt(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,Yt(i)}}const o=t.getAsFile();if(!o)throw new Error(`${t} is not a File`);return Yt(o,(a=s?.fullPath)!==null&&a!==void 0?a:void 0)})}function So(t){return Wt(this,void 0,void 0,function*(){return t.isDirectory?ja(t):Co(t)})}function ja(t){const s=t.createReader();return new Promise((a,o)=>{const n=[];function l(){s.readEntries(i=>Wt(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 Co(t){return Wt(this,void 0,void 0,function*(){return new Promise((s,a)=>{t.file(o=>{const n=Yt(o,t.fullPath);s(n)},o=>{a(o)})})})}var br={},qs;function Eo(){return qs||(qs=1,br.__esModule=!0,br.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}),br}var Mo=Eo();const qr=ds(Mo);function Js(t){return Io(t)||Do(t)||ka(t)||Lo()}function Lo(){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 Do(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Io(t){if(Array.isArray(t))return rs(t)}function Ks(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 Gs(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Ks(Object(a),!0).forEach(function(o){wa(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Ks(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function wa(t,s,a){return s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function dr(t,s){return Po(t)||Ro(t,s)||ka(t,s)||To()}function To(){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 ka(t,s){if(t){if(typeof t=="string")return rs(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 rs(t,s)}}function rs(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 Ro(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(x){l=!0,d=x}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 $o=typeof qr=="function"?qr:qr.default,zo="file-invalid-type",Ao="file-too-large",Oo="file-too-small",_o="too-many-files",Fo=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:zo,message:"File type must be ".concat(o)}},Vs=function(s){return{code:Ao,message:"File is larger than ".concat(s," ").concat(s===1?"byte":"bytes")}},Ys=function(s){return{code:Oo,message:"File is smaller than ".concat(s," ").concat(s===1?"byte":"bytes")}},Wo={code:_o,message:"Too many files"};function Na(t,s){var a=t.type==="application/x-moz-file"||$o(t,s);return[a,a?null:Fo(s)]}function Sa(t,s,a){if(zt(t.size))if(zt(s)&&zt(a)){if(t.size>a)return[!1,Vs(a)];if(t.size<s)return[!1,Ys(s)]}else{if(zt(s)&&t.size<s)return[!1,Ys(s)];if(zt(a)&&t.size>a)return[!1,Vs(a)]}return[!0,null]}function zt(t){return t!=null}function Bo(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(x){var h=Na(x,a),m=dr(h,1),v=m[0],b=Sa(x,o,n),j=dr(b,1),f=j[0],E=d?d(x):null;return v&&f&&!E})}function Er(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function vr(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 Qs(t){t.preventDefault()}function Uo(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function Ho(t){return t.indexOf("Edge/")!==-1}function qo(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return Uo(t)||Ho(t)}function ht(){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!Er(o)&&d&&d.apply(void 0,[o].concat(l)),Er(o)})}}function Jo(){return"showOpenFilePicker"in window}function Ko(t){if(zt(t)){var s=Object.entries(t).filter(function(a){var o=dr(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(Ea))&&(console.warn('Skipped "'.concat(n,'" because an invalid file extension was provided.')),i=!1),i}).reduce(function(a,o){var n=dr(o,2),l=n[0],i=n[1];return Gs(Gs({},a),{},wa({},l,i))},{});return[{description:"Files",accept:s}]}return t}function Go(t){if(zt(t))return Object.entries(t).reduce(function(s,a){var o=dr(a,2),n=o[0],l=o[1];return[].concat(Js(s),[n],Js(l))},[]).filter(function(s){return Ca(s)||Ea(s)}).join(",")}function Vo(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function Yo(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 Ea(t){return/^.*\.[\w]+$/.test(t)}var Qo=["children"],Zo=["open"],Xo=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],ei=["refKey","onChange","onClick"];function ti(t){return ai(t)||si(t)||Ma(t)||ri()}function ri(){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 si(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function ai(t){if(Array.isArray(t))return ss(t)}function Jr(t,s){return ii(t)||oi(t,s)||Ma(t,s)||ni()}function ni(){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 ss(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 ss(t,s)}}function ss(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 oi(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(x){l=!0,d=x}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw d}}return o}}function ii(t){if(Array.isArray(t))return t}function Zs(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 Ke(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Zs(Object(a),!0).forEach(function(o){as(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Zs(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function as(t,s,a){return s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function Mr(t,s){if(t==null)return{};var a=li(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 li(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 hs=r.forwardRef(function(t,s){var a=t.children,o=Mr(t,Qo),n=gs(o),l=n.open,i=Mr(n,Zo);return r.useImperativeHandle(s,function(){return{open:l}},[l]),it.createElement(r.Fragment,null,a(Ke(Ke({},i),{},{open:l})))});hs.displayName="Dropzone";var La={disabled:!1,getFilesFromEvent:bo,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};hs.defaultProps=La;hs.propTypes={children:Be.func,accept:Be.objectOf(Be.arrayOf(Be.string)),multiple:Be.bool,preventDropOnDocument:Be.bool,noClick:Be.bool,noKeyboard:Be.bool,noDrag:Be.bool,noDragEventsBubbling:Be.bool,minSize:Be.number,maxSize:Be.number,maxFiles:Be.number,disabled:Be.bool,getFilesFromEvent:Be.func,onFileDialogCancel:Be.func,onFileDialogOpen:Be.func,useFsAccessApi:Be.bool,autoFocus:Be.bool,onDragEnter:Be.func,onDragLeave:Be.func,onDragOver:Be.func,onDrop:Be.func,onDropAccepted:Be.func,onDropRejected:Be.func,onError:Be.func,validator:Be.func};var ns={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function gs(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=Ke(Ke({},La),t),a=s.accept,o=s.disabled,n=s.getFilesFromEvent,l=s.maxSize,i=s.minSize,d=s.multiple,x=s.maxFiles,h=s.onDragEnter,m=s.onDragLeave,v=s.onDragOver,b=s.onDrop,j=s.onDropAccepted,f=s.onDropRejected,E=s.onFileDialogCancel,O=s.onFileDialogOpen,T=s.useFsAccessApi,R=s.autoFocus,g=s.preventDropOnDocument,p=s.noClick,u=s.noKeyboard,y=s.noDrag,L=s.noDragEventsBubbling,$=s.onError,P=s.validator,z=r.useMemo(function(){return Go(a)},[a]),me=r.useMemo(function(){return Ko(a)},[a]),se=r.useMemo(function(){return typeof O=="function"?O:Xs},[O]),te=r.useMemo(function(){return typeof E=="function"?E:Xs},[E]),de=r.useRef(null),_=r.useRef(null),A=r.useReducer(ci,ns),ae=Jr(A,2),fe=ae[0],ue=ae[1],X=fe.isFocused,G=fe.isFileDialogActive,pe=r.useRef(typeof window<"u"&&window.isSecureContext&&T&&Jo()),Pe=function(){!pe.current&&G&&setTimeout(function(){if(_.current){var oe=_.current.files;oe.length||(ue({type:"closeDialog"}),te())}},300)};r.useEffect(function(){return window.addEventListener("focus",Pe,!1),function(){window.removeEventListener("focus",Pe,!1)}},[_,G,te,pe]);var Ee=r.useRef([]),Me=function(oe){de.current&&de.current.contains(oe.target)||(oe.preventDefault(),Ee.current=[])};r.useEffect(function(){return g&&(document.addEventListener("dragover",Qs,!1),document.addEventListener("drop",Me,!1)),function(){g&&(document.removeEventListener("dragover",Qs),document.removeEventListener("drop",Me))}},[de,g]),r.useEffect(function(){return!o&&R&&de.current&&de.current.focus(),function(){}},[de,R,o]);var Ne=r.useCallback(function(V){$?$(V):console.error(V)},[$]),qe=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V),Ee.current=[].concat(ti(Ee.current),[V.target]),vr(V)&&Promise.resolve(n(V)).then(function(oe){if(!(Er(V)&&!L)){var Ie=oe.length,Te=Ie>0&&Bo({files:oe,accept:z,minSize:i,maxSize:l,multiple:d,maxFiles:x,validator:P}),Ce=Ie>0&&!Te;ue({isDragAccept:Te,isDragReject:Ce,isDragActive:!0,type:"setDraggedFiles"}),h&&h(V)}}).catch(function(oe){return Ne(oe)})},[n,h,Ne,L,z,i,l,d,x,P]),Ge=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V);var oe=vr(V);if(oe&&V.dataTransfer)try{V.dataTransfer.dropEffect="copy"}catch{}return oe&&v&&v(V),!1},[v,L]),We=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V);var oe=Ee.current.filter(function(Te){return de.current&&de.current.contains(Te)}),Ie=oe.indexOf(V.target);Ie!==-1&&oe.splice(Ie,1),Ee.current=oe,!(oe.length>0)&&(ue({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),vr(V)&&m&&m(V))},[de,m,L]),De=r.useCallback(function(V,oe){var Ie=[],Te=[];V.forEach(function(Ce){var N=Na(Ce,z),ee=Jr(N,2),we=ee[0],Y=ee[1],U=Sa(Ce,i,l),M=Jr(U,2),ne=M[0],B=M[1],re=P?P(Ce):null;if(we&&ne&&!re)Ie.push(Ce);else{var ie=[Y,B];re&&(ie=ie.concat(re)),Te.push({file:Ce,errors:ie.filter(function(ye){return ye})})}}),(!d&&Ie.length>1||d&&x>=1&&Ie.length>x)&&(Ie.forEach(function(Ce){Te.push({file:Ce,errors:[Wo]})}),Ie.splice(0)),ue({acceptedFiles:Ie,fileRejections:Te,isDragReject:Te.length>0,type:"setFiles"}),b&&b(Ie,Te,oe),Te.length>0&&f&&f(Te,oe),Ie.length>0&&j&&j(Ie,oe)},[ue,d,z,i,l,x,b,j,f,P]),je=r.useCallback(function(V){V.preventDefault(),V.persist(),he(V),Ee.current=[],vr(V)&&Promise.resolve(n(V)).then(function(oe){Er(V)&&!L||De(oe,V)}).catch(function(oe){return Ne(oe)}),ue({type:"reset"})},[n,De,Ne,L]),$e=r.useCallback(function(){if(pe.current){ue({type:"openDialog"}),se();var V={multiple:d,types:me};window.showOpenFilePicker(V).then(function(oe){return n(oe)}).then(function(oe){De(oe,null),ue({type:"closeDialog"})}).catch(function(oe){Vo(oe)?(te(oe),ue({type:"closeDialog"})):Yo(oe)?(pe.current=!1,_.current?(_.current.value=null,_.current.click()):Ne(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."))):Ne(oe)});return}_.current&&(ue({type:"openDialog"}),se(),_.current.value=null,_.current.click())},[ue,se,te,T,De,Ne,me,d]),Fe=r.useCallback(function(V){!de.current||!de.current.isEqualNode(V.target)||(V.key===" "||V.key==="Enter"||V.keyCode===32||V.keyCode===13)&&(V.preventDefault(),$e())},[de,$e]),_e=r.useCallback(function(){ue({type:"focus"})},[]),ze=r.useCallback(function(){ue({type:"blur"})},[]),J=r.useCallback(function(){p||(qo()?setTimeout($e,0):$e())},[p,$e]),q=function(oe){return o?null:oe},w=function(oe){return u?null:q(oe)},K=function(oe){return y?null:q(oe)},he=function(oe){L&&oe.stopPropagation()},ve=r.useMemo(function(){return function(){var V=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},oe=V.refKey,Ie=oe===void 0?"ref":oe,Te=V.role,Ce=V.onKeyDown,N=V.onFocus,ee=V.onBlur,we=V.onClick,Y=V.onDragEnter,U=V.onDragOver,M=V.onDragLeave,ne=V.onDrop,B=Mr(V,Xo);return Ke(Ke(as({onKeyDown:w(ht(Ce,Fe)),onFocus:w(ht(N,_e)),onBlur:w(ht(ee,ze)),onClick:q(ht(we,J)),onDragEnter:K(ht(Y,qe)),onDragOver:K(ht(U,Ge)),onDragLeave:K(ht(M,We)),onDrop:K(ht(ne,je)),role:typeof Te=="string"&&Te!==""?Te:"presentation"},Ie,de),!o&&!u?{tabIndex:0}:{}),B)}},[de,Fe,_e,ze,J,qe,Ge,We,je,u,y,o]),Ae=r.useCallback(function(V){V.stopPropagation()},[]),Ue=r.useMemo(function(){return function(){var V=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},oe=V.refKey,Ie=oe===void 0?"ref":oe,Te=V.onChange,Ce=V.onClick,N=Mr(V,ei),ee=as({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:q(ht(Te,je)),onClick:q(ht(Ce,Ae)),tabIndex:-1},Ie,_);return Ke(Ke({},ee),N)}},[_,a,d,je,o]);return Ke(Ke({},fe),{},{isFocused:X&&!o,getRootProps:ve,getInputProps:Ue,rootRef:de,inputRef:_,open:q($e)})}function ci(t,s){switch(s.type){case"focus":return Ke(Ke({},t),{},{isFocused:!0});case"blur":return Ke(Ke({},t),{},{isFocused:!1});case"openDialog":return Ke(Ke({},ns),{},{isFileDialogActive:!0});case"closeDialog":return Ke(Ke({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Ke(Ke({},t),{},{isDragActive:s.isDragActive,isDragAccept:s.isDragAccept,isDragReject:s.isDragReject});case"setFiles":return Ke(Ke({},t),{},{acceptedFiles:s.acceptedFiles,fileRejections:s.fileRejections,isDragReject:s.isDragReject});case"reset":return Ke({},ns);default:return t}}function Xs(){}const Kr=({todos:t,isResult:s=!1})=>{if(!t||!Array.isArray(t))return null;const a=l=>{switch(l){case"completed":return e.jsx(wn,{className:"w-4 h-4 text-green-500 dark:text-green-400"});case"in_progress":return e.jsx(Vr,{className:"w-4 h-4 text-blue-500 dark:text-blue-400"});case"pending":default:return e.jsx(jn,{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(Qe,{variant:"outline",className:`text-xs px-2 py-0.5 ${n(l.priority)}`,children:l.priority}),e.jsx(Qe,{variant:"outline",className:`text-xs px-2 py-0.5 ${o(l.status)}`,children:l.status.replace("_"," ")})]})]})})]},l.id||`todo-${i}`))]})};function di({status:t,onAbort:s,isLoading:a,provider:o="claude"}){const[n,l]=r.useState(0),[i,d]=r.useState(0),[x,h]=r.useState(0);if(r.useEffect(()=>{if(!a){l(0),h(0);return}const T=Date.now(),R=30+Math.random()*20,g=setInterval(()=>{const p=Math.floor((Date.now()-T)/1e3);l(p),h(Math.floor(p*R))},1e3);return()=>clearInterval(g)},[a]),r.useEffect(()=>{if(!a)return;const T=setInterval(()=>{d(R=>(R+1)%4)},500);return()=>clearInterval(T)},[a]),!a)return null;const m=["思考中","处理中","分析中","工作中","计算中","推理中"],v=Math.floor(n/3)%m.length,b=t?.text||m[v],j=t?.tokens||x,f=t?.can_interrupt!==!1,O=["✻","✹","✸","✶"][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:Ve("text-base sm:text-xl transition-all duration-500 flex-shrink-0",i%2===0?"text-blue-400 scale-110":"text-blue-300"),children:O}),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:[b,"..."]}),e.jsxs("span",{className:"text-gray-400 text-xs sm:text-sm flex-shrink-0",children:["(",n,"s)"]}),j>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:["⚒ ",j.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 停止"})]})})]})}),f&&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 mi(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 ke.transcribe(a);if(!i.ok){const x=await i.json().catch(()=>({}));throw new Error(x.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 ui({onTranscript:t,className:s=""}){const[a,o]=r.useState("idle"),[n,l]=r.useState(null),[i,d]=r.useState(!0),x=r.useRef(null),h=r.useRef(null),m=r.useRef([]),v=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 b=async()=>{try{if(console.log("Starting recording..."),l(null),m.current=[],!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)throw new Error("Microphone access not available. Please use HTTPS or a supported browser.");const g=await navigator.mediaDevices.getUserMedia({audio:!0});h.current=g;const p=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",u=new MediaRecorder(g,{mimeType:p});x.current=u,u.ondataavailable=y=>{y.data.size>0&&m.current.push(y.data)},u.onstop=async()=>{console.log("Recording stopped, creating blob...");const y=new Blob(m.current,{type:p});h.current&&(h.current.getTracks().forEach(z=>z.stop()),h.current=null),o("transcribing");const L=window.localStorage.getItem("whisperMode")||"default",$=L==="prompt"||L==="vibe"||L==="instructions"||L==="architect";let P;$&&(P=setTimeout(()=>{o("processing")},2e3));try{const z=await mi(y);z&&t&&t(z)}catch(z){console.error("Transcription error:",z),l(z.message)}finally{P&&clearTimeout(P),o("idle")}},u.start(),o("recording"),console.log("Recording started successfully")}catch(g){console.error("Failed to start recording:",g);let p="Microphone access failed";g.name==="NotAllowedError"?p="Microphone access denied. Please allow microphone permissions.":g.name==="NotFoundError"?p="No microphone found. Please check your audio devices.":g.name==="NotSupportedError"?p="Microphone not supported by this browser.":g.name==="NotReadableError"?p="Microphone is being used by another application.":g.message.includes("HTTPS")&&(p=g.message),l(p),o("idle")}},j=()=>{console.log("Stopping recording..."),x.current&&x.current.state==="recording"?x.current.stop():(console.log("Recorder not in recording state, forcing cleanup"),h.current&&(h.current.getTracks().forEach(g=>g.stop()),h.current=null),o("idle"))},f=g=>{if(g&&(g.preventDefault(),g.stopPropagation()),!i)return;const p=Date.now();if(p-v.current<300){console.log("Ignoring rapid tap");return}v.current=p,console.log("Button clicked, current state:",a),a==="idle"?b():a==="recording"&&j()};r.useEffect(()=>()=>{h.current&&h.current.getTracks().forEach(g=>g.stop())},[]);const E=()=>{if(!i)return{icon:e.jsx(kr,{className:"w-5 h-5"}),className:"bg-gray-400 cursor-not-allowed",disabled:!0};switch(a){case"recording":return{icon:e.jsx(kr,{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(Dt,{className:"w-5 h-5 animate-spin"}),className:"bg-blue-500 hover:bg-blue-600",disabled:!0};case"processing":return{icon:e.jsx(la,{className:"w-5 h-5 animate-pulse"}),className:"bg-purple-500 hover:bg-purple-600",disabled:!0};default:return{icon:e.jsx(kr,{className:"w-5 h-5"}),className:"bg-gray-700 hover:bg-gray-600",disabled:!1}}},{icon:O,className:T,disabled:R}=E();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
6
  flex items-center justify-center
7
7
  w-12 h-12 rounded-full
8
8
  text-white transition-all duration-200
@@ -49,32 +49,32 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
49
49
  color: #9ca3af !important;
50
50
  }
51
51
  }
52
- `})]})},vr={OPTIONS:[{value:"sonnet",label:"Sonnet"},{value:"opus",label:"Opus"},{value:"haiku",label:"Haiku"}],DEFAULT:"sonnet"};function Jt(t){return t&&t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&amp;/g,"&")}function xi(t){if(!t||typeof t!="string")return t;try{return t.replace(/```\s*([^\n\r]+?)\s*```/g,"`$1`")}catch{return t}}function yr(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 Kt=({children:t,className:s})=>{const a=xi(String(t??"")),o=r.useMemo(()=>[Un,Hn],[]),n=r.useMemo(()=>[qn],[]);return e.jsx("div",{className:s,children:e.jsx(Jn,{remarkPlugins:o,rehypePlugins:n,components:fi,children:a})})};function ns(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?"+":"-",x=Math.abs(i),h=Math.floor(x/60),m=x%60,v=`GMT${d}${h}${m?":"+String(m).padStart(2,"0"):""}`,f=((Intl.DateTimeFormat().resolvedOptions().timeZone||"").split("/").pop()||"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,R=>R.toUpperCase()),E=f?`${v} (${f})`:v,O=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],T=`${n.getDate()} ${O[n.getMonth()]} ${n.getFullYear()}`;return`Claude usage limit reached. Your limit will reset at **${l} ${E}** - ${T}`})}catch{return t}}const tt={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 x=d.slice(-10);localStorage.setItem(t,JSON.stringify(x)),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)}}},Ma="claude-settings";function gs(){const t=tt.getItem(Ma);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 os(t,s){if(!t)return null;if(t!=="Bash")return t;const a=to(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 Xs(t){if(t==null)return"";if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function hi(t,s){if(s!=="claude"||!t?.toolResult?.isError)return null;const a=t?.toolName,o=os(a,t.toolInput);if(!o)return null;const l=gs().allowedTools.includes(o);return{toolName:a,entry:o,isAllowed:l}}function gi(t){if(!t)return{success:!1};const s=gs(),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 tt.setItem(Ma,JSON.stringify(l)),{success:!0,alreadyAllowed:a,updatedSettings:l}}const fi={code:({node:t,inline:s,className:a,children:o,...n})=>{const[l,i]=it.useState(!1),d=Array.isArray(o)?o.join(""):String(o??""),x=/[\r\n]/.test(d);if(s||t&&t.type==="inlineCode"||!x)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 v=/language-(\w+)/.exec(a||""),b=v?v[1]:"text",j=d,f=()=>{const E=()=>{i(!0),setTimeout(()=>i(!1),1500)};try{if(navigator&&navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(j).then(E).catch(()=>{const O=document.createElement("textarea");O.value=j,O.style.position="fixed",O.style.opacity="0",document.body.appendChild(O),O.select();try{document.execCommand("copy")}catch{}document.body.removeChild(O),E()});else{const O=document.createElement("textarea");O.value=j,O.style.position="fixed",O.style.opacity="0",document.body.appendChild(O),O.select();try{document.execCommand("copy")}catch{}document.body.removeChild(O),E()}}catch{}};return e.jsxs("div",{className:"relative group my-2",children:[b&&b!=="text"&&e.jsx("div",{className:"absolute top-2 left-3 z-10 text-xs text-gray-400 font-medium uppercase",children:b}),e.jsx("button",{type:"button",onClick:f,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(Kn,{language:b,style:co,customStyle:{margin:0,borderRadius:"0.5rem",fontSize:"0.875rem",padding:b&&b!=="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 bi({request:t,onSubmit:s,onSkip:a}){const o=t.input?.questions||[],[n,l]=it.useState(()=>Object.fromEntries(o.map(h=>[h.question,[]]))),i=(h,m,v)=>{l(b=>{const j=b[h]||[];return v?{...b,[h]:j.includes(m)?j.filter(f=>f!==m):[...j,m]}:{...b,[h]:[m]}})},d=o.every(h=>(n[h.question]||[]).length>0),x=()=>{const h={};o.forEach(m=>{h[m.question]=(n[m.question]||[]).join(", ")}),s(h)};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((h,m)=>e.jsxs("div",{className:m<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:[h.question,h.multiSelect&&e.jsx("span",{className:"ml-2 text-xs font-normal opacity-60",children:"(可多选)"})]}),e.jsx("div",{className:"space-y-1",children:h.options.map((v,b)=>{const j=(n[h.question]||[]).includes(v.label);return e.jsxs("button",{type:"button",onClick:()=>i(h.question,v.label,h.multiSelect),className:`w-full text-left px-3 py-2 rounded-md text-xs border transition-colors ${j?"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:v.label}),v.description&&e.jsxs("span",{className:"ml-1 opacity-70",children:[" — ",v.description]})]},b)})})]},m)),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx("button",{type:"button",onClick:x,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 La=r.memo(({image:t})=>{const[s,a]=r.useState(t.data||null),[o,n]=r.useState(!1),[l,i]=r.useState(!t.data&&!!t.id);return r.useEffect(()=>{if(t.data||!t.id)return;let d=!1;return i(!0),X(`/api/images/${t.id}`).then(x=>{if(!x.ok)throw new Error("expired");return x.blob()}).then(x=>{d||(a(URL.createObjectURL(x)),i(!1))}).catch(()=>{d||(n(!0),i(!1))}),()=>{d=!0}},[t.data,t.id]),o?e.jsx("div",{className:"rounded-lg bg-gray-100 dark:bg-gray-800 flex items-center justify-center text-gray-400 text-xs p-4 min-h-[60px]",children:"图片已过期"}):l?e.jsx("div",{className:"rounded-lg bg-gray-100 dark:bg-gray-800 flex items-center justify-center text-gray-400 text-xs p-4 min-h-[60px] animate-pulse",children:"加载中..."}):s?e.jsx("img",{src:s,alt:t.name||"image",className:"rounded-lg max-w-full h-auto cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(s,"_blank"),onError:()=>n(!0)}):null});La.displayName="PersistentImage";const vi=r.memo(({message:t,index:s,prevMessage:a,createDiff:o,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,autoExpandTools:d,showRawParameters:x,showThinking:h,selectedProject:m,provider:v})=>{const b=a&&a.type===t.type&&(a.type==="assistant"||a.type==="user"||a.type==="tool"||a.type==="error"),j=it.useRef(null),[f,E]=it.useState(!1),O=hi(t,v),[T,R]=it.useState("idle");return it.useEffect(()=>{R("idle")},[O?.entry,t.toolId]),it.useEffect(()=>{if(!d||!j.current||!t.isToolUse)return;const g=new IntersectionObserver(p=>{p.forEach(u=>{u.isIntersecting&&!f&&(E(!0),j.current.querySelectorAll("details").forEach(L=>{L.open=!0}))})},{threshold:.1});return g.observe(j.current),()=>{j.current&&g.unobserve(j.current)}},[d,f,t.isToolUse]),e.jsx("div",{ref:j,className:`chat-message ${t.type} ${b?"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((g,p)=>e.jsx(La,{image:g},g.id||p))}),e.jsx("div",{className:"text-xs text-blue-100 mt-1 text-right",children:new Date(t.timestamp).toLocaleTimeString()})]}),!b&&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:[!b&&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(ht,{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 p=JSON.parse(t.toolInput);return e.jsxs("span",{className:"font-mono truncate flex-1 min-w-0",children:[p.pattern&&e.jsxs("span",{children:["pattern: ",e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:p.pattern})]}),p.path&&e.jsxs("span",{className:"ml-2",children:["in: ",p.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:p=>{p.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 p=JSON.parse(t.toolInput);if(p.file_path&&p.old_string&&p.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 u=>{if(u.preventDefault(),u.stopPropagation(),!!n)try{const y=await ke.readFile(m?.name,p.file_path),L=await y.json();if(!y.ok||L.error){console.error("Failed to fetch file:",L.error),n(p.file_path);return}const $=L.content||"",P=$.replace(p.new_string,p.old_string);n(p.file_path,{old_string:P,new_string:$})}catch(y){console.error("Error preparing diff:",y),n(p.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:p.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 u=await ke.readFile(m?.name,p.file_path),y=await u.json();if(!u.ok||y.error){console.error("Failed to fetch file:",y.error),n(p.file_path);return}const L=y.content||"",$=L.replace(p.new_string,p.old_string);n(p.file_path,{old_string:$,new_string:L})}catch(u){console.error("Error preparing diff:",u),n(p.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:p.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(p.old_string,p.new_string).map((u,y)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${u.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:u.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${u.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:u.content})]},y))})]}),x&&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 p;if(typeof t.toolInput=="string"?p=JSON.parse(t.toolInput):p=t.toolInput,p.file_path&&p.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 u=>{if(u.preventDefault(),u.stopPropagation(),!!n)try{const y=await ke.readFile(m?.name,p.file_path),L=await y.json(),$=y.ok&&!L.error?L.content||"":p.content||"";n(p.file_path,{old_string:"",new_string:$})}catch(y){console.error("Error preparing diff:",y),n(p.file_path,{old_string:"",new_string:p.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:p.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 u=await ke.readFile(m?.name,p.file_path),y=await u.json(),L=u.ok&&!y.error?y.content||"":p.content||"";n(p.file_path,{old_string:"",new_string:L})}catch(u){console.error("Error preparing diff:",u),n(p.file_path,{old_string:"",new_string:p.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:p.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("",p.content).map((u,y)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${u.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:u.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${u.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:u.content})]},y))})]}),x&&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 p=JSON.parse(t.toolInput);if(p.todos&&Array.isArray(p.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(Jr,{todos:p.todos}),x&&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 p=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:p.command})]}),p.description&&e.jsx("div",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400 italic ml-1",children:p.description})]})}catch{}if(t.toolName==="Read")try{const p=JSON.parse(t.toolInput);if(p.file_path){const u=p.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(p.file_path),className:"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline font-mono",children:u})]})}}catch{}if(t.toolName==="exit_plan_mode")try{const p=JSON.parse(t.toolInput);if(p.plan){const u=p.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(Kt,{className:"mt-3 prose prose-sm max-w-none dark:prose-invert",children:u})]})}}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 u=String(t.toolResult.content||"");if((t.toolName==="TodoWrite"||t.toolName==="TodoRead")&&(u.includes("Todos have been modified successfully")||u.includes("Todo list")||u.startsWith("[")&&u.includes('"content"')&&u.includes('"status"')))try{let $=null;if(u.startsWith("["))$=JSON.parse(u);else if(u.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($&&Array.isArray($))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(Jr,{todos:$,isResult:!0})]})}catch{}if(t.toolName==="exit_plan_mode")try{const $=JSON.parse(u);if($.plan){const P=$.plan.replace(/\\n/g,`
52
+ `})]})},yr={OPTIONS:[{value:"sonnet",label:"Sonnet"},{value:"opus",label:"Opus"},{value:"haiku",label:"Haiku"}],DEFAULT:"sonnet"};function Jt(t){return t&&t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&amp;/g,"&")}function xi(t){if(!t||typeof t!="string")return t;try{return t.replace(/```\s*([^\n\r]+?)\s*```/g,"`$1`")}catch{return t}}function jr(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 Kt=({children:t,className:s})=>{const a=xi(String(t??"")),o=r.useMemo(()=>[Un,Hn],[]),n=r.useMemo(()=>[qn],[]);return e.jsx("div",{className:s,children:e.jsx(Jn,{remarkPlugins:o,rehypePlugins:n,components:fi,children:a})})};function os(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?"+":"-",x=Math.abs(i),h=Math.floor(x/60),m=x%60,v=`GMT${d}${h}${m?":"+String(m).padStart(2,"0"):""}`,f=((Intl.DateTimeFormat().resolvedOptions().timeZone||"").split("/").pop()||"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,R=>R.toUpperCase()),E=f?`${v} (${f})`:v,O=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],T=`${n.getDate()} ${O[n.getMonth()]} ${n.getFullYear()}`;return`Claude usage limit reached. Your limit will reset at **${l} ${E}** - ${T}`})}catch{return t}}const rt={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 x=d.slice(-10);localStorage.setItem(t,JSON.stringify(x)),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)}}},Da="claude-settings";function fs(){const t=rt.getItem(Da);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 is(t,s){if(!t)return null;if(t!=="Bash")return t;const a=to(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 ea(t){if(t==null)return"";if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function hi(t,s){if(s!=="claude"||!t?.toolResult?.isError)return null;const a=t?.toolName,o=is(a,t.toolInput);if(!o)return null;const l=fs().allowedTools.includes(o);return{toolName:a,entry:o,isAllowed:l}}function gi(t){if(!t)return{success:!1};const s=fs(),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 rt.setItem(Da,JSON.stringify(l)),{success:!0,alreadyAllowed:a,updatedSettings:l}}const fi={code:({node:t,inline:s,className:a,children:o,...n})=>{const[l,i]=it.useState(!1),d=Array.isArray(o)?o.join(""):String(o??""),x=/[\r\n]/.test(d);if(s||t&&t.type==="inlineCode"||!x)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 v=/language-(\w+)/.exec(a||""),b=v?v[1]:"text",j=d,f=()=>{const E=()=>{i(!0),setTimeout(()=>i(!1),1500)};try{if(navigator&&navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(j).then(E).catch(()=>{const O=document.createElement("textarea");O.value=j,O.style.position="fixed",O.style.opacity="0",document.body.appendChild(O),O.select();try{document.execCommand("copy")}catch{}document.body.removeChild(O),E()});else{const O=document.createElement("textarea");O.value=j,O.style.position="fixed",O.style.opacity="0",document.body.appendChild(O),O.select();try{document.execCommand("copy")}catch{}document.body.removeChild(O),E()}}catch{}};return e.jsxs("div",{className:"relative group my-2",children:[b&&b!=="text"&&e.jsx("div",{className:"absolute top-2 left-3 z-10 text-xs text-gray-400 font-medium uppercase",children:b}),e.jsx("button",{type:"button",onClick:f,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(Kn,{language:b,style:co,customStyle:{margin:0,borderRadius:"0.5rem",fontSize:"0.875rem",padding:b&&b!=="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 bi({request:t,onSubmit:s,onSkip:a}){const o=t.input?.questions||[],[n,l]=it.useState(()=>Object.fromEntries(o.map(h=>[h.question,[]]))),i=(h,m,v)=>{l(b=>{const j=b[h]||[];return v?{...b,[h]:j.includes(m)?j.filter(f=>f!==m):[...j,m]}:{...b,[h]:[m]}})},d=o.every(h=>(n[h.question]||[]).length>0),x=()=>{const h={};o.forEach(m=>{h[m.question]=(n[m.question]||[]).join(", ")}),s(h)};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((h,m)=>e.jsxs("div",{className:m<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:[h.question,h.multiSelect&&e.jsx("span",{className:"ml-2 text-xs font-normal opacity-60",children:"(可多选)"})]}),e.jsx("div",{className:"space-y-1",children:h.options.map((v,b)=>{const j=(n[h.question]||[]).includes(v.label);return e.jsxs("button",{type:"button",onClick:()=>i(h.question,v.label,h.multiSelect),className:`w-full text-left px-3 py-2 rounded-md text-xs border transition-colors ${j?"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:v.label}),v.description&&e.jsxs("span",{className:"ml-1 opacity-70",children:[" — ",v.description]})]},b)})})]},m)),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx("button",{type:"button",onClick:x,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 Ia=r.memo(({image:t})=>{const[s,a]=r.useState(t.data||null),[o,n]=r.useState(!1),[l,i]=r.useState(!t.data&&!!t.id);return r.useEffect(()=>{if(t.data||!t.id)return;let d=!1;return i(!0),Z(`/api/images/${t.id}`).then(x=>{if(!x.ok)throw new Error("expired");return x.blob()}).then(x=>{d||(a(URL.createObjectURL(x)),i(!1))}).catch(()=>{d||(n(!0),i(!1))}),()=>{d=!0}},[t.data,t.id]),o?e.jsx("div",{className:"rounded-lg bg-gray-100 dark:bg-gray-800 flex items-center justify-center text-gray-400 text-xs p-4 min-h-[60px]",children:"图片已过期"}):l?e.jsx("div",{className:"rounded-lg bg-gray-100 dark:bg-gray-800 flex items-center justify-center text-gray-400 text-xs p-4 min-h-[60px] animate-pulse",children:"加载中..."}):s?e.jsx("img",{src:s,alt:t.name||"image",className:"rounded-lg max-w-full h-auto cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(s,"_blank"),onError:()=>n(!0)}):null});Ia.displayName="PersistentImage";const vi=r.memo(({message:t,index:s,prevMessage:a,createDiff:o,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,autoExpandTools:d,showRawParameters:x,showThinking:h,selectedProject:m,provider:v})=>{const b=a&&a.type===t.type&&(a.type==="assistant"||a.type==="user"||a.type==="tool"||a.type==="error"),j=it.useRef(null),[f,E]=it.useState(!1),O=hi(t,v),[T,R]=it.useState("idle");return it.useEffect(()=>{R("idle")},[O?.entry,t.toolId]),it.useEffect(()=>{if(!d||!j.current||!t.isToolUse)return;const g=new IntersectionObserver(p=>{p.forEach(u=>{u.isIntersecting&&!f&&(E(!0),j.current.querySelectorAll("details").forEach(L=>{L.open=!0}))})},{threshold:.1});return g.observe(j.current),()=>{j.current&&g.unobserve(j.current)}},[d,f,t.isToolUse]),e.jsx("div",{ref:j,className:`chat-message ${t.type} ${b?"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((g,p)=>e.jsx(Ia,{image:g},g.id||p))}),e.jsx("div",{className:"text-xs text-blue-100 mt-1 text-right",children:new Date(t.timestamp).toLocaleTimeString()})]}),!b&&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:[!b&&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(gt,{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 p=JSON.parse(t.toolInput);return e.jsxs("span",{className:"font-mono truncate flex-1 min-w-0",children:[p.pattern&&e.jsxs("span",{children:["pattern: ",e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:p.pattern})]}),p.path&&e.jsxs("span",{className:"ml-2",children:["in: ",p.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:p=>{p.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 p=JSON.parse(t.toolInput);if(p.file_path&&p.old_string&&p.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 u=>{if(u.preventDefault(),u.stopPropagation(),!!n)try{const y=await ke.readFile(m?.name,p.file_path),L=await y.json();if(!y.ok||L.error){console.error("Failed to fetch file:",L.error),n(p.file_path);return}const $=L.content||"",P=$.replace(p.new_string,p.old_string);n(p.file_path,{old_string:P,new_string:$})}catch(y){console.error("Error preparing diff:",y),n(p.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:p.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 u=await ke.readFile(m?.name,p.file_path),y=await u.json();if(!u.ok||y.error){console.error("Failed to fetch file:",y.error),n(p.file_path);return}const L=y.content||"",$=L.replace(p.new_string,p.old_string);n(p.file_path,{old_string:$,new_string:L})}catch(u){console.error("Error preparing diff:",u),n(p.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:p.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(p.old_string,p.new_string).map((u,y)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${u.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:u.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${u.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:u.content})]},y))})]}),x&&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 p;if(typeof t.toolInput=="string"?p=JSON.parse(t.toolInput):p=t.toolInput,p.file_path&&p.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 u=>{if(u.preventDefault(),u.stopPropagation(),!!n)try{const y=await ke.readFile(m?.name,p.file_path),L=await y.json(),$=y.ok&&!L.error?L.content||"":p.content||"";n(p.file_path,{old_string:"",new_string:$})}catch(y){console.error("Error preparing diff:",y),n(p.file_path,{old_string:"",new_string:p.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:p.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 u=await ke.readFile(m?.name,p.file_path),y=await u.json(),L=u.ok&&!y.error?y.content||"":p.content||"";n(p.file_path,{old_string:"",new_string:L})}catch(u){console.error("Error preparing diff:",u),n(p.file_path,{old_string:"",new_string:p.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:p.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("",p.content).map((u,y)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${u.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:u.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${u.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:u.content})]},y))})]}),x&&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 p=JSON.parse(t.toolInput);if(p.todos&&Array.isArray(p.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(Kr,{todos:p.todos}),x&&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 p=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:p.command})]}),p.description&&e.jsx("div",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400 italic ml-1",children:p.description})]})}catch{}if(t.toolName==="Read")try{const p=JSON.parse(t.toolInput);if(p.file_path){const u=p.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(p.file_path),className:"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline font-mono",children:u})]})}}catch{}if(t.toolName==="exit_plan_mode")try{const p=JSON.parse(t.toolInput);if(p.plan){const u=p.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(Kt,{className:"mt-3 prose prose-sm max-w-none dark:prose-invert",children:u})]})}}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 u=String(t.toolResult.content||"");if((t.toolName==="TodoWrite"||t.toolName==="TodoRead")&&(u.includes("Todos have been modified successfully")||u.includes("Todo list")||u.startsWith("[")&&u.includes('"content"')&&u.includes('"status"')))try{let $=null;if(u.startsWith("["))$=JSON.parse(u);else if(u.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($&&Array.isArray($))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(Kr,{todos:$,isResult:!0})]})}catch{}if(t.toolName==="exit_plan_mode")try{const $=JSON.parse(u);if($.plan){const P=$.plan.replace(/\\n/g,`
55
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(Kt,{className:"prose prose-sm max-w-none dark:prose-invert",children:P})]})}}catch{}if((t.toolName==="Grep"||t.toolName==="Glob")&&t.toolResult?.toolUseResult){const $=t.toolResult.toolUseResult;if($.filenames&&Array.isArray($.filenames)&&$.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:["找到 ",$.numFiles||$.filenames.length," 个文件"]})}),e.jsx("div",{className:"space-y-1 max-h-96 overflow-y-auto",children:$.filenames.map((P,z)=>{const me=P.split("/").pop(),se=P.substring(0,P.lastIndexOf("/"));return e.jsxs("div",{onClick:()=>{n&&n(P)},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:me}),e.jsx("div",{className:"font-mono text-xs text-green-600/70 dark:text-green-400/70 truncate",children:se})]}),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(u.includes("Do you want to proceed?")&&t.toolName==="Bash"){const $=u.split(`
56
56
  `),P=$.findIndex(A=>A.includes("Do you want to proceed?")),z=$.slice(0,P).join(`
57
57
  `),me=$.slice(P),se=me.find(A=>A.includes("Do you want to proceed?"))||"",te=[];me.forEach(A=>{const ae=A.match(/^\s*(\d+)\.\s+(.+)$/);ae&&te.push({number:ae[1],text:ae[2].trim()})});const de=u.match(/>\s*(\d+)/),_=de?de[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:se}),e.jsx("div",{className:"space-y-2 mb-4",children:te.map(A=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${_===A.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"} ${_?"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 ${_===A.number?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:A.number}),e.jsx("span",{className:"text-sm sm:text-base font-medium flex-1",children:A.text}),_===A.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"})})]})},A.number))}),_&&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 选择了选项 ",_]}),e.jsx("p",{className:"text-amber-800 dark:text-amber-200 text-xs",children:"在 CLI 中,您可以使用方向键或输入数字来交互式地选择此选项。"})]})]})]})})]})}const y=u.match(/The file (.+?) has been updated\./);if(y)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(y[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:y[1]})]});const L=u.match(/(?:The file|File) (.+?) has been (?:created|written)(?: successfully)?\.?/);return L?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(L[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:L[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:"文件内容显示在上方的差异视图中"})]}):u.includes("cat -n")&&u.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:u})})]}):u.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"})}),"查看完整输出 (",u.length," 字符)"]}),e.jsx(Kt,{className:"mt-2 prose prose-sm max-w-none prose-green dark:prose-invert",children:u})]}):e.jsx(Kt,{className:"prose prose-sm max-w-none prose-green dark:prose-invert",children:u})})(),O&&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(O)?.success?R("granted"):R("error")},disabled:O.isAllowed||T==="granted",className:`inline-flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-medium border transition-colors ${O.isAllowed||T==="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:O.isAllowed||T==="granted"?"权限已添加":`授予权限 ${O.toolName}`}),l&&e.jsx("button",{type:"button",onClick:u=>{u.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:O.entry})," 到允许的工具列表。"]}),T==="error"&&e.jsx("div",{className:"mt-2 text-xs text-red-700 dark:text-red-200",children:"无法更新权限。请重试。"}),(O.isAllowed||T==="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 g=t.content.split(`
58
- `).filter(y=>y.trim()),p=g.find(y=>y.includes("?"))||g[0]||"",u=[];return g.forEach(y=>{const L=y.match(/[❯\s]*(\d+)\.\s+(.+)/);if(L){const $=y.includes("❯");u.push({number:L[1],text:L[2].trim(),isSelected:$})}}),e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200 mb-4",children:p}),e.jsx("div",{className:"space-y-2 mb-4",children:u.map(y=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${y.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 ${y.isSelected?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:y.number}),e.jsx("span",{className:"text-sm sm:text-base font-medium flex-1",children:y.text}),y.isSelected&&e.jsx("span",{className:"text-lg",children:"❯"})]})},y.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 g=JSON.parse(t.toolInput);if(g.file_path){const p=g.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(g.file_path),className:"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 font-mono transition-colors",children:p})]})})}}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 g=JSON.parse(t.toolInput);if(g.todos&&Array.isArray(g.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(Jr,{todos:g.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(Kt,{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:[h&&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 g=ns(String(t.content||"")),p=g.trim();if((p.startsWith("{")||p.startsWith("["))&&(p.endsWith("}")||p.endsWith("]")))try{const u=JSON.parse(p),y=JSON.stringify(u,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:y})})})]})}catch{}return t.type==="assistant"?e.jsx(Kt,{className:"prose prose-sm max-w-none dark:prose-invert prose-gray",children:g}):e.jsx("div",{className:"whitespace-pre-wrap",children:g})})()]}),e.jsx("div",{className:`text-xs text-gray-500 dark:text-gray-400 mt-1 ${b?"opacity-0 group-hover:opacity-100":""}`,children:new Date(t.timestamp).toLocaleTimeString()})]})]})})}),yi=({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 ji({selectedProject:t,selectedSession:s,ws:a,sendMessage:o,messages:n,onFileOpen:l,onInputFocusChange:i,onSessionActive:d,onSessionInactive:x,onSessionProcessing:h,onSessionNotProcessing:m,processingSessions:v,onReplaceTemporarySession:b,onNavigateToSession:j,onShowSettings:f,autoExpandTools:E,showRawParameters:O,showThinking:T,autoScrollToBottom:R,sendByCtrlEnter:g,externalMessageUpdate:p,onTaskClick:u,limitStatus:y,onLimitExceeded:L,checkLimitStatus:$}){const{showConfirm:P}=ct(),[z,me]=r.useState(()=>typeof window<"u"&&t&&tt.getItem(`draft_input_${t.name}`)||""),[se,te]=r.useState(()=>{if(typeof window<"u"&&t){const c=tt.getItem(`chat_messages_${t.name}`);return c?JSON.parse(c):[]}return[]}),[de,_]=r.useState(!1),[A,ae]=r.useState(s?.id||null),[fe,ue]=r.useState(!1),[Z,G]=r.useState([]),pe=r.useRef([]),[Pe,Me]=r.useState(!1),[Le,Ne]=r.useState(!1),[qe,Ke]=r.useState(0),[We,Ie]=r.useState(!1),[je,$e]=r.useState(0),Fe=20,_e=r.useCallback(c=>{Ye.current=c,Ke(c)},[]),[ze,J]=r.useState(!1),[q,w]=r.useState("default"),[K,he]=r.useState([]),ve=r.useRef(new Map),Ae=r.useRef(s?.id||null),[Ue,V]=r.useState([]),[oe,Te]=r.useState(new Map),[Re,Ce]=r.useState(new Map),[S,ee]=r.useState(!1),we=r.useRef(null),Y=r.useRef(null),H=r.useRef(null),M=r.useRef(null),ne=r.useRef(null),B=r.useRef(!1),re=r.useRef(!1),ie=r.useRef(!1),ye=r.useRef(!1),xe=r.useRef(null),Ye=r.useRef(0),De=r.useRef(""),Ge=r.useRef(null),rt=r.useRef(null),[st,Lr]=r.useState(""),[gt,Dt]=r.useState(!1),[_t,Ir]=r.useState([]),[at,Dr]=r.useState([]),[Ft,Zt]=r.useState(-1),[mr,Wt]=r.useState(0),[ur,Bt]=r.useState(-1),[Tr,ot]=r.useState(!1),[Xt,ut]=r.useState(!1),Ut=r.useRef({height:0,top:0}),[er,pt]=r.useState(!1),[Ht,tr]=r.useState(!1),ft=r.useRef(null),I=r.useRef(null),[U,le]=r.useState([]),[Ee,bt]=r.useState([]),[nt,kt]=r.useState(""),[Ta,Nt]=r.useState(!1),[ks,qt]=r.useState(null),[Rr,St]=r.useState(-1),[Ns,Ct]=r.useState(-1),[rr,Ra]=r.useState(100),[Pa,Et]=r.useState(null),[dt,Pr]=r.useState(()=>localStorage.getItem("claude-model")||vr.DEFAULT),vt="claude";r.useEffect(()=>{if(!Ht)return;const c=k=>{ft.current&&!ft.current.contains(k.target)&&I.current&&!I.current.contains(k.target)&&tr(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[Ht]),r.useEffect(()=>{if(s?.id){const c=localStorage.getItem(`permissionMode-${s.id}`);w(c||"default")}},[s?.id]),r.useEffect(()=>{const c=Ae.current,k=s?.id;Ae.current=k,he(c&&c!==k?C=>(ve.current.set(c,C),ve.current.get(k)||[]):C=>C.filter(N=>!N.sessionId||N.sessionId===k))},[s?.id]),r.useEffect(()=>{(async()=>{if(t)try{const k=await X("/api/commands/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPath:t.path})});if(!k.ok)throw new Error("Failed to fetch commands");const C=await k.json(),N=[...(C.builtIn||[]).map(be=>({...be,type:"built-in"})),...(C.custom||[]).map(be=>({...be,type:"custom"}))];le(N);const D=`command_history_${t.name}`,F=tt.getItem(D);if(F)try{const be=JSON.parse(F),ge=N.sort((Q,ce)=>{const Se=be[Q.name]||0;return(be[ce.name]||0)-Se});le(ge)}catch(be){console.error("Error parsing command history:",be)}}catch(k){console.error("Error fetching slash commands:",k),le([])}})()},[t]);const $r=r.useMemo(()=>U.length?new vn(U,{keys:[{name:"name",weight:2},{name:"description",weight:1}],threshold:.4,includeScore:!0,minMatchCharLength:1}):null,[U]);r.useEffect(()=>{if(!nt){bt(U);return}if(!$r){bt([]);return}const c=$r.search(nt);bt(c.map(k=>k.item))},[nt,U,$r]);const $a=r.useMemo(()=>{if(!t||U.length===0)return[];const c=`command_history_${t.name}`,k=tt.getItem(c);if(!k)return[];try{const C=JSON.parse(k);return U.map(D=>({...D,usageCount:C[D.name]||0})).filter(D=>D.usageCount>0).sort((D,F)=>F.usageCount-D.usageCount).slice(0,5)}catch(C){return console.error("Error parsing command history:",C),[]}},[t,U]),za=r.useCallback((c,k,C)=>{if(!c||!t)return;if(C){St(k);return}const N=`command_history_${t.name}`,D=tt.getItem(N);let F={};try{F=D?JSON.parse(D):{}}catch(be){console.error("Error parsing command history:",be)}F[c.name]=(F[c.name]||0)+1,tt.setItem(N,JSON.stringify(F)),pr(c)},[t]),Aa=r.useCallback(c=>{const{action:k,data:C}=c;switch(k){case"help":te(N=>[...N,{type:"assistant",content:C.content,timestamp:Date.now()}]);break;case"model":{const N=C.available.claude,D=C.message?.includes("Switching to model:")?C.message.replace("Switching to model: ","").trim():null;D&&N.includes(D)?(Pr(D),localStorage.setItem("claude-model",D),te(F=>[...F,{type:"assistant",content:`已切换到模型: **${D}**`,timestamp:Date.now()}])):te(D?F=>[...F,{type:"assistant",content:`无效的模型: ${D}
58
+ `).filter(y=>y.trim()),p=g.find(y=>y.includes("?"))||g[0]||"",u=[];return g.forEach(y=>{const L=y.match(/[❯\s]*(\d+)\.\s+(.+)/);if(L){const $=y.includes("❯");u.push({number:L[1],text:L[2].trim(),isSelected:$})}}),e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200 mb-4",children:p}),e.jsx("div",{className:"space-y-2 mb-4",children:u.map(y=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${y.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 ${y.isSelected?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:y.number}),e.jsx("span",{className:"text-sm sm:text-base font-medium flex-1",children:y.text}),y.isSelected&&e.jsx("span",{className:"text-lg",children:"❯"})]})},y.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 g=JSON.parse(t.toolInput);if(g.file_path){const p=g.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(g.file_path),className:"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 font-mono transition-colors",children:p})]})})}}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 g=JSON.parse(t.toolInput);if(g.todos&&Array.isArray(g.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(Kr,{todos:g.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(Kt,{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:[h&&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 g=os(String(t.content||"")),p=g.trim();if((p.startsWith("{")||p.startsWith("["))&&(p.endsWith("}")||p.endsWith("]")))try{const u=JSON.parse(p),y=JSON.stringify(u,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:y})})})]})}catch{}return t.type==="assistant"?e.jsx(Kt,{className:"prose prose-sm max-w-none dark:prose-invert prose-gray",children:g}):e.jsx("div",{className:"whitespace-pre-wrap",children:g})})()]}),e.jsx("div",{className:`text-xs text-gray-500 dark:text-gray-400 mt-1 ${b?"opacity-0 group-hover:opacity-100":""}`,children:new Date(t.timestamp).toLocaleTimeString()})]})]})})}),yi=({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 ji({selectedProject:t,selectedSession:s,ws:a,sendMessage:o,messages:n,onFileOpen:l,onInputFocusChange:i,onSessionActive:d,onSessionInactive:x,onSessionProcessing:h,onSessionNotProcessing:m,processingSessions:v,onReplaceTemporarySession:b,onNavigateToSession:j,onShowSettings:f,autoExpandTools:E,showRawParameters:O,showThinking:T,autoScrollToBottom:R,sendByCtrlEnter:g,externalMessageUpdate:p,onTaskClick:u,limitStatus:y,onLimitExceeded:L,checkLimitStatus:$}){const{showConfirm:P}=ct(),[z,me]=r.useState(()=>typeof window<"u"&&t&&rt.getItem(`draft_input_${t.name}`)||""),[se,te]=r.useState(()=>{if(typeof window<"u"&&t){const c=rt.getItem(`chat_messages_${t.name}`);return c?JSON.parse(c):[]}return[]}),[de,_]=r.useState(!1),[A,ae]=r.useState(s?.id||null),[fe,ue]=r.useState(!1),[X,G]=r.useState([]),pe=r.useRef([]),[Pe,Ee]=r.useState(!1),[Me,Ne]=r.useState(!1),[qe,Ge]=r.useState(0),[We,De]=r.useState(!1),[je,$e]=r.useState(0),Fe=20,_e=r.useCallback(c=>{Ye.current=c,Ge(c)},[]),[ze,J]=r.useState(!1),[q,w]=r.useState("default"),[K,he]=r.useState([]),ve=r.useRef(new Map),Ae=r.useRef(s?.id||null),[Ue,V]=r.useState([]),[oe,Ie]=r.useState(new Map),[Te,Ce]=r.useState(new Map),[N,ee]=r.useState(!1),we=r.useRef(null),Y=r.useRef(null),U=r.useRef(null),M=r.useRef(null),ne=r.useRef(null),B=r.useRef(!1),re=r.useRef(!1),ie=r.useRef(!1),ye=r.useRef(!1),xe=r.useRef(null),Ye=r.useRef(0),Le=r.useRef(""),Je=r.useRef(null),st=r.useRef(null),[at,Dr]=r.useState(""),[ft,Rt]=r.useState(!1),[St,Ir]=r.useState([]),[ot,Tr]=r.useState([]),[bt,Zt]=r.useState(-1),[Xt,Bt]=r.useState(0),[pr,Ut]=r.useState(-1),[Rr,dt]=r.useState(!1),[er,Pt]=r.useState(!1),tr=r.useRef({height:0,top:0}),[vt,mt]=r.useState(!1),[Ht,rr]=r.useState(!1),sr=r.useRef(null),yt=r.useRef(null),[et,D]=r.useState([]),[H,le]=r.useState([]),[Re,nt]=r.useState(""),[xt,Ct]=r.useState(!1),[Ns,qt]=r.useState(null),[Pr,Et]=r.useState(-1),[Ss,Mt]=r.useState(-1),[ar,Pa]=r.useState(100),[$a,Lt]=r.useState(null),[ut,$r]=r.useState(()=>localStorage.getItem("claude-model")||yr.DEFAULT),jt="claude";r.useEffect(()=>{if(!Ht)return;const c=k=>{sr.current&&!sr.current.contains(k.target)&&yt.current&&!yt.current.contains(k.target)&&rr(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[Ht]),r.useEffect(()=>{if(s?.id){const c=localStorage.getItem(`permissionMode-${s.id}`);w(c||"default")}},[s?.id]),r.useEffect(()=>{const c=Ae.current,k=s?.id;Ae.current=k,he(c&&c!==k?C=>(ve.current.set(c,C),ve.current.get(k)||[]):C=>C.filter(S=>!S.sessionId||S.sessionId===k))},[s?.id]),r.useEffect(()=>{(async()=>{if(t)try{const k=await Z("/api/commands/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPath:t.path})});if(!k.ok)throw new Error("Failed to fetch commands");const C=await k.json(),S=[...(C.builtIn||[]).map(be=>({...be,type:"built-in"})),...(C.custom||[]).map(be=>({...be,type:"custom"}))];D(S);const I=`command_history_${t.name}`,F=rt.getItem(I);if(F)try{const be=JSON.parse(F),ge=S.sort((Q,ce)=>{const Se=be[Q.name]||0;return(be[ce.name]||0)-Se});D(ge)}catch(be){console.error("Error parsing command history:",be)}}catch(k){console.error("Error fetching slash commands:",k),D([])}})()},[t]);const zr=r.useMemo(()=>et.length?new vn(et,{keys:[{name:"name",weight:2},{name:"description",weight:1}],threshold:.4,includeScore:!0,minMatchCharLength:1}):null,[et]);r.useEffect(()=>{if(!Re){le(et);return}if(!zr){le([]);return}const c=zr.search(Re);le(c.map(k=>k.item))},[Re,et,zr]);const za=r.useMemo(()=>{if(!t||et.length===0)return[];const c=`command_history_${t.name}`,k=rt.getItem(c);if(!k)return[];try{const C=JSON.parse(k);return et.map(I=>({...I,usageCount:C[I.name]||0})).filter(I=>I.usageCount>0).sort((I,F)=>F.usageCount-I.usageCount).slice(0,5)}catch(C){return console.error("Error parsing command history:",C),[]}},[t,et]),Aa=r.useCallback((c,k,C)=>{if(!c||!t)return;if(C){Et(k);return}const S=`command_history_${t.name}`,I=rt.getItem(S);let F={};try{F=I?JSON.parse(I):{}}catch(be){console.error("Error parsing command history:",be)}F[c.name]=(F[c.name]||0)+1,rt.setItem(S,JSON.stringify(F)),xr(c)},[t]),Oa=r.useCallback(c=>{const{action:k,data:C}=c;switch(k){case"help":te(S=>[...S,{type:"assistant",content:C.content,timestamp:Date.now()}]);break;case"model":{const S=C.available.claude,I=C.message?.includes("Switching to model:")?C.message.replace("Switching to model: ","").trim():null;I&&S.includes(I)?($r(I),localStorage.setItem("claude-model",I),te(F=>[...F,{type:"assistant",content:`已切换到模型: **${I}**`,timestamp:Date.now()}])):te(I?F=>[...F,{type:"assistant",content:`无效的模型: ${I}
59
59
 
60
- **可用模型**: ${N.join(", ")}`,timestamp:Date.now()}]:F=>[...F,{type:"assistant",content:`**当前模型**: ${dt}
60
+ **可用模型**: ${S.join(", ")}`,timestamp:Date.now()}]:F=>[...F,{type:"assistant",content:`**当前模型**: ${ut}
61
61
 
62
- **可用模型**: ${N.join(", ")}
62
+ **可用模型**: ${S.join(", ")}
63
63
 
64
- 使用 \`/model <模型名>\` 切换模型,例如 \`/model opus\``,timestamp:Date.now()}]);break}case"cost":{let N;C.usage?N=`**Token 使用量**: ${C.usage.used.toLocaleString()} / ${C.usage.total.toLocaleString()} (${C.usage.percentage}%)
64
+ 使用 \`/model <模型名>\` 切换模型,例如 \`/model opus\``,timestamp:Date.now()}]);break}case"cost":{let S;C.usage?S=`**Token 使用量**: ${C.usage.used.toLocaleString()} / ${C.usage.total.toLocaleString()} (${C.usage.percentage}%)
65
65
 
66
- **剩余**: ${C.usage.remaining.toLocaleString()} tokens`:N=C.message||"无可用的 Token 使用数据。",te(D=>[...D,{type:"assistant",content:N,timestamp:Date.now()}]);break}case"memory":C.error?te(N=>[...N,{type:"assistant",content:`⚠️ ${C.message}`,timestamp:Date.now()}]):(te(N=>[...N,{type:"assistant",content:`📝 ${C.message}
66
+ **剩余**: ${C.usage.remaining.toLocaleString()} tokens`:S=C.message||"无可用的 Token 使用数据。",te(I=>[...I,{type:"assistant",content:S,timestamp:Date.now()}]);break}case"memory":C.error?te(S=>[...S,{type:"assistant",content:`⚠️ ${C.message}`,timestamp:Date.now()}]):(te(S=>[...S,{type:"assistant",content:`📝 ${C.message}
67
67
 
68
- Path: \`${C.path}\``,timestamp:Date.now()}]),C.exists&&l&&l(C.path));break;case"config":f&&f();break;default:console.warn("Unknown built-in command action:",k)}},[l,f,dt]),zr=r.useRef(null),Oa=r.useCallback(async(c,k)=>{const{content:C,hasBashCommands:N,hasFileIncludes:D}=c;if(N&&!await P("此命令包含将被执行的 bash 命令。是否继续?",{title:"执行确认",variant:"warning",confirmText:"继续执行"})){te(be=>[...be,{type:"assistant",content:"❌ 命令执行已取消",timestamp:Date.now()}]);return}me(C),setTimeout(()=>{if(zr.current){const F={preventDefault:()=>{}};zr.current(F)}},50)},[]),pr=r.useCallback(async c=>{if(!(!c||!t))try{const k=z.match(new RegExp(`${c.name}\\s*(.*)`)),C=k&&k[1]?k[1].trim().split(/\s+/):[],N={projectPath:t.path,projectName:t.name,sessionId:A,provider:vt,model:dt,tokenUsage:ks},D=await X("/api/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandName:c.name,commandPath:c.path,args:C,context:N})});if(!D.ok)throw new Error("Failed to execute command");const F=await D.json();F.type==="builtin"?Aa(F):F.type==="custom"&&await Oa(F,C),me(""),pt(!1),Ct(-1),kt(""),St(-1)}catch(k){console.error("Error executing command:",k),te(C=>[...C,{type:"assistant",content:`Error executing command: ${k.message}`,timestamp:Date.now()}])}},[z,t,A,vt,dt,ks]),_a=r.useMemo(()=>{const c=new Map;return(k,C)=>{const N=`${k.length}-${C.length}-${k.slice(0,50)}`;if(c.has(N))return c.get(N);const D=Fa(k,C);if(c.set(N,D),c.size>100){const F=c.keys().next().value;c.delete(F)}return D}},[]),sr=r.useCallback(async(c,k,C=!1,N="claude")=>{if(!c||!k)return[];const D=!C;D?Me(!0):Ne(!0);try{const F=C?Ye.current:0,be=await ke.sessionMessages(c,k,Fe,F,N);if(!be.ok)throw new Error("Failed to load session messages");const ge=await be.json();if(D&&ge.sessionImages)pe.current=ge.sessionImages;else if(C&&ge.sessionImages){const Q=new Set(pe.current.map(Se=>Se.batchId)),ce=ge.sessionImages.filter(Se=>!Q.has(Se.batchId));ce.length>0&&(pe.current=[...ce,...pe.current])}if(D&&ge.tokenUsage&&qt(ge.tokenUsage),ge.hasMore!==void 0)return Ie(ge.hasMore),$e(ge.total),_e(F+(ge.messages?.length||0)),ge.messages||[];{const Q=ge.messages||[];return Ie(!1),$e(Q.length),Q}}catch(F){return console.error("Error loading session messages:",F),[]}finally{D?Me(!1):Ne(!1)}},[_e]),Fa=(c,k)=>{const C=c.split(`
69
- `),N=k.split(`
70
- `),D=[];let F=0,be=0;for(;F<C.length||be<N.length;){const ge=C[F],Q=N[be];F>=C.length?(D.push({type:"added",content:Q,lineNum:be+1}),be++):be>=N.length?(D.push({type:"removed",content:ge,lineNum:F+1}),F++):ge===Q?(F++,be++):(D.push({type:"removed",content:ge,lineNum:F+1}),D.push({type:"added",content:Q,lineNum:be+1}),F++,be++)}return D},Ss=c=>{const k=[],C=new Map;for(const N of c)if(N.message?.role==="user"&&Array.isArray(N.message?.content))for(const D of N.message.content)D.type==="tool_result"&&C.set(D.tool_use_id,{content:D.content,isError:D.is_error,timestamp:new Date(N.timestamp||Date.now()),toolUseResult:N.toolUseResult||null});for(const N of c)if(!N.isMeta){if(N.message?.role==="user"&&N.message?.content){let D="",F="user";if(Array.isArray(N.message.content)){const Q=[];for(const ce of N.message.content)ce.type==="text"&&Q.push(Jt(ce.text));D=Q.join(`
71
- `)}else typeof N.message.content=="string"?D=Jt(N.message.content):D=Jt(String(N.message.content));const be=D.match(/<command-name>(\/[^<]+)<\/command-name>/);be&&(D=be[1]),!D||D.startsWith("<command-args>")||D.startsWith("<local-command-stdout>")||D.startsWith("<system-reminder>")||D.startsWith("Caveat:")||D.startsWith("This session is being continued from a previous")||D.startsWith("[Request interrupted")||(D=D.replace(/(\n\n)?\[Images provided at the following paths:\]\n[\s\S]*$/,""),D=yr(D),D&&k.push({type:F,content:D,timestamp:N.timestamp||new Date().toISOString()}))}else if(N.type==="thinking"&&N.message?.content)k.push({type:"assistant",content:yr(N.message.content),timestamp:N.timestamp||new Date().toISOString(),isThinking:!0});else if(N.type==="tool_use"&&N.toolName)k.push({type:"assistant",content:"",timestamp:N.timestamp||new Date().toISOString(),isToolUse:!0,toolName:N.toolName,toolInput:N.toolInput||"",toolCallId:N.toolCallId});else if(N.type==="tool_result"){for(let D=k.length-1;D>=0;D--)if(k[D].isToolUse&&!k[D].toolResult&&(!N.toolCallId||k[D].toolCallId===N.toolCallId)){k[D].toolResult={content:N.output||"",isError:!1};break}}else if(N.message?.role==="assistant"&&N.message?.content){if(Array.isArray(N.message.content)){for(const D of N.message.content)if(D.type==="text"){let F=D.text;typeof F=="string"&&(F=yr(F)),k.push({type:"assistant",content:F,timestamp:N.timestamp||new Date().toISOString()})}else if(D.type==="tool_use"){const F=C.get(D.id);k.push({type:"assistant",content:"",timestamp:N.timestamp||new Date().toISOString(),isToolUse:!0,toolName:D.name,toolInput:JSON.stringify(D.input),toolResult:F?{content:typeof F.content=="string"?F.content:JSON.stringify(F.content),isError:F.isError,toolUseResult:F.toolUseResult}:null,toolError:F?.isError||!1,toolResultTimestamp:F?.timestamp||new Date})}}else if(typeof N.message.content=="string"){let D=N.message.content;D=yr(D),k.push({type:"assistant",content:D,timestamp:N.timestamp||new Date().toISOString()})}}}return k},Ar=r.useMemo(()=>Ss(Z),[Z]),yt=r.useCallback(()=>{ne.current&&(ne.current.scrollTop=ne.current.scrollHeight)},[]),xr=r.useCallback(()=>{if(!ne.current)return!1;const{scrollTop:c,scrollHeight:k,clientHeight:C}=ne.current;return k-c-C<50},[]),Cs=r.useCallback(async c=>{if(!c||ie.current||Le||!We||!s||!t)return!1;ie.current=!0;const k=c.scrollHeight,C=c.scrollTop;try{const N=await sr(t.name,s.id,!0,"claude");return N.length>0?(xe.current={height:k,top:C},G(D=>[...N,...D]),!0):!1}finally{ie.current=!1}},[We,Le,s,t,sr]),ar=r.useCallback(async()=>{if(ne.current){const c=ne.current,k=xr();ut(!k),c.scrollTop<100?ye.current||await Cs(c)&&(ye.current=!0):ye.current=!1}},[xr,Cs]);r.useLayoutEffect(()=>{if(!xe.current||!ne.current)return;const{height:c,top:k}=xe.current,C=ne.current,D=C.scrollHeight-c;C.scrollTop=k+Math.max(D,0),xe.current=null,setTimeout(()=>{ne.current&&ne.current.scrollTop>=100&&(ye.current=!1)},300)},[se.length]),r.useEffect(()=>{(async()=>{if(s&&t){const k=localStorage.getItem("selected-provider")||"claude";B.current=!0;const C=A!==null&&A!==s.id;if(C?(_e(0),Ie(!1),$e(0),qt(null),_(!1),a&&o&&o({type:"check-session-status",sessionId:s.id,provider:k})):A===null&&(_e(0),Ie(!1),$e(0),a&&o&&o({type:"check-session-status",sessionId:s.id,provider:k})),ae(s.id),ze)J(!1);else{const N=await sr(t.name,s.id,!1,"claude");G(N),C&&te(Ss(N))}}else!ze&&!de&&(te([]),G([]),pe.current=[]),ae(null),_e(0),Ie(!1),$e(0);setTimeout(()=>{B.current=!1},250)})()},[s,t,yt,ze]),r.useEffect(()=>{p>0&&s&&t&&(async()=>{try{const k=await sr(t.name,s.id,!1,"claude");G(k),R&&xr()&&setTimeout(()=>yt(),200)}catch(k){console.error("Error reloading messages from external update:",k)}})()},[p,s,t,sr,xr,R,yt]),r.useEffect(()=>{Z.length>0&&!de&&te(c=>{const k=new Map;for(const F of c)F.type==="user"&&F.images?.length>0&&k.set(F.content,F.images);const C=new Map;for(const F of pe.current)if(F.messageContent){const be=F.images.map(Q=>({id:Q.id,name:Q.name})),ge=C.get(F.messageContent)||[];C.set(F.messageContent,[...ge,...be])}const N=k.size>0,D=C.size>0;return!N&&!D?Ar:Ar.map(F=>F.type!=="user"?F:N&&k.has(F.content)?{...F,images:k.get(F.content)}:D&&C.has(F.content)?{...F,images:C.get(F.content)}:F)})},[Ar,Z,de]),r.useEffect(()=>{i&&i(fe)},[fe,i]),r.useEffect(()=>{t&&z!==""?tt.setItem(`draft_input_${t.name}`,z):t&&z===""&&tt.removeItem(`draft_input_${t.name}`)},[z,t]),r.useEffect(()=>{t&&se.length>0&&tt.setItem(`chat_messages_${t.name}`,JSON.stringify(se))},[se,t]),r.useEffect(()=>{if(t){const c=tt.getItem(`draft_input_${t.name}`)||"";c!==z&&me(c)}},[t?.name]),r.useEffect(()=>{A&&de&&h&&h(A)},[de,A,h]),r.useEffect(()=>{A&&v&&v.has(A)&&!de&&(_(!0),ot(!0))},[A,v]),r.useEffect(()=>{if(n.length>0){const c=n[n.length-1];if(!["projects_updated","session-created","claude-complete"].includes(c.type)&&c.sessionId&&A&&c.sessionId!==A){console.log("⏭️ Skipping message for different session:",c.sessionId,"current:",A);return}switch(c.type){case"session-created":c.sessionId&&!A&&(sessionStorage.setItem("pendingSessionId",c.sessionId),J(!0),b&&b(c.sessionId),he(Q=>Q.map(ce=>ce.sessionId?ce:{...ce,sessionId:c.sessionId})));break;case"token-budget":c.data&&qt(c.data);break;case"claude-response":if(c.data.isMeta)return;const N=c.data.message||c.data;if(N&&typeof N=="object"&&N.type){if(N.type==="content_block_delta"&&N.delta?.text){const Q=Jt(N.delta.text);De.current+=Q,Ge.current||(Ge.current=setTimeout(()=>{const ce=De.current;De.current="",Ge.current=null,ce&&te(Se=>{const Oe=[...Se],Ze=Oe[Oe.length-1];return Ze&&Ze.type==="assistant"&&!Ze.isToolUse&&Ze.isStreaming?Ze.content=(Ze.content||"")+ce:Oe.push({type:"assistant",content:ce,timestamp:new Date,isStreaming:!0}),Oe})},100));return}if(N.type==="content_block_stop"){Ge.current&&(clearTimeout(Ge.current),Ge.current=null);const Q=De.current;De.current="",Q&&te(ce=>{const Se=[...ce],Oe=Se[Se.length-1];return Oe&&Oe.type==="assistant"&&!Oe.isToolUse&&Oe.isStreaming?Oe.content=(Oe.content||"")+Q:Se.push({type:"assistant",content:Q,timestamp:new Date,isStreaming:!0}),Se}),te(ce=>{const Se=[...ce],Oe=Se[Se.length-1];return Oe&&Oe.type==="assistant"&&Oe.isStreaming&&(Oe.isStreaming=!1),Se});return}}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&A&&c.data.session_id!==A){console.log("🔄 Claude CLI session duplication detected:",{originalSession:A,newSession:c.data.session_id}),J(!0),j&&j(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&!A){console.log("🔄 New session init detected:",{newSession:c.data.session_id}),J(!0),j&&j(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&A&&c.data.session_id===A){console.log("🔄 System init message for current session, ignoring");return}const D=N.role==="user"||c.data.type==="user";if(Array.isArray(N.content)&&!D){for(const Q of N.content)if(Q.type==="tool_use"){const ce=Q.input?JSON.stringify(Q.input,null,2):"";te(Se=>[...Se,{type:"assistant",content:"",timestamp:new Date,isToolUse:!0,toolName:Q.name,toolInput:ce,toolId:Q.id,toolResult:null}])}else if(Q.type==="text"&&Q.text?.trim()){let ce=Jt(Q.text);ce=ns(ce),te(Se=>[...Se,{type:"assistant",content:ce,timestamp:new Date}])}}else if(typeof N.content=="string"&&N.content.trim()&&!D){let Q=Jt(N.content);Q=ns(Q),te(ce=>[...ce,{type:"assistant",content:Q,timestamp:new Date}])}if(N.role==="user"&&Array.isArray(N.content))for(const Q of N.content)Q.type==="tool_result"&&te(ce=>ce.map(Se=>Se.isToolUse&&Se.toolId===Q.tool_use_id?{...Se,toolResult:{content:Q.content,isError:Q.is_error,timestamp:new Date}}:Se));break;case"claude-output":{const Q=String(c.data||"");Q.trim()&&(De.current+=De.current?`
72
- ${Q}`:Q,Ge.current||(Ge.current=setTimeout(()=>{const ce=De.current;De.current="",Ge.current=null,ce&&te(Se=>{const Oe=[...Se],Ze=Oe[Oe.length-1];return Ze&&Ze.type==="assistant"&&!Ze.isToolUse&&Ze.isStreaming?Ze.content=Ze.content?`${Ze.content}
73
- ${ce}`:ce:Oe.push({type:"assistant",content:ce,timestamp:new Date,isStreaming:!0}),Oe})},100)))}break;case"claude-interactive-prompt":te(Q=>[...Q,{type:"assistant",content:c.data,timestamp:new Date,isInteractivePrompt:!0}]);break;case"claude-permission-request":{if(!c.requestId)break;he(Q=>Q.some(ce=>ce.requestId===c.requestId)?Q:[...Q,{requestId:c.requestId,toolName:c.toolName||"UnknownTool",input:c.input,context:c.context,sessionId:c.sessionId||null,receivedAt:new Date}]),_(!0),ot(!0),Et({text:"等待权限",tokens:0,can_interrupt:!0});break}case"claude-permission-cancelled":{if(!c.requestId)break;he(Q=>Q.filter(ce=>ce.requestId!==c.requestId));break}case"claude-error":te(Q=>[...Q,{type:"error",content:`错误: ${c.error}`,timestamp:new Date}]),_(!1),ot(!1),Et(null),he([]),A&&(x&&x(A),m&&m(A));break;case"claude-complete":const F=c.sessionId||A||sessionStorage.getItem("pendingSessionId");(F===A||!A)&&(_(!1),ot(!1),Et(null)),F&&(x&&x(F),m&&m(F));const be=sessionStorage.getItem("pendingSessionId");be&&!A&&c.exitCode===0&&(ae(be),sessionStorage.removeItem("pendingSessionId"),console.log("✅ New session complete, ID set to:",be)),t&&c.exitCode===0&&tt.removeItem(`chat_messages_${t.name}`),F===A&&he([]),ve.current.delete(F);break;case"session-aborted":{const Q=c.sessionId||A;Q===A&&(_(!1),ot(!1),Et(null)),Q&&(x&&x(Q),m&&m(Q)),he([]),te(ce=>[...ce,{type:"assistant",content:"会话已被用户中断。",timestamp:new Date}]);break}case"session-status":{const Q=c.sessionId;(Q===A||s&&Q===s.id)&&c.isProcessing&&(_(!0),ot(!0),h&&h(Q));break}case"claude-status":const ge=c.data;if(ge){let Q={text:"处理中...",tokens:0,can_interrupt:!0};ge.message?Q.text=ge.message:ge.status?Q.text=ge.status:typeof ge=="string"&&(Q.text=ge),ge.tokens?Q.tokens=ge.tokens:ge.token_count&&(Q.tokens=ge.token_count),ge.can_interrupt!==void 0&&(Q.can_interrupt=ge.can_interrupt),Et(Q),_(!0),ot(Q.can_interrupt)}break}}},[n]),r.useEffect(()=>{t&&Wa()},[t]);const Wa=async()=>{try{const c=await ke.getFiles(t.name);if(c.ok){const k=await c.json(),C=Es(k);Ir(C)}}catch(c){console.error("Error fetching files:",c)}},Es=(c,k="")=>{let C=[];for(const N of c){const D=k?`${k}/${N.name}`:N.name;N.type==="directory"&&N.children?C=C.concat(Es(N.children,D)):N.type==="file"&&C.push({name:N.name,path:D,relativePath:N.path})}return C};r.useEffect(()=>{const c=z.slice(0,mr),k=c.lastIndexOf("@");if(k!==-1){const C=c.slice(k+1);if(C.includes(" "))Dt(!1),Bt(-1);else{Bt(k),Dt(!0);const N=_t.filter(D=>D.name.toLowerCase().includes(C.toLowerCase())||D.path.toLowerCase().includes(C.toLowerCase())).slice(0,10);Dr(N),Zt(-1)}}else Dt(!1),Bt(-1)},[z,mr,_t]),r.useEffect(()=>{const c=setTimeout(()=>{Lr(z)},150);return()=>clearTimeout(c)},[z]);const Ms=r.useMemo(()=>se.length<=rr?se:se.slice(-rr),[se,rr]);r.useEffect(()=>{if(!R&&ne.current){const c=ne.current;Ut.current={height:c.scrollHeight,top:c.scrollTop}}}),r.useEffect(()=>{if(ne.current&&se.length>0)if(R)Xt||setTimeout(()=>yt(),50);else{const c=ne.current,k=Ut.current.height,C=Ut.current.top,D=c.scrollHeight-k;D>0&&C>0&&(c.scrollTop=C+D)}},[se.length,Xt,yt,R]),r.useEffect(()=>{ne.current&&se.length>0&&!B.current&&(ut(!1),setTimeout(()=>{yt()},200))},[s?.id,t?.name]),r.useEffect(()=>{const c=ne.current;if(c)return c.addEventListener("scroll",ar),()=>c.removeEventListener("scroll",ar)},[ar]),r.useEffect(()=>{if(Y.current){Y.current.style.height="auto",Y.current.style.height=Y.current.scrollHeight+"px";const c=parseInt(window.getComputedStyle(Y.current).lineHeight),k=Y.current.scrollHeight>c*2;Nt(k)}},[]),r.useEffect(()=>{Y.current&&!z.trim()&&(Y.current.style.height="auto",Nt(!1))},[z]),r.useEffect(()=>{if(!t||!s?.id||s.id.startsWith("new-session-")){qt(null);return}(async()=>{try{const k=`/api/projects/${t.name}/sessions/${s.id}/token-usage`,C=await X(k);if(C.ok){const N=await C.json();qt(N)}else qt(null)}catch(k){console.error("Failed to fetch initial token usage:",k)}})()},[s?.id,s?.__provider,t?.path]);const Ba=r.useCallback(c=>{c.trim()&&me(k=>{const C=k.trim()?`${k} ${c}`:c;return setTimeout(()=>{if(Y.current){Y.current.style.height="auto",Y.current.style.height=Y.current.scrollHeight+"px";const N=parseInt(window.getComputedStyle(Y.current).lineHeight),D=Y.current.scrollHeight>N*2;Nt(D)}},0),C})},[]),Ua=r.useCallback(()=>{Ra(c=>c+100)},[]),hr=r.useCallback(c=>{const k=c.filter(C=>{try{if(!C||typeof C!="object")return console.warn("Invalid file object:",C),!1;if(!C.type||!C.type.startsWith("image/"))return!1;if(!C.size||C.size>5242880){const N=C.name||"Unknown file";return Ce(D=>{const F=new Map(D);return F.set(N,"文件太大(最大 5MB)"),F}),!1}return!0}catch(N){return console.error("Error validating file:",N,C),!1}});k.length>0&&V(C=>[...C,...k].slice(0,5))},[]),Ha=r.useCallback(async c=>{const k=c.target.files;if(!(!k||k.length===0||!t)){ee(!0);try{const C=new FormData;Array.from(k).forEach(F=>{C.append("files",F)});const N=await ke.uploadFiles(t.name,C);if(!N.ok){const F=await N.json();throw new Error(F.error||"上传失败")}const D=await N.json();if(D.files&&D.files.length>0){const F=D.files.map(ge=>`@${ge.name}`).join(" "),be=z?`${z} ${F} `:`${F} `;me(be),Y.current&&Y.current.focus()}}catch(C){console.error("File upload failed:",C)}finally{ee(!1),H.current&&(H.current.value="")}}},[t,z]),qa=r.useCallback(async c=>{const k=Array.from(c.clipboardData.items);for(const C of k)if(C.type.startsWith("image/")){const N=C.getAsFile();N&&hr([N])}if(k.length===0&&c.clipboardData.files.length>0){const N=Array.from(c.clipboardData.files).filter(D=>D.type.startsWith("image/"));N.length>0&&hr(N)}},[hr]),{getRootProps:Ja,getInputProps:Ka,isDragActive:Ga,open:Va}=hs({accept:{"image/*":[".png",".jpg",".jpeg",".gif",".webp",".svg"]},maxSize:5*1024*1024,maxFiles:5,onDrop:hr,noClick:!0,noKeyboard:!0}),Tt=r.useCallback(async c=>{if(c.preventDefault(),!z.trim()||de||!t||re.current)return;re.current=!0;const k=z.trim();if(k.startsWith("/")){const ce=k.indexOf(" "),Se=ce!==-1?k.slice(0,ce):k,Oe=U.find(Ze=>Ze.name===Se&&Ze.namespace==="builtin");if(Oe){re.current=!1,pr(Oe);return}}if($){const ce=await $();if(ce&&!ce.allowed){re.current=!1,L?.(ce.reason);return}}let C=[],N=null;if(Ue.length>0){const ce=new FormData;Ue.forEach(Se=>{ce.append("images",Se)});try{const Se=await X(`/api/projects/${t.name}/upload-images`,{method:"POST",headers:{},body:ce});if(!Se.ok)throw new Error("图片上传失败");const Oe=await Se.json();C=Oe.images,N=Oe.uploadBatchId||null}catch(Se){console.error("Image upload failed:",Se),re.current=!1,te(Oe=>[...Oe,{type:"error",content:`图片上传失败: ${Se.message}`,timestamp:new Date}]);return}}const D={type:"user",content:z,images:C,timestamp:new Date};te(ce=>[...ce,D]),_(!0),re.current=!1,ot(!0),Et({text:"处理中",tokens:0,can_interrupt:!0}),ut(!1),setTimeout(()=>yt(),100);const be=A||s?.id||`new-session-${Date.now()}`;d&&d(be);const Q=(()=>{try{const ce=tt.getItem("claude-settings");if(ce)return JSON.parse(ce)}catch(ce){console.error("Error loading tools settings:",ce)}return{allowedTools:[],disallowedTools:[],skipPermissions:!1}})();o({type:"claude-command",command:z,options:{projectPath:t.path,cwd:t.fullPath,sessionId:A,resume:!!A,toolsSettings:Q,permissionMode:q,model:dt,images:C,uploadBatchId:N}}),me(""),V([]),Te(new Map),Ce(new Map),Nt(!1),Y.current&&(Y.current.style.height="auto"),t&&tt.removeItem(`draft_input_${t.name}`)},[z,de,t,Ue,A,s,vt,q,d,dt,o,me,V,Te,Ce,Nt,Y,te,_,ot,Et,ut,yt,$,L,pr,U]),Ls=r.useCallback(c=>!c||vt!=="claude"?{success:!1}:gi(c.entry),[vt]),nr=r.useCallback((c,k)=>{const N=(Array.isArray(c)?c:[c]).filter(Boolean);N.length!==0&&(N.forEach(D=>{o({type:"claude-permission-response",requestId:D,allow:!!k?.allow,updatedInput:k?.updatedInput,message:k?.message,rememberEntry:k?.rememberEntry})}),he(D=>{const F=D.filter(be=>!N.includes(be.requestId));return F.length===0&&Et(null),F}))},[o]);r.useEffect(()=>{zr.current=Tt},[Tt]);const Is=c=>{if(!c)return;const k=z.slice(0,Ns),C=z.slice(Ns),N=C.indexOf(" "),D=N!==-1?C.slice(N):"",F=k+c.name+" "+D;me(F),pt(!1),Ct(-1),kt(""),St(-1),rt.current&&clearTimeout(rt.current),pr(c)},Ya=c=>{if(er&&Ee.length>0){if(c.key==="ArrowDown"){c.preventDefault(),St(k=>k<Ee.length-1?k+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),St(k=>k>0?k-1:Ee.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),Rr>=0?Is(Ee[Rr]):Ee.length>0&&Is(Ee[0]);return}if(c.key==="Escape"){c.preventDefault(),pt(!1),Ct(-1),kt(""),St(-1),rt.current&&clearTimeout(rt.current);return}}if(gt&&at.length>0){if(c.key==="ArrowDown"){c.preventDefault(),Zt(k=>k<at.length-1?k+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),Zt(k=>k>0?k-1:at.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),Ft>=0?Or(at[Ft]):at.length>0&&Or(at[0]);return}if(c.key==="Escape"){c.preventDefault(),Dt(!1);return}}if(c.key==="Tab"&&!gt&&!er){c.preventDefault();const k=["default","acceptEdits","bypassPermissions","plan"],N=(k.indexOf(q)+1)%k.length,D=k[N];w(D),s?.id&&localStorage.setItem(`permissionMode-${s.id}`,D);return}if(c.key==="Enter"){if(c.nativeEvent.isComposing)return;(c.ctrlKey||c.metaKey)&&!c.shiftKey?(c.preventDefault(),Tt(c)):!c.shiftKey&&!c.ctrlKey&&!c.metaKey&&(g||(c.preventDefault(),Tt(c)))}},Or=c=>{const k=z.slice(0,ur),C=z.slice(ur),N=C.indexOf(" "),D=N!==-1?C.slice(N):"",F=k+"@"+c.path+" "+D,be=k.length+1+c.path.length+1;Y.current&&!Y.current.matches(":focus")&&Y.current.focus(),me(F),Wt(be),Dt(!1),Bt(-1),Y.current&&requestAnimationFrame(()=>{Y.current&&(Y.current.setSelectionRange(be,be),Y.current.matches(":focus")||Y.current.focus())})},Qa=c=>{const k=c.target.value,C=c.target.selectionStart;if(!A&&k.trim(),me(k),Wt(C),!k.trim()){c.target.style.height="auto",Nt(!1),pt(!1),Ct(-1),kt("");return}const N=k.slice(0,C);if((N.match(/```/g)||[]).length%2===1){pt(!1),Ct(-1),kt("");return}const be=/(^|\s)\/(\S*)$/,ge=N.match(be);if(ge){const Q=ge.index+ge[1].length,ce=ge[2];Ct(Q),pt(!0),St(-1),rt.current&&clearTimeout(rt.current),rt.current=setTimeout(()=>{kt(ce)},150)}else pt(!1),Ct(-1),kt(""),rt.current&&clearTimeout(rt.current)},Za=c=>{Wt(c.target.selectionStart)},Xa=()=>{A&&Tr&&o({type:"abort-session",sessionId:A,provider:vt})},en=()=>{const c=["default","acceptEdits","bypassPermissions","plan"],C=(c.indexOf(q)+1)%c.length,N=c[C];w(N),s?.id&&localStorage.setItem(`permissionMode-${s.id}`,N)};return t?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
68
+ Path: \`${C.path}\``,timestamp:Date.now()}]),C.exists&&l&&l(C.path));break;case"config":f&&f();break;default:console.warn("Unknown built-in command action:",k)}},[l,f,ut]),Ar=r.useRef(null),_a=r.useCallback(async(c,k)=>{const{content:C,hasBashCommands:S,hasFileIncludes:I}=c;if(S&&!await P("此命令包含将被执行的 bash 命令。是否继续?",{title:"执行确认",variant:"warning",confirmText:"继续执行"})){te(be=>[...be,{type:"assistant",content:"❌ 命令执行已取消",timestamp:Date.now()}]);return}me(C),setTimeout(()=>{if(Ar.current){const F={preventDefault:()=>{}};Ar.current(F)}},50)},[]),xr=r.useCallback(async c=>{if(!(!c||!t))try{const k=z.match(new RegExp(`${c.name}\\s*(.*)`)),C=k&&k[1]?k[1].trim().split(/\s+/):[],S={projectPath:t.path,projectName:t.name,sessionId:A,provider:jt,model:ut,tokenUsage:Ns},I=await Z("/api/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandName:c.name,commandPath:c.path,args:C,context:S})});if(!I.ok)throw new Error("Failed to execute command");const F=await I.json();F.type==="builtin"?Oa(F):F.type==="custom"&&await _a(F,C),me(""),mt(!1),Mt(-1),nt(""),Et(-1)}catch(k){console.error("Error executing command:",k),te(C=>[...C,{type:"assistant",content:`Error executing command: ${k.message}`,timestamp:Date.now()}])}},[z,t,A,jt,ut,Ns]),Fa=r.useMemo(()=>{const c=new Map;return(k,C)=>{const S=`${k.length}-${C.length}-${k.slice(0,50)}`;if(c.has(S))return c.get(S);const I=Wa(k,C);if(c.set(S,I),c.size>100){const F=c.keys().next().value;c.delete(F)}return I}},[]),nr=r.useCallback(async(c,k,C=!1,S="claude")=>{if(!c||!k)return[];const I=!C;I?Ee(!0):Ne(!0);try{const F=C?Ye.current:0,be=await ke.sessionMessages(c,k,Fe,F,S);if(!be.ok)throw new Error("Failed to load session messages");const ge=await be.json();if(I&&ge.sessionImages)pe.current=ge.sessionImages;else if(C&&ge.sessionImages){const Q=new Set(pe.current.map(Se=>Se.batchId)),ce=ge.sessionImages.filter(Se=>!Q.has(Se.batchId));ce.length>0&&(pe.current=[...ce,...pe.current])}if(I&&ge.tokenUsage&&qt(ge.tokenUsage),ge.hasMore!==void 0)return De(ge.hasMore),$e(ge.total),_e(F+(ge.messages?.length||0)),ge.messages||[];{const Q=ge.messages||[];return De(!1),$e(Q.length),Q}}catch(F){return console.error("Error loading session messages:",F),[]}finally{I?Ee(!1):Ne(!1)}},[_e]),Wa=(c,k)=>{const C=c.split(`
69
+ `),S=k.split(`
70
+ `),I=[];let F=0,be=0;for(;F<C.length||be<S.length;){const ge=C[F],Q=S[be];F>=C.length?(I.push({type:"added",content:Q,lineNum:be+1}),be++):be>=S.length?(I.push({type:"removed",content:ge,lineNum:F+1}),F++):ge===Q?(F++,be++):(I.push({type:"removed",content:ge,lineNum:F+1}),I.push({type:"added",content:Q,lineNum:be+1}),F++,be++)}return I},Cs=c=>{const k=[],C=new Map;for(const S of c)if(S.message?.role==="user"&&Array.isArray(S.message?.content))for(const I of S.message.content)I.type==="tool_result"&&C.set(I.tool_use_id,{content:I.content,isError:I.is_error,timestamp:new Date(S.timestamp||Date.now()),toolUseResult:S.toolUseResult||null});for(const S of c)if(!S.isMeta){if(S.message?.role==="user"&&S.message?.content){let I="",F="user";if(Array.isArray(S.message.content)){const Q=[];for(const ce of S.message.content)ce.type==="text"&&Q.push(Jt(ce.text));I=Q.join(`
71
+ `)}else typeof S.message.content=="string"?I=Jt(S.message.content):I=Jt(String(S.message.content));const be=I.match(/<command-name>(\/[^<]+)<\/command-name>/);be&&(I=be[1]),!I||I.startsWith("<command-args>")||I.startsWith("<local-command-stdout>")||I.startsWith("<system-reminder>")||I.startsWith("Caveat:")||I.startsWith("This session is being continued from a previous")||I.startsWith("[Request interrupted")||(I=I.replace(/(\n\n)?\[Images provided at the following paths:\]\n[\s\S]*$/,""),I=jr(I),I&&k.push({type:F,content:I,timestamp:S.timestamp||new Date().toISOString()}))}else if(S.type==="thinking"&&S.message?.content)k.push({type:"assistant",content:jr(S.message.content),timestamp:S.timestamp||new Date().toISOString(),isThinking:!0});else if(S.type==="tool_use"&&S.toolName)k.push({type:"assistant",content:"",timestamp:S.timestamp||new Date().toISOString(),isToolUse:!0,toolName:S.toolName,toolInput:S.toolInput||"",toolCallId:S.toolCallId});else if(S.type==="tool_result"){for(let I=k.length-1;I>=0;I--)if(k[I].isToolUse&&!k[I].toolResult&&(!S.toolCallId||k[I].toolCallId===S.toolCallId)){k[I].toolResult={content:S.output||"",isError:!1};break}}else if(S.message?.role==="assistant"&&S.message?.content){if(Array.isArray(S.message.content)){for(const I of S.message.content)if(I.type==="text"){let F=I.text;typeof F=="string"&&(F=jr(F)),k.push({type:"assistant",content:F,timestamp:S.timestamp||new Date().toISOString()})}else if(I.type==="tool_use"){const F=C.get(I.id);k.push({type:"assistant",content:"",timestamp:S.timestamp||new Date().toISOString(),isToolUse:!0,toolName:I.name,toolInput:JSON.stringify(I.input),toolResult:F?{content:typeof F.content=="string"?F.content:JSON.stringify(F.content),isError:F.isError,toolUseResult:F.toolUseResult}:null,toolError:F?.isError||!1,toolResultTimestamp:F?.timestamp||new Date})}}else if(typeof S.message.content=="string"){let I=S.message.content;I=jr(I),k.push({type:"assistant",content:I,timestamp:S.timestamp||new Date().toISOString()})}}}return k},Or=r.useMemo(()=>Cs(X),[X]),wt=r.useCallback(()=>{ne.current&&(ne.current.scrollTop=ne.current.scrollHeight)},[]),hr=r.useCallback(()=>{if(!ne.current)return!1;const{scrollTop:c,scrollHeight:k,clientHeight:C}=ne.current;return k-c-C<50},[]),Es=r.useCallback(async c=>{if(!c||ie.current||Me||!We||!s||!t)return!1;ie.current=!0;const k=c.scrollHeight,C=c.scrollTop;try{const S=await nr(t.name,s.id,!0,"claude");return S.length>0?(xe.current={height:k,top:C},G(I=>[...S,...I]),!0):!1}finally{ie.current=!1}},[We,Me,s,t,nr]),or=r.useCallback(async()=>{if(ne.current){const c=ne.current,k=hr();Pt(!k),c.scrollTop<100?ye.current||await Es(c)&&(ye.current=!0):ye.current=!1}},[hr,Es]);r.useLayoutEffect(()=>{if(!xe.current||!ne.current)return;const{height:c,top:k}=xe.current,C=ne.current,I=C.scrollHeight-c;C.scrollTop=k+Math.max(I,0),xe.current=null,setTimeout(()=>{ne.current&&ne.current.scrollTop>=100&&(ye.current=!1)},300)},[se.length]),r.useEffect(()=>{(async()=>{if(s&&t){const k=localStorage.getItem("selected-provider")||"claude";B.current=!0;const C=A!==null&&A!==s.id;if(C?(_e(0),De(!1),$e(0),qt(null),_(!1),a&&o&&o({type:"check-session-status",sessionId:s.id,provider:k})):A===null&&(_e(0),De(!1),$e(0),a&&o&&o({type:"check-session-status",sessionId:s.id,provider:k})),ae(s.id),ze)J(!1);else{const S=await nr(t.name,s.id,!1,"claude");G(S),C&&te(Cs(S))}}else!ze&&!de&&(te([]),G([]),pe.current=[]),ae(null),_e(0),De(!1),$e(0);setTimeout(()=>{B.current=!1},250)})()},[s,t,wt,ze]),r.useEffect(()=>{p>0&&s&&t&&(async()=>{try{const k=await nr(t.name,s.id,!1,"claude");G(k),R&&hr()&&setTimeout(()=>wt(),200)}catch(k){console.error("Error reloading messages from external update:",k)}})()},[p,s,t,nr,hr,R,wt]),r.useEffect(()=>{X.length>0&&!de&&te(c=>{const k=new Map;for(const F of c)F.type==="user"&&F.images?.length>0&&k.set(F.content,F.images);const C=new Map;for(const F of pe.current)if(F.messageContent){const be=F.images.map(Q=>({id:Q.id,name:Q.name})),ge=C.get(F.messageContent)||[];C.set(F.messageContent,[...ge,...be])}const S=k.size>0,I=C.size>0;return!S&&!I?Or:Or.map(F=>F.type!=="user"?F:S&&k.has(F.content)?{...F,images:k.get(F.content)}:I&&C.has(F.content)?{...F,images:C.get(F.content)}:F)})},[Or,X,de]),r.useEffect(()=>{i&&i(fe)},[fe,i]),r.useEffect(()=>{t&&z!==""?rt.setItem(`draft_input_${t.name}`,z):t&&z===""&&rt.removeItem(`draft_input_${t.name}`)},[z,t]),r.useEffect(()=>{t&&se.length>0&&rt.setItem(`chat_messages_${t.name}`,JSON.stringify(se))},[se,t]),r.useEffect(()=>{if(t){const c=rt.getItem(`draft_input_${t.name}`)||"";c!==z&&me(c)}},[t?.name]),r.useEffect(()=>{A&&de&&h&&h(A)},[de,A,h]),r.useEffect(()=>{A&&v&&v.has(A)&&!de&&(_(!0),dt(!0))},[A,v]),r.useEffect(()=>{if(n.length>0){const c=n[n.length-1];if(!["projects_updated","session-created","claude-complete"].includes(c.type)&&c.sessionId&&A&&c.sessionId!==A){console.log("⏭️ Skipping message for different session:",c.sessionId,"current:",A);return}switch(c.type){case"session-created":c.sessionId&&!A&&(sessionStorage.setItem("pendingSessionId",c.sessionId),J(!0),b&&b(c.sessionId),he(Q=>Q.map(ce=>ce.sessionId?ce:{...ce,sessionId:c.sessionId})));break;case"token-budget":c.data&&qt(c.data);break;case"claude-response":if(c.data.isMeta)return;const S=c.data.message||c.data;if(S&&typeof S=="object"&&S.type){if(S.type==="content_block_delta"&&S.delta?.text){const Q=Jt(S.delta.text);Le.current+=Q,Je.current||(Je.current=setTimeout(()=>{const ce=Le.current;Le.current="",Je.current=null,ce&&te(Se=>{const Oe=[...Se],Ze=Oe[Oe.length-1];return Ze&&Ze.type==="assistant"&&!Ze.isToolUse&&Ze.isStreaming?Ze.content=(Ze.content||"")+ce:Oe.push({type:"assistant",content:ce,timestamp:new Date,isStreaming:!0}),Oe})},100));return}if(S.type==="content_block_stop"){Je.current&&(clearTimeout(Je.current),Je.current=null);const Q=Le.current;Le.current="",Q&&te(ce=>{const Se=[...ce],Oe=Se[Se.length-1];return Oe&&Oe.type==="assistant"&&!Oe.isToolUse&&Oe.isStreaming?Oe.content=(Oe.content||"")+Q:Se.push({type:"assistant",content:Q,timestamp:new Date,isStreaming:!0}),Se}),te(ce=>{const Se=[...ce],Oe=Se[Se.length-1];return Oe&&Oe.type==="assistant"&&Oe.isStreaming&&(Oe.isStreaming=!1),Se});return}}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&A&&c.data.session_id!==A){console.log("🔄 Claude CLI session duplication detected:",{originalSession:A,newSession:c.data.session_id}),J(!0),j&&j(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&!A){console.log("🔄 New session init detected:",{newSession:c.data.session_id}),J(!0),j&&j(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&A&&c.data.session_id===A){console.log("🔄 System init message for current session, ignoring");return}const I=S.role==="user"||c.data.type==="user";if(Array.isArray(S.content)&&!I){for(const Q of S.content)if(Q.type==="tool_use"){const ce=Q.input?JSON.stringify(Q.input,null,2):"";te(Se=>[...Se,{type:"assistant",content:"",timestamp:new Date,isToolUse:!0,toolName:Q.name,toolInput:ce,toolId:Q.id,toolResult:null}])}else if(Q.type==="text"&&Q.text?.trim()){let ce=Jt(Q.text);ce=os(ce),te(Se=>[...Se,{type:"assistant",content:ce,timestamp:new Date}])}}else if(typeof S.content=="string"&&S.content.trim()&&!I){let Q=Jt(S.content);Q=os(Q),te(ce=>[...ce,{type:"assistant",content:Q,timestamp:new Date}])}if(S.role==="user"&&Array.isArray(S.content))for(const Q of S.content)Q.type==="tool_result"&&te(ce=>ce.map(Se=>Se.isToolUse&&Se.toolId===Q.tool_use_id?{...Se,toolResult:{content:Q.content,isError:Q.is_error,timestamp:new Date}}:Se));break;case"claude-output":{const Q=String(c.data||"");Q.trim()&&(Le.current+=Le.current?`
72
+ ${Q}`:Q,Je.current||(Je.current=setTimeout(()=>{const ce=Le.current;Le.current="",Je.current=null,ce&&te(Se=>{const Oe=[...Se],Ze=Oe[Oe.length-1];return Ze&&Ze.type==="assistant"&&!Ze.isToolUse&&Ze.isStreaming?Ze.content=Ze.content?`${Ze.content}
73
+ ${ce}`:ce:Oe.push({type:"assistant",content:ce,timestamp:new Date,isStreaming:!0}),Oe})},100)))}break;case"claude-interactive-prompt":te(Q=>[...Q,{type:"assistant",content:c.data,timestamp:new Date,isInteractivePrompt:!0}]);break;case"claude-permission-request":{if(!c.requestId)break;he(Q=>Q.some(ce=>ce.requestId===c.requestId)?Q:[...Q,{requestId:c.requestId,toolName:c.toolName||"UnknownTool",input:c.input,context:c.context,sessionId:c.sessionId||null,receivedAt:new Date}]),_(!0),dt(!0),Lt({text:"等待权限",tokens:0,can_interrupt:!0});break}case"claude-permission-cancelled":{if(!c.requestId)break;he(Q=>Q.filter(ce=>ce.requestId!==c.requestId));break}case"claude-error":te(Q=>[...Q,{type:"error",content:`错误: ${c.error}`,timestamp:new Date}]),_(!1),dt(!1),Lt(null),he([]),A&&(x&&x(A),m&&m(A));break;case"claude-complete":const F=c.sessionId||A||sessionStorage.getItem("pendingSessionId");(F===A||!A)&&(_(!1),dt(!1),Lt(null)),F&&(x&&x(F),m&&m(F));const be=sessionStorage.getItem("pendingSessionId");be&&!A&&c.exitCode===0&&(ae(be),sessionStorage.removeItem("pendingSessionId"),console.log("✅ New session complete, ID set to:",be)),t&&c.exitCode===0&&rt.removeItem(`chat_messages_${t.name}`),F===A&&he([]),ve.current.delete(F);break;case"session-aborted":{const Q=c.sessionId||A;Q===A&&(_(!1),dt(!1),Lt(null)),Q&&(x&&x(Q),m&&m(Q)),he([]),te(ce=>[...ce,{type:"assistant",content:"会话已被用户中断。",timestamp:new Date}]);break}case"session-status":{const Q=c.sessionId;(Q===A||s&&Q===s.id)&&c.isProcessing&&(_(!0),dt(!0),h&&h(Q));break}case"claude-status":const ge=c.data;if(ge){let Q={text:"处理中...",tokens:0,can_interrupt:!0};ge.message?Q.text=ge.message:ge.status?Q.text=ge.status:typeof ge=="string"&&(Q.text=ge),ge.tokens?Q.tokens=ge.tokens:ge.token_count&&(Q.tokens=ge.token_count),ge.can_interrupt!==void 0&&(Q.can_interrupt=ge.can_interrupt),Lt(Q),_(!0),dt(Q.can_interrupt)}break}}},[n]),r.useEffect(()=>{t&&Ba()},[t]);const Ba=async()=>{try{const c=await ke.getFiles(t.name);if(c.ok){const k=await c.json(),C=Ms(k);Ir(C)}}catch(c){console.error("Error fetching files:",c)}},Ms=(c,k="")=>{let C=[];for(const S of c){const I=k?`${k}/${S.name}`:S.name;S.type==="directory"&&S.children?C=C.concat(Ms(S.children,I)):S.type==="file"&&C.push({name:S.name,path:I,relativePath:S.path})}return C};r.useEffect(()=>{const c=z.slice(0,Xt),k=c.lastIndexOf("@");if(k!==-1){const C=c.slice(k+1);if(C.includes(" "))Rt(!1),Ut(-1);else{Ut(k),Rt(!0);const S=St.filter(I=>I.name.toLowerCase().includes(C.toLowerCase())||I.path.toLowerCase().includes(C.toLowerCase())).slice(0,10);Tr(S),Zt(-1)}}else Rt(!1),Ut(-1)},[z,Xt,St]),r.useEffect(()=>{const c=setTimeout(()=>{Dr(z)},150);return()=>clearTimeout(c)},[z]);const Ls=r.useMemo(()=>se.length<=ar?se:se.slice(-ar),[se,ar]);r.useEffect(()=>{if(!R&&ne.current){const c=ne.current;tr.current={height:c.scrollHeight,top:c.scrollTop}}}),r.useEffect(()=>{if(ne.current&&se.length>0)if(R)er||setTimeout(()=>wt(),50);else{const c=ne.current,k=tr.current.height,C=tr.current.top,I=c.scrollHeight-k;I>0&&C>0&&(c.scrollTop=C+I)}},[se.length,er,wt,R]),r.useEffect(()=>{ne.current&&se.length>0&&!B.current&&(Pt(!1),setTimeout(()=>{wt()},200))},[s?.id,t?.name]),r.useEffect(()=>{const c=ne.current;if(c)return c.addEventListener("scroll",or),()=>c.removeEventListener("scroll",or)},[or]),r.useEffect(()=>{if(Y.current){Y.current.style.height="auto",Y.current.style.height=Y.current.scrollHeight+"px";const c=parseInt(window.getComputedStyle(Y.current).lineHeight),k=Y.current.scrollHeight>c*2;Ct(k)}},[]),r.useEffect(()=>{Y.current&&!z.trim()&&(Y.current.style.height="auto",Ct(!1))},[z]),r.useEffect(()=>{if(!t||!s?.id||s.id.startsWith("new-session-")){qt(null);return}(async()=>{try{const k=`/api/projects/${t.name}/sessions/${s.id}/token-usage`,C=await Z(k);if(C.ok){const S=await C.json();qt(S)}else qt(null)}catch(k){console.error("Failed to fetch initial token usage:",k)}})()},[s?.id,s?.__provider,t?.path]);const Ua=r.useCallback(c=>{c.trim()&&me(k=>{const C=k.trim()?`${k} ${c}`:c;return setTimeout(()=>{if(Y.current){Y.current.style.height="auto",Y.current.style.height=Y.current.scrollHeight+"px";const S=parseInt(window.getComputedStyle(Y.current).lineHeight),I=Y.current.scrollHeight>S*2;Ct(I)}},0),C})},[]),Ha=r.useCallback(()=>{Pa(c=>c+100)},[]),gr=r.useCallback(c=>{const k=c.filter(C=>{try{if(!C||typeof C!="object")return console.warn("Invalid file object:",C),!1;if(!C.type||!C.type.startsWith("image/"))return!1;if(!C.size||C.size>5242880){const S=C.name||"Unknown file";return Ce(I=>{const F=new Map(I);return F.set(S,"文件太大(最大 5MB)"),F}),!1}return!0}catch(S){return console.error("Error validating file:",S,C),!1}});k.length>0&&V(C=>[...C,...k].slice(0,5))},[]),qa=r.useCallback(async c=>{const k=c.target.files;if(!(!k||k.length===0||!t)){ee(!0);try{const C=new FormData;Array.from(k).forEach(F=>{C.append("files",F)});const S=await ke.uploadFiles(t.name,C);if(!S.ok){const F=await S.json();throw new Error(F.error||"上传失败")}const I=await S.json();if(I.files&&I.files.length>0){const F=I.files.map(ge=>`@${ge.name}`).join(" "),be=z?`${z} ${F} `:`${F} `;me(be),Y.current&&Y.current.focus()}}catch(C){console.error("File upload failed:",C)}finally{ee(!1),U.current&&(U.current.value="")}}},[t,z]),Ja=r.useCallback(async c=>{const k=Array.from(c.clipboardData.items);for(const C of k)if(C.type.startsWith("image/")){const S=C.getAsFile();S&&gr([S])}if(k.length===0&&c.clipboardData.files.length>0){const S=Array.from(c.clipboardData.files).filter(I=>I.type.startsWith("image/"));S.length>0&&gr(S)}},[gr]),{getRootProps:Ka,getInputProps:Ga,isDragActive:Va,open:Ya}=gs({accept:{"image/*":[".png",".jpg",".jpeg",".gif",".webp",".svg"]},maxSize:5*1024*1024,maxFiles:5,onDrop:gr,noClick:!0,noKeyboard:!0}),$t=r.useCallback(async c=>{if(c.preventDefault(),!z.trim()||de||!t||re.current)return;re.current=!0;const k=z.trim();if(k.startsWith("/")){const ce=k.indexOf(" "),Se=ce!==-1?k.slice(0,ce):k,Oe=et.find(Ze=>Ze.name===Se&&Ze.namespace==="builtin");if(Oe){re.current=!1,xr(Oe);return}}if($){const ce=await $();if(ce&&!ce.allowed){re.current=!1,L?.(ce.reason);return}}let C=[],S=null;if(Ue.length>0){const ce=new FormData;Ue.forEach(Se=>{ce.append("images",Se)});try{const Se=await Z(`/api/projects/${t.name}/upload-images`,{method:"POST",headers:{},body:ce});if(!Se.ok)throw new Error("图片上传失败");const Oe=await Se.json();C=Oe.images,S=Oe.uploadBatchId||null}catch(Se){console.error("Image upload failed:",Se),re.current=!1,te(Oe=>[...Oe,{type:"error",content:`图片上传失败: ${Se.message}`,timestamp:new Date}]);return}}const I={type:"user",content:z,images:C,timestamp:new Date};te(ce=>[...ce,I]),_(!0),re.current=!1,dt(!0),Lt({text:"处理中",tokens:0,can_interrupt:!0}),Pt(!1),setTimeout(()=>wt(),100);const be=A||s?.id||`new-session-${Date.now()}`;d&&d(be);const Q=(()=>{try{const ce=rt.getItem("claude-settings");if(ce)return JSON.parse(ce)}catch(ce){console.error("Error loading tools settings:",ce)}return{allowedTools:[],disallowedTools:[],skipPermissions:!1}})();o({type:"claude-command",command:z,options:{projectPath:t.path,cwd:t.fullPath,sessionId:A,resume:!!A,toolsSettings:Q,permissionMode:q,model:ut,images:C,uploadBatchId:S}}),me(""),V([]),Ie(new Map),Ce(new Map),Ct(!1),Y.current&&(Y.current.style.height="auto"),t&&rt.removeItem(`draft_input_${t.name}`)},[z,de,t,Ue,A,s,jt,q,d,ut,o,me,V,Ie,Ce,Ct,Y,te,_,dt,Lt,Pt,wt,$,L,xr,et]),Ds=r.useCallback(c=>!c||jt!=="claude"?{success:!1}:gi(c.entry),[jt]),ir=r.useCallback((c,k)=>{const S=(Array.isArray(c)?c:[c]).filter(Boolean);S.length!==0&&(S.forEach(I=>{o({type:"claude-permission-response",requestId:I,allow:!!k?.allow,updatedInput:k?.updatedInput,message:k?.message,rememberEntry:k?.rememberEntry})}),he(I=>{const F=I.filter(be=>!S.includes(be.requestId));return F.length===0&&Lt(null),F}))},[o]);r.useEffect(()=>{Ar.current=$t},[$t]);const Is=c=>{if(!c)return;const k=z.slice(0,Ss),C=z.slice(Ss),S=C.indexOf(" "),I=S!==-1?C.slice(S):"",F=k+c.name+" "+I;me(F),mt(!1),Mt(-1),nt(""),Et(-1),st.current&&clearTimeout(st.current),xr(c)},Qa=c=>{if(vt&&H.length>0){if(c.key==="ArrowDown"){c.preventDefault(),Et(k=>k<H.length-1?k+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),Et(k=>k>0?k-1:H.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),Pr>=0?Is(H[Pr]):H.length>0&&Is(H[0]);return}if(c.key==="Escape"){c.preventDefault(),mt(!1),Mt(-1),nt(""),Et(-1),st.current&&clearTimeout(st.current);return}}if(ft&&ot.length>0){if(c.key==="ArrowDown"){c.preventDefault(),Zt(k=>k<ot.length-1?k+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),Zt(k=>k>0?k-1:ot.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),bt>=0?_r(ot[bt]):ot.length>0&&_r(ot[0]);return}if(c.key==="Escape"){c.preventDefault(),Rt(!1);return}}if(c.key==="Tab"&&!ft&&!vt){c.preventDefault();const k=["default","acceptEdits","bypassPermissions","plan"],S=(k.indexOf(q)+1)%k.length,I=k[S];w(I),s?.id&&localStorage.setItem(`permissionMode-${s.id}`,I);return}if(c.key==="Enter"){if(c.nativeEvent.isComposing)return;(c.ctrlKey||c.metaKey)&&!c.shiftKey?(c.preventDefault(),$t(c)):!c.shiftKey&&!c.ctrlKey&&!c.metaKey&&(g||(c.preventDefault(),$t(c)))}},_r=c=>{const k=z.slice(0,pr),C=z.slice(pr),S=C.indexOf(" "),I=S!==-1?C.slice(S):"",F=k+"@"+c.path+" "+I,be=k.length+1+c.path.length+1;Y.current&&!Y.current.matches(":focus")&&Y.current.focus(),me(F),Bt(be),Rt(!1),Ut(-1),Y.current&&requestAnimationFrame(()=>{Y.current&&(Y.current.setSelectionRange(be,be),Y.current.matches(":focus")||Y.current.focus())})},Za=c=>{const k=c.target.value,C=c.target.selectionStart;if(!A&&k.trim(),me(k),Bt(C),!k.trim()){c.target.style.height="auto",Ct(!1),mt(!1),Mt(-1),nt("");return}const S=k.slice(0,C);if((S.match(/```/g)||[]).length%2===1){mt(!1),Mt(-1),nt("");return}const be=/(^|\s)\/(\S*)$/,ge=S.match(be);if(ge){const Q=ge.index+ge[1].length,ce=ge[2];Mt(Q),mt(!0),Et(-1),st.current&&clearTimeout(st.current),st.current=setTimeout(()=>{nt(ce)},150)}else mt(!1),Mt(-1),nt(""),st.current&&clearTimeout(st.current)},Xa=c=>{Bt(c.target.selectionStart)},en=()=>{A&&Rr&&o({type:"abort-session",sessionId:A,provider:jt})},tn=()=>{const c=["default","acceptEdits","bypassPermissions","plan"],C=(c.indexOf(q)+1)%c.length,S=c[C];w(S),s?.id&&localStorage.setItem(`permissionMode-${s.id}`,S)};return t?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
74
74
  details[open] .details-chevron {
75
75
  transform: rotate(180deg);
76
76
  }
77
- `}),e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{ref:ne,onWheel:ar,onTouchMove:ar,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:[Pe&&se.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:"正在加载会话消息..."})]})}):se.length===0?e.jsxs("div",{className:"flex items-center justify-center h-full",children:[!s&&!A&&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(ht,{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:dt,onChange:c=>{const k=c.target.value;Pr(k),localStorage.setItem("claude-model",k)},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:vr.OPTIONS.map(({value:c,label:k})=>e.jsx("option",{value:c,children:k},c))})]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["已准备好使用 Claude ",dt,"。请在下方输入您的消息。"]})]}),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:[Le&&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:"正在加载历史消息..."})]})}),We&&!Le&&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:je>0&&e.jsxs("span",{children:["显示 ",Z.length," 条 / 共 ",je," 条消息 •",e.jsx("span",{className:"text-xs",children:"向上滚动加载更多"})]})}),!We&&se.length>rr&&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:["显示最近 ",rr," 条消息(共 ",se.length," 条) •",e.jsx("button",{className:"ml-1 text-blue-600 hover:text-blue-700 underline",onClick:Ua,children:"加载更早的消息"})]}),Ms.map((c,k)=>{const C=k>0?Ms[k-1]:null,N=c.id||`${c.type}-${c.timestamp?.getTime?.()||k}-${k}`;return e.jsx(vi,{message:c,index:k,prevMessage:C,createDiff:_a,onFileOpen:l,onShowSettings:f,onGrantToolPermission:Ls,autoExpandTools:E,showRawParameters:O,showThinking:T,selectedProject:t,provider:vt},N)})]}),de&&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(ht,{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:we})]}),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(di,{status:Pa,isLoading:de,onAbort:Xa,provider:vt,showThinking:T})}),e.jsxs("div",{ref:M,className:"max-w-4xl mx-auto mb-3",children:[K.length>0&&e.jsx("div",{className:"mb-3 space-y-2",children:K.map(c=>{const k=Xs(c.input),C=os(c.toolName,k),N=gs(),D=C?N.allowedTools.includes(C):!1,F=D?"已允许(已保存)":"允许并记住",be=C?K.filter(ge=>os(ge.toolName,Xs(ge.input))===C).map(ge=>ge.requestId):[c.requestId];return c.toolName==="AskUserQuestion"?e.jsx(bi,{request:c,onSubmit:ge=>{nr(c.requestId,{allow:!0,updatedInput:{...c.input,answers:ge}})},onSkip:()=>nr(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})]})]}),C&&e.jsxs("div",{className:"text-xs text-amber-700 dark:text-amber-300",children:["允许规则: ",e.jsx("span",{className:"font-mono",children:C})]})]}),k&&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:k})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>nr(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:()=>{C&&!D&&Ls({entry:C,toolName:c.toolName}),nr(be,{allow:!0,rememberEntry:C})},className:`inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border transition-colors ${C?"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:!C,children:F}),e.jsx("button",{type:"button",onClick:()=>nr(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:en,className:`px-3 py-1.5 rounded-lg text-sm font-medium border transition-all duration-200 ${q==="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":q==="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":q==="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 ${q==="default"?"bg-gray-500":q==="acceptEdits"?"bg-green-500":q==="bypassPermissions"?"bg-orange-500":"bg-blue-500"}`}),e.jsxs("span",{children:[q==="default"&&"默认模式",q==="acceptEdits"&&"接受编辑",q==="bypassPermissions"&&"跳过权限",q==="plan"&&"计划模式"]})]})}),e.jsx("button",{ref:I,type:"button",onClick:()=>tr(!Ht),className:"px-3 py-1.5 rounded-lg text-sm font-medium border transition-all duration-200 bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300 border-purple-300 dark:border-purple-600 hover:bg-purple-100 dark:hover:bg-purple-900/30",title:"切换模型",children:e.jsxs("div",{className:"flex items-center gap-1.5",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.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),e.jsx("span",{children:vr.OPTIONS.find(c=>c.value===dt)?.label||dt})]})}),z.trim()&&e.jsx("button",{type:"button",onClick:c=>{c.preventDefault(),c.stopPropagation(),me(""),Y.current&&(Y.current.style.height="auto",Y.current.focus()),Nt(!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"})})}),Xt&&se.length>0&&e.jsx("button",{onClick:yt,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:Tt,className:"relative max-w-4xl mx-auto",children:[Ga&&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:"将图片拖放到这里"})]})}),Ue.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:Ue.map((c,k)=>e.jsx(yi,{file:c,onRemove:()=>{V(C=>C.filter((N,D)=>D!==k))},uploadProgress:oe.get(c.name),error:Re.get(c.name)},k))})}),gt&&at.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:at.map((c,k)=>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 ${k===Ft?"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:C=>{C.preventDefault(),C.stopPropagation()},onClick:C=>{C.preventDefault(),C.stopPropagation(),Or(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(pi,{commands:Ee,selectedIndex:Rr,onSelect:za,onClose:()=>{pt(!1),Ct(-1),kt(""),St(-1)},position:{top:Y.current?Math.max(16,Y.current.getBoundingClientRect().top-316):0,left:Y.current?Y.current.getBoundingClientRect().left:16,bottom:Y.current?window.innerHeight-Y.current.getBoundingClientRect().top+8:90},isOpen:er,frequentCommands:nt?[]:$a}),Ht&&e.jsxs("div",{ref:ft,className:"rounded-lg border border-purple-200 dark:border-purple-800 bg-purple-50 dark:bg-purple-900/20 p-4 shadow-lg",style:{position:"fixed",bottom:I.current?window.innerHeight-I.current.getBoundingClientRect().top+8:90,left:I.current?I.current.getBoundingClientRect().left:16,zIndex:1e3,minWidth:"200px"},children:[e.jsx("div",{className:"text-sm font-semibold text-purple-900 dark:text-purple-100 mb-3",children:"切换模型"}),e.jsx("select",{value:dt,onChange:c=>{const k=c.target.value;Pr(k),localStorage.setItem("claude-model",k),tr(!1)},className:"w-full pl-3 pr-8 py-2 text-sm bg-white dark:bg-gray-800 border border-purple-300 dark:border-purple-600 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500 text-gray-900 dark:text-gray-100",children:vr.OPTIONS.map(({value:c,label:k})=>e.jsx("option",{value:c,children:k},c))})]}),e.jsxs("div",{...Ja(),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 ${Ta?"chat-input-expanded":""}`,children:[e.jsx("input",{...Ka()}),e.jsx("textarea",{ref:Y,value:z,onChange:Qa,onClick:Za,onKeyDown:Ya,onPaste:qa,onFocus:()=>ue(!0),onBlur:()=>ue(!1),onInput:c=>{c.target.style.height="auto",c.target.style.height=c.target.scrollHeight+"px",Wt(c.target.selectionStart);const k=parseInt(window.getComputedStyle(c.target).lineHeight),C=c.target.scrollHeight>k*2;Nt(C)},placeholder:y&&!y.allowed?y.reason==="total_limit_exceeded"?"使用上限已达到,请联系管理员":"今日使用上限已达到":"输入 / 使用命令,@ 引用文件,或向 Claude 提问...",disabled:de||y&&!y.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:Va,disabled:y&&!y.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:y&&!y.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:H,onChange:Ha,className:"hidden",multiple:!0}),e.jsx("button",{type:"button",onClick:()=>H.current?.click(),disabled:S||!t||y&&!y.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:y&&!y.allowed?"使用上限已达到":"上传文件并引用",children:S?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(ui,{onTranscript:Ba,className:"w-10 h-10 sm:w-10 sm:h-10"})}),e.jsx("button",{type:"submit",disabled:!z.trim()||de,onMouseDown:c=>{c.preventDefault(),Tt(c)},onTouchStart:c=>{c.preventDefault(),Tt(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 ${z.trim()?"opacity-0":"opacity-100"}`,children:g?"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 wi=it.memo(ji);function is({file:t,onClose:s,projectPath:a,isSidebar:o=!1,isExpanded:n=!1,onToggleExpand:l=null}){const{showAlert:i}=ct(),[d,x]=r.useState(""),[h,m]=r.useState(!0),[v,b]=r.useState(!1),[j,f]=r.useState(!1),[E,O]=r.useState(()=>{const _=localStorage.getItem("codeEditorTheme");return _?_==="dark":!0}),[T,R]=r.useState(!1),[g,p]=r.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[u,y]=r.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[L,$]=r.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),P=r.useRef(null),z=r.useMemo(()=>{const _=()=>{const A=document.createElement("div");A.className="cm-editor-toolbar-panel";const ae=()=>{let fe='<div style="display: flex; align-items: center; justify-content: flex-end; width: 100%;">';fe+='<div style="display: flex; align-items: center; gap: 4px;">',fe+=`
77
+ `}),e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{ref:ne,onWheel:or,onTouchMove:or,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:[Pe&&se.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:"正在加载会话消息..."})]})}):se.length===0?e.jsxs("div",{className:"flex items-center justify-center h-full",children:[!s&&!A&&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(gt,{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:ut,onChange:c=>{const k=c.target.value;$r(k),localStorage.setItem("claude-model",k)},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:yr.OPTIONS.map(({value:c,label:k})=>e.jsx("option",{value:c,children:k},c))})]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["已准备好使用 Claude ",ut,"。请在下方输入您的消息。"]})]}),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:[Me&&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:"正在加载历史消息..."})]})}),We&&!Me&&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:je>0&&e.jsxs("span",{children:["显示 ",X.length," 条 / 共 ",je," 条消息 •",e.jsx("span",{className:"text-xs",children:"向上滚动加载更多"})]})}),!We&&se.length>ar&&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:["显示最近 ",ar," 条消息(共 ",se.length," 条) •",e.jsx("button",{className:"ml-1 text-blue-600 hover:text-blue-700 underline",onClick:Ha,children:"加载更早的消息"})]}),Ls.map((c,k)=>{const C=k>0?Ls[k-1]:null,S=c.id||`${c.type}-${c.timestamp?.getTime?.()||k}-${k}`;return e.jsx(vi,{message:c,index:k,prevMessage:C,createDiff:Fa,onFileOpen:l,onShowSettings:f,onGrantToolPermission:Ds,autoExpandTools:E,showRawParameters:O,showThinking:T,selectedProject:t,provider:jt},S)})]}),de&&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(gt,{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:we})]}),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(di,{status:$a,isLoading:de,onAbort:en,provider:jt,showThinking:T})}),e.jsxs("div",{ref:M,className:"max-w-4xl mx-auto mb-3",children:[K.length>0&&e.jsx("div",{className:"mb-3 space-y-2",children:K.map(c=>{const k=ea(c.input),C=is(c.toolName,k),S=fs(),I=C?S.allowedTools.includes(C):!1,F=I?"已允许(已保存)":"允许并记住",be=C?K.filter(ge=>is(ge.toolName,ea(ge.input))===C).map(ge=>ge.requestId):[c.requestId];return c.toolName==="AskUserQuestion"?e.jsx(bi,{request:c,onSubmit:ge=>{ir(c.requestId,{allow:!0,updatedInput:{...c.input,answers:ge}})},onSkip:()=>ir(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})]})]}),C&&e.jsxs("div",{className:"text-xs text-amber-700 dark:text-amber-300",children:["允许规则: ",e.jsx("span",{className:"font-mono",children:C})]})]}),k&&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:k})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ir(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:()=>{C&&!I&&Ds({entry:C,toolName:c.toolName}),ir(be,{allow:!0,rememberEntry:C})},className:`inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border transition-colors ${C?"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:!C,children:F}),e.jsx("button",{type:"button",onClick:()=>ir(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:tn,className:`px-3 py-1.5 rounded-lg text-sm font-medium border transition-all duration-200 ${q==="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":q==="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":q==="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 ${q==="default"?"bg-gray-500":q==="acceptEdits"?"bg-green-500":q==="bypassPermissions"?"bg-orange-500":"bg-blue-500"}`}),e.jsxs("span",{children:[q==="default"&&"默认模式",q==="acceptEdits"&&"接受编辑",q==="bypassPermissions"&&"跳过权限",q==="plan"&&"计划模式"]})]})}),e.jsx("button",{ref:yt,type:"button",onClick:()=>rr(!Ht),className:"px-3 py-1.5 rounded-lg text-sm font-medium border transition-all duration-200 bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300 border-purple-300 dark:border-purple-600 hover:bg-purple-100 dark:hover:bg-purple-900/30",title:"切换模型",children:e.jsxs("div",{className:"flex items-center gap-1.5",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.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),e.jsx("span",{children:yr.OPTIONS.find(c=>c.value===ut)?.label||ut})]})}),z.trim()&&e.jsx("button",{type:"button",onClick:c=>{c.preventDefault(),c.stopPropagation(),me(""),Y.current&&(Y.current.style.height="auto",Y.current.focus()),Ct(!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"})})}),er&&se.length>0&&e.jsx("button",{onClick:wt,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:$t,className:"relative max-w-4xl mx-auto",children:[Va&&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:"将图片拖放到这里"})]})}),Ue.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:Ue.map((c,k)=>e.jsx(yi,{file:c,onRemove:()=>{V(C=>C.filter((S,I)=>I!==k))},uploadProgress:oe.get(c.name),error:Te.get(c.name)},k))})}),ft&&ot.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:ot.map((c,k)=>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 ${k===bt?"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:C=>{C.preventDefault(),C.stopPropagation()},onClick:C=>{C.preventDefault(),C.stopPropagation(),_r(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(pi,{commands:H,selectedIndex:Pr,onSelect:Aa,onClose:()=>{mt(!1),Mt(-1),nt(""),Et(-1)},position:{top:Y.current?Math.max(16,Y.current.getBoundingClientRect().top-316):0,left:Y.current?Y.current.getBoundingClientRect().left:16,bottom:Y.current?window.innerHeight-Y.current.getBoundingClientRect().top+8:90},isOpen:vt,frequentCommands:Re?[]:za}),Ht&&e.jsxs("div",{ref:sr,className:"rounded-lg border border-purple-200 dark:border-purple-800 bg-purple-50 dark:bg-purple-900/20 p-4 shadow-lg",style:{position:"fixed",bottom:yt.current?window.innerHeight-yt.current.getBoundingClientRect().top+8:90,left:yt.current?yt.current.getBoundingClientRect().left:16,zIndex:1e3,minWidth:"200px"},children:[e.jsx("div",{className:"text-sm font-semibold text-purple-900 dark:text-purple-100 mb-3",children:"切换模型"}),e.jsx("select",{value:ut,onChange:c=>{const k=c.target.value;$r(k),localStorage.setItem("claude-model",k),rr(!1)},className:"w-full pl-3 pr-8 py-2 text-sm bg-white dark:bg-gray-800 border border-purple-300 dark:border-purple-600 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500 text-gray-900 dark:text-gray-100",children:yr.OPTIONS.map(({value:c,label:k})=>e.jsx("option",{value:c,children:k},c))})]}),e.jsxs("div",{...Ka(),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 ${xt?"chat-input-expanded":""}`,children:[e.jsx("input",{...Ga()}),e.jsx("textarea",{ref:Y,value:z,onChange:Za,onClick:Xa,onKeyDown:Qa,onPaste:Ja,onFocus:()=>ue(!0),onBlur:()=>ue(!1),onInput:c=>{c.target.style.height="auto",c.target.style.height=c.target.scrollHeight+"px",Bt(c.target.selectionStart);const k=parseInt(window.getComputedStyle(c.target).lineHeight),C=c.target.scrollHeight>k*2;Ct(C)},placeholder:y&&!y.allowed?y.reason==="total_limit_exceeded"?"使用上限已达到,请联系管理员":"今日使用上限已达到":"输入 / 使用命令,@ 引用文件,或向 Claude 提问...",disabled:de||y&&!y.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:Ya,disabled:y&&!y.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:y&&!y.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:U,onChange:qa,className:"hidden",multiple:!0}),e.jsx("button",{type:"button",onClick:()=>U.current?.click(),disabled:N||!t||y&&!y.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:y&&!y.allowed?"使用上限已达到":"上传文件并引用",children:N?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(ui,{onTranscript:Ua,className:"w-10 h-10 sm:w-10 sm:h-10"})}),e.jsx("button",{type:"submit",disabled:!z.trim()||de,onMouseDown:c=>{c.preventDefault(),$t(c)},onTouchStart:c=>{c.preventDefault(),$t(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 ${z.trim()?"opacity-0":"opacity-100"}`,children:g?"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 wi=it.memo(ji);function ls({file:t,onClose:s,projectPath:a,isSidebar:o=!1,isExpanded:n=!1,onToggleExpand:l=null}){const{showAlert:i}=ct(),[d,x]=r.useState(""),[h,m]=r.useState(!0),[v,b]=r.useState(!1),[j,f]=r.useState(!1),[E,O]=r.useState(()=>{const _=localStorage.getItem("codeEditorTheme");return _?_==="dark":!0}),[T,R]=r.useState(!1),[g,p]=r.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[u,y]=r.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[L,$]=r.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),P=r.useRef(null),z=r.useMemo(()=>{const _=()=>{const A=document.createElement("div");A.className="cm-editor-toolbar-panel";const ae=()=>{let fe='<div style="display: flex; align-items: center; justify-content: flex-end; width: 100%;">';fe+='<div style="display: flex; align-items: center; gap: 4px;">',fe+=`
78
78
  <button class="cm-toolbar-btn cm-settings-btn" title="Editor Settings">
79
79
  <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
80
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" />
@@ -86,7 +86,7 @@ ${ce}`:ce:Oe.push({type:"assistant",content:ce,timestamp:new Date,isStreaming:!0
86
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
87
  </svg>
88
88
  </button>
89
- `),fe+="</div>",fe+="</div>",A.innerHTML=fe,A.querySelector(".cm-settings-btn")?.addEventListener("click",()=>{window.openSettings&&window.openSettings("appearance")}),o&&l&&A.querySelector(".cm-expand-btn")?.addEventListener("click",()=>{l()})};return ae(),{top:!0,dom:A,update:ae}};return[tn.of(_)]},[o,n,l]),me=_=>{const A=_.split(".").pop()?.toLowerCase();switch(A){case"js":case"jsx":case"ts":case"tsx":return[mn({jsx:!0,typescript:A.includes("ts")})];case"py":return[dn()];case"html":case"htm":return[cn()];case"css":case"scss":case"less":return[ln()];case"json":return[on()];case"md":case"markdown":return[nn()];default:return[]}};r.useEffect(()=>{(async()=>{try{m(!0);const A=await ke.readFile(t.projectName,t.path);if(!A.ok)throw new Error(`Failed to load file: ${A.status} ${A.statusText}`);const ae=await A.json();x(ae.content)}catch(A){console.error("Error loading file:",A),x(`// Error loading file: ${A.message}
89
+ `),fe+="</div>",fe+="</div>",A.innerHTML=fe,A.querySelector(".cm-settings-btn")?.addEventListener("click",()=>{window.openSettings&&window.openSettings("appearance")}),o&&l&&A.querySelector(".cm-expand-btn")?.addEventListener("click",()=>{l()})};return ae(),{top:!0,dom:A,update:ae}};return[rn.of(_)]},[o,n,l]),me=_=>{const A=_.split(".").pop()?.toLowerCase();switch(A){case"js":case"jsx":case"ts":case"tsx":return[un({jsx:!0,typescript:A.includes("ts")})];case"py":return[mn()];case"html":case"htm":return[dn()];case"css":case"scss":case"less":return[cn()];case"json":return[ln()];case"md":case"markdown":return[on()];default:return[]}};r.useEffect(()=>{(async()=>{try{m(!0);const A=await ke.readFile(t.projectName,t.path);if(!A.ok)throw new Error(`Failed to load file: ${A.status} ${A.statusText}`);const ae=await A.json();x(ae.content)}catch(A){console.error("Error loading file:",A),x(`// Error loading file: ${A.message}
90
90
  // File: ${t.name}
91
91
  // Path: ${t.path}`)}finally{m(!1)}})()},[t,a]);const se=async()=>{b(!0);try{console.log("Saving file:",{projectName:t.projectName,path:t.path,contentLength:d?.length});const _=await ke.saveFile(t.projectName,t.path,d);if(console.log("Save response:",{status:_.status,ok:_.ok,contentType:_.headers.get("content-type")}),!_.ok){const ae=_.headers.get("content-type");if(ae&&ae.includes("application/json")){const fe=await _.json();throw new Error(fe.error||`Save failed: ${_.status}`)}else{const fe=await _.text();throw console.error("Non-JSON error response:",fe),new Error(`Save failed: ${_.status} ${_.statusText}`)}}const A=await _.json();console.log("Save successful:",A),R(!0),setTimeout(()=>R(!1),2e3)}catch(_){console.error("Error saving file:",_),i(`保存文件失败: ${_.message}`,{variant:"error"})}finally{b(!1)}},te=()=>{const _=new Blob([d],{type:"text/plain"}),A=URL.createObjectURL(_),ae=document.createElement("a");ae.href=A,ae.download=t.name,document.body.appendChild(ae),ae.click(),document.body.removeChild(ae),URL.revokeObjectURL(A)},de=()=>{f(!j)};return r.useEffect(()=>{localStorage.setItem("codeEditorTheme",E?"dark":"light")},[E]),r.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",g.toString())},[g]),r.useEffect(()=>{const _=()=>{const A=localStorage.getItem("codeEditorTheme");A&&O(A==="dark");const ae=localStorage.getItem("codeEditorWordWrap");ae!==null&&p(ae==="true");const fe=localStorage.getItem("codeEditorLineNumbers");fe!==null&&y(fe!=="false");const ue=localStorage.getItem("codeEditorFontSize");ue&&$(ue)};return window.addEventListener("storage",_),window.addEventListener("codeEditorSettingsChanged",_),()=>{window.removeEventListener("storage",_),window.removeEventListener("codeEditorSettingsChanged",_)}},[]),r.useEffect(()=>{const _=A=>{(A.ctrlKey||A.metaKey)&&(A.key==="s"?(A.preventDefault(),se()):A.key==="Escape"&&(A.preventDefault(),s()))};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[d]),h?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
92
92
  .code-editor-loading {
@@ -121,9 +121,9 @@ ${ce}`:ce:Oe.push({type:"assistant",content:ce,timestamp:new Date,isStreaming:!0
121
121
  .cm-toolbar-btn:hover {
122
122
  background-color: ${E?"#374151":"#f3f4f6"};
123
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 ${j?"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"+(j?" 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:te,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($t,{className:"w-5 h-5 md:w-4 md:h-4"})}),e.jsx("button",{onClick:se,disabled:v,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 ${T?"bg-green-600 hover:bg-green-700":"bg-blue-600 hover:bg-blue-700"}`,children:T?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(ia,{className:"w-5 h-5 md:w-4 md:h-4"}),e.jsx("span",{className:"hidden sm:inline",children:v?"Saving...":"Save"})]})}),!o&&e.jsx("button",{onClick:de,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:j?"Exit fullscreen":"Fullscreen",children:j?e.jsx(kn,{className:"w-4 h-4"}):e.jsx(la,{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(He,{className:"w-6 h-6 md:w-4 md:h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(rn,{ref:P,value:d,onChange:x,extensions:[...me(t.name),...z,...g?[an.lineWrapping]:[]],theme:E?sn:void 0,height:"100%",style:{fontSize:`${L}px`,height:"100%"},basicSetup:{lineNumbers:u,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: ",d.split(`
125
- `).length]}),e.jsxs("span",{children:["Characters: ",d.length]})]}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Press Ctrl+S to save • Esc to close"})]})]})})]})}function ki({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,x]=r.useState(!0);return r.useEffect(()=>{let h;const m=new AbortController;return(async()=>{try{x(!0),i(null),n(null);const b=await X(a,{signal:m.signal});if(!b.ok)throw new Error(`Request failed with status ${b.status}`);const j=await b.blob();h=URL.createObjectURL(j),n(h)}catch(b){if(b.name==="AbortError")return;console.error("Error loading image:",b),i("无法加载图像")}finally{x(!1)}})(),()=>{m.abort(),h&&URL.revokeObjectURL(h)}},[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(W,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0",children:e.jsx(He,{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 Ni({selectedProject:t}){const{showAlert:s,showConfirm:a}=ct(),[o,n]=r.useState([]),[l,i]=r.useState(!1),[d,x]=r.useState(new Set),[h,m]=r.useState(new Set),[v,b]=r.useState(new Set),[j,f]=r.useState(null),[E,O]=r.useState(null),[T,R]=r.useState("detailed"),[g,p]=r.useState(""),[u,y]=r.useState([]),[L,$]=r.useState(!1),[P,z]=r.useState(!1),[me,se]=r.useState(null),[te,de]=r.useState({});r.useEffect(()=>{t&&(x(new Set),b(new Set),m(new Set),A())},[t]),r.useEffect(()=>{const J=localStorage.getItem("file-tree-view-mode");J&&["simple","detailed","compact"].includes(J)&&R(J)},[]),r.useEffect(()=>{if(!g.trim())y(o);else{const J=_(o,g.toLowerCase());y(J);const q=w=>{w.forEach(K=>{K.type==="directory"&&K.children&&K.children.length>0&&(x(he=>new Set(he.add(K.path))),q(K.children))})};q(J)}},[o,g]);const _=(J,q)=>J.reduce((w,K)=>{const he=K.name.toLowerCase().includes(q);let ve=[];return K.type==="directory"&&K.children&&(ve=_(K.children,q)),(he||ve.length>0)&&w.push({...K,children:ve}),w},[]),A=async()=>{i(!0);try{const J=await ke.getFiles(t.name,{depth:1});if(!J.ok){const w=await J.text();console.error("❌ File fetch failed:",J.status,w),n([]);return}const q=await J.json();n(q)}catch(J){console.error("❌ Error fetching files:",J),n([])}finally{i(!1)}},ae=async J=>{if(!(v.has(J)||h.has(J))){m(q=>new Set([...q,J]));try{const q=await ke.getFiles(t.name,{dirPath:J,depth:1});if(!q.ok){console.error("Failed to load directory:",J);return}const w=await q.json();n(K=>fe(K,J,w)),b(K=>new Set([...K,J]))}catch(q){console.error("Error loading directory:",q)}finally{m(q=>{const w=new Set(q);return w.delete(J),w})}}},fe=(J,q,w)=>J.map(K=>K.path===q?{...K,children:w}:K.type==="directory"&&K.children&&K.children.length>0?{...K,children:fe(K.children,q,w)}:K),ue=r.useCallback(async J=>{if(!t||J.length===0)return;z(!0),se(null);const q=new FormData;J.forEach(K=>{q.append("files",K)});const w={};J.forEach(K=>{w[K.name]=0}),de(w);try{const K=await ke.uploadFiles(t.name,q);if(!K.ok){const ve=await K.json();throw new Error(ve.error||"Upload failed")}const he={};J.forEach(ve=>{he[ve.name]=100}),de(he),await A(),setTimeout(()=>{$(!1),de({})},1e3)}catch(K){console.error("Upload failed:",K),se(K.message)}finally{z(!1)}},[t]),{getRootProps:Z,getInputProps:G,isDragActive:pe,open:Pe}=hs({onDrop:ue,noClick:!0,noKeyboard:!0}),Me=async(J,q,w)=>{const K=w==="directory";if(await a(`确定要删除${K?"文件夹":"文件"} "${q}" 吗?${K?`
126
- 这将删除内部的所有内容。`:""}`,{title:"确认删除",variant:"danger",confirmText:"删除"})&&t)try{const ve=await ke.deleteFile(t.name,J);if(!ve.ok){const Ae=await ve.json();throw new Error(Ae.error||"Delete failed")}await A()}catch(ve){console.error("Delete failed:",ve),s(`删除失败: ${ve.message}`,{variant:"error"})}},Le=async(J,q)=>{const w=new Set(d);w.has(J)?w.delete(J):(w.add(J),q&&!v.has(J)&&await ae(J)),x(w)},Ne=J=>{R(J),localStorage.setItem("file-tree-view-mode",J)},qe=J=>{if(!J||J===0)return"0 B";const q=1024,w=["B","KB","MB","GB"],K=Math.floor(Math.log(J)/Math.log(q));return parseFloat((J/Math.pow(q,K)).toFixed(1))+" "+w[K]},Ke=J=>{if(!J)return"-";const q=new Date,w=new Date(J),K=Math.floor((q-w)/1e3);return K<60?"just now":K<3600?`${Math.floor(K/60)} min ago`:K<86400?`${Math.floor(K/3600)} hours ago`:K<2592e3?`${Math.floor(K/86400)} days ago`:w.toLocaleDateString()},We=(J,q=0)=>J.map(w=>{const K=h.has(w.path),he=d.has(w.path),ve=w.hasChildren||w.children&&w.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:Ve("w-full flex items-center justify-between p-2 hover:bg-accent",w.type==="directory"||Ie(w.name)||je(w.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${q*16+12}px`},onClick:()=>{w.type==="directory"?Le(w.path,ve):Ie(w.name)?O({name:w.name,path:w.path,projectPath:t.path,projectName:t.name}):je(w.name)&&f({name:w.name,path:w.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[w.type==="directory"?K?e.jsx(Mt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):he?e.jsx(Pt,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):ve?e.jsx(mt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(mt,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Fe(w.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:w.name}),w.type==="directory"&&ve&&!he&&!K&&e.jsx(Vt,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[w.type==="file"&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity flex-shrink-0",onClick:Ae=>{Ae.stopPropagation(),$e(w)},title:"下载文件",children:e.jsx($t,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity flex-shrink-0",onClick:Ae=>{Ae.stopPropagation(),Me(w.path,w.name,w.type)},title:`删除${w.type==="directory"?"文件夹":"文件"}`,children:e.jsx(et,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),w.type==="directory"&&he&&e.jsx("div",{children:K?e.jsxs("div",{className:"flex items-center gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:[e.jsx(Mt,{className:"w-3 h-3 animate-spin"}),"加载中..."]}):w.children&&w.children.length>0?We(w.children,q+1):e.jsx("div",{className:"p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:"空文件夹"})})]},w.path)}),Ie=J=>{const q=J.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","svg","webp","ico","bmp"].includes(q)},je=J=>{const q=J.toLowerCase(),w=["dockerfile","makefile","gemfile","rakefile","procfile","vagrantfile","jenkinsfile"];if(!J.includes("."))return w.includes(q);const K=J.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(K)},$e=async J=>{try{const q=await ke.getFileContent(t.name,J.path);if(!q.ok)throw new Error("Download failed");const w=await q.blob(),K=URL.createObjectURL(w),he=document.createElement("a");he.href=K,he.download=J.name,document.body.appendChild(he),he.click(),document.body.removeChild(he),URL.revokeObjectURL(K)}catch(q){console.error("Download failed:",q)}},Fe=J=>{const q=J.split(".").pop()?.toLowerCase(),w=["js","jsx","ts","tsx","py","java","cpp","c","php","rb","go","rs"],K=["md","txt","doc","pdf"],he=["png","jpg","jpeg","gif","svg","webp","ico","bmp"];return w.includes(q)?e.jsx(Cn,{className:"w-4 h-4 text-green-500 flex-shrink-0"}):K.includes(q)?e.jsx(da,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):he.includes(q)?e.jsx(Ps,{className:"w-4 h-4 text-purple-500 flex-shrink-0"}):e.jsx(Ps,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"})},_e=(J,q=0)=>J.map(w=>{const K=h.has(w.path),he=d.has(w.path),ve=w.hasChildren||w.children&&w.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:Ve("grid grid-cols-12 gap-2 p-2 hover:bg-accent items-center",w.type==="directory"||Ie(w.name)||je(w.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${q*16+12}px`},onClick:()=>{w.type==="directory"?Le(w.path,ve):Ie(w.name)?O({name:w.name,path:w.path,projectPath:t.path,projectName:t.name}):je(w.name)&&f({name:w.name,path:w.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"col-span-4 flex items-center gap-2 min-w-0",children:[w.type==="directory"?K?e.jsx(Mt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):he?e.jsx(Pt,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):ve?e.jsx(mt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(mt,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Fe(w.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:w.name}),w.type==="directory"&&ve&&!he&&!K&&e.jsx(Vt,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground",children:w.type==="file"?qe(w.size):"-"}),e.jsx("div",{className:"col-span-3 text-sm text-muted-foreground",children:Ke(w.modified)}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground font-mono",children:w.permissionsRwx||"-"}),e.jsxs("div",{className:"col-span-1 flex justify-end items-center gap-0.5",children:[w.type==="file"&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),$e(w)},title:"下载文件",children:e.jsx($t,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),Me(w.path,w.name,w.type)},title:`删除${w.type==="directory"?"文件夹":"文件"}`,children:e.jsx(et,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),w.type==="directory"&&he&&e.jsx("div",{children:K?e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground items-center",style:{paddingLeft:`${(q+1)*16+12}px`},children:e.jsxs("div",{className:"col-span-4 flex items-center gap-2",children:[e.jsx(Mt,{className:"w-3 h-3 animate-spin"}),"加载中..."]})}):w.children&&w.children.length>0?_e(w.children,q+1):e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:e.jsx("div",{className:"col-span-4",children:"空文件夹"})})})]},w.path)}),ze=(J,q=0)=>J.map(w=>{const K=h.has(w.path),he=d.has(w.path),ve=w.hasChildren||w.children&&w.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:Ve("flex items-center justify-between p-2 hover:bg-accent",w.type==="directory"||Ie(w.name)||je(w.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${q*16+12}px`},onClick:()=>{w.type==="directory"?Le(w.path,ve):Ie(w.name)?O({name:w.name,path:w.path,projectPath:t.path,projectName:t.name}):je(w.name)&&f({name:w.name,path:w.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[w.type==="directory"?K?e.jsx(Mt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):he?e.jsx(Pt,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):ve?e.jsx(mt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(mt,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Fe(w.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:w.name}),w.type==="directory"&&ve&&!he&&!K&&e.jsx(Vt,{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:[w.type==="file"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:qe(w.size)}),e.jsx("span",{className:"font-mono",children:w.permissionsRwx})]}),w.type==="file"&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),$e(w)},title:"下载文件",children:e.jsx($t,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),Me(w.path,w.name,w.type)},title:`删除${w.type==="directory"?"文件夹":"文件"}`,children:e.jsx(et,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),w.type==="directory"&&he&&e.jsx("div",{children:K?e.jsxs("div",{className:"flex items-center gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:[e.jsx(Mt,{className:"w-3 h-3 animate-spin"}),"加载中..."]}):w.children&&w.children.length>0?ze(w.children,q+1):e.jsx("div",{className:"p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:"空文件夹"})})]},w.path)});return l?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:Ve("h-full flex flex-col bg-card relative",pe&&"ring-2 ring-primary ring-inset"),children:[e.jsx("input",{...G()}),pe&&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(W,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>$(!0),title:"上传文件",children:e.jsx(Rs,{className:"w-4 h-4"})}),e.jsx(W,{variant:T==="simple"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>Ne("simple"),title:"简单视图",children:e.jsx(Nn,{className:"w-4 h-4"})}),e.jsx(W,{variant:T==="compact"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>Ne("compact"),title:"紧凑视图",children:e.jsx(ca,{className:"w-4 h-4"})}),e.jsx(W,{variant:T==="detailed"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>Ne("detailed"),title:"详细视图",children:e.jsx(Sn,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(At,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索文件和文件夹...",value:g,onChange:J=>p(J.target.value),className:"pl-8 pr-8 h-8 text-sm"}),g&&e.jsx(W,{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:()=>p(""),title:"清除搜索",children:e.jsx(He,{className:"w-3 h-3"})})]})]}),T==="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(ps,{className:"flex-1 p-4",children:o.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(mt,{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&&g?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(At,{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:T==="detailed"?"":"space-y-1",children:[T==="simple"&&We(u),T==="compact"&&ze(u),T==="detailed"&&_e(u)]})}),j&&e.jsx(is,{file:j,onClose:()=>f(null),projectPath:j.projectPath}),E&&e.jsx(ki,{file:E,onClose:()=>O(null)}),L&&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(W,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{$(!1),se(null),de({})},children:e.jsx(He,{className:"w-4 h-4"})})]}),e.jsxs("div",{onClick:Pe,className:Ve("border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors","border-border hover:border-primary/50"),children:[e.jsx(Rs,{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(te).length>0&&e.jsx("div",{className:"mt-4 space-y-2 max-h-40 overflow-y-auto",children:Object.entries(te).map(([J,q])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm truncate flex-1 text-foreground",children:J}),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:`${q}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10",children:[q,"%"]})]},J))}),me&&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:me})}),P&&e.jsx("div",{className:"mt-4 text-center text-sm text-muted-foreground",children:"上传中..."})]})})]})}var fs=Gn(),bs=Vn(),vs=Yn(),ys=Qn();const Si=`
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 ${j?"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"+(j?" 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:te,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(Ot,{className:"w-5 h-5 md:w-4 md:h-4"})}),e.jsx("button",{onClick:se,disabled:v,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 ${T?"bg-green-600 hover:bg-green-700":"bg-blue-600 hover:bg-blue-700"}`,children:T?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(ca,{className:"w-5 h-5 md:w-4 md:h-4"}),e.jsx("span",{className:"hidden sm:inline",children:v?"Saving...":"Save"})]})}),!o&&e.jsx("button",{onClick:de,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:j?"Exit fullscreen":"Fullscreen",children:j?e.jsx(kn,{className:"w-4 h-4"}):e.jsx(da,{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(He,{className:"w-6 h-6 md:w-4 md:h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(sn,{ref:P,value:d,onChange:x,extensions:[...me(t.name),...z,...g?[nn.lineWrapping]:[]],theme:E?an:void 0,height:"100%",style:{fontSize:`${L}px`,height:"100%"},basicSetup:{lineNumbers:u,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: ",d.split(`
125
+ `).length]}),e.jsxs("span",{children:["Characters: ",d.length]})]}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Press Ctrl+S to save • Esc to close"})]})]})})]})}function ki({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,x]=r.useState(!0);return r.useEffect(()=>{let h;const m=new AbortController;return(async()=>{try{x(!0),i(null),n(null);const b=await Z(a,{signal:m.signal});if(!b.ok)throw new Error(`Request failed with status ${b.status}`);const j=await b.blob();h=URL.createObjectURL(j),n(h)}catch(b){if(b.name==="AbortError")return;console.error("Error loading image:",b),i("无法加载图像")}finally{x(!1)}})(),()=>{m.abort(),h&&URL.revokeObjectURL(h)}},[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(W,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0",children:e.jsx(He,{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 Ni({selectedProject:t}){const{showAlert:s,showConfirm:a}=ct(),[o,n]=r.useState([]),[l,i]=r.useState(!1),[d,x]=r.useState(new Set),[h,m]=r.useState(new Set),[v,b]=r.useState(new Set),[j,f]=r.useState(null),[E,O]=r.useState(null),[T,R]=r.useState("detailed"),[g,p]=r.useState(""),[u,y]=r.useState([]),[L,$]=r.useState(!1),[P,z]=r.useState(!1),[me,se]=r.useState(null),[te,de]=r.useState({});r.useEffect(()=>{t&&(x(new Set),b(new Set),m(new Set),A())},[t]),r.useEffect(()=>{const J=localStorage.getItem("file-tree-view-mode");J&&["simple","detailed","compact"].includes(J)&&R(J)},[]),r.useEffect(()=>{if(!g.trim())y(o);else{const J=_(o,g.toLowerCase());y(J);const q=w=>{w.forEach(K=>{K.type==="directory"&&K.children&&K.children.length>0&&(x(he=>new Set(he.add(K.path))),q(K.children))})};q(J)}},[o,g]);const _=(J,q)=>J.reduce((w,K)=>{const he=K.name.toLowerCase().includes(q);let ve=[];return K.type==="directory"&&K.children&&(ve=_(K.children,q)),(he||ve.length>0)&&w.push({...K,children:ve}),w},[]),A=async()=>{i(!0);try{const J=await ke.getFiles(t.name,{depth:1});if(!J.ok){const w=await J.text();console.error("❌ File fetch failed:",J.status,w),n([]);return}const q=await J.json();n(q)}catch(J){console.error("❌ Error fetching files:",J),n([])}finally{i(!1)}},ae=async J=>{if(!(v.has(J)||h.has(J))){m(q=>new Set([...q,J]));try{const q=await ke.getFiles(t.name,{dirPath:J,depth:1});if(!q.ok){console.error("Failed to load directory:",J);return}const w=await q.json();n(K=>fe(K,J,w)),b(K=>new Set([...K,J]))}catch(q){console.error("Error loading directory:",q)}finally{m(q=>{const w=new Set(q);return w.delete(J),w})}}},fe=(J,q,w)=>J.map(K=>K.path===q?{...K,children:w}:K.type==="directory"&&K.children&&K.children.length>0?{...K,children:fe(K.children,q,w)}:K),ue=r.useCallback(async J=>{if(!t||J.length===0)return;z(!0),se(null);const q=new FormData;J.forEach(K=>{q.append("files",K)});const w={};J.forEach(K=>{w[K.name]=0}),de(w);try{const K=await ke.uploadFiles(t.name,q);if(!K.ok){const ve=await K.json();throw new Error(ve.error||"Upload failed")}const he={};J.forEach(ve=>{he[ve.name]=100}),de(he),await A(),setTimeout(()=>{$(!1),de({})},1e3)}catch(K){console.error("Upload failed:",K),se(K.message)}finally{z(!1)}},[t]),{getRootProps:X,getInputProps:G,isDragActive:pe,open:Pe}=gs({onDrop:ue,noClick:!0,noKeyboard:!0}),Ee=async(J,q,w)=>{const K=w==="directory";if(await a(`确定要删除${K?"文件夹":"文件"} "${q}" 吗?${K?`
126
+ 这将删除内部的所有内容。`:""}`,{title:"确认删除",variant:"danger",confirmText:"删除"})&&t)try{const ve=await ke.deleteFile(t.name,J);if(!ve.ok){const Ae=await ve.json();throw new Error(Ae.error||"Delete failed")}await A()}catch(ve){console.error("Delete failed:",ve),s(`删除失败: ${ve.message}`,{variant:"error"})}},Me=async(J,q)=>{const w=new Set(d);w.has(J)?w.delete(J):(w.add(J),q&&!v.has(J)&&await ae(J)),x(w)},Ne=J=>{R(J),localStorage.setItem("file-tree-view-mode",J)},qe=J=>{if(!J||J===0)return"0 B";const q=1024,w=["B","KB","MB","GB"],K=Math.floor(Math.log(J)/Math.log(q));return parseFloat((J/Math.pow(q,K)).toFixed(1))+" "+w[K]},Ge=J=>{if(!J)return"-";const q=new Date,w=new Date(J),K=Math.floor((q-w)/1e3);return K<60?"just now":K<3600?`${Math.floor(K/60)} min ago`:K<86400?`${Math.floor(K/3600)} hours ago`:K<2592e3?`${Math.floor(K/86400)} days ago`:w.toLocaleDateString()},We=(J,q=0)=>J.map(w=>{const K=h.has(w.path),he=d.has(w.path),ve=w.hasChildren||w.children&&w.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:Ve("w-full flex items-center justify-between p-2 hover:bg-accent",w.type==="directory"||De(w.name)||je(w.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${q*16+12}px`},onClick:()=>{w.type==="directory"?Me(w.path,ve):De(w.name)?O({name:w.name,path:w.path,projectPath:t.path,projectName:t.name}):je(w.name)&&f({name:w.name,path:w.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[w.type==="directory"?K?e.jsx(Dt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):he?e.jsx(At,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):ve?e.jsx(pt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(pt,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Fe(w.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:w.name}),w.type==="directory"&&ve&&!he&&!K&&e.jsx(Vt,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[w.type==="file"&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity flex-shrink-0",onClick:Ae=>{Ae.stopPropagation(),$e(w)},title:"下载文件",children:e.jsx(Ot,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity flex-shrink-0",onClick:Ae=>{Ae.stopPropagation(),Ee(w.path,w.name,w.type)},title:`删除${w.type==="directory"?"文件夹":"文件"}`,children:e.jsx(tt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),w.type==="directory"&&he&&e.jsx("div",{children:K?e.jsxs("div",{className:"flex items-center gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:[e.jsx(Dt,{className:"w-3 h-3 animate-spin"}),"加载中..."]}):w.children&&w.children.length>0?We(w.children,q+1):e.jsx("div",{className:"p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:"空文件夹"})})]},w.path)}),De=J=>{const q=J.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","svg","webp","ico","bmp"].includes(q)},je=J=>{const q=J.toLowerCase(),w=["dockerfile","makefile","gemfile","rakefile","procfile","vagrantfile","jenkinsfile"];if(!J.includes("."))return w.includes(q);const K=J.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(K)},$e=async J=>{try{const q=await ke.getFileContent(t.name,J.path);if(!q.ok)throw new Error("Download failed");const w=await q.blob(),K=URL.createObjectURL(w),he=document.createElement("a");he.href=K,he.download=J.name,document.body.appendChild(he),he.click(),document.body.removeChild(he),URL.revokeObjectURL(K)}catch(q){console.error("Download failed:",q)}},Fe=J=>{const q=J.split(".").pop()?.toLowerCase(),w=["js","jsx","ts","tsx","py","java","cpp","c","php","rb","go","rs"],K=["md","txt","doc","pdf"],he=["png","jpg","jpeg","gif","svg","webp","ico","bmp"];return w.includes(q)?e.jsx(Cn,{className:"w-4 h-4 text-green-500 flex-shrink-0"}):K.includes(q)?e.jsx(ua,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):he.includes(q)?e.jsx($s,{className:"w-4 h-4 text-purple-500 flex-shrink-0"}):e.jsx($s,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"})},_e=(J,q=0)=>J.map(w=>{const K=h.has(w.path),he=d.has(w.path),ve=w.hasChildren||w.children&&w.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:Ve("grid grid-cols-12 gap-2 p-2 hover:bg-accent items-center",w.type==="directory"||De(w.name)||je(w.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${q*16+12}px`},onClick:()=>{w.type==="directory"?Me(w.path,ve):De(w.name)?O({name:w.name,path:w.path,projectPath:t.path,projectName:t.name}):je(w.name)&&f({name:w.name,path:w.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"col-span-4 flex items-center gap-2 min-w-0",children:[w.type==="directory"?K?e.jsx(Dt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):he?e.jsx(At,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):ve?e.jsx(pt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(pt,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Fe(w.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:w.name}),w.type==="directory"&&ve&&!he&&!K&&e.jsx(Vt,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground",children:w.type==="file"?qe(w.size):"-"}),e.jsx("div",{className:"col-span-3 text-sm text-muted-foreground",children:Ge(w.modified)}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground font-mono",children:w.permissionsRwx||"-"}),e.jsxs("div",{className:"col-span-1 flex justify-end items-center gap-0.5",children:[w.type==="file"&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),$e(w)},title:"下载文件",children:e.jsx(Ot,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),Ee(w.path,w.name,w.type)},title:`删除${w.type==="directory"?"文件夹":"文件"}`,children:e.jsx(tt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),w.type==="directory"&&he&&e.jsx("div",{children:K?e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground items-center",style:{paddingLeft:`${(q+1)*16+12}px`},children:e.jsxs("div",{className:"col-span-4 flex items-center gap-2",children:[e.jsx(Dt,{className:"w-3 h-3 animate-spin"}),"加载中..."]})}):w.children&&w.children.length>0?_e(w.children,q+1):e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:e.jsx("div",{className:"col-span-4",children:"空文件夹"})})})]},w.path)}),ze=(J,q=0)=>J.map(w=>{const K=h.has(w.path),he=d.has(w.path),ve=w.hasChildren||w.children&&w.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:Ve("flex items-center justify-between p-2 hover:bg-accent",w.type==="directory"||De(w.name)||je(w.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${q*16+12}px`},onClick:()=>{w.type==="directory"?Me(w.path,ve):De(w.name)?O({name:w.name,path:w.path,projectPath:t.path,projectName:t.name}):je(w.name)&&f({name:w.name,path:w.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[w.type==="directory"?K?e.jsx(Dt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):he?e.jsx(At,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):ve?e.jsx(pt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(pt,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):Fe(w.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:w.name}),w.type==="directory"&&ve&&!he&&!K&&e.jsx(Vt,{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:[w.type==="file"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:qe(w.size)}),e.jsx("span",{className:"font-mono",children:w.permissionsRwx})]}),w.type==="file"&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),$e(w)},title:"下载文件",children:e.jsx(Ot,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:Ae=>{Ae.stopPropagation(),Ee(w.path,w.name,w.type)},title:`删除${w.type==="directory"?"文件夹":"文件"}`,children:e.jsx(tt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),w.type==="directory"&&he&&e.jsx("div",{children:K?e.jsxs("div",{className:"flex items-center gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:[e.jsx(Dt,{className:"w-3 h-3 animate-spin"}),"加载中..."]}):w.children&&w.children.length>0?ze(w.children,q+1):e.jsx("div",{className:"p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(q+1)*16+12}px`},children:"空文件夹"})})]},w.path)});return l?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",{...X(),className:Ve("h-full flex flex-col bg-card relative",pe&&"ring-2 ring-primary ring-inset"),children:[e.jsx("input",{...G()}),pe&&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(W,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>$(!0),title:"上传文件",children:e.jsx(Ps,{className:"w-4 h-4"})}),e.jsx(W,{variant:T==="simple"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>Ne("simple"),title:"简单视图",children:e.jsx(Nn,{className:"w-4 h-4"})}),e.jsx(W,{variant:T==="compact"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>Ne("compact"),title:"紧凑视图",children:e.jsx(ma,{className:"w-4 h-4"})}),e.jsx(W,{variant:T==="detailed"?"default":"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>Ne("detailed"),title:"详细视图",children:e.jsx(Sn,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ft,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索文件和文件夹...",value:g,onChange:J=>p(J.target.value),className:"pl-8 pr-8 h-8 text-sm"}),g&&e.jsx(W,{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:()=>p(""),title:"清除搜索",children:e.jsx(He,{className:"w-3 h-3"})})]})]}),T==="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(xs,{className:"flex-1 p-4",children:o.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(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:"检查项目路径是否可访问"})]}):u.length===0&&g?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(Ft,{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:T==="detailed"?"":"space-y-1",children:[T==="simple"&&We(u),T==="compact"&&ze(u),T==="detailed"&&_e(u)]})}),j&&e.jsx(ls,{file:j,onClose:()=>f(null),projectPath:j.projectPath}),E&&e.jsx(ki,{file:E,onClose:()=>O(null)}),L&&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(W,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{$(!1),se(null),de({})},children:e.jsx(He,{className:"w-4 h-4"})})]}),e.jsxs("div",{onClick:Pe,className:Ve("border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors","border-border hover:border-primary/50"),children:[e.jsx(Ps,{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(te).length>0&&e.jsx("div",{className:"mt-4 space-y-2 max-h-40 overflow-y-auto",children:Object.entries(te).map(([J,q])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm truncate flex-1 text-foreground",children:J}),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:`${q}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10",children:[q,"%"]})]},J))}),me&&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:me})}),P&&e.jsx("div",{className:"mt-4 text-center text-sm text-muted-foreground",children:"上传中..."})]})})]})}var bs=Gn(),vs=Vn(),ys=Yn(),js=Qn();const Si=`
127
127
  .xterm .xterm-screen {
128
128
  outline: none !important;
129
129
  }
@@ -133,20 +133,20 @@ ${ce}`:ce:Oe.push({type:"assistant",content:ce,timestamp:new Date,isStreaming:!0
133
133
  .xterm-screen:focus {
134
134
  outline: none !important;
135
135
  }
136
- `;if(typeof document<"u"){const t=document.createElement("style");t.type="text/css",t.innerText=Si,document.head.appendChild(t)}function Ci({selectedProject:t,selectedSession:s,initialCommand:a,isPlainShell:o=!1,onProcessComplete:n,minimal:l=!1,autoConnect:i=!1}){const d=r.useRef(null),x=r.useRef(null),h=r.useRef(null),m=r.useRef(null),[v,b]=r.useState(!1),[j,f]=r.useState(!1),[E,O]=r.useState(!1),[T,R]=r.useState(null),[g,p]=r.useState(!1),u=r.useRef(t),y=r.useRef(s),L=r.useRef(a),$=r.useRef(o),P=r.useRef(n);r.useEffect(()=>{u.current=t,y.current=s,L.current=a,$.current=o,P.current=n});const z=r.useCallback(async()=>{if(!(g||v))try{let fe;{const ue=localStorage.getItem("auth-token");if(!ue){console.error("No authentication token found for Shell WebSocket connection");return}fe=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/shell?token=${encodeURIComponent(ue)}`}m.current=new WebSocket(fe),m.current.onopen=()=>{b(!0),p(!1),setTimeout(()=>{h.current&&x.current&&(h.current.fit(),m.current.send(JSON.stringify({type:"init",projectPath:u.current.fullPath||u.current.path,sessionId:$.current?null:y.current?.id,hasSession:$.current?!1:!!y.current,provider:$.current?"plain-shell":y.current?.__provider||"claude",cols:x.current.cols,rows:x.current.rows,initialCommand:L.current,isPlainShell:$.current})))},100)},m.current.onmessage=ue=>{try{const Z=JSON.parse(ue.data);if(Z.type==="output"){let G=Z.data;if($.current&&P.current){const pe=G.replace(/\x1b\[[0-9;]*m/g,"");if(pe.includes("Process exited with code 0"))P.current(0);else if(pe.match(/Process exited with code (\d+)/)){const Pe=parseInt(pe.match(/Process exited with code (\d+)/)[1]);Pe!==0&&P.current(Pe)}}x.current&&x.current.write(G)}else Z.type==="url_open"&&window.open(Z.url,"_blank")}catch(Z){console.error("[Shell] Error handling WebSocket message:",Z,ue.data)}},m.current.onclose=ue=>{b(!1),p(!1),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H"))},m.current.onerror=ue=>{b(!1),p(!1)}}catch{b(!1),p(!1)}},[g,v]),me=r.useCallback(()=>{!j||v||g||(p(!0),z())},[j,v,g,z]),se=r.useCallback(()=>{m.current&&(m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"terminate"})),m.current.close(),m.current=null),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H")),b(!1),p(!1)},[]),te=r.useMemo(()=>s?s.__provider==="cursor"?s.name||"Untitled Session":s.summary||"New Session":null,[s]),de=r.useMemo(()=>te?te.slice(0,30):null,[te]),_=r.useMemo(()=>te?te.slice(0,50):null,[te]),A=()=>{O(!0),m.current&&(m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"terminate"})),m.current.close(),m.current=null),x.current&&(x.current.dispose(),x.current=null,h.current=null),b(!1),f(!1),setTimeout(()=>{O(!1)},200)};return r.useEffect(()=>{const ae=s?.id||null;T!==null&&T!==ae&&j&&se(),R(ae)},[s?.id,j,se]),r.useEffect(()=>{if(!d.current||!t||E||x.current)return;x.current=new fs.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"]}}),h.current=new bs.FitAddon;const ae=new vs.WebglAddon,fe=new ys.WebLinksAddon;x.current.loadAddon(h.current),x.current.loadAddon(fe);try{x.current.loadAddon(ae)}catch{console.warn("[Shell] WebGL renderer unavailable, using Canvas fallback")}x.current.open(d.current),x.current.attachCustomKeyEventHandler(Z=>(Z.ctrlKey||Z.metaKey)&&Z.key==="c"&&x.current.hasSelection()?(document.execCommand("copy"),!1):(Z.ctrlKey||Z.metaKey)&&Z.key==="v"?(navigator.clipboard.readText().then(G=>{m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"input",data:G}))}).catch(()=>{}),!1):!0),setTimeout(()=>{h.current&&(h.current.fit(),x.current&&m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows})))},100),f(!0),x.current.onData(Z=>{m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"input",data:Z}))});const ue=new ResizeObserver(()=>{h.current&&x.current&&setTimeout(()=>{h.current.fit(),m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows}))},50)});return d.current&&ue.observe(d.current),()=>{ue.disconnect(),m.current&&(m.current.readyState===WebSocket.OPEN||m.current.readyState===WebSocket.CONNECTING)&&m.current.close(),m.current=null,x.current&&(x.current.dispose(),x.current=null)}},[t?.path||t?.fullPath,E]),r.useEffect(()=>{!i||!j||g||v||me()},[i,j,g,v,me]),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 ${v?"bg-green-500":"bg-red-500"}`}),s&&e.jsxs("span",{className:"text-xs text-blue-300",children:["(",de,"...)"]}),!s&&e.jsx("span",{className:"text-xs text-gray-400",children:"(新会话)"}),!j&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),E&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[v&&e.jsxs("button",{onClick:se,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:A,disabled:E||v,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"}}),!j&&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:"加载终端中..."})}),j&&!v&&!g&&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:me,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: ${_}...`:"Start a new Claude session"})]})}),g&&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 Ei({project:t,session:s=null,command:a=null,isPlainShell:o=null,autoConnect:n=!0,onComplete:l=null,onClose:i=null,title:d=null,className:x="",showHeader:h=!0,compact:m=!1,minimal:v=!1}){const[b,j]=r.useState(!1),f=o!==null?o:a!==null,E=r.useCallback(O=>{j(!0),l&&l(O)},[l]);return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${x}`,children:[!v&&h&&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}),b&&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(Ci,{selectedProject:t,selectedSession:s,initialCommand:a,isPlainShell:f,onProcessComplete:E,minimal:v,autoConnect:v?!0:n})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${x}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Shell 需要一个项目"})]})})}function Mi({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,x]=r.useState(!1),[h,m]=r.useState(!1),[v,b]=r.useState(!1),[j,f]=r.useState(!1),E=r.useRef(t);r.useEffect(()=>{E.current=t});const O=r.useCallback(async()=>{if(!(j||d))try{let u;{const y=localStorage.getItem("auth-token");if(!y){console.error("No authentication token found for Codex WebSocket connection");return}u=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/codex?token=${encodeURIComponent(y)}`}i.current=new WebSocket(u),i.current.onopen=()=>{x(!0),f(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:E.current.fullPath||E.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=y=>{try{const L=JSON.parse(y.data);L.type==="output"?n.current&&n.current.write(L.data):L.type==="url_open"&&window.open(L.url,"_blank")}catch(L){console.error("[CodexShell] Error handling WebSocket message:",L)}},i.current.onclose=()=>{x(!1),f(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{x(!1),f(!1)}}catch{x(!1),f(!1)}},[j,d]),T=r.useCallback(()=>{!h||d||j||(f(!0),O())},[h,d,j,O]),R=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")),x(!1),f(!1)},[]),g=()=>{b(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),x(!1),m(!1),setTimeout(()=>b(!1),200)};return r.useEffect(()=>{if(!o.current||!t||v||n.current)return;n.current=new fs.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 bs.FitAddon;const p=new vs.WebglAddon,u=new ys.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(u);try{n.current.loadAddon(p)}catch{console.warn("[CodexShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(L=>(L.ctrlKey||L.metaKey)&&L.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(L.ctrlKey||L.metaKey)&&L.key==="v"?(navigator.clipboard.readText().then($=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:$}))}).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),m(!0),n.current.onData(L=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:L}))});const y=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&&y.observe(o.current),()=>{y.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,v]),r.useEffect(()=>{!a||!h||j||d||T()},[a,h,j,d,T]),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"}),!h&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),v&&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:R,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:g,disabled:v||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"}}),!h&&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:"加载终端中..."})}),h&&!d&&!j&&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:T,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"]})]})}),j&&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(Mi,{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 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,x]=r.useState(!1),[h,m]=r.useState(!1),[v,b]=r.useState(!1),[j,f]=r.useState(!1),E=r.useRef(t);r.useEffect(()=>{E.current=t});const O=r.useCallback(async()=>{if(!(j||d))try{let u;{const y=localStorage.getItem("auth-token");if(!y){console.error("No authentication token found for Gemini WebSocket connection");return}u=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/gemini?token=${encodeURIComponent(y)}`}i.current=new WebSocket(u),i.current.onopen=()=>{x(!0),f(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:E.current.fullPath||E.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=y=>{try{const L=JSON.parse(y.data);L.type==="output"?n.current&&n.current.write(L.data):L.type==="url_open"&&window.open(L.url,"_blank")}catch(L){console.error("[GeminiShell] Error handling WebSocket message:",L)}},i.current.onclose=()=>{x(!1),f(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{x(!1),f(!1)}}catch{x(!1),f(!1)}},[j,d]),T=r.useCallback(()=>{!h||d||j||(f(!0),O())},[h,d,j,O]),R=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")),x(!1),f(!1)},[]),g=()=>{b(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),x(!1),m(!1),setTimeout(()=>b(!1),200)};return r.useEffect(()=>{if(!o.current||!t||v||n.current)return;n.current=new fs.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 bs.FitAddon;const p=new vs.WebglAddon,u=new ys.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(u);try{n.current.loadAddon(p)}catch{console.warn("[GeminiShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(L=>(L.ctrlKey||L.metaKey)&&L.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(L.ctrlKey||L.metaKey)&&L.key==="v"?(navigator.clipboard.readText().then($=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:$}))}).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),m(!0),n.current.onData(L=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:L}))});const y=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&&y.observe(o.current),()=>{y.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,v]),r.useEffect(()=>{!a||!h||j||d||T()},[a,h,j,d,T]),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"}),!h&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),v&&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:R,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:g,disabled:v||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"}}),!h&&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:"加载终端中..."})}),h&&!d&&!j&&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:T,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"]})]})}),j&&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(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:"打开 Gemini 需要一个项目"})]})})}class Ti extends it.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 or=({children:t,content:s,position:a="top",className:o="",delay:n=500})=>{const[l,i]=r.useState(!1),[d,x]=r.useState(null),h=()=>{const j=setTimeout(()=>{i(!0)},n);x(j)},m=()=>{d&&(clearTimeout(d),x(null)),i(!1)},v=()=>{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"}},b=()=>{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:h,onMouseLeave:m,children:[t,l&&e.jsxs("div",{className:Ve("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",v(),o),children:[s,e.jsx("div",{className:Ve("absolute w-0 h-0 border-4 border-transparent",b())})]})]}):t};function Ri({selectedProject:t,selectedSession:s,activeTab:a,setActiveTab:o,ws:n,sendMessage:l,messages:i,isMobile:d,isPWA:x,onMenuClick:h,isLoading:m,onInputFocusChange:v,onSessionActive:b,onSessionInactive:j,onSessionProcessing:f,onSessionNotProcessing:E,processingSessions:O,onReplaceTemporarySession:T,onNavigateToSession:R,onShowSettings:g,autoExpandTools:p,showRawParameters:u,showThinking:y,autoScrollToBottom:L,sendByCtrlEnter:$,externalMessageUpdate:P,limitStatus:z,onLimitBlocked:me,checkLimitStatus:se}){const[te,de]=r.useState(null),[_,A]=r.useState(600),[ae,fe]=r.useState(!1),[ue,Z]=r.useState(!1),G=r.useRef(null);r.useEffect(()=>{a==="shell"&&se&&se()},[a,se]);const pe=(Ne,qe=null)=>{const Ke={name:Ne.split("/").pop(),path:Ne,projectName:t?.name,diffInfo:qe};de(Ke)},Pe=()=>{de(null),Z(!1)},Me=()=>{Z(!ue)},Le=Ne=>{d||(fe(!0),Ne.preventDefault())};return r.useEffect(()=>{const Ne=Ke=>{if(!ae)return;const We=G.current?.parentElement;if(!We)return;const Ie=We.getBoundingClientRect(),je=Ie.right-Ke.clientX,$e=300,Fe=Ie.width*.8;je>=$e&&je<=Fe&&A(je)},qe=()=>{fe(!1)};return ae&&(document.addEventListener("mousemove",Ne),document.addEventListener("mouseup",qe),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",Ne),document.removeEventListener("mouseup",qe),document.body.style.cursor="",document.body.style.userSelect=""}},[ae]),m?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:h,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:h,onTouchStart:Ne=>{Ne.preventDefault(),h()},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(ht,{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(or,{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(or,{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(or,{content:z&&!z.allowed?"使用已达上限":"Claude Code",position:"bottom",children:e.jsx("button",{onClick:()=>{if(z&&!z.allowed){me?.(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(or,{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(or,{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 ${te?"mr-0":""} ${ue?"hidden":""}`,children:[e.jsx("div",{className:`h-full ${a==="chat"?"block":"hidden"}`,children:e.jsx(Ti,{showDetails:!0,children:e.jsx(wi,{selectedProject:t,selectedSession:s,ws:n,sendMessage:l,messages:i,onFileOpen:pe,onInputFocusChange:v,onSessionActive:b,onSessionInactive:j,onSessionProcessing:f,onSessionNotProcessing:E,processingSessions:O,onReplaceTemporarySession:T,onNavigateToSession:R,onShowSettings:g,autoExpandTools:p,showRawParameters:u,showThinking:y,autoScrollToBottom:L,sendByCtrlEnter:$,externalMessageUpdate:P,limitStatus:z,onLimitExceeded:me,checkLimitStatus:se})})}),a==="files"&&e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx(Ni,{selectedProject:t})}),a==="shell"&&e.jsxs("div",{className:"h-full w-full overflow-hidden relative",children:[e.jsx(Ei,{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"}`})]}),te&&!d&&e.jsxs(e.Fragment,{children:[!ue&&e.jsx("div",{ref:G,onMouseDown:Le,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 ${ue?"flex-1":""}`,style:ue?{}:{width:`${_}px`},children:e.jsx(is,{file:te,onClose:Pe,projectPath:t?.path,isSidebar:!0,isExpanded:ue,onToggleExpand:Me})})]})]}),te&&d&&e.jsx(is,{file:te,onClose:Pe,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:h,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=it.memo(Ri);function $i({activeTab:t,setActiveTab:s,isInputFocused:a}){const o=[{id:"chat",icon:Mr,onClick:()=>s("chat")},{id:"shell",icon:cr,onClick:()=>s("shell")},{id:"files",icon:mt,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 Ia=r.createContext(),js=()=>{const t=r.useContext(Ia);if(!t)throw new Error("useTheme must be used within a ThemeProvider");return t},zi=({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(Ia.Provider,{value:n,children:t})},Ai=["Bash(git log:*)","Bash(git diff:*)","Bash(git status:*)","Write","Read","Edit","Glob","Grep","MultiEdit","Task","TodoWrite","TodoRead","WebFetch","WebSearch"],Oi=["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 _i({skipPermissions:t,setSkipPermissions:s,allowedTools:a,setAllowedTools:o,disallowedTools:n,setDisallowedTools:l,newAllowedTool:i,setNewAllowedTool:d,newDisallowedTool:x,setNewDisallowedTool:h}){const m=f=>{f&&!a.includes(f)&&(o([...a,f]),d(""))},v=f=>{o(a.filter(E=>E!==f))},b=f=>{f&&!n.includes(f)&&(l([...n,f]),h(""))},j=f=>{l(n.filter(E=>E!==f))};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(ds,{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(Lt,{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:f=>s(f.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(jt,{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(Xe,{value:i,onChange:f=>d(f.target.value),placeholder:'e.g., "Bash(git log:*)" or "Write"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),m(i))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>m(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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:Ai.map(f=>e.jsx(W,{variant:"outline",size:"sm",onClick:()=>m(f),disabled:a.includes(f),className:"text-xs h-8",children:f},f))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>v(f),className:"text-green-600 hover:text-green-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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(Lt,{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(Xe,{value:x,onChange:f=>h(f.target.value),placeholder:'e.g., "Bash(rm:*)"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),b(x))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>b(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>j(f),className:"text-red-600 hover:text-red-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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 Fi({skipPermissions:t,setSkipPermissions:s,allowedCommands:a,setAllowedCommands:o,disallowedCommands:n,setDisallowedCommands:l,newAllowedCommand:i,setNewAllowedCommand:d,newDisallowedCommand:x,setNewDisallowedCommand:h}){const m=f=>{f&&!a.includes(f)&&(o([...a,f]),d(""))},v=f=>{o(a.filter(E=>E!==f))},b=f=>{f&&!n.includes(f)&&(l([...n,f]),h(""))},j=f=>{l(n.filter(E=>E!==f))};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(Lt,{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:f=>s(f.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(jt,{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(Xe,{value:i,onChange:f=>d(f.target.value),placeholder:'e.g., "Shell(ls)" or "Shell(git status)"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),m(i))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>m(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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:Oi.map(f=>e.jsx(W,{variant:"outline",size:"sm",onClick:()=>m(f),disabled:a.includes(f),className:"text-xs h-8",children:f},f))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>v(f),className:"text-green-600 hover:text-green-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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(Lt,{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(Xe,{value:x,onChange:f=>h(f.target.value),placeholder:'e.g., "Shell(rm -rf)" or "Shell(sudo)"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),b(x))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>b(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>j(f),className:"text-red-600 hover:text-red-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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 Wi({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(jt,{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(Lt,{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 Bi({agent:t,...s}){return t==="claude"?e.jsx(_i,{...s}):t==="cursor"?e.jsx(Fi,{...s}):t==="codex"?e.jsx(Wi,{...s}):null}const Ui=t=>{switch(t){case"stdio":return e.jsx(cr,{className:"w-4 h-4"});case"sse":return e.jsx(ma,{className:"w-4 h-4"});case"http":return e.jsx(kr,{className:"w-4 h-4"});default:return e.jsx(dr,{className:"w-4 h-4"})}};function Hi({servers:t,onAdd:s,onEdit:a,onDelete:o,onTest:n,onDiscoverTools:l,testResults:i,serverTools:d,toolsLoading:x,onDiscoverRepo:h}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(dr,{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(W,{onClick:s,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(lt,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(W,{onClick:h,variant:"outline",size:"sm",children:[e.jsx(ms,{className:"w-4 h-4 mr-2"}),"MCP 商店"]})})]}),e.jsxs("div",{className:"space-y-2",children:[t.map(m=>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:[Ui(m.type),e.jsx("span",{className:"font-medium text-foreground",children:m.name}),e.jsx(Qe,{variant:"outline",className:"text-xs",children:m.type}),e.jsx(Qe,{variant:"outline",className:"text-xs",children:m.scope==="local"?"local":m.scope==="user"?"user":m.scope})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[m.type==="stdio"&&m.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:m.config.command})]}),(m.type==="sse"||m.type==="http")&&m.config?.url&&e.jsxs("div",{children:["URL:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:m.config.url})]}),m.config?.args&&m.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:m.config.args.join(" ")})]})]}),i?.[m.id]&&e.jsx("div",{className:`mt-2 p-2 rounded text-xs ${i[m.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[m.id].message})}),d?.[m.id]&&d[m.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[m.id].tools.length,"):"]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[d[m.id].tools.slice(0,5).map((v,b)=>e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:v.name},b)),d[m.id].tools.length>5&&e.jsxs("span",{className:"text-xs opacity-75",children:["+",d[m.id].tools.length-5," 更多"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(W,{onClick:()=>a(m),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(ir,{className:"w-4 h-4"})}),e.jsx(W,{onClick:()=>o(m.id,m.scope),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(et,{className:"w-4 h-4"})})]})]})},m.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function qi({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(dr,{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(W,{onClick:s,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(lt,{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(cr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Qe,{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(W,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",children:e.jsx(ir,{className:"w-4 h-4"})}),e.jsx(W,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",children:e.jsx(et,{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 Ji({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(dr,{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(W,{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(lt,{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(cr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Qe,{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(W,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(ir,{className:"w-4 h-4"})}),e.jsx(W,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(et,{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 Ki({agent:t,...s}){return t==="claude"?e.jsx(Hi,{...s}):t==="cursor"?e.jsx(qi,{...s}):t==="codex"?e.jsx(Ji,{...s}):null}const Gi=[{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)使用的模型"}],Vi=r.forwardRef(function({onStatusChange:s},a){const[o,n]=r.useState({}),[l,i]=r.useState({}),[d,x]=r.useState(!0),[h,m]=r.useState(!1),[v,b]=r.useState(null),[j,f]=r.useState(null),E=JSON.stringify(o)!==JSON.stringify(l);r.useEffect(()=>{s?.({saving:h,hasChanges:E})},[h,E,s]),r.useEffect(()=>{O()},[]),r.useEffect(()=>{if(v){const g=setTimeout(()=>b(null),3e3);return()=>clearTimeout(g)}},[v]);const O=async()=>{try{x(!0),f(null);const g=await X("/api/settings/models");if(g.ok){const p=await g.json();n(p.models||{}),i(p.models||{})}else{const p=await g.json();f(p.error||"加载模型配置失败")}}catch(g){f(g.message)}finally{x(!1)}},T=async()=>{try{m(!0),b(null);const g=await X("/api/settings/models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({models:o})});if(g.ok)return b("success"),i({...o}),!0;{const p=await g.json();return b("error"),f(p.error||"保存失败"),!1}}catch(g){return b("error"),f(g.message),!1}finally{m(!1)}},R=()=>{n({...l}),b(null)};return r.useImperativeHandle(a,()=>({save:T,reset:R,get hasChanges(){return E},get saving(){return h}}),[E,h,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(ds,{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。"})]})]}),j&&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:j}),v==="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:"模型配置已保存"}),Gi.map(g=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"font-medium text-sm text-foreground",children:g.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:g.description})]}),e.jsx("input",{type:"text",value:o[g.key]||"",onChange:p=>n(u=>({...u,[g.key]:p.target.value})),placeholder:g.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:g.key})]})},g.key))]})});function Yi({onClose:t,onInstalled:s,onOpenRepoManager:a}){const{showAlert:o}=ct(),[n,l]=r.useState([]),[i,d]=r.useState([]),[x,h]=r.useState(!0),[m,v]=r.useState(null),[b,j]=r.useState(""),[f,E]=r.useState("all"),[O,T]=r.useState(null);r.useEffect(()=>{R()},[]);const R=async(u=!1)=>{try{h(!0),v(null),u&&await X("/api/skills/repos/refresh",{method:"POST"});const[y,L]=await Promise.all([X("/api/skills/available"),X("/api/skills/repos")]);if(y.ok){const $=await y.json();l($.skills||[])}if(L.ok){const $=await L.json();d($.repos||[])}}catch(y){v(y.message)}finally{h(!1)}},g=async u=>{try{T(u.name);const y=await X(`/api/skills/install/${u.name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillPath:u.path})});if(y.ok)R(),s?.();else{const L=await y.json();o(L.error||"安装技能失败",{variant:"error"})}}catch(y){o(y.message,{variant:"error"})}finally{T(null)}},p=n.filter(u=>{if(b){const y=b.toLowerCase();if(!u.name.toLowerCase().includes(y)&&!u.title?.toLowerCase().includes(y)&&!u.description?.toLowerCase().includes(y))return!1}return!(f!=="all"&&u.repository!==f)});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(W,{variant:"ghost",size:"sm",onClick:()=>R(!0),disabled:x,children:[e.jsx(zt,{className:`w-4 h-4 ${x?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(W,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(It,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(He,{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(At,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索技能名称或描述...",value:b,onChange:u=>j(u.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:f,onChange:u=>E(u.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:"全部"}),i.map(u=>e.jsxs("option",{value:`${u.owner}/${u.repo}`,children:[u.owner,"/",u.repo]},`${u.owner}/${u.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[m&&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:m}),x?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):p.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:n.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的技能"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加技能仓库"}),e.jsxs(W,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(It,{className:"w-4 h-4 mr-2"}),"管理仓库"]})]}):e.jsx("p",{children:"没有找到匹配的技能"})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:p.map(u=>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:u.title||u.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["skills/",u.name]}),e.jsx(Qe,{variant:"outline",className:"text-xs ml-2",children:u.repository})]})]}),u.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:u.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-auto pt-2",children:[e.jsxs(W,{variant:"ghost",size:"sm",onClick:()=>window.open(`https://github.com/${u.repository}`,"_blank"),children:[e.jsx(ua,{className:"w-4 h-4 mr-1"}),"查看"]}),u.installed?e.jsx(W,{size:"sm",disabled:!0,variant:"outline",className:"ml-auto",children:"已安装"}):e.jsxs(W,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white ml-auto",onClick:()=>g(u),disabled:O===u.name,children:[e.jsx($t,{className:"w-4 h-4 mr-1"}),O===u.name?"安装中...":"安装"]})]})]})},`${u.repository}-${u.name}`))})]})]})})}function Qi({onClose:t,onChanged:s}){const{showAlert:a,showConfirm:o}=ct(),[n,l]=r.useState([]),[i,d]=r.useState(!0),[x,h]=r.useState(null),[m,v]=r.useState(""),[b,j]=r.useState("main"),[f,E]=r.useState(!1),[O,T]=r.useState(null);r.useEffect(()=>{R()},[]);const R=async()=>{try{d(!0),h(null);const u=await X("/api/skills/repos");if(u.ok){const y=await u.json();l(y.repos||[])}else{const y=await u.json();h(y.error||"Failed to fetch repos")}}catch(u){h(u.message)}finally{d(!1)}},g=async u=>{if(u.preventDefault(),!m.trim()){h("请输入仓库 URL");return}try{E(!0),h(null);const y=await X("/api/skills/repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:m.trim(),branch:b.trim()||"main"})});if(y.ok)v(""),j("main"),R(),s?.();else{const L=await y.json();h(L.error||"Failed to add repo")}}catch(y){h(y.message)}finally{E(!1)}},p=async(u,y)=>{if(await o(`确定要移除仓库 "${u}/${y}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{T(`${u}/${y}`);const L=await X(`/api/skills/repos/${u}/${y}`,{method:"DELETE"});if(L.ok)R(),s?.();else{const $=await L.json();a($.error||"移除仓库失败",{variant:"error"})}}catch(L){a(L.message,{variant:"error"})}finally{T(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(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Qt,{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:g,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(Xe,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:m,onChange:u=>v(u.target.value),disabled:f})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"分支"}),e.jsx(Xe,{type:"text",placeholder:"main",value:b,onChange:u=>j(u.target.value),disabled:f})]}),e.jsxs(W,{type:"submit",disabled:f||!m.trim(),className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(lt,{className:"w-4 h-4 mr-2"}),f?"添加中...":"添加仓库"]})]})]}),x&&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:x}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"已添加的仓库"}),i?e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(pa,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何仓库"})]}):n.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(Qe,{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(ms,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Qe,{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(W,{variant:"ghost",size:"sm",onClick:()=>window.open(u.url,"_blank"),children:e.jsx(ua,{className:"w-4 h-4"})}),!u.isSystem&&e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>p(u.owner,u.repo),disabled:O===`${u.owner}/${u.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(et,{className:"w-4 h-4"})})]})]})},`${u.owner}/${u.repo}`))]})]})]})})}function Zi(){const{showAlert:t,showConfirm:s}=ct(),[a,o]=r.useState([]),[n,l]=r.useState(!0),[i,d]=r.useState(null),[x,h]=r.useState(!1),[m,v]=r.useState(!1),[b,j]=r.useState(!1),f=r.useRef(null);r.useEffect(()=>{E()},[]);const E=async()=>{try{l(!0),d(null);const p=await X("/api/skills");if(p.ok){const u=await p.json();o(u.skills||[])}else{const u=await p.json();d(u.error||"Failed to fetch skills")}}catch(p){d(p.message)}finally{l(!1)}},O=async p=>{if(await s(`确定要删除技能 "${p}" 吗?`,{title:"删除技能",variant:"danger",confirmText:"确认删除"}))try{const u=await X(`/api/skills/${p}`,{method:"DELETE"});if(u.ok)E();else{const y=await u.json();t(y.error||"删除技能失败",{variant:"error"})}}catch(u){t(u.message,{variant:"error"})}},T=()=>{f.current?.click()},R=async p=>{const u=p.target.files?.[0];if(u)try{j(!0);const y=new FormData;y.append("skillZip",u);const L=await X("/api/skills/import",{method:"POST",body:y});if(L.ok)E();else{const $=await L.json();t($.error||"导入技能失败",{variant:"error"})}}catch(y){t(y.message,{variant:"error"})}finally{j(!1),f.current&&(f.current.value="")}},g=(p,u)=>{switch(p){case"repo":return e.jsx(Qe,{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(Qe,{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(Qe,{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(Vr,{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:a.length})," 个技能"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{ref:f,type:"file",accept:".zip",className:"hidden",onChange:R}),e.jsxs(W,{onClick:T,variant:"outline",size:"sm",disabled:b,children:[e.jsx($t,{className:"w-4 h-4 mr-2"}),b?"导入中...":"导入已有"]}),e.jsxs(W,{onClick:()=>h(!0),className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:[e.jsx(At,{className:"w-4 h-4 mr-2"}),"发现技能"]})]})]}),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.jsx("div",{className:"space-y-2",children:n?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Vr,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有安装任何技能"}),e.jsx("p",{className:"text-xs mt-2",children:'点击"发现技能"从仓库安装,或"导入已有"上传本地技能'})]}):a.map(p=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-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:p.title||p.name}),g(p.source,p.repository)]}),p.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:p.description})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4 shrink-0",children:e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>O(p.name),className:"text-red-500 hover:text-red-600",title:"删除技能",children:e.jsx(et,{className:"w-4 h-4"})})})]})},p.name))}),x&&e.jsx(Yi,{onClose:()=>h(!1),onInstalled:E,onOpenRepoManager:()=>{h(!1),v(!0)}}),m&&e.jsx(Qi,{onClose:()=>v(!1),onChanged:()=>{}})]})}function Xi({onClose:t,onChanged:s}){const{showAlert:a,showConfirm:o}=ct(),[n,l]=r.useState([]),[i,d]=r.useState(!0),[x,h]=r.useState(null),[m,v]=r.useState(""),[b,j]=r.useState(!1),[f,E]=r.useState(null);r.useEffect(()=>{O()},[]);const O=async()=>{try{d(!0),h(null);const g=await X("/api/mcp-repos");if(g.ok){const p=await g.json();l(p.repos||[])}else{const p=await g.json();h(p.error||"Failed to fetch repos")}}catch(g){h(g.message)}finally{d(!1)}},T=async g=>{if(g.preventDefault(),!m.trim()){h("请输入仓库 URL");return}try{j(!0),h(null);const p=await X("/api/mcp-repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:m.trim()})});if(p.ok)v(""),O(),s?.();else{const u=await p.json();h(u.error||"Failed to add repo")}}catch(p){h(p.message)}finally{j(!1)}},R=async(g,p)=>{if(await o(`确定要移除仓库 "${g}/${p}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{E(`${g}/${p}`);const u=await X(`/api/mcp-repos/${g}/${p}`,{method:"DELETE"});if(u.ok)O(),s?.();else{const y=await u.json();a(y.error||"移除仓库失败",{variant:"error"})}}catch(u){a(u.message,{variant:"error"})}finally{E(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(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Qt,{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:T,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(Xe,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:m,onChange:g=>v(g.target.value),disabled:b})]}),e.jsxs(W,{type:"submit",disabled:b||!m.trim(),className:"bg-purple-600 hover:bg-purple-700 text-white",children:[e.jsx(lt,{className:"w-4 h-4 mr-2"}),b?"添加中...":"添加仓库"]})]})]}),x&&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:x}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"已添加的仓库"}),i?e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(pa,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何 MCP 仓库"})]}):n.map(g=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-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:[g.owner,"/",g.repo]}),g.isSystem&&e.jsx(Qe,{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(ms,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Qe,{variant:"outline",className:"text-xs",children:[g.serviceCount," 个 MCP 服务"]})]})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4",children:!g.isSystem&&e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>R(g.owner,g.repo),disabled:f===`${g.owner}/${g.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(et,{className:"w-4 h-4"})})})]})},`${g.owner}/${g.repo}`))]})]})]})})}const el=t=>{switch(t){case"stdio":return e.jsx(cr,{className:"w-3 h-3"});case"sse":return e.jsx(ma,{className:"w-3 h-3"});case"http":return e.jsx(kr,{className:"w-3 h-3"});default:return e.jsx(dr,{className:"w-3 h-3"})}};function tl({onClose:t,onInstalled:s,onOpenRepoManager:a}){const{showAlert:o,showConfirm:n}=ct(),[l,i]=r.useState([]),[d,x]=r.useState([]),[h,m]=r.useState(!0),[v,b]=r.useState(null),[j,f]=r.useState(""),[E,O]=r.useState("all"),[T,R]=r.useState(null),[g,p]=r.useState(null);r.useEffect(()=>{u()},[]);const u=async(P=!1)=>{try{m(!0),b(null),P&&await X("/api/mcp-repos/refresh",{method:"POST"});const[z,me]=await Promise.all([X("/api/mcp-repos/available"),X("/api/mcp-repos")]);if(z.ok){const se=await z.json();i(se.services||[])}if(me.ok){const se=await me.json();x(se.repos||[])}}catch(z){b(z.message)}finally{m(!1)}},y=async P=>{try{R(P.dirName+P.repository);const z=await X("/api/mcp-repos/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({servicePath:P.path})});if(z.ok)u(),s?.();else{const me=await z.json();o(me.error||"安装 MCP 服务失败",{variant:"error"})}}catch(z){o(z.message,{variant:"error"})}finally{R(null)}},L=async P=>{if(!(!P.serverNames||P.serverNames.length===0)&&await n(`确定要卸载 "${P.name}" 吗?这将移除 ${P.serverNames.join(", ")} 的配置。`,{title:"卸载 MCP 服务",variant:"danger",confirmText:"确认卸载"}))try{p(P.dirName+P.repository);for(const z of P.serverNames)await X(`/api/mcp-repos/uninstall/${encodeURIComponent(z)}`,{method:"DELETE"});u(),s?.()}catch(z){o(z.message,{variant:"error"})}finally{p(null)}},$=l.filter(P=>{if(j){const z=j.toLowerCase();if(!P.dirName?.toLowerCase().includes(z)&&!P.name?.toLowerCase().includes(z)&&!P.description?.toLowerCase().includes(z))return!1}return!(E!=="all"&&P.repository!==E)});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(W,{variant:"ghost",size:"sm",onClick:()=>u(!0),disabled:h,children:[e.jsx(zt,{className:`w-4 h-4 ${h?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(W,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(It,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(He,{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(At,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索 MCP 服务名称或描述...",value:j,onChange:P=>f(P.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:E,onChange:P=>O(P.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:"全部仓库"}),d.map(P=>e.jsxs("option",{value:`${P.owner}/${P.repo}`,children:[P.owner,"/",P.repo]},`${P.owner}/${P.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[v&&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:v}),h?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):$.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:l.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的 MCP 服务"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加 MCP 仓库"}),e.jsxs(W,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(It,{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:$.map(P=>{const z=`${P.repository}-${P.dirName}`,me=T===P.dirName+P.repository,se=g===P.dirName+P.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:P.name||P.dirName}),e.jsxs(Qe,{variant:"outline",className:"text-xs flex items-center gap-1",children:[el(P.type),P.type]})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:P.repository}),P.serverNames?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:["· ",P.serverNames.join(", ")]})]})]}),P.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:P.description}),e.jsx("div",{className:"flex items-center gap-2 mt-auto pt-2",children:P.installed?e.jsxs(W,{size:"sm",variant:"outline",className:"ml-auto text-red-600 hover:text-red-700 border-red-200 hover:border-red-300",onClick:()=>L(P),disabled:se,children:[e.jsx(et,{className:"w-4 h-4 mr-1"}),se?"卸载中...":"卸载"]}):e.jsxs(W,{size:"sm",className:"bg-purple-600 hover:bg-purple-700 text-white ml-auto",onClick:()=>y(P),disabled:me,children:[e.jsx($t,{className:"w-4 h-4 mr-1"}),me?"安装中...":"安装"]})})]})},z)})})]})]})})}function rl({isOpen:t,onClose:s,projects:a=[],initialTab:o="agents"}){const n=sa(),{isDarkMode:l,toggleDarkMode:i}=js(),{user:d,logout:x}=wt(),{showAlert:h,showConfirm:m}=ct(),[v,b]=r.useState([]),[j,f]=r.useState([]),[E,O]=r.useState(""),[T,R]=r.useState(""),[g,p]=r.useState(!1),[u,y]=r.useState(!1),[L,$]=r.useState(null),[P,z]=r.useState("name"),[me,se]=r.useState([]),[te,de]=r.useState(!1),[_,A]=r.useState(null),[ae,fe]=r.useState(!1),[ue,Z]=r.useState(!1),[G,pe]=r.useState({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),[Pe,Me]=r.useState(!1),[Le,Ne]=r.useState({}),[qe,Ke]=r.useState({}),[We,Ie]=r.useState({}),[je,$e]=r.useState(o),[Fe,_e]=r.useState(""),[ze,J]=r.useState("permissions"),q=r.useRef(null),[w,K]=r.useState({saving:!1,hasChanges:!1}),he=r.useCallback(I=>K(I),[]),[ve,Ae]=r.useState(""),[Ue,V]=r.useState(""),[oe,Te]=r.useState(""),[Re,Ce]=r.useState(""),[S,ee]=r.useState(""),[we,Y]=r.useState(!1),[H,M]=r.useState(""),[ne,B]=r.useState(!1),[re,ie]=r.useState(""),[ye,xe]=r.useState(!1),[Ye,De]=r.useState(()=>localStorage.getItem("codeEditorTheme")||"dark"),[Ge,rt]=r.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[st,Lr]=r.useState(()=>localStorage.getItem("codeEditorShowMinimap")!=="false"),[gt,Dt]=r.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[_t,Ir]=r.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),at=async()=>{try{const I=await X("/api/mcp/config/read");if(I.ok){const Ee=await I.json();if(Ee.success&&Ee.servers){se(Ee.servers);return}}const U=await X("/api/mcp/cli/list");if(U.ok){const Ee=await U.json();if(Ee.success&&Ee.servers){const bt=Ee.servers.map(nt=>({id:nt.name,name:nt.name,type:nt.type,scope:"user",config:{command:nt.command||"",args:nt.args||[],env:nt.env||{},url:nt.url||"",headers:nt.headers||{},timeout:3e4},created:new Date().toISOString(),updated:new Date().toISOString()}));se(bt);return}}const le=await X("/api/mcp/servers?scope=user");if(le.ok){const Ee=await le.json();se(Ee.servers||[])}else console.error("Failed to fetch MCP servers")}catch(I){console.error("Error fetching MCP servers:",I)}},Dr=async I=>{try{_&&await Ft(_.id,"user");const U=await X("/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(U.ok){const le=await U.json();if(le.success)return await at(),!0;throw new Error(le.error||"Failed to save server via Claude CLI")}else{const le=await U.json();throw new Error(le.error||"Failed to save server")}}catch(U){throw console.error("Error saving MCP server:",U),U}},Ft=async(I,U="user")=>{try{const le=await X(`/api/mcp/cli/remove/${I}?scope=${U}`,{method:"DELETE"});if(le.ok){const Ee=await le.json();if(Ee.success)return await at(),!0;throw new Error(Ee.error||"Failed to delete server via Claude CLI")}else{const Ee=await le.json();throw new Error(Ee.error||"Failed to delete server")}}catch(le){throw console.error("Error deleting MCP server:",le),le}},Zt=async(I,U="user")=>{try{const le=await X(`/api/mcp/servers/${I}/test?scope=${U}`,{method:"POST"});if(le.ok)return(await le.json()).testResult;{const Ee=await le.json();throw new Error(Ee.error||"Failed to test server")}}catch(le){throw console.error("Error testing MCP server:",le),le}},mr=async(I,U="user")=>{try{const le=await X(`/api/mcp/servers/${I}/tools?scope=${U}`,{method:"POST"});if(le.ok)return(await le.json()).toolsResult;{const Ee=await le.json();throw new Error(Ee.error||"Failed to discover tools")}}catch(le){throw console.error("Error discovering MCP tools:",le),le}};r.useEffect(()=>{t&&(Wt(),$e(o))},[t,o]),r.useEffect(()=>{localStorage.setItem("codeEditorTheme",Ye),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Ye]),r.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",Ge.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Ge]),r.useEffect(()=>{localStorage.setItem("codeEditorShowMinimap",st.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[st]),r.useEffect(()=>{localStorage.setItem("codeEditorLineNumbers",gt.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[gt]),r.useEffect(()=>{localStorage.setItem("codeEditorFontSize",_t),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[_t]);const Wt=async()=>{try{let I=null;try{const U=await ke.settings.getAgentPermissions();U.ok&&(I=(await U.json()).agentPermissions)}catch{}if(I)b(I.allowedTools||[]),f(I.disallowedTools||[]),p(I.skipPermissions||!1),z(I.projectSortOrder||"name"),localStorage.setItem("claude-settings",JSON.stringify(I));else{const U=localStorage.getItem("claude-settings");if(U){const le=JSON.parse(U);b(le.allowedTools||[]),f(le.disallowedTools||[]),p(le.skipPermissions||!1),z(le.projectSortOrder||"name")}else b([]),f([]),p(!1),z("name")}await at()}catch(I){console.error("Error loading tool settings:",I),b([]),f([]),p(!1),z("name")}},ur=async()=>{y(!0),$(null);try{const I={allowedTools:v,disallowedTools:j,skipPermissions:g,projectSortOrder:P,lastUpdated:new Date().toISOString()};localStorage.setItem("claude-settings",JSON.stringify(I));try{await ke.settings.saveAgentPermissions(I)}catch(U){console.warn("Failed to sync agent permissions to server:",U)}$("success"),setTimeout(()=>{s()},1e3)}catch(I){console.error("Error saving tool settings:",I),$("error")}finally{y(!1)}},Bt=async I=>{if(I.preventDefault(),Ce(""),ee(""),!ve){Ce("请输入当前密码");return}if(!Ue){Ce("请输入新密码");return}if(Ue.length<6){Ce("新密码至少需要6个字符");return}if(Ue!==oe){Ce("两次输入的新密码不一致");return}Y(!0);try{const U=await ke.auth.changePassword(ve,Ue),le=await U.json();U.ok?(ee("密码修改成功"),Ae(""),V(""),Te("")):Ce(le.error||"修改密码失败")}catch(U){console.error("Error changing password:",U),Ce("网络错误,请稍后再试")}finally{Y(!1)}},Tr=d?.username&&!d.username.includes("@"),ot=async()=>{B(!0),ie(""),M(""),xe(!1);try{const I=await ke.auth.feishuBindToken(),U=await I.json();I.ok&&U.token?M(U.token):ie(U.error||"生成失败,请重试")}catch{ie("网络错误,请稍后再试")}finally{B(!1)}},Xt=()=>{if(!H)return;const I=`/auth ${H}`;if(navigator.clipboard&&window.isSecureContext)navigator.clipboard.writeText(I).then(()=>{xe(!0),setTimeout(()=>xe(!1),2e3)});else{const U=document.createElement("textarea");U.value=I,U.style.position="fixed",U.style.opacity="0",document.body.appendChild(U),U.focus(),U.select();try{document.execCommand("copy"),xe(!0),setTimeout(()=>xe(!1),2e3)}finally{document.body.removeChild(U)}}},ut=()=>{pe({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),A(null),de(!1),_e("")},Ut=(I=null)=>{I?(A(I),pe({name:I.name,type:I.type,scope:I.scope,projectPath:I.projectPath||"",config:{...I.config},raw:I.raw,importMode:"form",jsonInput:""})):ut(),de(!0)},er=async I=>{I.preventDefault(),Me(!0);try{if(G.importMode==="json"){const U=await X("/api/mcp/cli/add-json",{method:"POST",body:JSON.stringify({name:G.name,jsonConfig:G.jsonInput,scope:G.scope,projectPath:G.projectPath})});if(U.ok){const le=await U.json();if(le.success)await at(),ut(),$("success");else throw new Error(le.error||"Failed to add server via JSON")}else{const le=await U.json();throw new Error(le.error||"Failed to add server")}}else await Dr(G),ut(),$("success")}catch(U){h(`错误: ${U.message}`,{variant:"error"}),$("error")}finally{Me(!1)}},pt=async(I,U)=>{if(await m("确定要删除此 MCP 服务器吗?",{title:"删除 MCP 服务器",variant:"danger",confirmText:"确认删除"}))try{await Ft(I,U),$("success")}catch(le){h(`错误: ${le.message}`,{variant:"error"}),$("error")}},Ht=async(I,U)=>{try{Ne({...Le,[I]:{loading:!0}});const le=await Zt(I,U);Ne({...Le,[I]:le})}catch(le){Ne({...Le,[I]:{success:!1,message:le.message,details:[]}})}},tr=async(I,U)=>{try{Ie({...We,[I]:!0});const le=await mr(I,U);Ke({...qe,[I]:le})}catch{Ke({...qe,[I]:{success:!1,tools:[],resources:[],prompts:[]}})}finally{Ie({...We,[I]:!1})}},ft=(I,U)=>{pe(le=>({...le,config:{...le.config,[I]:U}}))};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(It,{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(W,{variant:"ghost",size:"sm",onClick:s,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(He,{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:()=>$e("agents"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="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:()=>$e("appearance"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="appearance"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"外观"}),e.jsx("button",{onClick:()=>$e("account"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="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:[je==="appearance"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:je==="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(Yr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Qr,{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:P,onChange:I=>z(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:()=>De(Ye==="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":Ye==="dark","aria-label":"Toggle editor theme",children:[e.jsx("span",{className:"sr-only",children:"Toggle editor theme"}),e.jsx("span",{className:`${Ye==="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:Ye==="dark"?e.jsx(Yr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Qr,{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:()=>rt(!Ge),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":Ge,"aria-label":"Toggle word wrap",children:[e.jsx("span",{className:"sr-only",children:"Toggle word wrap"}),e.jsx("span",{className:`${Ge?"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:()=>Lr(!st),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":st,"aria-label":"Toggle minimap",children:[e.jsx("span",{className:"sr-only",children:"Toggle minimap"}),e.jsx("span",{className:`${st?"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:()=>Dt(!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 line numbers",children:[e.jsx("span",{className:"sr-only",children:"Toggle line numbers"}),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("select",{value:_t,onChange:I=>Ir(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"})]})]})})]})]})}),je==="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:()=>J("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 ${ze==="permissions"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"权限"}),e.jsx("button",{onClick:()=>J("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 ${ze==="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:()=>J("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 ${ze==="skills"?"border-amber-600 text-amber-600 dark:text-amber-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"技能"}),e.jsx("button",{onClick:()=>J("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 ${ze==="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:[ze==="permissions"&&e.jsx(Bi,{agent:"claude",skipPermissions:g,setSkipPermissions:p,allowedTools:v,setAllowedTools:b,disallowedTools:j,setDisallowedTools:f,newAllowedTool:E,setNewAllowedTool:O,newDisallowedTool:T,setNewDisallowedTool:R}),ze==="mcp"&&e.jsx(Ki,{agent:"claude",servers:me,onAdd:()=>Ut(),onEdit:I=>Ut(I),onDelete:(I,U)=>pt(I,U),onTest:(I,U)=>Ht(I,U),onDiscoverTools:(I,U)=>tr(I,U),testResults:Le,serverTools:qe,toolsLoading:We,onDiscoverRepo:()=>fe(!0)}),ze==="skills"&&e.jsx(Zi,{}),ze==="models"&&e.jsx(Vi,{ref:q,onStatusChange:he})]})]})}),je==="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==="super_admin"?"超级管理员":d?.role==="admin"?"管理员":"用户"})]})]})}),Tr&&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(Zr,{className:"w-5 h-5 text-blue-600"}),e.jsx("div",{className:"font-medium text-foreground",children:"修改密码"})]}),e.jsxs("form",{onSubmit:Bt,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"currentPassword",className:"block text-sm font-medium text-foreground mb-1",children:"当前密码"}),e.jsx("input",{type:"password",id:"currentPassword",value:ve,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:"请输入当前密码",disabled:we})]}),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:Ue,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:"请输入新密码(至少6个字符)",disabled:we})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmNewPassword",className:"block text-sm font-medium text-foreground mb-1",children:"确认新密码"}),e.jsx("input",{type:"password",id:"confirmNewPassword",value:oe,onChange:I=>Te(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:we})]}),Re&&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:Re})}),S&&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:S})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(W,{type:"submit",disabled:we,className:"bg-blue-600 hover:bg-blue-700",children:we?"修改中...":"修改密码"})})]})]}),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 小时。"]}),H?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 ",H]}),e.jsx("button",{onClick:Xt,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:ye?e.jsx(jr,{className:"w-4 h-4 text-green-500"}):e.jsx(En,{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:ot,disabled:ne,className:"flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 hover:underline disabled:opacity-50",children:[e.jsx(zt,{className:"w-3 h-3"}),"重新生成"]})]})]}):e.jsxs("div",{className:"space-y-2",children:[re&&e.jsx("p",{className:"text-sm text-red-500",children:re}),e.jsxs(W,{onClick:ot,disabled:ne,variant:"outline",className:"gap-2",children:[ne?e.jsx(zt,{className:"w-4 h-4 animate-spin"}):e.jsx(Zr,{className:"w-4 h-4"}),ne?"生成中...":"生成绑定 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(W,{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:async()=>{await m("确定要退出登录吗?",{title:"退出登录",variant:"warning",confirmText:"退出"})&&(s(),n("/"),x())},children:[e.jsx(Mn,{className:"w-4 h-4"}),"退出"]})]})})]})}),te&&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:_?"编辑 MCP 服务器":"添加 MCP 服务器"}),e.jsx(W,{variant:"ghost",size:"sm",onClick:ut,children:e.jsx(He,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:er,className:"p-4 space-y-4",children:[!_&&e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>pe(I=>({...I,importMode:"form"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${G.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:()=>pe(I=>({...I,importMode:"json"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${G.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 导入"})]}),G.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-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:[G.scope==="user"?e.jsx(kr,{className:"w-4 h-4"}):e.jsx(Pt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:G.scope==="user"?"用户(全局)":"项目(本地)"}),G.scope==="local"&&G.projectPath&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",G.projectPath]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"编辑现有服务器时无法更改作用域"})]}),G.importMode==="form"&&!_&&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:()=>pe(I=>({...I,scope:"user",projectPath:""})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${G.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(kr,{className:"w-4 h-4"}),e.jsx("span",{children:"用户(全局)"})]})}),e.jsx("button",{type:"button",onClick:()=>pe(I=>({...I,scope:"local"})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${G.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(Pt,{className:"w-4 h-4"}),e.jsx("span",{children:"项目(本地)"})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:G.scope==="user"?"用户作用域:在您机器上的所有项目中可用":"本地作用域:仅在选定的项目中可用"})]}),G.scope==="local"&&!_&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"项目 *"}),e.jsxs("select",{value:G.projectPath,onChange:I=>pe(U=>({...U,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:G.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))]}),G.projectPath&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Path: ",G.projectPath]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:G.importMode==="json"?"md:col-span-2":"",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称 *"}),e.jsx(Xe,{value:G.name,onChange:I=>{pe(U=>({...U,name:I.target.value}))},placeholder:"my-server",required:!0})]}),G.importMode==="form"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"传输类型 *"}),e.jsxs("select",{value:G.type,onChange:I=>{pe(U=>({...U,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"})]})]})]}),_&&G.raw&&G.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 ",_.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(G.raw,null,2)})]}),G.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:G.jsonInput,onChange:I=>{pe(U=>({...U,jsonInput:I.target.value}));try{if(I.target.value.trim()){const U=JSON.parse(I.target.value);U.type?U.type==="stdio"&&!U.command?_e("stdio 类型需要 command 字段"):(U.type==="http"||U.type==="sse")&&!U.url?_e(`${U.type} 类型需要 url 字段`):_e(""):_e("缺少必填字段:type")}}catch{I.target.value.trim()?_e("无效的 JSON 格式"):_e("")}},className:`w-full px-3 py-2 border ${Fe?"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
+ `;if(typeof document<"u"){const t=document.createElement("style");t.type="text/css",t.innerText=Si,document.head.appendChild(t)}function Ci({selectedProject:t,selectedSession:s,initialCommand:a,isPlainShell:o=!1,onProcessComplete:n,minimal:l=!1,autoConnect:i=!1}){const d=r.useRef(null),x=r.useRef(null),h=r.useRef(null),m=r.useRef(null),[v,b]=r.useState(!1),[j,f]=r.useState(!1),[E,O]=r.useState(!1),[T,R]=r.useState(null),[g,p]=r.useState(!1),u=r.useRef(t),y=r.useRef(s),L=r.useRef(a),$=r.useRef(o),P=r.useRef(n);r.useEffect(()=>{u.current=t,y.current=s,L.current=a,$.current=o,P.current=n});const z=r.useCallback(async()=>{if(!(g||v))try{let fe;{const ue=localStorage.getItem("auth-token");if(!ue){console.error("No authentication token found for Shell WebSocket connection");return}fe=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/shell?token=${encodeURIComponent(ue)}`}m.current=new WebSocket(fe),m.current.onopen=()=>{b(!0),p(!1),setTimeout(()=>{h.current&&x.current&&(h.current.fit(),m.current.send(JSON.stringify({type:"init",projectPath:u.current.fullPath||u.current.path,sessionId:$.current?null:y.current?.id,hasSession:$.current?!1:!!y.current,provider:$.current?"plain-shell":y.current?.__provider||"claude",cols:x.current.cols,rows:x.current.rows,initialCommand:L.current,isPlainShell:$.current})))},100)},m.current.onmessage=ue=>{try{const X=JSON.parse(ue.data);if(X.type==="output"){let G=X.data;if($.current&&P.current){const pe=G.replace(/\x1b\[[0-9;]*m/g,"");if(pe.includes("Process exited with code 0"))P.current(0);else if(pe.match(/Process exited with code (\d+)/)){const Pe=parseInt(pe.match(/Process exited with code (\d+)/)[1]);Pe!==0&&P.current(Pe)}}x.current&&x.current.write(G)}else X.type==="url_open"&&window.open(X.url,"_blank")}catch(X){console.error("[Shell] Error handling WebSocket message:",X,ue.data)}},m.current.onclose=ue=>{b(!1),p(!1),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H"))},m.current.onerror=ue=>{b(!1),p(!1)}}catch{b(!1),p(!1)}},[g,v]),me=r.useCallback(()=>{!j||v||g||(p(!0),z())},[j,v,g,z]),se=r.useCallback(()=>{m.current&&(m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"terminate"})),m.current.close(),m.current=null),x.current&&(x.current.clear(),x.current.write("\x1B[2J\x1B[H")),b(!1),p(!1)},[]),te=r.useMemo(()=>s?s.__provider==="cursor"?s.name||"Untitled Session":s.summary||"New Session":null,[s]),de=r.useMemo(()=>te?te.slice(0,30):null,[te]),_=r.useMemo(()=>te?te.slice(0,50):null,[te]),A=()=>{O(!0),m.current&&(m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"terminate"})),m.current.close(),m.current=null),x.current&&(x.current.dispose(),x.current=null,h.current=null),b(!1),f(!1),setTimeout(()=>{O(!1)},200)};return r.useEffect(()=>{const ae=s?.id||null;T!==null&&T!==ae&&j&&se(),R(ae)},[s?.id,j,se]),r.useEffect(()=>{if(!d.current||!t||E||x.current)return;x.current=new bs.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"]}}),h.current=new vs.FitAddon;const ae=new ys.WebglAddon,fe=new js.WebLinksAddon;x.current.loadAddon(h.current),x.current.loadAddon(fe);try{x.current.loadAddon(ae)}catch{console.warn("[Shell] WebGL renderer unavailable, using Canvas fallback")}x.current.open(d.current),x.current.attachCustomKeyEventHandler(X=>(X.ctrlKey||X.metaKey)&&X.key==="c"&&x.current.hasSelection()?(document.execCommand("copy"),!1):(X.ctrlKey||X.metaKey)&&X.key==="v"?(navigator.clipboard.readText().then(G=>{m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"input",data:G}))}).catch(()=>{}),!1):!0),setTimeout(()=>{h.current&&(h.current.fit(),x.current&&m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows})))},100),f(!0),x.current.onData(X=>{m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"input",data:X}))});const ue=new ResizeObserver(()=>{h.current&&x.current&&setTimeout(()=>{h.current.fit(),m.current&&m.current.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({type:"resize",cols:x.current.cols,rows:x.current.rows}))},50)});return d.current&&ue.observe(d.current),()=>{ue.disconnect(),m.current&&(m.current.readyState===WebSocket.OPEN||m.current.readyState===WebSocket.CONNECTING)&&m.current.close(),m.current=null,x.current&&(x.current.dispose(),x.current=null)}},[t?.path||t?.fullPath,E]),r.useEffect(()=>{!i||!j||g||v||me()},[i,j,g,v,me]),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 ${v?"bg-green-500":"bg-red-500"}`}),s&&e.jsxs("span",{className:"text-xs text-blue-300",children:["(",de,"...)"]}),!s&&e.jsx("span",{className:"text-xs text-gray-400",children:"(新会话)"}),!j&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),E&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[v&&e.jsxs("button",{onClick:se,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:A,disabled:E||v,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"}}),!j&&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:"加载终端中..."})}),j&&!v&&!g&&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:me,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: ${_}...`:"Start a new Claude session"})]})}),g&&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 Ei({project:t,session:s=null,command:a=null,isPlainShell:o=null,autoConnect:n=!0,onComplete:l=null,onClose:i=null,title:d=null,className:x="",showHeader:h=!0,compact:m=!1,minimal:v=!1}){const[b,j]=r.useState(!1),f=o!==null?o:a!==null,E=r.useCallback(O=>{j(!0),l&&l(O)},[l]);return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${x}`,children:[!v&&h&&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}),b&&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(Ci,{selectedProject:t,selectedSession:s,initialCommand:a,isPlainShell:f,onProcessComplete:E,minimal:v,autoConnect:v?!0:n})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${x}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Shell 需要一个项目"})]})})}function Mi({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,x]=r.useState(!1),[h,m]=r.useState(!1),[v,b]=r.useState(!1),[j,f]=r.useState(!1),E=r.useRef(t);r.useEffect(()=>{E.current=t});const O=r.useCallback(async()=>{if(!(j||d))try{let u;{const y=localStorage.getItem("auth-token");if(!y){console.error("No authentication token found for Codex WebSocket connection");return}u=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/codex?token=${encodeURIComponent(y)}`}i.current=new WebSocket(u),i.current.onopen=()=>{x(!0),f(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:E.current.fullPath||E.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=y=>{try{const L=JSON.parse(y.data);L.type==="output"?n.current&&n.current.write(L.data):L.type==="url_open"&&window.open(L.url,"_blank")}catch(L){console.error("[CodexShell] Error handling WebSocket message:",L)}},i.current.onclose=()=>{x(!1),f(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{x(!1),f(!1)}}catch{x(!1),f(!1)}},[j,d]),T=r.useCallback(()=>{!h||d||j||(f(!0),O())},[h,d,j,O]),R=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")),x(!1),f(!1)},[]),g=()=>{b(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),x(!1),m(!1),setTimeout(()=>b(!1),200)};return r.useEffect(()=>{if(!o.current||!t||v||n.current)return;n.current=new bs.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 vs.FitAddon;const p=new ys.WebglAddon,u=new js.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(u);try{n.current.loadAddon(p)}catch{console.warn("[CodexShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(L=>(L.ctrlKey||L.metaKey)&&L.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(L.ctrlKey||L.metaKey)&&L.key==="v"?(navigator.clipboard.readText().then($=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:$}))}).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),m(!0),n.current.onData(L=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:L}))});const y=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&&y.observe(o.current),()=>{y.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,v]),r.useEffect(()=>{!a||!h||j||d||T()},[a,h,j,d,T]),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"}),!h&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),v&&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:R,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:g,disabled:v||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"}}),!h&&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:"加载终端中..."})}),h&&!d&&!j&&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:T,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"]})]})}),j&&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(Mi,{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 Di({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,x]=r.useState(!1),[h,m]=r.useState(!1),[v,b]=r.useState(!1),[j,f]=r.useState(!1),E=r.useRef(t);r.useEffect(()=>{E.current=t});const O=r.useCallback(async()=>{if(!(j||d))try{let u;{const y=localStorage.getItem("auth-token");if(!y){console.error("No authentication token found for Gemini WebSocket connection");return}u=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/gemini?token=${encodeURIComponent(y)}`}i.current=new WebSocket(u),i.current.onopen=()=>{x(!0),f(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:E.current.fullPath||E.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=y=>{try{const L=JSON.parse(y.data);L.type==="output"?n.current&&n.current.write(L.data):L.type==="url_open"&&window.open(L.url,"_blank")}catch(L){console.error("[GeminiShell] Error handling WebSocket message:",L)}},i.current.onclose=()=>{x(!1),f(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{x(!1),f(!1)}}catch{x(!1),f(!1)}},[j,d]),T=r.useCallback(()=>{!h||d||j||(f(!0),O())},[h,d,j,O]),R=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")),x(!1),f(!1)},[]),g=()=>{b(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),x(!1),m(!1),setTimeout(()=>b(!1),200)};return r.useEffect(()=>{if(!o.current||!t||v||n.current)return;n.current=new bs.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 vs.FitAddon;const p=new ys.WebglAddon,u=new js.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(u);try{n.current.loadAddon(p)}catch{console.warn("[GeminiShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(L=>(L.ctrlKey||L.metaKey)&&L.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(L.ctrlKey||L.metaKey)&&L.key==="v"?(navigator.clipboard.readText().then($=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:$}))}).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),m(!0),n.current.onData(L=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:L}))});const y=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&&y.observe(o.current),()=>{y.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,v]),r.useEffect(()=>{!a||!h||j||d||T()},[a,h,j,d,T]),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"}),!h&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),v&&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:R,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:g,disabled:v||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"}}),!h&&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:"加载终端中..."})}),h&&!d&&!j&&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:T,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"]})]})}),j&&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 Ii({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(Di,{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 Ti extends it.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 lr=({children:t,content:s,position:a="top",className:o="",delay:n=500})=>{const[l,i]=r.useState(!1),[d,x]=r.useState(null),h=()=>{const j=setTimeout(()=>{i(!0)},n);x(j)},m=()=>{d&&(clearTimeout(d),x(null)),i(!1)},v=()=>{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"}},b=()=>{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:h,onMouseLeave:m,children:[t,l&&e.jsxs("div",{className:Ve("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",v(),o),children:[s,e.jsx("div",{className:Ve("absolute w-0 h-0 border-4 border-transparent",b())})]})]}):t};function Ri({selectedProject:t,selectedSession:s,activeTab:a,setActiveTab:o,ws:n,sendMessage:l,messages:i,isMobile:d,isPWA:x,onMenuClick:h,isLoading:m,onInputFocusChange:v,onSessionActive:b,onSessionInactive:j,onSessionProcessing:f,onSessionNotProcessing:E,processingSessions:O,onReplaceTemporarySession:T,onNavigateToSession:R,onShowSettings:g,autoExpandTools:p,showRawParameters:u,showThinking:y,autoScrollToBottom:L,sendByCtrlEnter:$,externalMessageUpdate:P,limitStatus:z,onLimitBlocked:me,checkLimitStatus:se}){const[te,de]=r.useState(null),[_,A]=r.useState(600),[ae,fe]=r.useState(!1),[ue,X]=r.useState(!1),G=r.useRef(null);r.useEffect(()=>{a==="shell"&&se&&se()},[a,se]);const pe=(Ne,qe=null)=>{const Ge={name:Ne.split("/").pop(),path:Ne,projectName:t?.name,diffInfo:qe};de(Ge)},Pe=()=>{de(null),X(!1)},Ee=()=>{X(!ue)},Me=Ne=>{d||(fe(!0),Ne.preventDefault())};return r.useEffect(()=>{const Ne=Ge=>{if(!ae)return;const We=G.current?.parentElement;if(!We)return;const De=We.getBoundingClientRect(),je=De.right-Ge.clientX,$e=300,Fe=De.width*.8;je>=$e&&je<=Fe&&A(je)},qe=()=>{fe(!1)};return ae&&(document.addEventListener("mousemove",Ne),document.addEventListener("mouseup",qe),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",Ne),document.removeEventListener("mouseup",qe),document.body.style.cursor="",document.body.style.userSelect=""}},[ae]),m?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:h,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:h,onTouchStart:Ne=>{Ne.preventDefault(),h()},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(gt,{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(lr,{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(lr,{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(lr,{content:z&&!z.allowed?"使用已达上限":"Claude Code",position:"bottom",children:e.jsx("button",{onClick:()=>{if(z&&!z.allowed){me?.(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(lr,{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(lr,{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 ${te?"mr-0":""} ${ue?"hidden":""}`,children:[e.jsx("div",{className:`h-full ${a==="chat"?"block":"hidden"}`,children:e.jsx(Ti,{showDetails:!0,children:e.jsx(wi,{selectedProject:t,selectedSession:s,ws:n,sendMessage:l,messages:i,onFileOpen:pe,onInputFocusChange:v,onSessionActive:b,onSessionInactive:j,onSessionProcessing:f,onSessionNotProcessing:E,processingSessions:O,onReplaceTemporarySession:T,onNavigateToSession:R,onShowSettings:g,autoExpandTools:p,showRawParameters:u,showThinking:y,autoScrollToBottom:L,sendByCtrlEnter:$,externalMessageUpdate:P,limitStatus:z,onLimitExceeded:me,checkLimitStatus:se})})}),a==="files"&&e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx(Ni,{selectedProject:t})}),a==="shell"&&e.jsxs("div",{className:"h-full w-full overflow-hidden relative",children:[e.jsx(Ei,{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(Ii,{project:t,showHeader:!1})}),e.jsx("div",{className:`h-full overflow-hidden ${a==="preview"?"block":"hidden"}`})]}),te&&!d&&e.jsxs(e.Fragment,{children:[!ue&&e.jsx("div",{ref:G,onMouseDown:Me,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 ${ue?"flex-1":""}`,style:ue?{}:{width:`${_}px`},children:e.jsx(ls,{file:te,onClose:Pe,projectPath:t?.path,isSidebar:!0,isExpanded:ue,onToggleExpand:Ee})})]})]}),te&&d&&e.jsx(ls,{file:te,onClose:Pe,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:h,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:"从侧边栏选择一个项目,开始与 AgentHub 进行交流。每个项目包含您的聊天会话和文件历史。"}),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=it.memo(Ri);function $i({activeTab:t,setActiveTab:s,isInputFocused:a}){const o=[{id:"chat",icon:Lr,onClick:()=>s("chat")},{id:"shell",icon:mr,onClick:()=>s("shell")},{id:"files",icon:pt,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 Ta=r.createContext(),ws=()=>{const t=r.useContext(Ta);if(!t)throw new Error("useTheme must be used within a ThemeProvider");return t},zi=({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(Ta.Provider,{value:n,children:t})},Ai=["Bash(git log:*)","Bash(git diff:*)","Bash(git status:*)","Write","Read","Edit","Glob","Grep","MultiEdit","Task","TodoWrite","TodoRead","WebFetch","WebSearch"],Oi=["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 _i({skipPermissions:t,setSkipPermissions:s,allowedTools:a,setAllowedTools:o,disallowedTools:n,setDisallowedTools:l,newAllowedTool:i,setNewAllowedTool:d,newDisallowedTool:x,setNewDisallowedTool:h}){const m=f=>{f&&!a.includes(f)&&(o([...a,f]),d(""))},v=f=>{o(a.filter(E=>E!==f))},b=f=>{f&&!n.includes(f)&&(l([...n,f]),h(""))},j=f=>{l(n.filter(E=>E!==f))};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(ms,{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(It,{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:f=>s(f.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(kt,{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(Xe,{value:i,onChange:f=>d(f.target.value),placeholder:'e.g., "Bash(git log:*)" or "Write"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),m(i))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>m(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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:Ai.map(f=>e.jsx(W,{variant:"outline",size:"sm",onClick:()=>m(f),disabled:a.includes(f),className:"text-xs h-8",children:f},f))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>v(f),className:"text-green-600 hover:text-green-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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(It,{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(Xe,{value:x,onChange:f=>h(f.target.value),placeholder:'e.g., "Bash(rm:*)"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),b(x))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>b(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>j(f),className:"text-red-600 hover:text-red-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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 Fi({skipPermissions:t,setSkipPermissions:s,allowedCommands:a,setAllowedCommands:o,disallowedCommands:n,setDisallowedCommands:l,newAllowedCommand:i,setNewAllowedCommand:d,newDisallowedCommand:x,setNewDisallowedCommand:h}){const m=f=>{f&&!a.includes(f)&&(o([...a,f]),d(""))},v=f=>{o(a.filter(E=>E!==f))},b=f=>{f&&!n.includes(f)&&(l([...n,f]),h(""))},j=f=>{l(n.filter(E=>E!==f))};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(It,{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:f=>s(f.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(kt,{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(Xe,{value:i,onChange:f=>d(f.target.value),placeholder:'e.g., "Shell(ls)" or "Shell(git status)"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),m(i))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>m(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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:Oi.map(f=>e.jsx(W,{variant:"outline",size:"sm",onClick:()=>m(f),disabled:a.includes(f),className:"text-xs h-8",children:f},f))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>v(f),className:"text-green-600 hover:text-green-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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(It,{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(Xe,{value:x,onChange:f=>h(f.target.value),placeholder:'e.g., "Shell(rm -rf)" or "Shell(sudo)"',onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),b(x))},className:"flex-1 h-10"}),e.jsxs(W,{onClick:()=>b(x),disabled:!x,size:"sm",className:"h-10 px-4",children:[e.jsx(lt,{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(f=>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:f}),e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>j(f),className:"text-red-600 hover:text-red-700",children:e.jsx(He,{className:"w-4 h-4"})})]},f)),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 Wi({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(kt,{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(It,{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 Bi({agent:t,...s}){return t==="claude"?e.jsx(_i,{...s}):t==="cursor"?e.jsx(Fi,{...s}):t==="codex"?e.jsx(Wi,{...s}):null}const Ui=t=>{switch(t){case"stdio":return e.jsx(mr,{className:"w-4 h-4"});case"sse":return e.jsx(pa,{className:"w-4 h-4"});case"http":return e.jsx(Nr,{className:"w-4 h-4"});default:return e.jsx(ur,{className:"w-4 h-4"})}};function Hi({servers:t,onAdd:s,onEdit:a,onDelete:o,onTest:n,onDiscoverTools:l,testResults:i,serverTools:d,toolsLoading:x,onDiscoverRepo:h}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ur,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Claude 提供额外的工具和数据源"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs(W,{onClick:s,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(lt,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(W,{onClick:h,variant:"outline",size:"sm",children:[e.jsx(us,{className:"w-4 h-4 mr-2"}),"MCP 商店"]})})]}),e.jsxs("div",{className:"space-y-2",children:[t.map(m=>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:[Ui(m.type),e.jsx("span",{className:"font-medium text-foreground",children:m.name}),e.jsx(Qe,{variant:"outline",className:"text-xs",children:m.type}),e.jsx(Qe,{variant:"outline",className:"text-xs",children:m.scope==="local"?"local":m.scope==="user"?"user":m.scope})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[m.type==="stdio"&&m.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:m.config.command})]}),(m.type==="sse"||m.type==="http")&&m.config?.url&&e.jsxs("div",{children:["URL:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:m.config.url})]}),m.config?.args&&m.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:m.config.args.join(" ")})]})]}),i?.[m.id]&&e.jsx("div",{className:`mt-2 p-2 rounded text-xs ${i[m.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[m.id].message})}),d?.[m.id]&&d[m.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[m.id].tools.length,"):"]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[d[m.id].tools.slice(0,5).map((v,b)=>e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:v.name},b)),d[m.id].tools.length>5&&e.jsxs("span",{className:"text-xs opacity-75",children:["+",d[m.id].tools.length-5," 更多"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(W,{onClick:()=>a(m),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(cr,{className:"w-4 h-4"})}),e.jsx(W,{onClick:()=>o(m.id,m.scope),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(tt,{className:"w-4 h-4"})})]})]})},m.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function qi({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(ur,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Cursor 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(W,{onClick:s,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(lt,{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(mr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Qe,{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(W,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",children:e.jsx(cr,{className:"w-4 h-4"})}),e.jsx(W,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",children:e.jsx(tt,{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 Ji({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(ur,{className:"w-5 h-5 text-gray-700 dark:text-gray-300"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 Codex 提供额外的工具和数据源"}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs(W,{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(lt,{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(mr,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium text-foreground",children:n.name}),e.jsx(Qe,{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(W,{onClick:()=>a(n),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(cr,{className:"w-4 h-4"})}),e.jsx(W,{onClick:()=>o(n.name),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(tt,{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 Ki({agent:t,...s}){return t==="claude"?e.jsx(Hi,{...s}):t==="cursor"?e.jsx(qi,{...s}):t==="codex"?e.jsx(Ji,{...s}):null}const Gi=[{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)使用的模型"}],Vi=r.forwardRef(function({onStatusChange:s},a){const[o,n]=r.useState({}),[l,i]=r.useState({}),[d,x]=r.useState(!0),[h,m]=r.useState(!1),[v,b]=r.useState(null),[j,f]=r.useState(null),E=JSON.stringify(o)!==JSON.stringify(l);r.useEffect(()=>{s?.({saving:h,hasChanges:E})},[h,E,s]),r.useEffect(()=>{O()},[]),r.useEffect(()=>{if(v){const g=setTimeout(()=>b(null),3e3);return()=>clearTimeout(g)}},[v]);const O=async()=>{try{x(!0),f(null);const g=await Z("/api/settings/models");if(g.ok){const p=await g.json();n(p.models||{}),i(p.models||{})}else{const p=await g.json();f(p.error||"加载模型配置失败")}}catch(g){f(g.message)}finally{x(!1)}},T=async()=>{try{m(!0),b(null);const g=await Z("/api/settings/models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({models:o})});if(g.ok)return b("success"),i({...o}),!0;{const p=await g.json();return b("error"),f(p.error||"保存失败"),!1}}catch(g){return b("error"),f(g.message),!1}finally{m(!1)}},R=()=>{n({...l}),b(null)};return r.useImperativeHandle(a,()=>({save:T,reset:R,get hasChanges(){return E},get saving(){return h}}),[E,h,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(ms,{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。"})]})]}),j&&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:j}),v==="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:"模型配置已保存"}),Gi.map(g=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"font-medium text-sm text-foreground",children:g.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:g.description})]}),e.jsx("input",{type:"text",value:o[g.key]||"",onChange:p=>n(u=>({...u,[g.key]:p.target.value})),placeholder:g.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:g.key})]})},g.key))]})});function Yi({onClose:t,onInstalled:s,onOpenRepoManager:a}){const{showAlert:o}=ct(),[n,l]=r.useState([]),[i,d]=r.useState([]),[x,h]=r.useState(!0),[m,v]=r.useState(null),[b,j]=r.useState(""),[f,E]=r.useState("all"),[O,T]=r.useState(null);r.useEffect(()=>{R()},[]);const R=async(u=!1)=>{try{h(!0),v(null),u&&await Z("/api/skills/repos/refresh",{method:"POST"});const[y,L]=await Promise.all([Z("/api/skills/available"),Z("/api/skills/repos")]);if(y.ok){const $=await y.json();l($.skills||[])}if(L.ok){const $=await L.json();d($.repos||[])}}catch(y){v(y.message)}finally{h(!1)}},g=async u=>{try{T(u.name);const y=await Z(`/api/skills/install/${u.name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillPath:u.path})});if(y.ok)R(),s?.();else{const L=await y.json();o(L.error||"安装技能失败",{variant:"error"})}}catch(y){o(y.message,{variant:"error"})}finally{T(null)}},p=n.filter(u=>{if(b){const y=b.toLowerCase();if(!u.name.toLowerCase().includes(y)&&!u.title?.toLowerCase().includes(y)&&!u.description?.toLowerCase().includes(y))return!1}return!(f!=="all"&&u.repository!==f)});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(W,{variant:"ghost",size:"sm",onClick:()=>R(!0),disabled:x,children:[e.jsx(_t,{className:`w-4 h-4 ${x?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(W,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Tt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(He,{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(Ft,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索技能名称或描述...",value:b,onChange:u=>j(u.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:f,onChange:u=>E(u.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:"全部"}),i.map(u=>e.jsxs("option",{value:`${u.owner}/${u.repo}`,children:[u.owner,"/",u.repo]},`${u.owner}/${u.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[m&&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:m}),x?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):p.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:n.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的技能"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加技能仓库"}),e.jsxs(W,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Tt,{className:"w-4 h-4 mr-2"}),"管理仓库"]})]}):e.jsx("p",{children:"没有找到匹配的技能"})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:p.map(u=>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:u.title||u.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["skills/",u.name]}),e.jsx(Qe,{variant:"outline",className:"text-xs ml-2",children:u.repository})]})]}),u.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:u.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-auto pt-2",children:[e.jsxs(W,{variant:"ghost",size:"sm",onClick:()=>window.open(`https://github.com/${u.repository}`,"_blank"),children:[e.jsx(xa,{className:"w-4 h-4 mr-1"}),"查看"]}),u.installed?e.jsx(W,{size:"sm",disabled:!0,variant:"outline",className:"ml-auto",children:"已安装"}):e.jsxs(W,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white ml-auto",onClick:()=>g(u),disabled:O===u.name,children:[e.jsx(Ot,{className:"w-4 h-4 mr-1"}),O===u.name?"安装中...":"安装"]})]})]})},`${u.repository}-${u.name}`))})]})]})})}function Qi({onClose:t,onChanged:s}){const{showAlert:a,showConfirm:o}=ct(),[n,l]=r.useState([]),[i,d]=r.useState(!0),[x,h]=r.useState(null),[m,v]=r.useState(""),[b,j]=r.useState("main"),[f,E]=r.useState(!1),[O,T]=r.useState(null);r.useEffect(()=>{R()},[]);const R=async()=>{try{d(!0),h(null);const u=await Z("/api/skills/repos");if(u.ok){const y=await u.json();l(y.repos||[])}else{const y=await u.json();h(y.error||"Failed to fetch repos")}}catch(u){h(u.message)}finally{d(!1)}},g=async u=>{if(u.preventDefault(),!m.trim()){h("请输入仓库 URL");return}try{E(!0),h(null);const y=await Z("/api/skills/repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:m.trim(),branch:b.trim()||"main"})});if(y.ok)v(""),j("main"),R(),s?.();else{const L=await y.json();h(L.error||"Failed to add repo")}}catch(y){h(y.message)}finally{E(!1)}},p=async(u,y)=>{if(await o(`确定要移除仓库 "${u}/${y}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{T(`${u}/${y}`);const L=await Z(`/api/skills/repos/${u}/${y}`,{method:"DELETE"});if(L.ok)R(),s?.();else{const $=await L.json();a($.error||"移除仓库失败",{variant:"error"})}}catch(L){a(L.message,{variant:"error"})}finally{T(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(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Qt,{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:g,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(Xe,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:m,onChange:u=>v(u.target.value),disabled:f})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"分支"}),e.jsx(Xe,{type:"text",placeholder:"main",value:b,onChange:u=>j(u.target.value),disabled:f})]}),e.jsxs(W,{type:"submit",disabled:f||!m.trim(),className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(lt,{className:"w-4 h-4 mr-2"}),f?"添加中...":"添加仓库"]})]})]}),x&&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:x}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"已添加的仓库"}),i?e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ha,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何仓库"})]}):n.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(Qe,{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(us,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Qe,{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(W,{variant:"ghost",size:"sm",onClick:()=>window.open(u.url,"_blank"),children:e.jsx(xa,{className:"w-4 h-4"})}),!u.isSystem&&e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>p(u.owner,u.repo),disabled:O===`${u.owner}/${u.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(tt,{className:"w-4 h-4"})})]})]})},`${u.owner}/${u.repo}`))]})]})]})})}function Zi(){const{showAlert:t,showConfirm:s}=ct(),[a,o]=r.useState([]),[n,l]=r.useState(!0),[i,d]=r.useState(null),[x,h]=r.useState(!1),[m,v]=r.useState(!1),[b,j]=r.useState(!1),f=r.useRef(null);r.useEffect(()=>{E()},[]);const E=async()=>{try{l(!0),d(null);const p=await Z("/api/skills");if(p.ok){const u=await p.json();o(u.skills||[])}else{const u=await p.json();d(u.error||"Failed to fetch skills")}}catch(p){d(p.message)}finally{l(!1)}},O=async p=>{if(await s(`确定要删除技能 "${p}" 吗?`,{title:"删除技能",variant:"danger",confirmText:"确认删除"}))try{const u=await Z(`/api/skills/${p}`,{method:"DELETE"});if(u.ok)E();else{const y=await u.json();t(y.error||"删除技能失败",{variant:"error"})}}catch(u){t(u.message,{variant:"error"})}},T=()=>{f.current?.click()},R=async p=>{const u=p.target.files?.[0];if(u)try{j(!0);const y=new FormData;y.append("skillZip",u);const L=await Z("/api/skills/import",{method:"POST",body:y});if(L.ok)E();else{const $=await L.json();t($.error||"导入技能失败",{variant:"error"})}}catch(y){t(y.message,{variant:"error"})}finally{j(!1),f.current&&(f.current.value="")}},g=(p,u)=>{switch(p){case"repo":return e.jsx(Qe,{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(Qe,{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(Qe,{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(Yr,{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:a.length})," 个技能"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{ref:f,type:"file",accept:".zip",className:"hidden",onChange:R}),e.jsxs(W,{onClick:T,variant:"outline",size:"sm",disabled:b,children:[e.jsx(Ot,{className:"w-4 h-4 mr-2"}),b?"导入中...":"导入已有"]}),e.jsxs(W,{onClick:()=>h(!0),className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:[e.jsx(Ft,{className:"w-4 h-4 mr-2"}),"发现技能"]})]})]}),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.jsx("div",{className:"space-y-2",children:n?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Yr,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有安装任何技能"}),e.jsx("p",{className:"text-xs mt-2",children:'点击"发现技能"从仓库安装,或"导入已有"上传本地技能'})]}):a.map(p=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-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:p.title||p.name}),g(p.source,p.repository)]}),p.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:p.description})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4 shrink-0",children:e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>O(p.name),className:"text-red-500 hover:text-red-600",title:"删除技能",children:e.jsx(tt,{className:"w-4 h-4"})})})]})},p.name))}),x&&e.jsx(Yi,{onClose:()=>h(!1),onInstalled:E,onOpenRepoManager:()=>{h(!1),v(!0)}}),m&&e.jsx(Qi,{onClose:()=>v(!1),onChanged:()=>{}})]})}function Xi({onClose:t,onChanged:s}){const{showAlert:a,showConfirm:o}=ct(),[n,l]=r.useState([]),[i,d]=r.useState(!0),[x,h]=r.useState(null),[m,v]=r.useState(""),[b,j]=r.useState(!1),[f,E]=r.useState(null);r.useEffect(()=>{O()},[]);const O=async()=>{try{d(!0),h(null);const g=await Z("/api/mcp-repos");if(g.ok){const p=await g.json();l(p.repos||[])}else{const p=await g.json();h(p.error||"Failed to fetch repos")}}catch(g){h(g.message)}finally{d(!1)}},T=async g=>{if(g.preventDefault(),!m.trim()){h("请输入仓库 URL");return}try{j(!0),h(null);const p=await Z("/api/mcp-repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:m.trim()})});if(p.ok)v(""),O(),s?.();else{const u=await p.json();h(u.error||"Failed to add repo")}}catch(p){h(p.message)}finally{j(!1)}},R=async(g,p)=>{if(await o(`确定要移除仓库 "${g}/${p}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{E(`${g}/${p}`);const u=await Z(`/api/mcp-repos/${g}/${p}`,{method:"DELETE"});if(u.ok)O(),s?.();else{const y=await u.json();a(y.error||"移除仓库失败",{variant:"error"})}}catch(u){a(u.message,{variant:"error"})}finally{E(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(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Qt,{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:T,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(Xe,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:m,onChange:g=>v(g.target.value),disabled:b})]}),e.jsxs(W,{type:"submit",disabled:b||!m.trim(),className:"bg-purple-600 hover:bg-purple-700 text-white",children:[e.jsx(lt,{className:"w-4 h-4 mr-2"}),b?"添加中...":"添加仓库"]})]})]}),x&&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:x}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"已添加的仓库"}),i?e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:"加载中..."}):n.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ha,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何 MCP 仓库"})]}):n.map(g=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-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:[g.owner,"/",g.repo]}),g.isSystem&&e.jsx(Qe,{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(us,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Qe,{variant:"outline",className:"text-xs",children:[g.serviceCount," 个 MCP 服务"]})]})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4",children:!g.isSystem&&e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>R(g.owner,g.repo),disabled:f===`${g.owner}/${g.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(tt,{className:"w-4 h-4"})})})]})},`${g.owner}/${g.repo}`))]})]})]})})}const el=t=>{switch(t){case"stdio":return e.jsx(mr,{className:"w-3 h-3"});case"sse":return e.jsx(pa,{className:"w-3 h-3"});case"http":return e.jsx(Nr,{className:"w-3 h-3"});default:return e.jsx(ur,{className:"w-3 h-3"})}};function tl({onClose:t,onInstalled:s,onOpenRepoManager:a}){const{showAlert:o,showConfirm:n}=ct(),[l,i]=r.useState([]),[d,x]=r.useState([]),[h,m]=r.useState(!0),[v,b]=r.useState(null),[j,f]=r.useState(""),[E,O]=r.useState("all"),[T,R]=r.useState(null),[g,p]=r.useState(null);r.useEffect(()=>{u()},[]);const u=async(P=!1)=>{try{m(!0),b(null),P&&await Z("/api/mcp-repos/refresh",{method:"POST"});const[z,me]=await Promise.all([Z("/api/mcp-repos/available"),Z("/api/mcp-repos")]);if(z.ok){const se=await z.json();i(se.services||[])}if(me.ok){const se=await me.json();x(se.repos||[])}}catch(z){b(z.message)}finally{m(!1)}},y=async P=>{try{R(P.dirName+P.repository);const z=await Z("/api/mcp-repos/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({servicePath:P.path})});if(z.ok)u(),s?.();else{const me=await z.json();o(me.error||"安装 MCP 服务失败",{variant:"error"})}}catch(z){o(z.message,{variant:"error"})}finally{R(null)}},L=async P=>{if(!(!P.serverNames||P.serverNames.length===0)&&await n(`确定要卸载 "${P.name}" 吗?这将移除 ${P.serverNames.join(", ")} 的配置。`,{title:"卸载 MCP 服务",variant:"danger",confirmText:"确认卸载"}))try{p(P.dirName+P.repository);for(const z of P.serverNames)await Z(`/api/mcp-repos/uninstall/${encodeURIComponent(z)}`,{method:"DELETE"});u(),s?.()}catch(z){o(z.message,{variant:"error"})}finally{p(null)}},$=l.filter(P=>{if(j){const z=j.toLowerCase();if(!P.dirName?.toLowerCase().includes(z)&&!P.name?.toLowerCase().includes(z)&&!P.description?.toLowerCase().includes(z))return!1}return!(E!=="all"&&P.repository!==E)});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(W,{variant:"ghost",size:"sm",onClick:()=>u(!0),disabled:h,children:[e.jsx(_t,{className:`w-4 h-4 ${h?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(W,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Tt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(W,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(He,{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(Ft,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Xe,{type:"text",placeholder:"搜索 MCP 服务名称或描述...",value:j,onChange:P=>f(P.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:E,onChange:P=>O(P.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:"全部仓库"}),d.map(P=>e.jsxs("option",{value:`${P.owner}/${P.repo}`,children:[P.owner,"/",P.repo]},`${P.owner}/${P.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[v&&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:v}),h?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):$.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:l.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的 MCP 服务"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加 MCP 仓库"}),e.jsxs(W,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Tt,{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:$.map(P=>{const z=`${P.repository}-${P.dirName}`,me=T===P.dirName+P.repository,se=g===P.dirName+P.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:P.name||P.dirName}),e.jsxs(Qe,{variant:"outline",className:"text-xs flex items-center gap-1",children:[el(P.type),P.type]})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:P.repository}),P.serverNames?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:["· ",P.serverNames.join(", ")]})]})]}),P.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:P.description}),e.jsx("div",{className:"flex items-center gap-2 mt-auto pt-2",children:P.installed?e.jsxs(W,{size:"sm",variant:"outline",className:"ml-auto text-red-600 hover:text-red-700 border-red-200 hover:border-red-300",onClick:()=>L(P),disabled:se,children:[e.jsx(tt,{className:"w-4 h-4 mr-1"}),se?"卸载中...":"卸载"]}):e.jsxs(W,{size:"sm",className:"bg-purple-600 hover:bg-purple-700 text-white ml-auto",onClick:()=>y(P),disabled:me,children:[e.jsx(Ot,{className:"w-4 h-4 mr-1"}),me?"安装中...":"安装"]})})]})},z)})})]})]})})}function rl({isOpen:t,onClose:s,projects:a=[],initialTab:o="agents"}){const n=na(),{isDarkMode:l,toggleDarkMode:i}=ws(),{user:d,logout:x}=Nt(),{showAlert:h,showConfirm:m}=ct(),[v,b]=r.useState([]),[j,f]=r.useState([]),[E,O]=r.useState(""),[T,R]=r.useState(""),[g,p]=r.useState(!1),[u,y]=r.useState(!1),[L,$]=r.useState(null),[P,z]=r.useState("name"),[me,se]=r.useState([]),[te,de]=r.useState(!1),[_,A]=r.useState(null),[ae,fe]=r.useState(!1),[ue,X]=r.useState(!1),[G,pe]=r.useState({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),[Pe,Ee]=r.useState(!1),[Me,Ne]=r.useState({}),[qe,Ge]=r.useState({}),[We,De]=r.useState({}),[je,$e]=r.useState(o),[Fe,_e]=r.useState(""),[ze,J]=r.useState("permissions"),q=r.useRef(null),[w,K]=r.useState({saving:!1,hasChanges:!1}),he=r.useCallback(D=>K(D),[]),[ve,Ae]=r.useState(""),[Ue,V]=r.useState(""),[oe,Ie]=r.useState(""),[Te,Ce]=r.useState(""),[N,ee]=r.useState(""),[we,Y]=r.useState(!1),[U,M]=r.useState(""),[ne,B]=r.useState(!1),[re,ie]=r.useState(""),[ye,xe]=r.useState(!1),[Ye,Le]=r.useState(null),[Je,st]=r.useState(()=>localStorage.getItem("codeEditorTheme")||"dark"),[at,Dr]=r.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[ft,Rt]=r.useState(()=>localStorage.getItem("codeEditorShowMinimap")!=="false"),[St,Ir]=r.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[ot,Tr]=r.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),bt=async()=>{try{const D=await Z("/api/mcp/config/read");if(D.ok){const Re=await D.json();if(Re.success&&Re.servers){se(Re.servers);return}}const H=await Z("/api/mcp/cli/list");if(H.ok){const Re=await H.json();if(Re.success&&Re.servers){const nt=Re.servers.map(xt=>({id:xt.name,name:xt.name,type:xt.type,scope:"user",config:{command:xt.command||"",args:xt.args||[],env:xt.env||{},url:xt.url||"",headers:xt.headers||{},timeout:3e4},created:new Date().toISOString(),updated:new Date().toISOString()}));se(nt);return}}const le=await Z("/api/mcp/servers?scope=user");if(le.ok){const Re=await le.json();se(Re.servers||[])}else console.error("Failed to fetch MCP servers")}catch(D){console.error("Error fetching MCP servers:",D)}},Zt=async D=>{try{_&&await Xt(_.id,"user");const H=await Z("/api/mcp/cli/add",{method:"POST",body:JSON.stringify({name:D.name,type:D.type,scope:D.scope,projectPath:D.projectPath,command:D.config?.command,args:D.config?.args||[],url:D.config?.url,headers:D.config?.headers||{},env:D.config?.env||{}})});if(H.ok){const le=await H.json();if(le.success)return await bt(),!0;throw new Error(le.error||"Failed to save server via Claude CLI")}else{const le=await H.json();throw new Error(le.error||"Failed to save server")}}catch(H){throw console.error("Error saving MCP server:",H),H}},Xt=async(D,H="user")=>{try{const le=await Z(`/api/mcp/cli/remove/${D}?scope=${H}`,{method:"DELETE"});if(le.ok){const Re=await le.json();if(Re.success)return await bt(),!0;throw new Error(Re.error||"Failed to delete server via Claude CLI")}else{const Re=await le.json();throw new Error(Re.error||"Failed to delete server")}}catch(le){throw console.error("Error deleting MCP server:",le),le}},Bt=async(D,H="user")=>{try{const le=await Z(`/api/mcp/servers/${D}/test?scope=${H}`,{method:"POST"});if(le.ok)return(await le.json()).testResult;{const Re=await le.json();throw new Error(Re.error||"Failed to test server")}}catch(le){throw console.error("Error testing MCP server:",le),le}},pr=async(D,H="user")=>{try{const le=await Z(`/api/mcp/servers/${D}/tools?scope=${H}`,{method:"POST"});if(le.ok)return(await le.json()).toolsResult;{const Re=await le.json();throw new Error(Re.error||"Failed to discover tools")}}catch(le){throw console.error("Error discovering MCP tools:",le),le}};r.useEffect(()=>{t&&(Ut(),$e(o),ke.auth.feishuStatus().then(D=>D.json()).then(D=>{Le(D.bound?D:!1)}).catch(()=>Le(!1)))},[t,o]),r.useEffect(()=>{localStorage.setItem("codeEditorTheme",Je),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Je]),r.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",at.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[at]),r.useEffect(()=>{localStorage.setItem("codeEditorShowMinimap",ft.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[ft]),r.useEffect(()=>{localStorage.setItem("codeEditorLineNumbers",St.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[St]),r.useEffect(()=>{localStorage.setItem("codeEditorFontSize",ot),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[ot]);const Ut=async()=>{try{let D=null;try{const H=await ke.settings.getAgentPermissions();H.ok&&(D=(await H.json()).agentPermissions)}catch{}if(D)b(D.allowedTools||[]),f(D.disallowedTools||[]),p(D.skipPermissions||!1),z(D.projectSortOrder||"name"),localStorage.setItem("claude-settings",JSON.stringify(D));else{const H=localStorage.getItem("claude-settings");if(H){const le=JSON.parse(H);b(le.allowedTools||[]),f(le.disallowedTools||[]),p(le.skipPermissions||!1),z(le.projectSortOrder||"name")}else b([]),f([]),p(!1),z("name")}await bt()}catch(D){console.error("Error loading tool settings:",D),b([]),f([]),p(!1),z("name")}},Rr=async()=>{y(!0),$(null);try{const D={allowedTools:v,disallowedTools:j,skipPermissions:g,projectSortOrder:P,lastUpdated:new Date().toISOString()};localStorage.setItem("claude-settings",JSON.stringify(D));try{await ke.settings.saveAgentPermissions(D)}catch(H){console.warn("Failed to sync agent permissions to server:",H)}$("success"),setTimeout(()=>{s()},1e3)}catch(D){console.error("Error saving tool settings:",D),$("error")}finally{y(!1)}},dt=async D=>{if(D.preventDefault(),Ce(""),ee(""),!ve){Ce("请输入当前密码");return}if(!Ue){Ce("请输入新密码");return}if(Ue.length<6){Ce("新密码至少需要6个字符");return}if(Ue!==oe){Ce("两次输入的新密码不一致");return}Y(!0);try{const H=await ke.auth.changePassword(ve,Ue),le=await H.json();H.ok?(ee("密码修改成功"),Ae(""),V(""),Ie("")):Ce(le.error||"修改密码失败")}catch(H){console.error("Error changing password:",H),Ce("网络错误,请稍后再试")}finally{Y(!1)}},er=d?.username&&!d.username.includes("@"),Pt=async()=>{B(!0),ie(""),M(""),xe(!1);try{const D=await ke.auth.feishuBindToken(),H=await D.json();D.ok&&H.token?M(H.token):ie(H.error||"生成失败,请重试")}catch{ie("网络错误,请稍后再试")}finally{B(!1)}},tr=()=>{if(!U)return;const D=`/auth ${U}`;if(navigator.clipboard&&window.isSecureContext)navigator.clipboard.writeText(D).then(()=>{xe(!0),setTimeout(()=>xe(!1),2e3)});else{const H=document.createElement("textarea");H.value=D,H.style.position="fixed",H.style.opacity="0",document.body.appendChild(H),H.focus(),H.select();try{document.execCommand("copy"),xe(!0),setTimeout(()=>xe(!1),2e3)}finally{document.body.removeChild(H)}}},vt=()=>{pe({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),A(null),de(!1),_e("")},mt=(D=null)=>{D?(A(D),pe({name:D.name,type:D.type,scope:D.scope,projectPath:D.projectPath||"",config:{...D.config},raw:D.raw,importMode:"form",jsonInput:""})):vt(),de(!0)},Ht=async D=>{D.preventDefault(),Ee(!0);try{if(G.importMode==="json"){const H=await Z("/api/mcp/cli/add-json",{method:"POST",body:JSON.stringify({name:G.name,jsonConfig:G.jsonInput,scope:G.scope,projectPath:G.projectPath})});if(H.ok){const le=await H.json();if(le.success)await bt(),vt(),$("success");else throw new Error(le.error||"Failed to add server via JSON")}else{const le=await H.json();throw new Error(le.error||"Failed to add server")}}else await Zt(G),vt(),$("success")}catch(H){h(`错误: ${H.message}`,{variant:"error"}),$("error")}finally{Ee(!1)}},rr=async(D,H)=>{if(await m("确定要删除此 MCP 服务器吗?",{title:"删除 MCP 服务器",variant:"danger",confirmText:"确认删除"}))try{await Xt(D,H),$("success")}catch(le){h(`错误: ${le.message}`,{variant:"error"}),$("error")}},sr=async(D,H)=>{try{Ne({...Me,[D]:{loading:!0}});const le=await Bt(D,H);Ne({...Me,[D]:le})}catch(le){Ne({...Me,[D]:{success:!1,message:le.message,details:[]}})}},yt=async(D,H)=>{try{De({...We,[D]:!0});const le=await pr(D,H);Ge({...qe,[D]:le})}catch{Ge({...qe,[D]:{success:!1,tools:[],resources:[],prompts:[]}})}finally{De({...We,[D]:!1})}},et=(D,H)=>{pe(le=>({...le,config:{...le.config,[D]:H}}))};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(Tt,{className:"w-5 h-5 md:w-6 md:h-6 text-blue-600"}),e.jsx("h2",{className:"text-lg md:text-xl font-semibold text-foreground",children:"设置"})]}),e.jsx(W,{variant:"ghost",size:"sm",onClick:s,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(He,{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:()=>$e("agents"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="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:()=>$e("appearance"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="appearance"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"外观"}),e.jsx("button",{onClick:()=>$e("account"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="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:[je==="appearance"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:je==="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(Qr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Zr,{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:P,onChange:D=>z(D.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:()=>st(Je==="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":Je==="dark","aria-label":"Toggle editor theme",children:[e.jsx("span",{className:"sr-only",children:"Toggle editor theme"}),e.jsx("span",{className:`${Je==="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:Je==="dark"?e.jsx(Qr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Zr,{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:()=>Dr(!at),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":at,"aria-label":"Toggle word wrap",children:[e.jsx("span",{className:"sr-only",children:"Toggle word wrap"}),e.jsx("span",{className:`${at?"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:()=>Rt(!ft),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":ft,"aria-label":"Toggle minimap",children:[e.jsx("span",{className:"sr-only",children:"Toggle minimap"}),e.jsx("span",{className:`${ft?"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:()=>Ir(!St),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":St,"aria-label":"Toggle line numbers",children:[e.jsx("span",{className:"sr-only",children:"Toggle line numbers"}),e.jsx("span",{className:`${St?"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:ot,onChange:D=>Tr(D.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"})]})]})})]})]})}),je==="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:()=>J("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 ${ze==="permissions"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"权限"}),e.jsx("button",{onClick:()=>J("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 ${ze==="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:()=>J("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 ${ze==="skills"?"border-amber-600 text-amber-600 dark:text-amber-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"技能"}),e.jsx("button",{onClick:()=>J("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 ${ze==="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:[ze==="permissions"&&e.jsx(Bi,{agent:"claude",skipPermissions:g,setSkipPermissions:p,allowedTools:v,setAllowedTools:b,disallowedTools:j,setDisallowedTools:f,newAllowedTool:E,setNewAllowedTool:O,newDisallowedTool:T,setNewDisallowedTool:R}),ze==="mcp"&&e.jsx(Ki,{agent:"claude",servers:me,onAdd:()=>mt(),onEdit:D=>mt(D),onDelete:(D,H)=>rr(D,H),onTest:(D,H)=>sr(D,H),onDiscoverTools:(D,H)=>yt(D,H),testResults:Me,serverTools:qe,toolsLoading:We,onDiscoverRepo:()=>fe(!0)}),ze==="skills"&&e.jsx(Zi,{}),ze==="models"&&e.jsx(Vi,{ref:q,onStatusChange:he})]})]})}),je==="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==="super_admin"?"超级管理员":d?.role==="admin"?"管理员":"用户"})]})]})}),er&&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(Xr,{className:"w-5 h-5 text-blue-600"}),e.jsx("div",{className:"font-medium text-foreground",children:"修改密码"})]}),e.jsxs("form",{onSubmit:dt,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:ve,onChange:D=>Ae(D.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:we})]}),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:Ue,onChange:D=>V(D.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:we})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmNewPassword",className:"block text-sm font-medium text-foreground mb-1",children:"确认新密码"}),e.jsx("input",{type:"password",id:"confirmNewPassword",value:oe,onChange:D=>Ie(D.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:we})]}),Te&&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:Te})}),N&&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:N})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(W,{type:"submit",disabled:we,className:"bg-blue-600 hover:bg-blue-700",children:we?"修改中...":"修改密码"})})]})]}),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:"飞书账号绑定"})]}),Ye?e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-md",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 shrink-0"}),e.jsxs("div",{className:"text-sm text-green-700 dark:text-green-400",children:["已绑定",e.jsx("span",{className:"ml-2 text-xs text-green-600/70 dark:text-green-500/70 font-mono",children:Ye.feishuOpenId}),Ye.createdAt&&e.jsxs("span",{className:"ml-2 text-xs text-green-600/70 dark:text-green-500/70",children:["· ",new Date(Ye.createdAt).toLocaleDateString("zh-CN")]})]})]}):Ye===!1?e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 bg-gray-100 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 rounded-md",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-gray-400 shrink-0"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"未绑定飞书账号"})]}):null,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 小时。"]}),U?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 ",U]}),e.jsx("button",{onClick:tr,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:ye?e.jsx(wr,{className:"w-4 h-4 text-green-500"}):e.jsx(En,{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:Pt,disabled:ne,className:"flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 hover:underline disabled:opacity-50",children:[e.jsx(_t,{className:"w-3 h-3"}),"重新生成"]})]})]}):e.jsxs("div",{className:"space-y-2",children:[re&&e.jsx("p",{className:"text-sm text-red-500",children:re}),e.jsxs(W,{onClick:Pt,disabled:ne,variant:"outline",className:"gap-2",children:[ne?e.jsx(_t,{className:"w-4 h-4 animate-spin"}):e.jsx(Xr,{className:"w-4 h-4"}),ne?"生成中...":"生成绑定 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(W,{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:async()=>{await m("确定要退出登录吗?",{title:"退出登录",variant:"warning",confirmText:"退出"})&&(s(),n("/"),x())},children:[e.jsx(Mn,{className:"w-4 h-4"}),"退出"]})]})})]})}),te&&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:_?"编辑 MCP 服务器":"添加 MCP 服务器"}),e.jsx(W,{variant:"ghost",size:"sm",onClick:vt,children:e.jsx(He,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:Ht,className:"p-4 space-y-4",children:[!_&&e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>pe(D=>({...D,importMode:"form"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${G.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:()=>pe(D=>({...D,importMode:"json"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${G.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 导入"})]}),G.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-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:[G.scope==="user"?e.jsx(Nr,{className:"w-4 h-4"}):e.jsx(At,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:G.scope==="user"?"用户(全局)":"项目(本地)"}),G.scope==="local"&&G.projectPath&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",G.projectPath]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"编辑现有服务器时无法更改作用域"})]}),G.importMode==="form"&&!_&&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:()=>pe(D=>({...D,scope:"user",projectPath:""})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${G.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(Nr,{className:"w-4 h-4"}),e.jsx("span",{children:"用户(全局)"})]})}),e.jsx("button",{type:"button",onClick:()=>pe(D=>({...D,scope:"local"})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${G.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(At,{className:"w-4 h-4"}),e.jsx("span",{children:"项目(本地)"})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:G.scope==="user"?"用户作用域:在您机器上的所有项目中可用":"本地作用域:仅在选定的项目中可用"})]}),G.scope==="local"&&!_&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"项目 *"}),e.jsxs("select",{value:G.projectPath,onChange:D=>pe(H=>({...H,projectPath:D.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:G.scope==="local",children:[e.jsx("option",{value:"",children:"选择项目..."}),a.map(D=>e.jsx("option",{value:D.path||D.fullPath,children:D.displayName||D.name},D.name))]}),G.projectPath&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Path: ",G.projectPath]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:G.importMode==="json"?"md:col-span-2":"",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称 *"}),e.jsx(Xe,{value:G.name,onChange:D=>{pe(H=>({...H,name:D.target.value}))},placeholder:"my-server",required:!0})]}),G.importMode==="form"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"传输类型 *"}),e.jsxs("select",{value:G.type,onChange:D=>{pe(H=>({...H,type:D.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"})]})]})]}),_&&G.raw&&G.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 ",_.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(G.raw,null,2)})]}),G.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:G.jsonInput,onChange:D=>{pe(H=>({...H,jsonInput:D.target.value}));try{if(D.target.value.trim()){const H=JSON.parse(D.target.value);H.type?H.type==="stdio"&&!H.command?_e("stdio 类型需要 command 字段"):(H.type==="http"||H.type==="sse")&&!H.url?_e(`${H.type} 类型需要 url 字段`):_e(""):_e("缺少必填字段:type")}}catch{D.target.value.trim()?_e("无效的 JSON 格式"):_e("")}},className:`w-full px-3 py-2 border ${Fe?"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:`{
137
137
  "type": "stdio",
138
138
  "command": "/path/to/server",
139
139
  "args": ["--api-key", "abc123"],
140
140
  "env": {
141
141
  "CACHE_DIR": "/tmp"
142
142
  }
143
- }`,required:!0}),Fe&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:Fe}),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"}']})]})}),G.importMode==="form"&&G.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(Xe,{value:G.config.command,onChange:I=>ft("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(G.config.args)?G.config.args.join(`
144
- `):"",onChange:I=>ft("args",I.target.value.split(`
145
- `).filter(U=>U.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
146
- abc123`})]})]}),G.importMode==="form"&&(G.type==="sse"||G.type==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"URL *"}),e.jsx(Xe,{value:G.config.url,onChange:I=>ft("url",I.target.value),placeholder:"https://api.example.com/mcp",type:"url",required:!0})]}),G.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(G.config.env||{}).map(([I,U])=>`${I}=${U}`).join(`
147
- `),onChange:I=>{const U={};I.target.value.split(`
148
- `).forEach(le=>{const[Ee,...bt]=le.split("=");Ee&&Ee.trim()&&(U[Ee.trim()]=bt.join("=").trim())}),ft("env",U)},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
149
- DEBUG=true`})]}),G.importMode==="form"&&(G.type==="sse"||G.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(G.config.headers||{}).map(([I,U])=>`${I}=${U}`).join(`
150
- `),onChange:I=>{const U={};I.target.value.split(`
151
- `).forEach(le=>{const[Ee,...bt]=le.split("=");Ee&&Ee.trim()&&(U[Ee.trim()]=bt.join("=").trim())}),ft("headers",U)},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
152
- X-API-Key=your-key`})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(W,{type:"button",variant:"outline",onClick:ut,children:"取消"}),e.jsx(W,{type:"submit",disabled:Pe,className:"bg-purple-600 hover:bg-purple-700 disabled:opacity-50",children:Pe?"保存中...":_?"更新服务器":"添加服务器"})]})]})]})})]})]}),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:je==="agents"&&ze==="models"?w.saving?e.jsx("span",{className:"text-sm text-muted-foreground",children:"保存中..."}):null:e.jsxs(e.Fragment,{children:[L==="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"})}),"设置保存成功!"]}),L==="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:[je==="agents"&&ze==="models"&&w.hasChanges&&e.jsx(W,{variant:"outline",onClick:()=>q.current?.reset(),disabled:w.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"重置"}),e.jsx(W,{variant:"outline",onClick:s,disabled:u||w.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"取消"}),e.jsx(W,{onClick:je==="agents"&&ze==="models"?()=>q.current?.save():ur,disabled:je==="agents"&&ze==="models"?w.saving||!w.hasChanges:u,className:"flex-1 sm:flex-none h-10 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 touch-manipulation",children:u||w.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"}),"保存中..."]}):"保存设置"})]})]})]})}),ae&&e.jsx(tl,{onClose:()=>fe(!1),onInstalled:()=>at(),onOpenRepoManager:()=>{fe(!1),Z(!0)}}),ue&&e.jsx(Xi,{onClose:()=>Z(!1),onChanged:()=>{}})]}):null}function sl({isSuperAdmin:t,onNavigateToUsage:s,onViewUser:a}){const{user:o}=wt(),{showConfirm:n}=ct(),[l,i]=r.useState([]),[d,x]=r.useState({}),[h,m]=r.useState(!0),[v,b]=r.useState(null),[j,f]=r.useState(!1),[E,O]=r.useState(""),[T,R]=r.useState(""),[g,p]=r.useState(""),[u,y]=r.useState(!1),[L,$]=r.useState(null),[P,z]=r.useState({total_limit_usd:"",daily_limit_usd:""}),[me,se]=r.useState(""),[te,de]=r.useState(!1),[_,A]=r.useState(null),[ae,fe]=r.useState(""),[ue,Z]=r.useState(""),[G,pe]=r.useState(""),[Pe,Me]=r.useState(!1),[Le,Ne]=r.useState(null),[qe,Ke]=r.useState(""),[We,Ie]=r.useState(""),[je,$e]=r.useState(!1),Fe=async()=>{try{const M=await X("/api/admin/users");if(M.ok){const ne=await M.json();i(ne.users)}}catch(M){console.error("Error fetching users:",M)}finally{m(!1)}},_e=async()=>{try{const M=await X("/api/admin/usage/summary");if(M.ok){const ne=await M.json(),B={};for(const re of ne.users)B[re.user_uuid]={total_cost:re.total_cost||0,total_requests:re.total_requests||0,last_active:re.last_active};x(B)}}catch(M){console.error("Error fetching usage data:",M)}};r.useEffect(()=>{Fe(),_e()},[]);const ze=M=>!M||M===0?"$0.00":M<.01?`$${M.toFixed(4)}`:`$${M.toFixed(2)}`,J=M=>M.role==="super_admin"?!1:t||M.id===o?.id?!0:M.role==="user",q=M=>M.id===o?.id?!1:t?M.role!=="super_admin":!["admin","super_admin"].includes(M.role),w=async(M,ne)=>{const B=ne==="active"?"disabled":"active";b(M);try{(await X(`/api/admin/users/${M}`,{method:"PATCH",body:JSON.stringify({status:B})})).ok&&i(l.map(ie=>ie.id===M?{...ie,status:B}:ie))}catch(re){console.error("Error updating user status:",re)}finally{b(null)}},K=async(M,ne)=>{if(await n(`确定要删除用户 "${ne}"?这将删除其所有数据。`,{title:"删除用户",variant:"danger",confirmText:"确认删除"})){b(M);try{(await X(`/api/admin/users/${M}`,{method:"DELETE"})).ok&&i(l.filter(re=>re.id!==M))}catch(B){console.error("Error deleting user:",B)}finally{b(null)}}},he=async M=>{if(M.preventDefault(),p(""),!E||!T){p("用户名和密码不能为空");return}if(E.length<3){p("用户名至少3个字符");return}if(T.length<6){p("密码至少6个字符");return}y(!0);try{const ne=await ke.admin.createUser(E,T),B=await ne.json();ne.ok?(await Fe(),f(!1),O(""),R("")):p(B.error||"创建用户失败")}catch(ne){console.error("Error creating user:",ne),p("网络错误,请稍后再试")}finally{y(!1)}},ve=()=>{f(!1),O(""),R(""),p("")},Ae=M=>{$(M),z({total_limit_usd:M.total_limit_usd!==null&&M.total_limit_usd!==void 0?String(M.total_limit_usd):"",daily_limit_usd:M.daily_limit_usd!==null&&M.daily_limit_usd!==void 0?String(M.daily_limit_usd):""}),se("")},Ue=()=>{$(null),z({total_limit_usd:"",daily_limit_usd:""}),se("")},V=async M=>{M.preventDefault(),se("");const ne=P.total_limit_usd.trim()===""?null:parseFloat(P.total_limit_usd),B=P.daily_limit_usd.trim()===""?null:parseFloat(P.daily_limit_usd);if(ne!==null&&(isNaN(ne)||ne<0)){se("总额度限制必须是正数或留空");return}if(B!==null&&(isNaN(B)||B<0)){se("每日额度限制必须是正数或留空");return}de(!0);try{const re=await ke.admin.updateUserLimits(L.id,{total_limit_usd:ne,daily_limit_usd:B}),ie=await re.json();re.ok?(i(l.map(ye=>ye.id===L.id?{...ye,total_limit_usd:ne,daily_limit_usd:B}:ye)),Ue()):se(ie.error||"更新限制失败")}catch(re){console.error("Error updating limits:",re),se("网络错误,请稍后再试")}finally{de(!1)}},oe=M=>M==null?"无限制":`$${M.toFixed(2)}`,Te=M=>{A(M),fe(""),Z(""),pe("")},Re=()=>{A(null),fe(""),Z(""),pe("")},Ce=async M=>{if(M.preventDefault(),pe(""),!ae){pe("请输入新密码");return}if(ae.length<6){pe("密码至少需要6个字符");return}if(ae!==ue){pe("两次输入的密码不一致");return}Me(!0);try{const ne=await ke.admin.resetUserPassword(_.id,ae),B=await ne.json();ne.ok?Re():pe(B.error||"重置密码失败")}catch(ne){console.error("Error resetting password:",ne),pe("网络错误,请稍后再试")}finally{Me(!1)}},S=M=>{Ne(M),Ke(M.role==="admin"?"admin":"user"),Ie("")},ee=()=>{Ne(null),Ke(""),Ie("")},we=async M=>{M.preventDefault(),Ie(""),$e(!0);try{const ne=await ke.admin.updateUserRole(Le.id,qe),B=await ne.json();ne.ok?(i(l.map(re=>re.id===Le.id?{...re,role:qe}:re)),ee()):Ie(B.error||"更新角色失败")}catch(ne){console.error("Error updating role:",ne),Ie("网络错误,请稍后再试")}finally{$e(!1)}},Y=M=>M==="super_admin"?e.jsx($n,{className:"w-4 h-4 text-amber-500 flex-shrink-0"}):M==="admin"?e.jsx(jt,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(Xr,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),H=M=>M==="super_admin"?e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-amber-500/20 text-amber-500",children:"超级管理员"}):M==="admin"?e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-blue-500/20 text-blue-400",children:"管理员"}):e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-gray-500/20 text-gray-400",children:"用户"});return h?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(W,{variant:"default",size:"sm",onClick:()=>f(!0),className:"flex items-center gap-2",children:[e.jsx(Ln,{className:"w-4 h-4"}),"创建用户"]}),s&&e.jsxs(W,{variant:"outline",size:"sm",onClick:s,className:"flex items-center gap-2",children:[e.jsx(In,{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-24",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-28",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:l.map(M=>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:[Y(M.role),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground text-sm truncate",children:M.username||M.email}),M.email&&M.username&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:M.email})]})]})}),e.jsx("td",{className:"px-3 py-2 text-center",children:H(M.role)}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${M.status==="active"?"bg-green-500":"bg-red-500"}`,title:M.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:ze(d[M.uuid]?.total_cost)})}),e.jsx("td",{className:"px-3 py-2 text-right",children:J(M)?e.jsx("button",{onClick:()=>Ae(M),className:"text-xs text-blue-600 dark:text-blue-400 hover:underline font-mono whitespace-nowrap",title:"点击编辑额度限制",children:M.total_limit_usd!==null||M.daily_limit_usd!==null?e.jsxs("span",{className:"flex flex-col items-end text-[11px] leading-tight",children:[e.jsxs("span",{children:["总:",oe(M.total_limit_usd)]}),e.jsxs("span",{children:["日:",oe(M.daily_limit_usd)]})]}):e.jsxs("span",{className:"flex items-center gap-1 justify-end",children:[e.jsx(us,{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(M.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[a&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>a(M.uuid,M.username||M.email),title:"查看使用详情",children:e.jsx(Dn,{className:"w-4 h-4 text-indigo-500"})}),t&&M.role!=="super_admin"&&M.id!==o?.id&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>S(M),title:"修改角色",children:e.jsx(Tn,{className:"w-4 h-4 text-purple-500"})}),q(M)&&e.jsxs(e.Fragment,{children:[M.username&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Te(M),disabled:v===M.id,title:"重置密码",children:e.jsx(Zr,{className:"w-4 h-4 text-blue-500"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>w(M.id,M.status),disabled:v===M.id,title:M.status==="active"?"禁用用户":"启用用户",children:M.status==="active"?e.jsx(Rn,{className:"w-4 h-4 text-orange-500"}):e.jsx(Pn,{className:"w-4 h-4 text-green-500"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>K(M.id,M.username||M.email),disabled:v===M.id,title:"删除用户",children:e.jsx(et,{className:"w-4 h-4 text-red-500"})})]})]})})]},M.id))})]})}),j&&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:ve,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:he,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newUsername",className:"block text-sm font-medium text-foreground mb-1",children:"用户名"}),e.jsx("input",{type:"text",id:"newUsername",value:E,onChange:M=>O(M.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入用户名",disabled:u})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newPassword",className:"block text-sm font-medium text-foreground mb-1",children:"密码"}),e.jsx("input",{type:"password",id:"newPassword",value:T,onChange:M=>R(M.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入密码",disabled:u})]}),g&&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:g})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:ve,disabled:u,children:"取消"}),e.jsx(W,{type:"submit",disabled:u,children:u?"创建中...":"创建"})]})]})]})}),L&&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:["设置额度限制 - ",L.username||L.email]}),e.jsx("button",{onClick:Ue,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:V,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:P.total_limit_usd,onChange:M=>z(ne=>({...ne,total_limit_usd:M.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:te}),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:P.daily_limit_usd,onChange:M=>z(ne=>({...ne,daily_limit_usd:M.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:te}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户每日使用金额达到此限制后,需等待次日重置"})]}),d[L.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:ze(d[L.uuid]?.total_cost)})]})}),me&&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:me})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:Ue,disabled:te,children:"取消"}),e.jsx(W,{type:"submit",disabled:te,children:te?"保存中...":"保存"})]})]})]})}),_&&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:["重置密码 - ",_.username]}),e.jsx("button",{onClick:Re,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:Ce,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:ae,onChange:M=>fe(M.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:Pe})]}),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:ue,onChange:M=>Z(M.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:Pe})]}),G&&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:G})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:Re,disabled:Pe,children:"取消"}),e.jsx(W,{type:"submit",disabled:Pe,children:Pe?"重置中...":"重置密码"})]})]})]})}),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||Le.email]}),e.jsx("button",{onClick:ee,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:we,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择角色"}),e.jsxs("label",{className:"flex items-center gap-3 p-3 border border-border rounded-md cursor-pointer hover:bg-accent/50 transition-colors",children:[e.jsx("input",{type:"radio",name:"role",value:"admin",checked:qe==="admin",onChange:M=>Ke(M.target.value),className:"text-blue-600",disabled:je}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(jt,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"管理员"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"可管理普通用户,但不能操作其他管理员"})]})]}),e.jsxs("label",{className:"flex items-center gap-3 p-3 border border-border rounded-md cursor-pointer hover:bg-accent/50 transition-colors",children:[e.jsx("input",{type:"radio",name:"role",value:"user",checked:qe==="user",onChange:M=>Ke(M.target.value),className:"text-blue-600",disabled:je}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xr,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"普通用户"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"受额度限制,无管理权限"})]})]})]}),We&&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:We})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:ee,disabled:je,children:"取消"}),e.jsx(W,{type:"submit",disabled:je,children:je?"保存中...":"保存"})]})]})]})})]})}function al(){const[t,s]=r.useState(""),[a,o]=r.useState(!0),[n,l]=r.useState(!1),[i,d]=r.useState(null);r.useEffect(()=>{x()},[]);const x=async()=>{try{const m=await ke.admin.getDefaultLimits();if(m.ok){const v=await m.json();s(v.default_total_limit_usd!==null?String(v.default_total_limit_usd):"")}}catch(m){console.error("Error fetching default limits:",m)}finally{o(!1)}},h=async m=>{m.preventDefault(),l(!0),d(null);const v=t.trim()===""?null:parseFloat(t);if(v!==null&&(isNaN(v)||v<0)){d("error"),l(!1);return}try{(await ke.admin.updateDefaultLimits({default_total_limit_usd:v})).ok?(d("success"),setTimeout(()=>d(null),2e3)):d("error")}catch(b){console.error("Error updating default limits:",b),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:h,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:m=>s(m.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(W,{type:"submit",variant:"default",size:"sm",disabled:n,className:"flex items-center gap-2",children:[e.jsx(ia,{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 nl(){const{showConfirm:t}=ct(),[s,a]=r.useState([]),[o,n]=r.useState(!0),[l,i]=r.useState(null),[d,x]=r.useState(!1),[h,m]=r.useState(""),[v,b]=r.useState(""),[j,f]=r.useState(!1),E=async()=>{try{const g=await ke.admin.getEmailDomains();if(g.ok){const p=await g.json();a(p.domains)}}catch(g){console.error("Error fetching email domains:",g)}finally{n(!1)}};r.useEffect(()=>{E()},[]);const O=async g=>{if(g.preventDefault(),b(""),!h){b("域名不能为空");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)){b("域名格式无效,例如: example.com");return}f(!0);try{const u=await ke.admin.addEmailDomain(h.toLowerCase()),y=await u.json();u.ok?(await E(),x(!1),m("")):b(y.error||"添加域名失败")}catch(u){console.error("Error adding domain:",u),b("网络错误,请稍后再试")}finally{f(!1)}},T=async(g,p)=>{if(await t(`确定要删除域名 "${p}"?删除后该域名的邮箱将无法注册。`,{title:"删除域名",variant:"danger",confirmText:"确认删除"})){i(g);try{(await ke.admin.removeEmailDomain(g)).ok&&a(s.filter(y=>y.id!==g))}catch(u){console.error("Error removing domain:",u)}finally{i(null)}}},R=()=>{x(!1),m(""),b("")};return o?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:s.length===0?"未设置白名单,所有邮箱域名均可注册":"只有白名单内的域名邮箱可以注册"})]}),e.jsxs(W,{variant:"default",size:"sm",onClick:()=>x(!0),className:"flex items-center gap-2",children:[e.jsx(lt,{className:"w-4 h-4"}),"添加域名"]})]}),s.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:s.map(g=>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(Nr,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"font-medium text-foreground",children:g.domain})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground",children:new Date(g.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>T(g.id,g.domain),disabled:l===g.id,title:"删除域名",children:e.jsx(et,{className:"w-4 h-4 text-red-500"})})})})]},g.id))})]})}):e.jsxs("div",{className:"border border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-8 text-center",children:[e.jsx(Nr,{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:"添加域名后,只有白名单内的域名邮箱可以注册"})]}),d&&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:R,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:O,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:g=>m(g.target.value.toLowerCase()),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"例如: example.com",disabled:j}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入域名后,该域名下的所有邮箱(如 user@example.com)都可以注册"})]}),v&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:v})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:R,disabled:j,children:"取消"}),e.jsx(W,{type:"submit",disabled:j,children:j?"添加中...":"添加"})]})]})]})})]})}function ol({days:t,formatCost:s,formatNumber:a}){const[o,n]=r.useState(null),l=Math.max(...t.map(i=>i.cost||0),.001);return e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"flex items-end justify-between gap-1.5 h-40",children:t.map(i=>{const d=(i.cost||0)/l*100,x=new Date(i.date+"T12:00:00").toLocaleDateString("zh-CN",{month:"numeric",day:"numeric"});return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 h-full",onMouseEnter:()=>n(i),onMouseLeave:()=>n(null),children:[e.jsx("div",{className:"flex-1 w-full flex items-end",children:e.jsx("div",{className:"w-full rounded-t bg-gradient-to-t from-blue-500 to-blue-400 transition-all duration-300",style:{height:`${Math.max(d,i.cost>0?2:0)}%`}})}),e.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:x})]},i.date)})}),o&&e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-popover border border-border rounded-lg px-3 py-2 text-xs shadow-lg z-10 whitespace-nowrap pointer-events-none",children:[e.jsx("div",{className:"font-medium text-foreground",children:o.date}),e.jsxs("div",{className:"text-muted-foreground",children:["费用:",s(o.cost)]}),e.jsxs("div",{className:"text-muted-foreground",children:["请求:",a(o.requests)]})]})]})}function il({onBack:t}){const[s,a]=r.useState("week"),[o,n]=r.useState(null),[l,i]=r.useState(!0),[d,x]=r.useState(!1),h=async()=>{try{const T=await X(`/api/admin/usage/dashboard?period=${s}`);if(T.ok){const R=await T.json();n(R)}}catch(T){console.error("Error fetching dashboard data:",T)}finally{i(!1),x(!1)}};r.useEffect(()=>{i(!0),h()},[s]);const m=async()=>{try{x(!0),await X("/api/admin/usage/scan",{method:"POST"}),await h()}catch(T){console.error("Error triggering scan:",T),x(!1)}},v=T=>!T||T===0?"$0.00":T<.01?`$${T.toFixed(4)}`:`$${T.toFixed(2)}`,b=T=>T?T>=1e6?`${(T/1e6).toFixed(1)}M`:T>=1e3?`${(T/1e3).toFixed(1)}K`:T.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:j,dailyTrend:f,modelDistribution:E,topUsers:O}=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(W,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(Qt,{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(T=>e.jsx("button",{onClick:()=>a(T),className:`px-4 py-2 text-sm font-medium transition-colors ${s===T?"bg-primary text-primary-foreground":"bg-background text-foreground hover:bg-muted"}`,children:T==="week"?"周":"月"},T))}),e.jsx(W,{variant:"outline",size:"sm",onClick:m,disabled:d,title:"扫描新的使用数据",children:e.jsx(zt,{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(us,{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:v(j?.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(xa,{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:[j?.activeUsers||0," / ",j?.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(Mr,{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:b(j?.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(ha,{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:b(j?.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:"每日成本趋势"}),f&&f.length>0?e.jsx(ol,{days:f,formatCost:v,formatNumber:b}):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:"模型成本"}),E&&E.length>0?e.jsx("div",{className:"space-y-3",children:E.map(T=>{const R=E.reduce((L,$)=>L+($.cost||0),0)||1,g=(T.cost||0)/R*100,p=(T.normalized_model||T.model||"").toLowerCase(),y=(L=>L.includes("codex")?"bg-orange-500":L.includes("opus")?"bg-purple-500":L.includes("sonnet")?"bg-blue-500":L.includes("haiku")?"bg-green-500":"bg-gray-500")(p);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(Qe,{variant:"secondary",className:"truncate max-w-[200px]",title:T.model,children:T.model}),e.jsxs("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:[b(T.requests)," 请求"]})]}),e.jsx("span",{className:"text-sm font-mono text-foreground whitespace-nowrap ml-2",children:v(T.cost)})]}),e.jsx("div",{className:"h-2 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:`h-full ${y} rounded`,style:{width:`${g}%`}})})]},T.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:"用户成本"}),O&&O.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:O.map((T,R)=>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:["#",R+1]}),e.jsx("td",{className:"py-2 text-sm font-medium text-foreground",children:T.username}),e.jsx("td",{className:"py-2 text-sm text-right text-muted-foreground",children:b(T.total_requests)}),e.jsx("td",{className:"py-2 text-sm text-right font-mono text-foreground",children:v(T.total_cost)})]},T.user_uuid))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]})}const ea={hex:{opus:"#a855f7",sonnet:"#3b82f6",haiku:"#22c55e",codex:"#f97316",default:"#6b7280"},tailwind:{opus:"bg-purple-500",sonnet:"bg-blue-500",haiku:"bg-green-500",codex:"bg-orange-500",default:"bg-gray-500"}};function ta(t=""){const s=t.toLowerCase();return s.includes("codex")?"codex":s.includes("opus")?"opus":s.includes("sonnet")?"sonnet":s.includes("haiku")?"haiku":"default"}function ws(t){return!t||t===0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function ls(t){return t?t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString():"0"}function ll(t){const s=[];for(let a=t-1;a>=0;a--){const o=new Date;o.setDate(o.getDate()-a),s.push(o.toISOString().split("T")[0])}return s}function cl({data:t}){const[s,a]=r.useState(null),o=140,n=o/2,l=o/2,i=56,d=t.reduce((m,v)=>m+(v.cost||0),0)||1;let x=-Math.PI/2;const h=t.map(m=>{const v=(m.cost||0)/d,b=v*2*Math.PI,j=x+b,f=n+i*Math.cos(x),E=l+i*Math.sin(x),O=n+i*Math.cos(j),T=l+i*Math.sin(j),R=b>Math.PI?1:0,g=v<.001?"":`M ${n} ${l} L ${f} ${E} A ${i} ${i} 0 ${R} 1 ${O} ${T} Z`,p=x+b/2,u={...m,pathD:g,ratio:v,midAngle:p,key:m.model};return x=j,u});return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("svg",{width:o,height:o,className:"flex-shrink-0",children:[h.map(m=>e.jsx("path",{d:m.pathD,fill:ea.hex[ta(m.model)],opacity:s===null||s===m.key?1:.4,stroke:"white",strokeWidth:"1.5",onMouseEnter:()=>a(m.key),onMouseLeave:()=>a(null),className:"cursor-pointer transition-opacity duration-150"},m.key)),t.length===0&&e.jsx("circle",{cx:n,cy:l,r:i,fill:"#e5e7eb"})]}),e.jsx("div",{className:"flex-1 space-y-1.5 min-w-0",children:h.map(m=>{const v=(m.ratio*100).toFixed(1),b=ta(m.model);return e.jsxs("div",{className:"flex items-center gap-2 min-w-0",onMouseEnter:()=>a(m.key),onMouseLeave:()=>a(null),children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${ea.tailwind[b]}`}),e.jsx("span",{className:"text-xs text-muted-foreground truncate flex-1",title:m.model,children:m.model}),e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[v,"%"]}),e.jsx("span",{className:"text-xs font-mono text-foreground flex-shrink-0 w-14 text-right",children:ws(m.cost)})]},m.key)})})]})}function dl({days:t}){const[s,a]=r.useState(null),o=Math.max(...t.map(n=>n.cost||0),.001);return e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"flex items-end justify-between gap-1.5 h-40",children:t.map(n=>{const l=(n.cost||0)/o*100,i=new Date(n.date+"T12:00:00").toLocaleDateString("zh-CN",{month:"numeric",day:"numeric"});return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 h-full",onMouseEnter:()=>a(n),onMouseLeave:()=>a(null),children:[e.jsx("div",{className:"flex-1 w-full flex items-end relative",children:e.jsx("div",{className:"w-full rounded-t bg-gradient-to-t from-blue-500 to-blue-400 transition-all duration-300 min-h-[2px]",style:{height:`${Math.max(l,n.cost>0?2:0)}%`}})}),e.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:i})]},n.date)})}),s&&e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-popover border border-border rounded-lg px-3 py-2 text-xs shadow-lg z-10 whitespace-nowrap pointer-events-none",children:[e.jsx("div",{className:"font-medium text-foreground",children:s.date}),e.jsxs("div",{className:"text-muted-foreground",children:["费用:",ws(s.cost)]}),e.jsxs("div",{className:"text-muted-foreground",children:["请求:",ls(s.requests)]})]})]})}function ml({userUuid:t,username:s,onBack:a}){const[o,n]=r.useState(null),[l,i]=r.useState(!0);r.useEffect(()=>{(async()=>{try{const v=await X(`/api/admin/usage/users/${t}?period=week`);v.ok&&n(await v.json())}catch(v){console.error("Error fetching user usage:",v)}finally{i(!1)}})()},[t]);const d=ll(7),x={};(o?.dailyTrend||[]).forEach(m=>{x[m.date]=m});const h=d.map(m=>({date:m,cost:x[m]?.cost||0,requests:x[m]?.requests||0}));return l?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-muted-foreground",children:"加载用户数据中..."})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(W,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Qt,{className:"w-4 h-4 mr-2"}),"返回"]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-foreground",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"最近 7 天使用情况"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 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(us,{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-xl font-bold text-foreground",children:ws(o?.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-purple-100 dark:bg-purple-900/30 rounded-lg",children:e.jsx(Mr,{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-xl font-bold text-foreground",children:ls(o?.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(ha,{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-xl font-bold text-foreground",children:ls(o?.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-base font-semibold text-foreground mb-4",children:"最近 7 天每日消耗"}),e.jsx(dl,{days:h})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground mb-4",children:"模型分布"}),o?.modelDistribution&&o.modelDistribution.length>0?e.jsx(cl,{data:o.modelDistribution}):e.jsx("div",{className:"flex items-center justify-center h-36 text-muted-foreground text-sm",children:"暂无使用数据"})]})]})]})}function ul({isOpen:t,onClose:s}){const{isAdmin:a,isSuperAdmin:o}=wt(),[n,l]=r.useState("users"),[i,d]=r.useState(!1),[x,h]=r.useState(null);if(!t||!a)return null;const m=[{id:"users",label:"用户管理",icon:xa},{id:"system",label:"系统设置",icon:zn}],v=b=>{l(b),d(!1),h(null)};return 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-5xl 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(jt,{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(W,{variant:"ghost",size:"sm",onClick:s,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 flex flex-col md:flex-row overflow-hidden",children:[e.jsx("div",{className:"md:hidden border-b border-border",children:e.jsx("div",{className:"flex px-4",children:m.map(b=>e.jsx("button",{onClick:()=>v(b.id),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${n===b.id?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:b.label},b.id))})}),e.jsx("div",{className:"hidden md:flex flex-col w-48 border-r border-border p-3 gap-1 flex-shrink-0",children:m.map(b=>{const j=b.icon;return e.jsxs("button",{onClick:()=>v(b.id),className:`flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${n===b.id?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground hover:bg-accent/50"}`,children:[e.jsx(j,{className:"w-4 h-4"}),b.label]},b.id)})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 md:p-6",children:[n==="users"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:i?e.jsx(il,{onBack:()=>d(!1)}):x?e.jsx(ml,{userUuid:x.uuid,username:x.username,onBack:()=>h(null)}):e.jsx(sl,{isSuperAdmin:o,onNavigateToUsage:()=>d(!0),onViewUser:(b,j)=>h({uuid:b,username:j})})}),n==="system"&&e.jsxs("div",{className:"space-y-6 md:space-y-8",children:[e.jsx(al,{}),e.jsx(nl,{})]})]})]})]})})}function pl(){const{isDarkMode:t,toggleDarkMode:s}=js();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 xl=({isOpen:t,onToggle:s,autoExpandTools:a,onAutoExpandChange:o,showRawParameters:n,onShowRawParametersChange:l,showThinking:i,onShowThinkingChange:d,autoScrollToBottom:x,onAutoScrollChange:h,sendByCtrlEnter:m,onSendByCtrlEnterChange:v,isMobile:b})=>{const[j,f]=r.useState(t),[E,O]=r.useState(()=>localStorage.getItem("whisperMode")||"default"),{isDarkMode:T}=js(),[R,g]=r.useState(()=>{const Z=localStorage.getItem("quickSettingsHandlePosition");if(Z)try{return JSON.parse(Z).y??50}catch{return localStorage.removeItem("quickSettingsHandlePosition"),50}return 50}),[p,u]=r.useState(!1),[y,L]=r.useState(0),[$,P]=r.useState(0),[z,me]=r.useState(!1),se=r.useRef(null),te=r.useRef({min:10,max:90}),de=5;r.useEffect(()=>{f(t)},[t]),r.useEffect(()=>{localStorage.setItem("quickSettingsHandlePosition",JSON.stringify({y:R}))},[R]);const _=r.useCallback(()=>b?{bottom:`${window.innerHeight*R/100}px`}:{top:`${R}%`,transform:"translateY(-50%)"},[R,b]),A=r.useCallback(Z=>{Z.stopPropagation();const G=Z.type.includes("touch")?Z.touches[0].clientY:Z.clientY;L(G),P(R),me(!1),u(!1)},[R]),ae=r.useCallback(Z=>{if(y===0)return;const G=Z.type.includes("touch")?Z.touches[0].clientY:Z.clientY,pe=Math.abs(G-y);if(!p&&pe>de&&(u(!0),me(!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%")),!p)return;Z.type.includes("touch")&&Z.preventDefault();const Pe=G-y;let Me;b?Me=-(Pe/window.innerHeight)*100:Me=Pe/window.innerHeight*100;let Le=$+Me;Le=Math.max(te.current.min,Math.min(te.current.max,Le)),g(Le)},[p,y,$,b,de]),fe=r.useCallback(()=>{u(!1),L(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(y!==0){const Z=Me=>ae(Me),G=()=>fe(),pe=Me=>ae(Me),Pe=()=>fe();return document.addEventListener("mousemove",Z),document.addEventListener("mouseup",G),document.addEventListener("touchmove",pe,{passive:!1}),document.addEventListener("touchend",Pe),()=>{document.removeEventListener("mousemove",Z),document.removeEventListener("mouseup",G),document.removeEventListener("touchmove",pe),document.removeEventListener("touchend",Pe)}}},[y,ae,fe]);const ue=Z=>{if(z){Z.preventDefault(),me(!1);return}const G=!j;f(G),s(G)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:se,onClick:ue,onMouseDown:Z=>{A(Z)},onTouchStart:Z=>{A(Z)},className:`fixed ${j?"right-64":"right-0"} z-50 ${p?"":"transition-all duration-150 ease-out"} bg-white dark:bg-gray-800 border ${p?"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 ${p?"cursor-grabbing":"cursor-pointer"} touch-none`,style:{..._(),touchAction:"none",WebkitTouchCallout:"none",WebkitUserSelect:"none"},"aria-label":p?"拖动手柄":j?"关闭设置面板":"打开设置面板",title:p?"拖动中...":"点击切换,拖动移动",children:p?e.jsx(An,{className:"h-5 w-5 text-blue-500 dark:text-blue-400"}):j?e.jsx(Vt,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"}):e.jsx(On,{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 ${j?"translate-x-0":"translate-x-full"} ${b?"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(_n,{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 ${b?"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:[T?e.jsx(Yr,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}):e.jsx(Qr,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"深色模式"]}),e.jsx(pl,{})]})]}),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(la,{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(ca,{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(oa,{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(Fn,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"自动滚动到底部"]}),e.jsx("input",{type:"checkbox",checked:x,onChange:Z=>h(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"}),"使用 Ctrl+Enter 发送"]}),e.jsx("input",{type:"checkbox",checked:m,onChange:Z=>v(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:E==="default",onChange:()=>{O("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(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:"直接转录您的语音"})]})]}),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:E==="prompt",onChange:()=>{O("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(Vr,{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:E==="vibe"||E==="instructions"||E==="architect",onChange:()=>{O("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(da,{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:"将想法格式化为带有详细说明的代理指令"})]})]})]})]})]})]})}),j&&e.jsx("div",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm z-30 transition-opacity duration-150 ease-out",onClick:ue})]})};function hl({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(Lt,{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(He,{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(W,{variant:"default",onClick:a,children:"我知道了"})})]})})}function gl(){const[t,s]=r.useState(null),[a,o]=r.useState([]),[n,l]=r.useState(!1),i=r.useRef(null),d=r.useRef(null),{token:x}=wt();r.useEffect(()=>(i.current&&(clearTimeout(i.current),i.current=null),d.current&&(d.current.close(),d.current=null),x||!1?h():(l(!1),s(null)),()=>{i.current&&clearTimeout(i.current),d.current&&d.current.close()}),[x]);const h=()=>{try{let b;{const f=x||localStorage.getItem("auth-token");if(!f){console.warn("No authentication token found for WebSocket connection");return}b=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws?token=${encodeURIComponent(f)}`}const j=new WebSocket(b);d.current=j,j.onopen=()=>{l(!0),s(j)},j.onmessage=f=>{try{const E=JSON.parse(f.data);o(O=>[...O,E])}catch(E){console.error("Error parsing WebSocket message:",E)}},j.onclose=()=>{l(!1),s(null),d.current=null,localStorage.getItem("auth-token")&&(i.current=setTimeout(()=>{h()},3e3))},j.onerror=f=>{console.error("WebSocket error:",f)}}catch(v){console.error("Error creating WebSocket connection:",v)}};return{ws:t,sendMessage:v=>{t&&n?t.send(JSON.stringify(v)):console.warn("WebSocket not connected")},messages:a,isConnected:n}}const Da=r.createContext({ws:null,sendMessage:()=>{},messages:[],isConnected:!1}),fl=()=>{const t=r.useContext(Da);if(!t)throw new Error("useWebSocketContext must be used within a WebSocketProvider");return t},bl=({children:t})=>{const s=gl();return e.jsx(Da.Provider,{value:s,children:t})},vl=()=>{const[t,s]=r.useState("email"),[a,o]=r.useState(""),[n,l]=r.useState(""),[i,d]=r.useState(!1),[x,h]=r.useState(""),[m,v]=r.useState(0),{sendCode:b,verifyCode:j,smtpConfigured:f}=wt();r.useEffect(()=>{if(m>0){const g=setTimeout(()=>v(m-1),1e3);return()=>clearTimeout(g)}},[m]);const E=async g=>{if(g.preventDefault(),h(""),!a||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)){h("请输入有效的邮箱地址");return}d(!0);const u=await b(a);u.success?(s("code"),v(60)):(h(u.error),u.waitSeconds&&v(u.waitSeconds)),d(!1)},O=async g=>{if(g.preventDefault(),h(""),!n||n.length!==6){h("请输入6位验证码");return}d(!0);const p=await j(a,n);p.success||h(p.error),d(!1)},T=async()=>{if(m>0)return;h(""),d(!0);const g=await b(a);g.success?v(60):h(g.error),d(!1)},R=()=>{s("email"),l(""),h("")};return f?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(ht,{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:E,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(Nr,{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:g=>o(g.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"})]})]}),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:i||m>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?"发送中...":m>0?`${m}秒后可重新发送`:"获取验证码"})]}),t==="code"&&e.jsxs("form",{onSubmit:O,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:R,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Qt,{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:g=>l(g.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"})]}),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: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:T,disabled:m>0||i,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:m>0?`${m}秒后可重新发送`:"重新发送验证码"})})]}),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(ht,{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"})]})]})]})})})},yl=()=>{const[t,s]=r.useState("email"),[a,o]=r.useState("email"),[n,l]=r.useState(""),[i,d]=r.useState(""),[x,h]=r.useState(""),[m,v]=r.useState(""),[b,j]=r.useState(!1),[f,E]=r.useState(""),[O,T]=r.useState(0),[R,g]=r.useState(!1),{login:p,sendCode:u,verifyCode:y,smtpConfigured:L}=wt();r.useEffect(()=>{if(O>0){const _=setTimeout(()=>T(O-1),1e3);return()=>clearTimeout(_)}},[O]),r.useEffect(()=>{L||s("password")},[L]);const $=async _=>{if(_.preventDefault(),E(""),!n||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)){E("请输入有效的邮箱地址");return}j(!0);const ae=await u(n);ae.success?(o("code"),T(60),g(ae.type==="register")):(E(ae.error),ae.waitSeconds&&T(ae.waitSeconds)),j(!1)},P=async _=>{if(_.preventDefault(),E(""),!i||i.length!==6){E("请输入6位验证码");return}j(!0);const A=await y(n,i);A.success||E(A.error),j(!1)},z=async()=>{if(O>0)return;E(""),j(!0);const _=await u(n);_.success?T(60):E(_.error),j(!1)},me=async _=>{if(_.preventDefault(),E(""),!x||!m){E("请输入用户名和密码");return}j(!0);const A=await p(x,m);A.success||E(A.error),j(!1)},se=()=>{o("email"),d(""),E("")},te=()=>{s("email"),o("email"),E("")},de=()=>{s("password"),E("")};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":R?"创建您的账户":"验证您的身份":"欢迎回来"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?a==="email"?"输入邮箱以接收验证码":`验证码已发送至 ${n}`:"使用账号密码登录"})]}),t==="email"&&a==="email"&&e.jsxs("form",{onSubmit:$,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(Nr,{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:_=>l(_.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:b,autoComplete:"email"})]})]}),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.jsx("button",{type:"submit",disabled:b||O>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:b?"发送中...":O>0?`${O}秒后可重新发送`:"获取验证码"})]}),t==="email"&&a==="code"&&e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:se,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Qt,{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(_.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:b,maxLength:6,autoComplete:"one-time-code"})]}),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.jsx("button",{type:"submit",disabled:b||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:b?"验证中...":R?"创建账户并登录":"登录"}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:z,disabled:O>0||b,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:O>0?`${O}秒后可重新发送`:"重新发送验证码"})})]}),t==="password"&&e.jsxs("form",{onSubmit:me,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(Xr,{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:x,onChange:_=>h(_.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:b})]})]}),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(Bn,{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:m,onChange:_=>v(_.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:b})]})]}),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.jsx("button",{type:"submit",disabled:b,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:b?"登录中...":"登录"})]}),e.jsx("div",{className:"text-center pt-4 border-t border-border",children:t==="email"&&L?e.jsx("button",{type:"button",onClick:de,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用账号密码登录"}):t==="password"&&L?e.jsx("button",{type:"button",onClick:te,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用邮箱验证码登录"}):null})]})})})},jl=()=>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(Mr,{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:"加载中..."})]})}),wl=({children:t})=>{const{user:s,isLoading:a,needsSetup:o}=wt();return a?e.jsx(jl,{}):o?e.jsx(vl,{}):s?t:e.jsx(yl,{})};function Gt(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 ra(){const t=sa(),{sessionId:s}=gn(),{limitStatus:a,setLimitStatus:o,checkLimitStatus:n,user:l,isAdmin:i}=wt(),[d,x]=r.useState([]),[h,m]=r.useState(null),[v,b]=r.useState(null),[j,f]=r.useState("chat"),[E,O]=r.useState(!1),[T,R]=r.useState(!1),[g,p]=r.useState(!0),[u,y]=r.useState(!1),[L,$]=r.useState(!1),[P,z]=r.useState(!1),[me,se]=r.useState("agents"),[te,de]=r.useState(!1),[_,A]=Gt("autoExpandTools",!1),[ae,fe]=Gt("showRawParameters",!1),[ue,Z]=Gt("showThinking",!0),[G,pe]=Gt("autoScrollToBottom",!0),[Pe,Me]=Gt("sendByCtrlEnter",!1),[Le,Ne]=Gt("sidebarVisible",!0),[qe,Ke]=r.useState(!1),[We,Ie]=r.useState(null),[je,$e]=r.useState(new Set),[Fe,_e]=r.useState(new Set),[ze,J]=r.useState(0),{ws:q,sendMessage:w,messages:K}=fl(),he=r.useCallback(B=>{Ie(B),Ke(!0)},[]),[ve,Ae]=r.useState(!1);r.useEffect(()=>{const B=()=>{const re=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone||document.referrer.includes("android-app://");Ae(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 B(),window.matchMedia("(display-mode: standalone)").addEventListener("change",B),()=>{window.matchMedia("(display-mode: standalone)").removeEventListener("change",B)}},[]),r.useEffect(()=>{const B=()=>{O(window.innerWidth<768)};return B(),window.addEventListener("resize",B),()=>window.removeEventListener("resize",B)},[]),r.useEffect(()=>{V()},[]);const Ue=(B,re,ie,ye)=>{if(!ie||!ye)return!0;const xe=B?.find(st=>st.name===ie.name),Ye=re?.find(st=>st.name===ie.name);if(!xe||!Ye)return!1;const De=xe.sessions?.find(st=>st.id===ye.id),Ge=Ye.sessions?.find(st=>st.id===ye.id);return!De||!Ge?!1:De.id===Ge.id&&De.title===Ge.title&&De.created_at===Ge.created_at&&De.updated_at===Ge.updated_at};r.useEffect(()=>{if(K.length>0){const B=K[K.length-1];if(B.type==="projects_updated"){if(B.changedFile&&v&&h){const xe=B.changedFile.replace(/\\/g,"/").split("/");xe.length>=2&&xe[xe.length-1].replace(".jsonl","")===v.id&&(je.has(v.id)||J(rt=>rt+1))}if(v&&je.has(v.id)||je.size>0&&Array.from(je).some(ye=>ye.startsWith("new-session-"))){const ye=B.projects;if(!Ue(d,ye,h,v))return}const ie=B.projects;if(x(ie),h){const ye=ie.find(xe=>xe.name===h.name);ye&&(JSON.stringify(ye)!==JSON.stringify(h)&&m(ye),v&&([...ye.sessions||[]].find(De=>De.id===v.id)||b(null)))}}}},[K,h,v,je]);const V=async()=>{try{p(!0);const re=await(await ke.projects()).json();x(ie=>ie.length===0||re.some((xe,Ye)=>{const De=ie[Ye];return De?xe.name!==De.name||xe.displayName!==De.displayName||xe.fullPath!==De.fullPath||JSON.stringify(xe.sessionMeta)!==JSON.stringify(De.sessionMeta)||JSON.stringify(xe.sessions)!==JSON.stringify(De.sessions):!0})||re.length!==ie.length?re:ie)}catch(B){console.error("Error fetching projects:",B)}finally{p(!1)}};window.refreshProjects=V,window.openSettings=r.useCallback((B="tools")=>{se(B),$(!0)},[]),window.openAdminPanel=r.useCallback(()=>{z(!0)},[]),r.useEffect(()=>{if(s&&d.length>0){const B=!v||v.id!==s;for(const re of d){let ie=re.sessions?.find(ye=>ye.id===s);if(ie){m(re),b({...ie,__provider:"claude"}),B&&f("chat");return}}}},[s,d,t]);const oe=B=>{m(B),b(null),t("/"),E&&R(!1)},Te=B=>{if(b(B),j!=="git"&&j!=="preview"&&f("chat"),E){const re=B.__projectName,ie=h?.name;re!==ie&&R(!1)}t(`/session/${B.id}`)},Re=B=>{m(B),b(null),f("chat"),t("/"),E&&R(!1)},Ce=B=>{v?.id===B&&(b(null),t("/")),x(re=>re.map(ie=>({...ie,sessions:ie.sessions?.filter(ye=>ye.id!==B)||[],sessionMeta:{...ie.sessionMeta,total:Math.max(0,(ie.sessionMeta?.total||0)-1)}})))},S=async()=>{try{const re=await(await ke.projects()).json();if(x(ie=>re.some((xe,Ye)=>{const De=ie[Ye];return De?xe.name!==De.name||xe.displayName!==De.displayName||xe.fullPath!==De.fullPath||JSON.stringify(xe.sessionMeta)!==JSON.stringify(De.sessionMeta)||JSON.stringify(xe.sessions)!==JSON.stringify(De.sessions):!0})||re.length!==ie.length?re:ie),h){const ie=re.find(ye=>ye.name===h.name);if(ie&&(JSON.stringify(ie)!==JSON.stringify(h)&&m(ie),v)){const ye=ie.sessions?.find(xe=>xe.id===v.id);ye&&JSON.stringify(ye)!==JSON.stringify(v)&&b(ye)}}}catch(B){console.error("Error refreshing sidebar:",B)}},ee=B=>{h?.name===B&&(m(null),b(null),t("/")),x(re=>re.filter(ie=>ie.name!==B))},we=r.useCallback(B=>{B&&$e(re=>new Set([...re,B]))},[]),Y=r.useCallback(B=>{B&&$e(re=>{const ie=new Set(re);return ie.delete(B),ie})},[]),H=r.useCallback(B=>{B&&_e(re=>new Set([...re,B]))},[]),M=r.useCallback(B=>{B&&_e(re=>{const ie=new Set(re);return ie.delete(B),ie})},[]),ne=r.useCallback(B=>{B&&$e(re=>{const ie=new Set;for(const ye of re)ye.startsWith("new-session-")||ie.add(ye);return ie.add(B),ie})},[]);return e.jsxs("div",{className:"fixed inset-0 flex bg-background",children:[!E&&e.jsx("div",{className:`h-full flex-shrink-0 border-r border-border bg-card transition-all duration-300 ${Le?"w-80":"w-14"}`,children:e.jsx("div",{className:"h-full overflow-hidden",children:Le?e.jsx(As,{projects:d,selectedProject:h,selectedSession:v,onProjectSelect:oe,onSessionSelect:Te,onNewSession:Re,onSessionDelete:Ce,onProjectDelete:ee,isLoading:g,onRefresh:S,onShowSettings:()=>$(!0),onShowAdmin:()=>z(!0),isPWA:ve,isMobile:E,onToggleSidebar:()=>Ne(!1)}):e.jsxs("div",{className:"h-full flex flex-col items-center py-4 gap-4",children:[e.jsx("button",{onClick:()=>Ne(!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:()=>$(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Settings",title:"Settings",children:e.jsx(It,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})}),i&&e.jsx("button",{onClick:()=>z(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Admin",title:"管理",children:e.jsx(jt,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})})]})})}),E&&e.jsxs("div",{className:`fixed inset-0 z-50 flex transition-all duration-150 ease-out ${T?"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:B=>{B.stopPropagation(),R(!1)},onTouchStart:B=>{B.preventDefault(),B.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 ${T?"translate-x-0":"-translate-x-full"}`,onClick:B=>B.stopPropagation(),onTouchStart:B=>B.stopPropagation(),children:e.jsx(As,{projects:d,selectedProject:h,selectedSession:v,onProjectSelect:oe,onSessionSelect:Te,onNewSession:Re,onSessionDelete:Ce,onProjectDelete:ee,isLoading:g,onRefresh:S,onShowSettings:()=>$(!0),onShowAdmin:()=>z(!0),isPWA:ve,isMobile:E,onToggleSidebar:()=>Ne(!1)})})]}),e.jsx("div",{className:`flex-1 flex flex-col min-w-0 ${E&&!u?"pb-mobile-nav":""}`,children:e.jsx(Pi,{selectedProject:h,selectedSession:v,activeTab:j,setActiveTab:f,ws:q,sendMessage:w,messages:K,isMobile:E,isPWA:ve,onMenuClick:()=>R(!0),isLoading:g,onInputFocusChange:y,onSessionActive:we,onSessionInactive:Y,onSessionProcessing:H,onSessionNotProcessing:M,processingSessions:Fe,onReplaceTemporarySession:ne,onNavigateToSession:B=>t(`/session/${B}`),onShowSettings:()=>$(!0),autoExpandTools:_,showRawParameters:ae,showThinking:ue,autoScrollToBottom:G,sendByCtrlEnter:Pe,externalMessageUpdate:ze,limitStatus:a,onLimitBlocked:he,checkLimitStatus:n})}),E&&e.jsx($i,{activeTab:j,setActiveTab:f,isInputFocused:u}),j==="chat"&&e.jsx(xl,{isOpen:te,onToggle:de,autoExpandTools:_,onAutoExpandChange:A,showRawParameters:ae,onShowRawParametersChange:fe,showThinking:ue,onShowThinkingChange:Z,autoScrollToBottom:G,onAutoScrollChange:pe,sendByCtrlEnter:Pe,onSendByCtrlEnterChange:Me,isMobile:E}),e.jsx(rl,{isOpen:L,onClose:()=>$(!1),projects:d,initialTab:me}),e.jsx(ul,{isOpen:P,onClose:()=>z(!1)}),e.jsx(hl,{isOpen:qe,limitType:We,onClose:()=>Ke(!1)})]})}function kl(){return e.jsx(zi,{children:e.jsx(oo,{children:e.jsx(bl,{children:e.jsx(ao,{children:e.jsx(wl,{children:e.jsx(xn,{children:e.jsxs(hn,{children:[e.jsx(Ds,{path:"/",element:e.jsx(ra,{})}),e.jsx(Ds,{path:"/session/:sessionId",element:e.jsx(ra,{})})]})})})})})})})}"serviceWorker"in navigator&&navigator.serviceWorker.getRegistrations().then(t=>{t.forEach(s=>{s.unregister()})}).catch(t=>{console.warn("Failed to unregister service workers:",t)});eo.createRoot(document.getElementById("root")).render(e.jsx(it.StrictMode,{children:e.jsx(kl,{})}));
143
+ }`,required:!0}),Fe&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:Fe}),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"}']})]})}),G.importMode==="form"&&G.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(Xe,{value:G.config.command,onChange:D=>et("command",D.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(G.config.args)?G.config.args.join(`
144
+ `):"",onChange:D=>et("args",D.target.value.split(`
145
+ `).filter(H=>H.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
146
+ abc123`})]})]}),G.importMode==="form"&&(G.type==="sse"||G.type==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"URL *"}),e.jsx(Xe,{value:G.config.url,onChange:D=>et("url",D.target.value),placeholder:"https://api.example.com/mcp",type:"url",required:!0})]}),G.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(G.config.env||{}).map(([D,H])=>`${D}=${H}`).join(`
147
+ `),onChange:D=>{const H={};D.target.value.split(`
148
+ `).forEach(le=>{const[Re,...nt]=le.split("=");Re&&Re.trim()&&(H[Re.trim()]=nt.join("=").trim())}),et("env",H)},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
149
+ DEBUG=true`})]}),G.importMode==="form"&&(G.type==="sse"||G.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(G.config.headers||{}).map(([D,H])=>`${D}=${H}`).join(`
150
+ `),onChange:D=>{const H={};D.target.value.split(`
151
+ `).forEach(le=>{const[Re,...nt]=le.split("=");Re&&Re.trim()&&(H[Re.trim()]=nt.join("=").trim())}),et("headers",H)},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
152
+ X-API-Key=your-key`})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(W,{type:"button",variant:"outline",onClick:vt,children:"取消"}),e.jsx(W,{type:"submit",disabled:Pe,className:"bg-purple-600 hover:bg-purple-700 disabled:opacity-50",children:Pe?"保存中...":_?"更新服务器":"添加服务器"})]})]})]})})]})]}),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:je==="agents"&&ze==="models"?w.saving?e.jsx("span",{className:"text-sm text-muted-foreground",children:"保存中..."}):null:e.jsxs(e.Fragment,{children:[L==="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"})}),"设置保存成功!"]}),L==="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:[je==="agents"&&ze==="models"&&w.hasChanges&&e.jsx(W,{variant:"outline",onClick:()=>q.current?.reset(),disabled:w.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"重置"}),e.jsx(W,{variant:"outline",onClick:s,disabled:u||w.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"取消"}),e.jsx(W,{onClick:je==="agents"&&ze==="models"?()=>q.current?.save():Rr,disabled:je==="agents"&&ze==="models"?w.saving||!w.hasChanges:u,className:"flex-1 sm:flex-none h-10 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 touch-manipulation",children:u||w.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"}),"保存中..."]}):"保存设置"})]})]})]})}),ae&&e.jsx(tl,{onClose:()=>fe(!1),onInstalled:()=>bt(),onOpenRepoManager:()=>{fe(!1),X(!0)}}),ue&&e.jsx(Xi,{onClose:()=>X(!1),onChanged:()=>{}})]}):null}function sl({isSuperAdmin:t,onNavigateToUsage:s,onViewUser:a}){const{user:o}=Nt(),{showConfirm:n}=ct(),[l,i]=r.useState([]),[d,x]=r.useState({}),[h,m]=r.useState(!0),[v,b]=r.useState(null),[j,f]=r.useState(!1),[E,O]=r.useState(""),[T,R]=r.useState(""),[g,p]=r.useState(""),[u,y]=r.useState(!1),[L,$]=r.useState(null),[P,z]=r.useState({total_limit_usd:"",daily_limit_usd:""}),[me,se]=r.useState(""),[te,de]=r.useState(!1),[_,A]=r.useState(null),[ae,fe]=r.useState(""),[ue,X]=r.useState(""),[G,pe]=r.useState(""),[Pe,Ee]=r.useState(!1),[Me,Ne]=r.useState(null),[qe,Ge]=r.useState(""),[We,De]=r.useState(""),[je,$e]=r.useState(!1),Fe=async()=>{try{const M=await Z("/api/admin/users");if(M.ok){const ne=await M.json();i(ne.users)}}catch(M){console.error("Error fetching users:",M)}finally{m(!1)}},_e=async()=>{try{const M=await Z("/api/admin/usage/summary");if(M.ok){const ne=await M.json(),B={};for(const re of ne.users)B[re.user_uuid]={total_cost:re.total_cost||0,total_requests:re.total_requests||0,last_active:re.last_active};x(B)}}catch(M){console.error("Error fetching usage data:",M)}};r.useEffect(()=>{Fe(),_e()},[]);const ze=M=>!M||M===0?"$0.00":M<.01?`$${M.toFixed(4)}`:`$${M.toFixed(2)}`,J=M=>M.role==="super_admin"?!1:t||M.id===o?.id?!0:M.role==="user",q=M=>M.id===o?.id?!1:t?M.role!=="super_admin":!["admin","super_admin"].includes(M.role),w=async(M,ne)=>{const B=ne==="active"?"disabled":"active";b(M);try{(await Z(`/api/admin/users/${M}`,{method:"PATCH",body:JSON.stringify({status:B})})).ok&&i(l.map(ie=>ie.id===M?{...ie,status:B}:ie))}catch(re){console.error("Error updating user status:",re)}finally{b(null)}},K=async(M,ne)=>{if(await n(`确定要删除用户 "${ne}"?这将删除其所有数据。`,{title:"删除用户",variant:"danger",confirmText:"确认删除"})){b(M);try{(await Z(`/api/admin/users/${M}`,{method:"DELETE"})).ok&&i(l.filter(re=>re.id!==M))}catch(B){console.error("Error deleting user:",B)}finally{b(null)}}},he=async M=>{if(M.preventDefault(),p(""),!E||!T){p("用户名和密码不能为空");return}if(E.length<3){p("用户名至少3个字符");return}if(T.length<6){p("密码至少6个字符");return}y(!0);try{const ne=await ke.admin.createUser(E,T),B=await ne.json();ne.ok?(await Fe(),f(!1),O(""),R("")):p(B.error||"创建用户失败")}catch(ne){console.error("Error creating user:",ne),p("网络错误,请稍后再试")}finally{y(!1)}},ve=()=>{f(!1),O(""),R(""),p("")},Ae=M=>{$(M),z({total_limit_usd:M.total_limit_usd!==null&&M.total_limit_usd!==void 0?String(M.total_limit_usd):"",daily_limit_usd:M.daily_limit_usd!==null&&M.daily_limit_usd!==void 0?String(M.daily_limit_usd):""}),se("")},Ue=()=>{$(null),z({total_limit_usd:"",daily_limit_usd:""}),se("")},V=async M=>{M.preventDefault(),se("");const ne=P.total_limit_usd.trim()===""?null:parseFloat(P.total_limit_usd),B=P.daily_limit_usd.trim()===""?null:parseFloat(P.daily_limit_usd);if(ne!==null&&(isNaN(ne)||ne<0)){se("总额度限制必须是正数或留空");return}if(B!==null&&(isNaN(B)||B<0)){se("每日额度限制必须是正数或留空");return}de(!0);try{const re=await ke.admin.updateUserLimits(L.id,{total_limit_usd:ne,daily_limit_usd:B}),ie=await re.json();re.ok?(i(l.map(ye=>ye.id===L.id?{...ye,total_limit_usd:ne,daily_limit_usd:B}:ye)),Ue()):se(ie.error||"更新限制失败")}catch(re){console.error("Error updating limits:",re),se("网络错误,请稍后再试")}finally{de(!1)}},oe=M=>M==null?"无限制":`$${M.toFixed(2)}`,Ie=M=>{A(M),fe(""),X(""),pe("")},Te=()=>{A(null),fe(""),X(""),pe("")},Ce=async M=>{if(M.preventDefault(),pe(""),!ae){pe("请输入新密码");return}if(ae.length<6){pe("密码至少需要6个字符");return}if(ae!==ue){pe("两次输入的密码不一致");return}Ee(!0);try{const ne=await ke.admin.resetUserPassword(_.id,ae),B=await ne.json();ne.ok?Te():pe(B.error||"重置密码失败")}catch(ne){console.error("Error resetting password:",ne),pe("网络错误,请稍后再试")}finally{Ee(!1)}},N=M=>{Ne(M),Ge(M.role==="admin"?"admin":"user"),De("")},ee=()=>{Ne(null),Ge(""),De("")},we=async M=>{M.preventDefault(),De(""),$e(!0);try{const ne=await ke.admin.updateUserRole(Me.id,qe),B=await ne.json();ne.ok?(i(l.map(re=>re.id===Me.id?{...re,role:qe}:re)),ee()):De(B.error||"更新角色失败")}catch(ne){console.error("Error updating role:",ne),De("网络错误,请稍后再试")}finally{$e(!1)}},Y=M=>M==="super_admin"?e.jsx($n,{className:"w-4 h-4 text-amber-500 flex-shrink-0"}):M==="admin"?e.jsx(kt,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(es,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),U=M=>M==="super_admin"?e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-amber-500/20 text-amber-500",children:"超级管理员"}):M==="admin"?e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-blue-500/20 text-blue-400",children:"管理员"}):e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-gray-500/20 text-gray-400",children:"用户"});return h?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(W,{variant:"default",size:"sm",onClick:()=>f(!0),className:"flex items-center gap-2",children:[e.jsx(Ln,{className:"w-4 h-4"}),"创建用户"]}),s&&e.jsxs(W,{variant:"outline",size:"sm",onClick:s,className:"flex items-center gap-2",children:[e.jsx(Dn,{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-24",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-28",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:l.map(M=>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:[Y(M.role),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground text-sm truncate",children:M.username||M.email}),M.email&&M.username&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:M.email})]})]})}),e.jsx("td",{className:"px-3 py-2 text-center",children:U(M.role)}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${M.status==="active"?"bg-green-500":"bg-red-500"}`,title:M.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:ze(d[M.uuid]?.total_cost)})}),e.jsx("td",{className:"px-3 py-2 text-right",children:J(M)?e.jsx("button",{onClick:()=>Ae(M),className:"text-xs text-blue-600 dark:text-blue-400 hover:underline font-mono whitespace-nowrap",title:"点击编辑额度限制",children:M.total_limit_usd!==null||M.daily_limit_usd!==null?e.jsxs("span",{className:"flex flex-col items-end text-[11px] leading-tight",children:[e.jsxs("span",{children:["总:",oe(M.total_limit_usd)]}),e.jsxs("span",{children:["日:",oe(M.daily_limit_usd)]})]}):e.jsxs("span",{className:"flex items-center gap-1 justify-end",children:[e.jsx(ps,{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(M.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[a&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>a(M.uuid,M.username||M.email),title:"查看使用详情",children:e.jsx(In,{className:"w-4 h-4 text-indigo-500"})}),t&&M.role!=="super_admin"&&M.id!==o?.id&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>N(M),title:"修改角色",children:e.jsx(Tn,{className:"w-4 h-4 text-purple-500"})}),q(M)&&e.jsxs(e.Fragment,{children:[M.username&&e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Ie(M),disabled:v===M.id,title:"重置密码",children:e.jsx(Xr,{className:"w-4 h-4 text-blue-500"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>w(M.id,M.status),disabled:v===M.id,title:M.status==="active"?"禁用用户":"启用用户",children:M.status==="active"?e.jsx(Rn,{className:"w-4 h-4 text-orange-500"}):e.jsx(Pn,{className:"w-4 h-4 text-green-500"})}),e.jsx(W,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>K(M.id,M.username||M.email),disabled:v===M.id,title:"删除用户",children:e.jsx(tt,{className:"w-4 h-4 text-red-500"})})]})]})})]},M.id))})]})}),j&&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:ve,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:he,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newUsername",className:"block text-sm font-medium text-foreground mb-1",children:"用户名"}),e.jsx("input",{type:"text",id:"newUsername",value:E,onChange:M=>O(M.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入用户名",disabled:u})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newPassword",className:"block text-sm font-medium text-foreground mb-1",children:"密码"}),e.jsx("input",{type:"password",id:"newPassword",value:T,onChange:M=>R(M.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入密码",disabled:u})]}),g&&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:g})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:ve,disabled:u,children:"取消"}),e.jsx(W,{type:"submit",disabled:u,children:u?"创建中...":"创建"})]})]})]})}),L&&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:["设置额度限制 - ",L.username||L.email]}),e.jsx("button",{onClick:Ue,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:V,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:P.total_limit_usd,onChange:M=>z(ne=>({...ne,total_limit_usd:M.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:te}),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:P.daily_limit_usd,onChange:M=>z(ne=>({...ne,daily_limit_usd:M.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:te}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户每日使用金额达到此限制后,需等待次日重置"})]}),d[L.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:ze(d[L.uuid]?.total_cost)})]})}),me&&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:me})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:Ue,disabled:te,children:"取消"}),e.jsx(W,{type:"submit",disabled:te,children:te?"保存中...":"保存"})]})]})]})}),_&&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:["重置密码 - ",_.username]}),e.jsx("button",{onClick:Te,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:Ce,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:ae,onChange:M=>fe(M.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:Pe})]}),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:ue,onChange:M=>X(M.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:Pe})]}),G&&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:G})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:Te,disabled:Pe,children:"取消"}),e.jsx(W,{type:"submit",disabled:Pe,children:Pe?"重置中...":"重置密码"})]})]})]})}),Me&&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:["修改角色 - ",Me.username||Me.email]}),e.jsx("button",{onClick:ee,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:we,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"选择角色"}),e.jsxs("label",{className:"flex items-center gap-3 p-3 border border-border rounded-md cursor-pointer hover:bg-accent/50 transition-colors",children:[e.jsx("input",{type:"radio",name:"role",value:"admin",checked:qe==="admin",onChange:M=>Ge(M.target.value),className:"text-blue-600",disabled:je}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(kt,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"管理员"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"可管理普通用户,但不能操作其他管理员"})]})]}),e.jsxs("label",{className:"flex items-center gap-3 p-3 border border-border rounded-md cursor-pointer hover:bg-accent/50 transition-colors",children:[e.jsx("input",{type:"radio",name:"role",value:"user",checked:qe==="user",onChange:M=>Ge(M.target.value),className:"text-blue-600",disabled:je}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{className:"w-4 h-4 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"普通用户"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"受额度限制,无管理权限"})]})]})]}),We&&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:We})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:ee,disabled:je,children:"取消"}),e.jsx(W,{type:"submit",disabled:je,children:je?"保存中...":"保存"})]})]})]})})]})}function al(){const[t,s]=r.useState(""),[a,o]=r.useState(!0),[n,l]=r.useState(!1),[i,d]=r.useState(null);r.useEffect(()=>{x()},[]);const x=async()=>{try{const m=await ke.admin.getDefaultLimits();if(m.ok){const v=await m.json();s(v.default_total_limit_usd!==null?String(v.default_total_limit_usd):"")}}catch(m){console.error("Error fetching default limits:",m)}finally{o(!1)}},h=async m=>{m.preventDefault(),l(!0),d(null);const v=t.trim()===""?null:parseFloat(t);if(v!==null&&(isNaN(v)||v<0)){d("error"),l(!1);return}try{(await ke.admin.updateDefaultLimits({default_total_limit_usd:v})).ok?(d("success"),setTimeout(()=>d(null),2e3)):d("error")}catch(b){console.error("Error updating default limits:",b),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:h,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:m=>s(m.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(W,{type:"submit",variant:"default",size:"sm",disabled:n,className:"flex items-center gap-2",children:[e.jsx(ca,{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 nl(){const{showConfirm:t}=ct(),[s,a]=r.useState([]),[o,n]=r.useState(!0),[l,i]=r.useState(null),[d,x]=r.useState(!1),[h,m]=r.useState(""),[v,b]=r.useState(""),[j,f]=r.useState(!1),E=async()=>{try{const g=await ke.admin.getEmailDomains();if(g.ok){const p=await g.json();a(p.domains)}}catch(g){console.error("Error fetching email domains:",g)}finally{n(!1)}};r.useEffect(()=>{E()},[]);const O=async g=>{if(g.preventDefault(),b(""),!h){b("域名不能为空");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)){b("域名格式无效,例如: example.com");return}f(!0);try{const u=await ke.admin.addEmailDomain(h.toLowerCase()),y=await u.json();u.ok?(await E(),x(!1),m("")):b(y.error||"添加域名失败")}catch(u){console.error("Error adding domain:",u),b("网络错误,请稍后再试")}finally{f(!1)}},T=async(g,p)=>{if(await t(`确定要删除域名 "${p}"?删除后该域名的邮箱将无法注册。`,{title:"删除域名",variant:"danger",confirmText:"确认删除"})){i(g);try{(await ke.admin.removeEmailDomain(g)).ok&&a(s.filter(y=>y.id!==g))}catch(u){console.error("Error removing domain:",u)}finally{i(null)}}},R=()=>{x(!1),m(""),b("")};return o?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:s.length===0?"未设置白名单,所有邮箱域名均可注册":"只有白名单内的域名邮箱可以注册"})]}),e.jsxs(W,{variant:"default",size:"sm",onClick:()=>x(!0),className:"flex items-center gap-2",children:[e.jsx(lt,{className:"w-4 h-4"}),"添加域名"]})]}),s.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:s.map(g=>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(Sr,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"font-medium text-foreground",children:g.domain})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground",children:new Date(g.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>T(g.id,g.domain),disabled:l===g.id,title:"删除域名",children:e.jsx(tt,{className:"w-4 h-4 text-red-500"})})})})]},g.id))})]})}):e.jsxs("div",{className:"border border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-8 text-center",children:[e.jsx(Sr,{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:"添加域名后,只有白名单内的域名邮箱可以注册"})]}),d&&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:R,className:"text-muted-foreground hover:text-foreground",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:O,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:g=>m(g.target.value.toLowerCase()),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"例如: example.com",disabled:j}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入域名后,该域名下的所有邮箱(如 user@example.com)都可以注册"})]}),v&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:v})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(W,{type:"button",variant:"outline",onClick:R,disabled:j,children:"取消"}),e.jsx(W,{type:"submit",disabled:j,children:j?"添加中...":"添加"})]})]})]})})]})}function ol({days:t,formatCost:s,formatNumber:a}){const[o,n]=r.useState(null),l=Math.max(...t.map(i=>i.cost||0),.001);return e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"flex items-end justify-between gap-1.5 h-40",children:t.map(i=>{const d=(i.cost||0)/l*100,x=new Date(i.date+"T12:00:00").toLocaleDateString("zh-CN",{month:"numeric",day:"numeric"});return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 h-full",onMouseEnter:()=>n(i),onMouseLeave:()=>n(null),children:[e.jsx("div",{className:"flex-1 w-full flex items-end",children:e.jsx("div",{className:"w-full rounded-t bg-gradient-to-t from-blue-500 to-blue-400 transition-all duration-300",style:{height:`${Math.max(d,i.cost>0?2:0)}%`}})}),e.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:x})]},i.date)})}),o&&e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-popover border border-border rounded-lg px-3 py-2 text-xs shadow-lg z-10 whitespace-nowrap pointer-events-none",children:[e.jsx("div",{className:"font-medium text-foreground",children:o.date}),e.jsxs("div",{className:"text-muted-foreground",children:["费用:",s(o.cost)]}),e.jsxs("div",{className:"text-muted-foreground",children:["请求:",a(o.requests)]})]})]})}function il({onBack:t}){const[s,a]=r.useState("week"),[o,n]=r.useState(null),[l,i]=r.useState(!0),[d,x]=r.useState(!1),h=async()=>{try{const T=await Z(`/api/admin/usage/dashboard?period=${s}`);if(T.ok){const R=await T.json();n(R)}}catch(T){console.error("Error fetching dashboard data:",T)}finally{i(!1),x(!1)}};r.useEffect(()=>{i(!0),h()},[s]);const m=async()=>{try{x(!0),await Z("/api/admin/usage/scan",{method:"POST"}),await h()}catch(T){console.error("Error triggering scan:",T),x(!1)}},v=T=>!T||T===0?"$0.00":T<.01?`$${T.toFixed(4)}`:`$${T.toFixed(2)}`,b=T=>T?T>=1e6?`${(T/1e6).toFixed(1)}M`:T>=1e3?`${(T/1e3).toFixed(1)}K`:T.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:j,dailyTrend:f,modelDistribution:E,topUsers:O}=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(W,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(Qt,{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(T=>e.jsx("button",{onClick:()=>a(T),className:`px-4 py-2 text-sm font-medium transition-colors ${s===T?"bg-primary text-primary-foreground":"bg-background text-foreground hover:bg-muted"}`,children:T==="week"?"周":"月"},T))}),e.jsx(W,{variant:"outline",size:"sm",onClick:m,disabled:d,title:"扫描新的使用数据",children:e.jsx(_t,{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(ps,{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:v(j?.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(ga,{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:[j?.activeUsers||0," / ",j?.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(Lr,{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:b(j?.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(fa,{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:b(j?.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:"每日成本趋势"}),f&&f.length>0?e.jsx(ol,{days:f,formatCost:v,formatNumber:b}):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:"模型成本"}),E&&E.length>0?e.jsx("div",{className:"space-y-3",children:E.map(T=>{const R=E.reduce((L,$)=>L+($.cost||0),0)||1,g=(T.cost||0)/R*100,p=(T.normalized_model||T.model||"").toLowerCase(),y=(L=>L.includes("codex")?"bg-orange-500":L.includes("opus")?"bg-purple-500":L.includes("sonnet")?"bg-blue-500":L.includes("haiku")?"bg-green-500":"bg-gray-500")(p);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(Qe,{variant:"secondary",className:"truncate max-w-[200px]",title:T.model,children:T.model}),e.jsxs("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:[b(T.requests)," 请求"]})]}),e.jsx("span",{className:"text-sm font-mono text-foreground whitespace-nowrap ml-2",children:v(T.cost)})]}),e.jsx("div",{className:"h-2 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:`h-full ${y} rounded`,style:{width:`${g}%`}})})]},T.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:"用户成本"}),O&&O.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:O.map((T,R)=>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:["#",R+1]}),e.jsx("td",{className:"py-2 text-sm font-medium text-foreground",children:T.username}),e.jsx("td",{className:"py-2 text-sm text-right text-muted-foreground",children:b(T.total_requests)}),e.jsx("td",{className:"py-2 text-sm text-right font-mono text-foreground",children:v(T.total_cost)})]},T.user_uuid))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]})}const ta={hex:{opus:"#a855f7",sonnet:"#3b82f6",haiku:"#22c55e",codex:"#f97316",default:"#6b7280"},tailwind:{opus:"bg-purple-500",sonnet:"bg-blue-500",haiku:"bg-green-500",codex:"bg-orange-500",default:"bg-gray-500"}};function ra(t=""){const s=t.toLowerCase();return s.includes("codex")?"codex":s.includes("opus")?"opus":s.includes("sonnet")?"sonnet":s.includes("haiku")?"haiku":"default"}function ks(t){return!t||t===0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function cs(t){return t?t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString():"0"}function ll(t){const s=[];for(let a=t-1;a>=0;a--){const o=new Date;o.setDate(o.getDate()-a),s.push(o.toISOString().split("T")[0])}return s}function cl({data:t}){const[s,a]=r.useState(null),o=140,n=o/2,l=o/2,i=56,d=t.reduce((m,v)=>m+(v.cost||0),0)||1;let x=-Math.PI/2;const h=t.map(m=>{const v=(m.cost||0)/d,b=v*2*Math.PI,j=x+b,f=n+i*Math.cos(x),E=l+i*Math.sin(x),O=n+i*Math.cos(j),T=l+i*Math.sin(j),R=b>Math.PI?1:0,g=v<.001?"":`M ${n} ${l} L ${f} ${E} A ${i} ${i} 0 ${R} 1 ${O} ${T} Z`,p=x+b/2,u={...m,pathD:g,ratio:v,midAngle:p,key:m.model};return x=j,u});return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("svg",{width:o,height:o,className:"flex-shrink-0",children:[h.map(m=>e.jsx("path",{d:m.pathD,fill:ta.hex[ra(m.model)],opacity:s===null||s===m.key?1:.4,stroke:"white",strokeWidth:"1.5",onMouseEnter:()=>a(m.key),onMouseLeave:()=>a(null),className:"cursor-pointer transition-opacity duration-150"},m.key)),t.length===0&&e.jsx("circle",{cx:n,cy:l,r:i,fill:"#e5e7eb"})]}),e.jsx("div",{className:"flex-1 space-y-1.5 min-w-0",children:h.map(m=>{const v=(m.ratio*100).toFixed(1),b=ra(m.model);return e.jsxs("div",{className:"flex items-center gap-2 min-w-0",onMouseEnter:()=>a(m.key),onMouseLeave:()=>a(null),children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${ta.tailwind[b]}`}),e.jsx("span",{className:"text-xs text-muted-foreground truncate flex-1",title:m.model,children:m.model}),e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[v,"%"]}),e.jsx("span",{className:"text-xs font-mono text-foreground flex-shrink-0 w-14 text-right",children:ks(m.cost)})]},m.key)})})]})}function dl({days:t}){const[s,a]=r.useState(null),o=Math.max(...t.map(n=>n.cost||0),.001);return e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"flex items-end justify-between gap-1.5 h-40",children:t.map(n=>{const l=(n.cost||0)/o*100,i=new Date(n.date+"T12:00:00").toLocaleDateString("zh-CN",{month:"numeric",day:"numeric"});return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 h-full",onMouseEnter:()=>a(n),onMouseLeave:()=>a(null),children:[e.jsx("div",{className:"flex-1 w-full flex items-end relative",children:e.jsx("div",{className:"w-full rounded-t bg-gradient-to-t from-blue-500 to-blue-400 transition-all duration-300 min-h-[2px]",style:{height:`${Math.max(l,n.cost>0?2:0)}%`}})}),e.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:i})]},n.date)})}),s&&e.jsxs("div",{className:"absolute -top-16 left-1/2 -translate-x-1/2 bg-popover border border-border rounded-lg px-3 py-2 text-xs shadow-lg z-10 whitespace-nowrap pointer-events-none",children:[e.jsx("div",{className:"font-medium text-foreground",children:s.date}),e.jsxs("div",{className:"text-muted-foreground",children:["费用:",ks(s.cost)]}),e.jsxs("div",{className:"text-muted-foreground",children:["请求:",cs(s.requests)]})]})]})}function ml({userUuid:t,username:s,onBack:a}){const[o,n]=r.useState(null),[l,i]=r.useState(!0);r.useEffect(()=>{(async()=>{try{const v=await Z(`/api/admin/usage/users/${t}?period=week`);v.ok&&n(await v.json())}catch(v){console.error("Error fetching user usage:",v)}finally{i(!1)}})()},[t]);const d=ll(7),x={};(o?.dailyTrend||[]).forEach(m=>{x[m.date]=m});const h=d.map(m=>({date:m,cost:x[m]?.cost||0,requests:x[m]?.requests||0}));return l?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-muted-foreground",children:"加载用户数据中..."})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(W,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Qt,{className:"w-4 h-4 mr-2"}),"返回"]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-foreground",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"最近 7 天使用情况"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 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(ps,{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-xl font-bold text-foreground",children:ks(o?.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-purple-100 dark:bg-purple-900/30 rounded-lg",children:e.jsx(Lr,{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-xl font-bold text-foreground",children:cs(o?.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(fa,{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-xl font-bold text-foreground",children:cs(o?.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-base font-semibold text-foreground mb-4",children:"最近 7 天每日消耗"}),e.jsx(dl,{days:h})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground mb-4",children:"模型分布"}),o?.modelDistribution&&o.modelDistribution.length>0?e.jsx(cl,{data:o.modelDistribution}):e.jsx("div",{className:"flex items-center justify-center h-36 text-muted-foreground text-sm",children:"暂无使用数据"})]})]})]})}function ul({isOpen:t,onClose:s}){const{isAdmin:a,isSuperAdmin:o}=Nt(),[n,l]=r.useState("users"),[i,d]=r.useState(!1),[x,h]=r.useState(null);if(!t||!a)return null;const m=[{id:"users",label:"用户管理",icon:ga},{id:"system",label:"系统设置",icon:zn}],v=b=>{l(b),d(!1),h(null)};return 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-5xl 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(kt,{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(W,{variant:"ghost",size:"sm",onClick:s,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 flex flex-col md:flex-row overflow-hidden",children:[e.jsx("div",{className:"md:hidden border-b border-border",children:e.jsx("div",{className:"flex px-4",children:m.map(b=>e.jsx("button",{onClick:()=>v(b.id),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${n===b.id?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:b.label},b.id))})}),e.jsx("div",{className:"hidden md:flex flex-col w-48 border-r border-border p-3 gap-1 flex-shrink-0",children:m.map(b=>{const j=b.icon;return e.jsxs("button",{onClick:()=>v(b.id),className:`flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${n===b.id?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground hover:bg-accent/50"}`,children:[e.jsx(j,{className:"w-4 h-4"}),b.label]},b.id)})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 md:p-6",children:[n==="users"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:i?e.jsx(il,{onBack:()=>d(!1)}):x?e.jsx(ml,{userUuid:x.uuid,username:x.username,onBack:()=>h(null)}):e.jsx(sl,{isSuperAdmin:o,onNavigateToUsage:()=>d(!0),onViewUser:(b,j)=>h({uuid:b,username:j})})}),n==="system"&&e.jsxs("div",{className:"space-y-6 md:space-y-8",children:[e.jsx(al,{}),e.jsx(nl,{})]})]})]})]})})}function pl(){const{isDarkMode:t,toggleDarkMode:s}=ws();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 xl=({isOpen:t,onToggle:s,autoExpandTools:a,onAutoExpandChange:o,showRawParameters:n,onShowRawParametersChange:l,showThinking:i,onShowThinkingChange:d,autoScrollToBottom:x,onAutoScrollChange:h,sendByCtrlEnter:m,onSendByCtrlEnterChange:v,isMobile:b})=>{const[j,f]=r.useState(t),[E,O]=r.useState(()=>localStorage.getItem("whisperMode")||"default"),{isDarkMode:T}=ws(),[R,g]=r.useState(()=>{const X=localStorage.getItem("quickSettingsHandlePosition");if(X)try{return JSON.parse(X).y??50}catch{return localStorage.removeItem("quickSettingsHandlePosition"),50}return 50}),[p,u]=r.useState(!1),[y,L]=r.useState(0),[$,P]=r.useState(0),[z,me]=r.useState(!1),se=r.useRef(null),te=r.useRef({min:10,max:90}),de=5;r.useEffect(()=>{f(t)},[t]),r.useEffect(()=>{localStorage.setItem("quickSettingsHandlePosition",JSON.stringify({y:R}))},[R]);const _=r.useCallback(()=>b?{bottom:`${window.innerHeight*R/100}px`}:{top:`${R}%`,transform:"translateY(-50%)"},[R,b]),A=r.useCallback(X=>{X.stopPropagation();const G=X.type.includes("touch")?X.touches[0].clientY:X.clientY;L(G),P(R),me(!1),u(!1)},[R]),ae=r.useCallback(X=>{if(y===0)return;const G=X.type.includes("touch")?X.touches[0].clientY:X.clientY,pe=Math.abs(G-y);if(!p&&pe>de&&(u(!0),me(!0),document.body.style.cursor="grabbing",document.body.style.userSelect="none",X.type.includes("touch")&&(document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.width="100%")),!p)return;X.type.includes("touch")&&X.preventDefault();const Pe=G-y;let Ee;b?Ee=-(Pe/window.innerHeight)*100:Ee=Pe/window.innerHeight*100;let Me=$+Ee;Me=Math.max(te.current.min,Math.min(te.current.max,Me)),g(Me)},[p,y,$,b,de]),fe=r.useCallback(()=>{u(!1),L(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(y!==0){const X=Ee=>ae(Ee),G=()=>fe(),pe=Ee=>ae(Ee),Pe=()=>fe();return document.addEventListener("mousemove",X),document.addEventListener("mouseup",G),document.addEventListener("touchmove",pe,{passive:!1}),document.addEventListener("touchend",Pe),()=>{document.removeEventListener("mousemove",X),document.removeEventListener("mouseup",G),document.removeEventListener("touchmove",pe),document.removeEventListener("touchend",Pe)}}},[y,ae,fe]);const ue=X=>{if(z){X.preventDefault(),me(!1);return}const G=!j;f(G),s(G)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:se,onClick:ue,onMouseDown:X=>{A(X)},onTouchStart:X=>{A(X)},className:`fixed ${j?"right-64":"right-0"} z-50 ${p?"":"transition-all duration-150 ease-out"} bg-white dark:bg-gray-800 border ${p?"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 ${p?"cursor-grabbing":"cursor-pointer"} touch-none`,style:{..._(),touchAction:"none",WebkitTouchCallout:"none",WebkitUserSelect:"none"},"aria-label":p?"拖动手柄":j?"关闭设置面板":"打开设置面板",title:p?"拖动中...":"点击切换,拖动移动",children:p?e.jsx(An,{className:"h-5 w-5 text-blue-500 dark:text-blue-400"}):j?e.jsx(Vt,{className:"h-5 w-5 text-gray-600 dark:text-gray-400"}):e.jsx(On,{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 ${j?"translate-x-0":"translate-x-full"} ${b?"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(_n,{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 ${b?"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:[T?e.jsx(Qr,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}):e.jsx(Zr,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"深色模式"]}),e.jsx(pl,{})]})]}),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(da,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"自动展开工具"]}),e.jsx("input",{type:"checkbox",checked:a,onChange:X=>o(X.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(ma,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"显示原始参数"]}),e.jsx("input",{type:"checkbox",checked:n,onChange:X=>l(X.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(la,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"显示思考过程"]}),e.jsx("input",{type:"checkbox",checked:i,onChange:X=>d(X.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(Fn,{className:"h-4 w-4 text-gray-600 dark:text-gray-400"}),"自动滚动到底部"]}),e.jsx("input",{type:"checkbox",checked:x,onChange:X=>h(X.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"}),"使用 Ctrl+Enter 发送"]}),e.jsx("input",{type:"checkbox",checked:m,onChange:X=>v(X.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:E==="default",onChange:()=>{O("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(kr,{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:E==="prompt",onChange:()=>{O("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(Yr,{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:E==="vibe"||E==="instructions"||E==="architect",onChange:()=>{O("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(ua,{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:"将想法格式化为带有详细说明的代理指令"})]})]})]})]})]})]})}),j&&e.jsx("div",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm z-30 transition-opacity duration-150 ease-out",onClick:ue})]})};function hl({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(It,{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(He,{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(W,{variant:"default",onClick:a,children:"我知道了"})})]})})}function gl(){const[t,s]=r.useState(null),[a,o]=r.useState([]),[n,l]=r.useState(!1),i=r.useRef(null),d=r.useRef(null),{token:x}=Nt();r.useEffect(()=>(i.current&&(clearTimeout(i.current),i.current=null),d.current&&(d.current.close(),d.current=null),x||!1?h():(l(!1),s(null)),()=>{i.current&&clearTimeout(i.current),d.current&&d.current.close()}),[x]);const h=()=>{try{let b;{const f=x||localStorage.getItem("auth-token");if(!f){console.warn("No authentication token found for WebSocket connection");return}b=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws?token=${encodeURIComponent(f)}`}const j=new WebSocket(b);d.current=j,j.onopen=()=>{l(!0),s(j)},j.onmessage=f=>{try{const E=JSON.parse(f.data);o(O=>[...O,E])}catch(E){console.error("Error parsing WebSocket message:",E)}},j.onclose=()=>{l(!1),s(null),d.current=null,localStorage.getItem("auth-token")&&(i.current=setTimeout(()=>{h()},3e3))},j.onerror=f=>{console.error("WebSocket error:",f)}}catch(v){console.error("Error creating WebSocket connection:",v)}};return{ws:t,sendMessage:v=>{t&&n?t.send(JSON.stringify(v)):console.warn("WebSocket not connected")},messages:a,isConnected:n}}const Ra=r.createContext({ws:null,sendMessage:()=>{},messages:[],isConnected:!1}),fl=()=>{const t=r.useContext(Ra);if(!t)throw new Error("useWebSocketContext must be used within a WebSocketProvider");return t},bl=({children:t})=>{const s=gl();return e.jsx(Ra.Provider,{value:s,children:t})},vl=()=>{const[t,s]=r.useState("email"),[a,o]=r.useState(""),[n,l]=r.useState(""),[i,d]=r.useState(!1),[x,h]=r.useState(""),[m,v]=r.useState(0),{sendCode:b,verifyCode:j,smtpConfigured:f}=Nt();r.useEffect(()=>{if(m>0){const g=setTimeout(()=>v(m-1),1e3);return()=>clearTimeout(g)}},[m]);const E=async g=>{if(g.preventDefault(),h(""),!a||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)){h("请输入有效的邮箱地址");return}d(!0);const u=await b(a);u.success?(s("code"),v(60)):(h(u.error),u.waitSeconds&&v(u.waitSeconds)),d(!1)},O=async g=>{if(g.preventDefault(),h(""),!n||n.length!==6){h("请输入6位验证码");return}d(!0);const p=await j(a,n);p.success||h(p.error),d(!1)},T=async()=>{if(m>0)return;h(""),d(!0);const g=await b(a);g.success?v(60):h(g.error),d(!1)},R=()=>{s("email"),l(""),h("")};return f?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(gt,{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:E,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(Sr,{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:g=>o(g.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"})]})]}),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:i||m>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?"发送中...":m>0?`${m}秒后可重新发送`:"获取验证码"})]}),t==="code"&&e.jsxs("form",{onSubmit:O,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:R,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Qt,{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:g=>l(g.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"})]}),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: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:T,disabled:m>0||i,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:m>0?`${m}秒后可重新发送`:"重新发送验证码"})})]}),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(gt,{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"})]})]})]})})})},yl=()=>{const[t,s]=r.useState("email"),[a,o]=r.useState("email"),[n,l]=r.useState(""),[i,d]=r.useState(""),[x,h]=r.useState(""),[m,v]=r.useState(""),[b,j]=r.useState(!1),[f,E]=r.useState(""),[O,T]=r.useState(0),[R,g]=r.useState(!1),{login:p,sendCode:u,verifyCode:y,smtpConfigured:L}=Nt();r.useEffect(()=>{if(O>0){const _=setTimeout(()=>T(O-1),1e3);return()=>clearTimeout(_)}},[O]),r.useEffect(()=>{L||s("password")},[L]);const $=async _=>{if(_.preventDefault(),E(""),!n||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)){E("请输入有效的邮箱地址");return}j(!0);const ae=await u(n);ae.success?(o("code"),T(60),g(ae.type==="register")):(E(ae.error),ae.waitSeconds&&T(ae.waitSeconds)),j(!1)},P=async _=>{if(_.preventDefault(),E(""),!i||i.length!==6){E("请输入6位验证码");return}j(!0);const A=await y(n,i);A.success||E(A.error),j(!1)},z=async()=>{if(O>0)return;E(""),j(!0);const _=await u(n);_.success?T(60):E(_.error),j(!1)},me=async _=>{if(_.preventDefault(),E(""),!x||!m){E("请输入用户名和密码");return}j(!0);const A=await p(x,m);A.success||E(A.error),j(!1)},se=()=>{o("email"),d(""),E("")},te=()=>{s("email"),o("email"),E("")},de=()=>{s("password"),E("")};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":R?"创建您的账户":"验证您的身份":"欢迎回来"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?a==="email"?"输入邮箱以接收验证码":`验证码已发送至 ${n}`:"使用账号密码登录"})]}),t==="email"&&a==="email"&&e.jsxs("form",{onSubmit:$,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(Sr,{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:_=>l(_.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:b,autoComplete:"email"})]})]}),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.jsx("button",{type:"submit",disabled:b||O>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:b?"发送中...":O>0?`${O}秒后可重新发送`:"获取验证码"})]}),t==="email"&&a==="code"&&e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:se,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Qt,{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(_.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:b,maxLength:6,autoComplete:"one-time-code"})]}),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.jsx("button",{type:"submit",disabled:b||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:b?"验证中...":R?"创建账户并登录":"登录"}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:z,disabled:O>0||b,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:O>0?`${O}秒后可重新发送`:"重新发送验证码"})})]}),t==="password"&&e.jsxs("form",{onSubmit:me,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(es,{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:x,onChange:_=>h(_.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:b})]})]}),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(Bn,{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:m,onChange:_=>v(_.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:b})]})]}),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.jsx("button",{type:"submit",disabled:b,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:b?"登录中...":"登录"})]}),e.jsx("div",{className:"text-center pt-4 border-t border-border",children:t==="email"&&L?e.jsx("button",{type:"button",onClick:de,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用账号密码登录"}):t==="password"&&L?e.jsx("button",{type:"button",onClick:te,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用邮箱验证码登录"}):null})]})})})},jl=()=>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(Lr,{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:"加载中..."})]})}),wl=({children:t})=>{const{user:s,isLoading:a,needsSetup:o}=Nt();return a?e.jsx(jl,{}):o?e.jsx(vl,{}):s?t:e.jsx(yl,{})};function Gt(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 sa(){const t=na(),{sessionId:s}=gn(),{limitStatus:a,setLimitStatus:o,checkLimitStatus:n,user:l,isAdmin:i}=Nt(),[d,x]=r.useState([]),[h,m]=r.useState(null),[v,b]=r.useState(null),[j,f]=r.useState("chat"),[E,O]=r.useState(!1),[T,R]=r.useState(!1),[g,p]=r.useState(!0),[u,y]=r.useState(!1),[L,$]=r.useState(!1),[P,z]=r.useState(!1),[me,se]=r.useState("agents"),[te,de]=r.useState(!1),[_,A]=Gt("autoExpandTools",!1),[ae,fe]=Gt("showRawParameters",!1),[ue,X]=Gt("showThinking",!0),[G,pe]=Gt("autoScrollToBottom",!0),[Pe,Ee]=Gt("sendByCtrlEnter",!1),[Me,Ne]=Gt("sidebarVisible",!0),[qe,Ge]=r.useState(!1),[We,De]=r.useState(null),[je,$e]=r.useState(new Set),[Fe,_e]=r.useState(new Set),[ze,J]=r.useState(0),{ws:q,sendMessage:w,messages:K}=fl(),he=r.useCallback(B=>{De(B),Ge(!0)},[]),[ve,Ae]=r.useState(!1);r.useEffect(()=>{const B=()=>{const re=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone||document.referrer.includes("android-app://");Ae(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 B(),window.matchMedia("(display-mode: standalone)").addEventListener("change",B),()=>{window.matchMedia("(display-mode: standalone)").removeEventListener("change",B)}},[]),r.useEffect(()=>{const B=()=>{O(window.innerWidth<768)};return B(),window.addEventListener("resize",B),()=>window.removeEventListener("resize",B)},[]),r.useEffect(()=>{V()},[]);const Ue=(B,re,ie,ye)=>{if(!ie||!ye)return!0;const xe=B?.find(at=>at.name===ie.name),Ye=re?.find(at=>at.name===ie.name);if(!xe||!Ye)return!1;const Le=xe.sessions?.find(at=>at.id===ye.id),Je=Ye.sessions?.find(at=>at.id===ye.id);return!Le||!Je?!1:Le.id===Je.id&&Le.title===Je.title&&Le.created_at===Je.created_at&&Le.updated_at===Je.updated_at};r.useEffect(()=>{if(K.length>0){const B=K[K.length-1];if(B.type==="projects_updated"){if(B.changedFile&&v&&h){const xe=B.changedFile.replace(/\\/g,"/").split("/");xe.length>=2&&xe[xe.length-1].replace(".jsonl","")===v.id&&(je.has(v.id)||J(st=>st+1))}if(v&&je.has(v.id)||je.size>0&&Array.from(je).some(ye=>ye.startsWith("new-session-"))){const ye=B.projects;if(!Ue(d,ye,h,v))return}const ie=B.projects;if(x(ie),h){const ye=ie.find(xe=>xe.name===h.name);ye&&(JSON.stringify(ye)!==JSON.stringify(h)&&m(ye),v&&([...ye.sessions||[]].find(Le=>Le.id===v.id)||b(null)))}}}},[K,h,v,je]);const V=async()=>{try{p(!0);const re=await(await ke.projects()).json();x(ie=>ie.length===0||re.some((xe,Ye)=>{const Le=ie[Ye];return Le?xe.name!==Le.name||xe.displayName!==Le.displayName||xe.fullPath!==Le.fullPath||JSON.stringify(xe.sessionMeta)!==JSON.stringify(Le.sessionMeta)||JSON.stringify(xe.sessions)!==JSON.stringify(Le.sessions):!0})||re.length!==ie.length?re:ie)}catch(B){console.error("Error fetching projects:",B)}finally{p(!1)}};window.refreshProjects=V,window.openSettings=r.useCallback((B="tools")=>{se(B),$(!0)},[]),window.openAdminPanel=r.useCallback(()=>{z(!0)},[]),r.useEffect(()=>{if(s&&d.length>0){const B=!v||v.id!==s;for(const re of d){let ie=re.sessions?.find(ye=>ye.id===s);if(ie){m(re),b({...ie,__provider:"claude"}),B&&f("chat");return}}}},[s,d,t]);const oe=B=>{m(B),b(null),t("/"),E&&R(!1)},Ie=B=>{if(b(B),j!=="git"&&j!=="preview"&&f("chat"),E){const re=B.__projectName,ie=h?.name;re!==ie&&R(!1)}t(`/session/${B.id}`)},Te=B=>{m(B),b(null),f("chat"),t("/"),E&&R(!1)},Ce=B=>{v?.id===B&&(b(null),t("/")),x(re=>re.map(ie=>({...ie,sessions:ie.sessions?.filter(ye=>ye.id!==B)||[],sessionMeta:{...ie.sessionMeta,total:Math.max(0,(ie.sessionMeta?.total||0)-1)}})))},N=async()=>{try{const re=await(await ke.projects()).json();if(x(ie=>re.some((xe,Ye)=>{const Le=ie[Ye];return Le?xe.name!==Le.name||xe.displayName!==Le.displayName||xe.fullPath!==Le.fullPath||JSON.stringify(xe.sessionMeta)!==JSON.stringify(Le.sessionMeta)||JSON.stringify(xe.sessions)!==JSON.stringify(Le.sessions):!0})||re.length!==ie.length?re:ie),h){const ie=re.find(ye=>ye.name===h.name);if(ie&&(JSON.stringify(ie)!==JSON.stringify(h)&&m(ie),v)){const ye=ie.sessions?.find(xe=>xe.id===v.id);ye&&JSON.stringify(ye)!==JSON.stringify(v)&&b(ye)}}}catch(B){console.error("Error refreshing sidebar:",B)}},ee=B=>{h?.name===B&&(m(null),b(null),t("/")),x(re=>re.filter(ie=>ie.name!==B))},we=r.useCallback(B=>{B&&$e(re=>new Set([...re,B]))},[]),Y=r.useCallback(B=>{B&&$e(re=>{const ie=new Set(re);return ie.delete(B),ie})},[]),U=r.useCallback(B=>{B&&_e(re=>new Set([...re,B]))},[]),M=r.useCallback(B=>{B&&_e(re=>{const ie=new Set(re);return ie.delete(B),ie})},[]),ne=r.useCallback(B=>{B&&$e(re=>{const ie=new Set;for(const ye of re)ye.startsWith("new-session-")||ie.add(ye);return ie.add(B),ie})},[]);return e.jsxs("div",{className:"fixed inset-0 flex bg-background",children:[!E&&e.jsx("div",{className:`h-full flex-shrink-0 border-r border-border bg-card transition-all duration-300 ${Me?"w-80":"w-14"}`,children:e.jsx("div",{className:"h-full overflow-hidden",children:Me?e.jsx(Os,{projects:d,selectedProject:h,selectedSession:v,onProjectSelect:oe,onSessionSelect:Ie,onNewSession:Te,onSessionDelete:Ce,onProjectDelete:ee,isLoading:g,onRefresh:N,onShowSettings:()=>$(!0),onShowAdmin:()=>z(!0),isPWA:ve,isMobile:E,onToggleSidebar:()=>Ne(!1)}):e.jsxs("div",{className:"h-full flex flex-col items-center py-4 gap-4",children:[e.jsx("button",{onClick:()=>Ne(!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:()=>$(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Settings",title:"Settings",children:e.jsx(Tt,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})}),i&&e.jsx("button",{onClick:()=>z(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Admin",title:"管理",children:e.jsx(kt,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})})]})})}),E&&e.jsxs("div",{className:`fixed inset-0 z-50 flex transition-all duration-150 ease-out ${T?"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:B=>{B.stopPropagation(),R(!1)},onTouchStart:B=>{B.preventDefault(),B.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 ${T?"translate-x-0":"-translate-x-full"}`,onClick:B=>B.stopPropagation(),onTouchStart:B=>B.stopPropagation(),children:e.jsx(Os,{projects:d,selectedProject:h,selectedSession:v,onProjectSelect:oe,onSessionSelect:Ie,onNewSession:Te,onSessionDelete:Ce,onProjectDelete:ee,isLoading:g,onRefresh:N,onShowSettings:()=>$(!0),onShowAdmin:()=>z(!0),isPWA:ve,isMobile:E,onToggleSidebar:()=>Ne(!1)})})]}),e.jsx("div",{className:`flex-1 flex flex-col min-w-0 ${E&&!u?"pb-mobile-nav":""}`,children:e.jsx(Pi,{selectedProject:h,selectedSession:v,activeTab:j,setActiveTab:f,ws:q,sendMessage:w,messages:K,isMobile:E,isPWA:ve,onMenuClick:()=>R(!0),isLoading:g,onInputFocusChange:y,onSessionActive:we,onSessionInactive:Y,onSessionProcessing:U,onSessionNotProcessing:M,processingSessions:Fe,onReplaceTemporarySession:ne,onNavigateToSession:B=>t(`/session/${B}`),onShowSettings:()=>$(!0),autoExpandTools:_,showRawParameters:ae,showThinking:ue,autoScrollToBottom:G,sendByCtrlEnter:Pe,externalMessageUpdate:ze,limitStatus:a,onLimitBlocked:he,checkLimitStatus:n})}),E&&e.jsx($i,{activeTab:j,setActiveTab:f,isInputFocused:u}),j==="chat"&&e.jsx(xl,{isOpen:te,onToggle:de,autoExpandTools:_,onAutoExpandChange:A,showRawParameters:ae,onShowRawParametersChange:fe,showThinking:ue,onShowThinkingChange:X,autoScrollToBottom:G,onAutoScrollChange:pe,sendByCtrlEnter:Pe,onSendByCtrlEnterChange:Ee,isMobile:E}),e.jsx(rl,{isOpen:L,onClose:()=>$(!1),projects:d,initialTab:me}),e.jsx(ul,{isOpen:P,onClose:()=>z(!1)}),e.jsx(hl,{isOpen:qe,limitType:We,onClose:()=>Ge(!1)})]})}function kl(){return e.jsx(zi,{children:e.jsx(oo,{children:e.jsx(bl,{children:e.jsx(ao,{children:e.jsx(wl,{children:e.jsx(xn,{children:e.jsxs(hn,{children:[e.jsx(Ts,{path:"/",element:e.jsx(sa,{})}),e.jsx(Ts,{path:"/session/:sessionId",element:e.jsx(sa,{})})]})})})})})})})}"serviceWorker"in navigator&&navigator.serviceWorker.getRegistrations().then(t=>{t.forEach(s=>{s.unregister()})}).catch(t=>{console.warn("Failed to unregister service workers:",t)});eo.createRoot(document.getElementById("root")).render(e.jsx(it.StrictMode,{children:e.jsx(kl,{})}));