@ian2018cs/agenthub 0.1.75 → 0.1.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,197 @@
1
+ import{j as e,s as Jn,R as Kn,o as Gn,E as Vn,m as Yn,b as Qn,c as Xn,h as Zn,p as eo,d as to}from"./vendor-codemirror-sVRjxPVQ.js";import{b as so,g as Pr,a as s,d as _s,R as ut,u as Gs,L as Yt,B as ro,e as za,f as js,h as ao}from"./vendor-react-Bv0Nkan8.js";import{t as no,c as oo,a as Oa,F as io}from"./vendor-utils-00TdZexr.js";import{T as Ot,C as Fa,I as Vs,F as ks,X as Ge,L as Dt,B as Pt,S as St,R as ct,D as At,a as vr,b as is,Z as Ar,c as Ys,G as Qs,d as Qt,e as zs,U as zt,f as Xt,g as Ns,h as ws,i as ca,j as bt,P as jr,k as Os,l as lo,m as Ft,n as Ut,o as Wt,M as cr,p as co,q as $r,r as mo,s as uo,E as Ua,t as po,u as da,v as dr,w as xo,x as _r,y as zr,z as Fs,A as Wa,H as Zt,J as Ba,K as ho,N as wr,O as Ha,Q as qa,V as Us,W as Ws,Y as go,_ as fo,$ as kr,a0 as Ja,a1 as bo,a2 as Ka,a3 as yo,a4 as vo,a5 as jo,a6 as Or,a7 as wo,a8 as ko,a9 as No,aa as So,ab as Co,ac as Nr,ad as Eo,ae as Bs,af as Ga,ag as Va,ah as Mo,ai as Io}from"./vendor-icons-DUmFlkZ8.js";import{r as Lo,a as To,b as Ro,M as Do}from"./vendor-markdown-CjscLcYM.js";import{h as Po}from"./vendor-syntax-BKENXTeY.js";import{r as Ao,a as $o,b as _o,c as zo}from"./vendor-xterm-CvdiG4-n.js";import"./vendor-katex-DK8hFnhL.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.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 Ds={},ma;function Oo(){if(ma)return Ds;ma=1;var t=so();return Ds.createRoot=t.createRoot,Ds.hydrateRoot=t.hydrateRoot,Ds}var Fo=Oo();const Uo=Pr(Fo);function rt(...t){return no(oo(t))}function Wo(t){if(!t||typeof t!="string")return null;try{return JSON.parse(t)}catch{return null}}const Fr=s.forwardRef(({className:t,children:r,...a},o)=>e.jsx("div",{ref:o,className:rt("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:r})}));Fr.displayName="ScrollArea";const Bo=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"}}),B=s.forwardRef(({className:t,variant:r,size:a,...o},n)=>e.jsx("button",{className:rt(Bo({variant:r,size:a,className:t})),ref:n,...o}));B.displayName="Button";const Ho=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 et({className:t,variant:r,...a}){return e.jsx("div",{className:rt(Ho({variant:r}),t),...a})}const it=s.forwardRef(({className:t,type:r,...a},o)=>e.jsx("input",{type:r,className:rt("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}));it.displayName="Input";const Ya="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}",Qa="[a-zA-Z0-9._/~:+@%=\\\\-]",qo=new RegExp(`${Qa}*\\/user-data\\/${Ya}\\/`,"gi"),Jo=new RegExp(`${Qa}*\\/user-projects\\/${Ya}\\/`,"gi");function He(t){return!t||typeof t!="string"?t||"":t.replace(qo,"./").replace(Jo,"./")}const Ze="AgentHub",Xa="你的 AI 助手",ua=[{icon:"📋",text:"帮我整理今天的工作计划"},{icon:"📊",text:"分析这段数据并给出洞察"},{icon:"✍️",text:"帮我润色这段文字"},{icon:"💡",text:"给我一些解决问题的思路"}],pa="default",Ko="0.1.76",Go={version:Ko},Za=s.createContext(null);function dt(){const t=s.useContext(Za);if(!t)throw new Error("useDialog must be used within DialogProvider");return t}function Vo({children:t}){const[r,a]=s.useState(null),o=s.useRef(null),n=s.useCallback(d=>{o.current?.(d),o.current=null,a(null)},[]),l=s.useCallback((d,u={})=>new Promise(f=>{o.current=f,a({type:"alert",message:d,title:u.title||"提示",variant:u.variant||"info"})}),[]),i=s.useCallback((d,u={})=>new Promise(f=>{o.current=f,a({type:"confirm",message:d,title:u.title||"确认操作",subtitle:u.subtitle,detail:u.detail,confirmText:u.confirmText||"确认",cancelText:u.cancelText||"取消",variant:u.variant||"warning",checkboxLabel:u.checkboxLabel})}),[]);return e.jsxs(Za.Provider,{value:{showAlert:l,showConfirm:i},children:[t,r&&_s.createPortal(e.jsx(Yo,{dialog:r,onClose:n}),document.body)]})}function Yo({dialog:t,onClose:r}){const a=s.useRef(null),o=s.useRef(null),[n,l]=s.useState(!1),i=s.useCallback(h=>{t.checkboxLabel!==void 0?r({confirmed:h,checked:h?n:!1}):r(h)},[t.checkboxLabel,n,r]);s.useEffect(()=>{t.type==="confirm"?a.current?.focus():o.current?.focus()},[t.type]),s.useEffect(()=>{const h=y=>{y.key==="Escape"&&(t.type==="confirm"?i(!1):r(void 0))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[t.type,r,i]);const d={info:e.jsx(Vs,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"}),warning:e.jsx(Ot,{className:"w-5 h-5 text-amber-600 dark:text-amber-400"}),error:e.jsx(Fa,{className:"w-5 h-5 text-red-600 dark:text-red-400"}),danger:e.jsx(Ot,{className:"w-5 h-5 text-red-600 dark:text-red-400"})},u={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"},f={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"},x=d[t.variant]||d.info,g=u[t.variant]||u.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:()=>r(),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 ${g} flex items-center justify-center flex-shrink-0`,children:x}),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:()=>r(),children:"确定"})})]})}):e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:()=>i(!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 ${g} flex items-center justify-center flex-shrink-0`,children:x}),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}),t.checkboxLabel&&e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:h=>l(h.target.checked),className:"w-4 h-4 rounded border-border accent-primary cursor-pointer"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t.checkboxLabel})]}),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:()=>i(!1),children:t.cancelText}),e.jsx("button",{ref:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${f[t.variant]||f.info}`,onClick:()=>i(!0),children:t.confirmText})]})]})})}const Y=(t,r={})=>{const a=localStorage.getItem("auth-token"),o={};return r.body instanceof FormData||(o["Content-Type"]="application/json"),a&&(o.Authorization=`Bearer ${a}`),fetch(t,{...r,headers:{...o,...r.headers}})},he={auth:{status:()=>fetch("/api/auth/status"),login:(t,r)=>fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:t,password:r})}),sendCode:t=>fetch("/api/auth/send-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t})}),verifyCode:(t,r)=>fetch("/api/auth/verify-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,code:r})}),user:()=>Y("/api/auth/user"),logout:()=>Y("/api/auth/logout",{method:"POST"}),limitStatus:()=>Y("/api/auth/limit-status"),changePassword:(t,r)=>Y("/api/auth/change-password",{method:"PATCH",body:JSON.stringify({current_password:t,new_password:r})}),feishuBindToken:()=>Y("/api/auth/feishu-bind-token",{method:"POST"}),feishuStatus:()=>Y("/api/auth/feishu-status"),featurePermissions:()=>Y("/api/auth/feature-permissions")},admin:{getUsers:()=>Y("/api/admin/users"),createUser:(t,r)=>Y("/api/admin/users",{method:"POST",body:JSON.stringify({username:t,password:r})}),updateUserStatus:(t,r)=>Y(`/api/admin/users/${t}`,{method:"PATCH",body:JSON.stringify({status:r})}),deleteUser:t=>Y(`/api/admin/users/${t}`,{method:"DELETE"}),getEmailDomains:()=>Y("/api/admin/email-domains"),addEmailDomain:t=>Y("/api/admin/email-domains",{method:"POST",body:JSON.stringify({domain:t})}),removeEmailDomain:t=>Y(`/api/admin/email-domains/${t}`,{method:"DELETE"}),getUserLimits:t=>Y(`/api/admin/users/${t}/limits`),updateUserLimits:(t,r)=>Y(`/api/admin/users/${t}/limits`,{method:"PATCH",body:JSON.stringify(r)}),resetUserPassword:(t,r)=>Y(`/api/admin/users/${t}/password`,{method:"PATCH",body:JSON.stringify({new_password:r})}),updateUserRole:(t,r)=>Y(`/api/admin/users/${t}/role`,{method:"PATCH",body:JSON.stringify({role:r})}),getDefaultLimits:()=>Y("/api/admin/settings/default-limits"),updateDefaultLimits:t=>Y("/api/admin/settings/default-limits",{method:"PUT",body:JSON.stringify(t)}),getUserPermissions:t=>Y(`/api/admin/users/${t}/permissions`),updateUserPermissions:(t,r)=>Y(`/api/admin/users/${t}/permissions`,{method:"PATCH",body:JSON.stringify({permissions:r})}),getDefaultPermissions:()=>Y("/api/admin/settings/default-permissions"),updateDefaultPermissions:t=>Y("/api/admin/settings/default-permissions",{method:"PUT",body:JSON.stringify({permissions:t})}),getUserVisibleAgents:t=>Y(`/api/admin/users/${t}/visible-agents`),updateUserVisibleAgents:(t,r)=>Y(`/api/admin/users/${t}/visible-agents`,{method:"PATCH",body:JSON.stringify({agents:r})})},projects:()=>Y("/api/projects"),sessions:(t,r=5,a=0)=>Y(`/api/projects/${t}/sessions?limit=${r}&offset=${a}`),sessionMessages:(t,r,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/${r}/messages${l?`?${l}`:""}`;return Y(i)},renameProject:(t,r)=>Y(`/api/projects/${t}/rename`,{method:"PUT",body:JSON.stringify({displayName:r})}),deleteSession:(t,r)=>Y(`/api/projects/${t}/sessions/${r}`,{method:"DELETE"}),renameSession:(t,r,a)=>Y(`/api/projects/${t}/sessions/${r}/rename`,{method:"PUT",body:JSON.stringify({title:a})}),forkSession:(t,r,a)=>Y(`/api/projects/${t}/sessions/${r}/fork`,{method:"POST",body:JSON.stringify({upToMessageId:a})}),deleteProject:(t,r=!0)=>Y(`/api/projects/${t}?deleteFolder=${r}`,{method:"DELETE"}),createProject:t=>Y("/api/projects/create",{method:"POST",body:JSON.stringify({path:t})}),createWorkspace:t=>Y("/api/projects/create-workspace",{method:"POST",body:JSON.stringify(t)}),readFile:(t,r)=>Y(`/api/projects/${t}/file?filePath=${encodeURIComponent(r)}`),saveFile:(t,r,a)=>Y(`/api/projects/${t}/file`,{method:"PUT",body:JSON.stringify({filePath:r,content:a})}),getFiles:(t,r={})=>{const a=new URLSearchParams;r.dirPath&&a.set("dirPath",r.dirPath),r.depth&&a.set("depth",r.depth.toString()),r.showHidden&&a.set("showHidden","true");const o=a.toString();return Y(`/api/projects/${t}/files${o?"?"+o:""}`)},uploadFiles:(t,r)=>Y(`/api/projects/${t}/upload-files`,{method:"POST",body:r,headers:{}}),deleteFile:(t,r)=>Y(`/api/projects/${t}/files?filePath=${encodeURIComponent(r)}`,{method:"DELETE"}),createDir:(t,r)=>Y(`/api/projects/${t}/create-dir`,{method:"POST",body:JSON.stringify({dirPath:r})}),getFileContent:(t,r)=>Y(`/api/projects/${t}/files/content?path=${encodeURIComponent(r)}`),transcribe:t=>Y("/api/transcribe",{method:"POST",body:t,headers:{}}),settings:{getAgentPermissions:()=>Y("/api/settings/agent-permissions"),saveAgentPermissions:t=>Y("/api/settings/agent-permissions",{method:"PUT",body:JSON.stringify({agentPermissions:t})})},get:t=>Y(`/api${t}`)},vs={claude_shell:!0,codex_shell:!0,gemini_shell:!0,submit_agent:!0,tab_models:!0,tab_skills:!0,tab_mcp:!0,tab_permissions:!0,feishu_binding:!0,create_project:!0},en=s.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:()=>{},featurePermissions:vs,hasPermission:()=>!0,refreshFeaturePermissions:()=>{}}),Ct=()=>{const t=s.useContext(en);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t};async function mr(){try{const t=await he.settings.getAgentPermissions();if(t.ok){const r=await t.json();r.agentPermissions&&localStorage.setItem("claude-settings",JSON.stringify(r.agentPermissions))}}catch{}}const Qo=({children:t})=>{const[r,a]=s.useState(null),[o,n]=s.useState(localStorage.getItem("auth-token")),[l,i]=s.useState(!0),[d,u]=s.useState(!1),[f,x]=s.useState(!1),[g,h]=s.useState(null),[y,k]=s.useState({allowed:!0}),[L,I]=s.useState(vs);s.useEffect(()=>{p()},[]);const p=async()=>{try{i(!0),h(null);const z=await(await he.auth.status()).json();if(x(z.smtpConfigured||!1),z.needsSetup){u(!0),i(!1);return}if(o)try{const q=await he.auth.user();if(q.ok){const S=await q.json();a(S.user),u(!1),S.featurePermissions&&I({...vs,...S.featurePermissions}),await mr()}else localStorage.removeItem("auth-token"),n(null),a(null)}catch(q){console.error("Token verification failed:",q),localStorage.removeItem("auth-token"),n(null),a(null)}}catch(N){console.error("[AuthContext] Auth status check failed:",N),h("Failed to check authentication status")}finally{i(!1)}},b=async N=>{try{h(null);const z=await he.auth.sendCode(N),q=await z.json();return z.ok?{success:!0,type:q.type}:{success:!1,error:q.error||"发送验证码失败",waitSeconds:q.waitSeconds}}catch(z){return console.error("Send code error:",z),{success:!1,error:"网络错误,请稍后再试"}}},m=async(N,z)=>{try{h(null);const q=await he.auth.verifyCode(N,z),S=await q.json();return q.ok?(n(S.token),a(S.user),u(!1),localStorage.setItem("auth-token",S.token),await mr(),await U(),{success:!0}):(h(S.error||"验证失败"),{success:!1,error:S.error||"验证失败"})}catch(q){return console.error("Verify code error:",q),{success:!1,error:"网络错误,请稍后再试"}}},j=async(N,z)=>{try{h(null);const q=await he.auth.login(N,z),S=await q.json();return q.ok?(n(S.token),a(S.user),localStorage.setItem("auth-token",S.token),await mr(),await U(),{success:!0}):(h(S.error||"登录失败"),{success:!1,error:S.error||"登录失败"})}catch(q){console.error("Login error:",q);const S="网络错误,请稍后再试";return h(S),{success:!1,error:S}}},R=()=>{n(null),a(null),k({allowed:!0}),I(vs),localStorage.removeItem("auth-token"),o&&he.auth.logout().catch(N=>{console.error("Logout endpoint error:",N)})},G=async()=>{if(!r)return{allowed:!0};try{const N=await he.auth.limitStatus();if(N.ok){const z=await N.json();return k(z),z}}catch(N){console.error("Error checking limit status:",N)}return{allowed:!0}},U=s.useCallback(async()=>{try{const N=await he.auth.featurePermissions();if(N.ok){const z=await N.json();z.featurePermissions&&I({...vs,...z.featurePermissions})}}catch(N){console.error("Error refreshing feature permissions:",N)}},[]),v=s.useCallback(N=>L[N]!==!1,[L]);s.useEffect(()=>{r&&!l&&G()},[r,l]);const H={user:r,token:o,login:j,sendCode:b,verifyCode:m,logout:R,isLoading:l,needsSetup:d,smtpConfigured:f,error:g,isAdmin:r?.role==="admin"||r?.role==="super_admin",isSuperAdmin:r?.role==="super_admin",limitStatus:y,checkLimitStatus:G,setLimitStatus:k,featurePermissions:L,hasPermission:v,refreshFeaturePermissions:U};return e.jsx(en.Provider,{value:H,children:t})},Xo=/^[a-zA-Z0-9_-]+$/,Zo=({onClose:t,onProjectCreated:r})=>{const[a,o]=s.useState(""),[n,l]=s.useState(""),[i,d]=s.useState(!1),[u,f]=s.useState(null),x=y=>y.trim()?Xo.test(y.trim())?null:"项目名称只能包含字母、数字、连字符和下划线":"项目名称为必填项",g=async()=>{f(null);const y=x(a);if(y){f(y);return}d(!0);try{const k={name:a.trim()};n.trim()&&(k.githubUrl=n.trim());const L=await he.createWorkspace(k),I=await L.json();if(!L.ok)throw new Error(I.error||"Failed to create project");r&&r(I.project),t()}catch(k){console.error("Error creating project:",k),f(k.message||"Failed to create project")}finally{d(!1)}},h=y=>{y.key==="Enter"&&!i&&g()};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(ks,{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(Ge,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[u&&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(Fa,{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:u})})]}),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(it,{type:"text",value:a,onChange:y=>o(y.target.value),onKeyDown:h,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(it,{type:"text",value:n,onChange:y=>l(y.target.value),onKeyDown:h,placeholder:"https://github.com/user/repo",className:"w-full"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"留空以创建空项目,或输入公共仓库链接以克隆"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 p-6 border-t border-gray-200 dark:border-gray-700",children:[e.jsx(B,{variant:"outline",onClick:t,disabled:i,children:"取消"}),e.jsx(B,{onClick:g,disabled:i||!a.trim(),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Dt,{className:"w-4 h-4 mr-2 animate-spin"}),"创建中..."]}):"创建项目"})]})]})})};function ei({projects:t=[],onClose:r}){const{showAlert:a,showConfirm:o}=dt(),[n,l]=s.useState([]),[i,d]=s.useState(!0),[u,f]=s.useState(null),[x,g]=s.useState(""),h={};for(const p of t)p.agentInfo?.isAgent&&(h[p.agentInfo.agentName]=p.agentInfo.installedVersion);s.useEffect(()=>{y()},[]),s.useEffect(()=>{const p=b=>{b.key==="Escape"&&r()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[r]);const y=async()=>{try{d(!0);const p=await Y("/api/agents");if(p.ok){const b=await p.json();l(b.agents||[])}else{const b=await p.json();a(b.error||"获取 Agent 列表失败",{variant:"error"})}}catch(p){a(p.message,{variant:"error"})}finally{d(!1)}},k=async(p,b=!1)=>{const m=p.dirName||p.name;f(m);try{const j=await Y("/api/agents/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentName:m,force:b})}),R=await j.json();if(j.status===409&&R.conflict){f(null),await o("检测到本地 CLAUDE.md 已被修改,更新将覆盖本地改动,是否继续?",{title:"本地文件冲突",confirmText:"强制更新",variant:"warning"})&&await k(p,!0);return}j.ok?(a(`Agent "${p.display_name||p.name}" ${b?"更新":"使用"}成功!项目已创建,Skills 和 MCP 服务已安装。`,{title:b?"更新成功":"使用成功"}),window.refreshProjects?.(),window.refreshMcpServers?.(),y()):a(R.error||"使用失败",{variant:"error"})}catch(j){a(j.message,{variant:"error"})}finally{f(null)}},L=p=>{const b=p.dirName||p.name,m=h[b];return m?m===p.version?{state:"up_to_date",installedVersion:m}:{state:"update_available",installedVersion:m,latestVersion:p.version}:{state:"not_installed"}},I=s.useMemo(()=>{if(!x.trim())return n;const p=x.toLowerCase();return n.filter(b=>(b.display_name||b.name||"").toLowerCase().includes(p)||(b.description||"").toLowerCase().includes(p))},[n,x]);return e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",onClick:r,children:e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-2xl w-full max-w-lg flex flex-col max-h-[80vh]",onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center",children:e.jsx(Pt,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground",children:"使用共享项目模板"}),!i&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n.length," 个可用"]})]})]}),e.jsx("button",{onClick:r,className:"w-7 h-7 rounded-md flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:e.jsx(Ge,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"px-4 py-3 border-b border-border",children:e.jsxs("div",{className:"relative",children:[e.jsx(St,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),e.jsx("input",{type:"text",placeholder:"搜索共享项目模板...",value:x,onChange:p=>g(p.target.value),className:"w-full h-8 pl-9 pr-3 text-sm bg-muted/50 border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-primary/30 focus:bg-background text-foreground placeholder:text-muted-foreground",autoFocus:!0})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3 space-y-2",children:i?e.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[e.jsx(ct,{className:"w-5 h-5 animate-spin mr-2"}),"加载中..."]}):n.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Pt,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"暂无可用共享项目模板"})]}):I.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(St,{className:"w-6 h-6 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的共享项目模板"})]}):I.map(p=>{const b=p.dirName||p.name,m=L(p),j=u===b;return e.jsxs("div",{className:"flex items-center gap-3 p-3 border border-border rounded-lg hover:bg-accent/50 transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center flex-shrink-0",children:e.jsx(Pt,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm text-foreground truncate",children:p.display_name||p.name}),e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:["v",p.version]}),m.state==="update_available"&&e.jsxs(et,{className:"text-xs bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400 border-amber-200 dark:border-amber-700 hover:bg-amber-200 dark:hover:bg-amber-900/50 flex-shrink-0",children:["有更新 v",m.latestVersion]}),m.state==="up_to_date"&&e.jsx(et,{className:"text-xs bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400 border-green-200 dark:border-green-700 hover:bg-green-200 dark:hover:bg-green-900/50 flex-shrink-0",children:"已使用"})]}),p.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:p.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[p.skills?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.skills.length," 个 Skill"]}),p.mcps?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[p.mcps.length," 个 MCP"]})]})]}),e.jsx(B,{size:"sm",variant:m.state==="not_installed"?"default":"outline",onClick:()=>k(p),disabled:j||m.state==="up_to_date",className:"text-xs h-7 px-2.5 flex-shrink-0",children:j?e.jsx(ct,{className:"w-3 h-3 animate-spin"}):m.state==="up_to_date"?"已是最新":m.state==="update_available"?e.jsxs(e.Fragment,{children:[e.jsx(At,{className:"w-3 h-3 mr-1"}),"更新"]}):e.jsxs(e.Fragment,{children:[e.jsx(At,{className:"w-3 h-3 mr-1"}),"使用"]})})]},b)})}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-border",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:!i&&x.trim()?`${I.length} / ${n.length} 个 共享项目模板`:i?"":`共 ${n.length} 个 共享项目模板`}),e.jsx(B,{variant:"outline",size:"sm",onClick:r,className:"text-xs h-7",children:"关闭"})]})]})})}function Ur({projects:t=[],onClose:r,onSubmitted:a,initialProjectKey:o="",prefillData:n=null}){const{showAlert:l}=dt(),[i,d]=s.useState(o),[u,f]=s.useState(""),[x,g]=s.useState(""),[h,y]=s.useState(""),[k,L]=s.useState(!1),[I,p]=s.useState({hasClaudeMd:!1,skills:[],mcps:[],refFiles:[],gitRepos:[]}),[b,m]=s.useState(new Set),[j,R]=s.useState(new Set),[G,U]=s.useState(new Set),[v,H]=s.useState(new Set),[N,z]=s.useState(!1),[q,S]=s.useState(""),[E,O]=s.useState({files:[],truncated:!1}),[se,re]=s.useState(!1),[J,le]=s.useState(new Set),[me,ge]=s.useState(""),[De,we]=s.useState(!1),[Me,Ue]=s.useState(null),[ie,Se]=s.useState(null),[We,Be]=s.useState(""),[ve,Ie]=s.useState(!1),Le=s.useRef(null),qe=s.useRef(null),ke=t.filter(V=>V.fullPath);s.useEffect(()=>{if(i){Je(i),$e(i);const V=ke.find($=>$.name===i);if(V){const $=V.fullPath.split("/").filter(Boolean).pop()||"";f($),g(V.displayName||V.name)}else if(n?.projectPath){const $=n.projectPath.split("/").filter(Boolean).pop()||"";f($)}}else O({files:[],truncated:!1}),le(new Set),ge(""),we(!1)},[i]),s.useEffect(()=>{n?.projectKey&&(d(n.projectKey),qe.current={displayName:n.displayName||"",description:n.description||"",updateNotes:n.updateNotes||"",skills:n.skills||[],mcps:n.mcps||[],files:n.files||[],gitRepos:n.gitRepos||[]})},[n]),s.useEffect(()=>{if(Le.current&&clearTimeout(Le.current),!u||!/^[a-zA-Z0-9_-]{1,100}$/.test(u)){Ue(null),Se(null),Ie(!1);return}return Ie(!0),Le.current=setTimeout(async()=>{try{const V=await Y(`/api/agents/check-name/${encodeURIComponent(u)}`);if(V.ok){const $=await V.json();Ue($.existing),Se($.pendingConflict);const w=qe.current;w?($.existing?(x||g($.existing.display_name||""),w.updateNotes&&Be(w.updateNotes),!h&&$.existing.description&&y($.existing.description)):(w.displayName&&!x&&g(w.displayName),w.description&&!h&&y(w.description)),qe.current=null):$.existing&&!h&&y($.existing.description||"")}}catch{Ue(null),Se(null)}finally{Ie(!1)}},400),()=>{Le.current&&clearTimeout(Le.current)}},[u]);const Je=async V=>{if(V)try{const $=await Y(`/api/agents/preview?projectKey=${encodeURIComponent(V)}`);if($.ok){const w=await $.json();p(w);const ee=qe.current;ee?(ee.skills?.length>0?m(new Set(ee.skills)):m(new Set((w.skills||[]).map(A=>A.name))),ee.mcps?.length>0?R(new Set(ee.mcps)):R(new Set((w.mcps||[]).map(A=>A.name))),U(new Set((w.refFiles||[]).filter(A=>A.exists).map(A=>A.path))),ee.gitRepos?.length>0?H(new Set(ee.gitRepos.map(A=>A.name))):H(new Set((w.gitRepos||[]).map(A=>A.name))),ee.files?.length>0&&(le(new Set(ee.files)),we(!0))):(m(new Set((w.skills||[]).map(A=>A.name))),R(new Set((w.mcps||[]).map(A=>A.name))),U(new Set((w.refFiles||[]).filter(A=>A.exists).map(A=>A.path))),H(new Set((w.gitRepos||[]).map(A=>A.name))))}}catch{p({hasClaudeMd:!1,skills:[],mcps:[],refFiles:[],gitRepos:[]}),m(new Set),R(new Set),U(new Set),H(new Set)}},$e=async V=>{re(!0),le(new Set),ge(""),we(!1);try{const $=await Y(`/api/agents/project-files?projectKey=${encodeURIComponent(V)}`);if($.ok){const w=await $.json();O(w)}else O({files:[],truncated:!1})}catch{O({files:[],truncated:!1})}finally{re(!1)}},Pe=V=>V<1024?`${V} B`:V<1024*1024?`${(V/1024).toFixed(1)} KB`:`${(V/(1024*1024)).toFixed(1)} MB`,_e=s.useMemo(()=>{const V=new Set((I.refFiles||[]).map(w=>w.path));let $=(E.files||[]).filter(w=>!V.has(w.path));if(me.trim()){const w=me.toLowerCase();$=$.filter(ee=>ee.path.toLowerCase().includes(w))}return $},[E.files,I.refFiles,me]),ze=async()=>{if(i){L(!0);try{const V=await Y("/api/agents/generate-description",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectKey:i,skills:[...b],mcps:[...j]})}),$=await V.json();V.ok?y($.description||""):l($.error||"生成失败",{variant:"error"})}catch(V){l(V.message,{variant:"error"})}finally{L(!1)}}},Ae=V=>/^[a-zA-Z0-9_-]{1,100}$/.test(V)?(S(""),!0):(S("只能包含字母、数字、连字符和下划线,1-100 字符"),!1),Ye=async()=>{if(!i){l("请选择一个项目",{variant:"warning"});return}if(!Ae(u))return;if(!x.trim()){l("请填写显示名称",{variant:"warning"});return}if(!(!ke.find($=>$.name===i)&&!n)){z(!0);try{const $=new Date().toISOString(),w=(I.skills||[]).filter(pe=>b.has(pe.name)),ee=(I.mcps||[]).filter(pe=>j.has(pe.name)),A=(I.gitRepos||[]).filter(pe=>v.has(pe.name)),te=w.map(pe=>` - name: "${pe.name}"
2
+ repo: "${pe.localPath||pe.repo||""}"`).join(`
3
+ `),K=ee.map(pe=>` - name: "${pe.name}"
4
+ repo: "${pe.repo||""}"`).join(`
5
+ `),oe=A.map(pe=>` - name: "${pe.name}"
6
+ repo: "${pe.repo}"
7
+ branch: "${pe.branch}"`).join(`
8
+ `),ce=[...new Set([...G,...J])],Re=[" - CLAUDE.md",...ce.map(pe=>` - ${pe}`)].join(`
9
+ `),ae=[`name: "${u}"`,`display_name: "${x}"`,"description: |",h.split(`
10
+ `).map(pe=>` ${pe}`).join(`
11
+ `)||" (no description)",'version: "1.0.0"',`created_at: "${$}"`,`updated_at: "${$}"`,w.length>0?`skills:
12
+ ${te}`:"skills: []",ee.length>0?`mcps:
13
+ ${K}`:"mcps: []",A.length>0?`git_repos:
14
+ ${oe}`:"git_repos: []",`files:
15
+ ${Re}`].join(`
16
+ `),Te=await Y("/api/agents/submit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentName:u,displayName:x,description:h,projectKey:i,agentYaml:ae,refFiles:ce,...Me?{updateNotes:We||void 0}:{}})}),Ee=await Te.json();Te.ok?(await l((Oe?"更新已提交!本次更新将在管理员审核通过后公开生效。":"分享成功!项目将在管理员审核通过后公开可见。")+`
17
+
18
+ 审核结果请在 设置 → 共享项目模板 → 我的提交记录 中查看。`,{title:Oe?"更新已提交":"提交成功",variant:"info"}),a?.({submissionId:Ee.submissionId,message:Ee.message})):l(Ee.error||"提交失败",{variant:"error"})}catch($){l($.message,{variant:"error"})}finally{z(!1)}}},Oe=!!Me;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl shadow-2xl w-full max-w-lg mx-4 flex flex-col max-h-[90vh]",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pt,{className:"w-5 h-5 text-blue-500"}),e.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:Oe?"更新项目模板":"分享项目模板"})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-4 space-y-4 overflow-y-auto flex-1",children:[n&&!n.isExistingProject?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"项目路径"}),e.jsx("div",{className:"w-full border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 text-sm bg-gray-50 dark:bg-gray-800 text-gray-600 dark:text-gray-400",children:He(n.projectPath)})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"选择项目"}),e.jsxs("select",{value:i,onChange:V=>d(V.target.value),className:"w-full border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"-- 选择项目 --"}),ke.map(V=>e.jsx("option",{value:V.name,children:V.displayName||V.name},V.name))]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:["项目标识名 ",e.jsx("span",{className:"text-gray-400 text-xs",children:"(英文,用于目录名)"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(it,{value:u,readOnly:!0,placeholder:"e.g. my-agent",className:"text-sm bg-gray-50 dark:bg-gray-800/50 cursor-default"}),ve&&e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2",children:e.jsx(Dt,{className:"w-4 h-4 text-gray-400 animate-spin"})})]}),q&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:q})]}),ve&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700",children:[e.jsx(Dt,{className:"w-3.5 h-3.5 text-gray-400 animate-spin flex-shrink-0"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"正在检查项目信息..."})]}),!ve&&Oe&&e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-lg bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-700",children:[e.jsx(Vs,{className:"w-4 h-4 text-blue-500 flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:[e.jsx("span",{className:"font-medium",children:"更新模式"}),":仓库中已存在项目「",Me.display_name,"」,当前版本 v",Me.version,"。提交将作为版本更新处理。"]})]}),!ve&&ie&&e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700",children:[e.jsx(Ot,{className:"w-4 h-4 text-amber-500 flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:["用户 ",ie.username," 已在 ",new Date(ie.submitted_at).toLocaleString("zh-CN",{dateStyle:"short",timeStyle:"short"})," 提交了同名项目的审核,建议更换标识名以避免冲突。"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"显示名称"}),e.jsx(it,{value:x,onChange:V=>g(V.target.value),placeholder:"My Project",className:"text-sm",disabled:ve})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"描述"}),e.jsxs("button",{type:"button",onClick:ze,disabled:!i||k||ve,className:"flex items-center gap-1 text-xs text-blue-500 hover:text-blue-600 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[e.jsx(vr,{className:"w-3 h-3"}),k?"AI 生成中...":"AI 生成"]})]}),e.jsx("textarea",{value:h,onChange:V=>y(V.target.value),placeholder:"描述这个项目的用途和功能...",rows:3,disabled:ve,className:"w-full border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none disabled:opacity-50 disabled:cursor-not-allowed"})]}),Oe&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:["更新说明 ",e.jsx("span",{className:"text-gray-400 text-xs",children:"(描述本次更新的内容)"})]}),e.jsx("textarea",{value:We,onChange:V=>Be(V.target.value),placeholder:"例如:修复了 XXX 问题,新增了 YYY 功能...",rows:2,className:"w-full border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none"})]}),i&&e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-3 bg-gray-50 dark:bg-gray-800/50",children:[e.jsx("p",{className:"text-xs font-medium text-gray-600 dark:text-gray-400 mb-2",children:"将包含的内容"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-700 dark:text-gray-300",children:[e.jsx(is,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"}),e.jsxs("span",{children:["agent.yaml ",e.jsx("span",{className:"text-gray-400",children:"(自动生成)"})]})]}),e.jsxs("div",{className:`flex items-center gap-2 text-xs ${I.hasClaudeMd?"text-gray-700 dark:text-gray-300":"text-gray-400 dark:text-gray-600"}`,children:[e.jsx(is,{className:`w-3.5 h-3.5 flex-shrink-0 ${I.hasClaudeMd?"text-green-500":"text-gray-300"}`}),e.jsxs("span",{children:["CLAUDE.md ",!I.hasClaudeMd&&e.jsx("span",{className:"text-amber-500",children:"(未找到)"})]})]}),I.skills?.length>0&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("p",{className:"text-[11px] text-gray-400 dark:text-gray-500 mb-1.5",children:["Skills ",e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"(勾选需要包含的)"})]}),I.skills.map(V=>e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-700 dark:text-gray-300 cursor-pointer py-0.5 hover:text-gray-900 dark:hover:text-gray-100",children:[e.jsx("input",{type:"checkbox",checked:b.has(V.name),onChange:$=>{const w=new Set(b);$.target.checked?w.add(V.name):w.delete(V.name),m(w)},className:"rounded text-purple-500 focus:ring-purple-400 focus:ring-offset-0"}),e.jsx(Ar,{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0"}),e.jsx("span",{children:V.name})]},V.name))]}),I.mcps?.length>0&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("p",{className:"text-[11px] text-gray-400 dark:text-gray-500 mb-1.5",children:["MCP 服务 ",e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"(勾选需要包含的)"})]}),I.mcps.map(V=>e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-700 dark:text-gray-300 cursor-pointer py-0.5 hover:text-gray-900 dark:hover:text-gray-100",children:[e.jsx("input",{type:"checkbox",checked:j.has(V.name),onChange:$=>{const w=new Set(j);$.target.checked?w.add(V.name):w.delete(V.name),R(w)},className:"rounded text-orange-500 focus:ring-orange-400 focus:ring-offset-0"}),e.jsx(Ys,{className:"w-3.5 h-3.5 text-orange-500 flex-shrink-0"}),e.jsx("span",{children:V.name})]},V.name))]}),I.gitRepos?.length>0&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("p",{className:"text-[11px] text-gray-400 dark:text-gray-500 mb-1.5",children:["Git 仓库依赖 ",e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"(勾选需要包含的子目录 git 仓库)"})]}),I.gitRepos.map(V=>e.jsxs("label",{className:"flex items-start gap-2 text-xs text-gray-700 dark:text-gray-300 cursor-pointer py-0.5 hover:text-gray-900 dark:hover:text-gray-100",children:[e.jsx("input",{type:"checkbox",checked:v.has(V.name),onChange:$=>{const w=new Set(v);$.target.checked?w.add(V.name):w.delete(V.name),H(w)},className:"rounded text-emerald-500 focus:ring-emerald-400 focus:ring-offset-0 mt-0.5"}),e.jsx(Qs,{className:"w-3.5 h-3.5 text-emerald-500 flex-shrink-0 mt-0.5"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"font-medium",children:V.name}),e.jsxs("span",{className:"text-gray-400 dark:text-gray-500 text-[10px] block truncate",children:[V.repo," (",V.branch,")"]})]})]},V.name))]}),I.refFiles?.length>0&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("p",{className:"text-[11px] text-gray-400 dark:text-gray-500 mb-1.5",children:["CLAUDE.md 引用文件 ",e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"(勾选需要包含的)"})]}),I.refFiles.map(V=>e.jsxs("label",{className:`flex items-center gap-2 text-xs cursor-pointer py-0.5 ${V.exists?"text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100":"text-gray-400 dark:text-gray-600"}`,children:[e.jsx("input",{type:"checkbox",checked:G.has(V.path),disabled:!V.exists,onChange:$=>{const w=new Set(G);$.target.checked?w.add(V.path):w.delete(V.path),U(w)},className:"rounded text-blue-500 focus:ring-blue-400 focus:ring-offset-0 disabled:opacity-40"}),e.jsx(is,{className:`w-3.5 h-3.5 flex-shrink-0 ${V.exists?"text-blue-400":"text-gray-300"}`}),e.jsx("span",{className:"truncate",children:V.path}),!V.exists&&e.jsx("span",{className:"text-amber-500 flex-shrink-0",children:"(未找到)"})]},V.path))]}),e.jsxs("div",{className:"mt-2 pt-2 border-t border-gray-200 dark:border-gray-700",children:[e.jsxs("button",{type:"button",onClick:()=>we(!De),className:"flex items-center justify-between w-full text-[11px] text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[De?e.jsx(Qt,{className:"w-3 h-3"}):e.jsx(zs,{className:"w-3 h-3"}),"项目文件 ",e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"(手动选择需要包含的)"})]}),J.size>0&&e.jsxs("span",{className:"text-[10px] bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400 px-1.5 py-0.5 rounded-full",children:["已选 ",J.size]})]}),De&&e.jsxs("div",{className:"mt-1.5 space-y-1.5",children:[e.jsxs("div",{className:"relative",children:[e.jsx(St,{className:"w-3 h-3 text-gray-400 absolute left-2 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"text",value:me,onChange:V=>ge(V.target.value),placeholder:"搜索文件名...",className:"w-full pl-6 pr-2 py-1 text-[11px] border border-gray-200 dark:border-gray-700 rounded bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-300 focus:outline-none focus:ring-1 focus:ring-blue-500"})]}),se?e.jsx("div",{className:"flex items-center justify-center py-3",children:e.jsx(Dt,{className:"w-3.5 h-3.5 text-gray-400 animate-spin"})}):_e.length===0?e.jsx("p",{className:"text-[11px] text-gray-400 text-center py-2",children:"无匹配文件"}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400 cursor-pointer py-0.5 border-b border-gray-100 dark:border-gray-700 mb-0.5",children:[e.jsx("input",{type:"checkbox",checked:_e.length>0&&_e.every(V=>J.has(V.path)),onChange:V=>{const $=new Set(J);V.target.checked?_e.forEach(w=>$.add(w.path)):_e.forEach(w=>$.delete(w.path)),le($)},className:"rounded text-teal-500 focus:ring-teal-400 focus:ring-offset-0"}),e.jsxs("span",{children:["全选(",_e.length," 个文件)"]})]}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-0.5",children:_e.map(V=>e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-700 dark:text-gray-300 cursor-pointer py-0.5 hover:text-gray-900 dark:hover:text-gray-100",children:[e.jsx("input",{type:"checkbox",checked:J.has(V.path),onChange:$=>{const w=new Set(J);$.target.checked?w.add(V.path):w.delete(V.path),le(w)},className:"rounded text-teal-500 focus:ring-teal-400 focus:ring-offset-0"}),e.jsx(is,{className:"w-3.5 h-3.5 text-teal-400 flex-shrink-0"}),e.jsx("span",{className:"truncate flex-1 min-w-0",children:V.path}),e.jsx("span",{className:"text-[10px] text-gray-400 flex-shrink-0",children:Pe(V.size)})]},V.path))})]}),E.truncated&&e.jsx("p",{className:"text-[10px] text-amber-500",children:"项目文件较多,仅显示前 500 个。请使用搜索缩小范围。"})]})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700",children:[e.jsx(B,{variant:"outline",size:"sm",onClick:r,disabled:N,children:"取消"}),e.jsx(B,{size:"sm",onClick:Ye,disabled:N||!i||ve,className:"flex items-center gap-1.5",children:N?e.jsx("span",{children:"提交中..."}):e.jsxs(e.Fragment,{children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),Oe?"更新":"分享"]})})]})]})})}const xa=(t,r)=>{const a=new Date(t),o=r;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)),u=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`:u===1?"1 day ago":u<7?`${u} days ago`:a.toLocaleDateString()};function ha({projects:t,selectedProject:r,selectedSession:a,onProjectSelect:o,onSessionSelect:n,onNewSession:l,onSessionDelete:i,onProjectDelete:d,isLoading:u,onRefresh:f,onShowSettings:x,onShowAdmin:g,isPWA:h,isMobile:y,onToggleSidebar:k}){const{showAlert:L,showConfirm:I}=dt(),{user:p,isAdmin:b,hasPermission:m}=Ct(),[j,R]=s.useState(new Set),[G,U]=s.useState(null),[v,H]=s.useState(!1),[N,z]=s.useState(!1),[q,S]=s.useState(""),[E,O]=s.useState({}),[se,re]=s.useState({}),[J,le]=s.useState(new Set),[me,ge]=s.useState(new Date),[De,we]=s.useState("name"),[Me,Ue]=s.useState(!1),[ie,Se]=s.useState(null),[We,Be]=s.useState(""),[ve,Ie]=s.useState({}),[Le,qe]=s.useState({}),[ke,Je]=s.useState(""),[$e,Pe]=s.useState(!1),[_e,ze]=s.useState(""),[Ae,Ye]=s.useState(()=>{try{const D=localStorage.getItem("starredProjects");return D?new Set(JSON.parse(D)):new Set}catch(D){return console.error("Error loading starred projects:",D),new Set}}),Oe=D=>ue=>{ue.target.closest(".overflow-y-auto")||ue.target.closest("[data-scroll-container]")||(ue.preventDefault(),ue.stopPropagation(),D())};s.useEffect(()=>{const D=setInterval(()=>{ge(new Date)},6e4);return()=>clearInterval(D)},[]),s.useEffect(()=>{re({}),le(new Set)},[t]),s.useEffect(()=>{a&&r&&R(D=>new Set([...D,r.name]))},[a,r]),s.useEffect(()=>{if(t.length>0&&!u){const D=new Set;t.forEach(ue=>{ue.sessions&&ue.sessions.length>=0&&D.add(ue.name)}),le(D)}},[t,u]),s.useEffect(()=>{const D=()=>{try{const ne=localStorage.getItem("claude-settings");if(ne){const W=JSON.parse(ne);we(W.projectSortOrder||"name")}}catch(ne){console.error("Error loading sort order:",ne)}};D();const ue=ne=>{ne.key==="claude-settings"&&D()};window.addEventListener("storage",ue);const M=setInterval(()=>{document.hasFocus()&&D()},1e3);return()=>{window.removeEventListener("storage",ue),clearInterval(M)}},[]);const V=D=>{const ue=new Set;j.has(D)||ue.add(D),R(ue)},$=(D,ue)=>{n({...D,__projectName:ue})},w=D=>{const ue=new Set(Ae);ue.has(D)?ue.delete(D):ue.add(D),Ye(ue);try{localStorage.setItem("starredProjects",JSON.stringify([...ue]))}catch(M){console.error("Error saving starred projects:",M)}},ee=D=>Ae.has(D),A=D=>[...D.sessions||[],...se[D.name]||[]].map(M=>({...M,__provider:"claude"})).sort((M,ne)=>new Date(ne.lastActivity)-new Date(M.lastActivity)),te=D=>{const ue=A(D);return ue.length===0?D.lastActivity?new Date(D.lastActivity):D.createdAt?new Date(D.createdAt):new Date(0):ue.reduce((ne,W)=>{const Ne=new Date(W.lastActivity);return Ne>ne?Ne:ne},new Date(0))},K=[...t].sort((D,ue)=>{const M=ee(D.name),ne=ee(ue.name);if(M&&!ne)return-1;if(!M&&ne)return 1;if(De==="date")return te(ue)-te(D);{const W=D.displayName||D.name,Ne=ue.displayName||ue.name;return W.localeCompare(Ne)}}),oe=D=>{U(D.name),S(D.displayName)},ce=()=>{U(null),S("")},Re=async D=>{try{(await he.renameProject(D,q)).ok?window.refreshProjects?window.refreshProjects():window.location.reload():console.error("Failed to rename project")}catch(ue){console.error("Error renaming project:",ue)}U(null),S("")},ae=async(D,ue,M="claude")=>{if(await I("确定要删除此会话吗?此操作不可撤销。",{title:"删除会话",variant:"danger",confirmText:"确认删除"}))try{console.log("[Sidebar] Deleting session:",{projectName:D,sessionId:ue,provider:M});const W=await he.deleteSession(D,ue);if(console.log("[Sidebar] Delete response:",{ok:W.ok,status:W.status}),W.ok)console.log("[Sidebar] Session deleted successfully, calling callback"),i?i(ue):console.warn("[Sidebar] No onSessionDelete callback provided");else{const Ne=await W.text();console.error("[Sidebar] Failed to delete session:",{status:W.status,error:Ne}),L("删除会话失败,请重试。",{variant:"error"})}}catch(W){console.error("[Sidebar] Error deleting session:",W),L("删除会话出错,请重试。",{variant:"error"})}},Te=async(D,ue,M)=>{if(!M||!M.trim()){Se(null),Be("");return}const ne=M.trim();Ie(W=>({...W,[ue]:ne})),Se(null),Be("");try{(await he.renameSession(D,ue,ne)).ok||(Ie(Ne=>{const nt={...Ne};return delete nt[ue],nt}),L("重命名会话失败,请重试。",{variant:"error"}))}catch(W){console.error("[Sidebar] Error renaming session:",W),Ie(Ne=>{const nt={...Ne};return delete nt[ue],nt}),L("重命名会话出错,请重试。",{variant:"error"})}},Ee=async(D,ue)=>{if(await I(`确定要删除项目 "${ue||D}" 吗?`,{title:"删除项目",subtitle:"此操作不可撤销",detail:"将同时删除:所有会话记录(JSONL 文件)和项目文件夹及其所有内容。",variant:"danger",confirmText:"确认删除"}))try{const ne=await he.deleteProject(D,!0);if(ne.ok)d&&d(D);else{const W=await ne.json();console.error("Failed to delete project"),L(W.error||"删除项目失败,请重试。",{variant:"error"})}}catch(ne){console.error("Error deleting project:",ne),L("删除项目出错,请重试。",{variant:"error"})}},pe=async D=>{if(!(!(D.sessionMeta?.hasMore!==!1)||E[D.name])){O(M=>({...M,[D.name]:!0}));try{const M=(D.sessions?.length||0)+(se[D.name]?.length||0),ne=await he.sessions(D.name,5,M);if(ne.ok){const W=await ne.json();re(Ne=>({...Ne,[D.name]:[...Ne[D.name]||[],...W.sessions]})),W.hasMore===!1&&(D.sessionMeta={...D.sessionMeta,hasMore:!1})}}catch(M){console.error("Error loading more sessions:",M)}finally{O(M=>({...M,[D.name]:!1}))}}},tt=K.filter(D=>{if(!ke.trim())return!0;const ue=ke.toLowerCase(),M=(D.displayName||D.name).toLowerCase(),ne=D.name.toLowerCase();return M.includes(ue)||ne.includes(ue)}),Fe=D=>{o(D)};return e.jsxs(e.Fragment,{children:[v&&_s.createPortal(e.jsx(Zo,{onClose:()=>H(!1),onProjectCreated:D=>{window.refreshProjects?window.refreshProjects():window.location.reload()}}),document.body),N&&_s.createPortal(e.jsx(ei,{projects:t,onClose:()=>z(!1)}),document.body),$e&&_s.createPortal(e.jsx(Ur,{projects:t,initialProjectKey:_e,onClose:()=>Pe(!1),onSubmitted:()=>Pe(!1)}),document.body),e.jsxs("div",{className:"h-full flex flex-col bg-card md:select-none",style:h&&y?{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:Ze}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("h1",{className:"text-lg font-bold text-foreground",children:Ze}),e.jsxs("span",{className:"text-xs text-muted-foreground/60",children:["v",Go.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:Xa})]})]}),k&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200",onClick:k,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:h&&y?{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:Ze}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:Ze}),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()=>{Ue(!0);try{await f()}finally{Ue(!1)}},disabled:Me,children:e.jsx(ct,{className:`w-4 h-4 text-foreground ${Me?"animate-spin":""}`})}),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:()=>z(!0),children:e.jsx(Pt,{className:"w-4 h-4 text-foreground"})}),m("create_project")&&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:()=>H(!0),children:e.jsx(ks,{className:"w-4 h-4"})})]})]})})]}),!u&&!y&&e.jsx("div",{className:"px-3 md:px-4 py-2 border-b border-border",children:e.jsxs("div",{className:"flex gap-2",children:[m("create_project")&&e.jsxs(B,{variant:"default",size:"sm",className:"flex-1 h-8 text-xs bg-primary hover:bg-primary/90 transition-all duration-200",onClick:()=>H(!0),title:"新建项目",children:[e.jsx(ks,{className:"w-3.5 h-3.5 mr-1.5"}),"新建项目"]}),e.jsxs(B,{variant:"default",size:"sm",className:"flex-1 h-8 text-xs bg-primary hover:bg-primary/90 transition-all duration-200",onClick:()=>z(!0),title:"使用项目模板",children:[e.jsx(Pt,{className:"w-3.5 h-3.5 mr-1.5"}),"使用项目模板"]}),e.jsx(B,{variant:"outline",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200 group",onClick:async()=>{Ue(!0);try{await f()}finally{Ue(!1)}},disabled:Me,title:"刷新项目和会话 (Ctrl+R)",children:e.jsx(ct,{className:`w-3.5 h-3.5 ${Me?"animate-spin":""} group-hover:rotate-180 transition-transform duration-300`})})]})}),t.length>0&&!u&&e.jsx("div",{className:"px-3 md:px-4 py-2 border-b border-border",children:e.jsxs("div",{className:"relative",children:[e.jsx(St,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(it,{type:"text",placeholder:"搜索项目...",value:ke,onChange:D=>Je(D.target.value),className:"pl-9 h-9 text-sm bg-muted/50 border-0 focus:bg-background focus:ring-1 focus:ring-primary/20"}),ke&&e.jsx("button",{onClick:()=>Je(""),className:"absolute right-2 top-1/2 transform -translate-y-1/2 p-1 hover:bg-accent rounded",children:e.jsx(Ge,{className:"w-3 h-3 text-muted-foreground"})})]})}),e.jsx(Fr,{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:u?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(Xt,{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.jsxs("p",{className:"text-sm text-muted-foreground",children:["请先创建一个项目,开始与 ",Ze," 进行交流"]})]}):tt.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(St,{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:"尝试调整搜索条件"})]}):tt.map(D=>{const ue=j.has(D.name),M=r?.name===D.name,ne=ee(D.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:rt("p-3 mx-3 my-1 rounded-lg bg-card border border-border/50 active:scale-[0.98] transition-all duration-150",M&&"bg-primary/5 border-primary/20",ne&&!M&&"bg-yellow-50/50 dark:bg-yellow-900/5 border-yellow-200/30 dark:border-yellow-800/30"),onClick:()=>{V(D.name)},onTouchEnd:Oe(()=>V(D.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:rt("w-8 h-8 rounded-lg flex items-center justify-center transition-colors",ue?"bg-primary/10":"bg-muted"),children:ue?e.jsx(Ns,{className:"w-4 h-4 text-primary"}):e.jsx(Xt,{className:"w-4 h-4 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0 flex-1",children:G===D.name?e.jsx("input",{type:"text",value:q,onChange:W=>S(W.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:W=>W.stopPropagation(),onKeyDown:W=>{W.key==="Enter"&&Re(D.name),W.key==="Escape"&&ce()},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.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground truncate",children:D.displayName}),D.agentInfo?.isAgent&&e.jsx("span",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded-full bg-blue-100 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400 font-medium leading-none",children:"Agent"})]})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(()=>{const W=A(D).length;return`${D.sessionMeta?.hasMore!==!1&&W>=5?`${W}+`:W} 会话`})()})]})})]}),e.jsx("div",{className:"flex items-center gap-1",children:G===D.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:W=>{W.stopPropagation(),Re(D.name)},children:e.jsx(ws,{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:W=>{W.stopPropagation(),ce()},children:e.jsx(Ge,{className:"w-4 h-4 text-white"})})]}):e.jsxs(e.Fragment,{children:[m("submit_agent")&&e.jsx("button",{className:"w-8 h-8 rounded-lg bg-blue-500/10 dark:bg-blue-900/30 flex items-center justify-center active:scale-90 transition-all duration-150 border border-blue-200 dark:border-blue-800",onClick:W=>{W.stopPropagation(),ze(D.name),Pe(!0)},onTouchEnd:Oe(()=>{ze(D.name),Pe(!0)}),title:"共享项目模板",children:e.jsx(zt,{className:"w-4 h-4 text-blue-500"})}),e.jsx("button",{className:rt("w-8 h-8 rounded-lg flex items-center justify-center active:scale-90 transition-all duration-150 border",ne?"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:W=>{W.stopPropagation(),w(D.name)},onTouchEnd:Oe(()=>w(D.name)),title:ne?"从收藏中移除":"添加到收藏",children:e.jsx(ca,{className:rt("w-4 h-4 transition-colors",ne?"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:W=>{W.stopPropagation(),Ee(D.name,D.displayName)},onTouchEnd:Oe(()=>Ee(D.name,D.displayName)),children:e.jsx(bt,{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:W=>{W.stopPropagation(),oe(D)},onTouchEnd:Oe(()=>oe(D)),children:e.jsx(jr,{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:ue?e.jsx(Qt,{className:"w-3 h-3 text-muted-foreground"}):e.jsx(zs,{className:"w-3 h-3 text-muted-foreground"})})]})})]})})}),e.jsxs(B,{variant:"ghost",className:rt("hidden md:flex w-full justify-between p-2 h-auto font-normal hover:bg-accent/50",M&&"bg-accent text-accent-foreground",ne&&!M&&"bg-yellow-50/50 dark:bg-yellow-900/10 hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20"),onClick:()=>{r?.name!==D.name&&Fe(D),V(D.name)},onTouchEnd:Oe(()=>{r?.name!==D.name&&Fe(D),V(D.name)}),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[ue?e.jsx(Ns,{className:"w-4 h-4 text-primary flex-shrink-0"}):e.jsx(Xt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"min-w-0 flex-1 text-left",children:G===D.name?e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{type:"text",value:q,onChange:W=>S(W.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:W=>{W.key==="Enter"&&Re(D.name),W.key==="Escape"&&ce()}}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",title:He(D.fullPath),children:He(D.fullPath)})]}):e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold truncate text-foreground",title:D.displayName,children:D.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[(()=>{const W=A(D).length;return D.sessionMeta?.hasMore!==!1&&W>=5?`${W}+`:W})(),D.fullPath!==D.displayName&&e.jsxs("span",{className:"ml-1 opacity-60",title:He(D.fullPath),children:["• ",(()=>{const W=He(D.fullPath);return W.length>25?"..."+W.slice(-22):W})()]})]})]})})]}),e.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:G===D.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:W=>{W.stopPropagation(),Re(D.name)},children:e.jsx(ws,{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:W=>{W.stopPropagation(),ce()},children:e.jsx(Ge,{className:"w-3 h-3"})})]}):e.jsxs(e.Fragment,{children:[m("submit_agent")&&e.jsx("div",{className:"w-6 h-6 opacity-0 group-hover:opacity-100 transition-all duration-200 hover:bg-blue-50 dark:hover:bg-blue-900/20 flex items-center justify-center rounded cursor-pointer touch:opacity-100",onClick:W=>{W.stopPropagation(),ze(D.name),Pe(!0)},title:"共享项目模板",children:e.jsx(zt,{className:"w-3 h-3 text-blue-500"})}),e.jsx("div",{className:rt("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",ne?"hover:bg-yellow-50 dark:hover:bg-yellow-900/20 opacity-100":"hover:bg-accent"),onClick:W=>{W.stopPropagation(),w(D.name)},title:ne?"从收藏中移除":"添加到收藏",children:e.jsx(ca,{className:rt("w-3 h-3 transition-colors",ne?"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:W=>{W.stopPropagation(),oe(D)},title:"重命名项目 (F2)",children:e.jsx(jr,{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:W=>{W.stopPropagation(),Ee(D.name,D.displayName)},title:"删除项目",children:e.jsx(bt,{className:"w-3 h-3 text-red-600 dark:text-red-400"})}),ue?e.jsx(Qt,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"}):e.jsx(zs,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"})]})})]})]}),ue&&e.jsxs("div",{className:"ml-3 space-y-1 border-l border-border pl-3",children:[J.has(D.name)?A(D).length===0&&!E[D.name]?e.jsx("div",{className:"py-2 px-3 text-left",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"还没有会话"})}):A(D).map(W=>{const Ne=new Date(W.lastActivity),Xe=Math.floor((me-Ne)/(1e3*60))<10,ot=ve[W.id]||W.summary||"新会话",pt=W.lastActivity,lt=W.messageCount||0;return e.jsxs("div",{className:"group relative",children:[Xe&&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:rt("p-2 mx-3 my-0.5 rounded-md bg-card border active:scale-[0.98] transition-all duration-150 relative",a?.id===W.id?"bg-primary/5 border-primary/20":Xe?"border-green-500/30 bg-green-50/5 dark:bg-green-900/5":"border-border/30"),onClick:()=>{Fe(D),$(W,D.name)},onTouchEnd:Oe(()=>{Fe(D),$(W,D.name)}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-medium truncate text-foreground",children:ot}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Os,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:xa(pt,me)}),lt>0&&e.jsx(et,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:lt})]})]}),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:st=>{st.stopPropagation(),ae(D.name,W.id)},onTouchEnd:Oe(()=>ae(D.name,W.id)),children:e.jsx(bt,{className:"w-2.5 h-2.5 text-red-600 dark:text-red-400"})})]})})}),e.jsxs("div",{className:"hidden md:block",children:[e.jsx(B,{variant:"ghost",className:rt("w-full justify-start p-2 h-auto font-normal text-left hover:bg-accent/50 transition-colors duration-200",a?.id===W.id&&"bg-accent text-accent-foreground"),onClick:()=>$(W,D.name),onTouchEnd:Oe(()=>$(W,D.name)),children:e.jsx("div",{className:"flex items-start gap-2 min-w-0 w-full",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-medium truncate text-foreground",children:ot}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(Os,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:xa(pt,me)}),lt>0&&e.jsx(et,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:lt})]})]})})}),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:ie===W.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:We,onChange:st=>Be(st.target.value),onKeyDown:st=>{st.stopPropagation(),st.key==="Enter"?Te(D.name,W.id,We):st.key==="Escape"&&(Se(null),Be(""))},onClick:st=>st.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:st=>{st.stopPropagation(),Te(D.name,W.id,We)},title:"Save",children:e.jsx(ws,{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:st=>{st.stopPropagation(),Se(null),Be("")},title:"Cancel",children:e.jsx(Ge,{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:st=>{st.stopPropagation(),Se(W.id),Be(ve[W.id]||W.summary||"新会话")},title:"手动编辑会话名称",children:e.jsx(lo,{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:st=>{st.stopPropagation(),ae(D.name,W.id)},title:"永久删除此会话",children:e.jsx(bt,{className:"w-3 h-3 text-red-600 dark:text-red-400"})})]})})]})]},W.id)}):Array.from({length:3}).map((W,Ne)=>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+Ne*15}%`}}),e.jsx("div",{className:"h-2 bg-muted rounded animate-pulse w-1/2"})]})]})},Ne)),A(D).length>0&&D.sessionMeta?.hasMore!==!1&&e.jsx(B,{variant:"ghost",size:"sm",className:"w-full justify-center gap-2 mt-2 text-muted-foreground",onClick:()=>pe(D),disabled:E[D.name],children:E[D.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(Qt,{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:()=>{Fe(D),l(D)},children:[e.jsx(Ft,{className:"w-3 h-3"}),"新会话"]})}),e.jsxs(B,{variant:"default",size:"sm",className:"hidden md:flex w-full justify-start gap-2 mt-1 h-8 text-xs font-medium bg-primary hover:bg-primary/90 text-primary-foreground transition-colors",onClick:()=>l(D),children:[e.jsx(Ft,{className:"w-3 h-3"}),"新会话"]})]})]},D.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:x,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx(Ut,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"设置"})]}),b&&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:g,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx(Wt,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"管理"})]})]}),e.jsxs(B,{variant:"ghost",className:"hidden md:flex w-full justify-start gap-2 p-2 h-auto font-normal text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-200",onClick:x,children:[e.jsx(Ut,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"设置"})]}),b&&e.jsxs(B,{variant:"ghost",className:"hidden md:flex w-full justify-start gap-2 p-2 h-auto font-normal text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-200",onClick:g,children:[e.jsx(Wt,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"管理"})]})]})]})]})}const ti={'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 ur={exports:{}},pr,ga;function si(){if(ga)return pr;ga=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return pr=t,pr}var xr,fa;function ri(){if(fa)return xr;fa=1;var t=si();function r(){}function a(){}return a.resetWarningCache=r,xr=function(){function o(i,d,u,f,x,g){if(g!==t){var h=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 h.name="Invariant Violation",h}}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:r};return l.PropTypes=l,l},xr}var ba;function ai(){return ba||(ba=1,ur.exports=ri()()),ur.exports}var ni=ai();const Ke=Pr(ni);function es(t,r,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(x){try{f(o.next(x))}catch(g){i(g)}}function u(x){try{f(o.throw(x))}catch(g){i(g)}}function f(x){x.done?l(x.value):n(x.value).then(d,u)}f((o=o.apply(t,r||[])).next())})}const oi=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 ls(t,r,a){const o=ii(t),{webkitRelativePath:n}=t,l=typeof r=="string"?r:typeof n=="string"&&n.length>0?n:`./${t.name}`;return typeof o.path!="string"&&ya(o,"path",l),ya(o,"relativePath",l),o}function ii(t){const{name:r}=t;if(r&&r.lastIndexOf(".")!==-1&&!t.type){const o=r.split(".").pop().toLowerCase(),n=oi.get(o);n&&Object.defineProperty(t,"type",{value:n,writable:!1,configurable:!1,enumerable:!0})}return t}function ya(t,r,a){Object.defineProperty(t,r,{value:a,writable:!1,configurable:!1,enumerable:!0})}const li=[".DS_Store","Thumbs.db"];function ci(t){return es(this,void 0,void 0,function*(){return Hs(t)&&di(t.dataTransfer)?xi(t.dataTransfer,t.type):mi(t)?ui(t):Array.isArray(t)&&t.every(r=>"getFile"in r&&typeof r.getFile=="function")?pi(t):[]})}function di(t){return Hs(t)}function mi(t){return Hs(t)&&Hs(t.target)}function Hs(t){return typeof t=="object"&&t!==null}function ui(t){return Sr(t.target.files).map(r=>ls(r))}function pi(t){return es(this,void 0,void 0,function*(){return(yield Promise.all(t.map(a=>a.getFile()))).map(a=>ls(a))})}function xi(t,r){return es(this,void 0,void 0,function*(){if(t.items){const a=Sr(t.items).filter(n=>n.kind==="file");if(r!=="drop")return a;const o=yield Promise.all(a.map(hi));return va(tn(o))}return va(Sr(t.files).map(a=>ls(a)))})}function va(t){return t.filter(r=>li.indexOf(r.name)===-1)}function Sr(t){if(t===null)return[];const r=[];for(let a=0;a<t.length;a++){const o=t[a];r.push(o)}return r}function hi(t){if(typeof t.webkitGetAsEntry!="function")return ja(t);const r=t.webkitGetAsEntry();return r&&r.isDirectory?sn(r):ja(t,r)}function tn(t){return t.reduce((r,a)=>[...r,...Array.isArray(a)?tn(a):[a]],[])}function ja(t,r){return es(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,ls(i)}}const o=t.getAsFile();if(!o)throw new Error(`${t} is not a File`);return ls(o,(a=r?.fullPath)!==null&&a!==void 0?a:void 0)})}function gi(t){return es(this,void 0,void 0,function*(){return t.isDirectory?sn(t):fi(t)})}function sn(t){const r=t.createReader();return new Promise((a,o)=>{const n=[];function l(){r.readEntries(i=>es(this,void 0,void 0,function*(){if(i.length){const d=Promise.all(i.map(gi));n.push(d),l()}else try{const d=yield Promise.all(n);a(d)}catch(d){o(d)}}),i=>{o(i)})}l()})}function fi(t){return es(this,void 0,void 0,function*(){return new Promise((r,a)=>{t.file(o=>{const n=ls(o,t.fullPath);r(n)},o=>{a(o)})})})}var Ps={},wa;function bi(){return wa||(wa=1,Ps.__esModule=!0,Ps.default=function(t,r){if(t&&r){var a=Array.isArray(r)?r:r.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}),Ps}var yi=bi();const hr=Pr(yi);function ka(t){return wi(t)||ji(t)||an(t)||vi()}function vi(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
19
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ji(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function wi(t){if(Array.isArray(t))return Cr(t)}function Na(t,r){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);r&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function Sa(t){for(var r=1;r<arguments.length;r++){var a=arguments[r]!=null?arguments[r]:{};r%2?Na(Object(a),!0).forEach(function(o){rn(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Na(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function rn(t,r,a){return r in t?Object.defineProperty(t,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[r]=a,t}function Ss(t,r){return Si(t)||Ni(t,r)||an(t,r)||ki()}function ki(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
20
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function an(t,r){if(t){if(typeof t=="string")return Cr(t,r);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 Cr(t,r)}}function Cr(t,r){(r==null||r>t.length)&&(r=t.length);for(var a=0,o=new Array(r);a<r;a++)o[a]=t[a];return o}function Ni(t,r){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),!(r&&o.length===r));n=!0);}catch(u){l=!0,d=u}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw d}}return o}}function Si(t){if(Array.isArray(t))return t}var Ci=typeof hr=="function"?hr:hr.default,Ei="file-invalid-type",Mi="file-too-large",Ii="file-too-small",Li="too-many-files",Ti=function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",a=r.split(","),o=a.length>1?"one of ".concat(a.join(", ")):a[0];return{code:Ei,message:"File type must be ".concat(o)}},Ca=function(r){return{code:Mi,message:"File is larger than ".concat(r," ").concat(r===1?"byte":"bytes")}},Ea=function(r){return{code:Ii,message:"File is smaller than ".concat(r," ").concat(r===1?"byte":"bytes")}},Ri={code:Li,message:"Too many files"};function nn(t,r){var a=t.type==="application/x-moz-file"||Ci(t,r);return[a,a?null:Ti(r)]}function on(t,r,a){if(Vt(t.size))if(Vt(r)&&Vt(a)){if(t.size>a)return[!1,Ca(a)];if(t.size<r)return[!1,Ea(r)]}else{if(Vt(r)&&t.size<r)return[!1,Ea(r)];if(Vt(a)&&t.size>a)return[!1,Ca(a)]}return[!0,null]}function Vt(t){return t!=null}function Di(t){var r=t.files,a=t.accept,o=t.minSize,n=t.maxSize,l=t.multiple,i=t.maxFiles,d=t.validator;return!l&&r.length>1||l&&i>=1&&r.length>i?!1:r.every(function(u){var f=nn(u,a),x=Ss(f,1),g=x[0],h=on(u,o,n),y=Ss(h,1),k=y[0],L=d?d(u):null;return g&&k&&!L})}function qs(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function As(t){return t.dataTransfer?Array.prototype.some.call(t.dataTransfer.types,function(r){return r==="Files"||r==="application/x-moz-file"}):!!t.target&&!!t.target.files}function Ma(t){t.preventDefault()}function Pi(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function Ai(t){return t.indexOf("Edge/")!==-1}function $i(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return Pi(t)||Ai(t)}function Mt(){for(var t=arguments.length,r=new Array(t),a=0;a<t;a++)r[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 r.some(function(d){return!qs(o)&&d&&d.apply(void 0,[o].concat(l)),qs(o)})}}function _i(){return"showOpenFilePicker"in window}function zi(t){if(Vt(t)){var r=Object.entries(t).filter(function(a){var o=Ss(a,2),n=o[0],l=o[1],i=!0;return ln(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(cn))&&(console.warn('Skipped "'.concat(n,'" because an invalid file extension was provided.')),i=!1),i}).reduce(function(a,o){var n=Ss(o,2),l=n[0],i=n[1];return Sa(Sa({},a),{},rn({},l,i))},{});return[{description:"Files",accept:r}]}return t}function Oi(t){if(Vt(t))return Object.entries(t).reduce(function(r,a){var o=Ss(a,2),n=o[0],l=o[1];return[].concat(ka(r),[n],ka(l))},[]).filter(function(r){return ln(r)||cn(r)}).join(",")}function Fi(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function Ui(t){return t instanceof DOMException&&(t.name==="SecurityError"||t.code===t.SECURITY_ERR)}function ln(t){return t==="audio/*"||t==="video/*"||t==="image/*"||t==="text/*"||t==="application/*"||/\w+\/[-+.\w]+/g.test(t)}function cn(t){return/^.*\.[\w]+$/.test(t)}var Wi=["children"],Bi=["open"],Hi=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],qi=["refKey","onChange","onClick"];function Ji(t){return Vi(t)||Gi(t)||dn(t)||Ki()}function Ki(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
21
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Gi(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Vi(t){if(Array.isArray(t))return Er(t)}function gr(t,r){return Xi(t)||Qi(t,r)||dn(t,r)||Yi()}function Yi(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
22
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function dn(t,r){if(t){if(typeof t=="string")return Er(t,r);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 Er(t,r)}}function Er(t,r){(r==null||r>t.length)&&(r=t.length);for(var a=0,o=new Array(r);a<r;a++)o[a]=t[a];return o}function Qi(t,r){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),!(r&&o.length===r));n=!0);}catch(u){l=!0,d=u}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw d}}return o}}function Xi(t){if(Array.isArray(t))return t}function Ia(t,r){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);r&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function Qe(t){for(var r=1;r<arguments.length;r++){var a=arguments[r]!=null?arguments[r]:{};r%2?Ia(Object(a),!0).forEach(function(o){Mr(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Ia(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function Mr(t,r,a){return r in t?Object.defineProperty(t,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[r]=a,t}function Js(t,r){if(t==null)return{};var a=Zi(t,r),o,n;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(n=0;n<l.length;n++)o=l[n],!(r.indexOf(o)>=0)&&Object.prototype.propertyIsEnumerable.call(t,o)&&(a[o]=t[o])}return a}function Zi(t,r){if(t==null)return{};var a={},o=Object.keys(t),n,l;for(l=0;l<o.length;l++)n=o[l],!(r.indexOf(n)>=0)&&(a[n]=t[n]);return a}var Wr=s.forwardRef(function(t,r){var a=t.children,o=Js(t,Wi),n=Br(o),l=n.open,i=Js(n,Bi);return s.useImperativeHandle(r,function(){return{open:l}},[l]),ut.createElement(s.Fragment,null,a(Qe(Qe({},i),{},{open:l})))});Wr.displayName="Dropzone";var mn={disabled:!1,getFilesFromEvent:ci,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};Wr.defaultProps=mn;Wr.propTypes={children:Ke.func,accept:Ke.objectOf(Ke.arrayOf(Ke.string)),multiple:Ke.bool,preventDropOnDocument:Ke.bool,noClick:Ke.bool,noKeyboard:Ke.bool,noDrag:Ke.bool,noDragEventsBubbling:Ke.bool,minSize:Ke.number,maxSize:Ke.number,maxFiles:Ke.number,disabled:Ke.bool,getFilesFromEvent:Ke.func,onFileDialogCancel:Ke.func,onFileDialogOpen:Ke.func,useFsAccessApi:Ke.bool,autoFocus:Ke.bool,onDragEnter:Ke.func,onDragLeave:Ke.func,onDragOver:Ke.func,onDrop:Ke.func,onDropAccepted:Ke.func,onDropRejected:Ke.func,onError:Ke.func,validator:Ke.func};var Ir={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function Br(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=Qe(Qe({},mn),t),a=r.accept,o=r.disabled,n=r.getFilesFromEvent,l=r.maxSize,i=r.minSize,d=r.multiple,u=r.maxFiles,f=r.onDragEnter,x=r.onDragLeave,g=r.onDragOver,h=r.onDrop,y=r.onDropAccepted,k=r.onDropRejected,L=r.onFileDialogCancel,I=r.onFileDialogOpen,p=r.useFsAccessApi,b=r.autoFocus,m=r.preventDropOnDocument,j=r.noClick,R=r.noKeyboard,G=r.noDrag,U=r.noDragEventsBubbling,v=r.onError,H=r.validator,N=s.useMemo(function(){return Oi(a)},[a]),z=s.useMemo(function(){return zi(a)},[a]),q=s.useMemo(function(){return typeof I=="function"?I:La},[I]),S=s.useMemo(function(){return typeof L=="function"?L:La},[L]),E=s.useRef(null),O=s.useRef(null),se=s.useReducer(el,Ir),re=gr(se,2),J=re[0],le=re[1],me=J.isFocused,ge=J.isFileDialogActive,De=s.useRef(typeof window<"u"&&window.isSecureContext&&p&&_i()),we=function(){!De.current&&ge&&setTimeout(function(){if(O.current){var w=O.current.files;w.length||(le({type:"closeDialog"}),S())}},300)};s.useEffect(function(){return window.addEventListener("focus",we,!1),function(){window.removeEventListener("focus",we,!1)}},[O,ge,S,De]);var Me=s.useRef([]),Ue=function(w){E.current&&E.current.contains(w.target)||(w.preventDefault(),Me.current=[])};s.useEffect(function(){return m&&(document.addEventListener("dragover",Ma,!1),document.addEventListener("drop",Ue,!1)),function(){m&&(document.removeEventListener("dragover",Ma),document.removeEventListener("drop",Ue))}},[E,m]),s.useEffect(function(){return!o&&b&&E.current&&E.current.focus(),function(){}},[E,b,o]);var ie=s.useCallback(function($){v?v($):console.error($)},[v]),Se=s.useCallback(function($){$.preventDefault(),$.persist(),Ae($),Me.current=[].concat(Ji(Me.current),[$.target]),As($)&&Promise.resolve(n($)).then(function(w){if(!(qs($)&&!U)){var ee=w.length,A=ee>0&&Di({files:w,accept:N,minSize:i,maxSize:l,multiple:d,maxFiles:u,validator:H}),te=ee>0&&!A;le({isDragAccept:A,isDragReject:te,isDragActive:!0,type:"setDraggedFiles"}),f&&f($)}}).catch(function(w){return ie(w)})},[n,f,ie,U,N,i,l,d,u,H]),We=s.useCallback(function($){$.preventDefault(),$.persist(),Ae($);var w=As($);if(w&&$.dataTransfer)try{$.dataTransfer.dropEffect="copy"}catch{}return w&&g&&g($),!1},[g,U]),Be=s.useCallback(function($){$.preventDefault(),$.persist(),Ae($);var w=Me.current.filter(function(A){return E.current&&E.current.contains(A)}),ee=w.indexOf($.target);ee!==-1&&w.splice(ee,1),Me.current=w,!(w.length>0)&&(le({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),As($)&&x&&x($))},[E,x,U]),ve=s.useCallback(function($,w){var ee=[],A=[];$.forEach(function(te){var K=nn(te,N),oe=gr(K,2),ce=oe[0],Re=oe[1],ae=on(te,i,l),Te=gr(ae,2),Ee=Te[0],pe=Te[1],tt=H?H(te):null;if(ce&&Ee&&!tt)ee.push(te);else{var Fe=[Re,pe];tt&&(Fe=Fe.concat(tt)),A.push({file:te,errors:Fe.filter(function(D){return D})})}}),(!d&&ee.length>1||d&&u>=1&&ee.length>u)&&(ee.forEach(function(te){A.push({file:te,errors:[Ri]})}),ee.splice(0)),le({acceptedFiles:ee,fileRejections:A,isDragReject:A.length>0,type:"setFiles"}),h&&h(ee,A,w),A.length>0&&k&&k(A,w),ee.length>0&&y&&y(ee,w)},[le,d,N,i,l,u,h,y,k,H]),Ie=s.useCallback(function($){$.preventDefault(),$.persist(),Ae($),Me.current=[],As($)&&Promise.resolve(n($)).then(function(w){qs($)&&!U||ve(w,$)}).catch(function(w){return ie(w)}),le({type:"reset"})},[n,ve,ie,U]),Le=s.useCallback(function(){if(De.current){le({type:"openDialog"}),q();var $={multiple:d,types:z};window.showOpenFilePicker($).then(function(w){return n(w)}).then(function(w){ve(w,null),le({type:"closeDialog"})}).catch(function(w){Fi(w)?(S(w),le({type:"closeDialog"})):Ui(w)?(De.current=!1,O.current?(O.current.value=null,O.current.click()):ie(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."))):ie(w)});return}O.current&&(le({type:"openDialog"}),q(),O.current.value=null,O.current.click())},[le,q,S,p,ve,ie,z,d]),qe=s.useCallback(function($){!E.current||!E.current.isEqualNode($.target)||($.key===" "||$.key==="Enter"||$.keyCode===32||$.keyCode===13)&&($.preventDefault(),Le())},[E,Le]),ke=s.useCallback(function(){le({type:"focus"})},[]),Je=s.useCallback(function(){le({type:"blur"})},[]),$e=s.useCallback(function(){j||($i()?setTimeout(Le,0):Le())},[j,Le]),Pe=function(w){return o?null:w},_e=function(w){return R?null:Pe(w)},ze=function(w){return G?null:Pe(w)},Ae=function(w){U&&w.stopPropagation()},Ye=s.useMemo(function(){return function(){var $=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},w=$.refKey,ee=w===void 0?"ref":w,A=$.role,te=$.onKeyDown,K=$.onFocus,oe=$.onBlur,ce=$.onClick,Re=$.onDragEnter,ae=$.onDragOver,Te=$.onDragLeave,Ee=$.onDrop,pe=Js($,Hi);return Qe(Qe(Mr({onKeyDown:_e(Mt(te,qe)),onFocus:_e(Mt(K,ke)),onBlur:_e(Mt(oe,Je)),onClick:Pe(Mt(ce,$e)),onDragEnter:ze(Mt(Re,Se)),onDragOver:ze(Mt(ae,We)),onDragLeave:ze(Mt(Te,Be)),onDrop:ze(Mt(Ee,Ie)),role:typeof A=="string"&&A!==""?A:"presentation"},ee,E),!o&&!R?{tabIndex:0}:{}),pe)}},[E,qe,ke,Je,$e,Se,We,Be,Ie,R,G,o]),Oe=s.useCallback(function($){$.stopPropagation()},[]),V=s.useMemo(function(){return function(){var $=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},w=$.refKey,ee=w===void 0?"ref":w,A=$.onChange,te=$.onClick,K=Js($,qi),oe=Mr({accept:N,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:Pe(Mt(A,Ie)),onClick:Pe(Mt(te,Oe)),tabIndex:-1},ee,O);return Qe(Qe({},oe),K)}},[O,a,d,Ie,o]);return Qe(Qe({},J),{},{isFocused:me&&!o,getRootProps:Ye,getInputProps:V,rootRef:E,inputRef:O,open:Pe(Le)})}function el(t,r){switch(r.type){case"focus":return Qe(Qe({},t),{},{isFocused:!0});case"blur":return Qe(Qe({},t),{},{isFocused:!1});case"openDialog":return Qe(Qe({},Ir),{},{isFileDialogActive:!0});case"closeDialog":return Qe(Qe({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Qe(Qe({},t),{},{isDragActive:r.isDragActive,isDragAccept:r.isDragAccept,isDragReject:r.isDragReject});case"setFiles":return Qe(Qe({},t),{},{acceptedFiles:r.acceptedFiles,fileRejections:r.fileRejections,isDragReject:r.isDragReject});case"reset":return Qe({},Ir);default:return t}}function La(){}const Ta=({todos:t,isResult:r=!1})=>{if(!t||!Array.isArray(t))return null;const a=n=>{switch(n){case"completed":return e.jsx("svg",{className:"w-3.5 h-3.5 text-green-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M5 13l4 4L19 7"})});case"in_progress":return e.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse flex-shrink-0 mt-0.5"});case"pending":default:return e.jsx("div",{className:"w-2 h-2 rounded-full border border-gray-300 dark:border-gray-600 flex-shrink-0 mt-0.5"})}},o=t.filter(n=>n.status==="completed").length;return e.jsxs("div",{className:"border border-gray-200/60 dark:border-gray-700/40 rounded-lg overflow-hidden my-1.5",children:[r&&e.jsxs("div",{className:"px-3 py-1.5 bg-gray-50 dark:bg-gray-800/60 border-b border-gray-200/60 dark:border-gray-700/40 flex items-center gap-2",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500",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.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["待办事项 · ",o,"/",t.length," 已完成"]})]}),e.jsx("div",{className:"divide-y divide-gray-100 dark:divide-gray-700/40",children:t.map((n,l)=>e.jsxs("div",{className:"flex items-start gap-2.5 px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-800/30 transition-colors",children:[e.jsx("div",{className:"mt-1",children:a(n.status)}),e.jsx("span",{className:`text-xs flex-1 leading-relaxed ${n.status==="completed"?"line-through text-gray-400 dark:text-gray-500":n.status==="in_progress"?"text-gray-700 dark:text-gray-300 font-medium":"text-gray-500 dark:text-gray-400"}`,children:n.content})]},n.id||`todo-${l}`))})]})},Ks=({className:t="w-5 h-5",size:r})=>{const a=r?{width:r,height:r}:void 0;return e.jsx("img",{src:"/logo.svg",alt:Ze,className:t,style:a})};function tl({status:t,onAbort:r,isLoading:a,provider:o="claude"}){const[n,l]=s.useState(0),[i,d]=s.useState(0),[u,f]=s.useState(0);if(s.useEffect(()=>{if(!a){l(0),f(0);return}const p=Date.now(),b=30+Math.random()*20,m=setInterval(()=>{const j=Math.floor((Date.now()-p)/1e3);l(j),f(Math.floor(j*b))},1e3);return()=>clearInterval(m)},[a]),s.useEffect(()=>{if(!a)return;const p=setInterval(()=>{d(b=>(b+1)%4)},500);return()=>clearInterval(p)},[a]),!a)return null;const x=["思考中","处理中","分析中","工作中","计算中","推理中"],g=Math.floor(n/3)%x.length,h=t?.text||x[g],y=t?.tokens||u,k=t?.can_interrupt!==!1,I=["✻","✹","✸","✶"][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:rt("text-base sm:text-xl transition-all duration-500 flex-shrink-0",i%2===0?"text-blue-400 scale-110":"text-blue-300"),children:I}),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:[h,"..."]}),e.jsxs("span",{className:"text-gray-400 text-xs sm:text-sm flex-shrink-0",children:["(",n,"s)"]}),y>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-500 hidden sm:inline",children:"·"}),e.jsxs("span",{className:"text-gray-300 text-xs sm:text-sm hidden sm:inline flex-shrink-0",children:["⚒ ",y.toLocaleString()]})]}),e.jsx("span",{className:"text-gray-500 hidden sm:inline",children:"·"}),e.jsx("span",{className:"text-gray-400 text-xs sm:text-sm hidden sm:inline",children:"按 esc 停止"})]})})]})}),k&&r&&e.jsxs("button",{onClick:r,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 sl(t,r){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 he.transcribe(a);if(!i.ok){const u=await i.json().catch(()=>({}));throw new Error(u.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 rl({onTranscript:t,className:r=""}){const[a,o]=s.useState("idle"),[n,l]=s.useState(null),[i,d]=s.useState(!0),u=s.useRef(null),f=s.useRef(null),x=s.useRef([]),g=s.useRef(0);s.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 h=async()=>{try{if(console.log("Starting recording..."),l(null),x.current=[],!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)throw new Error("Microphone access not available. Please use HTTPS or a supported browser.");const m=await navigator.mediaDevices.getUserMedia({audio:!0});f.current=m;const j=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",R=new MediaRecorder(m,{mimeType:j});u.current=R,R.ondataavailable=G=>{G.data.size>0&&x.current.push(G.data)},R.onstop=async()=>{console.log("Recording stopped, creating blob...");const G=new Blob(x.current,{type:j});f.current&&(f.current.getTracks().forEach(N=>N.stop()),f.current=null),o("transcribing");const U=window.localStorage.getItem("whisperMode")||"default",v=U==="prompt"||U==="vibe"||U==="instructions"||U==="architect";let H;v&&(H=setTimeout(()=>{o("processing")},2e3));try{const N=await sl(G);N&&t&&t(N)}catch(N){console.error("Transcription error:",N),l(N.message)}finally{H&&clearTimeout(H),o("idle")}},R.start(),o("recording"),console.log("Recording started successfully")}catch(m){console.error("Failed to start recording:",m);let j="Microphone access failed";m.name==="NotAllowedError"?j="Microphone access denied. Please allow microphone permissions.":m.name==="NotFoundError"?j="No microphone found. Please check your audio devices.":m.name==="NotSupportedError"?j="Microphone not supported by this browser.":m.name==="NotReadableError"?j="Microphone is being used by another application.":m.message.includes("HTTPS")&&(j=m.message),l(j),o("idle")}},y=()=>{console.log("Stopping recording..."),u.current&&u.current.state==="recording"?u.current.stop():(console.log("Recorder not in recording state, forcing cleanup"),f.current&&(f.current.getTracks().forEach(m=>m.stop()),f.current=null),o("idle"))},k=m=>{if(m&&(m.preventDefault(),m.stopPropagation()),!i)return;const j=Date.now();if(j-g.current<300){console.log("Ignoring rapid tap");return}g.current=j,console.log("Button clicked, current state:",a),a==="idle"?h():a==="recording"&&y()};s.useEffect(()=>()=>{f.current&&f.current.getTracks().forEach(m=>m.stop())},[]);const L=()=>{if(!i)return{icon:e.jsx(cr,{className:"w-5 h-5"}),className:"bg-gray-400 cursor-not-allowed",disabled:!0};switch(a){case"recording":return{icon:e.jsx(cr,{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(co,{className:"w-5 h-5 animate-pulse"}),className:"bg-purple-500 hover:bg-purple-600",disabled:!0};default:return{icon:e.jsx(cr,{className:"w-5 h-5"}),className:"bg-gray-700 hover:bg-gray-600",disabled:!1}}},{icon:I,className:p,disabled:b}=L();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:`
23
+ flex items-center justify-center
24
+ w-12 h-12 rounded-full
25
+ text-white transition-all duration-200
26
+ focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500
27
+ dark:ring-offset-gray-800
28
+ touch-action-manipulation
29
+ ${b?"cursor-not-allowed opacity-75":"cursor-pointer"}
30
+ ${a==="recording"?"animate-pulse":""}
31
+ hover:opacity-90
32
+ ${r}
33
+ `,onClick:k,disabled:b,children:I}),n&&e.jsx("div",{className:`absolute top-full mt-2 left-1/2 transform -translate-x-1/2
34
+ bg-red-500 text-white text-xs px-2 py-1 rounded whitespace-nowrap z-10
35
+ animate-fade-in`,children:n}),a==="recording"&&e.jsx("div",{className:"absolute -inset-1 rounded-full border-2 border-red-500 animate-ping pointer-events-none"}),a==="processing"&&e.jsx("div",{className:"absolute -inset-1 rounded-full border-2 border-purple-500 animate-ping pointer-events-none"})]})}const al=({commands:t=[],selectedIndex:r=-1,onSelect:a,onClose:o,position:n={top:0,left:0},isOpen:l=!1,frequentCommands:i=[]})=>{const d=s.useRef(null),u=s.useRef(null),x=window.innerWidth<640?{position:"fixed",bottom:`${n.bottom||90}px`,left:"16px",right:"16px",width:"auto",maxWidth:"calc(100vw - 32px)",maxHeight:"min(50vh, 300px)"}:{position:"fixed",bottom:`${n.bottom||90}px`,left:`${n.left}px`,width:"min(400px, calc(100vw - 32px))",maxWidth:"calc(100vw - 32px)",maxHeight:"300px"};if(s.useEffect(()=>{const b=m=>{d.current&&!d.current.contains(m.target)&&l&&o()};if(l)return document.addEventListener("mousedown",b),()=>{document.removeEventListener("mousedown",b)}},[l,o]),s.useEffect(()=>{if(u.current&&d.current){const b=d.current.getBoundingClientRect(),m=u.current.getBoundingClientRect();m.bottom>b.bottom?u.current.scrollIntoView({block:"nearest",behavior:"smooth"}):m.top<b.top&&u.current.scrollIntoView({block:"nearest",behavior:"smooth"})}},[r]),!l)return null;if(t.length===0){const b=window.innerWidth<640,m={position:"fixed",bottom:`${n.bottom||90}px`,left:b?"16px":`${n.left}px`,width:b?"auto":"min(400px, calc(100vw - 32px))",maxWidth:"calc(100vw - 32px)",...b?{right:"16px"}:{}};return e.jsx("div",{ref:d,className:"command-menu command-menu-empty",style:{...m,borderRadius:"8px",boxShadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",zIndex:1e3,padding:"20px",opacity:1,transform:"translateY(0)",transition:"opacity 150ms ease-in-out, transform 150ms ease-in-out",textAlign:"center"},children:"暂无可用命令"})}const g=i.length>0,h=t.reduce((b,m)=>{const j=m.namespace||m.type||"other";return b[j]||(b[j]=[]),b[j].push(m),b},{});g&&(h.frequent=i);const k=(g?["frequent","builtin","project","user","skill","mcp","other"]:["builtin","project","user","skill","mcp","other"]).filter(b=>h[b]),L={frequent:"⭐ 常用命令",builtin:"内置命令",project:"项目命令",user:"用户命令",skill:"🔧 技能",mcp:"🔌 MCP 工具",other:"其他命令"};let I=0;const p=[];return k.forEach(b=>{h[b].forEach(m=>{p.push({...m,globalIndex:I++,namespace:b})})}),e.jsxs("div",{ref:d,role:"listbox","aria-label":"Available commands",className:"command-menu",style:{...x,maxHeight:"300px",overflowY:"auto",borderRadius:"8px",boxShadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",zIndex:1e3,padding:"8px",opacity:l?1:0,transform:l?"translateY(0)":"translateY(-10px)",transition:"opacity 150ms ease-in-out, transform 150ms ease-in-out"},children:[k.map(b=>e.jsxs("div",{className:"command-group",children:[k.length>1&&e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"#6b7280",padding:"8px 12px 4px",letterSpacing:"0.05em"},children:L[b]||b}),h[b].map(m=>{const j=p.find(G=>G.name===m.name&&G.namespace===b),R=j&&j.globalIndex===r;return e.jsxs("div",{ref:R?u:null,role:"option","aria-selected":R,className:"command-item",onMouseEnter:()=>a&&a(m,j.globalIndex,!0),onClick:()=>a&&a(m,j.globalIndex,!1),style:{display:"flex",alignItems:"flex-start",padding:"10px 12px",borderRadius:"6px",cursor:"pointer",backgroundColor:R?"#eff6ff":"transparent",transition:"background-color 100ms ease-in-out",marginBottom:"2px"},onMouseDown:G=>G.preventDefault(),children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:m.description?"4px":0},children:[e.jsxs("span",{style:{fontSize:"16px",flexShrink:0},children:[b==="builtin"&&"⚡",b==="project"&&"📁",b==="user"&&"👤",b==="skill"&&"🔧",b==="mcp"&&"🔌",b==="other"&&"📝"]}),e.jsx("span",{style:{fontWeight:600,fontSize:"14px",color:"#111827",fontFamily:"monospace"},children:m.name}),m.metadata?.type&&e.jsx("span",{className:"command-metadata-badge",style:{fontSize:"10px",padding:"2px 6px",borderRadius:"4px",backgroundColor:"#f3f4f6",color:"#6b7280",fontWeight:500},children:m.metadata.type})]}),m.description&&e.jsx("div",{style:{fontSize:"13px",color:"#6b7280",marginLeft:"24px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:m.description})]}),R&&e.jsx("span",{style:{marginLeft:"8px",color:"#3b82f6",fontSize:"12px",fontWeight:600},children:"↵"})]},`${b}-${m.name}`)})]},b)),e.jsx("style",{children:`
36
+ .command-menu {
37
+ background-color: white;
38
+ border: 1px solid #e5e7eb;
39
+ }
40
+ .command-menu-empty {
41
+ color: #6b7280;
42
+ }
43
+
44
+ @media (prefers-color-scheme: dark) {
45
+ .command-menu {
46
+ background-color: #1f2937 !important;
47
+ border: 1px solid #374151 !important;
48
+ }
49
+ .command-menu-empty {
50
+ color: #9ca3af !important;
51
+ }
52
+ .command-item[aria-selected="true"] {
53
+ background-color: #1e40af !important;
54
+ }
55
+ .command-item span:not(.command-metadata-badge) {
56
+ color: #f3f4f6 !important;
57
+ }
58
+ .command-metadata-badge {
59
+ background-color: #f3f4f6 !important;
60
+ color: #6b7280 !important;
61
+ }
62
+ .command-item div {
63
+ color: #d1d5db !important;
64
+ }
65
+ .command-group > div:first-child {
66
+ color: #9ca3af !important;
67
+ }
68
+ }
69
+ `})]})},fr={OPTIONS:[{value:"sonnet",label:"Sonnet"},{value:"opus",label:"Opus"},{value:"haiku",label:"Haiku"}],DEFAULT:"sonnet"};function os(t){return t&&t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&amp;/g,"&")}function nl(t){if(!t||typeof t!="string")return t;try{return t.replace(/```\s*([^\n\r]+?)\s*```/g,"`$1`")}catch{return t}}function br(t){if(!t||typeof t!="string")return t;const r=[],a="__MATH_BLOCK_",o="__";let n=t.replace(/\$\$([\s\S]*?)\$\$|\$([^\$\n]+?)\$/g,l=>{const i=r.length;return r.push(l),`${a}${i}${o}`});return n=n.replace(/\\n/g,`
70
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r"),n=n.replace(new RegExp(`${a}(\\d+)${o}`,"g"),(l,i)=>r[parseInt(i)]),n}const fs=({children:t,className:r})=>{const a=nl(String(t??"")),o=s.useMemo(()=>[Lo,To],[]),n=s.useMemo(()=>[Ro],[]);return e.jsx("div",{className:r,children:e.jsx(Do,{remarkPlugins:o,rehypePlugins:n,components:ll,children:a})})};function Lr(t){try{return typeof t!="string"?t:t.replace(/Claude AI usage limit reached\|(\d{10,13})/g,(r,a)=>{let o=parseInt(a,10);if(!Number.isFinite(o))return r;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?"+":"-",u=Math.abs(i),f=Math.floor(u/60),x=u%60,g=`GMT${d}${f}${x?":"+String(x).padStart(2,"0"):""}`,k=((Intl.DateTimeFormat().resolvedOptions().timeZone||"").split("/").pop()||"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,b=>b.toUpperCase()),L=k?`${g} (${k})`:g,I=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=`${n.getDate()} ${I[n.getMonth()]} ${n.getFullYear()}`;return`Claude usage limit reached. Your limit will reset at **${l} ${L}** - ${p}`})}catch{return t}}const mt={setItem:(t,r)=>{try{if(t.startsWith("chat_messages_")&&typeof r=="string")try{const a=JSON.parse(r);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);r=JSON.stringify(o)}}catch(a){console.warn("Could not parse chat messages for truncation:",a)}localStorage.setItem(t,r)}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,r)}catch(i){if(console.error("Failed to save to localStorage even after cleanup:",i),t.startsWith("chat_messages_")&&typeof r=="string")try{const d=JSON.parse(r);if(Array.isArray(d)&&d.length>10){const u=d.slice(-10);localStorage.setItem(t,JSON.stringify(u)),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(r){return console.error("localStorage getItem error:",r),null}},removeItem:t=>{try{localStorage.removeItem(t)}catch(r){console.error("localStorage removeItem error:",r)}}},un="claude-settings";function Hr(){const t=mt.getItem(un);if(!t)return{allowedTools:[],disallowedTools:[],skipPermissions:!1,projectSortOrder:"name"};try{const r=JSON.parse(t);return{...r,allowedTools:Array.isArray(r.allowedTools)?r.allowedTools:[],disallowedTools:Array.isArray(r.disallowedTools)?r.disallowedTools:[],skipPermissions:!!r.skipPermissions,projectSortOrder:r.projectSortOrder||"name"}}catch{return{allowedTools:[],disallowedTools:[],skipPermissions:!1,projectSortOrder:"name"}}}function Tr(t,r){if(!t)return null;if(t!=="Bash")return t;const a=Wo(r),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 Ra(t){if(t==null)return"";if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function ol(t,r){if(r!=="claude"||!t?.toolResult?.isError)return null;const a=t?.toolName,o=Tr(a,t.toolInput);if(!o)return null;const l=Hr().allowedTools.includes(o);return{toolName:a,entry:o,isAllowed:l}}function il(t){if(!t)return{success:!1};const r=Hr(),a=r.allowedTools.includes(t),o=a?r.allowedTools:[...r.allowedTools,t],n=r.disallowedTools.filter(i=>i!==t),l={...r,allowedTools:o,disallowedTools:n,lastUpdated:new Date().toISOString()};return mt.setItem(un,JSON.stringify(l)),{success:!0,alreadyAllowed:a,updatedSettings:l}}const ll={code:({node:t,inline:r,className:a,children:o,...n})=>{const[l,i]=ut.useState(!1),d=Array.isArray(o)?o.join(""):String(o??""),u=/[\r\n]/.test(d);if(r||t&&t.type==="inlineCode"||!u)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 g=/language-(\w+)/.exec(a||""),h=g?g[1]:"text",y=d,k=()=>{const L=()=>{i(!0),setTimeout(()=>i(!1),1500)};try{if(navigator&&navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(y).then(L).catch(()=>{const I=document.createElement("textarea");I.value=y,I.style.position="fixed",I.style.opacity="0",document.body.appendChild(I),I.select();try{document.execCommand("copy")}catch{}document.body.removeChild(I),L()});else{const I=document.createElement("textarea");I.value=y,I.style.position="fixed",I.style.opacity="0",document.body.appendChild(I),I.select();try{document.execCommand("copy")}catch{}document.body.removeChild(I),L()}}catch{}};return e.jsxs("div",{className:"relative group my-2",children:[h&&h!=="text"&&e.jsx("div",{className:"absolute top-2 left-3 z-10 text-xs text-gray-400 font-medium uppercase",children:h}),e.jsx("button",{type:"button",onClick:k,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(Po,{language:h,style:ti,customStyle:{margin:0,borderRadius:"0.5rem",fontSize:"0.875rem",padding:h&&h!=="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:r})=>e.jsx("a",{href:t,className:"text-blue-600 dark:text-blue-400 hover:underline",target:"_blank",rel:"noopener noreferrer",children:r}),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 cl(t){let r=0;for(const a of t)if(!a.isMeta){if(a.type==="tool_use"&&a.toolName){r++;continue}if(a.type!=="tool_result"){if(a.message?.role==="user"&&a.message?.content){const o=a.message.content;(Array.isArray(o)?o.some(l=>l.type==="text"):!!o)&&r++}else if(a.message?.role==="assistant"&&a.message?.content){const o=a.message.content;Array.isArray(o)&&o.some(n=>n.type==="text"||n.type==="thinking")&&r++}}}return r}const bs="__other__";function dl({request:t,onSubmit:r,onSkip:a}){const o=t.input?.questions||[],[n,l]=ut.useState(0),[i,d]=ut.useState(()=>Object.fromEntries(o.map(j=>[j.question,[]]))),[u,f]=ut.useState(()=>Object.fromEntries(o.map(j=>[j.question,""]))),x=ut.useRef(null),g=o[n],h=o.length,y=j=>{const R=i[j.question]||[];return!(R.length===0||R.includes(bs)&&!(u[j.question]||"").trim())},k=g?y(g):!1,L=n===h-1,I=o.every(y),p=j=>(i[j]||[]).includes(bs),b=(j,R,G)=>{d(U=>{const v=U[j]||[];return G?{...U,[j]:v.includes(R)?v.filter(H=>H!==R):[...v,R]}:{...U,[j]:[R]}}),!G&&R!==bs&&n<h-1&&(x.current&&clearTimeout(x.current),x.current=setTimeout(()=>l(U=>U+1),280))},m=()=>{const j={};o.forEach(R=>{const U=(i[R.question]||[]).map(v=>v===bs?(u[R.question]||"").trim():v).filter(Boolean);j[R.question]=U.join(", ")}),r(j)};return g?e.jsxs("div",{className:"rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100",children:"Claude 需要您的回答"}),h>1&&e.jsxs("div",{className:"text-xs text-blue-500 dark:text-blue-400 font-medium tabular-nums",children:[n+1," / ",h]})]}),h>1&&e.jsx("div",{className:"px-3 pb-2.5 flex gap-1.5 items-center",children:o.map((j,R)=>e.jsx("button",{type:"button",onClick:()=>l(R),title:`问题 ${R+1}`,className:`h-1.5 rounded-full transition-all duration-200 ${R===n?"w-5 bg-blue-600":y(j)?"w-2 bg-blue-400 hover:bg-blue-500":"w-2 bg-blue-200 dark:bg-blue-700 hover:bg-blue-300 dark:hover:bg-blue-600"}`},R))}),e.jsxs("div",{className:"px-3 pb-3",children:[e.jsxs("div",{className:"text-sm font-medium text-blue-800 dark:text-blue-200 mb-2",children:[g.question,g.multiSelect&&e.jsx("span",{className:"ml-2 text-xs font-normal opacity-60",children:"(可多选)"})]}),e.jsxs("div",{className:"space-y-1",children:[g.options.map((j,R)=>{const G=(i[g.question]||[]).includes(j.label);return e.jsxs("button",{type:"button",onClick:()=>b(g.question,j.label,g.multiSelect),className:`w-full text-left px-3 py-2 rounded-md text-xs border transition-colors ${G?"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:j.label}),j.description&&e.jsxs("span",{className:"ml-1 opacity-70",children:[" — ",j.description]})]},R)}),e.jsxs("button",{type:"button",onClick:()=>b(g.question,bs,g.multiSelect),className:`w-full text-left px-3 py-2 rounded-md text-xs border transition-colors ${p(g.question)?"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:"其他"}),e.jsx("span",{className:"ml-1 opacity-70",children:" — 手动输入自定义答案"})]}),p(g.question)&&e.jsx("input",{autoFocus:!0,type:"text",value:u[g.question]||"",onChange:j=>f(R=>({...R,[g.question]:j.target.value})),placeholder:"请输入您的答案…",className:"w-full mt-1 px-3 py-2 rounded-md text-xs border border-blue-300 dark:border-blue-600 bg-white dark:bg-gray-800 text-blue-900 dark:text-blue-100 focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[n>0&&e.jsx("button",{type:"button",onClick:()=>l(j=>j-1),className:"inline-flex items-center gap-1 rounded-md text-xs font-medium px-2.5 py-1.5 border border-blue-300 dark:border-blue-700 text-blue-600 dark:text-blue-400 hover:bg-blue-100 dark:hover:bg-blue-900/30 transition-colors",children:"← 上一题"}),L?e.jsx("button",{type:"button",onClick:m,disabled:!I,className:"inline-flex items-center gap-1 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:()=>l(j=>j+1),disabled:!k,className:"inline-flex items-center gap-1 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:"ml-auto inline-flex items-center rounded-md text-xs font-medium px-2.5 py-1.5 border border-gray-300 dark:border-gray-700 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800/40 transition-colors",children:"跳过"})]})]})]}):null}const pn=s.memo(({image:t})=>{const[r,a]=s.useState(t.data||null),[o,n]=s.useState(!1),[l,i]=s.useState(!t.data&&!!t.id);return s.useEffect(()=>{if(t.data||!t.id)return;let d=!1;return i(!0),Y(`/api/images/${t.id}`).then(u=>{if(!u.ok)throw new Error("expired");return u.blob()}).then(u=>{d||(a(URL.createObjectURL(u)),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:"加载中..."}):r?e.jsx("img",{src:r,alt:t.name||"image",className:"rounded-lg max-w-full h-auto cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>window.open(r,"_blank"),onError:()=>n(!0)}):null});pn.displayName="PersistentImage";const Da=s.memo(({message:t,index:r,prevMessage:a,createDiff:o,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,selectedProject:d,provider:u,onFork:f,messageUuid:x})=>{const g=a&&a.type===t.type&&(a.type==="assistant"||a.type==="user"||a.type==="tool"||a.type==="error"),h=ut.useRef(null),y=ol(t,u),[k,L]=ut.useState("idle");return ut.useEffect(()=>{L("idle")},[y?.entry,t.toolId]),e.jsx("div",{ref:h,className:`group chat-message ${t.type} ${g?"grouped":""} ${t.type==="user"?"flex justify-end px-3 sm:px-0":"px-3 sm:px-0"}`,children:t.type==="user"?e.jsx("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((I,p)=>e.jsx(pn,{image:I},I.id||p))}),e.jsx("div",{className:"text-xs text-blue-100 mt-1 text-right",children:new Date(t.timestamp).toLocaleTimeString()})]})}):e.jsxs("div",{className:"w-full",children:[!g&&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(Ks,{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"?"工具":Ze})]}),e.jsxs("div",{className:"w-full",children:[t.isToolUse&&!["Read","TodoWrite","TodoRead"].includes(t.toolName)?(()=>{const I=(()=>{try{const p=JSON.parse(t.toolInput);switch(t.toolName){case"Bash":return He(p.command||"").slice(0,80);case"Edit":case"Write":return p.file_path?p.file_path.split("/").pop():"";case"Grep":{let b=p.pattern||"";return p.path&&(b+=" · "+He(p.path)),b}case"Glob":return p.pattern||"";default:{const b=Object.keys(p);if(b.length===0)return"";const m=b[0],j=p[m];return String(typeof j=="object"?JSON.stringify(j):j||"").slice(0,60)}}}catch{return""}})();return e.jsxs("details",{className:"group/tool border border-gray-200/60 dark:border-gray-700/40 rounded-lg my-1.5 overflow-hidden",open:!1,children:[e.jsxs("summary",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/40 transition-colors select-none [list-style:none] [&::-webkit-details-marker]:hidden",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),e.jsx("span",{className:"text-xs font-medium text-gray-600 dark:text-gray-400 flex-shrink-0",children:t.toolName}),e.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 truncate flex-1 font-mono min-w-0",children:I}),t.toolResult?t.toolResult.isError?e.jsx("svg",{className:"w-3.5 h-3.5 text-red-500 dark:text-red-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M6 18L18 6M6 6l12 12"})}):e.jsx("svg",{className:"w-3.5 h-3.5 text-green-500 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.5,d:"M5 13l4 4L19 7"})}):e.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse flex-shrink-0"}),e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500 flex-shrink-0 transition-transform duration-200 group-open/tool: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("div",{className:"border-t border-gray-100 dark:border-gray-700/40 divide-y divide-gray-100 dark:divide-gray-700/40",children:[t.toolInput&&e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-gray-400 dark:text-gray-500 mb-2",children:"参数"}),t.toolName==="Edit"&&(()=>{try{const p=JSON.parse(t.toolInput);if(p.file_path&&p.old_string&&p.new_string)return e.jsxs("div",{children:[e.jsx("button",{onClick:async()=>{if(n)try{const j=(await(await he.readFile(d?.name,p.file_path)).json()).content||"",R=j.replace(p.new_string,p.old_string);n(p.file_path,{old_string:R,new_string:j})}catch{n(p.file_path)}},className:"text-xs font-mono text-blue-600 dark:text-blue-400 hover:underline mb-2 block truncate max-w-full",children:He(p.file_path)}),e.jsx("div",{className:"bg-white dark:bg-gray-900/50 border border-gray-200/60 dark:border-gray-700/60 rounded-lg overflow-hidden text-xs font-mono",children:o(p.old_string,p.new_string).map((b,m)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r flex-shrink-0 ${b.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:b.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${b.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:b.content})]},m))})]})}catch{}return e.jsx("pre",{className:"text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-2.5 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-600 dark:text-gray-400 font-mono",children:He(t.toolInput)})})(),t.toolName==="Write"&&(()=>{try{const p=typeof t.toolInput=="string"?JSON.parse(t.toolInput):t.toolInput;if(p.file_path&&p.content!==void 0)return e.jsxs("div",{children:[e.jsx("button",{onClick:async()=>{if(n)try{const b=await he.readFile(d?.name,p.file_path),m=await b.json(),j=b.ok&&!m.error?m.content||"":p.content||"";n(p.file_path,{old_string:"",new_string:j})}catch{n(p.file_path,{old_string:"",new_string:p.content||""})}},className:"text-xs font-mono text-blue-600 dark:text-blue-400 hover:underline mb-2 block truncate max-w-full",children:He(p.file_path)}),e.jsx("div",{className:"bg-white dark:bg-gray-900/50 border border-gray-200/60 dark:border-gray-700/60 rounded-lg overflow-hidden text-xs font-mono",children:o("",p.content).map((b,m)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r flex-shrink-0 ${b.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:b.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${b.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:b.content})]},m))})]})}catch{}return e.jsx("pre",{className:"text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-2.5 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-600 dark:text-gray-400 font-mono",children:He(t.toolInput)})})(),t.toolName==="Bash"&&(()=>{try{const p=JSON.parse(t.toolInput);return e.jsxs("div",{children:[e.jsxs("div",{className:"bg-gray-900 dark:bg-gray-950 rounded-md px-3 py-2 font-mono text-xs",children:[e.jsx("span",{className:"text-green-400",children:"$"}),e.jsx("span",{className:"text-gray-100 ml-2",children:He(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{return null}})(),t.toolName==="exit_plan_mode"&&(()=>{try{const p=JSON.parse(t.toolInput);if(p.plan)return e.jsx(fs,{className:"prose prose-sm max-w-none dark:prose-invert",children:p.plan.replace(/\\n/g,`
71
+ `)})}catch{return null}})(),!["Edit","Write","Bash","exit_plan_mode"].includes(t.toolName)&&e.jsx("pre",{className:"text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-2.5 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-600 dark:text-gray-400 font-mono",children:He(t.toolInput)})]}),t.toolResult&&(()=>{if(!t.toolResult.isError&&(t.toolName==="Edit"||t.toolName==="Write"||t.toolName==="ApplyPatch"||t.toolName==="Bash"))return null;const b=He(String(t.toolResult.content||""));return e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsx("div",{className:`text-[10px] uppercase tracking-wide mb-2 ${t.toolResult.isError?"text-red-400 dark:text-red-400":"text-gray-400 dark:text-gray-500"}`,children:t.toolResult.isError?"错误":"结果"}),e.jsxs("div",{className:`text-xs ${t.toolResult.isError?"text-red-700 dark:text-red-300":"text-gray-700 dark:text-gray-300"}`,children:[(()=>{if((t.toolName==="TodoWrite"||t.toolName==="TodoRead")&&(b.includes("Todos have been modified successfully")||b.includes("Todo list")||b.startsWith("[")&&b.includes('"content"')&&b.includes('"status"')))try{if(b.startsWith("[")){const m=JSON.parse(b);if(Array.isArray(m))return e.jsx(Ta,{todos:m,isResult:!0})}return e.jsx("span",{className:"font-medium",children:"待办列表已更新成功"})}catch{}if(t.toolName==="exit_plan_mode")try{const m=JSON.parse(b);if(m.plan)return e.jsx(fs,{className:"prose prose-sm max-w-none dark:prose-invert",children:m.plan.replace(/\\n/g,`
72
+ `)})}catch{}if((t.toolName==="Grep"||t.toolName==="Glob")&&t.toolResult?.toolUseResult){const m=t.toolResult.toolUseResult;if(m.filenames&&Array.isArray(m.filenames)&&m.filenames.length>0)return e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium mb-2",children:["找到 ",m.numFiles||m.filenames.length," 个文件"]}),e.jsx("div",{className:"space-y-0.5 max-h-96 overflow-y-auto",children:m.filenames.map((j,R)=>{const G=j.split("/").pop(),U=j.substring(0,j.lastIndexOf("/"));return e.jsxs("div",{onClick:()=>n&&n(j),className:"flex items-center gap-2 px-2 py-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800/50 cursor-pointer transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-400 dark:text-gray-500 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("span",{className:"font-mono font-medium truncate block",children:G}),e.jsx("span",{className:"font-mono text-[10px] text-gray-400 dark:text-gray-500 truncate block",children:He(U)})]})]},R)})})]})}if(b.includes("Do you want to proceed?")&&t.toolName==="Bash"){const m=b.split(`
73
+ `),j=m.findIndex(z=>z.includes("Do you want to proceed?")),R=m.slice(0,j).join(`
74
+ `),G=m.slice(j),U=G.find(z=>z.includes("Do you want to proceed?"))||"",v=[];G.forEach(z=>{const q=z.match(/^\s*(\d+)\.\s+(.+)$/);q&&v.push({number:q[1],text:q[2].trim()})});const H=b.match(/>\s*(\d+)/),N=H?H[1]:null;return e.jsxs("div",{className:"space-y-2",children:[R&&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:R})}),e.jsx("div",{className:"text-gray-500 dark:text-gray-400 text-xs",children:U}),e.jsx("div",{className:"space-y-1",children:v.map(z=>e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1 rounded text-xs ${N===z.number?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"text-gray-500 dark:text-gray-400"}`,children:[e.jsxs("span",{className:"font-mono",children:[z.number,"."]}),e.jsx("span",{children:z.text}),N===z.number&&e.jsx("svg",{className:"w-3.5 h-3.5 ml-auto text-green-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M5 13l4 4L19 7"})})]},z.number))}),N&&e.jsxs("div",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:["Claude 选择了选项 ",N]})]})}return b.includes("cat -n")&&b.includes("→")?e.jsxs("details",{open:!1,children:[e.jsxs("summary",{className:"[list-style:none] [&::-webkit-details-marker]:hidden cursor-pointer text-gray-400 dark:text-gray-500 hover:text-gray-500 flex items-center gap-1 mb-1 text-xs",children:[e.jsx("svg",{className:"w-3.5 h-3.5 transition-transform [details[open]>summary_&]: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("div",{className:"mt-2 bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 rounded-lg overflow-hidden",children:e.jsx("div",{className:"text-xs font-mono p-3 whitespace-pre-wrap break-words overflow-hidden",children:b})})]}):b.length>300?e.jsxs("details",{open:!1,children:[e.jsxs("summary",{className:"[list-style:none] [&::-webkit-details-marker]:hidden cursor-pointer text-gray-400 dark:text-gray-500 hover:text-gray-500 flex items-center gap-1 mb-1 text-xs",children:[e.jsx("svg",{className:"w-3.5 h-3.5 transition-transform [details[open]>summary_&]: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"})}),"查看完整输出 (",b.length," 字符)"]}),e.jsx(fs,{className:"mt-2 prose prose-sm max-w-none dark:prose-invert",children:b})]}):e.jsx(fs,{className:"prose prose-sm max-w-none dark:prose-invert",children:b})})(),y&&e.jsxs("div",{className:"mt-3 pt-2 border-t border-gray-200/60 dark:border-gray-700/40",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{if(!i)return;i(y)?.success?L("granted"):L("error")},disabled:y.isAllowed||k==="granted",className:`inline-flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-medium border transition-colors ${y.isAllowed||k==="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:y.isAllowed||k==="granted"?"权限已添加":`授予权限 ${y.toolName}`}),l&&e.jsx("button",{type:"button",onClick:m=>{m.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:y.entry})," 到允许的工具列表。"]}),k==="error"&&e.jsx("div",{className:"mt-2 text-xs text-red-700 dark:text-red-200",children:"无法更新权限。请重试。"}),(y.isAllowed||k==="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 I=t.content.split(`
75
+ `).filter(m=>m.trim()),p=I.find(m=>m.includes("?"))||I[0]||"",b=[];return I.forEach(m=>{const j=m.match(/[❯\s]*(\d+)\.\s+(.+)/);if(j){const R=m.includes("❯");b.push({number:j[1],text:j[2].trim(),isSelected:R})}}),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:b.map(m=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${m.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 ${m.isSelected?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:m.number}),e.jsx("span",{className:"text-sm sm:text-base font-medium flex-1",children:m.text}),m.isSelected&&e.jsx("span",{className:"text-lg",children:"❯"})]})},m.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 I=JSON.parse(t.toolInput);if(I.file_path){const p=I.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(I.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 I=JSON.parse(t.toolInput);if(I.todos&&Array.isArray(I.todos))return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400 mb-1.5",children:[e.jsx("svg",{className:"w-3.5 h-3.5",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(Ta,{todos:I.todos})]})}catch{return e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",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:"读取待办列表"})]})}):e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300",children:(()=>{const I=He(Lr(String(t.content||""))),p=I.trim();if((p.startsWith("{")||p.startsWith("["))&&(p.endsWith("}")||p.endsWith("]")))try{const b=JSON.parse(p),m=JSON.stringify(b,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:m})})})]})}catch{}return t.type==="assistant"?e.jsx(fs,{className:"prose prose-sm max-w-none dark:prose-invert prose-gray",children:I}):e.jsx("div",{className:"whitespace-pre-wrap",children:I})})()}),e.jsxs("div",{className:`flex items-center gap-2 mt-1 ${g?"opacity-0 group-hover:opacity-100":""}`,children:[e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:new Date(t.timestamp).toLocaleTimeString()}),f&&t.type==="assistant"&&!t.isToolUse&&e.jsx("button",{onClick:()=>f(x),className:"opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700",title:"从此处创建新会话分支",children:e.jsxs("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",viewBox:"0 0 24 24",children:[e.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),e.jsx("circle",{cx:"18",cy:"6",r:"3"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("path",{d:"M18 9a9 9 0 0 1-9 9"})]})})]})]})]})})}),ml=({file:t,onRemove:r,uploadProgress:a,error:o})=>{const[n,l]=s.useState(null);return s.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:r,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 ul({selectedProject:t,selectedSession:r,ws:a,sendMessage:o,messages:n,onFileOpen:l,onInputFocusChange:i,onSessionActive:d,onSessionInactive:u,onSessionProcessing:f,onSessionNotProcessing:x,processingSessions:g,onReplaceTemporarySession:h,onNavigateToSession:y,onShowSettings:k,autoScrollToBottom:L,sendByCtrlEnter:I,externalMessageUpdate:p,onTaskClick:b,limitStatus:m,onLimitExceeded:j,checkLimitStatus:R}){const{showConfirm:G,showAlert:U}=dt(),[v,H]=s.useState(()=>typeof window<"u"&&t&&mt.getItem(`draft_input_${t.name}`)||""),[N,z]=s.useState(()=>{if(typeof window<"u"&&t){const c=mt.getItem(`chat_messages_${t.name}`);return c?JSON.parse(c):[]}return[]}),[q,S]=s.useState(!1),[E,O]=s.useState(r?.id||null),[se,re]=s.useState(!1),[J,le]=s.useState([]),me=s.useRef([]),[ge,De]=s.useState(!1),[we,Me]=s.useState(!1),[Ue,ie]=s.useState(0),[Se,We]=s.useState(!1),[,Be]=s.useState(0),ve=20,Ie=s.useCallback(c=>{nt.current=c,ie(c)},[]),[Le,qe]=s.useState(!1),[ke,Je]=s.useState(pa),$e=s.useRef(null),[Pe,_e]=s.useState([]),ze=s.useRef(new Map),[Ae,Ye]=s.useState(null);s.useEffect(()=>{const c=`${Ze} - ${Xa}`;return Pe.length>0?document.title=`[等待审批] ${c}`:document.title=c,()=>{document.title=c}},[Pe.length]);const Oe=s.useRef(r?.id||null),V=s.useRef(null);s.useEffect(()=>{a&&!V.current&&q&&E&&o({type:"check-session-status",sessionId:E,provider:kt}),V.current=a},[a]);const[$,w]=s.useState([]),[ee,A]=s.useState(new Map),[te,K]=s.useState(new Map),[oe,ce]=s.useState(!1),Re=s.useRef(null),ae=s.useRef(null),Te=s.useRef(null),Ee=s.useRef(null),pe=s.useRef(null),tt=s.useRef(!1),Fe=s.useRef(!1),D=s.useRef(!1),ue=s.useRef(!1),M=s.useRef(null),ne=s.useRef(null),W=s.useRef(null),Ne=s.useRef(null),nt=s.useRef(0),Xe=s.useRef(""),ot=s.useRef(null),pt=s.useRef(null),lt=s.useRef([]),[st,Bt]=s.useState(""),[cs,yt]=s.useState(!1),[Cs,Ht]=s.useState([]),[Et,ds]=s.useState([]),[ms,vt]=s.useState(-1),[Es,qt]=s.useState(0),[Ms,ts]=s.useState(-1),[Xs,ht]=s.useState(!1),[Jt,ss]=s.useState(!1),rs=s.useRef({height:0,top:0}),[us,xt]=s.useState(!1),[Kt,ps]=s.useState(!1),xs=s.useRef(null),It=s.useRef(null),[ft,Lt]=s.useState([]),[_,Z]=s.useState([]),[xe,Ce]=s.useState(""),[gt,Ve]=s.useState(!1),[Qr,as]=s.useState(null),[Zs,Tt]=s.useState(-1),[Xr,Rt]=s.useState(-1),[hs,bn]=s.useState(100),er=typeof window<"u"&&window.innerWidth<640,[$t,tr]=s.useState(!1),[yn,vn]=s.useState(380),[sr,Zr]=s.useState(!1),[jn,jt]=s.useState(null),[wt,ea]=s.useState(()=>localStorage.getItem("claude-model")||fr.DEFAULT),kt="claude";s.useEffect(()=>{if(!Kt)return;const c=C=>{xs.current&&!xs.current.contains(C.target)&&It.current&&!It.current.contains(C.target)&&ps(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[Kt]),s.useEffect(()=>{if(r?.id){const c=localStorage.getItem(`permissionMode-${r.id}`);if(c)Je(c),$e.current=null;else if($e.current){const C=$e.current;$e.current=null,localStorage.setItem(`permissionMode-${r.id}`,C),Je(C)}else Je(pa)}},[r?.id]),s.useEffect(()=>{const c=Oe.current,C=r?.id;Oe.current=C,_e(c&&c!==C?P=>(ze.current.set(c,P),ze.current.get(C)||[]):P=>P.filter(T=>!T.sessionId||T.sessionId===C))},[r?.id]),s.useEffect(()=>{(async()=>{if(t)try{const[C,P,T]=await Promise.all([Y("/api/commands/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPath:t.path})}),Y("/api/skills").catch(()=>null),Y("/api/mcp/config/read").catch(()=>null)]);if(!C.ok)throw new Error("Failed to fetch commands");const F=await C.json();let Q=[];P?.ok&&(Q=((await P.json()).skills||[]).filter(ye=>ye.scope!=="local"||ye.projectPath===t?.path).map(ye=>({name:"/"+ye.name,description:ye.description||ye.title||"",namespace:"skill",type:"skill"})));let fe=[];if(T?.ok){const be=await T.json();be.success&&be.servers&&(fe=be.servers.filter(ye=>ye.scope!=="local"||ye.projectPath===t?.path).map(ye=>({name:ye.name,description:`${ye.type}${ye.scope?" · "+ye.scope:""}`,namespace:"mcp",type:"mcp"})))}const je=[...(F.builtIn||[]).map(be=>({...be,type:"built-in"})),...(F.custom||[]).map(be=>({...be,type:"custom"})),...Q,...fe];Lt(je);const X=`command_history_${t.name}`,de=mt.getItem(X);if(de)try{const be=JSON.parse(de),ye=je.sort((at,Hn)=>{const qn=be[at.name]||0;return(be[Hn.name]||0)-qn});Lt(ye)}catch(be){console.error("Error parsing command history:",be)}}catch(C){console.error("Error fetching slash commands:",C),Lt([])}})()},[t]);const rr=s.useMemo(()=>ft.length?new io(ft,{keys:[{name:"name",weight:2},{name:"description",weight:1}],threshold:.4,includeScore:!0,minMatchCharLength:1}):null,[ft]);s.useEffect(()=>{if(!xe){Z(ft);return}if(!rr){Z([]);return}const c=rr.search(xe);Z(c.map(C=>C.item))},[xe,ft,rr]);const wn=s.useMemo(()=>{if(!t||ft.length===0)return[];const c=`command_history_${t.name}`,C=mt.getItem(c);if(!C)return[];try{const P=JSON.parse(C);return ft.map(F=>({...F,usageCount:P[F.name]||0})).filter(F=>F.usageCount>0).sort((F,Q)=>Q.usageCount-F.usageCount).slice(0,5)}catch(P){return console.error("Error parsing command history:",P),[]}},[t,ft]),kn=s.useCallback((c,C,P)=>{if(!c||!t)return;if(P){Tt(C);return}const T=`command_history_${t.name}`,F=mt.getItem(T);let Q={};try{Q=F?JSON.parse(F):{}}catch(fe){console.error("Error parsing command history:",fe)}if(Q[c.name]=(Q[c.name]||0)+1,mt.setItem(T,JSON.stringify(Q)),c.namespace==="skill"||c.namespace==="mcp"){H(c.name+" "),xt(!1),Rt(-1),Ce(""),Tt(-1),ae.current&&ae.current.focus();return}Is(c)},[t]),Nn=s.useCallback(c=>{const{action:C,data:P}=c;switch(C){case"help":z(T=>[...T,{type:"assistant",content:P.content,timestamp:Date.now()}]);break;case"model":{const T=P.available.claude,F=P.message?.includes("Switching to model:")?P.message.replace("Switching to model: ","").trim():null;F&&T.includes(F)?(ea(F),localStorage.setItem("claude-model",F),z(Q=>[...Q,{type:"assistant",content:`已切换到模型: **${F}**`,timestamp:Date.now()}])):z(F?Q=>[...Q,{type:"assistant",content:`无效的模型: ${F}
76
+
77
+ **可用模型**: ${T.join(", ")}`,timestamp:Date.now()}]:Q=>[...Q,{type:"assistant",content:`**当前模型**: ${wt}
78
+
79
+ **可用模型**: ${T.join(", ")}
80
+
81
+ 使用 \`/model <模型名>\` 切换模型,例如 \`/model opus\``,timestamp:Date.now()}]);break}case"cost":{let T;P.usage?T=`**Token 使用量**: ${P.usage.used.toLocaleString()} / ${P.usage.total.toLocaleString()} (${P.usage.percentage}%)
82
+
83
+ **剩余**: ${P.usage.remaining.toLocaleString()} tokens`:T=P.message||"无可用的 Token 使用数据。",z(F=>[...F,{type:"assistant",content:T,timestamp:Date.now()}]);break}case"memory":P.error?z(T=>[...T,{type:"assistant",content:`⚠️ ${P.message}`,timestamp:Date.now()}]):(z(T=>[...T,{type:"assistant",content:`📝 ${P.message}
84
+
85
+ Path: \`${He(P.path)}\``,timestamp:Date.now()}]),P.exists&&l&&l(P.path));break;case"config":k&&k();break;default:console.warn("Unknown built-in command action:",C)}},[l,k,wt]),ar=s.useRef(null),Sn=s.useCallback(async(c,C)=>{const{content:P,hasBashCommands:T,hasFileIncludes:F}=c;if(T&&!await G("此命令包含将被执行的 bash 命令。是否继续?",{title:"执行确认",variant:"warning",confirmText:"继续执行"})){z(fe=>[...fe,{type:"assistant",content:"❌ 命令执行已取消",timestamp:Date.now()}]);return}H(P),setTimeout(()=>{if(ar.current){const Q={preventDefault:()=>{}};ar.current(Q)}},50)},[]),Is=s.useCallback(async c=>{if(!(!c||!t))try{const C=v.match(new RegExp(`${c.name}\\s*(.*)`)),P=C&&C[1]?C[1].trim().split(/\s+/):[],T={projectPath:t.path,projectName:t.name,sessionId:E,provider:kt,model:wt,tokenUsage:Qr},F=await Y("/api/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandName:c.name,commandPath:c.path,args:P,context:T})});if(!F.ok)throw new Error("Failed to execute command");const Q=await F.json();Q.type==="builtin"?Nn(Q):Q.type==="custom"&&await Sn(Q,P),H(""),xt(!1),Rt(-1),Ce(""),Tt(-1)}catch(C){console.error("Error executing command:",C),z(P=>[...P,{type:"assistant",content:`Error executing command: ${C.message}`,timestamp:Date.now()}])}},[v,t,E,kt,wt,Qr]),ta=s.useMemo(()=>{const c=new Map;return(C,P)=>{const T=`${C.length}-${P.length}-${C.slice(0,50)}`;if(c.has(T))return c.get(T);const F=Cn(C,P);if(c.set(T,F),c.size>100){const Q=c.keys().next().value;c.delete(Q)}return F}},[]),ns=s.useCallback(async(c,C,P=!1,T="claude",F=!1)=>{if(!c||!C)return{messages:[],hasMore:!1};const Q=!P;F||(Q?De(!0):Me(!0));try{const fe=P?nt.current:0,je=await he.sessionMessages(c,C,ve,fe,T);if(!je.ok)throw new Error("Failed to load session messages");const X=await je.json();if(Q&&X.sessionImages)me.current=X.sessionImages;else if(P&&X.sessionImages){const de=new Set(me.current.map(ye=>ye.batchId)),be=X.sessionImages.filter(ye=>!de.has(ye.batchId));be.length>0&&(me.current=[...be,...me.current])}if(Q&&X.tokenUsage&&as(X.tokenUsage),X.hasMore!==void 0)return We(X.hasMore),Be(X.total),Ie(fe+(X.messages?.length||0)),{messages:X.messages||[],hasMore:X.hasMore};{const de=X.messages||[];return We(!1),Be(de.length),{messages:de,hasMore:!1}}}catch(fe){return console.error("Error loading session messages:",fe),{messages:[],hasMore:!1}}finally{F||(Q?De(!1):Me(!1))}},[Ie]),Cn=(c,C)=>{const P=c.split(`
86
+ `),T=C.split(`
87
+ `),F=[];let Q=0,fe=0;for(;Q<P.length||fe<T.length;){const je=P[Q],X=T[fe];Q>=P.length?(F.push({type:"added",content:X,lineNum:fe+1}),fe++):fe>=T.length?(F.push({type:"removed",content:je,lineNum:Q+1}),Q++):je===X?(Q++,fe++):(F.push({type:"removed",content:je,lineNum:Q+1}),F.push({type:"added",content:X,lineNum:fe+1}),Q++,fe++)}return F},sa=c=>{const C=[],P=new Map;for(const T of c)if(T.message?.role==="user"&&Array.isArray(T.message?.content))for(const F of T.message.content)F.type==="tool_result"&&P.set(F.tool_use_id,{content:F.content,isError:F.is_error,timestamp:new Date(T.timestamp||Date.now()),toolUseResult:T.toolUseResult||null});for(const T of c)if(!T.isMeta){if(T.message?.role==="user"&&T.message?.content){let F="",Q="user";if(Array.isArray(T.message.content)){const X=[];for(const de of T.message.content)de.type==="text"&&X.push(os(de.text));F=X.join(`
88
+ `)}else typeof T.message.content=="string"?F=os(T.message.content):F=os(String(T.message.content));const fe=F.match(/<command-name>(\/[^<]+)<\/command-name>/);fe&&(F=fe[1]),!F||F.startsWith("<command-args>")||F.startsWith("<local-command-stdout>")||F.startsWith("<system-reminder>")||F.startsWith("[Background Task Result]")||F.startsWith("<task-notification>")||F.startsWith("Caveat:")||F.startsWith("This session is being continued from a previous")||F.startsWith("[Request interrupted")||(F=F.replace(/(\n\n)?\[Images provided at the following paths:\]\n[\s\S]*$/,""),F=br(F),F&&C.push({type:Q,content:F,timestamp:T.timestamp||new Date().toISOString(),messageUuid:T.uuid||null}))}else if(T.type==="tool_use"&&T.toolName)C.push({type:"assistant",content:"",timestamp:T.timestamp||new Date().toISOString(),isToolUse:!0,toolName:T.toolName,toolInput:T.toolInput||"",toolCallId:T.toolCallId});else if(T.type==="tool_result"){for(let F=C.length-1;F>=0;F--)if(C[F].isToolUse&&!C[F].toolResult&&(!T.toolCallId||C[F].toolCallId===T.toolCallId)){C[F].toolResult={content:T.output||"",isError:!1};break}}else if(T.message?.role==="assistant"&&T.message?.content){if(Array.isArray(T.message.content)){for(const F of T.message.content)if(F.type==="text"){let Q=F.text;typeof Q=="string"&&(Q=br(Q)),C.push({type:"assistant",content:Q,timestamp:T.timestamp||new Date().toISOString(),messageUuid:T.uuid||null})}else if(F.type==="tool_use"){const Q=P.get(F.id);C.push({type:"assistant",content:"",timestamp:T.timestamp||new Date().toISOString(),isToolUse:!0,toolName:F.name,toolInput:JSON.stringify(F.input),toolResult:Q?{content:typeof Q.content=="string"?Q.content:JSON.stringify(Q.content),isError:Q.isError,toolUseResult:Q.toolUseResult}:null,toolError:Q?.isError||!1,toolResultTimestamp:Q?.timestamp||new Date})}}else if(typeof T.message.content=="string"){let F=T.message.content;F=br(F),C.push({type:"assistant",content:F,timestamp:T.timestamp||new Date().toISOString(),messageUuid:T.uuid||null})}}}return C},nr=s.useMemo(()=>sa(J),[J]),Nt=s.useCallback(()=>{pe.current&&(pe.current.scrollTop=pe.current.scrollHeight)},[]),Ls=s.useCallback(()=>{if(!pe.current)return!1;const{scrollTop:c,scrollHeight:C,clientHeight:P}=pe.current;return C-c-P<50},[]),En=s.useCallback(async c=>{if(await G("将基于此消息之前的对话历史创建一个新的会话分支,原会话保持不变。",{title:"创建会话分支",confirmText:"创建分支",cancelText:"取消",variant:"info"}))try{const P=await he.forkSession(t.name,E,c||void 0);if(!P.ok)throw new Error("Fork failed");const{newSessionId:T}=await P.json();y&&y(T)}catch(P){console.error("[Fork] Error:",P),U("创建会话分支失败,请稍后重试。",{variant:"error"})}},[t,E,y,G,U]),Mn=s.useCallback(async()=>{if(D.current||we||!Se||!r||!t)return;D.current=!0,Me(!0);const c=pe.current,C=c?.scrollHeight??0,P=c?.scrollTop??0,T=5;let F=[],Q=0,fe=!0;try{for(;Q<T&&fe;){const je=await ns(t.name,r.id,!0,"claude",!0);if(je.messages.length===0)break;F=[...je.messages,...F],Q+=cl(je.messages),fe=je.hasMore}F.length>0&&(M.current={height:C,top:P},le(je=>[...F,...je]))}finally{Me(!1),D.current=!1}},[Se,we,r,t,ns]),or=s.useCallback(()=>{pe.current&&ss(!Ls())},[Ls]);s.useLayoutEffect(()=>{if(!M.current||!pe.current)return;const{height:c,top:C}=M.current,P=pe.current,F=P.scrollHeight-c;P.scrollTop=C+Math.max(F,0),M.current=null,setTimeout(()=>{pe.current&&pe.current.scrollTop>=100&&(ue.current=!1)},300)},[N.length]),s.useEffect(()=>{(async()=>{if(r&&t){const C=localStorage.getItem("selected-provider")||"claude";tt.current=!0;const P=E!==null&&E!==r.id;if(P?(Ie(0),We(!1),Be(0),as(null),S(!1),a&&o&&o({type:"check-session-status",sessionId:r.id,provider:C})):E===null&&(Ie(0),We(!1),Be(0),a&&o&&o({type:"check-session-status",sessionId:r.id,provider:C})),O(r.id),Le)qe(!1);else{const{messages:T}=await ns(t.name,r.id,!1,"claude");le(T),P&&z(sa(T))}}else!Le&&!q&&(z([]),le([]),me.current=[]),O(null),Ie(0),We(!1),Be(0);setTimeout(()=>{tt.current=!1},250)})()},[r,t,Nt,Le]),s.useEffect(()=>{if(a&&r&&t){const c=localStorage.getItem("selected-provider")||"claude";o({type:"check-session-status",sessionId:r.id,provider:c})}},[a]),s.useEffect(()=>{p>0&&r&&t&&(async()=>{try{const{messages:C}=await ns(t.name,r.id,!1,"claude");le(C),L&&Ls()&&setTimeout(()=>Nt(),200)}catch(C){console.error("Error reloading messages from external update:",C)}})()},[p,r,t,ns,Ls,L,Nt]),s.useEffect(()=>{J.length>0&&!q&&z(c=>{const C=new Map;for(const Q of c)Q.type==="user"&&Q.images?.length>0&&C.set(Q.content,Q.images);const P=new Map;for(const Q of me.current)if(Q.messageContent){const fe=Q.images.map(X=>({id:X.id,name:X.name})),je=P.get(Q.messageContent)||[];P.set(Q.messageContent,[...je,...fe])}const T=C.size>0,F=P.size>0;return!T&&!F?nr:nr.map(Q=>Q.type!=="user"?Q:T&&C.has(Q.content)?{...Q,images:C.get(Q.content)}:F&&P.has(Q.content)?{...Q,images:P.get(Q.content)}:Q)})},[nr,J,q]),s.useEffect(()=>{i&&i(se)},[se,i]),s.useEffect(()=>{t&&v!==""?mt.setItem(`draft_input_${t.name}`,v):t&&v===""&&mt.removeItem(`draft_input_${t.name}`)},[v,t]),s.useEffect(()=>{t&&N.length>0&&mt.setItem(`chat_messages_${t.name}`,JSON.stringify(N))},[N,t]),s.useEffect(()=>{if(t){const c=mt.getItem(`draft_input_${t.name}`)||"";c!==v&&H(c)}},[t?.name]),s.useEffect(()=>{E&&q&&f&&f(E)},[q,E,f]),s.useEffect(()=>{E&&g&&g.has(E)&&!q&&(S(!0),ht(!0))},[E,g]),s.useEffect(()=>{if(n.length>0){const c=n[n.length-1];if(!["projects_updated","session-created","claude-complete","background-task-complete"].includes(c.type)&&c.sessionId&&E&&c.sessionId!==E){console.log("⏭️ Skipping message for different session:",c.sessionId,"current:",E);return}switch(c.type){case"session-created":c.sessionId&&!E&&(sessionStorage.setItem("pendingSessionId",c.sessionId),qe(!0),h&&h(c.sessionId),_e(X=>X.map(de=>de.sessionId?de:{...de,sessionId:c.sessionId})));break;case"token-budget":c.data&&as(c.data);break;case"claude-api-retry":jt({text:`API 请求失败,正在重试 (${c.attempt}/${c.maxRetries})${c.errorStatus?` [HTTP ${c.errorStatus}]`:""}`,tokens:0,can_interrupt:!0});break;case"claude-response":if(c.data.isMeta)return;const T=c.data.message||c.data;if(T&&typeof T=="object"&&T.type){if(T.type==="content_block_delta"&&T.delta?.text){const X=os(T.delta.text);Xe.current+=X,ot.current||(ot.current=setTimeout(()=>{const de=Xe.current;Xe.current="",ot.current=null,de&&z(be=>{const ye=[...be],at=ye[ye.length-1];return at&&at.type==="assistant"&&!at.isToolUse&&at.isStreaming?at.content=(at.content||"")+de:ye.push({type:"assistant",content:de,timestamp:new Date,isStreaming:!0}),ye})},100));return}if(T.type==="content_block_stop"){ot.current&&(clearTimeout(ot.current),ot.current=null);const X=Xe.current;Xe.current="",X&&z(de=>{const be=[...de],ye=be[be.length-1];return ye&&ye.type==="assistant"&&!ye.isToolUse&&ye.isStreaming?ye.content=(ye.content||"")+X:be.push({type:"assistant",content:X,timestamp:new Date,isStreaming:!0}),be}),z(de=>{const be=[...de],ye=be[be.length-1];return ye&&ye.type==="assistant"&&ye.isStreaming&&(ye.isStreaming=!1),be});return}}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&E&&c.data.session_id!==E){console.log("🔄 Claude CLI session duplication detected:",{originalSession:E,newSession:c.data.session_id}),qe(!0),y&&y(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&!E){console.log("🔄 New session init detected:",{newSession:c.data.session_id}),qe(!0),y&&y(c.data.session_id);return}if(c.data.type==="system"&&c.data.subtype==="init"&&c.data.session_id&&E&&c.data.session_id===E){console.log("🔄 System init message for current session, ignoring");return}const F=T.role==="user"||c.data.type==="user";if(Array.isArray(T.content)&&!F){for(const X of T.content)if(X.type==="tool_use"){const de=X.input?JSON.stringify(X.input,null,2):"";z(be=>[...be,{type:"assistant",content:"",timestamp:new Date,isToolUse:!0,toolName:X.name,toolInput:de,toolId:X.id,toolResult:null}])}else if(X.type==="text"&&X.text?.trim()){let de=os(X.text);de=Lr(de),z(be=>[...be,{type:"assistant",content:de,timestamp:new Date}])}}else if(typeof T.content=="string"&&T.content.trim()&&!F){let X=os(T.content);X=Lr(X),z(de=>[...de,{type:"assistant",content:X,timestamp:new Date}])}if(T.role==="user"&&Array.isArray(T.content))for(const X of T.content)X.type==="tool_result"&&z(de=>de.map(be=>be.isToolUse&&be.toolId===X.tool_use_id?{...be,toolResult:{content:typeof X.content=="string"?X.content:JSON.stringify(X.content),isError:X.is_error,timestamp:new Date}}:be));break;case"claude-output":{const X=String(c.data||"");X.trim()&&(Xe.current+=Xe.current?`
89
+ ${X}`:X,ot.current||(ot.current=setTimeout(()=>{const de=Xe.current;Xe.current="",ot.current=null,de&&z(be=>{const ye=[...be],at=ye[ye.length-1];return at&&at.type==="assistant"&&!at.isToolUse&&at.isStreaming?at.content=at.content?`${at.content}
90
+ ${de}`:de:ye.push({type:"assistant",content:de,timestamp:new Date,isStreaming:!0}),ye})},100)))}break;case"claude-interactive-prompt":z(X=>[...X,{type:"assistant",content:c.data,timestamp:new Date,isInteractivePrompt:!0}]);break;case"claude-permission-request":{if(!c.requestId)break;_e(X=>X.some(de=>de.requestId===c.requestId)?X:[...X,{requestId:c.requestId,toolName:c.toolName||"UnknownTool",input:c.input,context:c.context,sessionId:c.sessionId||null,receivedAt:new Date}]),S(!0),ht(!0),jt({text:"等待权限",tokens:0,can_interrupt:!0});break}case"claude-permission-cancelled":{if(!c.requestId)break;_e(X=>X.filter(de=>de.requestId!==c.requestId));break}case"share-project-template-request":{if(!c.requestId)break;Ye({requestId:c.requestId,prefillData:c.prefillData||{}}),S(!0),ht(!0),jt({text:"等待分享模板",tokens:0,can_interrupt:!0});break}case"background-task-complete":{const X=c;if(X.sessionId!==E){console.log(`[BgTask] Result for session ${X.sessionId}, current is ${E}, queuing.`),lt.current.push(X);break}if(q){console.log(`[BgTask] Session busy, queuing result ${X.taskId}`),lt.current.push(X);break}oa(X);break}case"claude-error":z(X=>[...X,{type:"error",content:`错误: ${c.error}`,timestamp:new Date}]),S(!1),ht(!1),jt(null),_e([]),E&&(u&&u(E),x&&x(E));break;case"claude-complete":const Q=c.sessionId||E||sessionStorage.getItem("pendingSessionId");(Q===E||!E)&&(S(!1),ht(!1),jt(null)),Q&&(u&&u(Q),x&&x(Q));const fe=sessionStorage.getItem("pendingSessionId");if(fe&&!E&&c.exitCode===0&&(O(fe),sessionStorage.removeItem("pendingSessionId"),console.log("✅ New session complete, ID set to:",fe)),t&&c.exitCode===0&&mt.removeItem(`chat_messages_${t.name}`),Q===E&&_e([]),ze.current.delete(Q),lt.current.length>0&&Q===E){const X=lt.current.findIndex(de=>de.sessionId===E);if(X>=0){const de=lt.current.splice(X,1)[0];setTimeout(()=>oa(de),100)}}break;case"session-aborted":{const X=c.sessionId||E;X===E&&(S(!1),ht(!1),jt(null)),X&&(u&&u(X),x&&x(X)),_e([]),z(de=>[...de,{type:"assistant",content:"会话已被用户中断。",timestamp:new Date}]);break}case"session-status":{const X=c.sessionId;(X===E||r&&X===r.id)&&(c.isProcessing?(S(!0),ht(!0),f&&f(X)):q&&(S(!1),ht(!1),x&&x(X),t?.name&&ns(t.name,X,!1,"claude").then(({messages:be})=>le(be))));break}case"claude-status":const je=c.data;if(je){let X={text:"处理中...",tokens:0,can_interrupt:!0};je.message?X.text=je.message:je.status?X.text=je.status:typeof je=="string"&&(X.text=je),je.tokens?X.tokens=je.tokens:je.token_count&&(X.tokens=je.token_count),je.can_interrupt!==void 0&&(X.can_interrupt=je.can_interrupt),jt(X),S(!0),ht(X.can_interrupt)}break}}},[n]),s.useEffect(()=>{t&&In()},[t]);const In=async()=>{try{const c=await he.getFiles(t.name);if(c.ok){const C=await c.json(),P=ra(C);Ht(P)}}catch(c){console.error("Error fetching files:",c)}},ra=(c,C="")=>{let P=[];for(const T of c){const F=C?`${C}/${T.name}`:T.name;T.type==="directory"&&T.children?P=P.concat(ra(T.children,F)):T.type==="file"&&P.push({name:T.name,path:F,relativePath:T.path})}return P};s.useEffect(()=>{const c=v.slice(0,Es),C=c.lastIndexOf("@");if(C!==-1){const P=c.slice(C+1);if(P.includes(" "))yt(!1),ts(-1);else{ts(C),yt(!0);const T=Cs.filter(F=>F.name.toLowerCase().includes(P.toLowerCase())||F.path.toLowerCase().includes(P.toLowerCase())).slice(0,10);ds(T),vt(-1)}}else yt(!1),ts(-1)},[v,Es,Cs]),s.useEffect(()=>{const c=setTimeout(()=>{Bt(v)},150);return()=>clearTimeout(c)},[v]);const Ts=s.useMemo(()=>N.length<=hs?N:N.slice(-hs),[N,hs]),aa=s.useMemo(()=>Ts.filter(c=>!c.isToolUse),[Ts]),_t=s.useMemo(()=>Ts.filter(c=>c.isToolUse),[Ts]),Ln=s.useMemo(()=>N.filter(c=>!c.isToolUse).length,[N]),na=s.useMemo(()=>N.filter(c=>c.isToolUse).length,[N]);s.useEffect(()=>{if(!L&&pe.current){const c=pe.current;rs.current={height:c.scrollHeight,top:c.scrollTop}}}),s.useEffect(()=>{if(pe.current&&N.length>0)if(L)Jt||setTimeout(()=>Nt(),50);else{const c=pe.current,C=rs.current.height,P=rs.current.top,F=c.scrollHeight-C;F>0&&P>0&&(c.scrollTop=P+F)}},[N.length,Jt,Nt,L]),s.useEffect(()=>{pe.current&&N.length>0&&!tt.current&&(ss(!1),setTimeout(()=>{Nt()},200))},[r?.id,t?.name]),s.useEffect(()=>{const c=pe.current;if(c)return c.addEventListener("scroll",or),()=>c.removeEventListener("scroll",or)},[or]),s.useEffect(()=>{const c=P=>{if(!sr)return;const T=ne.current;if(!T)return;const F=T.parentElement;if(!F)return;const fe=F.getBoundingClientRect().right-P.clientX;fe>=300&&fe<=600&&vn(fe)},C=()=>Zr(!1);return sr&&(document.addEventListener("mousemove",c),document.addEventListener("mouseup",C),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",C),document.body.style.cursor="",document.body.style.userSelect=""}},[sr]),s.useEffect(()=>{!er&&_t.length>0&&!$t&&tr(!0)},[_t.length]),s.useEffect(()=>{$t&&W.current&&(W.current.scrollTop=W.current.scrollHeight)},[_t.length,$t]),s.useEffect(()=>{Pe.length>0&&setTimeout(()=>{Jt||Nt(),$t&&W.current&&(W.current.scrollTop=W.current.scrollHeight)},100)},[Pe.length,Jt,Nt,$t]),s.useEffect(()=>{if(ae.current){ae.current.style.height="auto",ae.current.style.height=ae.current.scrollHeight+"px";const c=parseInt(window.getComputedStyle(ae.current).lineHeight),C=ae.current.scrollHeight>c*2;Ve(C)}},[]),s.useEffect(()=>{ae.current&&!v.trim()&&(ae.current.style.height="auto",Ve(!1))},[v]),s.useEffect(()=>{if(!t||!r?.id||r.id.startsWith("new-session-")){as(null);return}(async()=>{try{const C=`/api/projects/${t.name}/sessions/${r.id}/token-usage`,P=await Y(C);if(P.ok){const T=await P.json();as(T)}else as(null)}catch(C){console.error("Failed to fetch initial token usage:",C)}})()},[r?.id,r?.__provider,t?.path]);const Tn=s.useCallback(c=>{c.trim()&&H(C=>{const P=C.trim()?`${C} ${c}`:c;return setTimeout(()=>{if(ae.current){ae.current.style.height="auto",ae.current.style.height=ae.current.scrollHeight+"px";const T=parseInt(window.getComputedStyle(ae.current).lineHeight),F=ae.current.scrollHeight>T*2;Ve(F)}},0),P})},[]),Rn=s.useCallback(()=>{bn(c=>c+100)},[]),Rs=s.useCallback(c=>{const C=c.filter(P=>{try{if(!P||typeof P!="object")return console.warn("Invalid file object:",P),!1;if(!P.type||!P.type.startsWith("image/"))return!1;if(!P.size||P.size>5242880){const T=P.name||"Unknown file";return K(F=>{const Q=new Map(F);return Q.set(T,"文件太大(最大 5MB)"),Q}),!1}return!0}catch(T){return console.error("Error validating file:",T,P),!1}});C.length>0&&w(P=>[...P,...C].slice(0,5))},[]),Dn=s.useCallback(async c=>{const C=c.target.files;if(!(!C||C.length===0||!t)){ce(!0);try{const P=new FormData;Array.from(C).forEach(Q=>{P.append("files",Q)});const T=await he.uploadFiles(t.name,P);if(!T.ok){const Q=await T.json();throw new Error(Q.error||"上传失败")}const F=await T.json();if(F.files&&F.files.length>0){const Q=F.files.map(je=>`@${je.name}`).join(" "),fe=v?`${v} ${Q} `:`${Q} `;H(fe),ae.current&&ae.current.focus()}}catch(P){console.error("File upload failed:",P)}finally{ce(!1),Te.current&&(Te.current.value="")}}},[t,v]),Pn=s.useCallback(async c=>{const C=Array.from(c.clipboardData.items);for(const P of C)if(P.type.startsWith("image/")){const T=P.getAsFile();T&&Rs([T])}if(C.length===0&&c.clipboardData.files.length>0){const T=Array.from(c.clipboardData.files).filter(F=>F.type.startsWith("image/"));T.length>0&&Rs(T)}},[Rs]),{getRootProps:An,getInputProps:$n,isDragActive:_n,open:zn}=Br({accept:{"image/*":[".png",".jpg",".jpeg",".gif",".webp",".svg"]},maxSize:5*1024*1024,maxFiles:5,onDrop:Rs,noClick:!0,noKeyboard:!0}),oa=s.useCallback(c=>{if(!a||!o||!t)return;const C=["[Background Task Result]",`Task ID: ${c.taskId}`,`Command: ${c.command}`,`Status: ${c.status} (exit code: ${c.exitCode??"N/A"})`,`Duration: ${Math.round((c.duration||0)/1e3)}s`];c.truncated&&C.push("(Output truncated to 100KB)"),c.stdout&&C.push("","STDOUT:",c.stdout),c.stderr&&C.push("","STDERR:",c.stderr);const P=C.join(`
91
+ `);let T={allowedTools:[],disallowedTools:[],skipPermissions:!1};try{const F=mt.getItem("claude-settings");F&&(T=JSON.parse(F))}catch{}o({type:"claude-command",command:P,options:{projectPath:t.path,cwd:t.fullPath,sessionId:c.sessionId,resume:!0,isBackgroundResult:!0,toolsSettings:T,permissionMode:ke,model:wt}}),S(!0),ht(!0),jt({text:"处理后台任务结果",tokens:0,can_interrupt:!0})},[a,o,t,ke,wt]),Gt=s.useCallback(async c=>{if(c.preventDefault(),!v.trim()||q||!t||Fe.current)return;Fe.current=!0;const C=v.trim();if(C.startsWith("/")){const de=C.indexOf(" "),be=de!==-1?C.slice(0,de):C,ye=ft.find(at=>at.name===be&&at.namespace==="builtin");if(ye){Fe.current=!1,Is(ye);return}}if(R){const de=await R();if(de&&!de.allowed){Fe.current=!1,j?.(de.reason);return}}let P=[],T=null;if($.length>0){const de=new FormData;$.forEach(be=>{de.append("images",be)});try{const be=await Y(`/api/projects/${t.name}/upload-images`,{method:"POST",headers:{},body:de});if(!be.ok)throw new Error("图片上传失败");const ye=await be.json();P=ye.images,T=ye.uploadBatchId||null}catch(be){console.error("Image upload failed:",be),Fe.current=!1,z(ye=>[...ye,{type:"error",content:`图片上传失败: ${be.message}`,timestamp:new Date}]);return}}const F={type:"user",content:v,images:P,timestamp:new Date};z(de=>[...de,F]),S(!0),Fe.current=!1,ht(!0),jt({text:"处理中",tokens:0,can_interrupt:!0}),ss(!1),setTimeout(()=>Nt(),100);const fe=E||r?.id||`new-session-${Date.now()}`;d&&d(fe);const X=(()=>{try{const de=mt.getItem("claude-settings");if(de)return JSON.parse(de)}catch(de){console.error("Error loading tools settings:",de)}return{allowedTools:[],disallowedTools:[],skipPermissions:!1}})();E||($e.current=ke),o({type:"claude-command",command:v,options:{projectPath:t.path,cwd:t.fullPath,sessionId:E,resume:!!E,toolsSettings:X,permissionMode:ke,model:wt,images:P,uploadBatchId:T}}),H(""),w([]),A(new Map),K(new Map),Ve(!1),ae.current&&(ae.current.style.height="auto"),t&&mt.removeItem(`draft_input_${t.name}`)},[v,q,t,$,E,r,kt,ke,d,wt,o,H,w,A,K,Ve,ae,z,S,ht,jt,ss,Nt,R,j,Is,ft]),ir=s.useCallback(c=>!c||kt!=="claude"?{success:!1}:il(c.entry),[kt]),gs=s.useCallback((c,C)=>{const T=(Array.isArray(c)?c:[c]).filter(Boolean);T.length!==0&&(T.forEach(F=>{o({type:"claude-permission-response",requestId:F,allow:!!C?.allow,updatedInput:C?.updatedInput,message:C?.message,rememberEntry:C?.rememberEntry})}),_e(F=>{const Q=F.filter(fe=>!T.includes(fe.requestId));return Q.length===0&&jt(null),Q}))},[o]),ia=s.useCallback(c=>{Ae&&(o({type:"share-project-template-response",requestId:Ae.requestId,...c}),Ye(null))},[Ae,o]);s.useEffect(()=>{ar.current=Gt},[Gt]);const la=c=>{if(!c)return;const C=v.slice(0,Xr),P=v.slice(Xr),T=P.indexOf(" "),F=T!==-1?P.slice(T):"",Q=C+c.name+" "+F;if(H(Q),xt(!1),Rt(-1),Ce(""),Tt(-1),pt.current&&clearTimeout(pt.current),c.namespace==="skill"||c.namespace==="mcp"){ae.current&&ae.current.focus();return}Is(c)},On=c=>{if(us&&_.length>0){if(c.key==="ArrowDown"){c.preventDefault(),Tt(C=>C<_.length-1?C+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),Tt(C=>C>0?C-1:_.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),Zs>=0?la(_[Zs]):_.length>0&&la(_[0]);return}if(c.key==="Escape"){c.preventDefault(),xt(!1),Rt(-1),Ce(""),Tt(-1),pt.current&&clearTimeout(pt.current);return}}if(cs&&Et.length>0){if(c.key==="ArrowDown"){c.preventDefault(),vt(C=>C<Et.length-1?C+1:0);return}if(c.key==="ArrowUp"){c.preventDefault(),vt(C=>C>0?C-1:Et.length-1);return}if(c.key==="Tab"||c.key==="Enter"){c.preventDefault(),ms>=0?lr(Et[ms]):Et.length>0&&lr(Et[0]);return}if(c.key==="Escape"){c.preventDefault(),yt(!1);return}}if(c.key==="Tab"&&!cs&&!us){c.preventDefault();const C=["default","acceptEdits","bypassPermissions","plan"],T=(C.indexOf(ke)+1)%C.length,F=C[T];Je(F),r?.id&&localStorage.setItem(`permissionMode-${r.id}`,F);return}if(c.key==="Enter"){if(c.nativeEvent.isComposing)return;(c.ctrlKey||c.metaKey)&&!c.shiftKey?(c.preventDefault(),Gt(c)):!c.shiftKey&&!c.ctrlKey&&!c.metaKey&&(I||(c.preventDefault(),Gt(c)))}},lr=c=>{const C=v.slice(0,Ms),P=v.slice(Ms),T=P.indexOf(" "),F=T!==-1?P.slice(T):"",Q=C+"@"+c.path+" "+F,fe=C.length+1+c.path.length+1;ae.current&&!ae.current.matches(":focus")&&ae.current.focus(),H(Q),qt(fe),yt(!1),ts(-1),ae.current&&requestAnimationFrame(()=>{ae.current&&(ae.current.setSelectionRange(fe,fe),ae.current.matches(":focus")||ae.current.focus())})},Fn=c=>{const C=c.target.value,P=c.target.selectionStart;if(!E&&C.trim(),H(C),qt(P),!C.trim()){c.target.style.height="auto",Ve(!1),xt(!1),Rt(-1),Ce("");return}const T=C.slice(0,P);if((T.match(/```/g)||[]).length%2===1){xt(!1),Rt(-1),Ce("");return}const fe=/(^|\s)\/(\S*)$/,je=T.match(fe);if(je){const X=je.index+je[1].length,de=je[2];Rt(X),xt(!0),Tt(-1),pt.current&&clearTimeout(pt.current),pt.current=setTimeout(()=>{Ce(de)},150)}else xt(!1),Rt(-1),Ce(""),pt.current&&clearTimeout(pt.current)},Un=c=>{qt(c.target.selectionStart)},Wn=()=>{E&&Xs&&o({type:"abort-session",sessionId:E,provider:kt})},Bn=()=>{const c=["default","acceptEdits","bypassPermissions","plan"],P=(c.indexOf(ke)+1)%c.length,T=c[P];Je(T),r?.id&&localStorage.setItem(`permissionMode-${r.id}`,T)};return t?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
92
+ details[open] .details-chevron {
93
+ transform: rotate(180deg);
94
+ }
95
+ `}),e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsx("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:e.jsxs("div",{ref:pe,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:[ge&&N.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:"正在加载会话消息..."})]})}):N.length===0?e.jsxs("div",{className:"flex items-center justify-center h-full",children:[!r&&!E&&e.jsxs("div",{className:"text-center px-6 sm:px-4 py-8 w-full max-w-xl mx-auto",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-3",children:"开始新对话"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-8",children:["已准备好使用 ",Ze,"。试试以下常用指令:"]}),ua.length>0&&e.jsx("div",{className:"grid grid-cols-2 gap-3",children:ua.map((c,C)=>e.jsxs("button",{onClick:()=>{H(c.text),setTimeout(()=>ae.current?.focus(),0)},className:"flex items-center gap-2.5 px-4 py-3 rounded-2xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-left text-sm text-gray-700 dark:text-gray-300 hover:border-purple-400 dark:hover:border-purple-500 hover:bg-purple-50 dark:hover:bg-purple-900/20 transition-colors",children:[e.jsx("span",{className:"text-base",children:c.icon}),e.jsx("span",{children:c.text})]},C))})]}),r&&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:[we&&e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400 py-3",children:e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"}),e.jsx("p",{className:"text-sm",children:"正在加载历史消息..."})]})}),Se&&!we&&e.jsxs("div",{className:"text-center py-2 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400 mr-2",children:["已显示 ",Ln," 条对话",na>0?`,${na} 个工具调用`:""]}),e.jsx("button",{onClick:Mn,className:"text-xs text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline",children:"加载更多消息"})]}),!Se&&N.length>hs&&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:["显示最近 ",hs," 条消息(共 ",N.length," 条) •",e.jsx("button",{className:"ml-1 text-blue-600 hover:text-blue-700 underline",onClick:Rn,children:"加载更早的消息"})]}),aa.map((c,C)=>{const P=C>0?aa[C-1]:null,T=c.id||`${c.type}-${c.timestamp?.getTime?.()||C}-${C}`;return e.jsx(Da,{message:c,index:C,prevMessage:P,createDiff:ta,onFileOpen:l,onShowSettings:k,onGrantToolPermission:ir,selectedProject:t,provider:kt,onFork:c.type==="assistant"&&!q&&E?En:null,messageUuid:c.messageUuid||null},T)})]}),q&&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(Ks,{className:"w-full h-full"})}),e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:Ze})]}),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:Re})]})}),!er&&_t.length>0&&e.jsx("button",{onClick:()=>tr(c=>!c),className:"flex-shrink-0 w-4 self-stretch flex items-center justify-center bg-gray-100 dark:bg-gray-800/80 hover:bg-blue-50 dark:hover:bg-blue-900/30 border-x border-gray-200 dark:border-gray-700 transition-colors cursor-pointer",title:$t?"收起工具面板":"展开工具面板",children:e.jsx("svg",{className:"w-3 h-3 text-gray-400 dark:text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:$t?"M9 5l7 7-7 7":"M15 19l-7-7 7-7"})})}),$t&&!er&&_t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:ne,onMouseDown:c=>{Zr(!0),c.preventDefault()},className:"flex-shrink-0 w-1 bg-border hover:bg-blue-400 cursor-col-resize transition-colors duration-150"}),e.jsxs("div",{style:{width:`${yn}px`},className:"flex-shrink-0 border-l border-gray-200 dark:border-gray-700 flex flex-col overflow-hidden bg-gray-50 dark:bg-gray-900/50",children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-3 py-2 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"w-4 h-4 text-blue-500",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("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"工具调用"}),e.jsx("span",{className:"px-1.5 py-0.5 text-xs rounded-full bg-blue-100 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300",children:_t.length})]}),e.jsx("button",{onClick:()=>tr(!1),className:"p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",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.jsxs("div",{ref:W,className:"flex-1 overflow-y-auto p-2 space-y-2",children:[_t.map((c,C)=>{const P=C>0?_t[C-1]:null,T=c.id||`tool-${c.timestamp?.getTime?.()||C}-${C}`;return e.jsx(Da,{message:c,index:C,prevMessage:P,createDiff:ta,onFileOpen:l,onShowSettings:k,onGrantToolPermission:ir,selectedProject:t,provider:kt},T)}),e.jsx("div",{ref:Ne})]})]})]})]}),e.jsxs("div",{className:"p-2 sm:p-4 md:p-4 flex-shrink-0 border-t border-gray-200 dark:border-gray-700 pb-2 sm:pb-4 md:pb-6",children:[e.jsx("div",{className:"flex-1",children:e.jsx(tl,{status:jn,isLoading:q,onAbort:Wn,provider:kt})}),e.jsxs("div",{ref:Ee,className:"max-w-4xl mx-auto mb-3",children:[Pe.length>0&&e.jsx("div",{className:"mb-3 space-y-2",children:Pe.map(c=>{const C=Ra(c.input),P=Tr(c.toolName,C),T=Hr(),F=P?T.allowedTools.includes(P):!1,Q=F?"已允许(已保存)":"允许并记住",fe=P?Pe.filter(je=>Tr(je.toolName,Ra(je.input))===P).map(je=>je.requestId):[c.requestId];return c.toolName==="AskUserQuestion"?e.jsx(dl,{request:c,onSubmit:je=>{gs(c.requestId,{allow:!0,updatedInput:{...c.input,answers:je}})},onSkip:()=>gs(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})]})]}),P&&e.jsxs("div",{className:"text-xs text-amber-700 dark:text-amber-300",children:["允许规则: ",e.jsx("span",{className:"font-mono",children:He(P)})]})]}),C&&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:He(C)})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>gs(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:()=>{P&&!F&&ir({entry:P,toolName:c.toolName}),gs(fe,{allow:!0,rememberEntry:P})},className:`inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border transition-colors ${P?"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:!P,children:Q}),e.jsx("button",{type:"button",onClick:()=>gs(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:Bn,className:`px-3 py-1.5 rounded-lg text-sm font-medium border transition-all duration-200 ${ke==="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":ke==="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":ke==="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 ${ke==="default"?"bg-gray-500":ke==="acceptEdits"?"bg-green-500":ke==="bypassPermissions"?"bg-orange-500":"bg-blue-500"}`}),e.jsxs("span",{children:[ke==="default"&&"默认模式",ke==="acceptEdits"&&"接受编辑",ke==="bypassPermissions"&&"跳过权限",ke==="plan"&&"计划模式"]})]})}),e.jsx("button",{ref:It,type:"button",onClick:()=>ps(!Kt),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:fr.OPTIONS.find(c=>c.value===wt)?.label||wt})]})}),v.trim()&&e.jsx("button",{type:"button",onClick:c=>{c.preventDefault(),c.stopPropagation(),H(""),ae.current&&(ae.current.style.height="auto",ae.current.focus()),Ve(!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"})})}),Jt&&N.length>0&&e.jsx("button",{onClick:Nt,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:Gt,className:"relative max-w-4xl mx-auto",children:[_n&&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:"将图片拖放到这里"})]})}),$.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:$.map((c,C)=>e.jsx(ml,{file:c,onRemove:()=>{w(P=>P.filter((T,F)=>F!==C))},uploadProgress:ee.get(c.name),error:te.get(c.name)},C))})}),cs&&Et.length>0&&e.jsx("div",{className:"absolute bottom-full left-0 right-0 mb-2 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg shadow-lg max-h-48 overflow-y-auto z-50 backdrop-blur-sm",children:Et.map((c,C)=>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 ${C===ms?"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:P=>{P.preventDefault(),P.stopPropagation()},onClick:P=>{P.preventDefault(),P.stopPropagation(),lr(c)},children:[e.jsx("div",{className:"font-medium text-sm",children:c.name}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 font-mono",children:He(c.path)})]},c.path))}),e.jsx(al,{commands:_,selectedIndex:Zs,onSelect:kn,onClose:()=>{xt(!1),Rt(-1),Ce(""),Tt(-1)},position:{top:ae.current?Math.max(16,ae.current.getBoundingClientRect().top-316):0,left:ae.current?ae.current.getBoundingClientRect().left:16,bottom:ae.current?window.innerHeight-ae.current.getBoundingClientRect().top+8:90},isOpen:us,frequentCommands:xe?[]:wn}),Kt&&e.jsxs("div",{ref:xs,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:It.current?window.innerHeight-It.current.getBoundingClientRect().top+8:90,left:It.current?It.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:wt,onChange:c=>{const C=c.target.value;ea(C),localStorage.setItem("claude-model",C),ps(!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:fr.OPTIONS.map(({value:c,label:C})=>e.jsx("option",{value:c,children:C},c))})]}),e.jsxs("div",{...An(),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 ${gt?"chat-input-expanded":""}`,children:[e.jsx("input",{...$n()}),e.jsx("textarea",{ref:ae,value:v,onChange:Fn,onClick:Un,onKeyDown:On,onPaste:Pn,onFocus:()=>re(!0),onBlur:()=>re(!1),onInput:c=>{c.target.style.height="auto",c.target.style.height=c.target.scrollHeight+"px",qt(c.target.selectionStart);const C=parseInt(window.getComputedStyle(c.target).lineHeight),P=c.target.scrollHeight>C*2;Ve(P)},placeholder:m&&!m.allowed?m.reason==="total_limit_exceeded"?"使用上限已达到,请联系管理员":"今日使用上限已达到":`输入 / 使用命令,@ 引用文件,或向 ${Ze} 提问...`,disabled:q||m&&!m.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:zn,disabled:m&&!m.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:m&&!m.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:Te,onChange:Dn,className:"hidden",multiple:!0}),e.jsx("button",{type:"button",onClick:()=>Te.current?.click(),disabled:oe||!t||m&&!m.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:m&&!m.allowed?"使用上限已达到":"上传文件并引用",children:oe?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(rl,{onTranscript:Tn,className:"w-10 h-10 sm:w-10 sm:h-10"})}),e.jsx("button",{type:"submit",disabled:!v.trim()||q,onMouseDown:c=>{c.preventDefault(),Gt(c)},onTouchStart:c=>{c.preventDefault(),Gt(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 ${v.trim()?"opacity-0":"opacity-100"}`,children:I?"Ctrl+Enter 发送 • Shift+Enter 换行 • Tab 切换模式 • / 使用命令":"Enter 发送 • Shift+Enter 换行 • Tab 切换模式 • / 使用命令"})]})]})]})]}),Ae&&e.jsx(Ur,{prefillData:Ae.prefillData,onClose:()=>ia({cancelled:!0}),onSubmitted:c=>ia({success:!0,...c})})]}):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 pl=ut.memo(ul);function Rr({file:t,onClose:r,projectPath:a,isSidebar:o=!1,isExpanded:n=!1,onToggleExpand:l=null}){const{showAlert:i}=dt(),[d,u]=s.useState(""),[f,x]=s.useState(!0),[g,h]=s.useState(!1),[y,k]=s.useState(!1),[L,I]=s.useState(()=>{const O=localStorage.getItem("codeEditorTheme");return O?O==="dark":!0}),[p,b]=s.useState(!1),[m,j]=s.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[R,G]=s.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[U,v]=s.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),H=s.useRef(null),N=s.useMemo(()=>{const O=()=>{const se=document.createElement("div");se.className="cm-editor-toolbar-panel";const re=()=>{let J='<div style="display: flex; align-items: center; justify-content: flex-end; width: 100%;">';J+='<div style="display: flex; align-items: center; gap: 4px;">',J+=`
96
+ <button class="cm-toolbar-btn cm-settings-btn" title="Editor Settings">
97
+ <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
98
+ <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" />
99
+ </svg>
100
+ </button>
101
+ `,o&&l&&(J+=`
102
+ <button class="cm-toolbar-btn cm-expand-btn" title="${n?"Collapse editor":"Expand editor to full width"}">
103
+ <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
104
+ ${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" />'}
105
+ </svg>
106
+ </button>
107
+ `),J+="</div>",J+="</div>",se.innerHTML=J,se.querySelector(".cm-settings-btn")?.addEventListener("click",()=>{window.openSettings&&window.openSettings("appearance")}),o&&l&&se.querySelector(".cm-expand-btn")?.addEventListener("click",()=>{l()})};return re(),{top:!0,dom:se,update:re}};return[Jn.of(O)]},[o,n,l]),z=O=>{const se=O.split(".").pop()?.toLowerCase();switch(se){case"js":case"jsx":case"ts":case"tsx":return[to({jsx:!0,typescript:se.includes("ts")})];case"py":return[eo()];case"html":case"htm":return[Zn()];case"css":case"scss":case"less":return[Xn()];case"json":return[Qn()];case"md":case"markdown":return[Yn()];default:return[]}};s.useEffect(()=>{(async()=>{try{x(!0);const se=await he.readFile(t.projectName,t.path);if(!se.ok)throw new Error(`Failed to load file: ${se.status} ${se.statusText}`);const re=await se.json();u(re.content)}catch(se){console.error("Error loading file:",se),u(`// Error loading file: ${se.message}
108
+ // File: ${t.name}
109
+ // Path: ${He(t.path)}`)}finally{x(!1)}})()},[t,a]);const q=async()=>{h(!0);try{console.log("Saving file:",{projectName:t.projectName,path:t.path,contentLength:d?.length});const O=await he.saveFile(t.projectName,t.path,d);if(console.log("Save response:",{status:O.status,ok:O.ok,contentType:O.headers.get("content-type")}),!O.ok){const re=O.headers.get("content-type");if(re&&re.includes("application/json")){const J=await O.json();throw new Error(J.error||`Save failed: ${O.status}`)}else{const J=await O.text();throw console.error("Non-JSON error response:",J),new Error(`Save failed: ${O.status} ${O.statusText}`)}}const se=await O.json();console.log("Save successful:",se),b(!0),setTimeout(()=>b(!1),2e3)}catch(O){console.error("Error saving file:",O),i(`保存文件失败: ${O.message}`,{variant:"error"})}finally{h(!1)}},S=()=>{const O=new Blob([d],{type:"text/plain"}),se=URL.createObjectURL(O),re=document.createElement("a");re.href=se,re.download=t.name,document.body.appendChild(re),re.click(),document.body.removeChild(re),URL.revokeObjectURL(se)},E=()=>{k(!y)};return s.useEffect(()=>{localStorage.setItem("codeEditorTheme",L?"dark":"light")},[L]),s.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",m.toString())},[m]),s.useEffect(()=>{const O=()=>{const se=localStorage.getItem("codeEditorTheme");se&&I(se==="dark");const re=localStorage.getItem("codeEditorWordWrap");re!==null&&j(re==="true");const J=localStorage.getItem("codeEditorLineNumbers");J!==null&&G(J!=="false");const le=localStorage.getItem("codeEditorFontSize");le&&v(le)};return window.addEventListener("storage",O),window.addEventListener("codeEditorSettingsChanged",O),()=>{window.removeEventListener("storage",O),window.removeEventListener("codeEditorSettingsChanged",O)}},[]),s.useEffect(()=>{const O=se=>{(se.ctrlKey||se.metaKey)&&(se.key==="s"?(se.preventDefault(),q()):se.key==="Escape"&&(se.preventDefault(),r()))};return document.addEventListener("keydown",O),()=>document.removeEventListener("keydown",O)},[d]),f?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
110
+ .code-editor-loading {
111
+ background-color: ${L?"#111827":"#ffffff"} !important;
112
+ }
113
+ .code-editor-loading:hover {
114
+ background-color: ${L?"#111827":"#ffffff"} !important;
115
+ }
116
+ `}),o?e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-background",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"}),e.jsxs("span",{className:"text-gray-900 dark:text-white",children:["Loading ",t.name,"..."]})]})}):e.jsx("div",{className:"fixed inset-0 z-40 md:bg-black/50 md:flex md:items-center md:justify-center",children:e.jsx("div",{className:"code-editor-loading w-full h-full md:rounded-lg md:w-auto md:h-auto p-8 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"}),e.jsxs("span",{className:"text-gray-900 dark:text-white",children:["Loading ",t.name,"..."]})]})})})]}):e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
117
+ /* Editor toolbar panel styling */
118
+ .cm-editor-toolbar-panel {
119
+ padding: 8px 12px;
120
+ background-color: ${L?"#1f2937":"#ffffff"};
121
+ border-bottom: 1px solid ${L?"#374151":"#e5e7eb"};
122
+ color: ${L?"#d1d5db":"#374151"};
123
+ font-size: 14px;
124
+ }
125
+
126
+ .cm-toolbar-btn {
127
+ padding: 4px;
128
+ background: transparent;
129
+ border: none;
130
+ cursor: pointer;
131
+ border-radius: 4px;
132
+ display: inline-flex;
133
+ align-items: center;
134
+ justify-content: center;
135
+ color: inherit;
136
+ transition: background-color 0.2s;
137
+ }
138
+
139
+ .cm-toolbar-btn:hover {
140
+ background-color: ${L?"#374151":"#f3f4f6"};
141
+ }
142
+ `}),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 ${y?"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"+(y?" 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:He(t.path)})]})}),e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 flex-shrink-0",children:[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:"Download file",children:e.jsx(At,{className:"w-5 h-5 md:w-4 md:h-4"})}),e.jsx("button",{onClick:q,disabled:g,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 ${p?"bg-green-600 hover:bg-green-700":"bg-blue-600 hover:bg-blue-700"}`,children:p?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($r,{className:"w-5 h-5 md:w-4 md:h-4"}),e.jsx("span",{className:"hidden sm:inline",children:g?"Saving...":"Save"})]})}),!o&&e.jsx("button",{onClick:E,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:y?"Exit fullscreen":"Fullscreen",children:y?e.jsx(mo,{className:"w-4 h-4"}):e.jsx(uo,{className:"w-4 h-4"})}),e.jsx("button",{onClick:r,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(Ge,{className:"w-6 h-6 md:w-4 md:h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Kn,{ref:H,value:d,onChange:u,extensions:[...z(t.name),...N,...m?[Vn.lineWrapping]:[]],theme:L?Gn:void 0,height:"100%",style:{fontSize:`${U}px`,height:"100%"},basicSetup:{lineNumbers:R,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(`
143
+ `).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 xn({file:t,onClose:r}){const a=`/api/projects/${t.projectName}/files/content?path=${encodeURIComponent(t.path)}`,[o,n]=s.useState(null),[l,i]=s.useState(null),[d,u]=s.useState(!0);return s.useEffect(()=>{let f;const x=new AbortController;return(async()=>{try{u(!0),i(null),n(null);const h=await Y(a,{signal:x.signal});if(!h.ok)throw new Error(`Request failed with status ${h.status}`);const y=await h.blob();f=URL.createObjectURL(y),n(f)}catch(h){if(h.name==="AbortError")return;console.error("Error loading image:",h),i("无法加载图像")}finally{u(!1)}})(),()=>{x.abort(),f&&URL.revokeObjectURL(f)}},[a]),e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-4xl max-h-[90vh] w-full mx-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:t.name}),e.jsx(B,{variant:"ghost",size:"sm",onClick:r,className:"h-8 w-8 p-0",children:e.jsx(Ge,{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:He(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:He(t.path)})})]})})}function xl({selectedProject:t}){const{showAlert:r,showConfirm:a}=dt(),[o,n]=s.useState([]),[l,i]=s.useState(!1),[d,u]=s.useState(new Set),[f,x]=s.useState(new Set),[g,h]=s.useState(new Set),[y,k]=s.useState(null),[L,I]=s.useState(null),[p,b]=s.useState(""),[m,j]=s.useState([]),[R,G]=s.useState(!1),[U,v]=s.useState(!1),[H,N]=s.useState(null),[z,q]=s.useState({}),[S,E]=s.useState(null),[O,se]=s.useState(!1),[re,J]=s.useState(""),[le,me]=s.useState(!1),[ge,De]=s.useState(null),[we,Me]=s.useState(!1);s.useEffect(()=>{t&&(u(new Set),h(new Set),x(new Set),ie())},[t,we]),s.useEffect(()=>{if(!p.trim())j(o);else{const w=Ue(o,p.toLowerCase());j(w);const ee=A=>{A.forEach(te=>{te.type==="directory"&&te.children&&te.children.length>0&&(u(K=>new Set(K.add(te.path))),ee(te.children))})};ee(w)}},[o,p]);const Ue=(w,ee)=>w.reduce((A,te)=>{const K=te.name.toLowerCase().includes(ee);let oe=[];return te.type==="directory"&&te.children&&(oe=Ue(te.children,ee)),(K||oe.length>0)&&A.push({...te,children:oe}),A},[]),ie=async()=>{i(!0);try{const w=await he.getFiles(t.name,{depth:1,showHidden:we});if(!w.ok){const A=await w.text();console.error("❌ File fetch failed:",w.status,A),n([]);return}const ee=await w.json();n(ee)}catch(w){console.error("❌ Error fetching files:",w),n([])}finally{i(!1)}},Se=async(w,ee=!1)=>{if(!f.has(w)&&!(!ee&&g.has(w))){x(A=>new Set([...A,w]));try{const A=await he.getFiles(t.name,{dirPath:w,depth:1,showHidden:we});if(!A.ok){console.error("Failed to load directory:",w);return}const te=await A.json();n(K=>We(K,w,te)),h(K=>new Set([...K,w]))}catch(A){console.error("Error loading directory:",A)}finally{x(A=>{const te=new Set(A);return te.delete(w),te})}}},We=(w,ee,A)=>w.map(te=>te.path===ee?{...te,children:A}:te.type==="directory"&&te.children&&te.children.length>0?{...te,children:We(te.children,ee,A)}:te),Be=s.useCallback(async w=>{if(!t||w.length===0)return;v(!0),N(null);const ee=new FormData;S&&ee.append("targetDir",S),w.forEach(te=>{ee.append("files",te)});const A={};w.forEach(te=>{A[te.name]=0}),q(A);try{const te=await he.uploadFiles(t.name,ee);if(!te.ok){const oe=await te.json();throw new Error(oe.error||"Upload failed")}const K={};w.forEach(oe=>{K[oe.name]=100}),q(K),S?(u(oe=>new Set([...oe,S])),await Se(S,!0)):await ie(),setTimeout(()=>{G(!1),q({})},1e3)}catch(te){console.error("Upload failed:",te),N(te.message)}finally{v(!1)}},[t,S]),{getRootProps:ve,getInputProps:Ie,isDragActive:Le,open:qe}=Br({onDrop:Be,noClick:!0,noKeyboard:!0}),ke=async(w,ee,A)=>{const te=A==="directory";if(await a(`确定要删除${te?"文件夹":"文件"} "${ee}" 吗?${te?`
144
+ 这将删除内部的所有内容。`:""}`,{title:"确认删除",variant:"danger",confirmText:"删除"})&&t)try{const oe=await he.deleteFile(t.name,w);if(!oe.ok){const ce=await oe.json();throw new Error(ce.error||"Delete failed")}await ie()}catch(oe){console.error("Delete failed:",oe),r(`删除失败: ${oe.message}`,{variant:"error"})}},Je=async()=>{const w=re.trim();if(!w||!t)return;if(/[<>:"/\\|?*\x00-\x1f]/.test(w)){r("文件夹名称包含无效字符",{variant:"error"});return}const ee=ge?`${ge}/${w}`:w;me(!0);try{const A=await he.createDir(t.name,ee);if(!A.ok){const te=await A.json();throw new Error(te.error||"Create failed")}ge?(u(te=>new Set([...te,ge])),await Se(ge,!0)):await ie(),se(!1),J("")}catch(A){console.error("Create directory failed:",A),r(`创建失败: ${A.message}`,{variant:"error"})}finally{me(!1)}},$e=async(w,ee)=>{const A=new Set(d);A.has(w)?A.delete(w):(A.add(w),ee&&!g.has(w)&&await Se(w)),u(A)},Pe=w=>{if(!w||w===0)return"0 B";const ee=1024,A=["B","KB","MB","GB"],te=Math.floor(Math.log(w)/Math.log(ee));return parseFloat((w/Math.pow(ee,te)).toFixed(1))+" "+A[te]},_e=w=>{if(!w)return"-";const ee=new Date,A=new Date(w),te=Math.floor((ee-A)/1e3);return te<60?"just now":te<3600?`${Math.floor(te/60)} min ago`:te<86400?`${Math.floor(te/3600)} hours ago`:te<2592e3?`${Math.floor(te/86400)} days ago`:A.toLocaleDateString()},ze=w=>w.includes("/.claude/")||w.endsWith("/.claude"),Ae=w=>{const ee=w.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","svg","webp","ico","bmp"].includes(ee)},Ye=w=>{const ee=w.toLowerCase(),A=["dockerfile","makefile","gemfile","rakefile","procfile","vagrantfile","jenkinsfile"];if(!w.includes("."))return A.includes(ee);const te=w.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(te)},Oe=async w=>{try{const ee=await he.getFileContent(t.name,w.path);if(!ee.ok)throw new Error("Download failed");const A=await ee.blob(),te=URL.createObjectURL(A),K=document.createElement("a");K.href=te,K.download=w.name,document.body.appendChild(K),K.click(),document.body.removeChild(K),URL.revokeObjectURL(te)}catch(ee){console.error("Download failed:",ee)}},V=w=>{const ee=w.split(".").pop()?.toLowerCase(),A=["js","jsx","ts","tsx","py","java","cpp","c","php","rb","go","rs"],te=["md","txt","doc","pdf"],K=["png","jpg","jpeg","gif","svg","webp","ico","bmp"];return A.includes(ee)?e.jsx(xo,{className:"w-4 h-4 text-green-500 flex-shrink-0"}):te.includes(ee)?e.jsx(is,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):K.includes(ee)?e.jsx(dr,{className:"w-4 h-4 text-purple-500 flex-shrink-0"}):e.jsx(dr,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"})},$=(w,ee=0)=>w.map(A=>{const te=f.has(A.path),K=d.has(A.path),oe=A.hasChildren||A.children&&A.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:rt("grid grid-cols-12 gap-2 p-2 hover:bg-accent items-center",A.type==="directory"||Ae(A.name)||Ye(A.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${ee*16+12}px`},onClick:()=>{A.type==="directory"?$e(A.path,oe):ze(A.path)||(Ae(A.name)?I({name:A.name,path:A.path,projectPath:t.path,projectName:t.name}):Ye(A.name)&&k({name:A.name,path:A.path,projectPath:t.path,projectName:t.name}))},children:[e.jsxs("div",{className:"col-span-4 flex items-center gap-2 min-w-0",children:[A.type==="directory"?e.jsxs("div",{className:"relative flex-shrink-0",children:[te?e.jsx(Dt,{className:"w-4 h-4 text-blue-500 animate-spin"}):K?e.jsx(Ns,{className:"w-4 h-4 text-blue-500"}):oe?e.jsx(Xt,{className:"w-4 h-4 text-muted-foreground"}):e.jsx(Xt,{className:"w-4 h-4 text-muted-foreground/50"}),A.isSymlink&&e.jsx(da,{className:"absolute -bottom-1 -right-1 w-2.5 h-2.5 text-yellow-500"})]}):e.jsxs("div",{className:"relative flex-shrink-0",children:[A.isBrokenSymlink?e.jsx(dr,{className:"w-4 h-4 text-destructive/60"}):V(A.name),A.isSymlink&&e.jsx(da,{className:"absolute -bottom-1 -right-1 w-2.5 h-2.5 text-yellow-500"})]}),e.jsx("span",{className:rt("text-sm truncate",A.isBrokenSymlink?"text-destructive/60 line-through":"text-foreground"),children:A.name}),A.type==="directory"&&oe&&!K&&!te&&e.jsx(zs,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground",children:A.type==="file"?Pe(A.size):"-"}),e.jsx("div",{className:"col-span-3 text-sm text-muted-foreground",children:_e(A.modified)}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground font-mono",children:A.permissionsRwx||"-"}),e.jsxs("div",{className:"col-span-1 flex justify-end items-center gap-0.5",children:[A.type==="directory"&&!ze(A.path)&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:ce=>{ce.stopPropagation(),E(A.path),G(!0)},title:"上传文件到此文件夹",children:e.jsx(zt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),A.type==="directory"&&!ze(A.path)&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:ce=>{ce.stopPropagation(),De(A.path),J(""),se(!0)},title:"在此文件夹下新建子文件夹",children:e.jsx(ks,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),A.type==="file"&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:ce=>{ce.stopPropagation(),Oe(A)},title:"下载文件",children:e.jsx(At,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),!ze(A.path)&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:ce=>{ce.stopPropagation(),ke(A.path,A.name,A.type)},title:`删除${A.type==="directory"?"文件夹":"文件"}`,children:e.jsx(bt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),A.type==="directory"&&K&&e.jsx("div",{children:te?e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground items-center",style:{paddingLeft:`${(ee+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"}),"加载中..."]})}):A.children&&A.children.length>0?$(A.children,ee+1):e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(ee+1)*16+12}px`},children:e.jsx("div",{className:"col-span-4",children:"空文件夹"})})})]},A.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",{...ve(),className:rt("h-full flex flex-col bg-card relative",Le&&"ring-2 ring-primary ring-inset"),children:[e.jsx("input",{...Ie()}),Le&&e.jsx("div",{className:"absolute inset-0 bg-primary/10 flex items-center justify-center z-10 pointer-events-none",children:e.jsx("div",{className:"text-primary font-medium",children:"拖放文件以上传"})}),e.jsxs("div",{className:"p-4 border-b border-border space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:"文件"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{E(null),G(!0)},title:"上传文件",children:e.jsx(zt,{className:"w-4 h-4"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{De(null),J(""),se(!0)},title:"新建文件夹",children:e.jsx(ks,{className:"w-4 h-4"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>Me(w=>!w),title:we?"隐藏隐藏文件":"显示隐藏文件",children:we?e.jsx(Ua,{className:"w-4 h-4"}):e.jsx(po,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(St,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(it,{type:"text",placeholder:"搜索文件和文件夹...",value:p,onChange:w=>b(w.target.value),className:"pl-8 pr-8 h-8 text-sm"}),p&&e.jsx(B,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 transform -translate-y-1/2 h-6 w-6 p-0 hover:bg-accent",onClick:()=>b(""),title:"清除搜索",children:e.jsx(Ge,{className:"w-3 h-3"})})]})]}),m.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(Fr,{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(Xt,{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:"检查项目路径是否可访问"})]}):m.length===0&&p?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(St,{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.jsx("div",{children:$(m)})}),y&&e.jsx(Rr,{file:y,onClose:()=>k(null),projectPath:y.projectPath}),L&&e.jsx(xn,{file:L,onClose:()=>I(null)}),R&&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.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"上传文件"}),S&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 truncate max-w-xs",title:He(S),children:["位置:",He(S)]})]}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{G(!1),N(null),q({}),E(null)},children:e.jsx(Ge,{className:"w-4 h-4"})})]}),e.jsxs("div",{onClick:qe,className:rt("border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors","border-border hover:border-primary/50"),children:[e.jsx(zt,{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(z).length>0&&e.jsx("div",{className:"mt-4 space-y-2 max-h-40 overflow-y-auto",children:Object.entries(z).map(([w,ee])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm truncate flex-1 text-foreground",children:w}),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:`${ee}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10",children:[ee,"%"]})]},w))}),H&&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:H})}),U&&e.jsx("div",{className:"mt-4 text-center text-sm text-muted-foreground",children:"上传中..."})]})}),O&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-xl p-6 w-full max-w-sm mx-4 border border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"新建文件夹"}),ge&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 truncate max-w-xs",title:He(ge),children:["位置:",He(ge)]})]}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>se(!1),children:e.jsx(Ge,{className:"w-4 h-4"})})]}),e.jsx(it,{autoFocus:!0,type:"text",placeholder:"文件夹名称",value:re,onChange:w=>J(w.target.value),onKeyDown:w=>{w.key==="Enter"&&Je(),w.key==="Escape"&&se(!1)},className:"mb-4"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>se(!1),children:"取消"}),e.jsxs(B,{size:"sm",onClick:Je,disabled:!re.trim()||le,children:[le?e.jsx(Dt,{className:"w-4 h-4 animate-spin mr-1"}):null,"创建"]})]})]})})]})}var qr=Ao(),Jr=$o(),Kr=_o(),Gr=zo();const hl=`
145
+ .xterm .xterm-screen {
146
+ outline: none !important;
147
+ }
148
+ .xterm:focus .xterm-screen {
149
+ outline: none !important;
150
+ }
151
+ .xterm-screen:focus {
152
+ outline: none !important;
153
+ }
154
+ `;if(typeof document<"u"){const t=document.createElement("style");t.type="text/css",t.innerText=hl,document.head.appendChild(t)}function gl({selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:o=!1,onProcessComplete:n,minimal:l=!1,autoConnect:i=!1}){const d=s.useRef(null),u=s.useRef(null),f=s.useRef(null),x=s.useRef(null),[g,h]=s.useState(!1),[y,k]=s.useState(!1),[L,I]=s.useState(!1),[p,b]=s.useState(null),[m,j]=s.useState(!1),R=s.useRef(t),G=s.useRef(r),U=s.useRef(a),v=s.useRef(o),H=s.useRef(n);s.useEffect(()=>{R.current=t,G.current=r,U.current=a,v.current=o,H.current=n});const N=s.useCallback(async()=>{if(!(m||g))try{const re=localStorage.getItem("auth-token");if(!re){console.error("No authentication token found for Shell WebSocket connection");return}const le=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/shell?token=${encodeURIComponent(re)}`;x.current=new WebSocket(le),x.current.onopen=()=>{h(!0),j(!1),setTimeout(()=>{f.current&&u.current&&(f.current.fit(),x.current.send(JSON.stringify({type:"init",projectPath:R.current.fullPath||R.current.path,sessionId:v.current?null:G.current?.id,hasSession:v.current?!1:!!G.current,provider:v.current?"plain-shell":G.current?.__provider||"claude",cols:u.current.cols,rows:u.current.rows,initialCommand:U.current,isPlainShell:v.current})))},100)},x.current.onmessage=me=>{try{const ge=JSON.parse(me.data);if(ge.type==="output"){let De=ge.data;if(v.current&&H.current){const we=De.replace(/\x1b\[[0-9;]*m/g,"");if(we.includes("Process exited with code 0"))H.current(0);else if(we.match(/Process exited with code (\d+)/)){const Me=parseInt(we.match(/Process exited with code (\d+)/)[1]);Me!==0&&H.current(Me)}}u.current&&u.current.write(De)}else ge.type==="url_open"&&window.open(ge.url,"_blank")}catch(ge){console.error("[Shell] Error handling WebSocket message:",ge,me.data)}},x.current.onclose=me=>{h(!1),j(!1),u.current&&(u.current.clear(),u.current.write("\x1B[2J\x1B[H"))},x.current.onerror=me=>{h(!1),j(!1)}}catch{h(!1),j(!1)}},[m,g]),z=s.useCallback(()=>{!y||g||m||(j(!0),N())},[y,g,m,N]),q=s.useCallback(()=>{x.current&&(x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"terminate"})),x.current.close(),x.current=null),u.current&&(u.current.clear(),u.current.write("\x1B[2J\x1B[H")),h(!1),j(!1)},[]),S=s.useMemo(()=>r?r.summary||"New Session":null,[r]),E=s.useMemo(()=>S?S.slice(0,30):null,[S]),O=s.useMemo(()=>S?S.slice(0,50):null,[S]),se=()=>{I(!0),x.current&&(x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"terminate"})),x.current.close(),x.current=null),u.current&&(u.current.dispose(),u.current=null,f.current=null),h(!1),k(!1),setTimeout(()=>{I(!1)},200)};return s.useEffect(()=>{const re=r?.id||null;p!==null&&p!==re&&y&&q(),b(re)},[r?.id,y,q]),s.useEffect(()=>{if(!d.current||!t||L||u.current)return;u.current=new qr.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"]}}),f.current=new Jr.FitAddon;const re=new Kr.WebglAddon,J=new Gr.WebLinksAddon;u.current.loadAddon(f.current),u.current.loadAddon(J);try{u.current.loadAddon(re)}catch{console.warn("[Shell] WebGL renderer unavailable, using Canvas fallback")}u.current.open(d.current),u.current.attachCustomKeyEventHandler(me=>(me.ctrlKey||me.metaKey)&&me.key==="c"&&u.current.hasSelection()?(document.execCommand("copy"),!1):(me.ctrlKey||me.metaKey)&&me.key==="v"?(navigator.clipboard.readText().then(ge=>{x.current&&x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"input",data:ge}))}).catch(()=>{}),!1):!0),setTimeout(()=>{f.current&&(f.current.fit(),u.current&&x.current&&x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"resize",cols:u.current.cols,rows:u.current.rows})))},100),k(!0),u.current.onData(me=>{x.current&&x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"input",data:me}))});const le=new ResizeObserver(()=>{f.current&&u.current&&setTimeout(()=>{f.current.fit(),x.current&&x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"resize",cols:u.current.cols,rows:u.current.rows}))},50)});return d.current&&le.observe(d.current),()=>{le.disconnect(),x.current&&(x.current.readyState===WebSocket.OPEN||x.current.readyState===WebSocket.CONNECTING)&&x.current.close(),x.current=null,u.current&&(u.current.dispose(),u.current=null)}},[t?.path||t?.fullPath,L]),s.useEffect(()=>{!i||!y||m||g||z()},[i,y,m,g,z]),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 ${g?"bg-green-500":"bg-red-500"}`}),r&&e.jsxs("span",{className:"text-xs text-blue-300",children:["(",E,"...)"]}),!r&&e.jsx("span",{className:"text-xs text-gray-400",children:"(新会话)"}),!y&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),L&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[g&&e.jsxs("button",{onClick:q,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:se,disabled:L||g,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Shell(先断开连接)",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),e.jsx("span",{children:"重启"})]})]})]})}),e.jsxs("div",{className:"flex-1 p-2 overflow-hidden relative",children:[e.jsx("div",{ref:d,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!y&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90",children:e.jsx("div",{className:"text-white",children:"加载终端中..."})}),y&&!g&&!m&&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:z,className:"px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center justify-center space-x-2 text-base font-medium w-full sm:w-auto",title:"Connect to shell",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{children:"在 Shell 中继续"})]}),e.jsx("p",{className:"text-gray-400 text-sm mt-3 px-2",children:o?`Run ${a||"command"} in ${t.displayName}`:r?`Resume session: ${O}...`:"Start a new Claude session"})]})}),m&&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 fl({project:t,session:r=null,command:a=null,isPlainShell:o=null,autoConnect:n=!0,onComplete:l=null,onClose:i=null,title:d=null,className:u="",showHeader:f=!0,compact:x=!1,minimal:g=!1}){const[h,y]=s.useState(!1),k=o!==null?o:a!==null,L=s.useCallback(I=>{y(!0),l&&l(I)},[l]);return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${u}`,children:[!g&&f&&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}),h&&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(gl,{selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:k,onProcessComplete:L,minimal:g,autoConnect:g?!0:n})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${u}`,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 bl({selectedProject:t,minimal:r=!1,autoConnect:a=!1}){const o=s.useRef(null),n=s.useRef(null),l=s.useRef(null),i=s.useRef(null),[d,u]=s.useState(!1),[f,x]=s.useState(!1),[g,h]=s.useState(!1),[y,k]=s.useState(!1),L=s.useRef(t);s.useEffect(()=>{L.current=t});const I=s.useCallback(async()=>{if(!(y||d))try{const j=localStorage.getItem("auth-token");if(!j){console.error("No authentication token found for Codex WebSocket connection");return}const G=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/codex?token=${encodeURIComponent(j)}`;i.current=new WebSocket(G),i.current.onopen=()=>{u(!0),k(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:L.current.fullPath||L.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=U=>{try{const v=JSON.parse(U.data);v.type==="output"?n.current&&n.current.write(v.data):v.type==="url_open"&&window.open(v.url,"_blank")}catch(v){console.error("[CodexShell] Error handling WebSocket message:",v)}},i.current.onclose=()=>{u(!1),k(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{u(!1),k(!1)}}catch{u(!1),k(!1)}},[y,d]),p=s.useCallback(()=>{!f||d||y||(k(!0),I())},[f,d,y,I]),b=s.useCallback(()=>{i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H")),u(!1),k(!1)},[]),m=()=>{h(!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),u(!1),x(!1),setTimeout(()=>h(!1),200)};return s.useEffect(()=>{if(!o.current||!t||g||n.current)return;n.current=new qr.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 Jr.FitAddon;const j=new Kr.WebglAddon,R=new Gr.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(R);try{n.current.loadAddon(j)}catch{console.warn("[CodexShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(U=>(U.ctrlKey||U.metaKey)&&U.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(U.ctrlKey||U.metaKey)&&U.key==="v"?(navigator.clipboard.readText().then(v=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:v}))}).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),x(!0),n.current.onData(U=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:U}))});const G=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&&G.observe(o.current),()=>{G.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,g]),s.useEffect(()=>{!a||!f||y||d||p()},[a,f,y,d,p]),t?r?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}})}):e.jsxs("div",{className:"h-full flex flex-col bg-gray-900 w-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${d?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-300 font-medium",children:"Codex"}),!f&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),g&&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:b,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:m,disabled:g||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"}}),!f&&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:"加载终端中..."})}),f&&!d&&!y&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("button",{onClick:p,className:"px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center justify-center space-x-2 text-base font-medium w-full sm:w-auto",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{children:"启动 Codex"})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["在 ",t.displayName," 中启动 Codex CLI"]})]})}),y&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("div",{className:"flex items-center justify-center space-x-3 text-yellow-400",children:[e.jsx("div",{className:"w-6 h-6 animate-spin rounded-full border-2 border-yellow-400 border-t-transparent"}),e.jsx("span",{className:"text-base font-medium",children:"连接到 Codex..."})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["正在 ",t.displayName," 中启动 Codex CLI"]})]})})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"选择项目"}),e.jsx("p",{children:"选择一个项目以在该目录中打开 Codex"})]})})}function yl({project:t,autoConnect:r=!0,onClose:a=null,className:o="",showHeader:n=!0,minimal:l=!1}){return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${o}`,children:[!l&&n&&a&&e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-200",children:"Codex"}),e.jsx("button",{onClick:a,className:"text-gray-400 hover:text-white",title:"关闭",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsx("div",{className:"flex-1 w-full min-h-0",children:e.jsx(bl,{selectedProject:t,minimal:l,autoConnect:l?!0:r})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${o}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Codex 需要一个项目"})]})})}function vl({selectedProject:t,minimal:r=!1,autoConnect:a=!1}){const o=s.useRef(null),n=s.useRef(null),l=s.useRef(null),i=s.useRef(null),[d,u]=s.useState(!1),[f,x]=s.useState(!1),[g,h]=s.useState(!1),[y,k]=s.useState(!1),L=s.useRef(t);s.useEffect(()=>{L.current=t});const I=s.useCallback(async()=>{if(!(y||d))try{const j=localStorage.getItem("auth-token");if(!j){console.error("No authentication token found for Gemini WebSocket connection");return}const G=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/gemini?token=${encodeURIComponent(j)}`;i.current=new WebSocket(G),i.current.onopen=()=>{u(!0),k(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:L.current.fullPath||L.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=U=>{try{const v=JSON.parse(U.data);v.type==="output"?n.current&&n.current.write(v.data):v.type==="url_open"&&window.open(v.url,"_blank")}catch(v){console.error("[GeminiShell] Error handling WebSocket message:",v)}},i.current.onclose=()=>{u(!1),k(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{u(!1),k(!1)}}catch{u(!1),k(!1)}},[y,d]),p=s.useCallback(()=>{!f||d||y||(k(!0),I())},[f,d,y,I]),b=s.useCallback(()=>{i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H")),u(!1),k(!1)},[]),m=()=>{h(!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),u(!1),x(!1),setTimeout(()=>h(!1),200)};return s.useEffect(()=>{if(!o.current||!t||g||n.current)return;n.current=new qr.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 Jr.FitAddon;const j=new Kr.WebglAddon,R=new Gr.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(R);try{n.current.loadAddon(j)}catch{console.warn("[GeminiShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(U=>(U.ctrlKey||U.metaKey)&&U.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(U.ctrlKey||U.metaKey)&&U.key==="v"?(navigator.clipboard.readText().then(v=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:v}))}).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),x(!0),n.current.onData(U=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:U}))});const G=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&&G.observe(o.current),()=>{G.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,g]),s.useEffect(()=>{!a||!f||y||d||p()},[a,f,y,d,p]),t?r?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}})}):e.jsxs("div",{className:"h-full flex flex-col bg-gray-900 w-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${d?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-300 font-medium",children:"Gemini"}),!f&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),g&&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:b,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:m,disabled:g||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"}}),!f&&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:"加载终端中..."})}),f&&!d&&!y&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("button",{onClick:p,className:"px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors flex items-center justify-center space-x-2 text-base font-medium w-full sm:w-auto",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{children:"启动 Gemini"})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["在 ",t.displayName," 中启动 Gemini CLI"]})]})}),y&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90 p-4",children:e.jsxs("div",{className:"text-center max-w-sm w-full",children:[e.jsxs("div",{className:"flex items-center justify-center space-x-3 text-yellow-400",children:[e.jsx("div",{className:"w-6 h-6 animate-spin rounded-full border-2 border-yellow-400 border-t-transparent"}),e.jsx("span",{className:"text-base font-medium",children:"连接到 Gemini..."})]}),e.jsxs("p",{className:"text-gray-400 text-sm mt-3 px-2",children:["正在 ",t.displayName," 中启动 Gemini CLI"]})]})})]})]}):e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"选择项目"}),e.jsx("p",{children:"选择一个项目以在该目录中打开 Gemini"})]})})}function jl({project:t,autoConnect:r=!0,onClose:a=null,className:o="",showHeader:n=!0,minimal:l=!1}){return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${o}`,children:[!l&&n&&a&&e.jsx("div",{className:"flex-shrink-0 bg-gray-800 border-b border-gray-700 px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-200",children:"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(vl,{selectedProject:t,minimal:l,autoConnect:l?!0:r})})]}):e.jsx("div",{className:`h-full flex items-center justify-center ${o}`,children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"未选择项目"}),e.jsx("p",{children:"打开 Gemini 需要一个项目"})]})})}class wl extends ut.Component{constructor(r){super(r),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0}}componentDidCatch(r,a){console.error("ErrorBoundary caught an error:",r,a),this.setState({error:r,errorInfo:a})}render(){return this.state.hasError?e.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-6 max-w-md",children:[e.jsxs("div",{className:"flex items-center mb-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-red-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})}),e.jsx("h3",{className:"ml-3 text-sm font-medium text-red-800",children:"出现问题"})]}),e.jsxs("div",{className:"text-sm text-red-700",children:[e.jsx("p",{className:"mb-2",children:"加载聊天界面时出现错误。"}),this.props.showDetails&&this.state.error&&e.jsxs("details",{className:"mt-4",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-mono",children:"错误详情"}),e.jsxs("pre",{className:"mt-2 text-xs bg-red-100 p-2 rounded overflow-auto max-h-40",children:[this.state.error.toString(),this.state.errorInfo&&this.state.errorInfo.componentStack]})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx("button",{onClick:()=>{this.setState({hasError:!1,error:null,errorInfo:null}),this.props.onRetry&&this.props.onRetry()},className:"bg-red-600 text-white px-4 py-2 rounded text-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500",children:"重试"})})]})}):this.props.children}}const ys=({children:t,content:r,position:a="top",className:o="",delay:n=500})=>{const[l,i]=s.useState(!1),[d,u]=s.useState(null),f=()=>{const y=setTimeout(()=>{i(!0)},n);u(y)},x=()=>{d&&(clearTimeout(d),u(null)),i(!1)},g=()=>{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"}},h=()=>{switch(a){case"top":return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100";case"bottom":return"bottom-full left-1/2 transform -translate-x-1/2 border-b-gray-900 dark:border-b-gray-100";case"left":return"left-full top-1/2 transform -translate-y-1/2 border-l-gray-900 dark:border-l-gray-100";case"right":return"right-full top-1/2 transform -translate-y-1/2 border-r-gray-900 dark:border-r-gray-100";default:return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100"}};return r?e.jsxs("div",{className:"relative inline-block",onMouseEnter:f,onMouseLeave:x,children:[t,l&&e.jsxs("div",{className:rt("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",g(),o),children:[r,e.jsx("div",{className:rt("absolute w-0 h-0 border-4 border-transparent",h())})]})]}):t};function kl(){const[t,r]=s.useState(null),[a,o]=s.useState([]),[n,l]=s.useState(!1),i=s.useRef(null),d=s.useRef(null),u=s.useRef(0),{token:f}=Ct();s.useEffect(()=>{i.current&&(clearTimeout(i.current),i.current=null),d.current&&(d.current.close(),d.current=null),f?(u.current=0,x()):(l(!1),r(null));const h=()=>{if(document.visibilityState==="visible"){const y=d.current?.readyState;(y===void 0||y===3||y===2)&&(i.current&&(clearTimeout(i.current),i.current=null),u.current=0,x())}};return document.addEventListener("visibilitychange",h),()=>{document.removeEventListener("visibilitychange",h),i.current&&clearTimeout(i.current),d.current&&d.current.close()}},[f]);const x=()=>{try{const h=f||localStorage.getItem("auth-token");if(!h){console.warn("No authentication token found for WebSocket connection");return}const k=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws?token=${encodeURIComponent(h)}`,L=new WebSocket(k);d.current=L,L.onopen=()=>{u.current=0,l(!0),r(L)},L.onmessage=I=>{try{const p=JSON.parse(I.data);o(b=>[...b,p])}catch(p){console.error("Error parsing WebSocket message:",p)}},L.onclose=()=>{if(l(!1),r(null),d.current=null,localStorage.getItem("auth-token")){const p=Math.min(1e3*Math.pow(2,u.current),15e3);u.current+=1,i.current=setTimeout(()=>{x()},p)}},L.onerror=I=>{console.error("WebSocket error:",I)}}catch(h){console.error("Error creating WebSocket connection:",h)}};return{ws:t,sendMessage:h=>{t&&n?t.send(JSON.stringify(h)):console.warn("WebSocket not connected")},messages:a,isConnected:n}}const hn=s.createContext({ws:null,sendMessage:()=>{},messages:[],isConnected:!1}),gn=()=>{const t=s.useContext(hn);if(!t)throw new Error("useWebSocketContext must be used within a WebSocketProvider");return t},Nl=({children:t})=>{const r=kl();return e.jsx(hn.Provider,{value:r,children:t})};function Sl({selectedProject:t,selectedSession:r,activeTab:a,setActiveTab:o,ws:n,sendMessage:l,messages:i,isMobile:d,isPWA:u,onMenuClick:f,isLoading:x,onInputFocusChange:g,onSessionActive:h,onSessionInactive:y,onSessionProcessing:k,onSessionNotProcessing:L,processingSessions:I,onReplaceTemporarySession:p,onNavigateToSession:b,onShowSettings:m,autoScrollToBottom:j,sendByCtrlEnter:R,externalMessageUpdate:G,limitStatus:U,onLimitBlocked:v,checkLimitStatus:H}){const{showConfirm:N}=dt(),{hasPermission:z}=Ct(),{isConnected:q}=gn(),[S,E]=s.useState(null),[O,se]=s.useState(null),[re,J]=s.useState(600),[le,me]=s.useState(!1),[ge,De]=s.useState(!1),we=s.useRef(null),Me=async ve=>{const Ie="previewTabAcknowledged";if(!localStorage.getItem(Ie)){const Le=await N("此功能的对话记录不会显示在当前网页的会话列表中,与 Chat 是两套独立的系统,请注意区分。",{title:"预览功能提示",subtitle:ve==="codex"?"Codex":"Gemini CLI",variant:"warning",confirmText:"我知道了,继续",cancelText:"取消",checkboxLabel:"不再提醒"});if(!Le?.confirmed)return;Le.checked&&localStorage.setItem(Ie,"1")}o(ve)};s.useEffect(()=>{a==="shell"&&H&&H()},[a,H]);const Ue=["png","jpg","jpeg","gif","svg","webp","ico","bmp"],ie=(ve,Ie=null)=>{const Le=ve.split(".").pop()?.toLowerCase();if(Ue.includes(Le)){se({name:ve.split("/").pop(),path:ve,projectName:t?.name,projectPath:t?.path});return}const qe={name:ve.split("/").pop(),path:ve,projectName:t?.name,diffInfo:Ie};E(qe)},Se=()=>{E(null),De(!1)},We=()=>{De(!ge)},Be=ve=>{d||(me(!0),ve.preventDefault())};return s.useEffect(()=>{const ve=Le=>{if(!le)return;const qe=we.current?.parentElement;if(!qe)return;const ke=qe.getBoundingClientRect(),Je=ke.right-Le.clientX,$e=300,Pe=ke.width*.8;Je>=$e&&Je<=Pe&&J(Je)},Ie=()=>{me(!1)};return le&&(document.addEventListener("mousemove",ve),document.addEventListener("mouseup",Ie),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",ve),document.removeEventListener("mouseup",Ie),document.body.style.cursor="",document.body.style.userSelect=""}},[le]),x?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:f,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.jsxs("h2",{className:"text-xl font-semibold mb-2",children:["正在加载 ",Ze]}),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:f,onTouchStart:ve=>{ve.preventDefault(),f()},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.jsx("div",{className:"min-w-0 flex items-center gap-2 flex-1 overflow-x-auto scrollbar-hide",children:e.jsx("div",{className:"min-w-0 flex-1",children:a==="chat"&&r?e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white whitespace-nowrap overflow-x-auto scrollbar-hide",children:r.summary||"新会话"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName}),e.jsxs("span",{className:`inline-flex items-center gap-1 text-xs ${q?"text-green-600 dark:text-green-400":"text-red-500 dark:text-red-400 animate-pulse"}`,children:[q?e.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z"})}):e.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.412 15.655L9.75 21.75l3.745-4.012M9.257 13.5H3.75l2.659-2.849m2.048-2.194L14.25 2.25 12 10.5h8.25l-4.707 5.043M6.53 9.345A3.778 3.778 0 0112 8.25c1.372 0 2.585.59 3.43 1.53M3 3l18 18"})}),e.jsx("span",{className:"hidden sm:inline",children:q?"连接正常":"连接异常"})]})]})]}):a==="chat"&&!r?e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white",children:"新会话"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName}),e.jsxs("span",{className:`inline-flex items-center gap-1 text-xs ${q?"text-green-600 dark:text-green-400":"text-red-500 dark:text-red-400 animate-pulse"}`,children:[q?e.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z"})}):e.jsx("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11.412 15.655L9.75 21.75l3.745-4.012M9.257 13.5H3.75l2.659-2.849m2.048-2.194L14.25 2.25 12 10.5h8.25l-4.707 5.043M6.53 9.345A3.778 3.778 0 0112 8.25c1.372 0 2.585.59 3.43 1.53M3 3l18 18"})}),e.jsx("span",{className:"hidden sm:inline",children:q?"连接正常":"连接异常"})]})]})]}):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(ys,{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(ys,{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"})]})})}),z("claude_shell")&&e.jsx(ys,{content:U&&!U.allowed?"使用已达上限":"Claude Code",position:"bottom",children:e.jsx("button",{onClick:()=>{if(U&&!U.allowed){v?.(U.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 ${U&&!U.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"})]})})}),z("codex_shell")&&e.jsx(ys,{content:"Codex",position:"bottom",children:e.jsx("button",{onClick:()=>Me("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"})]})})}),z("gemini_shell")&&e.jsx(ys,{content:"Gemini CLI",position:"bottom",children:e.jsx("button",{onClick:()=>Me("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 ${S?"mr-0":""} ${ge?"hidden":""}`,children:[e.jsx("div",{className:`h-full ${a==="chat"?"block":"hidden"}`,children:e.jsx(wl,{showDetails:!0,children:e.jsx(pl,{selectedProject:t,selectedSession:r,ws:n,sendMessage:l,messages:i,onFileOpen:ie,onInputFocusChange:g,onSessionActive:h,onSessionInactive:y,onSessionProcessing:k,onSessionNotProcessing:L,processingSessions:I,onReplaceTemporarySession:p,onNavigateToSession:b,onShowSettings:m,autoScrollToBottom:j,sendByCtrlEnter:R,externalMessageUpdate:G,limitStatus:U,onLimitExceeded:v,checkLimitStatus:H})})}),a==="files"&&e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx(xl,{selectedProject:t})}),a==="shell"&&e.jsxs("div",{className:"h-full w-full overflow-hidden relative",children:[e.jsx(fl,{project:t,session:r,showHeader:!1}),U&&!U.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:U.reason==="total_limit_exceeded"?"使用上限已达到":"今日使用上限已达到"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:U.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(yl,{project:t,showHeader:!1})}),a==="gemini"&&e.jsx("div",{className:"h-full w-full overflow-hidden relative",children:e.jsx(jl,{project:t,showHeader:!1})}),e.jsx("div",{className:`h-full overflow-hidden ${a==="preview"?"block":"hidden"}`})]}),S&&!d&&e.jsxs(e.Fragment,{children:[!ge&&e.jsx("div",{ref:we,onMouseDown:Be,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 ${ge?"flex-1":""}`,style:ge?{}:{width:`${re}px`},children:e.jsx(Rr,{file:S,onClose:Se,projectPath:t?.path,isSidebar:!0,isExpanded:ge,onToggleExpand:We})})]})]}),S&&d&&e.jsx(Rr,{file:S,onClose:Se,projectPath:t?.path,isSidebar:!1}),O&&e.jsx(xn,{file:O,onClose:()=>se(null)})]}):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:f,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.jsxs("p",{className:"text-gray-600 dark:text-gray-300 mb-6 leading-relaxed",children:["从侧边栏选择一个项目,开始与 ",Ze," 进行交流。每个项目包含您的聊天会话和文件历史。"]}),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?"点击上方菜单按钮访问项目":z("create_project")?"点击侧边栏中的文件夹图标创建新项目":"点击侧边栏中的「使用项目模板」按钮来创建项目"]})})]})})]})}const Cl=ut.memo(Sl);function El({activeTab:t,setActiveTab:r,isInputFocused:a}){const o=[{id:"chat",icon:_r,onClick:()=>r("chat")},{id:"shell",icon:zr,onClick:()=>r("shell")},{id:"files",icon:Xt,onClick:()=>r("files")}];return e.jsx("div",{className:`fixed bottom-0 left-0 right-0 bg-background border-t border-border z-50 ios-bottom-safe transform transition-transform duration-300 ease-in-out shadow-lg ${a?"translate-y-full":"translate-y-0"}`,children:e.jsx("div",{className:"flex items-center justify-around py-1",children:o.map(n=>{const l=n.icon,i=t===n.id;return e.jsxs("button",{onClick:n.onClick,onTouchStart: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 fn=s.createContext(),Vr=()=>{const t=s.useContext(fn);if(!t)throw new Error("useTheme must be used within a ThemeProvider");return t},Ml=({children:t})=>{const[r,a]=s.useState(()=>{const l=localStorage.getItem("theme");return l?l==="dark":window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches:!1});s.useEffect(()=>{if(r){document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark");const l=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');l&&l.setAttribute("content","black-translucent");const i=document.querySelector('meta[name="theme-color"]');i&&i.setAttribute("content","#0c1117")}else{document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light");const l=document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');l&&l.setAttribute("content","default");const i=document.querySelector('meta[name="theme-color"]');i&&i.setAttribute("content","#ffffff")}},[r]),s.useEffect(()=>{if(!window.matchMedia)return;const l=window.matchMedia("(prefers-color-scheme: dark)"),i=d=>{localStorage.getItem("theme")||a(d.matches)};return l.addEventListener("change",i),()=>l.removeEventListener("change",i)},[]);const n={isDarkMode:r,toggleDarkMode:()=>{a(l=>!l)}};return e.jsx(fn.Provider,{value:n,children:t})},Il=["Bash(git log:*)","Bash(git diff:*)","Bash(git status:*)","Write","Read","Edit","Glob","Grep","MultiEdit","Task","TodoWrite","TodoRead","WebFetch","WebSearch"];function Ll({skipPermissions:t,setSkipPermissions:r,allowedTools:a,setAllowedTools:o,disallowedTools:n,setDisallowedTools:l,newAllowedTool:i,setNewAllowedTool:d,newDisallowedTool:u,setNewDisallowedTool:f}){const x=k=>{k&&!a.includes(k)&&(o([...a,k]),d(""))},g=k=>{o(a.filter(L=>L!==k))},h=k=>{k&&!n.includes(k)&&(l([...n,k]),f(""))},y=k=>{l(n.filter(L=>L!==k))};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(Vs,{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(聊天)"})," 生效,对 ",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(Ot,{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:k=>r(k.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(Wt,{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(it,{value:i,onChange:k=>d(k.target.value),placeholder:'e.g., "Bash(git log:*)" or "Write"',onKeyPress:k=>{k.key==="Enter"&&(k.preventDefault(),x(i))},className:"flex-1 h-10"}),e.jsxs(B,{onClick:()=>x(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(Ft,{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:Il.map(k=>e.jsx(B,{variant:"outline",size:"sm",onClick:()=>x(k),disabled:a.includes(k),className:"text-xs h-8",children:k},k))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(k=>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:k}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>g(k),className:"text-green-600 hover:text-green-700",children:e.jsx(Ge,{className:"w-4 h-4"})})]},k)),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(Ot,{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(it,{value:u,onChange:k=>f(k.target.value),placeholder:'e.g., "Bash(rm:*)"',onKeyPress:k=>{k.key==="Enter"&&(k.preventDefault(),h(u))},className:"flex-1 h-10"}),e.jsxs(B,{onClick:()=>h(u),disabled:!u,size:"sm",className:"h-10 px-4",children:[e.jsx(Ft,{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(k=>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:k}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>y(k),className:"text-red-600 hover:text-red-700",children:e.jsx(Ge,{className:"w-4 h-4"})})]},k)),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 Tl({permissionMode:t,setPermissionMode:r}){return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Wt,{className:"w-5 h-5 text-green-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"权限模式"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"控制 Codex 如何处理文件修改和命令执行"}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="default"?"bg-gray-100 dark:bg-gray-800 border-gray-400 dark:border-gray-500":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("default"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="default",onChange:()=>r("default"),className:"mt-1 w-4 h-4 text-green-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"默认"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"仅受信任的命令(ls、cat、grep、git status 等)会自动运行。其他命令将被跳过。可以写入工作区。"})]})]})}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="acceptEdits"?"bg-green-50 dark:bg-green-900/20 border-green-400 dark:border-green-600":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("acceptEdits"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="acceptEdits",onChange:()=>r("acceptEdits"),className:"mt-1 w-4 h-4 text-green-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-green-900 dark:text-green-100",children:"接受编辑"}),e.jsx("div",{className:"text-sm text-green-700 dark:text-green-300",children:"所有命令在工作区内自动运行。沙盒执行的完全自动模式。"})]})]})}),e.jsx("div",{className:`border rounded-lg p-4 cursor-pointer transition-all ${t==="bypassPermissions"?"bg-orange-50 dark:bg-orange-900/20 border-orange-400 dark:border-orange-600":"bg-gray-50 dark:bg-gray-900/50 border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,onClick:()=>r("bypassPermissions"),children:e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"codexPermissionMode",checked:t==="bypassPermissions",onChange:()=>r("bypassPermissions"),className:"mt-1 w-4 h-4 text-orange-600"}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium text-orange-900 dark:text-orange-100 flex items-center gap-2",children:["跳过权限",e.jsx(Ot,{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 Rl({agent:t,...r}){return t==="claude"?e.jsx(Ll,{...r}):t==="codex"?e.jsx(Tl,{...r}):null}const Dl=t=>{switch(t){case"stdio":return e.jsx(zr,{className:"w-4 h-4"});case"sse":return e.jsx(Ar,{className:"w-4 h-4"});case"http":return e.jsx(Fs,{className:"w-4 h-4"});default:return e.jsx(Ys,{className:"w-4 h-4"})}};function Pl({servers:t,onAdd:r,onEdit:a,onDelete:o,testResults:n,serverTools:l,onDiscoverRepo:i}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ys,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Model Context Protocol 服务器为 ",Ze," 提供额外的工具和数据源"]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs(B,{onClick:r,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(Ft,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(B,{onClick:i,variant:"outline",size:"sm",children:[e.jsx(Qs,{className:"w-4 h-4 mr-2"}),"MCP 商店"]})})]}),e.jsxs("div",{className:"space-y-2",children:[t.map(d=>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:[Dl(d.type),e.jsx("span",{className:"font-medium text-foreground",children:d.name}),e.jsx(et,{variant:"outline",className:"text-xs",children:d.type}),e.jsx(et,{variant:"outline",className:"text-xs",title:d.scope==="local"&&d.projectPath?d.projectPath:void 0,children:d.scope==="local"?`local${d.projectPath?` · ${d.projectPath.split("/").filter(Boolean).pop()}`:""}`:d.scope==="user"?"user":d.scope})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[d.type==="stdio"&&d.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:d.config.command})]}),(d.type==="sse"||d.type==="http")&&d.config?.url&&e.jsxs("div",{children:["URL:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:d.config.url})]}),d.config?.args&&d.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:d.config.args.join(" ")})]})]}),n?.[d.id]&&e.jsx("div",{className:`mt-2 p-2 rounded text-xs ${n[d.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:n[d.id].message})}),l?.[d.id]&&l[d.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:["工具(",l[d.id].tools.length,"):"]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[l[d.id].tools.slice(0,5).map((u,f)=>e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:u.name},f)),l[d.id].tools.length>5&&e.jsxs("span",{className:"text-xs opacity-75",children:["+",l[d.id].tools.length-5," 更多"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(B,{onClick:()=>a(d),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(jr,{className:"w-4 h-4"})}),e.jsx(B,{onClick:()=>o(d.id,d.scope,d.projectPath),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(bt,{className:"w-4 h-4"})})]})]})},d.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function Al(t){return e.jsx(Pl,{...t})}const $l=[{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)使用的模型"}],_l=s.forwardRef(function({onStatusChange:r},a){const[o,n]=s.useState({}),[l,i]=s.useState({}),[d,u]=s.useState(!0),[f,x]=s.useState(!1),[g,h]=s.useState(null),[y,k]=s.useState(null),L=JSON.stringify(o)!==JSON.stringify(l);s.useEffect(()=>{r?.({saving:f,hasChanges:L})},[f,L,r]),s.useEffect(()=>{I()},[]),s.useEffect(()=>{if(g){const m=setTimeout(()=>h(null),3e3);return()=>clearTimeout(m)}},[g]);const I=async()=>{try{u(!0),k(null);const m=await Y("/api/settings/models");if(m.ok){const j=await m.json();n(j.models||{}),i(j.models||{})}else{const j=await m.json();k(j.error||"加载模型配置失败")}}catch(m){k(m.message)}finally{u(!1)}},p=async()=>{try{x(!0),h(null);const m=await Y("/api/settings/models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({models:o})});if(m.ok)return h("success"),i({...o}),!0;{const j=await m.json();return h("error"),k(j.error||"保存失败"),!1}}catch(m){return h("error"),k(m.message),!1}finally{x(!1)}},b=()=>{n({...l}),h(null)};return s.useImperativeHandle(a,()=>({save:p,reset:b,get hasChanges(){return L},get saving(){return f}}),[L,f,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(Vs,{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.jsxs("p",{children:["自定义模型 ID 来覆盖 ",Ze," 和 Claude Code 使用的默认模型。留空表示使用默认模型。"]}),e.jsx("p",{className:"mt-1 text-blue-600 dark:text-blue-400",children:"非 Claude 模型将按 Sonnet 定价计费,但统计中会记录实际模型 ID。"})]})]}),y&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-600 dark:text-red-400",children:y}),g==="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:"模型配置已保存"}),$l.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:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"font-medium text-sm text-foreground",children:m.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:m.description})]}),e.jsx("input",{type:"text",value:o[m.key]||"",onChange:j=>n(R=>({...R,[m.key]:j.target.value})),placeholder:m.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:m.key})]})},m.key))]})});function zl({onClose:t,onInstalled:r,onOpenRepoManager:a,projects:o=[]}){const{showAlert:n}=dt(),[l,i]=s.useState([]),[d,u]=s.useState([]),[f,x]=s.useState(!0),[g,h]=s.useState(null),[y,k]=s.useState(""),[L,I]=s.useState("all"),[p,b]=s.useState(null),[m,j]=s.useState(null),[R,G]=s.useState("user"),[U,v]=s.useState("");s.useEffect(()=>{H()},[]);const H=async(E=!1)=>{try{x(!0),h(null),E&&await Y("/api/skills/repos/refresh",{method:"POST"});const[O,se]=await Promise.all([Y("/api/skills/available"),Y("/api/skills/repos")]);if(O.ok){const re=await O.json();i(re.skills||[])}if(se.ok){const re=await se.json();u(re.repos||[])}}catch(O){h(O.message)}finally{x(!1)}},N=E=>{j(E),G("user"),v("")},z=()=>{j(null),G("user"),v("")},q=async()=>{const E=m;if(E){if(R==="local"&&!U){n("请选择要安装到的项目",{variant:"warning"});return}try{j(null),b(E.name);const O={skillPath:E.path};R==="local"&&U&&(O.projectPath=U);const se=await Y(`/api/skills/install/${E.name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O)});if(se.ok)i(re=>re.map(J=>J.name===E.name?{...J,installed:!0}:J)),r?.();else{const re=await se.json();n(re.error||"安装技能失败",{variant:"error"})}}catch(O){n(O.message,{variant:"error"})}finally{b(null),G("user"),v("")}}},S=l.filter(E=>{if(y){const O=y.toLowerCase();if(!E.name.toLowerCase().includes(O)&&!E.title?.toLowerCase().includes(O)&&!E.description?.toLowerCase().includes(O))return!1}return!(L!=="all"&&E.repository!==L)});return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Skills 管理"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>H(!0),disabled:f,children:[e.jsx(ct,{className:`w-4 h-4 ${f?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(B,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Ut,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Ge,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2"}),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(St,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(it,{type:"text",placeholder:"搜索技能名称或描述...",value:y,onChange:E=>k(E.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:L,onChange:E=>I(E.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(E=>e.jsxs("option",{value:`${E.owner}/${E.repo}`,children:[E.owner,"/",E.repo]},`${E.owner}/${E.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[g&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm mb-4",children:g}),f?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):S.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:l.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的技能"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加技能仓库"}),e.jsxs(B,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Ut,{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:S.map(E=>{const O=p===E.name,se=m?.name===E.name;return 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:E.title||E.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["skills/",E.name]}),e.jsx(et,{variant:"outline",className:"text-xs ml-2",children:E.repository})]})]}),E.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:E.description}),se&&e.jsxs("div",{className:"mt-2 mb-3 p-3 rounded-lg bg-muted/50 border border-border text-sm",children:[e.jsx("p",{className:"font-medium text-foreground mb-2",children:"选择安装位置"}),e.jsxs("label",{className:"flex items-center gap-2 mb-1 cursor-pointer",children:[e.jsx("input",{type:"radio",name:`scope-${E.name}`,value:"user",checked:R==="user",onChange:()=>{G("user"),v("")},className:"accent-amber-600"}),e.jsx("span",{className:"text-foreground",children:"全局(所有项目可用)"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:`scope-${E.name}`,value:"local",checked:R==="local",onChange:()=>G("local"),className:"accent-amber-600"}),e.jsx("span",{className:"text-foreground",children:"安装到指定项目"})]}),R==="local"&&e.jsxs("select",{value:U,onChange:re=>v(re.target.value),className:"mt-2 w-full px-2 py-1.5 rounded-md border border-border bg-background text-foreground text-xs",children:[e.jsx("option",{value:"",children:"选择项目..."}),o.map(re=>e.jsx("option",{value:re.path||re.fullPath,children:re.displayName||re.name},re.name))]}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(B,{size:"sm",variant:"outline",onClick:z,className:"flex-1",children:"取消"}),e.jsx(B,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white flex-1",onClick:q,children:"确认安装"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-auto pt-2",children:[e.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>window.open(`https://github.com/${E.repository}`,"_blank"),children:[e.jsx(Wa,{className:"w-4 h-4 mr-1"}),"查看"]}),E.installed?e.jsx(B,{size:"sm",disabled:!0,variant:"outline",className:"ml-auto",children:"已安装"}):!se&&e.jsxs(B,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white ml-auto",onClick:()=>N(E),disabled:O||!!m,children:[e.jsx(At,{className:"w-4 h-4 mr-1"}),O?"安装中...":"安装"]})]})]})},`${E.repository}-${E.name}`)})})]})]})})}function Ol({onClose:t,onChanged:r}){const{showAlert:a,showConfirm:o}=dt(),[n,l]=s.useState([]),[i,d]=s.useState(!0),[u,f]=s.useState(null),[x,g]=s.useState(""),[h,y]=s.useState("main"),[k,L]=s.useState(!1),[I,p]=s.useState(null);s.useEffect(()=>{b()},[]);const b=async()=>{try{d(!0),f(null);const R=await Y("/api/skills/repos");if(R.ok){const G=await R.json();l(G.repos||[])}else{const G=await R.json();f(G.error||"Failed to fetch repos")}}catch(R){f(R.message)}finally{d(!1)}},m=async R=>{if(R.preventDefault(),!x.trim()){f("请输入仓库 URL");return}try{L(!0),f(null);const G=await Y("/api/skills/repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:x.trim(),branch:h.trim()||"main"})});if(G.ok)g(""),y("main"),b(),r?.();else{const U=await G.json();f(U.error||"Failed to add repo")}}catch(G){f(G.message)}finally{L(!1)}},j=async(R,G)=>{if(await o(`确定要移除仓库 "${R}/${G}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{p(`${R}/${G}`);const U=await Y(`/api/skills/repos/${R}/${G}`,{method:"DELETE"});if(U.ok)b(),r?.();else{const v=await U.json();a(v.error||"移除仓库失败",{variant:"error"})}}catch(U){a(U.message,{variant:"error"})}finally{p(null)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 border-b border-border",children:[e.jsx(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Zt,{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:m,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(it,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:x,onChange:R=>g(R.target.value),disabled:k})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"分支"}),e.jsx(it,{type:"text",placeholder:"main",value:h,onChange:R=>y(R.target.value),disabled:k})]}),e.jsxs(B,{type:"submit",disabled:k||!x.trim(),className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(Ft,{className:"w-4 h-4 mr-2"}),k?"添加中...":"添加仓库"]})]})]}),u&&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:u}),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(Ba,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何仓库"})]}):n.map(R=>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:[R.owner,"/",R.repo]}),R.isSystem&&e.jsx(et,{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(Qs,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(et,{variant:"outline",className:"text-xs",children:["识别到 ",R.skillCount," 个技能"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[!R.isSystem&&R.url&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>window.open(R.url,"_blank"),children:e.jsx(Wa,{className:"w-4 h-4"})}),!R.isSystem&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>j(R.owner,R.repo),disabled:I===`${R.owner}/${R.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(bt,{className:"w-4 h-4"})})]})]})},`${R.owner}/${R.repo}`))]})]})]})})}function Fl({projects:t=[]}){const{showAlert:r,showConfirm:a}=dt(),[o,n]=s.useState([]),[l,i]=s.useState(!0),[d,u]=s.useState(null),[f,x]=s.useState(!1),[g,h]=s.useState(!1),[y,k]=s.useState(!1),[L,I]=s.useState(null),p=s.useRef(null);s.useEffect(()=>{b()},[]);const b=async()=>{try{i(!0),u(null);const N=await Y("/api/skills");if(N.ok){const z=await N.json();n(z.skills||[])}else{const z=await N.json();u(z.error||"Failed to fetch skills")}}catch(N){u(N.message)}finally{i(!1)}},m=async()=>{try{const N=await Y("/api/skills");if(N.ok){const z=await N.json();n(z.skills||[])}}catch{}},j=async N=>{try{const z=await Y(`/api/skills/${N}/download`);if(!z.ok){const O=await z.json();r(O.error||"下载技能失败",{variant:"error"});return}const q=await z.blob(),S=URL.createObjectURL(q),E=document.createElement("a");E.href=S,E.download=`${N}.zip`,E.click(),URL.revokeObjectURL(S)}catch(z){r(z.message,{variant:"error"})}},R=async N=>{if(await a(`确定要删除技能 "${N.name}" 吗?`,{title:"删除技能",variant:"danger",confirmText:"确认删除"}))try{const z=N.projectPath?`/api/skills/${N.name}?projectPath=${encodeURIComponent(N.projectPath)}`:`/api/skills/${N.name}`,q=await Y(z,{method:"DELETE"});if(q.ok)b();else{const S=await q.json();r(S.error||"删除技能失败",{variant:"error"})}}catch(z){r(z.message,{variant:"error"})}},G=async N=>{let z,q;if(N.syncType==="builtin"?(q="同步修改到云端",z=`确定要将技能 "${N.name}" 的本地修改推送到共享仓库吗?
155
+
156
+ 这会把你在本地对该技能所做的修改同步到公司的共享 Git 仓库,其他用户拉取更新后即可获得最新版本。`):N.syncType==="external"?(q="迁移技能到共享仓库",z=`确定要将技能 "${N.name}" 迁移到公司共享仓库吗?
157
+
158
+ 该技能目前来自第三方仓库(${N.repository}),迁移后将由你自行维护,与原仓库互不影响(原仓库中仍保留该技能)。`):(q="同步技能到共享仓库",z=`确定要将技能 "${N.name}" 上传到公司共享仓库吗?
159
+
160
+ 同步后,这个本地技能将上传到共享 Git 仓库,其他人即可安装使用。本地副本将被删除,后续该技能将从共享仓库加载。`),!!await a(z,{title:q,confirmText:"确认同步"}))try{I(N.name);const S=await Y(`/api/skills/${N.name}/sync`,{method:"POST"});if(S.ok)b();else{const E=await S.json();r(E.error||"同步失败",{variant:"error"})}}catch(S){r(S.message,{variant:"error"})}finally{I(null)}},U=()=>{p.current?.click()},v=async N=>{const z=N.target.files?.[0];if(z)try{k(!0);const q=new FormData;q.append("skillZip",z);const S=await Y("/api/skills/import",{method:"POST",body:q});if(S.ok)b();else{const E=await S.json();r(E.error||"上传技能失败",{variant:"error"})}}catch(q){r(q.message,{variant:"error"})}finally{k(!1),p.current&&(p.current.value="")}},H=(N,z)=>{switch(N){case"repo":return e.jsx(et,{variant:"outline",className:"text-xs bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300",children:z||"仓库"});case"imported":return e.jsx(et,{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(et,{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.jsxs("p",{className:"text-sm text-muted-foreground",children:["Skills 是 ",Ze," 的扩展能力,可以通过 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:["已安装: ",e.jsx("span",{className:"font-medium text-foreground",children:o.length})," 个技能"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{ref:p,type:"file",accept:".zip",className:"hidden",onChange:v}),e.jsxs(B,{onClick:U,variant:"outline",size:"sm",disabled:y,children:[e.jsx(zt,{className:"w-4 h-4 mr-2"}),y?"上传中...":"上传本地技能"]}),e.jsxs(B,{onClick:()=>x(!0),className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:[e.jsx(St,{className:"w-4 h-4 mr-2"}),"发现技能"]})]})]}),d&&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:d}),l?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):o.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:'点击"发现技能"从仓库安装,或"上传已有"本地技能'})]}):e.jsx("div",{className:"grid grid-cols-2 gap-3",children:o.map(N=>e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg px-4 pt-4 pb-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:N.title||N.name}),H(N.source,N.repository),e.jsx(et,{variant:"outline",className:"text-xs",title:N.scope==="local"&&N.projectPath?N.projectPath:void 0,children:N.scope==="local"?`local · ${N.projectPath?N.projectPath.split("/").filter(Boolean).pop():""}`:"user"})]}),N.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-3 flex-1",children:N.description}),e.jsxs("div",{className:"flex items-center justify-end mt-2",children:[N.syncable&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>G(N),disabled:L===N.name,title:"同步到云端",children:L===N.name?e.jsx(ct,{className:"w-4 h-4 animate-spin"}):e.jsx(ho,{className:"w-4 h-4"})}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>j(N.name),title:"下载技能",children:e.jsx(At,{className:"w-4 h-4"})}),e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>R(N),className:"text-red-500 hover:text-red-600",title:"删除技能",children:e.jsx(bt,{className:"w-4 h-4"})})]})]},N.name))}),f&&e.jsx(zl,{onClose:()=>x(!1),onInstalled:m,onOpenRepoManager:()=>{x(!1),h(!0)},projects:t}),g&&e.jsx(Ol,{onClose:()=>h(!1),onChanged:()=>{}})]})}function Ul({projects:t=[]}){const{showAlert:r,showConfirm:a}=dt(),{hasPermission:o}=Ct(),[n,l]=s.useState([]),[i,d]=s.useState(!0),[u,f]=s.useState(!1),[x,g]=s.useState(null),[h,y]=s.useState(!1),[k,L]=s.useState(null),[I,p]=s.useState([]),[b,m]=s.useState(!1),[j,R]=s.useState(!1),G={};for(const S of t)if(S.agentInfo?.isAgent){const E=S.agentInfo.agentName;G[E]=S.agentInfo.installedVersion}const U=i?[]:t.filter(S=>S.agentInfo?.isAgent&&!n.some(E=>(E.dirName||E.name)===S.agentInfo.agentName));s.useEffect(()=>{v(),H()},[]);const v=async()=>{try{d(!0);const S=await Y("/api/agents");if(S.ok){const E=await S.json();l(E.agents||[])}else{const E=await S.json();r(E.error||"获取 Agent 列表失败",{variant:"error"})}}catch(S){r(S.message,{variant:"error"})}finally{d(!1)}},H=async()=>{try{m(!0);const S=await Y("/api/agents/submissions/my");if(S.ok){const E=await S.json();p(E.submissions||[])}}catch{}finally{m(!1)}},N=async()=>{try{f(!0);const S=await Y("/api/agents/refresh",{method:"POST"});if(S.ok)await v();else{const E=await S.json();r(E.error||"刷新失败",{variant:"error"})}}catch(S){r(S.message,{variant:"error"})}finally{f(!1)}},z=async(S,E=!1)=>{const O=S.dirName||S.name;g(O);try{const se=await Y("/api/agents/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentName:O,force:E})}),re=await se.json();if(se.status===409&&re.conflict){g(null),await a("检测到本地 CLAUDE.md 已被修改,更新将覆盖本地改动,是否继续?",{title:"本地文件冲突",confirmText:"强制更新",variant:"warning"})&&await z(S,!0);return}se.ok?(r(`Agent "${S.display_name||S.name}" ${E?"更新":"安装"}成功!项目已创建,Skills 和 MCP 服务已安装。`,{title:E?"更新成功":"安装成功"}),window.refreshProjects?.(),window.refreshMcpServers?.(),v()):r(re.error||"安装失败",{variant:"error"})}catch(se){r(se.message,{variant:"error"})}finally{g(null)}},q=S=>{const E=S.dirName||S.name,O=G[E];return O?O===S.version?{state:"up_to_date",installedVersion:O}:{state:"update_available",installedVersion:O,latestVersion:S.version}:{state:"not_installed"}};return i?e.jsxs("div",{className:"flex items-center justify-center py-12 text-gray-500 dark:text-gray-400",children:[e.jsx(ct,{className:"w-5 h-5 animate-spin mr-2"}),"加载中..."]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"从共享项目仓库使用预配置的项目模板,包含所需的 Skills 和 MCP 服务。"}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(B,{variant:"outline",size:"sm",onClick:N,disabled:u,className:"flex items-center gap-1.5",children:[e.jsx(ct,{className:`w-3.5 h-3.5 ${u?"animate-spin":""}`}),"刷新"]}),o("submit_agent")&&e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>y(!0),className:"flex items-center gap-1.5",children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),"分享项目模板"]})]})]}),n.length===0?e.jsxs("div",{className:"text-center py-12 text-gray-500 dark:text-gray-400 border border-dashed border-gray-200 dark:border-gray-700 rounded-lg",children:[e.jsx(Pt,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"暂无可用共享项目模板"}),e.jsx("p",{className:"text-xs mt-1",children:'点击"刷新"从服务器获取最新共享项目模板列表'})]}):e.jsx("div",{className:"space-y-2",children:n.map(S=>{const E=S.dirName||S.name,O=q(S),se=k===E,re=x===E;return e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center flex-shrink-0",children:e.jsx(Pt,{className:"w-4 h-4 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm text-gray-900 dark:text-gray-100 truncate",children:S.display_name||S.name}),e.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:["v",S.version]}),O.state==="update_available"&&e.jsxs(et,{className:"text-xs bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400 border-amber-200 dark:border-amber-700 hover:bg-amber-200 dark:hover:bg-amber-900/50 flex-shrink-0",children:["有更新 v",O.latestVersion]}),O.state==="up_to_date"&&e.jsx(et,{className:"text-xs bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400 border-green-200 dark:border-green-700 hover:bg-green-200 dark:hover:bg-green-900/50 flex-shrink-0",children:"已使用"})]}),S.description&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 truncate",children:S.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[S.skills?.length>0&&e.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:[S.skills.length," 个 Skill"]}),S.mcps?.length>0&&e.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:[S.mcps.length," 个 MCP"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(B,{size:"sm",variant:O.state==="not_installed"?"default":"outline",onClick:()=>z(S),disabled:re||O.state==="up_to_date",className:"text-xs h-7 px-2.5",children:re?e.jsx(ct,{className:"w-3 h-3 animate-spin"}):O.state==="up_to_date"?"已是最新":O.state==="update_available"?e.jsxs(e.Fragment,{children:[e.jsx(At,{className:"w-3 h-3 mr-1"}),"更新"]}):e.jsxs(e.Fragment,{children:[e.jsx(At,{className:"w-3 h-3 mr-1"}),"使用"]})}),(S.skills?.length>0||S.mcps?.length>0)&&e.jsx("button",{onClick:()=>L(se?null:E),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:se?e.jsx(wr,{className:"w-4 h-4"}):e.jsx(Qt,{className:"w-4 h-4"})})]})]}),se&&e.jsxs("div",{className:"border-t border-gray-100 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 px-3 py-2 space-y-2",children:[S.skills?.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 mb-1",children:"所需 Skills"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:S.skills.map(J=>e.jsx(et,{variant:"outline",className:"text-xs",children:J.name},J.name))})]}),S.mcps?.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 mb-1",children:"所需 MCP 服务"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:S.mcps.map(J=>e.jsx(et,{variant:"outline",className:"text-xs",children:J.name},J.name))})]})]})]},E)})}),U.length>0&&e.jsxs("div",{className:"border border-amber-200 dark:border-amber-800 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-amber-50 dark:bg-amber-900/10 border-b border-amber-200 dark:border-amber-800",children:[e.jsx(Ot,{className:"w-3.5 h-3.5 text-amber-500"}),e.jsx("span",{className:"text-xs font-medium text-amber-700 dark:text-amber-400",children:"以下 Agent 已从仓库下线"})]}),e.jsx("div",{className:"divide-y divide-amber-100 dark:divide-amber-900/20",children:U.map(S=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-gray-800 dark:text-gray-200",children:S.displayName}),e.jsx("span",{className:"text-xs text-gray-400 font-mono ml-2",children:S.agentInfo.agentName}),e.jsxs("span",{className:"text-xs text-amber-600 dark:text-amber-400 ml-2",children:["v",S.agentInfo.installedVersion]})]}),e.jsx("span",{className:"text-xs text-amber-500 dark:text-amber-400",children:"已下线,本地仍可继续使用"})]},S.agentInfo.agentName))})]}),(I.length>0||b)&&e.jsxs("div",{className:"mt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("button",{onClick:()=>R(S=>!S),className:"flex items-center gap-1 text-sm font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100",children:[j?e.jsx(wr,{className:"w-3.5 h-3.5"}):e.jsx(Qt,{className:"w-3.5 h-3.5"}),"我的提交记录"]}),e.jsxs("button",{onClick:H,disabled:b,className:"text-xs text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex items-center gap-1",children:[e.jsx(ct,{className:`w-3 h-3 ${b?"animate-spin":""}`}),"刷新"]})]}),j&&e.jsx("div",{className:"space-y-2",children:I.map(S=>{const E={pending:{label:"审核中",icon:Os,color:"text-amber-600 dark:text-amber-400",bg:"bg-amber-50 dark:bg-amber-900/20 border-amber-200 dark:border-amber-800"},approved:{label:"已通过",icon:qa,color:"text-green-600 dark:text-green-400",bg:"bg-green-50 dark:bg-green-900/20 border-green-200 dark:border-green-800"},rejected:{label:"已拒绝",icon:Ha,color:"text-red-600 dark:text-red-400",bg:"bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800"}},O=E[S.status]||E.pending,se=O.icon;return e.jsx("div",{className:`border rounded-lg px-3 py-2.5 ${O.bg}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:S.display_name}),e.jsxs("span",{className:"text-xs text-gray-400",children:["(",S.agent_name,")"]}),S.version&&e.jsxs("span",{className:"text-xs text-gray-400",children:["v",S.version]})]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:["提交于 ",new Date(S.submitted_at).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"})]}),S.status==="rejected"&&S.reject_reason&&e.jsxs("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1",children:["拒绝原因:",S.reject_reason]}),S.status==="approved"&&S.reviewed_at&&e.jsxs("p",{className:"text-xs text-green-600 dark:text-green-400 mt-0.5",children:["审核通过,已发布为 v",S.version]})]}),e.jsxs("div",{className:`flex items-center gap-1 flex-shrink-0 text-xs font-medium ${O.color}`,children:[e.jsx(se,{className:"w-3.5 h-3.5"}),O.label]})]})},S.id)})})]}),h&&e.jsx(Ur,{projects:t,onClose:()=>y(!1),onSubmitted:()=>{y(!1),H()}})]})}function Wl({onClose:t,onChanged:r}){const{showAlert:a,showConfirm:o}=dt(),[n,l]=s.useState([]),[i,d]=s.useState(!0),[u,f]=s.useState(null),[x,g]=s.useState(""),[h,y]=s.useState(!1),[k,L]=s.useState(null);s.useEffect(()=>{I()},[]);const I=async()=>{try{d(!0),f(null);const m=await Y("/api/mcp-repos");if(m.ok){const j=await m.json();l(j.repos||[])}else{const j=await m.json();f(j.error||"Failed to fetch repos")}}catch(m){f(m.message)}finally{d(!1)}},p=async m=>{if(m.preventDefault(),!x.trim()){f("请输入仓库 URL");return}try{y(!0),f(null);const j=await Y("/api/mcp-repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:x.trim()})});if(j.ok)g(""),I(),r?.();else{const R=await j.json();f(R.error||"Failed to add repo")}}catch(j){f(j.message)}finally{y(!1)}},b=async(m,j)=>{if(await o(`确定要移除仓库 "${m}/${j}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{L(`${m}/${j}`);const R=await Y(`/api/mcp-repos/${m}/${j}`,{method:"DELETE"});if(R.ok)I(),r?.();else{const G=await R.json();a(G.error||"移除仓库失败",{variant:"error"})}}catch(R){a(R.message,{variant:"error"})}finally{L(null)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[10000] p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 border-b border-border",children:[e.jsx(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Zt,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"管理 MCP 仓库"})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-900/50 rounded-lg p-4 space-y-4",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"添加 MCP 仓库"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["仓库中每个文件夹代表一个 MCP 服务,需包含 ",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:"mcp.json"}),"(配置)和 ",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:"mcp.yaml"}),"(说明)。"]}),e.jsxs("form",{onSubmit:p,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"仓库 URL"}),e.jsx(it,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:x,onChange:m=>g(m.target.value),disabled:h})]}),e.jsxs(B,{type:"submit",disabled:h||!x.trim(),className:"bg-purple-600 hover:bg-purple-700 text-white",children:[e.jsx(Ft,{className:"w-4 h-4 mr-2"}),h?"添加中...":"添加仓库"]})]})]}),u&&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:u}),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(Ba,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何 MCP 仓库"})]}):n.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-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:[m.owner,"/",m.repo]}),m.isSystem&&e.jsx(et,{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(Qs,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(et,{variant:"outline",className:"text-xs",children:[m.serviceCount," 个 MCP 服务"]})]})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4",children:!m.isSystem&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>b(m.owner,m.repo),disabled:k===`${m.owner}/${m.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(bt,{className:"w-4 h-4"})})})]})},`${m.owner}/${m.repo}`))]})]})]})})}const Bl=t=>{switch(t){case"stdio":return e.jsx(zr,{className:"w-3 h-3"});case"sse":return e.jsx(Ar,{className:"w-3 h-3"});case"http":return e.jsx(Fs,{className:"w-3 h-3"});default:return e.jsx(Ys,{className:"w-3 h-3"})}};function Hl({onClose:t,onInstalled:r,onOpenRepoManager:a,projects:o=[]}){const{showAlert:n,showConfirm:l}=dt(),[i,d]=s.useState([]),[u,f]=s.useState([]),[x,g]=s.useState(!0),[h,y]=s.useState(null),[k,L]=s.useState(""),[I,p]=s.useState("all"),[b,m]=s.useState(null),[j,R]=s.useState(null),[G,U]=s.useState(null),[v,H]=s.useState("user"),[N,z]=s.useState("");s.useEffect(()=>{q()},[]);const q=async(J=!1)=>{try{g(!0),y(null),J&&await Y("/api/mcp-repos/refresh",{method:"POST"});const[le,me]=await Promise.all([Y("/api/mcp-repos/available"),Y("/api/mcp-repos")]);if(le.ok){const ge=await le.json();d(ge.services||[])}if(me.ok){const ge=await me.json();f(ge.repos||[])}}catch(le){y(le.message)}finally{g(!1)}},S=J=>{U(J),H("user"),z("")},E=()=>{U(null),H("user"),z("")},O=async()=>{const J=G;if(J){if(v==="local"&&!N){n("请选择要安装到的项目",{variant:"warning"});return}try{U(null),m(J.dirName+J.repository);const le={servicePath:J.path,scope:v};v==="local"&&N&&(le.projectPath=N);const me=await Y("/api/mcp-repos/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(le)});if(me.ok)q(),r?.();else{const ge=await me.json();n(ge.error||"安装 MCP 服务失败",{variant:"error"})}}catch(le){n(le.message,{variant:"error"})}finally{m(null),H("user"),z("")}}},se=async J=>{if(!(!J.serverNames||J.serverNames.length===0)&&await l(`确定要卸载 "${J.name}" 吗?这将移除 ${J.serverNames.join(", ")} 的配置。`,{title:"卸载 MCP 服务",variant:"danger",confirmText:"确认卸载"}))try{R(J.dirName+J.repository);for(const le of J.serverNames)await Y(`/api/mcp-repos/uninstall/${encodeURIComponent(le)}`,{method:"DELETE"});q(),r?.()}catch(le){n(le.message,{variant:"error"})}finally{R(null)}},re=i.filter(J=>{if(k){const le=k.toLowerCase();if(!J.dirName?.toLowerCase().includes(le)&&!J.name?.toLowerCase().includes(le)&&!J.description?.toLowerCase().includes(le))return!1}return!(I!=="all"&&J.repository!==I)});return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[10000] p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"MCP 仓库"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>q(!0),disabled:x,children:[e.jsx(ct,{className:`w-4 h-4 ${x?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(B,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Ut,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(B,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Ge,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2"}),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(St,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(it,{type:"text",placeholder:"搜索 MCP 服务名称或描述...",value:k,onChange:J=>L(J.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:I,onChange:J=>p(J.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:"全部仓库"}),u.map(J=>e.jsxs("option",{value:`${J.owner}/${J.repo}`,children:[J.owner,"/",J.repo]},`${J.owner}/${J.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[h&&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:h}),x?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):re.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:i.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的 MCP 服务"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加 MCP 仓库"}),e.jsxs(B,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Ut,{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:re.map(J=>{const le=`${J.repository}-${J.dirName}`,me=b===J.dirName+J.repository,ge=j===J.dirName+J.repository,De=G&&G.dirName+G.repository===J.dirName+J.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:J.name||J.dirName}),e.jsxs(et,{variant:"outline",className:"text-xs flex items-center gap-1",children:[Bl(J.type),J.type]})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:J.repository}),J.serverNames?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:["· ",J.serverNames.join(", ")]})]})]}),J.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:J.description}),De&&e.jsxs("div",{className:"mt-2 mb-3 p-3 rounded-lg bg-muted/50 border border-border text-sm",children:[e.jsx("p",{className:"font-medium text-foreground mb-2",children:"选择安装位置"}),e.jsxs("label",{className:"flex items-center gap-2 mb-1 cursor-pointer",children:[e.jsx("input",{type:"radio",name:`scope-${le}`,value:"user",checked:v==="user",onChange:()=>{H("user"),z("")},className:"accent-purple-600"}),e.jsx("span",{className:"text-foreground",children:"全局(所有项目可用)"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:`scope-${le}`,value:"local",checked:v==="local",onChange:()=>H("local"),className:"accent-purple-600"}),e.jsx("span",{className:"text-foreground",children:"安装到指定项目"})]}),v==="local"&&e.jsxs("select",{value:N,onChange:we=>z(we.target.value),className:"mt-2 w-full px-2 py-1.5 rounded-md border border-border bg-background text-foreground text-xs",children:[e.jsx("option",{value:"",children:"选择项目..."}),o.map(we=>e.jsx("option",{value:we.path||we.fullPath,children:we.displayName||we.name},we.name))]}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(B,{size:"sm",variant:"outline",onClick:E,className:"flex-1",children:"取消"}),e.jsx(B,{size:"sm",className:"bg-purple-600 hover:bg-purple-700 text-white flex-1",onClick:O,children:"确认安装"})]})]}),e.jsx("div",{className:"flex items-center gap-2 mt-auto pt-2",children:J.installed?e.jsxs(B,{size:"sm",variant:"outline",className:"ml-auto text-red-600 hover:text-red-700 border-red-200 hover:border-red-300",onClick:()=>se(J),disabled:ge,children:[e.jsx(bt,{className:"w-4 h-4 mr-1"}),ge?"卸载中...":"卸载"]}):!De&&e.jsxs(B,{size:"sm",className:"bg-purple-600 hover:bg-purple-700 text-white ml-auto",onClick:()=>S(J),disabled:me||!!G,children:[e.jsx(At,{className:"w-4 h-4 mr-1"}),me?"安装中...":"安装"]})})]})},le)})})]})]})})}function ql({isOpen:t,onClose:r,projects:a=[],initialTab:o="shared_projects",autoScrollToBottom:n,onAutoScrollChange:l,sendByCtrlEnter:i,onSendByCtrlEnterChange:d}){const u=Gs(),{isDarkMode:f,toggleDarkMode:x}=Vr(),{user:g,logout:h,hasPermission:y}=Ct(),{showAlert:k,showConfirm:L}=dt(),[I,p]=s.useState([]),[b,m]=s.useState([]),[j,R]=s.useState(""),[G,U]=s.useState(""),[v,H]=s.useState(!1),[N,z]=s.useState(!1),[q,S]=s.useState(null),[E,O]=s.useState("name"),[se,re]=s.useState([]),[J,le]=s.useState(!1),[me,ge]=s.useState(null),[De,we]=s.useState(!1),[Me,Ue]=s.useState(!1),[ie,Se]=s.useState({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),[We,Be]=s.useState(!1),[ve,Ie]=s.useState({}),[Le,qe]=s.useState({}),[ke,Je]=s.useState({}),[$e,Pe]=s.useState(o),[_e,ze]=s.useState(""),[Ae,Ye]=s.useState("permissions"),Oe=y("tab_permissions")||y("tab_mcp")||y("tab_skills")||y("tab_models");s.useEffect(()=>{const _={permissions:"tab_permissions",mcp:"tab_mcp",skills:"tab_skills",models:"tab_models"},Z=_[Ae];if(Z&&!y(Z)){const Ce=["permissions","mcp","skills","models"].find(gt=>{const Ve=_[gt];return!Ve||y(Ve)});Ce&&Ye(Ce)}},[y,Ae]),s.useEffect(()=>{$e==="agents"&&!Oe&&Pe("shared_projects")},[$e,Oe]);const V=s.useRef(null),[$,w]=s.useState({saving:!1,hasChanges:!1}),ee=s.useCallback(_=>w(_),[]),[A,te]=s.useState(""),[K,oe]=s.useState(""),[ce,Re]=s.useState(""),[ae,Te]=s.useState(""),[Ee,pe]=s.useState(""),[tt,Fe]=s.useState(!1),[D,ue]=s.useState(""),[M,ne]=s.useState(!1),[W,Ne]=s.useState(""),[nt,Xe]=s.useState(!1),[ot,pt]=s.useState(null),[lt,st]=s.useState(()=>localStorage.getItem("codeEditorTheme")||"dark"),[Bt,cs]=s.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[yt,Cs]=s.useState(()=>localStorage.getItem("codeEditorShowMinimap")!=="false"),[Ht,Et]=s.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[ds,ms]=s.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),vt=async()=>{try{const _=await Y("/api/mcp/config/read");if(_.ok){const Ce=await _.json();if(Ce.success&&Ce.servers){re(Ce.servers);return}}const Z=await Y("/api/mcp/cli/list");if(Z.ok){const Ce=await Z.json();if(Ce.success&&Ce.servers){const gt=Ce.servers.map(Ve=>({id:Ve.name,name:Ve.name,type:Ve.type,scope:"user",config:{command:Ve.command||"",args:Ve.args||[],env:Ve.env||{},url:Ve.url||"",headers:Ve.headers||{},timeout:3e4},created:new Date().toISOString(),updated:new Date().toISOString()}));re(gt);return}}const xe=await Y("/api/mcp/servers?scope=user");if(xe.ok){const Ce=await xe.json();re(Ce.servers||[])}else console.error("Failed to fetch MCP servers")}catch(_){console.error("Error fetching MCP servers:",_)}},Es=async _=>{try{me&&await qt(me.id,"user");const Z=await Y("/api/mcp/cli/add",{method:"POST",body:JSON.stringify({name:_.name,type:_.type,scope:_.scope,projectPath:_.projectPath,command:_.config?.command,args:_.config?.args||[],url:_.config?.url,headers:_.config?.headers||{},env:_.config?.env||{}})});if(Z.ok){const xe=await Z.json();if(xe.success)return await vt(),!0;throw new Error(xe.error||"Failed to save server via Claude CLI")}else{const xe=await Z.json();throw new Error(xe.error||"Failed to save server")}}catch(Z){throw console.error("Error saving MCP server:",Z),Z}},qt=async(_,Z="user",xe="")=>{try{let Ce=`/api/mcp/cli/remove/${encodeURIComponent(_)}?scope=${Z}`;Z==="local"&&xe&&(Ce+=`&projectPath=${encodeURIComponent(xe)}`);const gt=await Y(Ce,{method:"DELETE"});if(gt.ok){const Ve=await gt.json();if(Ve.success)return await vt(),!0;throw new Error(Ve.error||"Failed to delete server via Claude CLI")}else{const Ve=await gt.json();throw new Error(Ve.error||"Failed to delete server")}}catch(Ce){throw console.error("Error deleting MCP server:",Ce),Ce}},Ms=async(_,Z="user")=>{try{const xe=await Y(`/api/mcp/servers/${_}/test?scope=${Z}`,{method:"POST"});if(xe.ok)return(await xe.json()).testResult;{const Ce=await xe.json();throw new Error(Ce.error||"Failed to test server")}}catch(xe){throw console.error("Error testing MCP server:",xe),xe}},ts=async(_,Z="user")=>{try{const xe=await Y(`/api/mcp/servers/${_}/tools?scope=${Z}`,{method:"POST"});if(xe.ok)return(await xe.json()).toolsResult;{const Ce=await xe.json();throw new Error(Ce.error||"Failed to discover tools")}}catch(xe){throw console.error("Error discovering MCP tools:",xe),xe}};s.useEffect(()=>{t&&(Xs(),Pe(o),he.auth.feishuStatus().then(_=>_.json()).then(_=>{pt(_.bound?_:!1)}).catch(()=>pt(!1)))},[t,o]),s.useEffect(()=>(window.refreshMcpServers=vt,()=>{delete window.refreshMcpServers}),[vt]),s.useEffect(()=>{localStorage.setItem("codeEditorTheme",lt),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[lt]),s.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",Bt.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Bt]),s.useEffect(()=>{localStorage.setItem("codeEditorShowMinimap",yt.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[yt]),s.useEffect(()=>{localStorage.setItem("codeEditorLineNumbers",Ht.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Ht]),s.useEffect(()=>{localStorage.setItem("codeEditorFontSize",ds),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[ds]);const Xs=async()=>{try{let _=null;try{const Z=await he.settings.getAgentPermissions();Z.ok&&(_=(await Z.json()).agentPermissions)}catch{}if(_)p(_.allowedTools||[]),m(_.disallowedTools||[]),H(_.skipPermissions||!1),O(_.projectSortOrder||"name"),localStorage.setItem("claude-settings",JSON.stringify(_));else{const Z=localStorage.getItem("claude-settings");if(Z){const xe=JSON.parse(Z);p(xe.allowedTools||[]),m(xe.disallowedTools||[]),H(xe.skipPermissions||!1),O(xe.projectSortOrder||"name")}else p([]),m([]),H(!1),O("name")}await vt()}catch(_){console.error("Error loading tool settings:",_),p([]),m([]),H(!1),O("name")}},ht=async()=>{z(!0),S(null);try{const _={allowedTools:I,disallowedTools:b,skipPermissions:v,projectSortOrder:E,lastUpdated:new Date().toISOString()};localStorage.setItem("claude-settings",JSON.stringify(_));try{await he.settings.saveAgentPermissions(_)}catch(Z){console.warn("Failed to sync agent permissions to server:",Z)}S("success"),setTimeout(()=>{r()},1e3)}catch(_){console.error("Error saving tool settings:",_),S("error")}finally{z(!1)}},Jt=async _=>{if(_.preventDefault(),Te(""),pe(""),!A){Te("请输入当前密码");return}if(!K){Te("请输入新密码");return}if(K.length<6){Te("新密码至少需要6个字符");return}if(K!==ce){Te("两次输入的新密码不一致");return}Fe(!0);try{const Z=await he.auth.changePassword(A,K),xe=await Z.json();Z.ok?(pe("密码修改成功"),te(""),oe(""),Re("")):Te(xe.error||"修改密码失败")}catch(Z){console.error("Error changing password:",Z),Te("网络错误,请稍后再试")}finally{Fe(!1)}},ss=g?.username&&!g.username.includes("@"),rs=async()=>{ne(!0),Ne(""),ue(""),Xe(!1);try{const _=await he.auth.feishuBindToken(),Z=await _.json();_.ok&&Z.token?ue(Z.token):Ne(Z.error||"生成失败,请重试")}catch{Ne("网络错误,请稍后再试")}finally{ne(!1)}},us=()=>{if(!D)return;const _=`/auth ${D}`;if(navigator.clipboard&&window.isSecureContext)navigator.clipboard.writeText(_).then(()=>{Xe(!0),setTimeout(()=>Xe(!1),2e3)});else{const Z=document.createElement("textarea");Z.value=_,Z.style.position="fixed",Z.style.opacity="0",document.body.appendChild(Z),Z.focus(),Z.select();try{document.execCommand("copy"),Xe(!0),setTimeout(()=>Xe(!1),2e3)}finally{document.body.removeChild(Z)}}},xt=()=>{Se({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),ge(null),le(!1),ze("")},Kt=(_=null)=>{_?(ge(_),Se({name:_.name,type:_.type,scope:_.scope,projectPath:_.projectPath||"",config:{..._.config},raw:_.raw,importMode:"form",jsonInput:""})):xt(),le(!0)},ps=async _=>{_.preventDefault(),Be(!0);try{if(ie.importMode==="json"){const Z=await Y("/api/mcp/cli/add-json",{method:"POST",body:JSON.stringify({name:ie.name,jsonConfig:ie.jsonInput,scope:ie.scope,projectPath:ie.projectPath})});if(Z.ok){const xe=await Z.json();if(xe.success)await vt(),xt(),S("success");else throw new Error(xe.error||"Failed to add server via JSON")}else{const xe=await Z.json();throw new Error(xe.error||"Failed to add server")}}else await Es(ie),xt(),S("success")}catch(Z){k(`错误: ${Z.message}`,{variant:"error"}),S("error")}finally{Be(!1)}},xs=async(_,Z,xe)=>{if(await L("确定要删除此 MCP 服务器吗?",{title:"删除 MCP 服务器",variant:"danger",confirmText:"确认删除"}))try{await qt(_,Z,xe),S("success")}catch(Ce){k(`错误: ${Ce.message}`,{variant:"error"}),S("error")}},It=async(_,Z)=>{try{Ie({...ve,[_]:{loading:!0}});const xe=await Ms(_,Z);Ie({...ve,[_]:xe})}catch(xe){Ie({...ve,[_]:{success:!1,message:xe.message,details:[]}})}},ft=async(_,Z)=>{try{Je({...ke,[_]:!0});const xe=await ts(_,Z);qe({...Le,[_]:xe})}catch{qe({...Le,[_]:{success:!1,tools:[],resources:[],prompts:[]}})}finally{Je({...ke,[_]:!1})}},Lt=(_,Z)=>{Se(xe=>({...xe,config:{...xe.config,[_]:Z}}))};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(Ut,{className:"w-5 h-5 md:w-6 md:h-6 text-blue-600"}),e.jsx("h2",{className:"text-lg md:text-xl font-semibold text-foreground",children:"设置"})]}),e.jsx(B,{variant:"ghost",size:"sm",onClick:r,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(Ge,{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:[Oe&&e.jsx("button",{onClick:()=>Pe("agents"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${$e==="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:()=>Pe("shared_projects"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${$e==="shared_projects"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"共享项目模板"}),e.jsx("button",{onClick:()=>Pe("appearance"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${$e==="appearance"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"外观"}),e.jsx("button",{onClick:()=>Pe("account"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${$e==="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:[$e==="appearance"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:$e==="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:x,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":f,"aria-label":"Toggle dark mode",children:[e.jsx("span",{className:"sr-only",children:"Toggle dark mode"}),e.jsx("span",{className:`${f?"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:f?e.jsx(Us,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Ws,{className:"w-3.5 h-3.5 text-yellow-500"})})]})]})})}),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.jsxs("div",{className:"font-medium text-foreground flex items-center gap-2",children:[e.jsx(go,{className:"h-4 w-4 text-muted-foreground"}),"自动滚动到底部"]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"有新消息时自动滚动到底部"})]}),e.jsxs("button",{onClick:()=>l&&l(!n),className:`relative inline-flex h-8 w-14 items-center rounded-full transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900 ${n?"bg-blue-600":"bg-gray-200 dark:bg-gray-700"}`,role:"switch","aria-checked":n,"aria-label":"Toggle auto scroll",children:[e.jsx("span",{className:"sr-only",children:"Toggle auto scroll"}),e.jsx("span",{className:`${n?"translate-x-7":"translate-x-1"} inline-block h-6 w-6 transform rounded-full bg-white shadow-lg transition-transform duration-200`})]})]})})]}),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.jsxs("div",{className:"font-medium text-foreground flex items-center gap-2",children:[e.jsx(fo,{className:"h-4 w-4 text-muted-foreground"}),"使用 Ctrl+Enter 发送"]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"启用后,按 Ctrl+Enter 发送消息而不是 Enter。这对于输入法用户很有用,可以避免误发送。"})]}),e.jsxs("button",{onClick:()=>d&&d(!i),className:`relative inline-flex h-8 w-14 items-center rounded-full transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900 ${i?"bg-blue-600":"bg-gray-200 dark:bg-gray-700"}`,role:"switch","aria-checked":i,"aria-label":"Toggle ctrl enter",children:[e.jsx("span",{className:"sr-only",children:"Toggle ctrl enter"}),e.jsx("span",{className:`${i?"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:"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:E,onChange:_=>O(_.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(lt==="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":lt==="dark","aria-label":"Toggle editor theme",children:[e.jsx("span",{className:"sr-only",children:"Toggle editor theme"}),e.jsx("span",{className:`${lt==="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:lt==="dark"?e.jsx(Us,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Ws,{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:()=>cs(!Bt),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":Bt,"aria-label":"Toggle word wrap",children:[e.jsx("span",{className:"sr-only",children:"Toggle word wrap"}),e.jsx("span",{className:`${Bt?"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:()=>Cs(!yt),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":yt,"aria-label":"Toggle minimap",children:[e.jsx("span",{className:"sr-only",children:"Toggle minimap"}),e.jsx("span",{className:`${yt?"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:()=>Et(!Ht),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":Ht,"aria-label":"Toggle line numbers",children:[e.jsx("span",{className:"sr-only",children:"Toggle line numbers"}),e.jsx("span",{className:`${Ht?"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:ds,onChange:_=>ms(_.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"})]})]})})]})]})}),$e==="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:[y("tab_permissions")&&e.jsx("button",{onClick:()=>Ye("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 ${Ae==="permissions"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"权限"}),y("tab_mcp")&&e.jsx("button",{onClick:()=>Ye("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 ${Ae==="mcp"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"MCP 服务器"}),y("tab_skills")&&e.jsx("button",{onClick:()=>Ye("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 ${Ae==="skills"?"border-amber-600 text-amber-600 dark:text-amber-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"技能"}),y("tab_models")&&e.jsx("button",{onClick:()=>Ye("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 ${Ae==="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:[Ae==="permissions"&&e.jsx(Rl,{agent:"claude",skipPermissions:v,setSkipPermissions:H,allowedTools:I,setAllowedTools:p,disallowedTools:b,setDisallowedTools:m,newAllowedTool:j,setNewAllowedTool:R,newDisallowedTool:G,setNewDisallowedTool:U}),Ae==="mcp"&&e.jsx(Al,{agent:"claude",servers:se,onAdd:()=>Kt(),onEdit:_=>Kt(_),onDelete:(_,Z,xe)=>xs(_,Z,xe),onTest:(_,Z)=>It(_,Z),onDiscoverTools:(_,Z)=>ft(_,Z),testResults:ve,serverTools:Le,toolsLoading:ke,onDiscoverRepo:()=>we(!0)}),Ae==="skills"&&e.jsx(Fl,{projects:a}),Ae==="models"&&e.jsx(_l,{ref:V,onStatusChange:ee})]})]})}),$e==="shared_projects"&&e.jsx(Ul,{projects:a}),$e==="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:g?.username?.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:g?.username}),e.jsx("div",{className:"text-sm text-muted-foreground",children:g?.role==="super_admin"?"超级管理员":g?.role==="admin"?"管理员":"用户"})]})]})}),ss&&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(kr,{className:"w-5 h-5 text-blue-600"}),e.jsx("div",{className:"font-medium text-foreground",children:"修改密码"})]}),e.jsxs("form",{onSubmit:Jt,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:A,onChange:_=>te(_.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:tt})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"newPassword",className:"block text-sm font-medium text-foreground mb-1",children:"新密码"}),e.jsx("input",{type:"password",id:"newPassword",value:K,onChange:_=>oe(_.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:tt})]}),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:ce,onChange:_=>Re(_.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:tt})]}),ae&&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:ae})}),Ee&&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:Ee})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(B,{type:"submit",disabled:tt,className:"bg-blue-600 hover:bg-blue-700",children:tt?"修改中...":"修改密码"})})]})]}),y("feishu_binding")&&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:"飞书账号绑定"})]}),ot?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:ot.feishuOpenId}),ot.createdAt&&e.jsxs("span",{className:"ml-2 text-xs text-green-600/70 dark:text-green-500/70",children:["· ",new Date(ot.createdAt).toLocaleDateString("zh-CN")]})]})]}):ot===!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 小时。"]}),D?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 ",D]}),e.jsx("button",{onClick:us,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:nt?e.jsx(ws,{className:"w-4 h-4 text-green-500"}):e.jsx(Ja,{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:rs,disabled:M,className:"flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 hover:underline disabled:opacity-50",children:[e.jsx(ct,{className:"w-3 h-3"}),"重新生成"]})]})]}):e.jsxs("div",{className:"space-y-2",children:[W&&e.jsx("p",{className:"text-sm text-red-500",children:W}),e.jsxs(B,{onClick:rs,disabled:M,variant:"outline",className:"gap-2",children:[M?e.jsx(ct,{className:"w-4 h-4 animate-spin"}):e.jsx(kr,{className:"w-4 h-4"}),M?"生成中...":"生成绑定 Token"]})]})]}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"退出登录"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"结束当前会话"})]}),e.jsxs(B,{variant:"outline",className:"gap-2 text-red-600 dark:text-red-400 border-red-200 dark:border-red-800 hover:bg-red-50 dark:hover:bg-red-900/20",onClick:async()=>{await L("确定要退出登录吗?",{title:"退出登录",variant:"warning",confirmText:"退出"})&&(r(),u("/app"),h())},children:[e.jsx(bo,{className:"w-4 h-4"}),"退出"]})]})})]})}),J&&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:me?"编辑 MCP 服务器":"添加 MCP 服务器"}),e.jsx(B,{variant:"ghost",size:"sm",onClick:xt,children:e.jsx(Ge,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:ps,className:"p-4 space-y-4",children:[!me&&e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>Se(_=>({..._,importMode:"form"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${ie.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:()=>Se(_=>({..._,importMode:"json"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${ie.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 导入"})]}),ie.importMode==="form"&&me&&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:[ie.scope==="user"?e.jsx(Fs,{className:"w-4 h-4"}):e.jsx(Ns,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:ie.scope==="user"?"用户(全局)":"项目(本地)"}),ie.scope==="local"&&ie.projectPath&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",He(ie.projectPath)]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"编辑现有服务器时无法更改作用域"})]}),ie.importMode==="form"&&!me&&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:()=>Se(_=>({..._,scope:"user",projectPath:""})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${ie.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(Fs,{className:"w-4 h-4"}),e.jsx("span",{children:"用户(全局)"})]})}),e.jsx("button",{type:"button",onClick:()=>Se(_=>({..._,scope:"local"})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${ie.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(Ns,{className:"w-4 h-4"}),e.jsx("span",{children:"项目(本地)"})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:ie.scope==="user"?"用户作用域:在您机器上的所有项目中可用":"本地作用域:仅在选定的项目中可用"})]}),ie.scope==="local"&&!me&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"项目 *"}),e.jsxs("select",{value:ie.projectPath,onChange:_=>Se(Z=>({...Z,projectPath:_.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:ie.scope==="local",children:[e.jsx("option",{value:"",children:"选择项目..."}),a.map(_=>e.jsx("option",{value:_.path||_.fullPath,children:_.displayName||_.name},_.name))]}),ie.projectPath&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Path: ",He(ie.projectPath)]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:ie.importMode==="json"?"md:col-span-2":"",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称 *"}),e.jsx(it,{value:ie.name,onChange:_=>{Se(Z=>({...Z,name:_.target.value}))},placeholder:"my-server",required:!0})]}),ie.importMode==="form"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"传输类型 *"}),e.jsxs("select",{value:ie.type,onChange:_=>{Se(Z=>({...Z,type:_.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"})]})]})]}),me&&ie.raw&&ie.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 ",me.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(ie.raw,null,2)})]}),ie.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:ie.jsonInput,onChange:_=>{Se(Z=>({...Z,jsonInput:_.target.value}));try{if(_.target.value.trim()){const Z=JSON.parse(_.target.value);Z.type?Z.type==="stdio"&&!Z.command?ze("stdio 类型需要 command 字段"):(Z.type==="http"||Z.type==="sse")&&!Z.url?ze(`${Z.type} 类型需要 url 字段`):ze(""):ze("缺少必填字段:type")}}catch{_.target.value.trim()?ze("无效的 JSON 格式"):ze("")}},className:`w-full px-3 py-2 border ${_e?"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:`{
161
+ "type": "stdio",
162
+ "command": "/path/to/server",
163
+ "args": ["--api-key", "abc123"],
164
+ "env": {
165
+ "CACHE_DIR": "/tmp"
166
+ }
167
+ }`,required:!0}),_e&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:_e}),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"}']})]})}),ie.importMode==="form"&&ie.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(it,{value:ie.config.command,onChange:_=>Lt("command",_.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(ie.config.args)?ie.config.args.join(`
168
+ `):"",onChange:_=>Lt("args",_.target.value.split(`
169
+ `).filter(Z=>Z.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
170
+ abc123`})]})]}),ie.importMode==="form"&&(ie.type==="sse"||ie.type==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"URL *"}),e.jsx(it,{value:ie.config.url,onChange:_=>Lt("url",_.target.value),placeholder:"https://api.example.com/mcp",type:"url",required:!0})]}),ie.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(ie.config.env||{}).map(([_,Z])=>`${_}=${Z}`).join(`
171
+ `),onChange:_=>{const Z={};_.target.value.split(`
172
+ `).forEach(xe=>{const[Ce,...gt]=xe.split("=");Ce&&Ce.trim()&&(Z[Ce.trim()]=gt.join("=").trim())}),Lt("env",Z)},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
173
+ DEBUG=true`})]}),ie.importMode==="form"&&(ie.type==="sse"||ie.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(ie.config.headers||{}).map(([_,Z])=>`${_}=${Z}`).join(`
174
+ `),onChange:_=>{const Z={};_.target.value.split(`
175
+ `).forEach(xe=>{const[Ce,...gt]=xe.split("=");Ce&&Ce.trim()&&(Z[Ce.trim()]=gt.join("=").trim())}),Lt("headers",Z)},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
176
+ X-API-Key=your-key`})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(B,{type:"button",variant:"outline",onClick:xt,children:"取消"}),e.jsx(B,{type:"submit",disabled:We,className:"bg-purple-600 hover:bg-purple-700 disabled:opacity-50",children:We?"保存中...":me?"更新服务器":"添加服务器"})]})]})]})})]})]}),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:$e==="agents"&&Ae==="models"?$.saving?e.jsx("span",{className:"text-sm text-muted-foreground",children:"保存中..."}):null:e.jsxs(e.Fragment,{children:[q==="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"})}),"设置保存成功!"]}),q==="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:[$e==="agents"&&Ae==="models"&&$.hasChanges&&e.jsx(B,{variant:"outline",onClick:()=>V.current?.reset(),disabled:$.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"重置"}),e.jsx(B,{variant:"outline",onClick:r,disabled:N||$.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"取消"}),e.jsx(B,{onClick:$e==="agents"&&Ae==="models"?()=>V.current?.save():ht,disabled:$e==="agents"&&Ae==="models"?$.saving||!$.hasChanges:N,className:"flex-1 sm:flex-none h-10 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 touch-manipulation",children:N||$.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"}),"保存中..."]}):"保存设置"})]})]})]})}),De&&e.jsx(Hl,{onClose:()=>we(!1),onInstalled:()=>vt(),onOpenRepoManager:()=>{we(!1),Ue(!0)},projects:a}),Me&&e.jsx(Wl,{onClose:()=>Ue(!1),onChanged:()=>{}})]}):null}const Jl=[{key:"claude_shell",label:"Claude Code Shell",desc:"访问 Claude Code 终端"},{key:"codex_shell",label:"Codex Shell",desc:"访问 Codex 终端"},{key:"gemini_shell",label:"Gemini CLI Shell",desc:"访问 Gemini CLI 终端"},{key:"submit_agent",label:"提交 Agent",desc:"在 Agent 商店中提交新 Agent"},{key:"tab_models",label:"模型设置",desc:"设置 > Agent > 模型 tab"},{key:"tab_skills",label:"技能设置",desc:"设置 > Agent > 技能 tab"},{key:"tab_mcp",label:"MCP 服务器设置",desc:"设置 > Agent > MCP 服务器 tab"},{key:"tab_permissions",label:"权限设置",desc:"设置 > Agent > 权限 tab"},{key:"feishu_binding",label:"绑定飞书账号",desc:"设置 > 账户 > 飞书绑定"},{key:"create_project",label:"新建项目",desc:"侧边栏 > 新建项目按钮"}];function Kl({user:t,onClose:r,onSaved:a}){const[o,n]=s.useState({}),[l,i]=s.useState(!0),[d,u]=s.useState(!1),[f,x]=s.useState(""),[g,h]=s.useState(!1);s.useEffect(()=>{y()},[t.id]);const y=async()=>{i(!0);try{const b=await(await he.admin.getUserPermissions(t.id)).json();if(b.permissions)n(b.permissions),h(!0);else{const j=await(await he.admin.getDefaultPermissions()).json();n(j.permissions||{}),h(!1)}}catch(p){console.error("Error fetching permissions:",p),x("加载权限失败")}finally{i(!1)}},k=p=>{n(b=>({...b,[p]:!b[p]})),h(!0)},L=async p=>{p.preventDefault(),x(""),u(!0);try{const b=await he.admin.updateUserPermissions(t.id,o),m=await b.json();b.ok?(a?.(),r()):x(m.error||"保存失败")}catch(b){console.error("Error saving permissions:",b),x("网络错误,请稍后再试")}finally{u(!1)}},I=async()=>{x(""),u(!0);try{if((await he.admin.updateUserPermissions(t.id,null)).ok){const m=await(await he.admin.getDefaultPermissions()).json();n(m.permissions||{}),h(!1)}}catch(p){console.error("Error resetting permissions:",p),x("重置失败")}finally{u(!1)}};return 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("div",{children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["功能权限 - ",t.username||t.email]}),g?e.jsx("p",{className:"text-xs text-blue-500 mt-0.5",children:"已设置个性化权限"}):e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"使用系统默认权限"})]}),e.jsx("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),l?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):e.jsxs("form",{onSubmit:L,className:"space-y-3",children:[e.jsx("div",{className:"space-y-1 max-h-[400px] overflow-y-auto",children:Jl.map(p=>e.jsxs("label",{className:"flex items-center justify-between p-2.5 rounded-md hover:bg-accent/50 cursor-pointer transition-colors",children:[e.jsxs("div",{className:"min-w-0 mr-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:p.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:p.desc})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":o[p.key]!==!1,onClick:()=>k(p.key),className:`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${o[p.key]!==!1?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:e.jsx("span",{className:`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${o[p.key]!==!1?"translate-x-4":"translate-x-0"}`})})]},p.key))}),f&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:f})}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(B,{type:"button",variant:"ghost",size:"sm",onClick:I,disabled:d||!g,className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(Ka,{className:"w-3.5 h-3.5"}),"重置为默认"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:r,disabled:d,children:"取消"}),e.jsx(B,{type:"submit",disabled:d,children:d?"保存中...":"保存"})]})]})]})]})})}function Gl({user:t,onClose:r,onSaved:a}){const[o,n]=s.useState(new Set),[l,i]=s.useState([]),[d,u]=s.useState(""),[f,x]=s.useState(!0),[g,h]=s.useState(!1),[y,k]=s.useState(""),[L,I]=s.useState(!1);s.useEffect(()=>{p()},[t.id]);const p=async()=>{x(!0);try{const[v,H]=await Promise.all([Y("/api/agents"),he.admin.getUserVisibleAgents(t.id)]),N=await v.json(),z=await H.json();i(N.agents||[]),z.agents&&Array.isArray(z.agents)?(n(new Set(z.agents)),I(!0)):(n(new Set),I(!1))}catch(v){console.error("Error fetching agent visibility data:",v),k("加载数据失败")}finally{x(!1)}},b=s.useMemo(()=>{if(!d.trim())return l;const v=d.toLowerCase();return l.filter(H=>(H.display_name||H.name||"").toLowerCase().includes(v)||(H.description||"").toLowerCase().includes(v)||(H.dirName||"").toLowerCase().includes(v))},[l,d]),m=b.length>0&&b.every(v=>o.has(v.dirName||v.name)),j=v=>{n(H=>{const N=new Set(H);return N.has(v)?N.delete(v):N.add(v),N}),I(!0)},R=()=>{n(v=>{const H=new Set(v);return m?b.forEach(N=>H.delete(N.dirName||N.name)):b.forEach(N=>H.add(N.dirName||N.name)),H}),I(!0)},G=async v=>{v.preventDefault(),k(""),h(!0);try{const H=[...o],N=await he.admin.updateUserVisibleAgents(t.id,H),z=await N.json();N.ok?(a?.(),r()):k(z.error||"保存失败")}catch(H){console.error("Error saving agent visibility:",H),k("网络错误,请稍后再试")}finally{h(!1)}},U=async()=>{k(""),h(!0);try{(await he.admin.updateUserVisibleAgents(t.id,null)).ok&&(n(new Set),I(!1))}catch(v){console.error("Error resetting agent visibility:",v),k("重置失败")}finally{h(!1)}};return 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("div",{children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["共享项目可见性 - ",t.username||t.email]}),L?e.jsxs("p",{className:"text-xs text-blue-500 mt-0.5",children:["已设置个性化配置(已选 ",o.size," 个)"]}):e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"使用默认配置(不可见任何 Agent)"})]}),e.jsx("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),f?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):l.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(yo,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"仓库中暂无 Agent"})]}):e.jsxs("form",{onSubmit:G,className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(St,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx("input",{type:"text",value:d,onChange:v=>u(v.target.value),placeholder:"搜索 Agent...",className:"w-full pl-8 pr-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500"})]}),e.jsxs("label",{className:"flex items-center gap-2 px-2.5 py-1.5 text-sm text-muted-foreground cursor-pointer hover:text-foreground",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:R,className:"w-3.5 h-3.5 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500"}),d?`全选搜索结果(${b.length})`:`全选(${l.length})`]}),e.jsx("div",{className:"space-y-0.5 max-h-[400px] overflow-y-auto border border-border rounded-md",children:b.length===0?e.jsx("div",{className:"text-center py-6 text-muted-foreground text-sm",children:"未找到匹配的 Agent"}):b.map(v=>{const H=v.dirName||v.name,N=o.has(H);return e.jsxs("label",{className:`flex items-start gap-2.5 px-3 py-2 cursor-pointer transition-colors hover:bg-accent/50 ${N?"bg-blue-50/50 dark:bg-blue-900/10":""}`,children:[e.jsx("input",{type:"checkbox",checked:N,onChange:()=>j(H),className:"w-3.5 h-3.5 mt-0.5 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:v.display_name||v.name}),v.version&&e.jsxs("span",{className:"text-xs px-1.5 py-0.5 bg-gray-100 dark:bg-gray-800 text-muted-foreground rounded flex-shrink-0",children:["v",v.version]})]}),v.description&&e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:v.description})]})]},H)})}),e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:["已选 ",o.size," / 共 ",l.length," 个 Agent"]}),y&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:y})}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(B,{type:"button",variant:"ghost",size:"sm",onClick:U,disabled:g||!L,className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(Ka,{className:"w-3.5 h-3.5"}),"重置为默认"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:r,disabled:g,children:"取消"}),e.jsx(B,{type:"submit",disabled:g,children:g?"保存中...":"保存"})]})]})]})]})})}function Vl({isSuperAdmin:t,onNavigateToUsage:r,onViewUser:a}){const{user:o}=Ct(),{showConfirm:n}=dt(),[l,i]=s.useState([]),[d,u]=s.useState({}),[f,x]=s.useState(!0),[g,h]=s.useState(null),[y,k]=s.useState(!1),[L,I]=s.useState(""),[p,b]=s.useState(""),[m,j]=s.useState(""),[R,G]=s.useState(!1),[U,v]=s.useState(null),[H,N]=s.useState({total_limit_usd:"",daily_limit_usd:""}),[z,q]=s.useState(""),[S,E]=s.useState(!1),[O,se]=s.useState(null),[re,J]=s.useState(""),[le,me]=s.useState(""),[ge,De]=s.useState(""),[we,Me]=s.useState(!1),[Ue,ie]=s.useState(null),[Se,We]=s.useState(""),[Be,ve]=s.useState(""),[Ie,Le]=s.useState(!1),[qe,ke]=s.useState(null),[Je,$e]=s.useState(null),[Pe,_e]=s.useState(null),ze=async()=>{try{const M=await Y("/api/admin/users");if(M.ok){const ne=await M.json();i(ne.users)}}catch(M){console.error("Error fetching users:",M)}finally{x(!1)}},Ae=async()=>{try{const M=await Y("/api/admin/usage/summary");if(M.ok){const ne=await M.json(),W={};for(const Ne of ne.users)W[Ne.user_uuid]={total_cost:Ne.total_cost||0,total_requests:Ne.total_requests||0,last_active:Ne.last_active};u(W)}}catch(M){console.error("Error fetching usage data:",M)}};s.useEffect(()=>{ze(),Ae()},[]);const Ye=M=>!M||M===0?"$0.00":M<.01?`$${M.toFixed(4)}`:`$${M.toFixed(2)}`,Oe=M=>M.role==="super_admin"?!1:t||M.id===o?.id?!0:M.role==="user",V=M=>M.id===o?.id?!1:t?M.role!=="super_admin":!["admin","super_admin"].includes(M.role),$=async(M,ne)=>{const W=ne==="active"?"disabled":"active";h(M);try{(await Y(`/api/admin/users/${M}`,{method:"PATCH",body:JSON.stringify({status:W})})).ok&&i(l.map(nt=>nt.id===M?{...nt,status:W}:nt))}catch(Ne){console.error("Error updating user status:",Ne)}finally{h(null)}},w=async(M,ne)=>{if(await n(`确定要删除用户 "${ne}"?这将删除其所有数据。`,{title:"删除用户",variant:"danger",confirmText:"确认删除"})){h(M);try{(await Y(`/api/admin/users/${M}`,{method:"DELETE"})).ok&&i(l.filter(Ne=>Ne.id!==M))}catch(W){console.error("Error deleting user:",W)}finally{h(null)}}},ee=async M=>{if(M.preventDefault(),j(""),!L||!p){j("用户名和密码不能为空");return}if(L.length<3){j("用户名至少3个字符");return}if(p.length<6){j("密码至少6个字符");return}G(!0);try{const ne=await he.admin.createUser(L,p),W=await ne.json();ne.ok?(await ze(),k(!1),I(""),b("")):j(W.error||"创建用户失败")}catch(ne){console.error("Error creating user:",ne),j("网络错误,请稍后再试")}finally{G(!1)}},A=()=>{k(!1),I(""),b(""),j("")},te=M=>{v(M),N({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):""}),q("")},K=()=>{v(null),N({total_limit_usd:"",daily_limit_usd:""}),q("")},oe=async M=>{M.preventDefault(),q("");const ne=H.total_limit_usd.trim()===""?null:parseFloat(H.total_limit_usd),W=H.daily_limit_usd.trim()===""?null:parseFloat(H.daily_limit_usd);if(ne!==null&&(isNaN(ne)||ne<0)){q("总额度限制必须是正数或留空");return}if(W!==null&&(isNaN(W)||W<0)){q("每日额度限制必须是正数或留空");return}E(!0);try{const Ne=await he.admin.updateUserLimits(U.id,{total_limit_usd:ne,daily_limit_usd:W}),nt=await Ne.json();Ne.ok?(i(l.map(Xe=>Xe.id===U.id?{...Xe,total_limit_usd:ne,daily_limit_usd:W}:Xe)),K()):q(nt.error||"更新限制失败")}catch(Ne){console.error("Error updating limits:",Ne),q("网络错误,请稍后再试")}finally{E(!1)}},ce=M=>M==null?"无限制":`$${M.toFixed(2)}`,Re=M=>{se(M),J(""),me(""),De("")},ae=()=>{se(null),J(""),me(""),De("")},Te=async M=>{if(M.preventDefault(),De(""),!re){De("请输入新密码");return}if(re.length<6){De("密码至少需要6个字符");return}if(re!==le){De("两次输入的密码不一致");return}Me(!0);try{const ne=await he.admin.resetUserPassword(O.id,re),W=await ne.json();ne.ok?ae():De(W.error||"重置密码失败")}catch(ne){console.error("Error resetting password:",ne),De("网络错误,请稍后再试")}finally{Me(!1)}},Ee=M=>{ie(M),We(M.role==="admin"?"admin":"user"),ve("")},pe=()=>{ie(null),We(""),ve("")},tt=async M=>{M.preventDefault(),ve(""),Le(!0);try{const ne=await he.admin.updateUserRole(Ue.id,Se),W=await ne.json();ne.ok?(i(l.map(Ne=>Ne.id===Ue.id?{...Ne,role:Se}:Ne)),pe()):ve(W.error||"更新角色失败")}catch(ne){console.error("Error updating role:",ne),ve("网络错误,请稍后再试")}finally{Le(!1)}},Fe=M=>M==="super_admin"?e.jsx(Eo,{className:"w-4 h-4 text-amber-500 flex-shrink-0"}):M==="admin"?e.jsx(Wt,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(Nr,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),D=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:"用户"}),ue=M=>{const ne=()=>{_e(M),setTimeout(()=>_e(null),2e3)};if(navigator.clipboard&&window.isSecureContext)navigator.clipboard.writeText(M).then(ne);else{const W=document.createElement("textarea");W.value=M,W.style.position="fixed",W.style.opacity="0",document.body.appendChild(W),W.select(),document.execCommand("copy"),document.body.removeChild(W),ne()}};return f?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"正在加载用户..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"用户管理"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{variant:"default",size:"sm",onClick:()=>k(!0),className:"flex items-center gap-2",children:[e.jsx(vo,{className:"w-4 h-4"}),"创建用户"]}),r&&e.jsxs(B,{variant:"outline",size:"sm",onClick:r,className:"flex items-center gap-2",children:[e.jsx(jo,{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-[580px] table-fixed",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 w-44",children:"用户"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-20",children:"角色"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-10",children:"状"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-36",children:"费用 / 额度"}),e.jsx("th",{className:"px-3 py-2 text-left 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",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 w-44",children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[Fe(M.role),e.jsx("span",{className:"font-medium text-foreground text-sm truncate block min-w-0",title:M.username||M.email,children:M.username||(M.email?.includes("@")?M.email.split("@")[0]:M.email)})]})}),e.jsx("td",{className:"px-3 py-2 text-center",children:D(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.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsx("span",{className:"font-mono text-xs text-foreground whitespace-nowrap",children:Ye(d[M.uuid]?.total_cost)}),Oe(M)?e.jsx("button",{onClick:()=>te(M),className:"text-[11px] text-blue-600 dark:text-blue-400 hover:underline font-mono whitespace-nowrap leading-tight",title:"点击编辑额度限制",children:M.total_limit_usd!==null||M.daily_limit_usd!==null?e.jsxs("span",{children:["总:",ce(M.total_limit_usd)," 日:",ce(M.daily_limit_usd)]}):e.jsxs("span",{className:"flex items-center gap-0.5 justify-end text-muted-foreground",children:[e.jsx(Or,{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-0.5",children:[e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>ue(M.uuid),title:`复制用户 UID: ${M.uuid}`,children:Pe===M.uuid?e.jsx(ws,{className:"w-4 h-4 text-green-500"}):e.jsx(Ja,{className:"w-4 h-4 text-gray-400"})}),a&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>a(M.uuid,M.username||M.email),title:"查看使用详情",children:e.jsx(wo,{className:"w-4 h-4 text-indigo-500"})}),t&&M.role!=="super_admin"&&M.id!==o?.id&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Ee(M),title:"修改角色",children:e.jsx(ko,{className:"w-4 h-4 text-purple-500"})}),M.role==="user"&&V(M)&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>ke(M),title:"功能权限",children:e.jsx(No,{className:"w-4 h-4 text-green-500"})}),M.role==="user"&&V(M)&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>$e(M),title:"共享项目可见性",children:e.jsx(Ua,{className:"w-4 h-4 text-cyan-500"})}),V(M)&&e.jsxs(e.Fragment,{children:[M.username&&e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Re(M),disabled:g===M.id,title:"重置密码",children:e.jsx(kr,{className:"w-4 h-4 text-blue-500"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>$(M.id,M.status),disabled:g===M.id,title:M.status==="active"?"禁用用户":"启用用户",children:M.status==="active"?e.jsx(So,{className:"w-4 h-4 text-orange-500"}):e.jsx(Co,{className:"w-4 h-4 text-green-500"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>w(M.id,M.username||M.email),disabled:g===M.id,title:"删除用户",children:g===M.id?e.jsx(Dt,{className:"w-4 h-4 text-red-500 animate-spin"}):e.jsx(bt,{className:"w-4 h-4 text-red-500"})})]})]})})]},M.id))})]})}),y&&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:A,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:ee,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:L,onChange:M=>I(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:R})]}),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:p,onChange:M=>b(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:R})]}),m&&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:m})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:A,disabled:R,children:"取消"}),e.jsx(B,{type:"submit",disabled:R,children:R?"创建中...":"创建"})]})]})]})}),U&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["设置额度限制 - ",U.username||U.email]}),e.jsx("button",{onClick:K,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:oe,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:H.total_limit_usd,onChange:M=>N(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:S}),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:H.daily_limit_usd,onChange:M=>N(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:S}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户每日使用金额达到此限制后,需等待次日重置"})]}),d[U.uuid]&&e.jsx("div",{className:"p-3 bg-gray-100 dark:bg-gray-800 rounded-md",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["当前已使用:",e.jsx("span",{className:"font-mono text-foreground",children:Ye(d[U.uuid]?.total_cost)})]})}),z&&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:z})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:K,disabled:S,children:"取消"}),e.jsx(B,{type:"submit",disabled:S,children:S?"保存中...":"保存"})]})]})]})}),O&&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:["重置密码 - ",O.username]}),e.jsx("button",{onClick:ae,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:Te,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:re,onChange:M=>J(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:we})]}),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:le,onChange:M=>me(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:we})]}),ge&&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:ge})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:ae,disabled:we,children:"取消"}),e.jsx(B,{type:"submit",disabled:we,children:we?"重置中...":"重置密码"})]})]})]})}),Ue&&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:["修改角色 - ",Ue.username||Ue.email]}),e.jsx("button",{onClick:pe,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:tt,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:Se==="admin",onChange:M=>We(M.target.value),className:"text-blue-600",disabled:Ie}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Wt,{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:Se==="user",onChange:M=>We(M.target.value),className:"text-blue-600",disabled:Ie}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Nr,{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:"受额度限制,无管理权限"})]})]})]}),Be&&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:Be})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(B,{type:"button",variant:"outline",onClick:pe,disabled:Ie,children:"取消"}),e.jsx(B,{type:"submit",disabled:Ie,children:Ie?"保存中...":"保存"})]})]})]})}),qe&&e.jsx(Kl,{user:qe,onClose:()=>ke(null),onSaved:()=>ze()}),Je&&e.jsx(Gl,{user:Je,onClose:()=>$e(null),onSaved:()=>ze()})]})}function Yl(){const[t,r]=s.useState(""),[a,o]=s.useState(""),[n,l]=s.useState(!0),[i,d]=s.useState(!1),[u,f]=s.useState(null);s.useEffect(()=>{x()},[]);const x=async()=>{try{const h=await he.admin.getDefaultLimits();if(h.ok){const y=await h.json();r(y.default_total_limit_usd!==null?String(y.default_total_limit_usd):""),o(y.default_daily_limit_usd!==null?String(y.default_daily_limit_usd):"")}}catch(h){console.error("Error fetching default limits:",h)}finally{l(!1)}},g=async h=>{h.preventDefault(),d(!0),f(null);const y=t.trim()===""?null:parseFloat(t),k=a.trim()===""?null:parseFloat(a);if(y!==null&&(isNaN(y)||y<0)){f("error"),d(!1);return}if(k!==null&&(isNaN(k)||k<0)){f("error"),d(!1);return}try{(await he.admin.updateDefaultLimits({default_total_limit_usd:y,default_daily_limit_usd:k})).ok?(f("success"),setTimeout(()=>f(null),2e3)):f("error")}catch(L){console.error("Error updating default limits:",L),f("error")}finally{d(!1)}};return n?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.jsx("form",{onSubmit:g,className:"space-y-3",children:e.jsxs("div",{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:h=>r(h.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"留空表示不限制",disabled:i})]}),e.jsxs("div",{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:a,onChange:h=>o(h.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"留空表示不限制",disabled:i})]}),e.jsxs(B,{type:"submit",variant:"default",size:"sm",disabled:i,className:"flex items-center gap-2",children:[e.jsx($r,{className:"w-4 h-4"}),i?"保存中...":"保存"]}),u==="success"&&e.jsx("span",{className:"text-sm text-green-600",children:"已保存"}),u==="error"&&e.jsx("span",{className:"text-sm text-red-600",children:"请输入有效的正数"})]})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"此设置仅影响新注册的用户,不会修改已有用户的额度。"})]})}const Ql=[{key:"claude_shell",label:"Claude Code Shell"},{key:"codex_shell",label:"Codex Shell"},{key:"gemini_shell",label:"Gemini CLI Shell"},{key:"submit_agent",label:"提交 Agent"},{key:"tab_models",label:"模型设置"},{key:"tab_skills",label:"技能设置"},{key:"tab_mcp",label:"MCP 服务器设置"},{key:"tab_permissions",label:"权限设置"},{key:"feishu_binding",label:"绑定飞书账号"},{key:"create_project",label:"新建项目"}];function Xl(){const[t,r]=s.useState({}),[a,o]=s.useState(!0),[n,l]=s.useState(!1),[i,d]=s.useState(null);s.useEffect(()=>{u()},[]);const u=async()=>{try{const g=await he.admin.getDefaultPermissions();if(g.ok){const h=await g.json();r(h.permissions||{})}}catch(g){console.error("Error fetching default permissions:",g)}finally{o(!1)}},f=g=>{r(h=>({...h,[g]:!h[g]}))},x=async g=>{g.preventDefault(),l(!0),d(null);try{(await he.admin.updateDefaultPermissions(t)).ok?(d("success"),setTimeout(()=>d(null),2e3)):d("error")}catch(h){console.error("Error updating default permissions:",h),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:x,className:"space-y-3",children:[e.jsx("div",{className:"space-y-1",children:Ql.map(g=>e.jsxs("label",{className:"flex items-center justify-between p-2.5 rounded-md hover:bg-accent/50 cursor-pointer transition-colors",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:g.label}),e.jsx("button",{type:"button",role:"switch","aria-checked":t[g.key]!==!1,onClick:()=>f(g.key),className:`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${t[g.key]!==!1?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:e.jsx("span",{className:`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${t[g.key]!==!1?"translate-x-4":"translate-x-0"}`})})]},g.key))}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsxs(B,{type:"submit",variant:"default",size:"sm",disabled:n,className:"flex items-center gap-2",children:[e.jsx($r,{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 Zl(){const{showConfirm:t}=dt(),[r,a]=s.useState([]),[o,n]=s.useState(!0),[l,i]=s.useState(null),[d,u]=s.useState(!1),[f,x]=s.useState(""),[g,h]=s.useState(""),[y,k]=s.useState(!1),L=async()=>{try{const m=await he.admin.getEmailDomains();if(m.ok){const j=await m.json();a(j.domains)}}catch(m){console.error("Error fetching email domains:",m)}finally{n(!1)}};s.useEffect(()=>{L()},[]);const I=async m=>{if(m.preventDefault(),h(""),!f){h("域名不能为空");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(f)){h("域名格式无效,例如: example.com");return}k(!0);try{const R=await he.admin.addEmailDomain(f.toLowerCase()),G=await R.json();R.ok?(await L(),u(!1),x("")):h(G.error||"添加域名失败")}catch(R){console.error("Error adding domain:",R),h("网络错误,请稍后再试")}finally{k(!1)}},p=async(m,j)=>{if(await t(`确定要删除域名 "${j}"?删除后该域名的邮箱将无法注册。`,{title:"删除域名",variant:"danger",confirmText:"确认删除"})){i(m);try{(await he.admin.removeEmailDomain(m)).ok&&a(r.filter(G=>G.id!==m))}catch(R){console.error("Error removing domain:",R)}finally{i(null)}}},b=()=>{u(!1),x(""),h("")};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:r.length===0?"未设置白名单,所有邮箱域名均可注册":"只有白名单内的域名邮箱可以注册"})]}),e.jsxs(B,{variant:"default",size:"sm",onClick:()=>u(!0),className:"flex items-center gap-2",children:[e.jsx(Ft,{className:"w-4 h-4"}),"添加域名"]})]}),r.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:r.map(m=>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(Bs,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"font-medium text-foreground",children:m.domain})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-muted-foreground",children:new Date(m.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>p(m.id,m.domain),disabled:l===m.id,title:"删除域名",children:e.jsx(bt,{className:"w-4 h-4 text-red-500"})})})})]},m.id))})]})}):e.jsxs("div",{className:"border border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-8 text-center",children:[e.jsx(Bs,{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:b,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ge,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:I,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:f,onChange:m=>x(m.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:y}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入域名后,该域名下的所有邮箱(如 user@example.com)都可以注册"})]}),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(B,{type:"button",variant:"outline",onClick:b,disabled:y,children:"取消"}),e.jsx(B,{type:"submit",disabled:y,children:y?"添加中...":"添加"})]})]})]})})]})}const $s={pending:{label:"待审核",className:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",icon:Os},approved:{label:"已通过",className:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",icon:qa},rejected:{label:"已拒绝",className:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",icon:Ha}};function Pa(t){return t?new Date(t).toLocaleString("zh-CN",{dateStyle:"short",timeStyle:"short"}):"-"}function ec({submissionId:t}){const[r,a]=s.useState(null),[o,n]=s.useState(!0),[l,i]=s.useState(0);if(s.useEffect(()=>{Y(`/api/agents/submissions/${t}/contents`).then(u=>u.json()).then(u=>{a(u.files||[]),i(0)}).catch(()=>a([])).finally(()=>n(!1))},[t]),o)return e.jsxs("div",{className:"flex items-center gap-1.5 py-3 text-xs text-gray-400",children:[e.jsx(ct,{className:"w-3 h-3 animate-spin"})," 加载文件内容..."]});if(!r||r.length===0)return e.jsx("p",{className:"text-xs text-gray-400 py-2",children:"无法读取文件内容"});const d=r[l];return e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"flex items-center gap-1 mb-2 flex-wrap",children:r.map((u,f)=>e.jsxs("button",{onClick:()=>i(f),className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded border transition-colors ${f===l?"bg-blue-50 dark:bg-blue-900/20 border-blue-300 dark:border-blue-700 text-blue-700 dark:text-blue-300":"border-gray-200 dark:border-gray-700 text-gray-500 dark:text-gray-400 hover:border-gray-300"}`,children:[e.jsx(is,{className:"w-3 h-3"}),u.name]},u.name))}),e.jsx("pre",{className:"text-[11px] leading-relaxed bg-gray-900 dark:bg-gray-950 text-gray-100 rounded-lg p-3 overflow-auto max-h-72 whitespace-pre-wrap break-words",children:d?.content||""})]})}function tc(){const{showAlert:t}=dt(),[r,a]=s.useState([]),[o,n]=s.useState(!0),[l,i]=s.useState("pending"),[d,u]=s.useState(null),[f,x]=s.useState(null),[g,h]=s.useState(""),[y,k]=s.useState(null),[L,I]=s.useState(null),[p,b]=s.useState(!1);s.useEffect(()=>{m()},[l]);const m=async()=>{try{n(!0);const v=l?`/api/agents/submissions?status=${l}`:"/api/agents/submissions",H=await Y(v);if(H.ok){const N=await H.json();a(N.submissions||[])}else t("加载提交列表失败",{variant:"error"})}catch(v){t(v.message,{variant:"error"})}finally{n(!1)}},j=v=>{I(v.id),b(!1)},R=async(v,H)=>{x(v.id);try{const N=await Y(`/api/agents/submissions/${v.id}/approve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updateAllUsers:H})}),z=await N.json();if(N.ok){let q=`已通过审核,版本 v${z.version} 已发布到仓库。`;z.updatedUsersCount>0&&(q+=`
177
+ 另已强制更新 ${z.updatedUsersCount} 个已使用用户。`),t(q,{title:"审核通过"}),I(null),m()}else t(z.error||"操作失败",{variant:"error"})}catch(N){t(N.message,{variant:"error"})}finally{x(null)}},G=v=>{k(v.id),h("")},U=async v=>{x(v.id);try{const H=await Y(`/api/agents/submissions/${v.id}/reject`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:g})});if(H.ok)t("已拒绝该提交。",{title:"审核拒绝"}),k(null),m();else{const N=await H.json();t(N.error||"操作失败",{variant:"error"})}}catch(H){t(H.message,{variant:"error"})}finally{x(null)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:["pending","approved","rejected",""].map(v=>e.jsx("button",{onClick:()=>i(v),className:`px-3 py-1 text-xs rounded-full border transition-colors ${l===v?"bg-blue-500 text-white border-blue-500":"border-gray-200 dark:border-gray-700 text-gray-600 dark:text-gray-400 hover:border-blue-300"}`,children:v===""?"全部":$s[v]?.label},v||"all"))}),e.jsxs(B,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-1.5",children:[e.jsx(ct,{className:`w-3.5 h-3.5 ${o?"animate-spin":""}`}),"刷新"]})]}),o?e.jsx("div",{className:"text-center py-8 text-gray-400 text-sm",children:"加载中..."}):r.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-400 text-sm border border-dashed border-gray-200 dark:border-gray-700 rounded-lg",children:["暂无",l?$s[l]?.label:"","提交记录"]}):e.jsx("div",{className:"space-y-2",children:r.map(v=>{const H=$s[v.status]||$s.pending,N=H.icon,z=d===v.id,q=f===v.id,S=y===v.id,E=L===v.id;return e.jsxs("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm text-gray-900 dark:text-gray-100",children:v.display_name}),e.jsx("span",{className:"text-xs text-gray-400 font-mono",children:v.agent_name}),e.jsxs(et,{className:`text-xs ${H.className} flex items-center gap-1`,children:[e.jsx(N,{className:"w-3 h-3"}),H.label]}),v.version&&e.jsxs("span",{className:"text-xs text-green-600 dark:text-green-400",children:["v",v.version]})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-0.5 text-xs text-gray-400",children:[e.jsxs("span",{children:["提交人: ",v.username||v.email||`uid-${v.user_id}`]}),e.jsxs("span",{children:["提交时间: ",Pa(v.submitted_at)]}),v.reviewed_at&&e.jsxs("span",{children:["审核时间: ",Pa(v.reviewed_at)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[v.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx(B,{size:"sm",className:"text-xs h-7 px-2.5 bg-green-600 hover:bg-green-700 text-white",onClick:()=>j(v),disabled:q,children:"通过"}),e.jsx(B,{size:"sm",variant:"outline",className:"text-xs h-7 px-2.5 text-red-600 border-red-200 hover:bg-red-50 dark:border-red-800 dark:hover:bg-red-900/20",onClick:()=>G(v),disabled:q,children:"拒绝"})]}),e.jsx("button",{onClick:()=>u(z?null:v.id),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:z?e.jsx(wr,{className:"w-4 h-4"}):e.jsx(Qt,{className:"w-4 h-4"})})]})]}),z&&e.jsxs("div",{className:"border-t border-gray-100 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3 space-y-2",children:[v.description&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 mb-1",children:"描述"}),e.jsx("p",{className:"text-xs text-gray-700 dark:text-gray-300",children:v.description})]}),v.update_notes&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-blue-500 dark:text-blue-400 mb-1",children:"更新说明"}),e.jsx("p",{className:"text-xs text-gray-700 dark:text-gray-300",children:v.update_notes})]}),v.status==="rejected"&&v.reject_reason&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-red-500 mb-1",children:"拒绝原因"}),e.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",children:v.reject_reason})]}),e.jsx(ec,{submissionId:v.id})]}),S&&e.jsxs("div",{className:"border-t border-red-100 dark:border-red-900/30 bg-red-50 dark:bg-red-900/10 p-3",children:[e.jsx("p",{className:"text-xs font-medium text-red-600 dark:text-red-400 mb-2",children:"填写拒绝原因"}),e.jsx("textarea",{value:g,onChange:O=>h(O.target.value),placeholder:"可选:填写拒绝原因告知提交者",rows:2,className:"w-full border border-red-200 dark:border-red-800 rounded px-2 py-1.5 text-xs bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none resize-none mb-2"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{size:"sm",className:"text-xs h-7 px-2.5 bg-red-600 hover:bg-red-700 text-white",onClick:()=>U(v),disabled:q,children:q?"处理中...":"确认拒绝"}),e.jsx(B,{size:"sm",variant:"outline",className:"text-xs h-7 px-2.5",onClick:()=>k(null),disabled:q,children:"取消"})]})]}),E&&e.jsxs("div",{className:"border-t border-green-100 dark:border-green-900/30 bg-green-50 dark:bg-green-900/10 p-3",children:[e.jsx("p",{className:"text-xs font-medium text-green-700 dark:text-green-400 mb-2",children:"确认通过审核?系统将自动递增版本并发布到仓库。"}),e.jsxs("label",{className:"flex items-start gap-2 mb-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:O=>b(O.target.checked),disabled:q,className:"mt-0.5 cursor-pointer"}),e.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300",children:"同时强制更新所有已使用该项目模板的用户(将覆盖本地修改)"})]}),p&&e.jsxs("p",{className:"text-xs text-amber-600 dark:text-amber-400 mb-2 flex items-start gap-1",children:[e.jsx("span",{children:"⚠"}),e.jsx("span",{children:"此操作将强制覆盖所有用户对该项目模板文件的本地修改,不可撤销。"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{size:"sm",className:"text-xs h-7 px-2.5 bg-green-600 hover:bg-green-700 text-white flex items-center gap-1.5",onClick:()=>R(v,p),disabled:q,children:q?e.jsxs(e.Fragment,{children:[e.jsx(ct,{className:"w-3 h-3 animate-spin"}),p?"更新中,请稍候...":"处理中..."]}):"确认通过"}),e.jsx(B,{size:"sm",variant:"outline",className:"text-xs h-7 px-2.5",onClick:()=>I(null),disabled:q,children:"取消"})]})]})]},v.id)})})]})}function sc({days:t,formatCost:r,formatNumber:a}){const[o,n]=s.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,u=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:u})]},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:["费用:",r(o.cost)]}),e.jsxs("div",{className:"text-muted-foreground",children:["请求:",a(o.requests)]})]})]})}function rc({onBack:t}){const[r,a]=s.useState("week"),[o,n]=s.useState(null),[l,i]=s.useState(!0),[d,u]=s.useState(!1),f=async()=>{try{const p=await Y(`/api/admin/usage/dashboard?period=${r}`);if(p.ok){const b=await p.json();n(b)}}catch(p){console.error("Error fetching dashboard data:",p)}finally{i(!1),u(!1)}};s.useEffect(()=>{i(!0),f()},[r]);const x=async()=>{try{u(!0),await Y("/api/admin/usage/scan",{method:"POST"}),await f()}catch(p){console.error("Error triggering scan:",p),u(!1)}},g=p=>!p||p===0?"$0.00":p<.01?`$${p.toFixed(4)}`:`$${p.toFixed(2)}`,h=p=>p?p>=1e6?`${(p/1e6).toFixed(1)}M`:p>=1e3?`${(p/1e3).toFixed(1)}K`:p.toString():"0";if(l)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"text-muted-foreground",children:"加载仪表板中..."})});const{totals:y,dailyTrend:k,modelDistribution:L,topUsers:I}=o||{};return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[t&&e.jsxs(B,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(Zt,{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(p=>e.jsx("button",{onClick:()=>a(p),className:`px-4 py-2 text-sm font-medium transition-colors ${r===p?"bg-primary text-primary-foreground":"bg-background text-foreground hover:bg-muted"}`,children:p==="week"?"周":"月"},p))}),e.jsx(B,{variant:"outline",size:"sm",onClick:x,disabled:d,title:"扫描新的使用数据",children:e.jsx(ct,{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(Or,{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:g(y?.totalCost)})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/30 rounded-lg",children:e.jsx(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:[y?.activeUsers||0," / ",y?.totalUsers||0]})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-purple-100 dark:bg-purple-900/30 rounded-lg",children:e.jsx(_r,{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:h(y?.totalRequests)})]})]})}),e.jsx("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-orange-100 dark:bg-orange-900/30 rounded-lg",children:e.jsx(Va,{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:h(y?.totalSessions)})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"每日成本趋势"}),k&&k.length>0?e.jsx(sc,{days:k,formatCost:g,formatNumber:h}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"模型成本"}),L&&L.length>0?e.jsx("div",{className:"space-y-3",children:L.map(p=>{const b=L.reduce((U,v)=>U+(v.cost||0),0)||1,m=(p.cost||0)/b*100,j=(p.normalized_model||p.model||"").toLowerCase(),G=(U=>U.includes("codex")?"bg-orange-500":U.includes("opus")?"bg-purple-500":U.includes("sonnet")?"bg-blue-500":U.includes("haiku")?"bg-green-500":"bg-gray-500")(j);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(et,{variant:"secondary",className:"truncate max-w-[200px]",title:p.model,children:p.model}),e.jsxs("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:[h(p.requests)," 请求"]})]}),e.jsx("span",{className:"text-sm font-mono text-foreground whitespace-nowrap ml-2",children:g(p.cost)})]}),e.jsx("div",{className:"h-2 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:`h-full ${G} rounded`,style:{width:`${m}%`}})})]},p.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:"用户成本"}),I&&I.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:I.map((p,b)=>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:["#",b+1]}),e.jsx("td",{className:"py-2 text-sm font-medium text-foreground",children:p.username}),e.jsx("td",{className:"py-2 text-sm text-right text-muted-foreground",children:h(p.total_requests)}),e.jsx("td",{className:"py-2 text-sm text-right font-mono text-foreground",children:g(p.total_cost)})]},p.user_uuid))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]})}const Aa={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 $a(t=""){const r=t.toLowerCase();return r.includes("codex")?"codex":r.includes("opus")?"opus":r.includes("sonnet")?"sonnet":r.includes("haiku")?"haiku":"default"}function Yr(t){return!t||t===0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Dr(t){return t?t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString():"0"}function ac(t){const r=[];for(let a=t-1;a>=0;a--){const o=new Date;o.setDate(o.getDate()-a),r.push(o.toISOString().split("T")[0])}return r}function nc({data:t}){const[r,a]=s.useState(null),o=140,n=o/2,l=o/2,i=56,d=t.reduce((x,g)=>x+(g.cost||0),0)||1;let u=-Math.PI/2;const f=t.map(x=>{const g=(x.cost||0)/d,h=g*2*Math.PI,y=u+h,k=n+i*Math.cos(u),L=l+i*Math.sin(u),I=n+i*Math.cos(y),p=l+i*Math.sin(y),b=h>Math.PI?1:0,m=g<.001?"":`M ${n} ${l} L ${k} ${L} A ${i} ${i} 0 ${b} 1 ${I} ${p} Z`,j=u+h/2,R={...x,pathD:m,ratio:g,midAngle:j,key:x.model};return u=y,R});return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("svg",{width:o,height:o,className:"flex-shrink-0",children:[f.map(x=>e.jsx("path",{d:x.pathD,fill:Aa.hex[$a(x.model)],opacity:r===null||r===x.key?1:.4,stroke:"white",strokeWidth:"1.5",onMouseEnter:()=>a(x.key),onMouseLeave:()=>a(null),className:"cursor-pointer transition-opacity duration-150"},x.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:f.map(x=>{const g=(x.ratio*100).toFixed(1),h=$a(x.model);return e.jsxs("div",{className:"flex items-center gap-2 min-w-0",onMouseEnter:()=>a(x.key),onMouseLeave:()=>a(null),children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${Aa.tailwind[h]}`}),e.jsx("span",{className:"text-xs text-muted-foreground truncate flex-1",title:x.model,children:x.model}),e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[g,"%"]}),e.jsx("span",{className:"text-xs font-mono text-foreground flex-shrink-0 w-14 text-right",children:Yr(x.cost)})]},x.key)})})]})}function oc({days:t}){const[r,a]=s.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)})}),r&&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:r.date}),e.jsxs("div",{className:"text-muted-foreground",children:["费用:",Yr(r.cost)]}),e.jsxs("div",{className:"text-muted-foreground",children:["请求:",Dr(r.requests)]})]})]})}function ic({userUuid:t,username:r,onBack:a}){const[o,n]=s.useState(null),[l,i]=s.useState(!0);s.useEffect(()=>{(async()=>{try{const g=await Y(`/api/admin/usage/users/${t}?period=week`);g.ok&&n(await g.json())}catch(g){console.error("Error fetching user usage:",g)}finally{i(!1)}})()},[t]);const d=ac(7),u={};(o?.dailyTrend||[]).forEach(x=>{u[x.date]=x});const f=d.map(x=>({date:x,cost:u[x]?.cost||0,requests:u[x]?.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(B,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Zt,{className:"w-4 h-4 mr-2"}),"返回"]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-foreground",children:r}),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(Or,{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:Yr(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(_r,{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:Dr(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(Va,{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:Dr(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(oc,{days:f})]}),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(nc,{data:o.modelDistribution}):e.jsx("div",{className:"flex items-center justify-center h-36 text-muted-foreground text-sm",children:"暂无使用数据"})]})]})]})}function lc({isOpen:t,onClose:r}){const{isAdmin:a,isSuperAdmin:o}=Ct(),[n,l]=s.useState("users"),[i,d]=s.useState(!1),[u,f]=s.useState(null);if(!t||!a)return null;const x=[{id:"users",label:"用户管理",icon:Ga},{id:"system",label:"系统设置",icon:Mo},{id:"agents",label:"共享项目审核",icon:Pt}],g=h=>{l(h),d(!1),f(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(Wt,{className:"w-5 h-5 md:w-6 md:h-6 text-blue-600"}),e.jsx("h2",{className:"text-lg md:text-xl font-semibold text-foreground",children:"管理"})]}),e.jsx(B,{variant:"ghost",size:"sm",onClick:r,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(Ge,{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:x.map(h=>e.jsx("button",{onClick:()=>g(h.id),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${n===h.id?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:h.label},h.id))})}),e.jsx("div",{className:"hidden md:flex flex-col w-48 border-r border-border p-3 gap-1 flex-shrink-0",children:x.map(h=>{const y=h.icon;return e.jsxs("button",{onClick:()=>g(h.id),className:`flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${n===h.id?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground hover:bg-accent/50"}`,children:[e.jsx(y,{className:"w-4 h-4"}),h.label]},h.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(rc,{onBack:()=>d(!1)}):u?e.jsx(ic,{userUuid:u.uuid,username:u.username,onBack:()=>f(null)}):e.jsx(Vl,{isSuperAdmin:o,onNavigateToUsage:()=>d(!0),onViewUser:(h,y)=>f({uuid:h,username:y})})}),n==="system"&&e.jsxs("div",{className:"space-y-6 md:space-y-8",children:[e.jsx(Yl,{}),e.jsx("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 md:pt-8",children:e.jsx(Xl,{})}),e.jsx(Zl,{})]}),n==="agents"&&e.jsx(tc,{})]})]})]})})}function cc({isOpen:t,limitType:r,onClose:a}){if(!t)return null;const o=r==="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(Ot,{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(Ge,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"mb-6 text-muted-foreground space-y-3",children:o?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"您的账户已达到使用总额度上限。"}),e.jsx("p",{className:"text-sm",children:"请联系管理员提升您的额度限制,以继续使用 Claude 服务。"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"您已达到今日使用额度上限。"}),e.jsx("p",{className:"text-sm",children:"您可以等待明日额度重置后继续使用,或联系管理员提升您的每日额度限制。"})]})}),e.jsx("div",{className:"mb-6 p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg",children:e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:o?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"提示:"}),"请联系您的管理员,申请提升使用额度。"]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"提示:"}),"每日额度将在次日 00:00 自动重置,您也可以联系管理员调整限额。"]})})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(B,{variant:"default",onClick:a,children:"我知道了"})})]})})}const dc=[{type:"user",content:"为什么上周的活跃用户数突然下降了 12%?",delay:1500},{type:"system",content:null,temporary:!0,delay:2e3},{type:"system",content:`正在分析最近 7 天的用户行为数据与服务端日志...
178
+
179
+ 经排查,主要原因如下:
180
+ 1. 上周四发布的 v3.2.1 版本引入了一个登录态校验 Bug,导致约 18% 的 iOS 用户被强制登出。
181
+ 2. 首页推荐算法调整使点击率下降 22%,间接影响留存。
182
+
183
+ 需要查看具体修复方案和用户召回策略吗?`,delay:4500},{type:"user",content:"给我修复方案,以及一个用户召回运营策略。",delay:8e3},{type:"system",content:null,temporary:!0,delay:9e3},{type:"system",content:`已定位到 auth-middleware.js 中的 token 刷新逻辑缺陷,修复 PR 已生成...
184
+
185
+ 运营建议:对受影响的 1,287 名用户推送定向 Push 通知 + 赠送 7 天会员体验,历史数据显示该策略召回率约 65%。`,delay:11e3}];function mc(){return e.jsxs("div",{className:"lp-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}function uc({msg:t}){const r=t.type==="user";return e.jsxs("div",{className:`lp-message ${r?"lp-user-msg":"lp-system-msg"}`,children:[e.jsx("div",{className:"lp-avatar",children:r?"U":e.jsx("img",{src:"/logo.svg",alt:"AgentHub"})}),e.jsx("div",{className:"lp-msg-content",children:t.temporary?e.jsx(mc,{}):t.content.split(`
186
+ `).map((a,o)=>e.jsxs(ut.Fragment,{children:[o>0&&e.jsx("br",{}),a]},o))})]})}function pc(){const t=Gs(),{isDarkMode:r,toggleDarkMode:a}=Vr(),[o,n]=s.useState([]),[l,i]=s.useState(!1),d=s.useRef(null),u=s.useRef(null);s.useEffect(()=>{const x=()=>i(window.scrollY>50);return window.addEventListener("scroll",x,{passive:!0}),()=>window.removeEventListener("scroll",x)},[]),s.useEffect(()=>{const x=[];return dc.forEach((g,h)=>{const y=setTimeout(()=>{n(k=>[...g.temporary?k:k.filter(I=>!I.temporary),{...g,id:h}])},g.delay);x.push(y)}),()=>x.forEach(clearTimeout)},[]),s.useEffect(()=>{d.current&&(d.current.scrollTop=d.current.scrollHeight)},[o]),s.useEffect(()=>(u.current=new IntersectionObserver(x=>{x.forEach(g=>{g.isIntersecting&&(g.target.classList.add("visible"),u.current?.unobserve(g.target))})},{threshold:.1}),document.querySelectorAll(".lp-fade-up").forEach(x=>{u.current?.observe(x)}),()=>u.current?.disconnect()),[]);const f=s.useCallback(()=>t("/app"),[t]);return e.jsxs("div",{className:"landing-page",children:[e.jsx("div",{className:"bg-orb orb-1"}),e.jsx("div",{className:"bg-orb orb-2"}),e.jsx("div",{className:"bg-grid"}),e.jsxs("nav",{className:`lp-navbar${l?" scrolled":""}`,children:[e.jsxs(Yt,{to:"/",className:"lp-logo",children:[e.jsx("img",{className:"lp-logo-icon",src:"/logo.svg",alt:"AgentHub"}),e.jsx("span",{children:"AgentHub"})]}),e.jsxs("ul",{className:"lp-nav-links",children:[e.jsx("li",{children:e.jsx("a",{href:"#features",children:"功能特性"})}),e.jsx("li",{children:e.jsx(Yt,{to:"/demo",children:"演示"})})]}),e.jsxs("div",{className:"lp-nav-right",children:[e.jsx("button",{className:"lp-theme-toggle",onClick:a,title:r?"切换到亮色":"切换到暗色",children:r?e.jsx(Ws,{size:18}):e.jsx(Us,{size:18})}),e.jsx("button",{className:"lp-btn lp-btn-primary",onClick:f,children:"开始使用"})]})]}),e.jsxs("main",{children:[e.jsxs("section",{className:"lp-hero",children:[e.jsxs("div",{className:"lp-hero-content",children:[e.jsx("div",{className:"lp-badge",children:"AI 驱动的智能工作平台"}),e.jsxs("h1",{className:"lp-hero-title",children:["一个入口",e.jsx("br",{}),e.jsx("span",{className:"gradient-text",children:"所有 AI Agent"})]}),e.jsx("p",{className:"lp-hero-subtitle",children:"AgentHub 整合 Claude、Gemini、Codex 等多个顶级 AI 模型,通过对话式交互完成代码分析、数据洞察与自动化任务。一站式管理你的 AI Agent 工作流。"}),e.jsxs("div",{className:"lp-hero-actions",children:[e.jsx("button",{className:"lp-btn lp-btn-primary lp-btn-large",onClick:f,children:"开始使用"}),e.jsx(Yt,{to:"/demo",className:"lp-btn lp-btn-secondary lp-btn-large",children:"查看演示"})]}),e.jsxs("div",{className:"lp-hero-stats",children:[e.jsxs("div",{className:"lp-stat",children:[e.jsx("span",{className:"lp-stat-number",children:"3+"}),e.jsx("span",{className:"lp-stat-label",children:"顶级 AI 模型"})]}),e.jsxs("div",{className:"lp-stat",children:[e.jsx("span",{className:"lp-stat-number",children:"10x"}),e.jsx("span",{className:"lp-stat-label",children:"效率提升"})]}),e.jsxs("div",{className:"lp-stat",children:[e.jsx("span",{className:"lp-stat-number",children:"0"}),e.jsx("span",{className:"lp-stat-label",children:"使用门槛"})]})]})]}),e.jsx("div",{className:"lp-hero-visual",children:e.jsxs("div",{className:"lp-chat-container glass-panel",children:[e.jsxs("div",{className:"lp-chat-header",children:[e.jsxs("div",{className:"lp-window-controls",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("div",{className:"lp-chat-title",children:"AgentHub 智能助手"})]}),e.jsxs("div",{className:"lp-chat-body",ref:d,children:[e.jsxs("div",{className:"lp-message lp-system-msg",children:[e.jsx("div",{className:"lp-avatar",children:e.jsx("img",{src:"/logo.svg",alt:"AgentHub"})}),e.jsx("div",{className:"lp-msg-content",children:"你好!我是 AgentHub 智能助手。我可以帮你分析数据、排查问题、生成代码。你想了解什么?"})]}),o.map(x=>e.jsx(uc,{msg:x},x.id))]}),e.jsxs("div",{className:"lp-chat-input-area",children:[e.jsx("input",{type:"text",placeholder:"例如:为什么昨天的用户留存率下降了?",disabled:!0}),e.jsx("button",{className:"lp-btn-send",children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),e.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})})]}),e.jsxs("section",{id:"features",className:"lp-features-section",children:[e.jsx("h2",{className:"lp-section-title",children:"为什么选择 AgentHub"}),e.jsxs("div",{className:"lp-features-grid",children:[e.jsxs("div",{className:"lp-feature-card glass-panel lp-fade-up",children:[e.jsx("div",{className:"lp-feature-icon",children:"🤖"}),e.jsx("h3",{children:"多模型统一平台"}),e.jsx("p",{children:"在同一个界面中自由切换 Claude、Gemini、Codex 等多个顶级 AI 模型,为不同任务选择最合适的引擎,无需反复跳转。"})]}),e.jsxs("div",{className:"lp-feature-card glass-panel lp-fade-up",style:{animationDelay:"0.1s"},children:[e.jsx("div",{className:"lp-feature-icon",children:"💬"}),e.jsx("h3",{children:"完全对话式交互"}),e.jsx("p",{children:"无需学习复杂操作。用自然语言提问,AI 瞬间理解你的意图并展开深度分析,就像和顶级工程师面对面沟通。"})]}),e.jsxs("div",{className:"lp-feature-card glass-panel lp-fade-up",style:{animationDelay:"0.2s"},children:[e.jsx("div",{className:"lp-feature-icon",children:"🔍"}),e.jsx("h3",{children:"深入代码与数据"}),e.jsx("p",{children:"不止是简单问答。Agent 能直接读取你的代码仓库、查询数据库、分析日志,找出问题的根本原因并提供修复方案。"})]}),e.jsxs("div",{className:"lp-feature-card glass-panel lp-fade-up",style:{animationDelay:"0.3s"},children:[e.jsx("div",{className:"lp-feature-icon",children:"🚀"}),e.jsx("h3",{children:"可扩展 Agent 生态"}),e.jsx("p",{children:"通过 MCP 服务器、自定义 Skills 和 Agent 商店,按需扩展平台能力。团队可以创建、分享和复用专属 Agent 工作流。"})]})]})]})]}),e.jsx("footer",{className:"lp-footer",children:e.jsxs("div",{className:"lp-footer-content",children:[e.jsxs(Yt,{to:"/",className:"lp-logo",children:[e.jsx("img",{className:"lp-logo-icon",src:"/logo.svg",alt:"AgentHub"}),e.jsx("span",{children:"AgentHub"})]}),e.jsxs("p",{className:"lp-copyright",children:["© ",new Date().getFullYear()," AgentHub. All rights reserved."]})]})})]})}const xc=[{tag:"数据分析",tagClass:"data",title:"用户流失根因分析",description:"面对突然变化的业务指标,AgentHub 能自动关联数据库与日志,定位根因并给出可执行建议。",highlights:["自动查询多张数据表交叉分析","关联服务端错误日志定位 Bug","输出量化的运营挽回方案"],messages:[{type:"user",content:"为什么上周高级会员流失率上升了 5%?"},{type:"system",content:"经分析,主要原因是上周四的支付模块更新导致 Android 13 设备出现签名验证失败(错误率 +420%),受影响的 231 名高净值用户在 30 分钟内流失。"},{type:"user",content:"有什么挽回方案?"},{type:"system",content:"建议对这批用户推送致歉邮件并附赠 50% 折扣券,历史数据显示此策略召回率约 65%。我已生成邮件模板和券码批量发放脚本。"}]},{tag:"代码排查",tagClass:"code",title:"线上 Bug 快速定位",description:"Agent 能直接阅读项目源码、分析 Git 提交记录,精准定位引入 Bug 的代码行并生成修复 PR。",highlights:["读取项目代码仓库并理解上下文","追溯 Git 历史找到问题提交","自动生成修复代码和测试用例"],messages:[{type:"user",content:"用户反馈登录后一直白屏,帮我排查一下。"},{type:"system",content:"已定位问题:auth-middleware.js 第 47 行的 token 刷新逻辑在 refreshToken 为 null 时抛出未捕获异常,导致前端路由守卫死循环。这个 Bug 在 commit a3f82d1(3 天前)引入。"},{type:"user",content:"帮我修复并生成测试。"},{type:"system",content:"修复方案:在 token 刷新前增加空值判断,当 refreshToken 无效时走重新登录流程。已生成修复代码和对应的 3 个单元测试用例。"}]},{tag:"运营决策",tagClass:"ops",title:"数据驱动增长策略",description:"结合业务数据和行业最佳实践,AI 为你量身定制增长方案,附带预期效果预测。",highlights:["基于历史数据建立预测模型","结合 A/B 测试结果优化策略","输出带 ROI 预估的行动清单"],messages:[{type:"user",content:"这个月的目标是把 7 日留存从 32% 提升到 40%,有什么方案?"},{type:"system",content:`分析了过去 6 个月的留存数据和用户行为漏斗后,建议聚焦以下 3 个高杠杆动作:
187
+ 1. 优化新手引导流程(预期 +3%)
188
+ 2. 第 3 天触发个性化推送(预期 +2.5%)
189
+ 3. 增加社交分享激励(预期 +2%)`},{type:"user",content:"先做第一个,帮我出方案细节。"},{type:"system",content:`新手引导优化方案:
190
+ • 将 5 步引导缩减为 3 步核心操作
191
+ • 增加「跳过」按钮降低流失
192
+ • 完成引导奖励首日 VIP 体验
193
+ 预计开发工期 3 天,已生成产品需求文档。`}]},{tag:"多模型协作",tagClass:"multi",title:"灵活切换 AI 引擎",description:"AgentHub 支持在同一个工作流中无缝切换 Claude、Gemini、Codex 等模型,为不同任务选择最优引擎。",highlights:["Claude 擅长复杂推理与代码生成","Gemini 擅长多模态和长上下文分析","Codex 专注高效代码补全"],messages:[{type:"user",content:"用 Claude 帮我设计一个缓存策略。"},{type:"system",content:"[Claude] 建议采用两级缓存架构:L1 使用进程内 LRU Cache(容量 1000),L2 使用 Redis(TTL 5 分钟),缓存命中率预计可达 92%。"},{type:"user",content:"切换到 Gemini,帮我分析这段代码的性能瓶颈。"},{type:"system",content:`[Gemini] 发现 3 个性能热点:
194
+ 1. 数据库查询未使用索引(耗时占 45%)
195
+ 2. JSON 序列化存在冗余字段(内存多占 30%)
196
+ 3. 日志写入为同步 I/O(P99 延迟 +200ms)`}]}];function hc({messages:t}){return e.jsxs("div",{className:"demo-chat-mockup glass-panel",children:[e.jsxs("div",{className:"lp-chat-header",children:[e.jsxs("div",{className:"lp-window-controls",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("div",{className:"lp-chat-title",children:"AgentHub"})]}),e.jsx("div",{className:"lp-chat-body",children:t.map((r,a)=>e.jsxs("div",{className:`lp-message ${r.type==="user"?"lp-user-msg":"lp-system-msg"}`,children:[e.jsx("div",{className:"lp-avatar",children:r.type==="user"?"U":e.jsx("img",{src:"/logo.svg",alt:"AgentHub"})}),e.jsx("div",{className:"lp-msg-content",children:r.content.split(`
197
+ `).map((o,n)=>e.jsxs(ut.Fragment,{children:[n>0&&e.jsx("br",{}),o]},n))})]},a))})]})}function gc(){const t=Gs(),{isDarkMode:r,toggleDarkMode:a}=Vr(),[o,n]=s.useState(!1);return s.useEffect(()=>{const l=()=>n(window.scrollY>50);return window.addEventListener("scroll",l,{passive:!0}),()=>window.removeEventListener("scroll",l)},[]),s.useEffect(()=>{window.scrollTo(0,0)},[]),s.useEffect(()=>{const l=new IntersectionObserver(i=>{i.forEach(d=>{d.isIntersecting&&(d.target.classList.add("visible"),l.unobserve(d.target))})},{threshold:.1});return document.querySelectorAll(".lp-fade-up").forEach(i=>l.observe(i)),()=>l.disconnect()},[]),e.jsxs("div",{className:"landing-page",children:[e.jsx("div",{className:"bg-orb orb-1"}),e.jsx("div",{className:"bg-orb orb-2"}),e.jsx("div",{className:"bg-grid"}),e.jsxs("nav",{className:`lp-navbar${o?" scrolled":""}`,children:[e.jsxs(Yt,{to:"/",className:"lp-logo",children:[e.jsx("img",{className:"lp-logo-icon",src:"/logo.svg",alt:"AgentHub"}),e.jsx("span",{children:"AgentHub"})]}),e.jsx("ul",{className:"lp-nav-links",children:e.jsx("li",{children:e.jsxs(Yt,{to:"/",style:{display:"inline-flex",alignItems:"center",gap:"0.4rem"},children:[e.jsx(Zt,{size:16})," 返回首页"]})})}),e.jsxs("div",{className:"lp-nav-right",children:[e.jsx("button",{className:"lp-theme-toggle",onClick:a,title:r?"切换到亮色":"切换到暗色",children:r?e.jsx(Ws,{size:18}):e.jsx(Us,{size:18})}),e.jsx("button",{className:"lp-btn lp-btn-primary",onClick:()=>t("/app"),children:"开始使用"})]})]}),e.jsxs("main",{children:[e.jsxs("section",{className:"demo-hero",children:[e.jsxs("h1",{children:["看看 ",e.jsx("span",{className:"gradient-text",children:"AgentHub"})," 能做什么"]}),e.jsx("p",{children:"以下是几个真实的使用场景,展示 AI Agent 如何帮你解决工作中的实际问题。"})]}),e.jsx("section",{className:"demo-scenarios",children:xc.map((l,i)=>e.jsxs("div",{className:"demo-scenario lp-fade-up",children:[e.jsxs("div",{className:"demo-scenario-info",children:[e.jsx("span",{className:`demo-scenario-tag ${l.tagClass}`,children:l.tag}),e.jsx("h2",{children:l.title}),e.jsx("p",{children:l.description}),e.jsx("ul",{className:"demo-highlights",children:l.highlights.map((d,u)=>e.jsx("li",{children:d},u))})]}),e.jsx(hc,{messages:l.messages})]},i))}),e.jsxs("section",{className:"demo-cta",children:[e.jsx("h2",{children:"准备好开始了吗?"}),e.jsx("p",{children:"立即体验 AgentHub,让 AI 成为你的超级助手。"}),e.jsx("button",{className:"lp-btn lp-btn-primary lp-btn-large",onClick:()=>t("/app"),children:"开始使用"})]})]}),e.jsx("footer",{className:"lp-footer",children:e.jsxs("div",{className:"lp-footer-content",children:[e.jsxs(Yt,{to:"/",className:"lp-logo",children:[e.jsx("img",{className:"lp-logo-icon",src:"/logo.svg",alt:"AgentHub"}),e.jsx("span",{children:"AgentHub"})]}),e.jsxs("p",{className:"lp-copyright",children:["© ",new Date().getFullYear()," AgentHub. All rights reserved."]})]})})]})}const fc=()=>{const[t,r]=s.useState("email"),[a,o]=s.useState(""),[n,l]=s.useState(""),[i,d]=s.useState(!1),[u,f]=s.useState(""),[x,g]=s.useState(0),{sendCode:h,verifyCode:y,smtpConfigured:k}=Ct();s.useEffect(()=>{if(x>0){const m=setTimeout(()=>g(x-1),1e3);return()=>clearTimeout(m)}},[x]);const L=async m=>{if(m.preventDefault(),f(""),!a||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)){f("请输入有效的邮箱地址");return}d(!0);const R=await h(a);R.success?(r("code"),g(60)):(f(R.error),R.waitSeconds&&g(R.waitSeconds)),d(!1)},I=async m=>{if(m.preventDefault(),f(""),!n||n.length!==6){f("请输入6位验证码");return}d(!0);const j=await y(a,n);j.success||f(j.error),d(!1)},p=async()=>{if(x>0)return;f(""),d(!0);const m=await h(a);m.success?g(60):f(m.error),d(!1)},b=()=>{r("email"),l(""),f("")};return k?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(Ks,{size:64})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:t==="email"?`欢迎使用 ${Ze}`:"创建管理员账户"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?"输入邮箱创建管理员账户":`验证码已发送至 ${a}`})]}),t==="email"&&e.jsxs("form",{onSubmit:L,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(Bs,{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:m=>o(m.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"})]})]}),u&&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:u})}),e.jsx("button",{type:"submit",disabled:i||x>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?"发送中...":x>0?`${x}秒后可重新发送`:"获取验证码"})]}),t==="code"&&e.jsxs("form",{onSubmit:I,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:b,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Zt,{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:m=>l(m.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"})]}),u&&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:u})}),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:p,disabled:x>0||i,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:x>0?`${x}秒后可重新发送`:"重新发送验证码"})})]}),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(Ks,{size:64})}),e.jsxs("h1",{className:"text-2xl font-bold text-foreground",children:["欢迎使用 ",Ze]}),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"})]})]})]})})})},bc=()=>{const[t,r]=s.useState("email"),[a,o]=s.useState("email"),[n,l]=s.useState(""),[i,d]=s.useState(""),[u,f]=s.useState(""),[x,g]=s.useState(""),[h,y]=s.useState(!1),[k,L]=s.useState(""),[I,p]=s.useState(0),[b,m]=s.useState(!1),{login:j,sendCode:R,verifyCode:G,smtpConfigured:U}=Ct();s.useEffect(()=>{if(I>0){const O=setTimeout(()=>p(I-1),1e3);return()=>clearTimeout(O)}},[I]),s.useEffect(()=>{U||r("password")},[U]);const v=async O=>{if(O.preventDefault(),L(""),!n||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)){L("请输入有效的邮箱地址");return}y(!0);const re=await R(n);re.success?(o("code"),p(60),m(re.type==="register")):(L(re.error),re.waitSeconds&&p(re.waitSeconds)),y(!1)},H=async O=>{if(O.preventDefault(),L(""),!i||i.length!==6){L("请输入6位验证码");return}y(!0);const se=await G(n,i);se.success||L(se.error),y(!1)},N=async()=>{if(I>0)return;L(""),y(!0);const O=await R(n);O.success?p(60):L(O.error),y(!1)},z=async O=>{if(O.preventDefault(),L(""),!u||!x){L("请输入用户名和密码");return}y(!0);const se=await j(u,x);se.success||L(se.error),y(!1)},q=()=>{o("email"),d(""),L("")},S=()=>{r("email"),o("email"),L("")},E=()=>{r("password"),L("")};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:Ze})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:t==="email"?a==="email"?`欢迎使用 ${Ze}`:b?"创建您的账户":"验证您的身份":"欢迎回来"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?a==="email"?"输入邮箱以接收验证码":`验证码已发送至 ${n}`:"使用账号密码登录"})]}),t==="email"&&a==="email"&&e.jsxs("form",{onSubmit:v,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(Bs,{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:O=>l(O.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:h,autoComplete:"email"})]})]}),k&&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:k})}),e.jsx("button",{type:"submit",disabled:h||I>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:h?"发送中...":I>0?`${I}秒后可重新发送`:"获取验证码"})]}),t==="email"&&a==="code"&&e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:q,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Zt,{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:O=>d(O.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:h,maxLength:6,autoComplete:"one-time-code"})]}),k&&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:k})}),e.jsx("button",{type:"submit",disabled:h||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:h?"验证中...":b?"创建账户并登录":"登录"}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:N,disabled:I>0||h,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:I>0?`${I}秒后可重新发送`:"重新发送验证码"})})]}),t==="password"&&e.jsxs("form",{onSubmit:z,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(Nr,{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:u,onChange:O=>f(O.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:h})]})]}),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(Io,{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:x,onChange:O=>g(O.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:h})]})]}),k&&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:k})}),e.jsx("button",{type:"submit",disabled:h,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:h?"登录中...":"登录"})]}),e.jsx("div",{className:"text-center pt-4 border-t border-border",children:t==="email"&&U?e.jsx("button",{type:"button",onClick:E,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用账号密码登录"}):t==="password"&&U?e.jsx("button",{type:"button",onClick:S,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用邮箱验证码登录"}):null})]})})})},yc=()=>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("img",{src:"/logo.svg",alt:Ze,className:"w-16 h-16"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground mb-2",children:Ze}),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:"加载中..."})]})}),vc=({children:t})=>{const{user:r,isLoading:a,needsSetup:o}=Ct();return a?e.jsx(yc,{}):o?e.jsx(fc,{}):r?t:e.jsx(bc,{})};function yr(t,r){const[a,o]=s.useState(()=>{if(typeof window>"u")return r;try{const l=window.localStorage.getItem(t);return l?JSON.parse(l):r}catch(l){return console.log(l),r}});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 _a(){const t=Gs(),{sessionId:r}=ao(),{limitStatus:a,setLimitStatus:o,checkLimitStatus:n,user:l,isAdmin:i}=Ct(),[d,u]=s.useState([]),[f,x]=s.useState(null),[g,h]=s.useState(null),[y,k]=s.useState("chat"),[L,I]=s.useState(!1),[p,b]=s.useState(!1),[m,j]=s.useState(!0),[R,G]=s.useState(!1),[U,v]=s.useState(!1),[H,N]=s.useState(!1),[z,q]=s.useState("shared_projects"),[S,E]=yr("autoScrollToBottom",!0),[O,se]=yr("sendByCtrlEnter",!1),[re,J]=yr("sidebarVisible",!0),[le,me]=s.useState(!1),[ge,De]=s.useState(null),we=ut.useRef(null),[Me,Ue]=s.useState(new Set),[ie,Se]=s.useState(new Set),[We,Be]=s.useState(0),{ws:ve,sendMessage:Ie,messages:Le}=gn(),qe=s.useCallback(K=>{De(K),me(!0)},[]),[ke,Je]=s.useState(!1);s.useEffect(()=>{const K=()=>{const oe=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone||document.referrer.includes("android-app://");Je(oe),document.addEventListener("touchstart",{}),oe?(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 K(),window.matchMedia("(display-mode: standalone)").addEventListener("change",K),()=>{window.matchMedia("(display-mode: standalone)").removeEventListener("change",K)}},[]),s.useEffect(()=>{const K=()=>{I(window.innerWidth<768)};return K(),window.addEventListener("resize",K),()=>window.removeEventListener("resize",K)},[]),s.useEffect(()=>{Pe()},[]);const $e=(K,oe,ce,Re)=>{if(!ce||!Re)return!0;const ae=K?.find(Fe=>Fe.name===ce.name),Te=oe?.find(Fe=>Fe.name===ce.name);if(!ae||!Te)return!1;const Ee=ae.sessions?.find(Fe=>Fe.id===Re.id),pe=Te.sessions?.find(Fe=>Fe.id===Re.id);return!Ee||!pe?!1:Ee.id===pe.id&&Ee.title===pe.title&&Ee.created_at===pe.created_at&&Ee.updated_at===pe.updated_at};s.useEffect(()=>{if(Le.length>0){const K=Le[Le.length-1];if(K.type==="projects_updated"){const oe=K.timestamp;if(oe&&oe===we.current)return;if(we.current=oe||null,K.changedFile&&g&&f){const Te=K.changedFile.replace(/\\/g,"/").split("/");Te.length>=2&&Te[Te.length-1].replace(".jsonl","")===g.id&&(Me.has(g.id)||Be(Fe=>Fe+1))}if(g&&Me.has(g.id)||Me.size>0&&Array.from(Me).some(ae=>ae.startsWith("new-session-"))){const ae=K.projects;if(!$e(d,ae,f,g))return}const Re=K.projects;if(u(Re),f){const ae=Re.find(Te=>Te.name===f.name);ae&&(JSON.stringify(ae)!==JSON.stringify(f)&&x(ae),g&&([...ae.sessions||[]].find(pe=>pe.id===g.id)||h(null)))}}}},[Le,f,g,Me]);const Pe=async()=>{try{j(!0);const oe=await(await he.projects()).json();u(ce=>ce.length===0||oe.some((ae,Te)=>{const Ee=ce[Te];return Ee?ae.name!==Ee.name||ae.displayName!==Ee.displayName||ae.fullPath!==Ee.fullPath||JSON.stringify(ae.sessionMeta)!==JSON.stringify(Ee.sessionMeta)||JSON.stringify(ae.sessions)!==JSON.stringify(Ee.sessions)||JSON.stringify(ae.agentInfo)!==JSON.stringify(Ee.agentInfo):!0})||oe.length!==ce.length?oe:ce)}catch(K){console.error("Error fetching projects:",K)}finally{j(!1)}};window.refreshProjects=Pe,window.openSettings=s.useCallback((K="tools")=>{q(K),v(!0)},[]),window.openAdminPanel=s.useCallback(()=>{N(!0)},[]),s.useEffect(()=>{if(r&&d.length>0){const K=!g||g.id!==r;for(const oe of d){let ce=oe.sessions?.find(Re=>Re.id===r);if(ce){x(oe),h({...ce,__provider:"claude"}),K&&k("chat");return}}}},[r,d,t]);const _e=K=>{x(K),h(null),t("/app"),L&&b(!1)},ze=K=>{if(h(K),y!=="git"&&y!=="preview"&&k("chat"),L){const oe=K.__projectName,ce=f?.name;oe!==ce&&b(!1)}t(`/app/session/${K.id}`)},Ae=K=>{x(K),h(null),k("chat"),t("/app"),L&&b(!1)},Ye=K=>{g?.id===K&&(h(null),t("/app")),u(oe=>oe.map(ce=>({...ce,sessions:ce.sessions?.filter(Re=>Re.id!==K)||[],sessionMeta:{...ce.sessionMeta,total:Math.max(0,(ce.sessionMeta?.total||0)-1)}})))},Oe=async()=>{try{const oe=await(await he.projects()).json();if(u(ce=>oe.some((ae,Te)=>{const Ee=ce[Te];return Ee?ae.name!==Ee.name||ae.displayName!==Ee.displayName||ae.fullPath!==Ee.fullPath||JSON.stringify(ae.sessionMeta)!==JSON.stringify(Ee.sessionMeta)||JSON.stringify(ae.sessions)!==JSON.stringify(Ee.sessions):!0})||oe.length!==ce.length?oe:ce),f){const ce=oe.find(Re=>Re.name===f.name);if(ce&&(JSON.stringify(ce)!==JSON.stringify(f)&&x(ce),g)){const Re=ce.sessions?.find(ae=>ae.id===g.id);Re&&JSON.stringify(Re)!==JSON.stringify(g)&&h(Re)}}}catch(K){console.error("Error refreshing sidebar:",K)}},V=K=>{f?.name===K&&(x(null),h(null),t("/app")),u(oe=>oe.filter(ce=>ce.name!==K))},$=s.useCallback(K=>{K&&Ue(oe=>new Set([...oe,K]))},[]),w=s.useCallback(K=>{K&&Ue(oe=>{const ce=new Set(oe);return ce.delete(K),ce})},[]),ee=s.useCallback(K=>{K&&Se(oe=>new Set([...oe,K]))},[]),A=s.useCallback(K=>{K&&Se(oe=>{const ce=new Set(oe);return ce.delete(K),ce})},[]),te=s.useCallback(K=>{K&&Ue(oe=>{const ce=new Set;for(const Re of oe)Re.startsWith("new-session-")||ce.add(Re);return ce.add(K),ce})},[]);return e.jsxs("div",{className:"fixed inset-0 flex bg-background",children:[!L&&e.jsx("div",{className:`h-full flex-shrink-0 border-r border-border bg-card transition-all duration-300 ${re?"w-80":"w-14"}`,children:e.jsx("div",{className:"h-full overflow-hidden",children:re?e.jsx(ha,{projects:d,selectedProject:f,selectedSession:g,onProjectSelect:_e,onSessionSelect:ze,onNewSession:Ae,onSessionDelete:Ye,onProjectDelete:V,isLoading:m,onRefresh:Oe,onShowSettings:()=>v(!0),onShowAdmin:()=>N(!0),isPWA:ke,isMobile:L,onToggleSidebar:()=>J(!1)}):e.jsxs("div",{className:"h-full flex flex-col items-center py-4 gap-4",children:[e.jsx("button",{onClick:()=>J(!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:()=>v(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Settings",title:"Settings",children:e.jsx(Ut,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})}),i&&e.jsx("button",{onClick:()=>N(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Admin",title:"管理",children:e.jsx(Wt,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})})]})})}),L&&e.jsxs("div",{className:`fixed inset-0 z-50 flex transition-all duration-150 ease-out ${p?"opacity-100 visible":"opacity-0 invisible"}`,children:[e.jsx("button",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm transition-opacity duration-150 ease-out",onClick:K=>{K.stopPropagation(),b(!1)},onTouchStart:K=>{K.preventDefault(),K.stopPropagation(),b(!1)},"aria-label":"Close sidebar"}),e.jsx("div",{className:`relative w-[85vw] max-w-sm sm:w-80 h-full bg-card border-r border-border transform transition-transform duration-150 ease-out ${p?"translate-x-0":"-translate-x-full"}`,onClick:K=>K.stopPropagation(),onTouchStart:K=>K.stopPropagation(),children:e.jsx(ha,{projects:d,selectedProject:f,selectedSession:g,onProjectSelect:_e,onSessionSelect:ze,onNewSession:Ae,onSessionDelete:Ye,onProjectDelete:V,isLoading:m,onRefresh:Oe,onShowSettings:()=>v(!0),onShowAdmin:()=>N(!0),isPWA:ke,isMobile:L,onToggleSidebar:()=>J(!1)})})]}),e.jsx("div",{className:`flex-1 flex flex-col min-w-0 ${L&&!R?"pb-mobile-nav":""}`,children:e.jsx(Cl,{selectedProject:f,selectedSession:g,activeTab:y,setActiveTab:k,ws:ve,sendMessage:Ie,messages:Le,isMobile:L,isPWA:ke,onMenuClick:()=>b(!0),isLoading:m,onInputFocusChange:G,onSessionActive:$,onSessionInactive:w,onSessionProcessing:ee,onSessionNotProcessing:A,processingSessions:ie,onReplaceTemporarySession:te,onNavigateToSession:K=>t(`/app/session/${K}`),onShowSettings:()=>v(!0),autoScrollToBottom:S,sendByCtrlEnter:O,externalMessageUpdate:We,limitStatus:a,onLimitBlocked:qe,checkLimitStatus:n})}),L&&e.jsx(El,{activeTab:y,setActiveTab:k,isInputFocused:R}),e.jsx(ql,{isOpen:U,onClose:()=>v(!1),projects:d,initialTab:z,autoScrollToBottom:S,onAutoScrollChange:E,sendByCtrlEnter:O,onSendByCtrlEnterChange:se}),e.jsx(lc,{isOpen:H,onClose:()=>N(!1)}),e.jsx(cc,{isOpen:le,limitType:ge,onClose:()=>me(!1)})]})}function jc(){return e.jsx(Qo,{children:e.jsx(Nl,{children:e.jsx(Vo,{children:e.jsx(vc,{children:e.jsxs(za,{children:[e.jsx(js,{index:!0,element:e.jsx(_a,{})}),e.jsx(js,{path:"session/:sessionId",element:e.jsx(_a,{})})]})})})})})}function wc(){return e.jsx(Ml,{children:e.jsx(ro,{children:e.jsxs(za,{children:[e.jsx(js,{path:"/",element:e.jsx(pc,{})}),e.jsx(js,{path:"/demo",element:e.jsx(gc,{})}),e.jsx(js,{path:"/app/*",element:e.jsx(jc,{})})]})})})}Uo.createRoot(document.getElementById("root")).render(e.jsx(ut.StrictMode,{children:e.jsx(wc,{})}));