@ian2018cs/agenthub 0.1.64 → 0.1.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,164 +0,0 @@
1
- import{j as e,s as yn,R as jn,o as wn,E as kn,m as Nn,b as Sn,c as Cn,h as En,p as Mn,d as Ln}from"./vendor-codemirror-C_VWDoZS.js";import{b as In,g as jr,a as s,d as ir,R as ft,u as va,B as Dn,e as Tn,f as Hr,h as An}from"./vendor-react-BeVl62c0.js";import{t as Rn,c as Pn,a as ya,F as $n}from"./vendor-utils-00TdZexr.js";import{T as At,C as ja,I as $s,F as fs,X as Ke,L as Tt,B as St,S as dt,R as nt,D as Ct,a as Wt,b as gs,c as Ms,d as Jr,e as lt,P as lr,f as ts,g as Ls,h as bs,i as _n,j as Rt,k as Pt,l as $t,m as zn,n as On,M as Ys,o as Fn,p as wr,q as Wn,r as Un,U as hs,s as Bn,t as es,u as qr,v as _s,w as kr,x as zs,G as Nr,y as Is,Z as Sr,E as wa,A as rs,z as ka,H as cr,J as Na,K as Sa,N as Ca,O as Kr,Q as Vr,V as Hn,W as Jn,Y as dr,_ as qn,$ as Kn,a0 as Ea,a1 as Vn,a2 as Gn,a3 as Yn,a4 as Cr,a5 as Qn,a6 as Xn,a7 as Zn,a8 as eo,a9 as to,aa as so,ab as mr,ac as ro,ad as Ds,ae as Ma,af as La,ag as ao,ah as no}from"./vendor-icons-D0W5CcE4.js";import{r as oo,a as io,b as lo,M as co}from"./vendor-markdown-VwNYkg_0.js";import{h as mo}from"./vendor-syntax-CdGaPJRS.js";import{r as uo,a as xo,b as po,c as ho}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 Ns={},Gr;function fo(){if(Gr)return Ns;Gr=1;var t=In();return Ns.createRoot=t.createRoot,Ns.hydrateRoot=t.hydrateRoot,Ns}var go=fo();const bo=jr(go);function Xe(...t){return Rn(Pn(t))}function vo(t){if(!t||typeof t!="string")return null;try{return JSON.parse(t)}catch{return null}}const Er=s.forwardRef(({className:t,children:r,...a},o)=>e.jsx("div",{ref:o,className:Xe("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})}));Er.displayName="ScrollArea";const yo=ya("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"}}),U=s.forwardRef(({className:t,variant:r,size:a,...o},n)=>e.jsx("button",{className:Xe(yo({variant:r,size:a,className:t})),ref:n,...o}));U.displayName="Button";const jo=ya("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",success:"border-transparent bg-green-500 text-white shadow hover:bg-green-500/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Qe({className:t,variant:r,...a}){return e.jsx("div",{className:Xe(jo({variant:r}),t),...a})}const Ze=s.forwardRef(({className:t,type:r,...a},o)=>e.jsx("input",{type:r,className:Xe("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}));Ze.displayName="Input";const Ia="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}",Da="[a-zA-Z0-9._/~:+@%=\\\\-]",wo=new RegExp(`${Da}*\\/user-data\\/${Ia}\\/`,"gi"),ko=new RegExp(`${Da}*\\/user-projects\\/${Ia}\\/`,"gi");function qe(t){return!t||typeof t!="string"?t||"":t.replace(wo,"./").replace(ko,"./")}const Ta=s.createContext(null);function tt(){const t=s.useContext(Ta);if(!t)throw new Error("useDialog must be used within DialogProvider");return t}function No({children:t}){const[r,a]=s.useState(null),o=s.useRef(null),n=s.useCallback(c=>{o.current?.(c),o.current=null,a(null)},[]),l=s.useCallback((c,u={})=>new Promise(g=>{o.current=g,a({type:"alert",message:c,title:u.title||"提示",variant:u.variant||"info"})}),[]),i=s.useCallback((c,u={})=>new Promise(g=>{o.current=g,a({type:"confirm",message:c,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(Ta.Provider,{value:{showAlert:l,showConfirm:i},children:[t,r&&ir.createPortal(e.jsx(So,{dialog:r,onClose:n}),document.body)]})}function So({dialog:t,onClose:r}){const a=s.useRef(null),o=s.useRef(null),[n,l]=s.useState(!1),i=s.useCallback(b=>{t.checkboxLabel!==void 0?r({confirmed:b,checked:b?n:!1}):r(b)},[t.checkboxLabel,n,r]);s.useEffect(()=>{t.type==="confirm"?a.current?.focus():o.current?.focus()},[t.type]),s.useEffect(()=>{const b=N=>{N.key==="Escape"&&(t.type==="confirm"?i(!1):r(void 0))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[t.type,r,i]);const c={info:e.jsx($s,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"}),warning:e.jsx(At,{className:"w-5 h-5 text-amber-600 dark:text-amber-400"}),error:e.jsx(ja,{className:"w-5 h-5 text-red-600 dark:text-red-400"}),danger:e.jsx(At,{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"},g={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=c[t.variant]||c.info,f=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:b=>b.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-full ${f} 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:b=>b.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-full ${f} 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:b=>l(b.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 ${g[t.variant]||g.info}`,onClick:()=>i(!0),children:t.confirmText})]})]})})}const K=(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:()=>K("/api/auth/user"),logout:()=>K("/api/auth/logout",{method:"POST"}),limitStatus:()=>K("/api/auth/limit-status"),changePassword:(t,r)=>K("/api/auth/change-password",{method:"PATCH",body:JSON.stringify({current_password:t,new_password:r})}),feishuBindToken:()=>K("/api/auth/feishu-bind-token",{method:"POST"}),feishuStatus:()=>K("/api/auth/feishu-status"),featurePermissions:()=>K("/api/auth/feature-permissions")},admin:{getUsers:()=>K("/api/admin/users"),createUser:(t,r)=>K("/api/admin/users",{method:"POST",body:JSON.stringify({username:t,password:r})}),updateUserStatus:(t,r)=>K(`/api/admin/users/${t}`,{method:"PATCH",body:JSON.stringify({status:r})}),deleteUser:t=>K(`/api/admin/users/${t}`,{method:"DELETE"}),getEmailDomains:()=>K("/api/admin/email-domains"),addEmailDomain:t=>K("/api/admin/email-domains",{method:"POST",body:JSON.stringify({domain:t})}),removeEmailDomain:t=>K(`/api/admin/email-domains/${t}`,{method:"DELETE"}),getUserLimits:t=>K(`/api/admin/users/${t}/limits`),updateUserLimits:(t,r)=>K(`/api/admin/users/${t}/limits`,{method:"PATCH",body:JSON.stringify(r)}),resetUserPassword:(t,r)=>K(`/api/admin/users/${t}/password`,{method:"PATCH",body:JSON.stringify({new_password:r})}),updateUserRole:(t,r)=>K(`/api/admin/users/${t}/role`,{method:"PATCH",body:JSON.stringify({role:r})}),getDefaultLimits:()=>K("/api/admin/settings/default-limits"),updateDefaultLimits:t=>K("/api/admin/settings/default-limits",{method:"PUT",body:JSON.stringify(t)}),getUserPermissions:t=>K(`/api/admin/users/${t}/permissions`),updateUserPermissions:(t,r)=>K(`/api/admin/users/${t}/permissions`,{method:"PATCH",body:JSON.stringify({permissions:r})}),getDefaultPermissions:()=>K("/api/admin/settings/default-permissions"),updateDefaultPermissions:t=>K("/api/admin/settings/default-permissions",{method:"PUT",body:JSON.stringify({permissions:t})}),getUserVisibleAgents:t=>K(`/api/admin/users/${t}/visible-agents`),updateUserVisibleAgents:(t,r)=>K(`/api/admin/users/${t}/visible-agents`,{method:"PATCH",body:JSON.stringify({agents:r})})},projects:()=>K("/api/projects"),sessions:(t,r=5,a=0)=>K(`/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 K(i)},renameProject:(t,r)=>K(`/api/projects/${t}/rename`,{method:"PUT",body:JSON.stringify({displayName:r})}),deleteSession:(t,r)=>K(`/api/projects/${t}/sessions/${r}`,{method:"DELETE"}),deleteProject:(t,r=!0)=>K(`/api/projects/${t}?deleteFolder=${r}`,{method:"DELETE"}),createProject:t=>K("/api/projects/create",{method:"POST",body:JSON.stringify({path:t})}),createWorkspace:t=>K("/api/projects/create-workspace",{method:"POST",body:JSON.stringify(t)}),readFile:(t,r)=>K(`/api/projects/${t}/file?filePath=${encodeURIComponent(r)}`),saveFile:(t,r,a)=>K(`/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());const o=a.toString();return K(`/api/projects/${t}/files${o?"?"+o:""}`)},uploadFiles:(t,r)=>K(`/api/projects/${t}/upload-files`,{method:"POST",body:r,headers:{}}),deleteFile:(t,r)=>K(`/api/projects/${t}/files?filePath=${encodeURIComponent(r)}`,{method:"DELETE"}),createDir:(t,r)=>K(`/api/projects/${t}/create-dir`,{method:"POST",body:JSON.stringify({dirPath:r})}),getFileContent:(t,r)=>K(`/api/projects/${t}/files/content?path=${encodeURIComponent(r)}`),transcribe:t=>K("/api/transcribe",{method:"POST",body:t,headers:{}}),settings:{getAgentPermissions:()=>K("/api/settings/agent-permissions"),saveAgentPermissions:t=>K("/api/settings/agent-permissions",{method:"PUT",body:JSON.stringify({agentPermissions:t})})},get:t=>K(`/api${t}`)},ps={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},Aa=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:ps,hasPermission:()=>!0,refreshFeaturePermissions:()=>{}}),mt=()=>{const t=s.useContext(Aa);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t};async function Qs(){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 Co=({children:t})=>{const[r,a]=s.useState(null),[o,n]=s.useState(localStorage.getItem("auth-token")),[l,i]=s.useState(!0),[c,u]=s.useState(!1),[g,x]=s.useState(!1),[f,b]=s.useState(null),[N,y]=s.useState({allowed:!0}),[p,w]=s.useState(ps);s.useEffect(()=>{h()},[]);const h=async()=>{try{i(!0),b(null);const M=await(await he.auth.status()).json();if(x(M.smtpConfigured||!1),M.needsSetup){u(!0),i(!1);return}if(o)try{const B=await he.auth.user();if(B.ok){const _=await B.json();a(_.user),u(!1),_.featurePermissions&&w({...ps,..._.featurePermissions}),await Qs()}else localStorage.removeItem("auth-token"),n(null),a(null)}catch(B){console.error("Token verification failed:",B),localStorage.removeItem("auth-token"),n(null),a(null)}}catch(T){console.error("[AuthContext] Auth status check failed:",T),b("Failed to check authentication status")}finally{i(!1)}},S=async T=>{try{b(null);const M=await he.auth.sendCode(T),B=await M.json();return M.ok?{success:!0,type:B.type}:{success:!1,error:B.error||"发送验证码失败",waitSeconds:B.waitSeconds}}catch(M){return console.error("Send code error:",M),{success:!1,error:"网络错误,请稍后再试"}}},m=async(T,M)=>{try{b(null);const B=await he.auth.verifyCode(T,M),_=await B.json();return B.ok?(n(_.token),a(_.user),u(!1),localStorage.setItem("auth-token",_.token),await Qs(),{success:!0}):(b(_.error||"验证失败"),{success:!1,error:_.error||"验证失败"})}catch(B){return console.error("Verify code error:",B),{success:!1,error:"网络错误,请稍后再试"}}},v=async(T,M)=>{try{b(null);const B=await he.auth.login(T,M),_=await B.json();return B.ok?(n(_.token),a(_.user),localStorage.setItem("auth-token",_.token),await Qs(),{success:!0}):(b(_.error||"登录失败"),{success:!1,error:_.error||"登录失败"})}catch(B){console.error("Login error:",B);const _="网络错误,请稍后再试";return b(_),{success:!1,error:_}}},j=()=>{n(null),a(null),y({allowed:!0}),w(ps),localStorage.removeItem("auth-token"),o&&he.auth.logout().catch(T=>{console.error("Logout endpoint error:",T)})},W=async()=>{if(!r)return{allowed:!0};try{const T=await he.auth.limitStatus();if(T.ok){const M=await T.json();return y(M),M}}catch(T){console.error("Error checking limit status:",T)}return{allowed:!0}},I=s.useCallback(async()=>{try{const T=await he.auth.featurePermissions();if(T.ok){const M=await T.json();M.featurePermissions&&w({...ps,...M.featurePermissions})}}catch(T){console.error("Error refreshing feature permissions:",T)}},[]),O=s.useCallback(T=>p[T]!==!1,[p]);s.useEffect(()=>{r&&!l&&W()},[r,l]);const A={user:r,token:o,login:v,sendCode:S,verifyCode:m,logout:j,isLoading:l,needsSetup:c,smtpConfigured:g,error:f,isAdmin:r?.role==="admin"||r?.role==="super_admin",isSuperAdmin:r?.role==="super_admin",limitStatus:N,checkLimitStatus:W,setLimitStatus:y,featurePermissions:p,hasPermission:O,refreshFeaturePermissions:I};return e.jsx(Aa.Provider,{value:A,children:t})},Eo=/^[a-zA-Z0-9_-]+$/,Mo=({onClose:t,onProjectCreated:r})=>{const[a,o]=s.useState(""),[n,l]=s.useState(""),[i,c]=s.useState(!1),[u,g]=s.useState(null),x=N=>N.trim()?Eo.test(N.trim())?null:"项目名称只能包含字母、数字、连字符和下划线":"项目名称为必填项",f=async()=>{g(null);const N=x(a);if(N){g(N);return}c(!0);try{const y={name:a.trim()};n.trim()&&(y.githubUrl=n.trim());const p=await he.createWorkspace(y),w=await p.json();if(!p.ok)throw new Error(w.error||"Failed to create project");r&&r(w.project),t()}catch(y){console.error("Error creating project:",y),g(y.message||"Failed to create project")}finally{c(!1)}},b=N=>{N.key==="Enter"&&!i&&f()};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(fs,{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(Ke,{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(ja,{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(Ze,{type:"text",value:a,onChange:N=>o(N.target.value),onKeyDown:b,placeholder:"my-awesome-project",className:"w-full",autoFocus:!0}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"仅允许字母、数字、连字符和下划线"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"GitHub 链接(可选)"}),e.jsx(Ze,{type:"text",value:n,onChange:N=>l(N.target.value),onKeyDown:b,placeholder:"https://github.com/user/repo",className:"w-full"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"留空以创建空项目,或输入公共仓库链接以克隆"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 p-6 border-t border-gray-200 dark:border-gray-700",children:[e.jsx(U,{variant:"outline",onClick:t,disabled:i,children:"取消"}),e.jsx(U,{onClick:f,disabled:i||!a.trim(),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Tt,{className:"w-4 h-4 mr-2 animate-spin"}),"创建中..."]}):"创建项目"})]})]})})};function Lo({projects:t=[],onClose:r}){const{showAlert:a,showConfirm:o}=tt(),[n,l]=s.useState([]),[i,c]=s.useState(!0),[u,g]=s.useState(null),[x,f]=s.useState(""),b={};for(const h of t)h.agentInfo?.isAgent&&(b[h.agentInfo.agentName]=h.agentInfo.installedVersion);s.useEffect(()=>{N()},[]),s.useEffect(()=>{const h=S=>{S.key==="Escape"&&r()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[r]);const N=async()=>{try{c(!0);const h=await K("/api/agents");if(h.ok){const S=await h.json();l(S.agents||[])}else{const S=await h.json();a(S.error||"获取 Agent 列表失败",{variant:"error"})}}catch(h){a(h.message,{variant:"error"})}finally{c(!1)}},y=async(h,S=!1)=>{const m=h.dirName||h.name;g(m);try{const v=await K("/api/agents/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentName:m,force:S})}),j=await v.json();if(v.status===409&&j.conflict){g(null),await o("检测到本地 CLAUDE.md 已被修改,更新将覆盖本地改动,是否继续?",{title:"本地文件冲突",confirmText:"强制更新",variant:"warning"})&&await y(h,!0);return}v.ok?(a(`Agent "${h.display_name||h.name}" ${S?"更新":"安装"}成功!项目已创建,Skills 和 MCP 服务已安装。`,{title:S?"更新成功":"安装成功"}),window.refreshProjects?.(),window.refreshMcpServers?.(),N()):a(j.error||"安装失败",{variant:"error"})}catch(v){a(v.message,{variant:"error"})}finally{g(null)}},p=h=>{const S=h.dirName||h.name,m=b[S];return m?m===h.version?{state:"up_to_date",installedVersion:m}:{state:"update_available",installedVersion:m,latestVersion:h.version}:{state:"not_installed"}},w=s.useMemo(()=>{if(!x.trim())return n;const h=x.toLowerCase();return n.filter(S=>(S.display_name||S.name||"").toLowerCase().includes(h)||(S.description||"").toLowerCase().includes(h))},[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:h=>h.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(St,{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:"安装 Agent 项目"}),!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(Ke,{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(dt,{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:"搜索 Agent...",value:x,onChange:h=>f(h.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(nt,{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(St,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"暂无可用 Agent"})]}):w.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(dt,{className:"w-6 h-6 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"未找到匹配的 Agent"})]}):w.map(h=>{const S=h.dirName||h.name,m=p(h),v=u===S;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(St,{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:h.display_name||h.name}),e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:["v",h.version]}),m.state==="update_available"&&e.jsxs(Qe,{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(Qe,{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 flex-shrink-0",children:"已安装"})]}),h.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:h.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[h.skills?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[h.skills.length," 个 Skill"]}),h.mcps?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[h.mcps.length," 个 MCP"]})]})]}),e.jsx(U,{size:"sm",variant:m.state==="not_installed"?"default":"outline",onClick:()=>y(h),disabled:v||m.state==="up_to_date",className:"text-xs h-7 px-2.5 flex-shrink-0",children:v?e.jsx(nt,{className:"w-3 h-3 animate-spin"}):m.state==="up_to_date"?"已是最新":m.state==="update_available"?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"w-3 h-3 mr-1"}),"更新"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"w-3 h-3 mr-1"}),"安装"]})})]},S)})}),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()?`${w.length} / ${n.length} 个 Agent`:i?"":`共 ${n.length} 个 Agent`}),e.jsx(U,{variant:"outline",size:"sm",onClick:r,className:"text-xs h-7",children:"关闭"})]})]})})}const Yr=(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)),c=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`:c===1?"1 hour ago":c<24?`${c} hours ago`:u===1?"1 day ago":u<7?`${u} days ago`:a.toLocaleDateString()};function Qr({projects:t,selectedProject:r,selectedSession:a,onProjectSelect:o,onSessionSelect:n,onNewSession:l,onSessionDelete:i,onProjectDelete:c,isLoading:u,onRefresh:g,onShowSettings:x,onShowAdmin:f,isPWA:b,isMobile:N,onToggleSidebar:y}){const{showAlert:p,showConfirm:w}=tt(),{user:h,isAdmin:S,hasPermission:m}=mt(),[v,j]=s.useState(new Set),[W,I]=s.useState(null),[O,A]=s.useState(!1),[T,M]=s.useState(!1),[B,_]=s.useState(""),[ce,V]=s.useState({}),[ee,ne]=s.useState({}),[ve,ye]=s.useState(new Set),[xe,ke]=s.useState(new Date),[Ee,Me]=s.useState("name"),[_e,Be]=s.useState(!1),[Q,Se]=s.useState(null),[Fe,Ne]=s.useState(""),[Le,Te]=s.useState({}),[ze,Ce]=s.useState(""),[He,Ve]=s.useState(()=>{try{const k=localStorage.getItem("starredProjects");return k?new Set(JSON.parse(k)):new Set}catch(k){return console.error("Error loading starred projects:",k),new Set}}),je=k=>X=>{X.target.closest(".overflow-y-auto")||X.target.closest("[data-scroll-container]")||(X.preventDefault(),X.stopPropagation(),k())};s.useEffect(()=>{const k=setInterval(()=>{ke(new Date)},6e4);return()=>clearInterval(k)},[]),s.useEffect(()=>{ne({}),ye(new Set)},[t]),s.useEffect(()=>{a&&r&&j(k=>new Set([...k,r.name]))},[a,r]),s.useEffect(()=>{if(t.length>0&&!u){const k=new Set;t.forEach(X=>{X.sessions&&X.sessions.length>=0&&k.add(X.name)}),ye(k)}},[t,u]),s.useEffect(()=>{const k=()=>{try{const fe=localStorage.getItem("claude-settings");if(fe){const J=JSON.parse(fe);Me(J.projectSortOrder||"name")}}catch(fe){console.error("Error loading sort order:",fe)}};k();const X=fe=>{fe.key==="claude-settings"&&k()};window.addEventListener("storage",X);const se=setInterval(()=>{document.hasFocus()&&k()},1e3);return()=>{window.removeEventListener("storage",X),clearInterval(se)}},[]);const Ae=k=>{const X=new Set;v.has(k)||X.add(k),j(X)},q=(k,X)=>{n({...k,__projectName:X})},oe=k=>{const X=new Set(He);X.has(k)?X.delete(k):X.add(k),Ve(X);try{localStorage.setItem("starredProjects",JSON.stringify([...X]))}catch(se){console.error("Error saving starred projects:",se)}},te=k=>He.has(k),Ie=k=>[...k.sessions||[],...ee[k.name]||[]].map(se=>({...se,__provider:"claude"})).sort((se,fe)=>new Date(fe.lastActivity)-new Date(se.lastActivity)),G=k=>{const X=Ie(k);return X.length===0?k.lastActivity?new Date(k.lastActivity):k.createdAt?new Date(k.createdAt):new Date(0):X.reduce((fe,J)=>{const Re=new Date(J.lastActivity);return Re>fe?Re:fe},new Date(0))},re=[...t].sort((k,X)=>{const se=te(k.name),fe=te(X.name);if(se&&!fe)return-1;if(!se&&fe)return 1;if(Ee==="date")return G(X)-G(k);{const J=k.displayName||k.name,Re=X.displayName||X.name;return J.localeCompare(Re)}}),C=k=>{I(k.name),_(k.displayName)},F=()=>{I(null),_("")},de=async k=>{try{(await he.renameProject(k,B)).ok?window.refreshProjects?window.refreshProjects():window.location.reload():console.error("Failed to rename project")}catch(X){console.error("Error renaming project:",X)}I(null),_("")},pe=async(k,X,se="claude")=>{if(await w("确定要删除此会话吗?此操作不可撤销。",{title:"删除会话",variant:"danger",confirmText:"确认删除"}))try{console.log("[Sidebar] Deleting session:",{projectName:k,sessionId:X,provider:se});const J=await he.deleteSession(k,X);if(console.log("[Sidebar] Delete response:",{ok:J.ok,status:J.status}),J.ok)console.log("[Sidebar] Session deleted successfully, calling callback"),i?i(X):console.warn("[Sidebar] No onSessionDelete callback provided");else{const Re=await J.text();console.error("[Sidebar] Failed to delete session:",{status:J.status,error:Re}),p("删除会话失败,请重试。",{variant:"error"})}}catch(J){console.error("[Sidebar] Error deleting session:",J),p("删除会话出错,请重试。",{variant:"error"})}},P=async(k,X)=>{if(await w(`确定要删除项目 "${X||k}" 吗?`,{title:"删除项目",subtitle:"此操作不可撤销",detail:"将同时删除:所有会话记录(JSONL 文件)和项目文件夹及其所有内容。",variant:"danger",confirmText:"确认删除"}))try{const fe=await he.deleteProject(k,!0);if(fe.ok)c&&c(k);else{const J=await fe.json();console.error("Failed to delete project"),p(J.error||"删除项目失败,请重试。",{variant:"error"})}}catch(fe){console.error("Error deleting project:",fe),p("删除项目出错,请重试。",{variant:"error"})}},ae=async k=>{if(!(!(k.sessionMeta?.hasMore!==!1)||ce[k.name])){V(se=>({...se,[k.name]:!0}));try{const se=(k.sessions?.length||0)+(ee[k.name]?.length||0),fe=await he.sessions(k.name,5,se);if(fe.ok){const J=await fe.json();ne(Re=>({...Re,[k.name]:[...Re[k.name]||[],...J.sessions]})),J.hasMore===!1&&(k.sessionMeta={...k.sessionMeta,hasMore:!1})}}catch(se){console.error("Error loading more sessions:",se)}finally{V(se=>({...se,[k.name]:!1}))}}},ue=re.filter(k=>{if(!ze.trim())return!0;const X=ze.toLowerCase(),se=(k.displayName||k.name).toLowerCase(),fe=k.name.toLowerCase();return se.includes(X)||fe.includes(X)}),le=k=>{o(k)};return e.jsxs(e.Fragment,{children:[O&&ir.createPortal(e.jsx(Mo,{onClose:()=>A(!1),onProjectCreated:k=>{window.refreshProjects?window.refreshProjects():window.location.reload()}}),document.body),T&&ir.createPortal(e.jsx(Lo,{projects:t,onClose:()=>M(!1)}),document.body),e.jsxs("div",{className:"h-full flex flex-col bg-card md:select-none",style:b&&N?{paddingTop:"44px"}:{},children:[e.jsxs("div",{className:"md:p-4 md:border-b md:border-border",children:[e.jsxs("div",{className:"hidden md:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:"/logo.svg",className:"w-8 h-8",alt:"AgentHub"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold text-foreground",children:"AgentHub"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"你的 AI 助手"})]})]}),y&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200",onClick:y,title:"收起侧边栏",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})})]}),e.jsx("div",{className:"md:hidden p-3 border-b border-border",style:b&&N?{paddingTop:"16px"}:{},children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:"/logo.svg",className:"w-8 h-8",alt:"AgentHub"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"AgentHub"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"项目"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{className:"w-8 h-8 rounded-md bg-background border border-border flex items-center justify-center active:scale-95 transition-all duration-150",onClick:async()=>{Be(!0);try{await g()}finally{Be(!1)}},disabled:_e,children:e.jsx(nt,{className:`w-4 h-4 text-foreground ${_e?"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:()=>M(!0),children:e.jsx(St,{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:()=>A(!0),children:e.jsx(fs,{className:"w-4 h-4"})})]})]})})]}),!u&&!N&&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(U,{variant:"default",size:"sm",className:"flex-1 h-8 text-xs bg-primary hover:bg-primary/90 transition-all duration-200",onClick:()=>A(!0),title:"创建新项目",children:[e.jsx(fs,{className:"w-3.5 h-3.5 mr-1.5"}),"新建项目"]}),e.jsxs(U,{variant:"default",size:"sm",className:"flex-1 h-8 text-xs bg-primary hover:bg-primary/90 transition-all duration-200",onClick:()=>M(!0),title:"安装 Agent 项目",children:[e.jsx(St,{className:"w-3.5 h-3.5 mr-1.5"}),"安装 Agent 项目"]}),e.jsx(U,{variant:"outline",size:"sm",className:"h-8 w-8 px-0 hover:bg-accent transition-colors duration-200 group",onClick:async()=>{Be(!0);try{await g()}finally{Be(!1)}},disabled:_e,title:"刷新项目和会话 (Ctrl+R)",children:e.jsx(nt,{className:`w-3.5 h-3.5 ${_e?"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(dt,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ze,{type:"text",placeholder:"搜索项目...",value:ze,onChange:k=>Ce(k.target.value),className:"pl-9 h-9 text-sm bg-muted/50 border-0 focus:bg-background focus:ring-1 focus:ring-primary/20"}),ze&&e.jsx("button",{onClick:()=>Ce(""),className:"absolute right-2 top-1/2 transform -translate-y-1/2 p-1 hover:bg-accent rounded",children:e.jsx(Ke,{className:"w-3 h-3 text-muted-foreground"})})]})}),e.jsx(Er,{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(Wt,{className:"w-6 h-6 text-muted-foreground"})}),e.jsx("h3",{className:"text-base font-medium text-foreground mb-2 md:mb-1",children:"未找到项目"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"请先创建一个项目,开始与 AgentHub 进行交流"})]}):ue.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(dt,{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:"尝试调整搜索条件"})]}):ue.map(k=>{const X=v.has(k.name),se=r?.name===k.name,fe=te(k.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:Xe("p-3 mx-3 my-1 rounded-lg bg-card border border-border/50 active:scale-[0.98] transition-all duration-150",se&&"bg-primary/5 border-primary/20",fe&&!se&&"bg-yellow-50/50 dark:bg-yellow-900/5 border-yellow-200/30 dark:border-yellow-800/30"),onClick:()=>{Ae(k.name)},onTouchEnd:je(()=>Ae(k.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:Xe("w-8 h-8 rounded-lg flex items-center justify-center transition-colors",X?"bg-primary/10":"bg-muted"),children:X?e.jsx(gs,{className:"w-4 h-4 text-primary"}):e.jsx(Wt,{className:"w-4 h-4 text-muted-foreground"})}),e.jsx("div",{className:"min-w-0 flex-1",children:W===k.name?e.jsx("input",{type:"text",value:B,onChange:J=>_(J.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:J=>J.stopPropagation(),onKeyDown:J=>{J.key==="Enter"&&de(k.name),J.key==="Escape"&&F()},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:k.displayName}),k.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 J=Ie(k).length;return`${k.sessionMeta?.hasMore!==!1&&J>=5?`${J}+`:J} 会话`})()})]})})]}),e.jsx("div",{className:"flex items-center gap-1",children:W===k.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:J=>{J.stopPropagation(),de(k.name)},children:e.jsx(Ms,{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:J=>{J.stopPropagation(),F()},children:e.jsx(Ke,{className:"w-4 h-4 text-white"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:Xe("w-8 h-8 rounded-lg flex items-center justify-center active:scale-90 transition-all duration-150 border",fe?"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:J=>{J.stopPropagation(),oe(k.name)},onTouchEnd:je(()=>oe(k.name)),title:fe?"从收藏中移除":"添加到收藏",children:e.jsx(Jr,{className:Xe("w-4 h-4 transition-colors",fe?"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:J=>{J.stopPropagation(),P(k.name,k.displayName)},onTouchEnd:je(()=>P(k.name,k.displayName)),children:e.jsx(lt,{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:J=>{J.stopPropagation(),C(k)},onTouchEnd:je(()=>C(k)),children:e.jsx(lr,{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:X?e.jsx(ts,{className:"w-3 h-3 text-muted-foreground"}):e.jsx(Ls,{className:"w-3 h-3 text-muted-foreground"})})]})})]})})}),e.jsxs(U,{variant:"ghost",className:Xe("hidden md:flex w-full justify-between p-2 h-auto font-normal hover:bg-accent/50",se&&"bg-accent text-accent-foreground",fe&&!se&&"bg-yellow-50/50 dark:bg-yellow-900/10 hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20"),onClick:()=>{r?.name!==k.name&&le(k),Ae(k.name)},onTouchEnd:je(()=>{r?.name!==k.name&&le(k),Ae(k.name)}),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[X?e.jsx(gs,{className:"w-4 h-4 text-primary flex-shrink-0"}):e.jsx(Wt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"min-w-0 flex-1 text-left",children:W===k.name?e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{type:"text",value:B,onChange:J=>_(J.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:J=>{J.key==="Enter"&&de(k.name),J.key==="Escape"&&F()}}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",title:qe(k.fullPath),children:qe(k.fullPath)})]}):e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold truncate text-foreground",title:k.displayName,children:k.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[(()=>{const J=Ie(k).length;return k.sessionMeta?.hasMore!==!1&&J>=5?`${J}+`:J})(),k.fullPath!==k.displayName&&e.jsxs("span",{className:"ml-1 opacity-60",title:qe(k.fullPath),children:["• ",(()=>{const J=qe(k.fullPath);return J.length>25?"..."+J.slice(-22):J})()]})]})]})})]}),e.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:W===k.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:J=>{J.stopPropagation(),de(k.name)},children:e.jsx(Ms,{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:J=>{J.stopPropagation(),F()},children:e.jsx(Ke,{className:"w-3 h-3"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:Xe("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",fe?"hover:bg-yellow-50 dark:hover:bg-yellow-900/20 opacity-100":"hover:bg-accent"),onClick:J=>{J.stopPropagation(),oe(k.name)},title:fe?"从收藏中移除":"添加到收藏",children:e.jsx(Jr,{className:Xe("w-3 h-3 transition-colors",fe?"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:J=>{J.stopPropagation(),C(k)},title:"重命名项目 (F2)",children:e.jsx(lr,{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:J=>{J.stopPropagation(),P(k.name,k.displayName)},title:"删除项目",children:e.jsx(lt,{className:"w-3 h-3 text-red-600 dark:text-red-400"})}),X?e.jsx(ts,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"}):e.jsx(Ls,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"})]})})]})]}),X&&e.jsxs("div",{className:"ml-3 space-y-1 border-l border-border pl-3",children:[ve.has(k.name)?Ie(k).length===0&&!ce[k.name]?e.jsx("div",{className:"py-2 px-3 text-left",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"还没有会话"})}):Ie(k).map(J=>{const Re=new Date(J.lastActivity),we=Math.floor((xe-Re)/(1e3*60))<10,We=J.summary||"新会话",Oe=J.lastActivity,Ge=J.messageCount||0;return e.jsxs("div",{className:"group relative",children:[we&&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:Xe("p-2 mx-3 my-0.5 rounded-md bg-card border active:scale-[0.98] transition-all duration-150 relative",a?.id===J.id?"bg-primary/5 border-primary/20":we?"border-green-500/30 bg-green-50/5 dark:bg-green-900/5":"border-border/30"),onClick:()=>{le(k),q(J,k.name)},onTouchEnd:je(()=>{le(k),q(J,k.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:We}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(bs,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Yr(Oe,xe)}),Ge>0&&e.jsx(Qe,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:Ge})]})]}),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:Pe=>{Pe.stopPropagation(),pe(k.name,J.id)},onTouchEnd:je(()=>pe(k.name,J.id)),children:e.jsx(lt,{className:"w-2.5 h-2.5 text-red-600 dark:text-red-400"})})]})})}),e.jsxs("div",{className:"hidden md:block",children:[e.jsx(U,{variant:"ghost",className:Xe("w-full justify-start p-2 h-auto font-normal text-left hover:bg-accent/50 transition-colors duration-200",a?.id===J.id&&"bg-accent text-accent-foreground"),onClick:()=>q(J,k.name),onTouchEnd:je(()=>q(J,k.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:We}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(bs,{className:"w-2.5 h-2.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Yr(Oe,xe)}),Ge>0&&e.jsx(Qe,{variant:"secondary",className:"text-xs px-1 py-0 ml-auto",children:Ge})]})]})})}),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:Q===J.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:Fe,onChange:Pe=>Ne(Pe.target.value),onKeyDown:Pe=>{Pe.stopPropagation(),Pe.key==="Enter"?updateSessionSummary(k.name,J.id,Fe):Pe.key==="Escape"&&(Se(null),Ne(""))},onClick:Pe=>Pe.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:Pe=>{Pe.stopPropagation(),updateSessionSummary(k.name,J.id,Fe)},title:"Save",children:e.jsx(Ms,{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:Pe=>{Pe.stopPropagation(),Se(null),Ne("")},title:"Cancel",children:e.jsx(Ke,{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:Pe=>{Pe.stopPropagation(),Se(J.id),Ne(J.summary||"新会话")},title:"手动编辑会话名称",children:e.jsx(_n,{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:Pe=>{Pe.stopPropagation(),pe(k.name,J.id)},title:"永久删除此会话",children:e.jsx(lt,{className:"w-3 h-3 text-red-600 dark:text-red-400"})})]})})]})]},J.id)}):Array.from({length:3}).map((J,Re)=>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+Re*15}%`}}),e.jsx("div",{className:"h-2 bg-muted rounded animate-pulse w-1/2"})]})]})},Re)),Ie(k).length>0&&k.sessionMeta?.hasMore!==!1&&e.jsx(U,{variant:"ghost",size:"sm",className:"w-full justify-center gap-2 mt-2 text-muted-foreground",onClick:()=>ae(k),disabled:ce[k.name],children:ce[k.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(ts,{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:()=>{le(k),l(k)},children:[e.jsx(Rt,{className:"w-3 h-3"}),"新会话"]})}),e.jsxs(U,{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(k),children:[e.jsx(Rt,{className:"w-3 h-3"}),"新会话"]})]})]},k.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(Pt,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"设置"})]}),S&&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:f,children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-background/80 flex items-center justify-center",children:e.jsx($t,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("span",{className:"text-lg font-medium text-foreground",children:"管理"})]})]}),e.jsxs(U,{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(Pt,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"设置"})]}),S&&e.jsxs(U,{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:f,children:[e.jsx($t,{className:"w-3 h-3"}),e.jsx("span",{className:"text-xs",children:"管理"})]})]})]})]})}const Io={'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 Xs={exports:{}},Zs,Xr;function Do(){if(Xr)return Zs;Xr=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Zs=t,Zs}var er,Zr;function To(){if(Zr)return er;Zr=1;var t=Do();function r(){}function a(){}return a.resetWarningCache=r,er=function(){function o(i,c,u,g,x,f){if(f!==t){var b=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw b.name="Invariant Violation",b}}o.isRequired=o;function n(){return o}var l={array:o,bigint:o,bool:o,func:o,number:o,object:o,string:o,symbol:o,any:o,arrayOf:n,element:o,elementType:o,instanceOf:n,node:o,objectOf:n,oneOf:n,oneOfType:n,shape:n,exact:n,checkPropTypes:a,resetWarningCache:r};return l.PropTypes=l,l},er}var ea;function Ao(){return ea||(ea=1,Xs.exports=To()()),Xs.exports}var Ro=Ao();const Je=jr(Ro);function Ut(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 c(x){try{g(o.next(x))}catch(f){i(f)}}function u(x){try{g(o.throw(x))}catch(f){i(f)}}function g(x){x.done?l(x.value):n(x.value).then(c,u)}g((o=o.apply(t,r||[])).next())})}const Po=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 ss(t,r,a){const o=$o(t),{webkitRelativePath:n}=t,l=typeof r=="string"?r:typeof n=="string"&&n.length>0?n:`./${t.name}`;return typeof o.path!="string"&&ta(o,"path",l),ta(o,"relativePath",l),o}function $o(t){const{name:r}=t;if(r&&r.lastIndexOf(".")!==-1&&!t.type){const o=r.split(".").pop().toLowerCase(),n=Po.get(o);n&&Object.defineProperty(t,"type",{value:n,writable:!1,configurable:!1,enumerable:!0})}return t}function ta(t,r,a){Object.defineProperty(t,r,{value:a,writable:!1,configurable:!1,enumerable:!0})}const _o=[".DS_Store","Thumbs.db"];function zo(t){return Ut(this,void 0,void 0,function*(){return Ts(t)&&Oo(t.dataTransfer)?Bo(t.dataTransfer,t.type):Fo(t)?Wo(t):Array.isArray(t)&&t.every(r=>"getFile"in r&&typeof r.getFile=="function")?Uo(t):[]})}function Oo(t){return Ts(t)}function Fo(t){return Ts(t)&&Ts(t.target)}function Ts(t){return typeof t=="object"&&t!==null}function Wo(t){return ur(t.target.files).map(r=>ss(r))}function Uo(t){return Ut(this,void 0,void 0,function*(){return(yield Promise.all(t.map(a=>a.getFile()))).map(a=>ss(a))})}function Bo(t,r){return Ut(this,void 0,void 0,function*(){if(t.items){const a=ur(t.items).filter(n=>n.kind==="file");if(r!=="drop")return a;const o=yield Promise.all(a.map(Ho));return sa(Ra(o))}return sa(ur(t.files).map(a=>ss(a)))})}function sa(t){return t.filter(r=>_o.indexOf(r.name)===-1)}function ur(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 Ho(t){if(typeof t.webkitGetAsEntry!="function")return ra(t);const r=t.webkitGetAsEntry();return r&&r.isDirectory?Pa(r):ra(t,r)}function Ra(t){return t.reduce((r,a)=>[...r,...Array.isArray(a)?Ra(a):[a]],[])}function ra(t,r){return Ut(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,ss(i)}}const o=t.getAsFile();if(!o)throw new Error(`${t} is not a File`);return ss(o,(a=r?.fullPath)!==null&&a!==void 0?a:void 0)})}function Jo(t){return Ut(this,void 0,void 0,function*(){return t.isDirectory?Pa(t):qo(t)})}function Pa(t){const r=t.createReader();return new Promise((a,o)=>{const n=[];function l(){r.readEntries(i=>Ut(this,void 0,void 0,function*(){if(i.length){const c=Promise.all(i.map(Jo));n.push(c),l()}else try{const c=yield Promise.all(n);a(c)}catch(c){o(c)}}),i=>{o(i)})}l()})}function qo(t){return Ut(this,void 0,void 0,function*(){return new Promise((r,a)=>{t.file(o=>{const n=ss(o,t.fullPath);r(n)},o=>{a(o)})})})}var Ss={},aa;function Ko(){return aa||(aa=1,Ss.__esModule=!0,Ss.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 c=i.trim().toLowerCase();return c.charAt(0)==="."?o.toLowerCase().endsWith(c):c.endsWith("/*")?l===c.replace(/\/.*$/,""):n===c})}return!0}),Ss}var Vo=Ko();const tr=jr(Vo);function na(t){return Qo(t)||Yo(t)||_a(t)||Go()}function Go(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
2
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Yo(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Qo(t){if(Array.isArray(t))return xr(t)}function oa(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 ia(t){for(var r=1;r<arguments.length;r++){var a=arguments[r]!=null?arguments[r]:{};r%2?oa(Object(a),!0).forEach(function(o){$a(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):oa(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function $a(t,r,a){return r in t?Object.defineProperty(t,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[r]=a,t}function vs(t,r){return ei(t)||Zo(t,r)||_a(t,r)||Xo()}function Xo(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
3
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _a(t,r){if(t){if(typeof t=="string")return xr(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 xr(t,r)}}function xr(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 Zo(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,c;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,c=u}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw c}}return o}}function ei(t){if(Array.isArray(t))return t}var ti=typeof tr=="function"?tr:tr.default,si="file-invalid-type",ri="file-too-large",ai="file-too-small",ni="too-many-files",oi=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:si,message:"File type must be ".concat(o)}},la=function(r){return{code:ri,message:"File is larger than ".concat(r," ").concat(r===1?"byte":"bytes")}},ca=function(r){return{code:ai,message:"File is smaller than ".concat(r," ").concat(r===1?"byte":"bytes")}},ii={code:ni,message:"Too many files"};function za(t,r){var a=t.type==="application/x-moz-file"||ti(t,r);return[a,a?null:oi(r)]}function Oa(t,r,a){if(Ft(t.size))if(Ft(r)&&Ft(a)){if(t.size>a)return[!1,la(a)];if(t.size<r)return[!1,ca(r)]}else{if(Ft(r)&&t.size<r)return[!1,ca(r)];if(Ft(a)&&t.size>a)return[!1,la(a)]}return[!0,null]}function Ft(t){return t!=null}function li(t){var r=t.files,a=t.accept,o=t.minSize,n=t.maxSize,l=t.multiple,i=t.maxFiles,c=t.validator;return!l&&r.length>1||l&&i>=1&&r.length>i?!1:r.every(function(u){var g=za(u,a),x=vs(g,1),f=x[0],b=Oa(u,o,n),N=vs(b,1),y=N[0],p=c?c(u):null;return f&&y&&!p})}function As(t){return typeof t.isPropagationStopped=="function"?t.isPropagationStopped():typeof t.cancelBubble<"u"?t.cancelBubble:!1}function Cs(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 da(t){t.preventDefault()}function ci(t){return t.indexOf("MSIE")!==-1||t.indexOf("Trident/")!==-1}function di(t){return t.indexOf("Edge/")!==-1}function mi(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.navigator.userAgent;return ci(t)||di(t)}function ht(){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(c){return!As(o)&&c&&c.apply(void 0,[o].concat(l)),As(o)})}}function ui(){return"showOpenFilePicker"in window}function xi(t){if(Ft(t)){var r=Object.entries(t).filter(function(a){var o=vs(a,2),n=o[0],l=o[1],i=!0;return Fa(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(Wa))&&(console.warn('Skipped "'.concat(n,'" because an invalid file extension was provided.')),i=!1),i}).reduce(function(a,o){var n=vs(o,2),l=n[0],i=n[1];return ia(ia({},a),{},$a({},l,i))},{});return[{description:"Files",accept:r}]}return t}function pi(t){if(Ft(t))return Object.entries(t).reduce(function(r,a){var o=vs(a,2),n=o[0],l=o[1];return[].concat(na(r),[n],na(l))},[]).filter(function(r){return Fa(r)||Wa(r)}).join(",")}function hi(t){return t instanceof DOMException&&(t.name==="AbortError"||t.code===t.ABORT_ERR)}function fi(t){return t instanceof DOMException&&(t.name==="SecurityError"||t.code===t.SECURITY_ERR)}function Fa(t){return t==="audio/*"||t==="video/*"||t==="image/*"||t==="text/*"||t==="application/*"||/\w+\/[-+.\w]+/g.test(t)}function Wa(t){return/^.*\.[\w]+$/.test(t)}var gi=["children"],bi=["open"],vi=["refKey","role","onKeyDown","onFocus","onBlur","onClick","onDragEnter","onDragOver","onDragLeave","onDrop"],yi=["refKey","onChange","onClick"];function ji(t){return Ni(t)||ki(t)||Ua(t)||wi()}function wi(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
4
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ki(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Ni(t){if(Array.isArray(t))return pr(t)}function sr(t,r){return Ei(t)||Ci(t,r)||Ua(t,r)||Si()}function Si(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
5
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ua(t,r){if(t){if(typeof t=="string")return pr(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 pr(t,r)}}function pr(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 Ci(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,c;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,c=u}finally{try{!n&&a.return!=null&&a.return()}finally{if(l)throw c}}return o}}function Ei(t){if(Array.isArray(t))return t}function ma(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 Ye(t){for(var r=1;r<arguments.length;r++){var a=arguments[r]!=null?arguments[r]:{};r%2?ma(Object(a),!0).forEach(function(o){hr(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):ma(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}function hr(t,r,a){return r in t?Object.defineProperty(t,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[r]=a,t}function Rs(t,r){if(t==null)return{};var a=Mi(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 Mi(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 Mr=s.forwardRef(function(t,r){var a=t.children,o=Rs(t,gi),n=Lr(o),l=n.open,i=Rs(n,bi);return s.useImperativeHandle(r,function(){return{open:l}},[l]),ft.createElement(s.Fragment,null,a(Ye(Ye({},i),{},{open:l})))});Mr.displayName="Dropzone";var Ba={disabled:!1,getFilesFromEvent:zo,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};Mr.defaultProps=Ba;Mr.propTypes={children:Je.func,accept:Je.objectOf(Je.arrayOf(Je.string)),multiple:Je.bool,preventDropOnDocument:Je.bool,noClick:Je.bool,noKeyboard:Je.bool,noDrag:Je.bool,noDragEventsBubbling:Je.bool,minSize:Je.number,maxSize:Je.number,maxFiles:Je.number,disabled:Je.bool,getFilesFromEvent:Je.func,onFileDialogCancel:Je.func,onFileDialogOpen:Je.func,useFsAccessApi:Je.bool,autoFocus:Je.bool,onDragEnter:Je.func,onDragLeave:Je.func,onDragOver:Je.func,onDrop:Je.func,onDropAccepted:Je.func,onDropRejected:Je.func,onError:Je.func,validator:Je.func};var fr={isFocused:!1,isFileDialogActive:!1,isDragActive:!1,isDragAccept:!1,isDragReject:!1,acceptedFiles:[],fileRejections:[]};function Lr(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=Ye(Ye({},Ba),t),a=r.accept,o=r.disabled,n=r.getFilesFromEvent,l=r.maxSize,i=r.minSize,c=r.multiple,u=r.maxFiles,g=r.onDragEnter,x=r.onDragLeave,f=r.onDragOver,b=r.onDrop,N=r.onDropAccepted,y=r.onDropRejected,p=r.onFileDialogCancel,w=r.onFileDialogOpen,h=r.useFsAccessApi,S=r.autoFocus,m=r.preventDropOnDocument,v=r.noClick,j=r.noKeyboard,W=r.noDrag,I=r.noDragEventsBubbling,O=r.onError,A=r.validator,T=s.useMemo(function(){return pi(a)},[a]),M=s.useMemo(function(){return xi(a)},[a]),B=s.useMemo(function(){return typeof w=="function"?w:ua},[w]),_=s.useMemo(function(){return typeof p=="function"?p:ua},[p]),ce=s.useRef(null),V=s.useRef(null),ee=s.useReducer(Li,fr),ne=sr(ee,2),ve=ne[0],ye=ne[1],xe=ve.isFocused,ke=ve.isFileDialogActive,Ee=s.useRef(typeof window<"u"&&window.isSecureContext&&h&&ui()),Me=function(){!Ee.current&&ke&&setTimeout(function(){if(V.current){var F=V.current.files;F.length||(ye({type:"closeDialog"}),_())}},300)};s.useEffect(function(){return window.addEventListener("focus",Me,!1),function(){window.removeEventListener("focus",Me,!1)}},[V,ke,_,Ee]);var _e=s.useRef([]),Be=function(F){ce.current&&ce.current.contains(F.target)||(F.preventDefault(),_e.current=[])};s.useEffect(function(){return m&&(document.addEventListener("dragover",da,!1),document.addEventListener("drop",Be,!1)),function(){m&&(document.removeEventListener("dragover",da),document.removeEventListener("drop",Be))}},[ce,m]),s.useEffect(function(){return!o&&S&&ce.current&&ce.current.focus(),function(){}},[ce,S,o]);var Q=s.useCallback(function(C){O?O(C):console.error(C)},[O]),Se=s.useCallback(function(C){C.preventDefault(),C.persist(),te(C),_e.current=[].concat(ji(_e.current),[C.target]),Cs(C)&&Promise.resolve(n(C)).then(function(F){if(!(As(C)&&!I)){var de=F.length,pe=de>0&&li({files:F,accept:T,minSize:i,maxSize:l,multiple:c,maxFiles:u,validator:A}),P=de>0&&!pe;ye({isDragAccept:pe,isDragReject:P,isDragActive:!0,type:"setDraggedFiles"}),g&&g(C)}}).catch(function(F){return Q(F)})},[n,g,Q,I,T,i,l,c,u,A]),Fe=s.useCallback(function(C){C.preventDefault(),C.persist(),te(C);var F=Cs(C);if(F&&C.dataTransfer)try{C.dataTransfer.dropEffect="copy"}catch{}return F&&f&&f(C),!1},[f,I]),Ne=s.useCallback(function(C){C.preventDefault(),C.persist(),te(C);var F=_e.current.filter(function(pe){return ce.current&&ce.current.contains(pe)}),de=F.indexOf(C.target);de!==-1&&F.splice(de,1),_e.current=F,!(F.length>0)&&(ye({type:"setDraggedFiles",isDragActive:!1,isDragAccept:!1,isDragReject:!1}),Cs(C)&&x&&x(C))},[ce,x,I]),Le=s.useCallback(function(C,F){var de=[],pe=[];C.forEach(function(P){var ae=za(P,T),ue=sr(ae,2),le=ue[0],k=ue[1],X=Oa(P,i,l),se=sr(X,2),fe=se[0],J=se[1],Re=A?A(P):null;if(le&&fe&&!Re)de.push(P);else{var $=[k,J];Re&&($=$.concat(Re)),pe.push({file:P,errors:$.filter(function(we){return we})})}}),(!c&&de.length>1||c&&u>=1&&de.length>u)&&(de.forEach(function(P){pe.push({file:P,errors:[ii]})}),de.splice(0)),ye({acceptedFiles:de,fileRejections:pe,isDragReject:pe.length>0,type:"setFiles"}),b&&b(de,pe,F),pe.length>0&&y&&y(pe,F),de.length>0&&N&&N(de,F)},[ye,c,T,i,l,u,b,N,y,A]),Te=s.useCallback(function(C){C.preventDefault(),C.persist(),te(C),_e.current=[],Cs(C)&&Promise.resolve(n(C)).then(function(F){As(C)&&!I||Le(F,C)}).catch(function(F){return Q(F)}),ye({type:"reset"})},[n,Le,Q,I]),ze=s.useCallback(function(){if(Ee.current){ye({type:"openDialog"}),B();var C={multiple:c,types:M};window.showOpenFilePicker(C).then(function(F){return n(F)}).then(function(F){Le(F,null),ye({type:"closeDialog"})}).catch(function(F){hi(F)?(_(F),ye({type:"closeDialog"})):fi(F)?(Ee.current=!1,V.current?(V.current.value=null,V.current.click()):Q(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."))):Q(F)});return}V.current&&(ye({type:"openDialog"}),B(),V.current.value=null,V.current.click())},[ye,B,_,h,Le,Q,M,c]),Ce=s.useCallback(function(C){!ce.current||!ce.current.isEqualNode(C.target)||(C.key===" "||C.key==="Enter"||C.keyCode===32||C.keyCode===13)&&(C.preventDefault(),ze())},[ce,ze]),He=s.useCallback(function(){ye({type:"focus"})},[]),Ve=s.useCallback(function(){ye({type:"blur"})},[]),je=s.useCallback(function(){v||(mi()?setTimeout(ze,0):ze())},[v,ze]),Ae=function(F){return o?null:F},q=function(F){return j?null:Ae(F)},oe=function(F){return W?null:Ae(F)},te=function(F){I&&F.stopPropagation()},Ie=s.useMemo(function(){return function(){var C=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},F=C.refKey,de=F===void 0?"ref":F,pe=C.role,P=C.onKeyDown,ae=C.onFocus,ue=C.onBlur,le=C.onClick,k=C.onDragEnter,X=C.onDragOver,se=C.onDragLeave,fe=C.onDrop,J=Rs(C,vi);return Ye(Ye(hr({onKeyDown:q(ht(P,Ce)),onFocus:q(ht(ae,He)),onBlur:q(ht(ue,Ve)),onClick:Ae(ht(le,je)),onDragEnter:oe(ht(k,Se)),onDragOver:oe(ht(X,Fe)),onDragLeave:oe(ht(se,Ne)),onDrop:oe(ht(fe,Te)),role:typeof pe=="string"&&pe!==""?pe:"presentation"},de,ce),!o&&!j?{tabIndex:0}:{}),J)}},[ce,Ce,He,Ve,je,Se,Fe,Ne,Te,j,W,o]),G=s.useCallback(function(C){C.stopPropagation()},[]),re=s.useMemo(function(){return function(){var C=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},F=C.refKey,de=F===void 0?"ref":F,pe=C.onChange,P=C.onClick,ae=Rs(C,yi),ue=hr({accept:T,multiple:c,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:Ae(ht(pe,Te)),onClick:Ae(ht(P,G)),tabIndex:-1},de,V);return Ye(Ye({},ue),ae)}},[V,a,c,Te,o]);return Ye(Ye({},ve),{},{isFocused:xe&&!o,getRootProps:Ie,getInputProps:re,rootRef:ce,inputRef:V,open:Ae(ze)})}function Li(t,r){switch(r.type){case"focus":return Ye(Ye({},t),{},{isFocused:!0});case"blur":return Ye(Ye({},t),{},{isFocused:!1});case"openDialog":return Ye(Ye({},fr),{},{isFileDialogActive:!0});case"closeDialog":return Ye(Ye({},t),{},{isFileDialogActive:!1});case"setDraggedFiles":return Ye(Ye({},t),{},{isDragActive:r.isDragActive,isDragAccept:r.isDragAccept,isDragReject:r.isDragReject});case"setFiles":return Ye(Ye({},t),{},{acceptedFiles:r.acceptedFiles,fileRejections:r.fileRejections,isDragReject:r.isDragReject});case"reset":return Ye({},fr);default:return t}}function ua(){}const rr=({todos:t,isResult:r=!1})=>{if(!t||!Array.isArray(t))return null;const a=l=>{switch(l){case"completed":return e.jsx(On,{className:"w-4 h-4 text-green-500 dark:text-green-400"});case"in_progress":return e.jsx(bs,{className:"w-4 h-4 text-blue-500 dark:text-blue-400"});case"pending":default:return e.jsx(zn,{className:"w-4 h-4 text-gray-400 dark:text-gray-500"})}},o=l=>{switch(l){case"completed":return"bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-200 border-green-200 dark:border-green-800";case"in_progress":return"bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-200 border-blue-200 dark:border-blue-800";case"pending":default:return"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700"}},n=l=>{switch(l){case"high":return"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 border-red-200 dark:border-red-800";case"medium":return"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800";case"low":default:return"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700"}};return e.jsxs("div",{className:"space-y-3",children:[r&&e.jsxs("div",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-3",children:["待办事项列表 (",t.length," 项)"]}),t.map((l,i)=>e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm hover:shadow-md dark:shadow-gray-900/50 transition-shadow",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:a(l.status)}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsx("p",{className:`text-sm font-medium ${l.status==="completed"?"line-through text-gray-500 dark:text-gray-400":"text-gray-900 dark:text-gray-100"}`,children:l.content}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx(Qe,{variant:"outline",className:`text-xs px-2 py-0.5 ${n(l.priority)}`,children:l.priority}),e.jsx(Qe,{variant:"outline",className:`text-xs px-2 py-0.5 ${o(l.status)}`,children:l.status.replace("_"," ")})]})]})})]},l.id||`todo-${i}`))]})},Ps=({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:"AgentHub",className:t,style:a})};function Ii({status:t,onAbort:r,isLoading:a,provider:o="claude"}){const[n,l]=s.useState(0),[i,c]=s.useState(0),[u,g]=s.useState(0);if(s.useEffect(()=>{if(!a){l(0),g(0);return}const h=Date.now(),S=30+Math.random()*20,m=setInterval(()=>{const v=Math.floor((Date.now()-h)/1e3);l(v),g(Math.floor(v*S))},1e3);return()=>clearInterval(m)},[a]),s.useEffect(()=>{if(!a)return;const h=setInterval(()=>{c(S=>(S+1)%4)},500);return()=>clearInterval(h)},[a]),!a)return null;const x=["思考中","处理中","分析中","工作中","计算中","推理中"],f=Math.floor(n/3)%x.length,b=t?.text||x[f],N=t?.tokens||u,y=t?.can_interrupt!==!1,w=["✻","✹","✸","✶"][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:Xe("text-base sm:text-xl transition-all duration-500 flex-shrink-0",i%2===0?"text-blue-400 scale-110":"text-blue-300"),children:w}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[e.jsxs("span",{className:"font-medium text-xs sm:text-sm truncate",children:[b,"..."]}),e.jsxs("span",{className:"text-gray-400 text-xs sm:text-sm flex-shrink-0",children:["(",n,"s)"]}),N>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:["⚒ ",N.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 停止"})]})})]})}),y&&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 Di(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 Ti({onTranscript:t,className:r=""}){const[a,o]=s.useState("idle"),[n,l]=s.useState(null),[i,c]=s.useState(!0),u=s.useRef(null),g=s.useRef(null),x=s.useRef([]),f=s.useRef(0);s.useEffect(()=>{(()=>{if(!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia){c(!1),l("Microphone not supported. Please use HTTPS or a modern browser.");return}if(location.protocol!=="https:"&&location.hostname!=="localhost"){c(!1),l("Microphone requires HTTPS. Please use a secure connection.");return}c(!0),l(null)})()},[]);const b=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});g.current=m;const v=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",j=new MediaRecorder(m,{mimeType:v});u.current=j,j.ondataavailable=W=>{W.data.size>0&&x.current.push(W.data)},j.onstop=async()=>{console.log("Recording stopped, creating blob...");const W=new Blob(x.current,{type:v});g.current&&(g.current.getTracks().forEach(T=>T.stop()),g.current=null),o("transcribing");const I=window.localStorage.getItem("whisperMode")||"default",O=I==="prompt"||I==="vibe"||I==="instructions"||I==="architect";let A;O&&(A=setTimeout(()=>{o("processing")},2e3));try{const T=await Di(W);T&&t&&t(T)}catch(T){console.error("Transcription error:",T),l(T.message)}finally{A&&clearTimeout(A),o("idle")}},j.start(),o("recording"),console.log("Recording started successfully")}catch(m){console.error("Failed to start recording:",m);let v="Microphone access failed";m.name==="NotAllowedError"?v="Microphone access denied. Please allow microphone permissions.":m.name==="NotFoundError"?v="No microphone found. Please check your audio devices.":m.name==="NotSupportedError"?v="Microphone not supported by this browser.":m.name==="NotReadableError"?v="Microphone is being used by another application.":m.message.includes("HTTPS")&&(v=m.message),l(v),o("idle")}},N=()=>{console.log("Stopping recording..."),u.current&&u.current.state==="recording"?u.current.stop():(console.log("Recorder not in recording state, forcing cleanup"),g.current&&(g.current.getTracks().forEach(m=>m.stop()),g.current=null),o("idle"))},y=m=>{if(m&&(m.preventDefault(),m.stopPropagation()),!i)return;const v=Date.now();if(v-f.current<300){console.log("Ignoring rapid tap");return}f.current=v,console.log("Button clicked, current state:",a),a==="idle"?b():a==="recording"&&N()};s.useEffect(()=>()=>{g.current&&g.current.getTracks().forEach(m=>m.stop())},[]);const p=()=>{if(!i)return{icon:e.jsx(Ys,{className:"w-5 h-5"}),className:"bg-gray-400 cursor-not-allowed",disabled:!0};switch(a){case"recording":return{icon:e.jsx(Ys,{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(Tt,{className:"w-5 h-5 animate-spin"}),className:"bg-blue-500 hover:bg-blue-600",disabled:!0};case"processing":return{icon:e.jsx(Fn,{className:"w-5 h-5 animate-pulse"}),className:"bg-purple-500 hover:bg-purple-600",disabled:!0};default:return{icon:e.jsx(Ys,{className:"w-5 h-5"}),className:"bg-gray-700 hover:bg-gray-600",disabled:!1}}},{icon:w,className:h,disabled:S}=p();return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",style:{backgroundColor:a==="recording"?"#ef4444":a==="transcribing"?"#3b82f6":a==="processing"?"#a855f7":"#374151"},className:`
6
- flex items-center justify-center
7
- w-12 h-12 rounded-full
8
- text-white transition-all duration-200
9
- focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500
10
- dark:ring-offset-gray-800
11
- touch-action-manipulation
12
- ${S?"cursor-not-allowed opacity-75":"cursor-pointer"}
13
- ${a==="recording"?"animate-pulse":""}
14
- hover:opacity-90
15
- ${r}
16
- `,onClick:y,disabled:S,children:w}),n&&e.jsx("div",{className:`absolute top-full mt-2 left-1/2 transform -translate-x-1/2
17
- bg-red-500 text-white text-xs px-2 py-1 rounded whitespace-nowrap z-10
18
- animate-fade-in`,children:n}),a==="recording"&&e.jsx("div",{className:"absolute -inset-1 rounded-full border-2 border-red-500 animate-ping pointer-events-none"}),a==="processing"&&e.jsx("div",{className:"absolute -inset-1 rounded-full border-2 border-purple-500 animate-ping pointer-events-none"})]})}const Ai=({commands:t=[],selectedIndex:r=-1,onSelect:a,onClose:o,position:n={top:0,left:0},isOpen:l=!1,frequentCommands:i=[]})=>{const c=s.useRef(null),u=s.useRef(null),x=(()=>{const S=window.innerWidth<640,m=window.innerHeight;return S?{position:"fixed",bottom:`${n.bottom||90}px`,left:"16px",right:"16px",width:"auto",maxWidth:"calc(100vw - 32px)",maxHeight:"min(50vh, 300px)"}:{position:"fixed",top:`${Math.max(16,Math.min(n.top,m-316))}px`,left:`${n.left}px`,width:"min(400px, calc(100vw - 32px))",maxWidth:"calc(100vw - 32px)",maxHeight:"300px"}})();if(s.useEffect(()=>{const S=m=>{c.current&&!c.current.contains(m.target)&&l&&o()};if(l)return document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[l,o]),s.useEffect(()=>{if(u.current&&c.current){const S=c.current.getBoundingClientRect(),m=u.current.getBoundingClientRect();m.bottom>S.bottom?u.current.scrollIntoView({block:"nearest",behavior:"smooth"}):m.top<S.top&&u.current.scrollIntoView({block:"nearest",behavior:"smooth"})}},[r]),!l)return null;if(t.length===0)return e.jsx("div",{ref:c,className:"command-menu command-menu-empty",style:{...x,maxHeight:"300px",borderRadius:"8px",boxShadow:"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",zIndex:1e3,padding:"20px",opacity:1,transform:"translateY(0)",transition:"opacity 150ms ease-in-out, transform 150ms ease-in-out",textAlign:"center"},children:"暂无可用命令"});const f=i.length>0,b=t.reduce((S,m)=>{const v=m.namespace||m.type||"other";return S[v]||(S[v]=[]),S[v].push(m),S},{});f&&(b.frequent=i);const y=(f?["frequent","builtin","project","user","other"]:["builtin","project","user","other"]).filter(S=>b[S]),p={frequent:"⭐ 常用命令",builtin:"内置命令",project:"项目命令",user:"用户命令",other:"其他命令"};let w=0;const h=[];return y.forEach(S=>{b[S].forEach(m=>{h.push({...m,globalIndex:w++,namespace:S})})}),e.jsxs("div",{ref:c,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:[y.map(S=>e.jsxs("div",{className:"command-group",children:[y.length>1&&e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"#6b7280",padding:"8px 12px 4px",letterSpacing:"0.05em"},children:p[S]||S}),b[S].map(m=>{const v=h.find(W=>W.name===m.name&&W.namespace===S),j=v&&v.globalIndex===r;return e.jsxs("div",{ref:j?u:null,role:"option","aria-selected":j,className:"command-item",onMouseEnter:()=>a&&a(m,v.globalIndex,!0),onClick:()=>a&&a(m,v.globalIndex,!1),style:{display:"flex",alignItems:"flex-start",padding:"10px 12px",borderRadius:"6px",cursor:"pointer",backgroundColor:j?"#eff6ff":"transparent",transition:"background-color 100ms ease-in-out",marginBottom:"2px"},onMouseDown:W=>W.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:[S==="builtin"&&"⚡",S==="project"&&"📁",S==="user"&&"👤",S==="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})]}),j&&e.jsx("span",{style:{marginLeft:"8px",color:"#3b82f6",fontSize:"12px",fontWeight:600},children:"↵"})]},`${S}-${m.name}`)})]},S)),e.jsx("style",{children:`
19
- .command-menu {
20
- background-color: white;
21
- border: 1px solid #e5e7eb;
22
- }
23
- .command-menu-empty {
24
- color: #6b7280;
25
- }
26
-
27
- @media (prefers-color-scheme: dark) {
28
- .command-menu {
29
- background-color: #1f2937 !important;
30
- border: 1px solid #374151 !important;
31
- }
32
- .command-menu-empty {
33
- color: #9ca3af !important;
34
- }
35
- .command-item[aria-selected="true"] {
36
- background-color: #1e40af !important;
37
- }
38
- .command-item span:not(.command-metadata-badge) {
39
- color: #f3f4f6 !important;
40
- }
41
- .command-metadata-badge {
42
- background-color: #f3f4f6 !important;
43
- color: #6b7280 !important;
44
- }
45
- .command-item div {
46
- color: #d1d5db !important;
47
- }
48
- .command-group > div:first-child {
49
- color: #9ca3af !important;
50
- }
51
- }
52
- `})]})},ar={OPTIONS:[{value:"sonnet",label:"Sonnet"},{value:"opus",label:"Opus"},{value:"haiku",label:"Haiku"}],DEFAULT:"sonnet"};function Zt(t){return t&&t.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&amp;/g,"&")}function Ri(t){if(!t||typeof t!="string")return t;try{return t.replace(/```\s*([^\n\r]+?)\s*```/g,"`$1`")}catch{return t}}function nr(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,`
53
- `).replace(/\\t/g," ").replace(/\\r/g,"\r"),n=n.replace(new RegExp(`${a}(\\d+)${o}`,"g"),(l,i)=>r[parseInt(i)]),n}const us=({children:t,className:r})=>{const a=Ri(String(t??"")),o=s.useMemo(()=>[oo,io],[]),n=s.useMemo(()=>[lo],[]);return e.jsx("div",{className:r,children:e.jsx(co,{remarkPlugins:o,rehypePlugins:n,components:_i,children:a})})};function gr(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(),c=i>=0?"+":"-",u=Math.abs(i),g=Math.floor(u/60),x=u%60,f=`GMT${c}${g}${x?":"+String(x).padStart(2,"0"):""}`,y=((Intl.DateTimeFormat().resolvedOptions().timeZone||"").split("/").pop()||"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,S=>S.toUpperCase()),p=y?`${f} (${y})`:f,w=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=`${n.getDate()} ${w[n.getMonth()]} ${n.getFullYear()}`;return`Claude usage limit reached. Your limit will reset at **${l} ${p}** - ${h}`})}catch{return t}}const at={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 c=JSON.parse(r);if(Array.isArray(c)&&c.length>10){const u=c.slice(-10);localStorage.setItem(t,JSON.stringify(u)),console.warn("Saved only last 10 messages due to quota constraints")}}catch(c){console.error("Final save attempt failed:",c)}}}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)}}},Ha="claude-settings";function Ir(){const t=at.getItem(Ha);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 br(t,r){if(!t)return null;if(t!=="Bash")return t;const a=vo(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 xa(t){if(t==null)return"";if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function Pi(t,r){if(r!=="claude"||!t?.toolResult?.isError)return null;const a=t?.toolName,o=br(a,t.toolInput);if(!o)return null;const l=Ir().allowedTools.includes(o);return{toolName:a,entry:o,isAllowed:l}}function $i(t){if(!t)return{success:!1};const r=Ir(),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 at.setItem(Ha,JSON.stringify(l)),{success:!0,alreadyAllowed:a,updatedSettings:l}}const _i={code:({node:t,inline:r,className:a,children:o,...n})=>{const[l,i]=ft.useState(!1),c=Array.isArray(o)?o.join(""):String(o??""),u=/[\r\n]/.test(c);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 f=/language-(\w+)/.exec(a||""),b=f?f[1]:"text",N=c,y=()=>{const p=()=>{i(!0),setTimeout(()=>i(!1),1500)};try{if(navigator&&navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(N).then(p).catch(()=>{const w=document.createElement("textarea");w.value=N,w.style.position="fixed",w.style.opacity="0",document.body.appendChild(w),w.select();try{document.execCommand("copy")}catch{}document.body.removeChild(w),p()});else{const w=document.createElement("textarea");w.value=N,w.style.position="fixed",w.style.opacity="0",document.body.appendChild(w),w.select();try{document.execCommand("copy")}catch{}document.body.removeChild(w),p()}}catch{}};return e.jsxs("div",{className:"relative group my-2",children:[b&&b!=="text"&&e.jsx("div",{className:"absolute top-2 left-3 z-10 text-xs text-gray-400 font-medium uppercase",children:b}),e.jsx("button",{type:"button",onClick:y,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(mo,{language:b,style:Io,customStyle:{margin:0,borderRadius:"0.5rem",fontSize:"0.875rem",padding:b&&b!=="text"?"2rem 1rem 1rem 1rem":"1rem"},codeTagProps:{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'}},children:c})]})},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 zi({request:t,onSubmit:r,onSkip:a}){const o=t.input?.questions||[],[n,l]=ft.useState(()=>Object.fromEntries(o.map(g=>[g.question,[]]))),i=(g,x,f)=>{l(b=>{const N=b[g]||[];return f?{...b,[g]:N.includes(x)?N.filter(y=>y!==x):[...N,x]}:{...b,[g]:[x]}})},c=o.every(g=>(n[g.question]||[]).length>0),u=()=>{const g={};o.forEach(x=>{g[x.question]=(n[x.question]||[]).join(", ")}),r(g)};return e.jsxs("div",{className:"rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 p-3 shadow-sm",children:[e.jsx("div",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100 mb-3",children:"Claude 需要您的回答"}),o.map((g,x)=>e.jsxs("div",{className:x<o.length-1?"mb-4":"mb-0",children:[e.jsxs("div",{className:"text-sm font-medium text-blue-800 dark:text-blue-200 mb-2",children:[g.question,g.multiSelect&&e.jsx("span",{className:"ml-2 text-xs font-normal opacity-60",children:"(可多选)"})]}),e.jsx("div",{className:"space-y-1",children:g.options.map((f,b)=>{const N=(n[g.question]||[]).includes(f.label);return e.jsxs("button",{type:"button",onClick:()=>i(g.question,f.label,g.multiSelect),className:`w-full text-left px-3 py-2 rounded-md text-xs border transition-colors ${N?"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:f.label}),f.description&&e.jsxs("span",{className:"ml-1 opacity-70",children:[" — ",f.description]})]},b)})})]},x)),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx("button",{type:"button",onClick:u,disabled:!c,className:"inline-flex items-center gap-2 rounded-md bg-blue-600 text-white text-xs font-medium px-3 py-1.5 hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:"提交答案"}),e.jsx("button",{type:"button",onClick:a,className:"inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border border-gray-300 text-gray-600 hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800/30 transition-colors",children:"跳过"})]})]})}const Ja=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 c=!1;return i(!0),K(`/api/images/${t.id}`).then(u=>{if(!u.ok)throw new Error("expired");return u.blob()}).then(u=>{c||(a(URL.createObjectURL(u)),i(!1))}).catch(()=>{c||(n(!0),i(!1))}),()=>{c=!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});Ja.displayName="PersistentImage";const pa=s.memo(({message:t,index:r,prevMessage:a,createDiff:o,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,selectedProject:c,provider:u})=>{const g=a&&a.type===t.type&&(a.type==="assistant"||a.type==="user"||a.type==="tool"||a.type==="error"),x=ft.useRef(null),f=Pi(t,u),[b,N]=ft.useState("idle");return ft.useEffect(()=>{N("idle")},[f?.entry,t.toolId]),e.jsx("div",{ref:x,className:`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((y,p)=>e.jsx(Ja,{image:y},y.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(Ps,{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"?"工具":"AgentHub"})]}),e.jsxs("div",{className:"w-full",children:[t.isToolUse&&!["Read","TodoWrite","TodoRead"].includes(t.toolName)?["Grep","Glob"].includes(t.toolName)?e.jsx(e.Fragment,{children:e.jsx("div",{className:"group relative bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-blue-400 dark:border-blue-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400 flex-1 min-w-0",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-blue-500 dark:text-blue-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),e.jsx("span",{className:"font-medium flex-shrink-0",children:t.toolName}),e.jsx("span",{className:"text-gray-400 dark:text-gray-500 flex-shrink-0",children:"•"}),t.toolInput&&(()=>{try{const p=JSON.parse(t.toolInput);return e.jsxs("span",{className:"font-mono truncate flex-1 min-w-0",children:[p.pattern&&e.jsxs("span",{children:["pattern: ",e.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:p.pattern})]}),p.path&&e.jsxs("span",{className:"ml-2",children:["in: ",qe(p.path)]})]})}catch{return null}})()]}),t.toolResult&&e.jsxs("a",{href:`#tool-result-${t.toolId}`,className:"flex-shrink-0 text-xs text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 font-medium transition-colors flex items-center gap-1",children:[e.jsx("span",{children:"结果"}),e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]})})}):e.jsxs("div",{className:"group relative bg-gradient-to-br from-blue-50/50 to-indigo-50/50 dark:from-blue-950/20 dark:to-indigo-950/20 border border-blue-100/30 dark:border-blue-800/30 rounded-lg p-3 mb-2",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500/3 to-indigo-500/3 dark:from-blue-400/3 dark:to-indigo-400/3 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity duration-300"}),e.jsxs("div",{className:"relative flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative w-8 h-8 bg-gradient-to-br from-blue-500 to-indigo-600 dark:from-blue-400 dark:to-indigo-500 rounded-lg flex items-center justify-center shadow-lg shadow-blue-500/20 dark:shadow-blue-400/20",children:[e.jsxs("svg",{className:"w-4 h-4 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),e.jsx("div",{className:"absolute inset-0 rounded-lg bg-blue-500 dark:bg-blue-400 animate-pulse opacity-20"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-semibold text-gray-900 dark:text-white text-sm",children:t.toolName}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-mono",children:t.toolId})]})]}),l&&e.jsx("button",{onClick:p=>{p.stopPropagation(),l()},className:"p-2 rounded-lg hover:bg-white/60 dark:hover:bg-gray-800/60 transition-all duration-200 group/btn backdrop-blur-sm",title:"工具设置",children:e.jsxs("svg",{className:"w-4 h-4 text-gray-600 dark:text-gray-400 group-hover/btn:text-blue-600 dark:group-hover/btn:text-blue-400 transition-colors",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]}),t.toolInput&&t.toolName==="Edit"&&(()=>{try{const p=JSON.parse(t.toolInput);if(p.file_path&&p.old_string&&p.new_string)return e.jsxs("details",{className:"relative mt-3 group/details",open:!1,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/details:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),e.jsx("span",{className:"flex items-center gap-2",children:e.jsx("span",{children:"查看编辑差异"})}),e.jsx("button",{onClick:async w=>{if(w.preventDefault(),w.stopPropagation(),!!n)try{const h=await he.readFile(c?.name,p.file_path),S=await h.json();if(!h.ok||S.error){console.error("Failed to fetch file:",S.error),n(p.file_path);return}const m=S.content||"",v=m.replace(p.new_string,p.old_string);n(p.file_path,{old_string:v,new_string:m})}catch(h){console.error("Error preparing diff:",h),n(p.file_path)}},className:"px-2.5 py-1 rounded-md bg-white/60 dark:bg-gray-800/60 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/30 font-mono text-xs font-medium transition-all duration-200 shadow-sm",children:p.file_path.split("/").pop()})]}),e.jsx("div",{className:"mt-3 pl-6",children:e.jsxs("div",{className:"bg-white dark:bg-gray-900/50 border border-gray-200/60 dark:border-gray-700/60 rounded-lg overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 bg-gradient-to-r from-gray-50 to-gray-100/50 dark:from-gray-800/80 dark:to-gray-800/40 border-b border-gray-200/60 dark:border-gray-700/60 backdrop-blur-sm",children:[e.jsx("button",{onClick:async()=>{if(n)try{const w=await he.readFile(c?.name,p.file_path),h=await w.json();if(!w.ok||h.error){console.error("Failed to fetch file:",h.error),n(p.file_path);return}const S=h.content||"",m=S.replace(p.new_string,p.old_string);n(p.file_path,{old_string:m,new_string:S})}catch(w){console.error("Error preparing diff:",w),n(p.file_path)}},className:"text-xs font-mono text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 truncate cursor-pointer font-medium transition-colors",children:qe(p.file_path)}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-medium px-2 py-0.5 bg-gray-100 dark:bg-gray-700/50 rounded",children:"Diff"})]}),e.jsx("div",{className:"text-xs font-mono",children:o(p.old_string,p.new_string).map((w,h)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${w.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:w.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${w.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:w.content})]},h))})]})})]})}catch{}return e.jsxs("details",{className:"relative mt-3 group/params",open:!1,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/params:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看输入参数"]}),e.jsx("pre",{className:"mt-3 text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-3 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-700 dark:text-gray-300 font-mono",children:qe(t.toolInput)})]})})(),t.toolInput&&t.toolName!=="Edit"&&(()=>{if(t.toolName==="Write")try{let p;if(typeof t.toolInput=="string"?p=JSON.parse(t.toolInput):p=t.toolInput,p.file_path&&p.content!==void 0)return e.jsxs("details",{className:"relative mt-3 group/details",open:!1,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/details:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg leading-none",children:"📄"}),e.jsx("span",{children:"创建新文件:"})]}),e.jsx("button",{onClick:async w=>{if(w.preventDefault(),w.stopPropagation(),!!n)try{const h=await he.readFile(c?.name,p.file_path),S=await h.json(),m=h.ok&&!S.error?S.content||"":p.content||"";n(p.file_path,{old_string:"",new_string:m})}catch(h){console.error("Error preparing diff:",h),n(p.file_path,{old_string:"",new_string:p.content||""})}},className:"px-2.5 py-1 rounded-md bg-white/60 dark:bg-gray-800/60 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/30 font-mono text-xs font-medium transition-all duration-200 shadow-sm",children:p.file_path.split("/").pop()})]}),e.jsx("div",{className:"mt-3 pl-6",children:e.jsxs("div",{className:"bg-white dark:bg-gray-900/50 border border-gray-200/60 dark:border-gray-700/60 rounded-lg overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 bg-gradient-to-r from-gray-50 to-gray-100/50 dark:from-gray-800/80 dark:to-gray-800/40 border-b border-gray-200/60 dark:border-gray-700/60 backdrop-blur-sm",children:[e.jsx("button",{onClick:async()=>{if(n)try{const w=await he.readFile(c?.name,p.file_path),h=await w.json(),S=w.ok&&!h.error?h.content||"":p.content||"";n(p.file_path,{old_string:"",new_string:S})}catch(w){console.error("Error preparing diff:",w),n(p.file_path,{old_string:"",new_string:p.content||""})}},className:"text-xs font-mono text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 truncate cursor-pointer font-medium transition-colors",children:qe(p.file_path)}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 font-medium px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded",children:"新文件"})]}),e.jsx("div",{className:"text-xs font-mono",children:o("",p.content).map((w,h)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:`w-8 text-center border-r ${w.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:w.type==="removed"?"-":"+"}),e.jsx("span",{className:`px-2 py-0.5 flex-1 whitespace-pre-wrap ${w.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:w.content})]},h))})]})})]})}catch{}if(t.toolName==="TodoWrite")try{const p=JSON.parse(t.toolInput);if(p.todos&&Array.isArray(p.todos))return e.jsxs("details",{className:"relative mt-3 group/todo",open:!1,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/todo:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg leading-none",children:"✓"}),e.jsx("span",{children:"更新待办列表"})]})]}),e.jsx("div",{className:"mt-3",children:e.jsx(rr,{todos:p.todos})})]})}catch{}if(t.toolName==="Bash")try{const p=JSON.parse(t.toolInput);return e.jsxs("div",{className:"my-2",children:[e.jsxs("div",{className:"bg-gray-900 dark:bg-gray-950 rounded-md px-3 py-2 font-mono text-sm",children:[e.jsx("span",{className:"text-green-400",children:"$"}),e.jsx("span",{className:"text-gray-100 ml-2",children:qe(p.command)})]}),p.description&&e.jsx("div",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400 italic ml-1",children:p.description})]})}catch{}if(t.toolName==="Read")try{const p=JSON.parse(t.toolInput);if(p.file_path){const w=p.file_path.split("/").pop();return e.jsxs("div",{className:"mt-2 text-sm text-blue-700 dark:text-blue-300",children:["Read"," ",e.jsx("button",{onClick:()=>n&&n(p.file_path),className:"text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline font-mono",children:w})]})}}catch{}if(t.toolName==="exit_plan_mode")try{const p=JSON.parse(t.toolInput);if(p.plan){const w=p.plan.replace(/\\n/g,`
54
- `);return e.jsxs("details",{className:"mt-2",open:!1,children:[e.jsxs("summary",{className:"text-sm text-blue-700 dark:text-blue-300 cursor-pointer hover:text-blue-800 dark:hover:text-blue-200 flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform details-chevron",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"📋 查看实现计划"]}),e.jsx(us,{className:"mt-3 prose prose-sm max-w-none dark:prose-invert",children:w})]})}}catch{}return e.jsxs("details",{className:"relative mt-3 group/params",open:!1,children:[e.jsxs("summary",{className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors duration-200 p-2.5 rounded-lg hover:bg-white/50 dark:hover:bg-gray-800/50",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform duration-200 group-open/params:rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看输入参数"]}),e.jsx("pre",{className:"mt-3 text-xs bg-gray-50 dark:bg-gray-800/50 border border-gray-200/60 dark:border-gray-700/60 p-3 rounded-lg whitespace-pre-wrap break-words overflow-hidden text-gray-700 dark:text-gray-300 font-mono",children:qe(t.toolInput)})]})})(),t.toolResult&&(!t.toolResult.isError&&(t.toolName==="Edit"||t.toolName==="Write"||t.toolName==="ApplyPatch"||t.toolName==="Bash")?null:e.jsxs("div",{id:`tool-result-${t.toolId}`,className:`relative mt-4 p-4 rounded-lg border backdrop-blur-sm scroll-mt-4 ${t.toolResult.isError?"bg-gradient-to-br from-red-50 to-rose-50 dark:from-red-950/20 dark:to-rose-950/20 border-red-200/60 dark:border-red-800/60":"bg-gradient-to-br from-green-50 to-emerald-50 dark:from-green-950/20 dark:to-emerald-950/20 border-green-200/60 dark:border-green-800/60"}`,children:[e.jsx("div",{className:`absolute inset-0 rounded-lg opacity-50 ${t.toolResult.isError?"bg-gradient-to-br from-red-500/5 to-rose-500/5 dark:from-red-400/5 dark:to-rose-400/5":"bg-gradient-to-br from-green-500/5 to-emerald-500/5 dark:from-green-400/5 dark:to-emerald-400/5"}`}),e.jsxs("div",{className:"relative flex items-center gap-2.5 mb-3",children:[e.jsx("div",{className:`w-6 h-6 rounded-lg flex items-center justify-center shadow-md ${t.toolResult.isError?"bg-gradient-to-br from-red-500 to-rose-600 dark:from-red-400 dark:to-rose-500 shadow-red-500/20":"bg-gradient-to-br from-green-500 to-emerald-600 dark:from-green-400 dark:to-emerald-500 shadow-green-500/20"}`,children:e.jsx("svg",{className:"w-3.5 h-3.5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.toolResult.isError?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M6 18L18 6M6 6l12 12"}):e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:`text-sm font-semibold ${t.toolResult.isError?"text-red-800 dark:text-red-200":"text-green-800 dark:text-green-200"}`,children:t.toolResult.isError?"工具错误":"工具结果"})]}),e.jsxs("div",{className:`relative text-sm ${t.toolResult.isError?"text-red-900 dark:text-red-100":"text-green-900 dark:text-green-100"}`,children:[(()=>{const w=qe(String(t.toolResult.content||""));if((t.toolName==="TodoWrite"||t.toolName==="TodoRead")&&(w.includes("Todos have been modified successfully")||w.includes("Todo list")||w.startsWith("[")&&w.includes('"content"')&&w.includes('"status"')))try{let m=null;if(w.startsWith("["))m=JSON.parse(w);else if(w.includes("Todos have been modified successfully"))return e.jsx("div",{children:e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"font-medium",children:"待办列表已更新成功"})})});if(m&&Array.isArray(m))return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("span",{className:"font-medium",children:"当前待办列表"})}),e.jsx(rr,{todos:m,isResult:!0})]})}catch{}if(t.toolName==="exit_plan_mode")try{const m=JSON.parse(w);if(m.plan){const v=m.plan.replace(/\\n/g,`
55
- `);return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("span",{className:"font-medium",children:"实现计划"})}),e.jsx(us,{className:"prose prose-sm max-w-none dark:prose-invert",children:v})]})}}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.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsxs("span",{className:"font-medium",children:["找到 ",m.numFiles||m.filenames.length," 个文件"]})}),e.jsx("div",{className:"space-y-1 max-h-96 overflow-y-auto",children:m.filenames.map((v,j)=>{const W=v.split("/").pop(),I=v.substring(0,v.lastIndexOf("/"));return e.jsxs("div",{onClick:()=>{n&&n(v)},className:"group flex items-center gap-2 px-2 py-1.5 rounded hover:bg-green-100/50 dark:hover:bg-green-800/20 cursor-pointer transition-colors",children:[e.jsx("svg",{className:"w-4 h-4 text-green-600 dark:text-green-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-mono text-sm font-medium text-green-800 dark:text-green-200 truncate group-hover:text-green-900 dark:group-hover:text-green-100",children:W}),e.jsx("div",{className:"font-mono text-xs text-green-600/70 dark:text-green-400/70 truncate",children:qe(I)})]}),e.jsx("svg",{className:"w-4 h-4 text-green-600 dark:text-green-400 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]},j)})})]})}if(w.includes("Do you want to proceed?")&&t.toolName==="Bash"){const m=w.split(`
56
- `),v=m.findIndex(M=>M.includes("Do you want to proceed?")),j=m.slice(0,v).join(`
57
- `),W=m.slice(v),I=W.find(M=>M.includes("Do you want to proceed?"))||"",O=[];W.forEach(M=>{const B=M.match(/^\s*(\d+)\.\s+(.+)$/);B&&O.push({number:B[1],text:B[2].trim()})});const A=w.match(/>\s*(\d+)/),T=A?A[1]:null;return e.jsxs("div",{className:"space-y-3",children:[j&&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:j})}),e.jsx("div",{className:"bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-amber-500 rounded-full flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-amber-900 dark:text-amber-100 text-base mb-2",children:"交互式提示"}),e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200 mb-4",children:I}),e.jsx("div",{className:"space-y-2 mb-4",children:O.map(M=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${T===M.number?"bg-amber-600 dark:bg-amber-700 text-white border-amber-600 dark:border-amber-700 shadow-md":"bg-white dark:bg-gray-800 text-amber-900 dark:text-amber-100 border-amber-300 dark:border-amber-700 hover:border-amber-400 dark:hover:border-amber-600 hover:shadow-sm"} ${T?"cursor-default":"cursor-not-allowed opacity-75"}`,disabled:!0,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold ${T===M.number?"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}),T===M.number&&e.jsx("svg",{className:"w-5 h-5 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})]})},M.number))}),T&&e.jsxs("div",{className:"bg-amber-100 dark:bg-amber-800/30 rounded-lg p-3",children:[e.jsxs("p",{className:"text-amber-900 dark:text-amber-100 text-sm font-medium mb-1",children:["✓ Claude 选择了选项 ",T]}),e.jsx("p",{className:"text-amber-800 dark:text-amber-200 text-xs",children:"在 CLI 中,您可以使用方向键或输入数字来交互式地选择此选项。"})]})]})]})})]})}const h=w.match(/The file (.+?) has been updated\./);if(h)return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"font-medium",children:"文件更新成功"})}),e.jsx("button",{onClick:()=>{n&&n(h[1])},className:"text-xs font-mono bg-green-100 dark:bg-green-800/30 px-2 py-1 rounded text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline cursor-pointer",children:h[1]})]});const S=w.match(/(?:The file|File) (.+?) has been (?:created|written)(?: successfully)?\.?/);return S?e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"font-medium",children:"文件创建成功"})}),e.jsx("button",{onClick:()=>{n&&n(S[1])},className:"text-xs font-mono bg-green-100 dark:bg-green-800/30 px-2 py-1 rounded text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline cursor-pointer",children:S[1]})]}):t.toolName==="Write"&&!t.toolResult.isError?e.jsxs("div",{className:"text-green-700 dark:text-green-300",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("span",{className:"font-medium",children:"文件写入成功"})]}),e.jsx("p",{className:"text-xs mt-1 text-green-600 dark:text-green-400",children:"文件内容显示在上方的差异视图中"})]}):w.includes("cat -n")&&w.includes("→")?e.jsxs("details",{open:!1,children:[e.jsxs("summary",{className:"text-sm text-green-700 dark:text-green-300 cursor-pointer hover:text-green-800 dark:hover:text-green-200 mb-2 flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform details-chevron",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看文件内容"]}),e.jsx("div",{className:"mt-2 bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden",children:e.jsx("div",{className:"text-xs font-mono p-3 whitespace-pre-wrap break-words overflow-hidden",children:w})})]}):w.length>300?e.jsxs("details",{open:!1,children:[e.jsxs("summary",{className:"text-sm text-green-700 dark:text-green-300 cursor-pointer hover:text-green-800 dark:hover:text-green-200 mb-2 flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4 transition-transform details-chevron",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}),"查看完整输出 (",w.length," 字符)"]}),e.jsx(us,{className:"mt-2 prose prose-sm max-w-none prose-green dark:prose-invert",children:w})]}):e.jsx(us,{className:"prose prose-sm max-w-none prose-green dark:prose-invert",children:w})})(),f&&e.jsxs("div",{className:"mt-4 border-t border-red-200/60 dark:border-red-800/60 pt-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{if(!i)return;i(f)?.success?N("granted"):N("error")},disabled:f.isAllowed||b==="granted",className:`inline-flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-medium border transition-colors ${f.isAllowed||b==="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:f.isAllowed||b==="granted"?"权限已添加":`授予权限 ${f.toolName}`}),l&&e.jsx("button",{type:"button",onClick:w=>{w.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:f.entry})," 到允许的工具列表。"]}),b==="error"&&e.jsx("div",{className:"mt-2 text-xs text-red-700 dark:text-red-200",children:"无法更新权限。请重试。"}),(f.isAllowed||b==="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 y=t.content.split(`
58
- `).filter(h=>h.trim()),p=y.find(h=>h.includes("?"))||y[0]||"",w=[];return y.forEach(h=>{const S=h.match(/[❯\s]*(\d+)\.\s+(.+)/);if(S){const m=h.includes("❯");w.push({number:S[1],text:S[2].trim(),isSelected:m})}}),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:w.map(h=>e.jsx("button",{className:`w-full text-left px-4 py-3 rounded-lg border-2 transition-all ${h.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 ${h.isSelected?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:h.number}),e.jsx("span",{className:"text-sm sm:text-base font-medium flex-1",children:h.text}),h.isSelected&&e.jsx("span",{className:"text-lg",children:"❯"})]})},h.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 y=JSON.parse(t.toolInput);if(y.file_path){const p=y.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(y.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 y=JSON.parse(t.toolInput);if(y.todos&&Array.isArray(y.todos))return e.jsxs("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400 mb-2",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),e.jsx("span",{className:"font-medium",children:"更新待办列表"})]}),e.jsx(rr,{todos:y.todos})]})}catch{return e.jsx("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),e.jsx("span",{className:"font-medium",children:"更新待办列表"})]})})}})():t.isToolUse&&t.toolName==="TodoRead"?e.jsx("div",{className:"bg-gray-50/50 dark:bg-gray-800/30 border-l-2 border-gray-400 dark:border-gray-500 pl-3 py-2 my-2",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),e.jsx("span",{className:"font-medium",children:"读取待办列表"})]})}):e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300",children:(()=>{const y=qe(gr(String(t.content||""))),p=y.trim();if((p.startsWith("{")||p.startsWith("["))&&(p.endsWith("}")||p.endsWith("]")))try{const w=JSON.parse(p),h=JSON.stringify(w,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:h})})})]})}catch{}return t.type==="assistant"?e.jsx(us,{className:"prose prose-sm max-w-none dark:prose-invert prose-gray",children:y}):e.jsx("div",{className:"whitespace-pre-wrap",children:y})})()}),e.jsx("div",{className:`text-xs text-gray-500 dark:text-gray-400 mt-1 ${g?"opacity-0 group-hover:opacity-100":""}`,children:new Date(t.timestamp).toLocaleTimeString()})]})]})})}),Oi=({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 Fi({selectedProject:t,selectedSession:r,ws:a,sendMessage:o,messages:n,onFileOpen:l,onInputFocusChange:i,onSessionActive:c,onSessionInactive:u,onSessionProcessing:g,onSessionNotProcessing:x,processingSessions:f,onReplaceTemporarySession:b,onNavigateToSession:N,onShowSettings:y,autoScrollToBottom:p,sendByCtrlEnter:w,externalMessageUpdate:h,onTaskClick:S,limitStatus:m,onLimitExceeded:v,checkLimitStatus:j}){const{showConfirm:W}=tt(),[I,O]=s.useState(()=>typeof window<"u"&&t&&at.getItem(`draft_input_${t.name}`)||""),[A,T]=s.useState(()=>{if(typeof window<"u"&&t){const d=at.getItem(`chat_messages_${t.name}`);return d?JSON.parse(d):[]}return[]}),[M,B]=s.useState(!1),[_,ce]=s.useState(r?.id||null),[V,ee]=s.useState(!1),[ne,ve]=s.useState([]),ye=s.useRef([]),[xe,ke]=s.useState(!1),[Ee,Me]=s.useState(!1),[_e,Be]=s.useState(0),[Q,Se]=s.useState(!1),[,Fe]=s.useState(0),Ne=20,Le=s.useCallback(d=>{We.current=d,Be(d)},[]),[Te,ze]=s.useState(!1),[Ce,He]=s.useState("default"),[Ve,je]=s.useState([]),Ae=s.useRef(new Map),q=s.useRef(r?.id||null),[oe,te]=s.useState([]),[Ie,G]=s.useState(new Map),[re,C]=s.useState(new Map),[F,de]=s.useState(!1),pe=s.useRef(null),P=s.useRef(null),ae=s.useRef(null),ue=s.useRef(null),le=s.useRef(null),k=s.useRef(!1),X=s.useRef(!1),se=s.useRef(!1),fe=s.useRef(!1),J=s.useRef(null),Re=s.useRef(null),$=s.useRef(null),we=s.useRef(null),We=s.useRef(0),Oe=s.useRef(""),Ge=s.useRef(null),Pe=s.useRef(null),[$r,_t]=s.useState(""),[gt,Et]=s.useState(!1),[bt,Os]=s.useState([]),[ot,Fs]=s.useState([]),[vt,as]=s.useState(-1),[Mt,Bt]=s.useState(0),[Ht,Jt]=s.useState(-1),[yt,ct]=s.useState(!1),[qt,Kt]=s.useState(!1),ns=s.useRef({height:0,top:0}),[os,ut]=s.useState(!1),[Vt,is]=s.useState(!1),Gt=s.useRef(null),jt=s.useRef(null),[st,Yt]=s.useState([]),[wt,ls]=s.useState([]),[Qt,xt]=s.useState(""),[zt,R]=s.useState(!1),[Y,ie]=s.useState(null),[$e,rt]=s.useState(-1),[it,Lt]=s.useState(-1),[cs,Ga]=s.useState(100),Ws=typeof window<"u"&&window.innerWidth<640,[Xt,Us]=s.useState(!1),[Ya,Qa]=s.useState(380),[Bs,_r]=s.useState(!1),[Xa,It]=s.useState(null),[kt,zr]=s.useState(()=>localStorage.getItem("claude-model")||ar.DEFAULT),pt="claude";s.useEffect(()=>{if(!Vt)return;const d=E=>{Gt.current&&!Gt.current.contains(E.target)&&jt.current&&!jt.current.contains(E.target)&&is(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[Vt]),s.useEffect(()=>{if(r?.id){const d=localStorage.getItem(`permissionMode-${r.id}`);He(d||"default")}},[r?.id]),s.useEffect(()=>{const d=q.current,E=r?.id;q.current=E,je(d&&d!==E?D=>(Ae.current.set(d,D),Ae.current.get(E)||[]):D=>D.filter(L=>!L.sessionId||L.sessionId===E))},[r?.id]),s.useEffect(()=>{(async()=>{if(t)try{const E=await K("/api/commands/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPath:t.path})});if(!E.ok)throw new Error("Failed to fetch commands");const D=await E.json(),L=[...(D.builtIn||[]).map(ge=>({...ge,type:"built-in"})),...(D.custom||[]).map(ge=>({...ge,type:"custom"}))];Yt(L);const z=`command_history_${t.name}`,H=at.getItem(z);if(H)try{const ge=JSON.parse(H),be=L.sort((Z,me)=>{const De=ge[Z.name]||0;return(ge[me.name]||0)-De});Yt(be)}catch(ge){console.error("Error parsing command history:",ge)}}catch(E){console.error("Error fetching slash commands:",E),Yt([])}})()},[t]);const Hs=s.useMemo(()=>st.length?new $n(st,{keys:[{name:"name",weight:2},{name:"description",weight:1}],threshold:.4,includeScore:!0,minMatchCharLength:1}):null,[st]);s.useEffect(()=>{if(!Qt){ls(st);return}if(!Hs){ls([]);return}const d=Hs.search(Qt);ls(d.map(E=>E.item))},[Qt,st,Hs]);const Za=s.useMemo(()=>{if(!t||st.length===0)return[];const d=`command_history_${t.name}`,E=at.getItem(d);if(!E)return[];try{const D=JSON.parse(E);return st.map(z=>({...z,usageCount:D[z.name]||0})).filter(z=>z.usageCount>0).sort((z,H)=>H.usageCount-z.usageCount).slice(0,5)}catch(D){return console.error("Error parsing command history:",D),[]}},[t,st]),en=s.useCallback((d,E,D)=>{if(!d||!t)return;if(D){rt(E);return}const L=`command_history_${t.name}`,z=at.getItem(L);let H={};try{H=z?JSON.parse(z):{}}catch(ge){console.error("Error parsing command history:",ge)}H[d.name]=(H[d.name]||0)+1,at.setItem(L,JSON.stringify(H)),ys(d)},[t]),tn=s.useCallback(d=>{const{action:E,data:D}=d;switch(E){case"help":T(L=>[...L,{type:"assistant",content:D.content,timestamp:Date.now()}]);break;case"model":{const L=D.available.claude,z=D.message?.includes("Switching to model:")?D.message.replace("Switching to model: ","").trim():null;z&&L.includes(z)?(zr(z),localStorage.setItem("claude-model",z),T(H=>[...H,{type:"assistant",content:`已切换到模型: **${z}**`,timestamp:Date.now()}])):T(z?H=>[...H,{type:"assistant",content:`无效的模型: ${z}
59
-
60
- **可用模型**: ${L.join(", ")}`,timestamp:Date.now()}]:H=>[...H,{type:"assistant",content:`**当前模型**: ${kt}
61
-
62
- **可用模型**: ${L.join(", ")}
63
-
64
- 使用 \`/model <模型名>\` 切换模型,例如 \`/model opus\``,timestamp:Date.now()}]);break}case"cost":{let L;D.usage?L=`**Token 使用量**: ${D.usage.used.toLocaleString()} / ${D.usage.total.toLocaleString()} (${D.usage.percentage}%)
65
-
66
- **剩余**: ${D.usage.remaining.toLocaleString()} tokens`:L=D.message||"无可用的 Token 使用数据。",T(z=>[...z,{type:"assistant",content:L,timestamp:Date.now()}]);break}case"memory":D.error?T(L=>[...L,{type:"assistant",content:`⚠️ ${D.message}`,timestamp:Date.now()}]):(T(L=>[...L,{type:"assistant",content:`📝 ${D.message}
67
-
68
- Path: \`${qe(D.path)}\``,timestamp:Date.now()}]),D.exists&&l&&l(D.path));break;case"config":y&&y();break;default:console.warn("Unknown built-in command action:",E)}},[l,y,kt]),Js=s.useRef(null),sn=s.useCallback(async(d,E)=>{const{content:D,hasBashCommands:L,hasFileIncludes:z}=d;if(L&&!await W("此命令包含将被执行的 bash 命令。是否继续?",{title:"执行确认",variant:"warning",confirmText:"继续执行"})){T(ge=>[...ge,{type:"assistant",content:"❌ 命令执行已取消",timestamp:Date.now()}]);return}O(D),setTimeout(()=>{if(Js.current){const H={preventDefault:()=>{}};Js.current(H)}},50)},[]),ys=s.useCallback(async d=>{if(!(!d||!t))try{const E=I.match(new RegExp(`${d.name}\\s*(.*)`)),D=E&&E[1]?E[1].trim().split(/\s+/):[],L={projectPath:t.path,projectName:t.name,sessionId:_,provider:pt,model:kt,tokenUsage:Y},z=await K("/api/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandName:d.name,commandPath:d.path,args:D,context:L})});if(!z.ok)throw new Error("Failed to execute command");const H=await z.json();H.type==="builtin"?tn(H):H.type==="custom"&&await sn(H,D),O(""),ut(!1),Lt(-1),xt(""),rt(-1)}catch(E){console.error("Error executing command:",E),T(D=>[...D,{type:"assistant",content:`Error executing command: ${E.message}`,timestamp:Date.now()}])}},[I,t,_,pt,kt,Y]),Or=s.useMemo(()=>{const d=new Map;return(E,D)=>{const L=`${E.length}-${D.length}-${E.slice(0,50)}`;if(d.has(L))return d.get(L);const z=rn(E,D);if(d.set(L,z),d.size>100){const H=d.keys().next().value;d.delete(H)}return z}},[]),ds=s.useCallback(async(d,E,D=!1,L="claude")=>{if(!d||!E)return[];const z=!D;z?ke(!0):Me(!0);try{const H=D?We.current:0,ge=await he.sessionMessages(d,E,Ne,H,L);if(!ge.ok)throw new Error("Failed to load session messages");const be=await ge.json();if(z&&be.sessionImages)ye.current=be.sessionImages;else if(D&&be.sessionImages){const Z=new Set(ye.current.map(De=>De.batchId)),me=be.sessionImages.filter(De=>!Z.has(De.batchId));me.length>0&&(ye.current=[...me,...ye.current])}if(z&&be.tokenUsage&&ie(be.tokenUsage),be.hasMore!==void 0)return Se(be.hasMore),Fe(be.total),Le(H+(be.messages?.length||0)),be.messages||[];{const Z=be.messages||[];return Se(!1),Fe(Z.length),Z}}catch(H){return console.error("Error loading session messages:",H),[]}finally{z?ke(!1):Me(!1)}},[Le]),rn=(d,E)=>{const D=d.split(`
69
- `),L=E.split(`
70
- `),z=[];let H=0,ge=0;for(;H<D.length||ge<L.length;){const be=D[H],Z=L[ge];H>=D.length?(z.push({type:"added",content:Z,lineNum:ge+1}),ge++):ge>=L.length?(z.push({type:"removed",content:be,lineNum:H+1}),H++):be===Z?(H++,ge++):(z.push({type:"removed",content:be,lineNum:H+1}),z.push({type:"added",content:Z,lineNum:ge+1}),H++,ge++)}return z},Fr=d=>{const E=[],D=new Map;for(const L of d)if(L.message?.role==="user"&&Array.isArray(L.message?.content))for(const z of L.message.content)z.type==="tool_result"&&D.set(z.tool_use_id,{content:z.content,isError:z.is_error,timestamp:new Date(L.timestamp||Date.now()),toolUseResult:L.toolUseResult||null});for(const L of d)if(!L.isMeta){if(L.message?.role==="user"&&L.message?.content){let z="",H="user";if(Array.isArray(L.message.content)){const Z=[];for(const me of L.message.content)me.type==="text"&&Z.push(Zt(me.text));z=Z.join(`
71
- `)}else typeof L.message.content=="string"?z=Zt(L.message.content):z=Zt(String(L.message.content));const ge=z.match(/<command-name>(\/[^<]+)<\/command-name>/);ge&&(z=ge[1]),!z||z.startsWith("<command-args>")||z.startsWith("<local-command-stdout>")||z.startsWith("<system-reminder>")||z.startsWith("Caveat:")||z.startsWith("This session is being continued from a previous")||z.startsWith("[Request interrupted")||(z=z.replace(/(\n\n)?\[Images provided at the following paths:\]\n[\s\S]*$/,""),z=nr(z),z&&E.push({type:H,content:z,timestamp:L.timestamp||new Date().toISOString()}))}else if(L.type==="tool_use"&&L.toolName)E.push({type:"assistant",content:"",timestamp:L.timestamp||new Date().toISOString(),isToolUse:!0,toolName:L.toolName,toolInput:L.toolInput||"",toolCallId:L.toolCallId});else if(L.type==="tool_result"){for(let z=E.length-1;z>=0;z--)if(E[z].isToolUse&&!E[z].toolResult&&(!L.toolCallId||E[z].toolCallId===L.toolCallId)){E[z].toolResult={content:L.output||"",isError:!1};break}}else if(L.message?.role==="assistant"&&L.message?.content){if(Array.isArray(L.message.content)){for(const z of L.message.content)if(z.type==="text"){let H=z.text;typeof H=="string"&&(H=nr(H)),E.push({type:"assistant",content:H,timestamp:L.timestamp||new Date().toISOString()})}else if(z.type==="tool_use"){const H=D.get(z.id);E.push({type:"assistant",content:"",timestamp:L.timestamp||new Date().toISOString(),isToolUse:!0,toolName:z.name,toolInput:JSON.stringify(z.input),toolResult:H?{content:typeof H.content=="string"?H.content:JSON.stringify(H.content),isError:H.isError,toolUseResult:H.toolUseResult}:null,toolError:H?.isError||!1,toolResultTimestamp:H?.timestamp||new Date})}}else if(typeof L.message.content=="string"){let z=L.message.content;z=nr(z),E.push({type:"assistant",content:z,timestamp:L.timestamp||new Date().toISOString()})}}}return E},qs=s.useMemo(()=>Fr(ne),[ne]),Nt=s.useCallback(()=>{le.current&&(le.current.scrollTop=le.current.scrollHeight)},[]),js=s.useCallback(()=>{if(!le.current)return!1;const{scrollTop:d,scrollHeight:E,clientHeight:D}=le.current;return E-d-D<50},[]),an=s.useCallback(async()=>{if(se.current||Ee||!Q||!r||!t)return;se.current=!0;const d=le.current,E=d?.scrollHeight??0,D=d?.scrollTop??0;try{const L=await ds(t.name,r.id,!0,"claude");L.length>0&&(J.current={height:E,top:D},ve(z=>[...L,...z]))}finally{se.current=!1}},[Q,Ee,r,t,ds]),Ks=s.useCallback(()=>{le.current&&Kt(!js())},[js]);s.useLayoutEffect(()=>{if(!J.current||!le.current)return;const{height:d,top:E}=J.current,D=le.current,z=D.scrollHeight-d;D.scrollTop=E+Math.max(z,0),J.current=null,setTimeout(()=>{le.current&&le.current.scrollTop>=100&&(fe.current=!1)},300)},[A.length]),s.useEffect(()=>{(async()=>{if(r&&t){const E=localStorage.getItem("selected-provider")||"claude";k.current=!0;const D=_!==null&&_!==r.id;if(D?(Le(0),Se(!1),Fe(0),ie(null),B(!1),a&&o&&o({type:"check-session-status",sessionId:r.id,provider:E})):_===null&&(Le(0),Se(!1),Fe(0),a&&o&&o({type:"check-session-status",sessionId:r.id,provider:E})),ce(r.id),Te)ze(!1);else{const L=await ds(t.name,r.id,!1,"claude");ve(L),D&&T(Fr(L))}}else!Te&&!M&&(T([]),ve([]),ye.current=[]),ce(null),Le(0),Se(!1),Fe(0);setTimeout(()=>{k.current=!1},250)})()},[r,t,Nt,Te]),s.useEffect(()=>{h>0&&r&&t&&(async()=>{try{const E=await ds(t.name,r.id,!1,"claude");ve(E),p&&js()&&setTimeout(()=>Nt(),200)}catch(E){console.error("Error reloading messages from external update:",E)}})()},[h,r,t,ds,js,p,Nt]),s.useEffect(()=>{ne.length>0&&!M&&T(d=>{const E=new Map;for(const H of d)H.type==="user"&&H.images?.length>0&&E.set(H.content,H.images);const D=new Map;for(const H of ye.current)if(H.messageContent){const ge=H.images.map(Z=>({id:Z.id,name:Z.name})),be=D.get(H.messageContent)||[];D.set(H.messageContent,[...be,...ge])}const L=E.size>0,z=D.size>0;return!L&&!z?qs:qs.map(H=>H.type!=="user"?H:L&&E.has(H.content)?{...H,images:E.get(H.content)}:z&&D.has(H.content)?{...H,images:D.get(H.content)}:H)})},[qs,ne,M]),s.useEffect(()=>{i&&i(V)},[V,i]),s.useEffect(()=>{t&&I!==""?at.setItem(`draft_input_${t.name}`,I):t&&I===""&&at.removeItem(`draft_input_${t.name}`)},[I,t]),s.useEffect(()=>{t&&A.length>0&&at.setItem(`chat_messages_${t.name}`,JSON.stringify(A))},[A,t]),s.useEffect(()=>{if(t){const d=at.getItem(`draft_input_${t.name}`)||"";d!==I&&O(d)}},[t?.name]),s.useEffect(()=>{_&&M&&g&&g(_)},[M,_,g]),s.useEffect(()=>{_&&f&&f.has(_)&&!M&&(B(!0),ct(!0))},[_,f]),s.useEffect(()=>{if(n.length>0){const d=n[n.length-1];if(!["projects_updated","session-created","claude-complete"].includes(d.type)&&d.sessionId&&_&&d.sessionId!==_){console.log("⏭️ Skipping message for different session:",d.sessionId,"current:",_);return}switch(d.type){case"session-created":d.sessionId&&!_&&(sessionStorage.setItem("pendingSessionId",d.sessionId),ze(!0),b&&b(d.sessionId),je(Z=>Z.map(me=>me.sessionId?me:{...me,sessionId:d.sessionId})));break;case"token-budget":d.data&&ie(d.data);break;case"claude-response":if(d.data.isMeta)return;const L=d.data.message||d.data;if(L&&typeof L=="object"&&L.type){if(L.type==="content_block_delta"&&L.delta?.text){const Z=Zt(L.delta.text);Oe.current+=Z,Ge.current||(Ge.current=setTimeout(()=>{const me=Oe.current;Oe.current="",Ge.current=null,me&&T(De=>{const Ue=[...De],et=Ue[Ue.length-1];return et&&et.type==="assistant"&&!et.isToolUse&&et.isStreaming?et.content=(et.content||"")+me:Ue.push({type:"assistant",content:me,timestamp:new Date,isStreaming:!0}),Ue})},100));return}if(L.type==="content_block_stop"){Ge.current&&(clearTimeout(Ge.current),Ge.current=null);const Z=Oe.current;Oe.current="",Z&&T(me=>{const De=[...me],Ue=De[De.length-1];return Ue&&Ue.type==="assistant"&&!Ue.isToolUse&&Ue.isStreaming?Ue.content=(Ue.content||"")+Z:De.push({type:"assistant",content:Z,timestamp:new Date,isStreaming:!0}),De}),T(me=>{const De=[...me],Ue=De[De.length-1];return Ue&&Ue.type==="assistant"&&Ue.isStreaming&&(Ue.isStreaming=!1),De});return}}if(d.data.type==="system"&&d.data.subtype==="init"&&d.data.session_id&&_&&d.data.session_id!==_){console.log("🔄 Claude CLI session duplication detected:",{originalSession:_,newSession:d.data.session_id}),ze(!0),N&&N(d.data.session_id);return}if(d.data.type==="system"&&d.data.subtype==="init"&&d.data.session_id&&!_){console.log("🔄 New session init detected:",{newSession:d.data.session_id}),ze(!0),N&&N(d.data.session_id);return}if(d.data.type==="system"&&d.data.subtype==="init"&&d.data.session_id&&_&&d.data.session_id===_){console.log("🔄 System init message for current session, ignoring");return}const z=L.role==="user"||d.data.type==="user";if(Array.isArray(L.content)&&!z){for(const Z of L.content)if(Z.type==="tool_use"){const me=Z.input?JSON.stringify(Z.input,null,2):"";T(De=>[...De,{type:"assistant",content:"",timestamp:new Date,isToolUse:!0,toolName:Z.name,toolInput:me,toolId:Z.id,toolResult:null}])}else if(Z.type==="text"&&Z.text?.trim()){let me=Zt(Z.text);me=gr(me),T(De=>[...De,{type:"assistant",content:me,timestamp:new Date}])}}else if(typeof L.content=="string"&&L.content.trim()&&!z){let Z=Zt(L.content);Z=gr(Z),T(me=>[...me,{type:"assistant",content:Z,timestamp:new Date}])}if(L.role==="user"&&Array.isArray(L.content))for(const Z of L.content)Z.type==="tool_result"&&T(me=>me.map(De=>De.isToolUse&&De.toolId===Z.tool_use_id?{...De,toolResult:{content:Z.content,isError:Z.is_error,timestamp:new Date}}:De));break;case"claude-output":{const Z=String(d.data||"");Z.trim()&&(Oe.current+=Oe.current?`
72
- ${Z}`:Z,Ge.current||(Ge.current=setTimeout(()=>{const me=Oe.current;Oe.current="",Ge.current=null,me&&T(De=>{const Ue=[...De],et=Ue[Ue.length-1];return et&&et.type==="assistant"&&!et.isToolUse&&et.isStreaming?et.content=et.content?`${et.content}
73
- ${me}`:me:Ue.push({type:"assistant",content:me,timestamp:new Date,isStreaming:!0}),Ue})},100)))}break;case"claude-interactive-prompt":T(Z=>[...Z,{type:"assistant",content:d.data,timestamp:new Date,isInteractivePrompt:!0}]);break;case"claude-permission-request":{if(!d.requestId)break;je(Z=>Z.some(me=>me.requestId===d.requestId)?Z:[...Z,{requestId:d.requestId,toolName:d.toolName||"UnknownTool",input:d.input,context:d.context,sessionId:d.sessionId||null,receivedAt:new Date}]),B(!0),ct(!0),It({text:"等待权限",tokens:0,can_interrupt:!0});break}case"claude-permission-cancelled":{if(!d.requestId)break;je(Z=>Z.filter(me=>me.requestId!==d.requestId));break}case"claude-error":T(Z=>[...Z,{type:"error",content:`错误: ${d.error}`,timestamp:new Date}]),B(!1),ct(!1),It(null),je([]),_&&(u&&u(_),x&&x(_));break;case"claude-complete":const H=d.sessionId||_||sessionStorage.getItem("pendingSessionId");(H===_||!_)&&(B(!1),ct(!1),It(null)),H&&(u&&u(H),x&&x(H));const ge=sessionStorage.getItem("pendingSessionId");ge&&!_&&d.exitCode===0&&(ce(ge),sessionStorage.removeItem("pendingSessionId"),console.log("✅ New session complete, ID set to:",ge)),t&&d.exitCode===0&&at.removeItem(`chat_messages_${t.name}`),H===_&&je([]),Ae.current.delete(H);break;case"session-aborted":{const Z=d.sessionId||_;Z===_&&(B(!1),ct(!1),It(null)),Z&&(u&&u(Z),x&&x(Z)),je([]),T(me=>[...me,{type:"assistant",content:"会话已被用户中断。",timestamp:new Date}]);break}case"session-status":{const Z=d.sessionId;(Z===_||r&&Z===r.id)&&d.isProcessing&&(B(!0),ct(!0),g&&g(Z));break}case"claude-status":const be=d.data;if(be){let Z={text:"处理中...",tokens:0,can_interrupt:!0};be.message?Z.text=be.message:be.status?Z.text=be.status:typeof be=="string"&&(Z.text=be),be.tokens?Z.tokens=be.tokens:be.token_count&&(Z.tokens=be.token_count),be.can_interrupt!==void 0&&(Z.can_interrupt=be.can_interrupt),It(Z),B(!0),ct(Z.can_interrupt)}break}}},[n]),s.useEffect(()=>{t&&nn()},[t]);const nn=async()=>{try{const d=await he.getFiles(t.name);if(d.ok){const E=await d.json(),D=Wr(E);Os(D)}}catch(d){console.error("Error fetching files:",d)}},Wr=(d,E="")=>{let D=[];for(const L of d){const z=E?`${E}/${L.name}`:L.name;L.type==="directory"&&L.children?D=D.concat(Wr(L.children,z)):L.type==="file"&&D.push({name:L.name,path:z,relativePath:L.path})}return D};s.useEffect(()=>{const d=I.slice(0,Mt),E=d.lastIndexOf("@");if(E!==-1){const D=d.slice(E+1);if(D.includes(" "))Et(!1),Jt(-1);else{Jt(E),Et(!0);const L=bt.filter(z=>z.name.toLowerCase().includes(D.toLowerCase())||z.path.toLowerCase().includes(D.toLowerCase())).slice(0,10);Fs(L),as(-1)}}else Et(!1),Jt(-1)},[I,Mt,bt]),s.useEffect(()=>{const d=setTimeout(()=>{_t(I)},150);return()=>clearTimeout(d)},[I]);const ws=s.useMemo(()=>A.length<=cs?A:A.slice(-cs),[A,cs]),Ur=s.useMemo(()=>ws.filter(d=>!d.isToolUse),[ws]),Dt=s.useMemo(()=>ws.filter(d=>d.isToolUse),[ws]);s.useEffect(()=>{if(!p&&le.current){const d=le.current;ns.current={height:d.scrollHeight,top:d.scrollTop}}}),s.useEffect(()=>{if(le.current&&A.length>0)if(p)qt||setTimeout(()=>Nt(),50);else{const d=le.current,E=ns.current.height,D=ns.current.top,z=d.scrollHeight-E;z>0&&D>0&&(d.scrollTop=D+z)}},[A.length,qt,Nt,p]),s.useEffect(()=>{le.current&&A.length>0&&!k.current&&(Kt(!1),setTimeout(()=>{Nt()},200))},[r?.id,t?.name]),s.useEffect(()=>{const d=le.current;if(d)return d.addEventListener("scroll",Ks),()=>d.removeEventListener("scroll",Ks)},[Ks]),s.useEffect(()=>{const d=D=>{if(!Bs)return;const L=Re.current;if(!L)return;const z=L.parentElement;if(!z)return;const ge=z.getBoundingClientRect().right-D.clientX;ge>=300&&ge<=600&&Qa(ge)},E=()=>_r(!1);return Bs&&(document.addEventListener("mousemove",d),document.addEventListener("mouseup",E),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",E),document.body.style.cursor="",document.body.style.userSelect=""}},[Bs]),s.useEffect(()=>{!Ws&&Dt.length>0&&!Xt&&Us(!0)},[Dt.length]),s.useEffect(()=>{Xt&&$.current&&($.current.scrollTop=$.current.scrollHeight)},[Dt.length,Xt]),s.useEffect(()=>{if(P.current){P.current.style.height="auto",P.current.style.height=P.current.scrollHeight+"px";const d=parseInt(window.getComputedStyle(P.current).lineHeight),E=P.current.scrollHeight>d*2;R(E)}},[]),s.useEffect(()=>{P.current&&!I.trim()&&(P.current.style.height="auto",R(!1))},[I]),s.useEffect(()=>{if(!t||!r?.id||r.id.startsWith("new-session-")){ie(null);return}(async()=>{try{const E=`/api/projects/${t.name}/sessions/${r.id}/token-usage`,D=await K(E);if(D.ok){const L=await D.json();ie(L)}else ie(null)}catch(E){console.error("Failed to fetch initial token usage:",E)}})()},[r?.id,r?.__provider,t?.path]);const on=s.useCallback(d=>{d.trim()&&O(E=>{const D=E.trim()?`${E} ${d}`:d;return setTimeout(()=>{if(P.current){P.current.style.height="auto",P.current.style.height=P.current.scrollHeight+"px";const L=parseInt(window.getComputedStyle(P.current).lineHeight),z=P.current.scrollHeight>L*2;R(z)}},0),D})},[]),ln=s.useCallback(()=>{Ga(d=>d+100)},[]),ks=s.useCallback(d=>{const E=d.filter(D=>{try{if(!D||typeof D!="object")return console.warn("Invalid file object:",D),!1;if(!D.type||!D.type.startsWith("image/"))return!1;if(!D.size||D.size>5242880){const L=D.name||"Unknown file";return C(z=>{const H=new Map(z);return H.set(L,"文件太大(最大 5MB)"),H}),!1}return!0}catch(L){return console.error("Error validating file:",L,D),!1}});E.length>0&&te(D=>[...D,...E].slice(0,5))},[]),cn=s.useCallback(async d=>{const E=d.target.files;if(!(!E||E.length===0||!t)){de(!0);try{const D=new FormData;Array.from(E).forEach(H=>{D.append("files",H)});const L=await he.uploadFiles(t.name,D);if(!L.ok){const H=await L.json();throw new Error(H.error||"上传失败")}const z=await L.json();if(z.files&&z.files.length>0){const H=z.files.map(be=>`@${be.name}`).join(" "),ge=I?`${I} ${H} `:`${H} `;O(ge),P.current&&P.current.focus()}}catch(D){console.error("File upload failed:",D)}finally{de(!1),ae.current&&(ae.current.value="")}}},[t,I]),dn=s.useCallback(async d=>{const E=Array.from(d.clipboardData.items);for(const D of E)if(D.type.startsWith("image/")){const L=D.getAsFile();L&&ks([L])}if(E.length===0&&d.clipboardData.files.length>0){const L=Array.from(d.clipboardData.files).filter(z=>z.type.startsWith("image/"));L.length>0&&ks(L)}},[ks]),{getRootProps:mn,getInputProps:un,isDragActive:xn,open:pn}=Lr({accept:{"image/*":[".png",".jpg",".jpeg",".gif",".webp",".svg"]},maxSize:5*1024*1024,maxFiles:5,onDrop:ks,noClick:!0,noKeyboard:!0}),Ot=s.useCallback(async d=>{if(d.preventDefault(),!I.trim()||M||!t||X.current)return;X.current=!0;const E=I.trim();if(E.startsWith("/")){const me=E.indexOf(" "),De=me!==-1?E.slice(0,me):E,Ue=st.find(et=>et.name===De&&et.namespace==="builtin");if(Ue){X.current=!1,ys(Ue);return}}if(j){const me=await j();if(me&&!me.allowed){X.current=!1,v?.(me.reason);return}}let D=[],L=null;if(oe.length>0){const me=new FormData;oe.forEach(De=>{me.append("images",De)});try{const De=await K(`/api/projects/${t.name}/upload-images`,{method:"POST",headers:{},body:me});if(!De.ok)throw new Error("图片上传失败");const Ue=await De.json();D=Ue.images,L=Ue.uploadBatchId||null}catch(De){console.error("Image upload failed:",De),X.current=!1,T(Ue=>[...Ue,{type:"error",content:`图片上传失败: ${De.message}`,timestamp:new Date}]);return}}const z={type:"user",content:I,images:D,timestamp:new Date};T(me=>[...me,z]),B(!0),X.current=!1,ct(!0),It({text:"处理中",tokens:0,can_interrupt:!0}),Kt(!1),setTimeout(()=>Nt(),100);const ge=_||r?.id||`new-session-${Date.now()}`;c&&c(ge);const Z=(()=>{try{const me=at.getItem("claude-settings");if(me)return JSON.parse(me)}catch(me){console.error("Error loading tools settings:",me)}return{allowedTools:[],disallowedTools:[],skipPermissions:!1}})();o({type:"claude-command",command:I,options:{projectPath:t.path,cwd:t.fullPath,sessionId:_,resume:!!_,toolsSettings:Z,permissionMode:Ce,model:kt,images:D,uploadBatchId:L}}),O(""),te([]),G(new Map),C(new Map),R(!1),P.current&&(P.current.style.height="auto"),t&&at.removeItem(`draft_input_${t.name}`)},[I,M,t,oe,_,r,pt,Ce,c,kt,o,O,te,G,C,R,P,T,B,ct,It,Kt,Nt,j,v,ys,st]),Vs=s.useCallback(d=>!d||pt!=="claude"?{success:!1}:$i(d.entry),[pt]),ms=s.useCallback((d,E)=>{const L=(Array.isArray(d)?d:[d]).filter(Boolean);L.length!==0&&(L.forEach(z=>{o({type:"claude-permission-response",requestId:z,allow:!!E?.allow,updatedInput:E?.updatedInput,message:E?.message,rememberEntry:E?.rememberEntry})}),je(z=>{const H=z.filter(ge=>!L.includes(ge.requestId));return H.length===0&&It(null),H}))},[o]);s.useEffect(()=>{Js.current=Ot},[Ot]);const Br=d=>{if(!d)return;const E=I.slice(0,it),D=I.slice(it),L=D.indexOf(" "),z=L!==-1?D.slice(L):"",H=E+d.name+" "+z;O(H),ut(!1),Lt(-1),xt(""),rt(-1),Pe.current&&clearTimeout(Pe.current),ys(d)},hn=d=>{if(os&&wt.length>0){if(d.key==="ArrowDown"){d.preventDefault(),rt(E=>E<wt.length-1?E+1:0);return}if(d.key==="ArrowUp"){d.preventDefault(),rt(E=>E>0?E-1:wt.length-1);return}if(d.key==="Tab"||d.key==="Enter"){d.preventDefault(),$e>=0?Br(wt[$e]):wt.length>0&&Br(wt[0]);return}if(d.key==="Escape"){d.preventDefault(),ut(!1),Lt(-1),xt(""),rt(-1),Pe.current&&clearTimeout(Pe.current);return}}if(gt&&ot.length>0){if(d.key==="ArrowDown"){d.preventDefault(),as(E=>E<ot.length-1?E+1:0);return}if(d.key==="ArrowUp"){d.preventDefault(),as(E=>E>0?E-1:ot.length-1);return}if(d.key==="Tab"||d.key==="Enter"){d.preventDefault(),vt>=0?Gs(ot[vt]):ot.length>0&&Gs(ot[0]);return}if(d.key==="Escape"){d.preventDefault(),Et(!1);return}}if(d.key==="Tab"&&!gt&&!os){d.preventDefault();const E=["default","acceptEdits","bypassPermissions","plan"],L=(E.indexOf(Ce)+1)%E.length,z=E[L];He(z),r?.id&&localStorage.setItem(`permissionMode-${r.id}`,z);return}if(d.key==="Enter"){if(d.nativeEvent.isComposing)return;(d.ctrlKey||d.metaKey)&&!d.shiftKey?(d.preventDefault(),Ot(d)):!d.shiftKey&&!d.ctrlKey&&!d.metaKey&&(w||(d.preventDefault(),Ot(d)))}},Gs=d=>{const E=I.slice(0,Ht),D=I.slice(Ht),L=D.indexOf(" "),z=L!==-1?D.slice(L):"",H=E+"@"+d.path+" "+z,ge=E.length+1+d.path.length+1;P.current&&!P.current.matches(":focus")&&P.current.focus(),O(H),Bt(ge),Et(!1),Jt(-1),P.current&&requestAnimationFrame(()=>{P.current&&(P.current.setSelectionRange(ge,ge),P.current.matches(":focus")||P.current.focus())})},fn=d=>{const E=d.target.value,D=d.target.selectionStart;if(!_&&E.trim(),O(E),Bt(D),!E.trim()){d.target.style.height="auto",R(!1),ut(!1),Lt(-1),xt("");return}const L=E.slice(0,D);if((L.match(/```/g)||[]).length%2===1){ut(!1),Lt(-1),xt("");return}const ge=/(^|\s)\/(\S*)$/,be=L.match(ge);if(be){const Z=be.index+be[1].length,me=be[2];Lt(Z),ut(!0),rt(-1),Pe.current&&clearTimeout(Pe.current),Pe.current=setTimeout(()=>{xt(me)},150)}else ut(!1),Lt(-1),xt(""),Pe.current&&clearTimeout(Pe.current)},gn=d=>{Bt(d.target.selectionStart)},bn=()=>{_&&yt&&o({type:"abort-session",sessionId:_,provider:pt})},vn=()=>{const d=["default","acceptEdits","bypassPermissions","plan"],D=(d.indexOf(Ce)+1)%d.length,L=d[D];He(L),r?.id&&localStorage.setItem(`permissionMode-${r.id}`,L)};return t?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
74
- details[open] .details-chevron {
75
- transform: rotate(180deg);
76
- }
77
- `}),e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{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:le,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:[xe&&A.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:"正在加载会话消息..."})]})}):A.length===0?e.jsxs("div",{className:"flex items-center justify-center h-full",children:[!r&&!_&&e.jsxs("div",{className:"text-center px-6 sm:px-4 py-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-3",children:"开始新对话"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-8",children:"与 AgentHub 对话以获取帮助"})]}),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:[Ee&&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:"正在加载历史消息..."})]})}),Q&&!Ee&&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:["已显示 ",A.length," 条消息"]}),e.jsx("button",{onClick:an,className:"text-xs text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 underline",children:"加载更多消息"})]}),!Q&&A.length>cs&&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:["显示最近 ",cs," 条消息(共 ",A.length," 条) •",e.jsx("button",{className:"ml-1 text-blue-600 hover:text-blue-700 underline",onClick:ln,children:"加载更早的消息"})]}),Ur.map((d,E)=>{const D=E>0?Ur[E-1]:null,L=d.id||`${d.type}-${d.timestamp?.getTime?.()||E}-${E}`;return e.jsx(pa,{message:d,index:E,prevMessage:D,createDiff:Or,onFileOpen:l,onShowSettings:y,onGrantToolPermission:Vs,selectedProject:t,provider:pt},L)})]}),M&&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(Ps,{className:"w-full h-full"})}),e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"AgentHub"})]}),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:pe})]})}),!Ws&&Dt.length>0&&e.jsx("button",{onClick:()=>Us(d=>!d),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:Xt?"收起工具面板":"展开工具面板",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:Xt?"M9 5l7 7-7 7":"M15 19l-7-7 7-7"})})}),Xt&&!Ws&&Dt.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:Re,onMouseDown:d=>{_r(!0),d.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:`${Ya}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:Dt.length})]}),e.jsx("button",{onClick:()=>Us(!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:$,className:"flex-1 overflow-y-auto p-2 space-y-2",children:[Dt.map((d,E)=>{const D=E>0?Dt[E-1]:null,L=d.id||`tool-${d.timestamp?.getTime?.()||E}-${E}`;return e.jsx(pa,{message:d,index:E,prevMessage:D,createDiff:Or,onFileOpen:l,onShowSettings:y,onGrantToolPermission:Vs,selectedProject:t,provider:pt},L)}),e.jsx("div",{ref:we})]})]})]})]}),e.jsxs("div",{className:"p-2 sm:p-4 md:p-4 flex-shrink-0 pb-2 sm:pb-4 md:pb-6",children:[e.jsx("div",{className:"flex-1",children:e.jsx(Ii,{status:Xa,isLoading:M,onAbort:bn,provider:pt})}),e.jsxs("div",{ref:ue,className:"max-w-4xl mx-auto mb-3",children:[Ve.length>0&&e.jsx("div",{className:"mb-3 space-y-2",children:Ve.map(d=>{const E=xa(d.input),D=br(d.toolName,E),L=Ir(),z=D?L.allowedTools.includes(D):!1,H=z?"已允许(已保存)":"允许并记住",ge=D?Ve.filter(be=>br(be.toolName,xa(be.input))===D).map(be=>be.requestId):[d.requestId];return d.toolName==="AskUserQuestion"?e.jsx(zi,{request:d,onSubmit:be=>{ms(d.requestId,{allow:!0,updatedInput:{...d.input,answers:be}})},onSkip:()=>ms(d.requestId,{allow:!1,message:"用户跳过问题"})},d.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:d.toolName})]})]}),D&&e.jsxs("div",{className:"text-xs text-amber-700 dark:text-amber-300",children:["允许规则: ",e.jsx("span",{className:"font-mono",children:qe(D)})]})]}),E&&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:qe(E)})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ms(d.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:()=>{D&&!z&&Vs({entry:D,toolName:d.toolName}),ms(ge,{allow:!0,rememberEntry:D})},className:`inline-flex items-center gap-2 rounded-md text-xs font-medium px-3 py-1.5 border transition-colors ${D?"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:!D,children:H}),e.jsx("button",{type:"button",onClick:()=>ms(d.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:"拒绝"})]})]},d.requestId)})}),e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[e.jsx("button",{type:"button",onClick:vn,className:`px-3 py-1.5 rounded-lg text-sm font-medium border transition-all duration-200 ${Ce==="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":Ce==="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":Ce==="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 ${Ce==="default"?"bg-gray-500":Ce==="acceptEdits"?"bg-green-500":Ce==="bypassPermissions"?"bg-orange-500":"bg-blue-500"}`}),e.jsxs("span",{children:[Ce==="default"&&"默认模式",Ce==="acceptEdits"&&"接受编辑",Ce==="bypassPermissions"&&"跳过权限",Ce==="plan"&&"计划模式"]})]})}),e.jsx("button",{ref:jt,type:"button",onClick:()=>is(!Vt),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:ar.OPTIONS.find(d=>d.value===kt)?.label||kt})]})}),I.trim()&&e.jsx("button",{type:"button",onClick:d=>{d.preventDefault(),d.stopPropagation(),O(""),P.current&&(P.current.style.height="auto",P.current.focus()),R(!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"})})}),qt&&A.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:Ot,className:"relative max-w-4xl mx-auto",children:[xn&&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:"将图片拖放到这里"})]})}),oe.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:oe.map((d,E)=>e.jsx(Oi,{file:d,onRemove:()=>{te(D=>D.filter((L,z)=>z!==E))},uploadProgress:Ie.get(d.name),error:re.get(d.name)},E))})}),gt&&ot.length>0&&e.jsx("div",{className:"absolute bottom-full left-0 right-0 mb-2 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg shadow-lg max-h-48 overflow-y-auto z-50 backdrop-blur-sm",children:ot.map((d,E)=>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 ${E===vt?"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:D=>{D.preventDefault(),D.stopPropagation()},onClick:D=>{D.preventDefault(),D.stopPropagation(),Gs(d)},children:[e.jsx("div",{className:"font-medium text-sm",children:d.name}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 font-mono",children:qe(d.path)})]},d.path))}),e.jsx(Ai,{commands:wt,selectedIndex:$e,onSelect:en,onClose:()=>{ut(!1),Lt(-1),xt(""),rt(-1)},position:{top:P.current?Math.max(16,P.current.getBoundingClientRect().top-316):0,left:P.current?P.current.getBoundingClientRect().left:16,bottom:P.current?window.innerHeight-P.current.getBoundingClientRect().top+8:90},isOpen:os,frequentCommands:Qt?[]:Za}),Vt&&e.jsxs("div",{ref:Gt,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:jt.current?window.innerHeight-jt.current.getBoundingClientRect().top+8:90,left:jt.current?jt.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:kt,onChange:d=>{const E=d.target.value;zr(E),localStorage.setItem("claude-model",E),is(!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:ar.OPTIONS.map(({value:d,label:E})=>e.jsx("option",{value:d,children:E},d))})]}),e.jsxs("div",{...mn(),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 ${zt?"chat-input-expanded":""}`,children:[e.jsx("input",{...un()}),e.jsx("textarea",{ref:P,value:I,onChange:fn,onClick:gn,onKeyDown:hn,onPaste:dn,onFocus:()=>ee(!0),onBlur:()=>ee(!1),onInput:d=>{d.target.style.height="auto",d.target.style.height=d.target.scrollHeight+"px",Bt(d.target.selectionStart);const E=parseInt(window.getComputedStyle(d.target).lineHeight),D=d.target.scrollHeight>E*2;R(D)},placeholder:m&&!m.allowed?m.reason==="total_limit_exceeded"?"使用上限已达到,请联系管理员":"今日使用上限已达到":"输入 / 使用命令,@ 引用文件,或向 Claude 提问...",disabled:M||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:pn,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:ae,onChange:cn,className:"hidden",multiple:!0}),e.jsx("button",{type:"button",onClick:()=>ae.current?.click(),disabled:F||!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:F?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(Ti,{onTranscript:on,className:"w-10 h-10 sm:w-10 sm:h-10"})}),e.jsx("button",{type:"submit",disabled:!I.trim()||M,onMouseDown:d=>{d.preventDefault(),Ot(d)},onTouchStart:d=>{d.preventDefault(),Ot(d)},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 ${I.trim()?"opacity-0":"opacity-100"}`,children:w?"Ctrl+Enter 发送 • Shift+Enter 换行 • Tab 切换模式 • / 使用命令":"Enter 发送 • Shift+Enter 换行 • Tab 切换模式 • / 使用命令"})]})]})]})]})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400",children:e.jsx("p",{children:"选择一个项目开始与 Claude 对话"})})})}const Wi=ft.memo(Fi);function vr({file:t,onClose:r,projectPath:a,isSidebar:o=!1,isExpanded:n=!1,onToggleExpand:l=null}){const{showAlert:i}=tt(),[c,u]=s.useState(""),[g,x]=s.useState(!0),[f,b]=s.useState(!1),[N,y]=s.useState(!1),[p,w]=s.useState(()=>{const V=localStorage.getItem("codeEditorTheme");return V?V==="dark":!0}),[h,S]=s.useState(!1),[m,v]=s.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[j,W]=s.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[I,O]=s.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),A=s.useRef(null),T=s.useMemo(()=>{const V=()=>{const ee=document.createElement("div");ee.className="cm-editor-toolbar-panel";const ne=()=>{let ve='<div style="display: flex; align-items: center; justify-content: flex-end; width: 100%;">';ve+='<div style="display: flex; align-items: center; gap: 4px;">',ve+=`
78
- <button class="cm-toolbar-btn cm-settings-btn" title="Editor Settings">
79
- <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
80
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
81
- </svg>
82
- </button>
83
- `,o&&l&&(ve+=`
84
- <button class="cm-toolbar-btn cm-expand-btn" title="${n?"Collapse editor":"Expand editor to full width"}">
85
- <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
86
- ${n?'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25" />':'<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4" />'}
87
- </svg>
88
- </button>
89
- `),ve+="</div>",ve+="</div>",ee.innerHTML=ve,ee.querySelector(".cm-settings-btn")?.addEventListener("click",()=>{window.openSettings&&window.openSettings("appearance")}),o&&l&&ee.querySelector(".cm-expand-btn")?.addEventListener("click",()=>{l()})};return ne(),{top:!0,dom:ee,update:ne}};return[yn.of(V)]},[o,n,l]),M=V=>{const ee=V.split(".").pop()?.toLowerCase();switch(ee){case"js":case"jsx":case"ts":case"tsx":return[Ln({jsx:!0,typescript:ee.includes("ts")})];case"py":return[Mn()];case"html":case"htm":return[En()];case"css":case"scss":case"less":return[Cn()];case"json":return[Sn()];case"md":case"markdown":return[Nn()];default:return[]}};s.useEffect(()=>{(async()=>{try{x(!0);const ee=await he.readFile(t.projectName,t.path);if(!ee.ok)throw new Error(`Failed to load file: ${ee.status} ${ee.statusText}`);const ne=await ee.json();u(ne.content)}catch(ee){console.error("Error loading file:",ee),u(`// Error loading file: ${ee.message}
90
- // File: ${t.name}
91
- // Path: ${qe(t.path)}`)}finally{x(!1)}})()},[t,a]);const B=async()=>{b(!0);try{console.log("Saving file:",{projectName:t.projectName,path:t.path,contentLength:c?.length});const V=await he.saveFile(t.projectName,t.path,c);if(console.log("Save response:",{status:V.status,ok:V.ok,contentType:V.headers.get("content-type")}),!V.ok){const ne=V.headers.get("content-type");if(ne&&ne.includes("application/json")){const ve=await V.json();throw new Error(ve.error||`Save failed: ${V.status}`)}else{const ve=await V.text();throw console.error("Non-JSON error response:",ve),new Error(`Save failed: ${V.status} ${V.statusText}`)}}const ee=await V.json();console.log("Save successful:",ee),S(!0),setTimeout(()=>S(!1),2e3)}catch(V){console.error("Error saving file:",V),i(`保存文件失败: ${V.message}`,{variant:"error"})}finally{b(!1)}},_=()=>{const V=new Blob([c],{type:"text/plain"}),ee=URL.createObjectURL(V),ne=document.createElement("a");ne.href=ee,ne.download=t.name,document.body.appendChild(ne),ne.click(),document.body.removeChild(ne),URL.revokeObjectURL(ee)},ce=()=>{y(!N)};return s.useEffect(()=>{localStorage.setItem("codeEditorTheme",p?"dark":"light")},[p]),s.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",m.toString())},[m]),s.useEffect(()=>{const V=()=>{const ee=localStorage.getItem("codeEditorTheme");ee&&w(ee==="dark");const ne=localStorage.getItem("codeEditorWordWrap");ne!==null&&v(ne==="true");const ve=localStorage.getItem("codeEditorLineNumbers");ve!==null&&W(ve!=="false");const ye=localStorage.getItem("codeEditorFontSize");ye&&O(ye)};return window.addEventListener("storage",V),window.addEventListener("codeEditorSettingsChanged",V),()=>{window.removeEventListener("storage",V),window.removeEventListener("codeEditorSettingsChanged",V)}},[]),s.useEffect(()=>{const V=ee=>{(ee.ctrlKey||ee.metaKey)&&(ee.key==="s"?(ee.preventDefault(),B()):ee.key==="Escape"&&(ee.preventDefault(),r()))};return document.addEventListener("keydown",V),()=>document.removeEventListener("keydown",V)},[c]),g?e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
92
- .code-editor-loading {
93
- background-color: ${p?"#111827":"#ffffff"} !important;
94
- }
95
- .code-editor-loading:hover {
96
- background-color: ${p?"#111827":"#ffffff"} !important;
97
- }
98
- `}),o?e.jsx("div",{className:"w-full h-full flex items-center justify-center bg-background",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"}),e.jsxs("span",{className:"text-gray-900 dark:text-white",children:["Loading ",t.name,"..."]})]})}):e.jsx("div",{className:"fixed inset-0 z-40 md:bg-black/50 md:flex md:items-center md:justify-center",children:e.jsx("div",{className:"code-editor-loading w-full h-full md:rounded-lg md:w-auto md:h-auto p-8 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-blue-600"}),e.jsxs("span",{className:"text-gray-900 dark:text-white",children:["Loading ",t.name,"..."]})]})})})]}):e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
99
- /* Editor toolbar panel styling */
100
- .cm-editor-toolbar-panel {
101
- padding: 8px 12px;
102
- background-color: ${p?"#1f2937":"#ffffff"};
103
- border-bottom: 1px solid ${p?"#374151":"#e5e7eb"};
104
- color: ${p?"#d1d5db":"#374151"};
105
- font-size: 14px;
106
- }
107
-
108
- .cm-toolbar-btn {
109
- padding: 4px;
110
- background: transparent;
111
- border: none;
112
- cursor: pointer;
113
- border-radius: 4px;
114
- display: inline-flex;
115
- align-items: center;
116
- justify-content: center;
117
- color: inherit;
118
- transition: background-color 0.2s;
119
- }
120
-
121
- .cm-toolbar-btn:hover {
122
- background-color: ${p?"#374151":"#f3f4f6"};
123
- }
124
- `}),e.jsx("div",{className:o?"w-full h-full flex flex-col":`fixed inset-0 z-40 md:bg-black/50 md:flex md:items-center md:justify-center md:p-4 ${N?"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"+(N?" 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:qe(t.path)})]})}),e.jsxs("div",{className:"flex items-center gap-1 md:gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:_,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(Ct,{className:"w-5 h-5 md:w-4 md:h-4"})}),e.jsx("button",{onClick:B,disabled:f,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 ${h?"bg-green-600 hover:bg-green-700":"bg-blue-600 hover:bg-blue-700"}`,children:h?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(wr,{className:"w-5 h-5 md:w-4 md:h-4"}),e.jsx("span",{className:"hidden sm:inline",children:f?"Saving...":"Save"})]})}),!o&&e.jsx("button",{onClick:ce,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:N?"Exit fullscreen":"Fullscreen",children:N?e.jsx(Wn,{className:"w-4 h-4"}):e.jsx(Un,{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(Ke,{className:"w-6 h-6 md:w-4 md:h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(jn,{ref:A,value:c,onChange:u,extensions:[...M(t.name),...T,...m?[kn.lineWrapping]:[]],theme:p?wn:void 0,height:"100%",style:{fontSize:`${I}px`,height:"100%"},basicSetup:{lineNumbers:j,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: ",c.split(`
125
- `).length]}),e.jsxs("span",{children:["Characters: ",c.length]})]}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Press Ctrl+S to save • Esc to close"})]})]})})]})}function qa({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),[c,u]=s.useState(!0);return s.useEffect(()=>{let g;const x=new AbortController;return(async()=>{try{u(!0),i(null),n(null);const b=await K(a,{signal:x.signal});if(!b.ok)throw new Error(`Request failed with status ${b.status}`);const N=await b.blob();g=URL.createObjectURL(N),n(g)}catch(b){if(b.name==="AbortError")return;console.error("Error loading image:",b),i("无法加载图像")}finally{u(!1)}})(),()=>{x.abort(),g&&URL.revokeObjectURL(g)}},[a]),e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-4xl max-h-[90vh] w-full mx-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:t.name}),e.jsx(U,{variant:"ghost",size:"sm",onClick:r,className:"h-8 w-8 p-0",children:e.jsx(Ke,{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:[c&&e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400",children:e.jsx("p",{children:"加载图像中…"})}),!c&&o&&e.jsx("img",{src:o,alt:t.name,className:"max-w-full max-h-[70vh] object-contain rounded-lg shadow-md"}),!c&&!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:qe(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:qe(t.path)})})]})})}function Ui({selectedProject:t}){const{showAlert:r,showConfirm:a}=tt(),[o,n]=s.useState([]),[l,i]=s.useState(!1),[c,u]=s.useState(new Set),[g,x]=s.useState(new Set),[f,b]=s.useState(new Set),[N,y]=s.useState(null),[p,w]=s.useState(null),[h,S]=s.useState(""),[m,v]=s.useState([]),[j,W]=s.useState(!1),[I,O]=s.useState(!1),[A,T]=s.useState(null),[M,B]=s.useState({}),[_,ce]=s.useState(null),[V,ee]=s.useState(!1),[ne,ve]=s.useState(""),[ye,xe]=s.useState(!1),[ke,Ee]=s.useState(null);s.useEffect(()=>{t&&(u(new Set),b(new Set),x(new Set),_e())},[t]),s.useEffect(()=>{if(!h.trim())v(o);else{const G=Me(o,h.toLowerCase());v(G);const re=C=>{C.forEach(F=>{F.type==="directory"&&F.children&&F.children.length>0&&(u(de=>new Set(de.add(F.path))),re(F.children))})};re(G)}},[o,h]);const Me=(G,re)=>G.reduce((C,F)=>{const de=F.name.toLowerCase().includes(re);let pe=[];return F.type==="directory"&&F.children&&(pe=Me(F.children,re)),(de||pe.length>0)&&C.push({...F,children:pe}),C},[]),_e=async()=>{i(!0);try{const G=await he.getFiles(t.name,{depth:1});if(!G.ok){const C=await G.text();console.error("❌ File fetch failed:",G.status,C),n([]);return}const re=await G.json();n(re)}catch(G){console.error("❌ Error fetching files:",G),n([])}finally{i(!1)}},Be=async(G,re=!1)=>{if(!g.has(G)&&!(!re&&f.has(G))){x(C=>new Set([...C,G]));try{const C=await he.getFiles(t.name,{dirPath:G,depth:1});if(!C.ok){console.error("Failed to load directory:",G);return}const F=await C.json();n(de=>Q(de,G,F)),b(de=>new Set([...de,G]))}catch(C){console.error("Error loading directory:",C)}finally{x(C=>{const F=new Set(C);return F.delete(G),F})}}},Q=(G,re,C)=>G.map(F=>F.path===re?{...F,children:C}:F.type==="directory"&&F.children&&F.children.length>0?{...F,children:Q(F.children,re,C)}:F),Se=s.useCallback(async G=>{if(!t||G.length===0)return;O(!0),T(null);const re=new FormData;_&&re.append("targetDir",_),G.forEach(F=>{re.append("files",F)});const C={};G.forEach(F=>{C[F.name]=0}),B(C);try{const F=await he.uploadFiles(t.name,re);if(!F.ok){const pe=await F.json();throw new Error(pe.error||"Upload failed")}const de={};G.forEach(pe=>{de[pe.name]=100}),B(de),_?(u(pe=>new Set([...pe,_])),await Be(_,!0)):await _e(),setTimeout(()=>{W(!1),B({})},1e3)}catch(F){console.error("Upload failed:",F),T(F.message)}finally{O(!1)}},[t,_]),{getRootProps:Fe,getInputProps:Ne,isDragActive:Le,open:Te}=Lr({onDrop:Se,noClick:!0,noKeyboard:!0}),ze=async(G,re,C)=>{const F=C==="directory";if(await a(`确定要删除${F?"文件夹":"文件"} "${re}" 吗?${F?`
126
- 这将删除内部的所有内容。`:""}`,{title:"确认删除",variant:"danger",confirmText:"删除"})&&t)try{const pe=await he.deleteFile(t.name,G);if(!pe.ok){const P=await pe.json();throw new Error(P.error||"Delete failed")}await _e()}catch(pe){console.error("Delete failed:",pe),r(`删除失败: ${pe.message}`,{variant:"error"})}},Ce=async()=>{const G=ne.trim();if(!G||!t)return;if(/[<>:"/\\|?*\x00-\x1f]/.test(G)){r("文件夹名称包含无效字符",{variant:"error"});return}const re=ke?`${ke}/${G}`:G;xe(!0);try{const C=await he.createDir(t.name,re);if(!C.ok){const F=await C.json();throw new Error(F.error||"Create failed")}ke?(u(F=>new Set([...F,ke])),await Be(ke,!0)):await _e(),ee(!1),ve("")}catch(C){console.error("Create directory failed:",C),r(`创建失败: ${C.message}`,{variant:"error"})}finally{xe(!1)}},He=async(G,re)=>{const C=new Set(c);C.has(G)?C.delete(G):(C.add(G),re&&!f.has(G)&&await Be(G)),u(C)},Ve=G=>{if(!G||G===0)return"0 B";const re=1024,C=["B","KB","MB","GB"],F=Math.floor(Math.log(G)/Math.log(re));return parseFloat((G/Math.pow(re,F)).toFixed(1))+" "+C[F]},je=G=>{if(!G)return"-";const re=new Date,C=new Date(G),F=Math.floor((re-C)/1e3);return F<60?"just now":F<3600?`${Math.floor(F/60)} min ago`:F<86400?`${Math.floor(F/3600)} hours ago`:F<2592e3?`${Math.floor(F/86400)} days ago`:C.toLocaleDateString()},Ae=G=>{const re=G.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","svg","webp","ico","bmp"].includes(re)},q=G=>{const re=G.toLowerCase(),C=["dockerfile","makefile","gemfile","rakefile","procfile","vagrantfile","jenkinsfile"];if(!G.includes("."))return C.includes(re);const F=G.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(F)},oe=async G=>{try{const re=await he.getFileContent(t.name,G.path);if(!re.ok)throw new Error("Download failed");const C=await re.blob(),F=URL.createObjectURL(C),de=document.createElement("a");de.href=F,de.download=G.name,document.body.appendChild(de),de.click(),document.body.removeChild(de),URL.revokeObjectURL(F)}catch(re){console.error("Download failed:",re)}},te=G=>{const re=G.split(".").pop()?.toLowerCase(),C=["js","jsx","ts","tsx","py","java","cpp","c","php","rb","go","rs"],F=["md","txt","doc","pdf"],de=["png","jpg","jpeg","gif","svg","webp","ico","bmp"];return C.includes(re)?e.jsx(Bn,{className:"w-4 h-4 text-green-500 flex-shrink-0"}):F.includes(re)?e.jsx(es,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):de.includes(re)?e.jsx(qr,{className:"w-4 h-4 text-purple-500 flex-shrink-0"}):e.jsx(qr,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"})},Ie=(G,re=0)=>G.map(C=>{const F=g.has(C.path),de=c.has(C.path),pe=C.hasChildren||C.children&&C.children.length>0;return e.jsxs("div",{className:"select-none group/item",children:[e.jsxs("div",{className:Xe("grid grid-cols-12 gap-2 p-2 hover:bg-accent items-center",C.type==="directory"||Ae(C.name)||q(C.name)?"cursor-pointer":"cursor-default"),style:{paddingLeft:`${re*16+12}px`},onClick:()=>{C.type==="directory"?He(C.path,pe):Ae(C.name)?w({name:C.name,path:C.path,projectPath:t.path,projectName:t.name}):q(C.name)&&y({name:C.name,path:C.path,projectPath:t.path,projectName:t.name})},children:[e.jsxs("div",{className:"col-span-4 flex items-center gap-2 min-w-0",children:[C.type==="directory"?F?e.jsx(Tt,{className:"w-4 h-4 text-blue-500 flex-shrink-0 animate-spin"}):de?e.jsx(gs,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):pe?e.jsx(Wt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(Wt,{className:"w-4 h-4 text-muted-foreground/50 flex-shrink-0"}):te(C.name),e.jsx("span",{className:"text-sm truncate text-foreground",children:C.name}),C.type==="directory"&&pe&&!de&&!F&&e.jsx(Ls,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground",children:C.type==="file"?Ve(C.size):"-"}),e.jsx("div",{className:"col-span-3 text-sm text-muted-foreground",children:je(C.modified)}),e.jsx("div",{className:"col-span-2 text-sm text-muted-foreground font-mono",children:C.permissionsRwx||"-"}),e.jsxs("div",{className:"col-span-1 flex justify-end items-center gap-0.5",children:[C.type==="directory"&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:P=>{P.stopPropagation(),ce(C.path),W(!0)},title:"上传文件到此文件夹",children:e.jsx(hs,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),C.type==="directory"&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:P=>{P.stopPropagation(),Ee(C.path),ve(""),ee(!0)},title:"在此文件夹下新建子文件夹",children:e.jsx(fs,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),C.type==="file"&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:P=>{P.stopPropagation(),oe(C)},title:"下载文件",children:e.jsx(Ct,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-primary"})}),e.jsx(U,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover/item:opacity-100 transition-opacity",onClick:P=>{P.stopPropagation(),ze(C.path,C.name,C.type)},title:`删除${C.type==="directory"?"文件夹":"文件"}`,children:e.jsx(lt,{className:"w-3.5 h-3.5 text-muted-foreground hover:text-destructive"})})]})]}),C.type==="directory"&&de&&e.jsx("div",{children:F?e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground items-center",style:{paddingLeft:`${(re+1)*16+12}px`},children:e.jsxs("div",{className:"col-span-4 flex items-center gap-2",children:[e.jsx(Tt,{className:"w-3 h-3 animate-spin"}),"加载中..."]})}):C.children&&C.children.length>0?Ie(C.children,re+1):e.jsx("div",{className:"grid grid-cols-12 gap-2 p-2 text-sm text-muted-foreground",style:{paddingLeft:`${(re+1)*16+12}px`},children:e.jsx("div",{className:"col-span-4",children:"空文件夹"})})})]},C.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",{...Fe(),className:Xe("h-full flex flex-col bg-card relative",Le&&"ring-2 ring-primary ring-inset"),children:[e.jsx("input",{...Ne()}),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(U,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{ce(null),W(!0)},title:"上传文件",children:e.jsx(hs,{className:"w-4 h-4"})}),e.jsx(U,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{Ee(null),ve(""),ee(!0)},title:"新建文件夹",children:e.jsx(fs,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(dt,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ze,{type:"text",placeholder:"搜索文件和文件夹...",value:h,onChange:G=>S(G.target.value),className:"pl-8 pr-8 h-8 text-sm"}),h&&e.jsx(U,{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:()=>S(""),title:"清除搜索",children:e.jsx(Ke,{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(Er,{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(Wt,{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&&h?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(dt,{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:Ie(m)})}),N&&e.jsx(vr,{file:N,onClose:()=>y(null),projectPath:N.projectPath}),p&&e.jsx(qa,{file:p,onClose:()=>w(null)}),j&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card 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:"上传文件"}),_&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 truncate max-w-xs",title:qe(_),children:["位置:",qe(_)]})]}),e.jsx(U,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>{W(!1),T(null),B({}),ce(null)},children:e.jsx(Ke,{className:"w-4 h-4"})})]}),e.jsxs("div",{onClick:Te,className:Xe("border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors","border-border hover:border-primary/50"),children:[e.jsx(hs,{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(M).length>0&&e.jsx("div",{className:"mt-4 space-y-2 max-h-40 overflow-y-auto",children:Object.entries(M).map(([G,re])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm truncate flex-1 text-foreground",children:G}),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:`${re}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10",children:[re,"%"]})]},G))}),A&&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:A})}),I&&e.jsx("div",{className:"mt-4 text-center text-sm text-muted-foreground",children:"上传中..."})]})}),V&&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:"新建文件夹"}),ke&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 truncate max-w-xs",title:qe(ke),children:["位置:",qe(ke)]})]}),e.jsx(U,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>ee(!1),children:e.jsx(Ke,{className:"w-4 h-4"})})]}),e.jsx(Ze,{autoFocus:!0,type:"text",placeholder:"文件夹名称",value:ne,onChange:G=>ve(G.target.value),onKeyDown:G=>{G.key==="Enter"&&Ce(),G.key==="Escape"&&ee(!1)},className:"mb-4"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>ee(!1),children:"取消"}),e.jsxs(U,{size:"sm",onClick:Ce,disabled:!ne.trim()||ye,children:[ye?e.jsx(Tt,{className:"w-4 h-4 animate-spin mr-1"}):null,"创建"]})]})]})})]})}var Dr=uo(),Tr=xo(),Ar=po(),Rr=ho();const Bi=`
127
- .xterm .xterm-screen {
128
- outline: none !important;
129
- }
130
- .xterm:focus .xterm-screen {
131
- outline: none !important;
132
- }
133
- .xterm-screen:focus {
134
- outline: none !important;
135
- }
136
- `;if(typeof document<"u"){const t=document.createElement("style");t.type="text/css",t.innerText=Bi,document.head.appendChild(t)}function Hi({selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:o=!1,onProcessComplete:n,minimal:l=!1,autoConnect:i=!1}){const c=s.useRef(null),u=s.useRef(null),g=s.useRef(null),x=s.useRef(null),[f,b]=s.useState(!1),[N,y]=s.useState(!1),[p,w]=s.useState(!1),[h,S]=s.useState(null),[m,v]=s.useState(!1),j=s.useRef(t),W=s.useRef(r),I=s.useRef(a),O=s.useRef(o),A=s.useRef(n);s.useEffect(()=>{j.current=t,W.current=r,I.current=a,O.current=o,A.current=n});const T=s.useCallback(async()=>{if(!(m||f))try{const ne=localStorage.getItem("auth-token");if(!ne){console.error("No authentication token found for Shell WebSocket connection");return}const ye=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/shell?token=${encodeURIComponent(ne)}`;x.current=new WebSocket(ye),x.current.onopen=()=>{b(!0),v(!1),setTimeout(()=>{g.current&&u.current&&(g.current.fit(),x.current.send(JSON.stringify({type:"init",projectPath:j.current.fullPath||j.current.path,sessionId:O.current?null:W.current?.id,hasSession:O.current?!1:!!W.current,provider:O.current?"plain-shell":W.current?.__provider||"claude",cols:u.current.cols,rows:u.current.rows,initialCommand:I.current,isPlainShell:O.current})))},100)},x.current.onmessage=xe=>{try{const ke=JSON.parse(xe.data);if(ke.type==="output"){let Ee=ke.data;if(O.current&&A.current){const Me=Ee.replace(/\x1b\[[0-9;]*m/g,"");if(Me.includes("Process exited with code 0"))A.current(0);else if(Me.match(/Process exited with code (\d+)/)){const _e=parseInt(Me.match(/Process exited with code (\d+)/)[1]);_e!==0&&A.current(_e)}}u.current&&u.current.write(Ee)}else ke.type==="url_open"&&window.open(ke.url,"_blank")}catch(ke){console.error("[Shell] Error handling WebSocket message:",ke,xe.data)}},x.current.onclose=xe=>{b(!1),v(!1),u.current&&(u.current.clear(),u.current.write("\x1B[2J\x1B[H"))},x.current.onerror=xe=>{b(!1),v(!1)}}catch{b(!1),v(!1)}},[m,f]),M=s.useCallback(()=>{!N||f||m||(v(!0),T())},[N,f,m,T]),B=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")),b(!1),v(!1)},[]),_=s.useMemo(()=>r?r.summary||"New Session":null,[r]),ce=s.useMemo(()=>_?_.slice(0,30):null,[_]),V=s.useMemo(()=>_?_.slice(0,50):null,[_]),ee=()=>{w(!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,g.current=null),b(!1),y(!1),setTimeout(()=>{w(!1)},200)};return s.useEffect(()=>{const ne=r?.id||null;h!==null&&h!==ne&&N&&B(),S(ne)},[r?.id,N,B]),s.useEffect(()=>{if(!c.current||!t||p||u.current)return;u.current=new Dr.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Menlo, Monaco, "Courier New", monospace',allowProposedApi:!0,allowTransparency:!1,convertEol:!0,scrollback:1e4,tabStopWidth:4,windowsMode:!1,macOptionIsMeta:!0,macOptionClickForcesSelection:!1,theme:{background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#ffffff",cursorAccent:"#1e1e1e",selection:"#264f78",selectionForeground:"#ffffff",black:"#000000",red:"#cd3131",green:"#0dbc79",yellow:"#e5e510",blue:"#2472c8",magenta:"#bc3fbc",cyan:"#11a8cd",white:"#e5e5e5",brightBlack:"#666666",brightRed:"#f14c4c",brightGreen:"#23d18b",brightYellow:"#f5f543",brightBlue:"#3b8eea",brightMagenta:"#d670d6",brightCyan:"#29b8db",brightWhite:"#ffffff",extendedAnsi:["#000000","#800000","#008000","#808000","#000080","#800080","#008080","#c0c0c0","#808080","#ff0000","#00ff00","#ffff00","#0000ff","#ff00ff","#00ffff","#ffffff"]}}),g.current=new Tr.FitAddon;const ne=new Ar.WebglAddon,ve=new Rr.WebLinksAddon;u.current.loadAddon(g.current),u.current.loadAddon(ve);try{u.current.loadAddon(ne)}catch{console.warn("[Shell] WebGL renderer unavailable, using Canvas fallback")}u.current.open(c.current),u.current.attachCustomKeyEventHandler(xe=>(xe.ctrlKey||xe.metaKey)&&xe.key==="c"&&u.current.hasSelection()?(document.execCommand("copy"),!1):(xe.ctrlKey||xe.metaKey)&&xe.key==="v"?(navigator.clipboard.readText().then(ke=>{x.current&&x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"input",data:ke}))}).catch(()=>{}),!1):!0),setTimeout(()=>{g.current&&(g.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),y(!0),u.current.onData(xe=>{x.current&&x.current.readyState===WebSocket.OPEN&&x.current.send(JSON.stringify({type:"input",data:xe}))});const ye=new ResizeObserver(()=>{g.current&&u.current&&setTimeout(()=>{g.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 c.current&&ye.observe(c.current),()=>{ye.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,p]),s.useEffect(()=>{!i||!N||m||f||M()},[i,N,m,f,M]),t?l?e.jsx("div",{className:"h-full w-full bg-gray-900",children:e.jsx("div",{ref:c,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 ${f?"bg-green-500":"bg-red-500"}`}),r&&e.jsxs("span",{className:"text-xs text-blue-300",children:["(",ce,"...)"]}),!r&&e.jsx("span",{className:"text-xs text-gray-400",children:"(新会话)"}),!N&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),p&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[f&&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:"断开 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:ee,disabled:p||f,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:c,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!N&&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:"加载终端中..."})}),N&&!f&&!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:M,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: ${V}...`:"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 Ji({project:t,session:r=null,command:a=null,isPlainShell:o=null,autoConnect:n=!0,onComplete:l=null,onClose:i=null,title:c=null,className:u="",showHeader:g=!0,compact:x=!1,minimal:f=!1}){const[b,N]=s.useState(!1),y=o!==null?o:a!==null,p=s.useCallback(w=>{N(!0),l&&l(w)},[l]);return t?e.jsxs("div",{className:`h-full w-full flex flex-col ${u}`,children:[!f&&g&&c&&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:c}),b&&e.jsx("span",{className:"text-xs text-green-400",children:"(已完成)"})]}),i&&e.jsx("button",{onClick:i,className:"text-gray-400 hover:text-white",title:"关闭",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsx("div",{className:"flex-1 w-full min-h-0",children:e.jsx(Hi,{selectedProject:t,selectedSession:r,initialCommand:a,isPlainShell:y,onProcessComplete:p,minimal:f,autoConnect:f?!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 qi({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),[c,u]=s.useState(!1),[g,x]=s.useState(!1),[f,b]=s.useState(!1),[N,y]=s.useState(!1),p=s.useRef(t);s.useEffect(()=>{p.current=t});const w=s.useCallback(async()=>{if(!(N||c))try{const v=localStorage.getItem("auth-token");if(!v){console.error("No authentication token found for Codex WebSocket connection");return}const W=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/codex?token=${encodeURIComponent(v)}`;i.current=new WebSocket(W),i.current.onopen=()=>{u(!0),y(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:p.current.fullPath||p.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=I=>{try{const O=JSON.parse(I.data);O.type==="output"?n.current&&n.current.write(O.data):O.type==="url_open"&&window.open(O.url,"_blank")}catch(O){console.error("[CodexShell] Error handling WebSocket message:",O)}},i.current.onclose=()=>{u(!1),y(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{u(!1),y(!1)}}catch{u(!1),y(!1)}},[N,c]),h=s.useCallback(()=>{!g||c||N||(y(!0),w())},[g,c,N,w]),S=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),y(!1)},[]),m=()=>{b(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),u(!1),x(!1),setTimeout(()=>b(!1),200)};return s.useEffect(()=>{if(!o.current||!t||f||n.current)return;n.current=new Dr.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 Tr.FitAddon;const v=new Ar.WebglAddon,j=new Rr.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(j);try{n.current.loadAddon(v)}catch{console.warn("[CodexShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(I=>(I.ctrlKey||I.metaKey)&&I.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(I.ctrlKey||I.metaKey)&&I.key==="v"?(navigator.clipboard.readText().then(O=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:O}))}).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(I=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:I}))});const W=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&&W.observe(o.current),()=>{W.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,f]),s.useEffect(()=>{!a||!g||N||c||h()},[a,g,N,c,h]),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 ${c?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-300 font-medium",children:"Codex"}),!g&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),f&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[c&&e.jsxs("button",{onClick:S,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:f||c,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Codex(先断开连接)",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),e.jsx("span",{children:"重启"})]})]})]})}),e.jsxs("div",{className:"flex-1 p-2 overflow-hidden relative",children:[e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!g&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90",children:e.jsx("div",{className:"text-white",children:"加载终端中..."})}),g&&!c&&!N&&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:h,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"]})]})}),N&&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 Ki({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(qi,{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 Vi({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),[c,u]=s.useState(!1),[g,x]=s.useState(!1),[f,b]=s.useState(!1),[N,y]=s.useState(!1),p=s.useRef(t);s.useEffect(()=>{p.current=t});const w=s.useCallback(async()=>{if(!(N||c))try{const v=localStorage.getItem("auth-token");if(!v){console.error("No authentication token found for Gemini WebSocket connection");return}const W=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/gemini?token=${encodeURIComponent(v)}`;i.current=new WebSocket(W),i.current.onopen=()=>{u(!0),y(!1),setTimeout(()=>{l.current&&n.current&&(l.current.fit(),i.current.send(JSON.stringify({type:"init",projectPath:p.current.fullPath||p.current.path,cols:n.current.cols,rows:n.current.rows})))},100)},i.current.onmessage=I=>{try{const O=JSON.parse(I.data);O.type==="output"?n.current&&n.current.write(O.data):O.type==="url_open"&&window.open(O.url,"_blank")}catch(O){console.error("[GeminiShell] Error handling WebSocket message:",O)}},i.current.onclose=()=>{u(!1),y(!1),n.current&&(n.current.clear(),n.current.write("\x1B[2J\x1B[H"))},i.current.onerror=()=>{u(!1),y(!1)}}catch{u(!1),y(!1)}},[N,c]),h=s.useCallback(()=>{!g||c||N||(y(!0),w())},[g,c,N,w]),S=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),y(!1)},[]),m=()=>{b(!0),i.current&&(i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"terminate"})),i.current.close(),i.current=null),n.current&&(n.current.dispose(),n.current=null,l.current=null),u(!1),x(!1),setTimeout(()=>b(!1),200)};return s.useEffect(()=>{if(!o.current||!t||f||n.current)return;n.current=new Dr.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 Tr.FitAddon;const v=new Ar.WebglAddon,j=new Rr.WebLinksAddon;n.current.loadAddon(l.current),n.current.loadAddon(j);try{n.current.loadAddon(v)}catch{console.warn("[GeminiShell] WebGL renderer unavailable, using Canvas fallback")}n.current.open(o.current),n.current.attachCustomKeyEventHandler(I=>(I.ctrlKey||I.metaKey)&&I.key==="c"&&n.current.hasSelection()?(document.execCommand("copy"),!1):(I.ctrlKey||I.metaKey)&&I.key==="v"?(navigator.clipboard.readText().then(O=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:O}))}).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(I=>{i.current&&i.current.readyState===WebSocket.OPEN&&i.current.send(JSON.stringify({type:"input",data:I}))});const W=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&&W.observe(o.current),()=>{W.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,f]),s.useEffect(()=>{!a||!g||N||c||h()},[a,g,N,c,h]),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 ${c?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-xs text-gray-300 font-medium",children:"Gemini"}),!g&&e.jsx("span",{className:"text-xs text-yellow-400",children:"(正在初始化...)"}),f&&e.jsx("span",{className:"text-xs text-blue-400",children:"(正在重启...)"})]}),e.jsxs("div",{className:"flex items-center space-x-3",children:[c&&e.jsxs("button",{onClick:S,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:f||c,className:"text-xs text-gray-400 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed flex items-center space-x-1",title:"重启 Gemini(先断开连接)",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),e.jsx("span",{children:"重启"})]})]})]})}),e.jsxs("div",{className:"flex-1 p-2 overflow-hidden relative",children:[e.jsx("div",{ref:o,className:"h-full w-full focus:outline-none",style:{outline:"none"}}),!g&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-900 bg-opacity-90",children:e.jsx("div",{className:"text-white",children:"加载终端中..."})}),g&&!c&&!N&&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:h,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"]})]})}),N&&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 Gi({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(Vi,{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 Yi extends ft.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 xs=({children:t,content:r,position:a="top",className:o="",delay:n=500})=>{const[l,i]=s.useState(!1),[c,u]=s.useState(null),g=()=>{const N=setTimeout(()=>{i(!0)},n);u(N)},x=()=>{c&&(clearTimeout(c),u(null)),i(!1)},f=()=>{switch(a){case"top":return"bottom-full left-1/2 transform -translate-x-1/2 mb-2";case"bottom":return"top-full left-1/2 transform -translate-x-1/2 mt-2";case"left":return"right-full top-1/2 transform -translate-y-1/2 mr-2";case"right":return"left-full top-1/2 transform -translate-y-1/2 ml-2";default:return"bottom-full left-1/2 transform -translate-x-1/2 mb-2"}},b=()=>{switch(a){case"top":return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100";case"bottom":return"bottom-full left-1/2 transform -translate-x-1/2 border-b-gray-900 dark:border-b-gray-100";case"left":return"left-full top-1/2 transform -translate-y-1/2 border-l-gray-900 dark:border-l-gray-100";case"right":return"right-full top-1/2 transform -translate-y-1/2 border-r-gray-900 dark:border-r-gray-100";default:return"top-full left-1/2 transform -translate-x-1/2 border-t-gray-900 dark:border-t-gray-100"}};return r?e.jsxs("div",{className:"relative inline-block",onMouseEnter:g,onMouseLeave:x,children:[t,l&&e.jsxs("div",{className:Xe("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",f(),o),children:[r,e.jsx("div",{className:Xe("absolute w-0 h-0 border-4 border-transparent",b())})]})]}):t};function Qi({selectedProject:t,selectedSession:r,activeTab:a,setActiveTab:o,ws:n,sendMessage:l,messages:i,isMobile:c,isPWA:u,onMenuClick:g,isLoading:x,onInputFocusChange:f,onSessionActive:b,onSessionInactive:N,onSessionProcessing:y,onSessionNotProcessing:p,processingSessions:w,onReplaceTemporarySession:h,onNavigateToSession:S,onShowSettings:m,autoScrollToBottom:v,sendByCtrlEnter:j,externalMessageUpdate:W,limitStatus:I,onLimitBlocked:O,checkLimitStatus:A}){const{showConfirm:T}=tt(),{hasPermission:M}=mt(),[B,_]=s.useState(null),[ce,V]=s.useState(null),[ee,ne]=s.useState(600),[ve,ye]=s.useState(!1),[xe,ke]=s.useState(!1),Ee=s.useRef(null),Me=async Ne=>{const Le="previewTabAcknowledged";if(!localStorage.getItem(Le)){const Te=await T("此功能的对话记录不会显示在当前网页的会话列表中,与 Chat 是两套独立的系统,请注意区分。",{title:"预览功能提示",subtitle:Ne==="codex"?"Codex":"Gemini CLI",variant:"warning",confirmText:"我知道了,继续",cancelText:"取消",checkboxLabel:"不再提醒"});if(!Te?.confirmed)return;Te.checked&&localStorage.setItem(Le,"1")}o(Ne)};s.useEffect(()=>{a==="shell"&&A&&A()},[a,A]);const _e=["png","jpg","jpeg","gif","svg","webp","ico","bmp"],Be=(Ne,Le=null)=>{const Te=Ne.split(".").pop()?.toLowerCase();if(_e.includes(Te)){V({name:Ne.split("/").pop(),path:Ne,projectName:t?.name,projectPath:t?.path});return}const ze={name:Ne.split("/").pop(),path:Ne,projectName:t?.name,diffInfo:Le};_(ze)},Q=()=>{_(null),ke(!1)},Se=()=>{ke(!xe)},Fe=Ne=>{c||(ye(!0),Ne.preventDefault())};return s.useEffect(()=>{const Ne=Te=>{if(!ve)return;const ze=Ee.current?.parentElement;if(!ze)return;const Ce=ze.getBoundingClientRect(),He=Ce.right-Te.clientX,Ve=300,je=Ce.width*.8;He>=Ve&&He<=je&&ne(He)},Le=()=>{ye(!1)};return ve&&(document.addEventListener("mousemove",Ne),document.addEventListener("mouseup",Le),document.body.style.cursor="col-resize",document.body.style.userSelect="none"),()=>{document.removeEventListener("mousemove",Ne),document.removeEventListener("mouseup",Le),document.body.style.cursor="",document.body.style.userSelect=""}},[ve]),x?e.jsxs("div",{className:"h-full flex flex-col",children:[c&&e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsx("button",{onClick:g,className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 pwa-menu-button",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-4",children:e.jsx("div",{className:"w-full h-full rounded-full border-4 border-gray-200 border-t-blue-500",style:{animation:"spin 1s linear infinite",WebkitAnimation:"spin 1s linear infinite",MozAnimation:"spin 1s linear infinite"}})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"正在加载 AgentHub"}),e.jsx("p",{children:"正在设置您的工作区..."})]})})]}):t?e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between relative",children:[e.jsxs("div",{className:"flex items-center space-x-2 min-w-0 flex-1",children:[c&&e.jsx("button",{onClick:g,onTouchStart:Ne=>{Ne.preventDefault(),g()},className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 touch-manipulation active:scale-95 pwa-menu-button flex-shrink-0",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),e.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.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]}):a==="chat"&&!r?e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white",children:"新会话"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]}):e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white",children:a==="files"?"项目文件":"项目"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:t.displayName})]})})})]}),e.jsx("div",{className:"flex-shrink-0 hidden sm:block",children:e.jsxs("div",{className:"relative flex bg-gray-100 dark:bg-gray-800 rounded-lg p-1",children:[e.jsx(xs,{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(xs,{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"})]})})}),M("claude_shell")&&e.jsx(xs,{content:I&&!I.allowed?"使用已达上限":"Claude Code",position:"bottom",children:e.jsx("button",{onClick:()=>{if(I&&!I.allowed){O?.(I.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 ${I&&!I.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"})]})})}),M("codex_shell")&&e.jsx(xs,{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"})]})})}),M("gemini_shell")&&e.jsx(xs,{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 ${B?"mr-0":""} ${xe?"hidden":""}`,children:[e.jsx("div",{className:`h-full ${a==="chat"?"block":"hidden"}`,children:e.jsx(Yi,{showDetails:!0,children:e.jsx(Wi,{selectedProject:t,selectedSession:r,ws:n,sendMessage:l,messages:i,onFileOpen:Be,onInputFocusChange:f,onSessionActive:b,onSessionInactive:N,onSessionProcessing:y,onSessionNotProcessing:p,processingSessions:w,onReplaceTemporarySession:h,onNavigateToSession:S,onShowSettings:m,autoScrollToBottom:v,sendByCtrlEnter:j,externalMessageUpdate:W,limitStatus:I,onLimitExceeded:O,checkLimitStatus:A})})}),a==="files"&&e.jsx("div",{className:"h-full overflow-hidden",children:e.jsx(Ui,{selectedProject:t})}),a==="shell"&&e.jsxs("div",{className:"h-full w-full overflow-hidden relative",children:[e.jsx(Ji,{project:t,session:r,showHeader:!1}),I&&!I.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:I.reason==="total_limit_exceeded"?"使用上限已达到":"今日使用上限已达到"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:I.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(Ki,{project:t,showHeader:!1})}),a==="gemini"&&e.jsx("div",{className:"h-full w-full overflow-hidden relative",children:e.jsx(Gi,{project:t,showHeader:!1})}),e.jsx("div",{className:`h-full overflow-hidden ${a==="preview"?"block":"hidden"}`})]}),B&&!c&&e.jsxs(e.Fragment,{children:[!xe&&e.jsx("div",{ref:Ee,onMouseDown:Fe,className:"flex-shrink-0 w-1 bg-gray-200 dark:bg-gray-700 hover:bg-blue-500 dark:hover:bg-blue-600 cursor-col-resize transition-colors relative group",title:"Drag to resize",children:e.jsx("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-1 bg-blue-500 dark:bg-blue-600 opacity-0 group-hover:opacity-100 transition-opacity"})}),e.jsx("div",{className:`flex-shrink-0 border-l border-gray-200 dark:border-gray-700 h-full overflow-hidden ${xe?"flex-1":""}`,style:xe?{}:{width:`${ee}px`},children:e.jsx(vr,{file:B,onClose:Q,projectPath:t?.path,isSidebar:!0,isExpanded:xe,onToggleExpand:Se})})]})]}),B&&c&&e.jsx(vr,{file:B,onClose:Q,projectPath:t?.path,isSidebar:!1}),ce&&e.jsx(qa,{file:ce,onClose:()=>V(null)})]}):e.jsxs("div",{className:"h-full flex flex-col",children:[c&&e.jsx("div",{className:"bg-background border-b border-border p-2 sm:p-3 pwa-header-safe flex-shrink-0",children:e.jsx("button",{onClick:g,className:"p-2 text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 pwa-menu-button",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})})}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400 max-w-md mx-auto px-6",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-6 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-5l-2-2H5a2 2 0 00-2 2z"})})}),e.jsx("h2",{className:"text-2xl font-semibold mb-3 text-gray-900 dark:text-white",children:"选择您的项目"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-300 mb-6 leading-relaxed",children:"从侧边栏选择一个项目,开始与 AgentHub 进行交流。每个项目包含您的聊天会话和文件历史。"}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 rounded-lg p-4 border border-blue-200 dark:border-blue-800",children:e.jsxs("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:["💡 ",e.jsx("strong",{children:"提示:"})," ",c?"点击上方菜单按钮访问项目":M("create_project")?"点击侧边栏中的文件夹图标创建新项目":"点击侧边栏中的「安装 Agent 项目」按钮来创建项目"]})})]})})]})}const Xi=ft.memo(Qi);function Zi({activeTab:t,setActiveTab:r,isInputFocused:a}){const o=[{id:"chat",icon:_s,onClick:()=>r("chat")},{id:"shell",icon:kr,onClick:()=>r("shell")},{id:"files",icon:Wt,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:c=>{c.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 Ka=s.createContext(),el=()=>{const t=s.useContext(Ka);if(!t)throw new Error("useTheme must be used within a ThemeProvider");return t},tl=({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=c=>{localStorage.getItem("theme")||a(c.matches)};return l.addEventListener("change",i),()=>l.removeEventListener("change",i)},[]);const n={isDarkMode:r,toggleDarkMode:()=>{a(l=>!l)}};return e.jsx(Ka.Provider,{value:n,children:t})},sl=["Bash(git log:*)","Bash(git diff:*)","Bash(git status:*)","Write","Read","Edit","Glob","Grep","MultiEdit","Task","TodoWrite","TodoRead","WebFetch","WebSearch"];function rl({skipPermissions:t,setSkipPermissions:r,allowedTools:a,setAllowedTools:o,disallowedTools:n,setDisallowedTools:l,newAllowedTool:i,setNewAllowedTool:c,newDisallowedTool:u,setNewDisallowedTool:g}){const x=y=>{y&&!a.includes(y)&&(o([...a,y]),c(""))},f=y=>{o(a.filter(p=>p!==y))},b=y=>{y&&!n.includes(y)&&(l([...n,y]),g(""))},N=y=>{l(n.filter(p=>p!==y))};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($s,{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(At,{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:y=>r(y.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($t,{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(Ze,{value:i,onChange:y=>c(y.target.value),placeholder:'e.g., "Bash(git log:*)" or "Write"',onKeyPress:y=>{y.key==="Enter"&&(y.preventDefault(),x(i))},className:"flex-1 h-10"}),e.jsxs(U,{onClick:()=>x(i),disabled:!i,size:"sm",className:"h-10 px-4",children:[e.jsx(Rt,{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:sl.map(y=>e.jsx(U,{variant:"outline",size:"sm",onClick:()=>x(y),disabled:a.includes(y),className:"text-xs h-8",children:y},y))})]}),e.jsxs("div",{className:"space-y-2",children:[a.map(y=>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:y}),e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>f(y),className:"text-green-600 hover:text-green-700",children:e.jsx(Ke,{className:"w-4 h-4"})})]},y)),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(At,{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(Ze,{value:u,onChange:y=>g(y.target.value),placeholder:'e.g., "Bash(rm:*)"',onKeyPress:y=>{y.key==="Enter"&&(y.preventDefault(),b(u))},className:"flex-1 h-10"}),e.jsxs(U,{onClick:()=>b(u),disabled:!u,size:"sm",className:"h-10 px-4",children:[e.jsx(Rt,{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(y=>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:y}),e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>N(y),className:"text-red-600 hover:text-red-700",children:e.jsx(Ke,{className:"w-4 h-4"})})]},y)),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 al({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($t,{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(At,{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 nl({agent:t,...r}){return t==="claude"?e.jsx(rl,{...r}):t==="codex"?e.jsx(al,{...r}):null}const ol=t=>{switch(t){case"stdio":return e.jsx(kr,{className:"w-4 h-4"});case"sse":return e.jsx(Sr,{className:"w-4 h-4"});case"http":return e.jsx(Is,{className:"w-4 h-4"});default:return e.jsx(zs,{className:"w-4 h-4"})}};function il({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(zs,{className:"w-5 h-5 text-purple-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"MCP 服务器"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Model Context Protocol 服务器为 AgentHub 提供额外的工具和数据源"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs(U,{onClick:r,className:"bg-purple-600 hover:bg-purple-700 text-white",size:"sm",children:[e.jsx(Rt,{className:"w-4 h-4 mr-2"}),"添加 MCP 服务器"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(U,{onClick:i,variant:"outline",size:"sm",children:[e.jsx(Nr,{className:"w-4 h-4 mr-2"}),"MCP 商店"]})})]}),e.jsxs("div",{className:"space-y-2",children:[t.map(c=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[ol(c.type),e.jsx("span",{className:"font-medium text-foreground",children:c.name}),e.jsx(Qe,{variant:"outline",className:"text-xs",children:c.type}),e.jsx(Qe,{variant:"outline",className:"text-xs",children:c.scope==="local"?"local":c.scope==="user"?"user":c.scope})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[c.type==="stdio"&&c.config?.command&&e.jsxs("div",{children:["命令:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:c.config.command})]}),(c.type==="sse"||c.type==="http")&&c.config?.url&&e.jsxs("div",{children:["URL:",e.jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded text-xs",children:c.config.url})]}),c.config?.args&&c.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:c.config.args.join(" ")})]})]}),n?.[c.id]&&e.jsx("div",{className:`mt-2 p-2 rounded text-xs ${n[c.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[c.id].message})}),l?.[c.id]&&l[c.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[c.id].tools.length,"):"]}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[l[c.id].tools.slice(0,5).map((u,g)=>e.jsx("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded",children:u.name},g)),l[c.id].tools.length>5&&e.jsxs("span",{className:"text-xs opacity-75",children:["+",l[c.id].tools.length-5," 更多"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(U,{onClick:()=>a(c),variant:"ghost",size:"sm",className:"text-gray-600 hover:text-gray-700",title:"编辑服务器",children:e.jsx(lr,{className:"w-4 h-4"})}),e.jsx(U,{onClick:()=>o(c.id,c.scope),variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",title:"删除服务器",children:e.jsx(lt,{className:"w-4 h-4"})})]})]})},c.id)),t.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"未配置 MCP 服务器"})]})]})}function ll(t){return e.jsx(il,{...t})}const cl=[{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)使用的模型"}],dl=s.forwardRef(function({onStatusChange:r},a){const[o,n]=s.useState({}),[l,i]=s.useState({}),[c,u]=s.useState(!0),[g,x]=s.useState(!1),[f,b]=s.useState(null),[N,y]=s.useState(null),p=JSON.stringify(o)!==JSON.stringify(l);s.useEffect(()=>{r?.({saving:g,hasChanges:p})},[g,p,r]),s.useEffect(()=>{w()},[]),s.useEffect(()=>{if(f){const m=setTimeout(()=>b(null),3e3);return()=>clearTimeout(m)}},[f]);const w=async()=>{try{u(!0),y(null);const m=await K("/api/settings/models");if(m.ok){const v=await m.json();n(v.models||{}),i(v.models||{})}else{const v=await m.json();y(v.error||"加载模型配置失败")}}catch(m){y(m.message)}finally{u(!1)}},h=async()=>{try{x(!0),b(null);const m=await K("/api/settings/models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({models:o})});if(m.ok)return b("success"),i({...o}),!0;{const v=await m.json();return b("error"),y(v.error||"保存失败"),!1}}catch(m){return b("error"),y(m.message),!1}finally{x(!1)}},S=()=>{n({...l}),b(null)};return s.useImperativeHandle(a,()=>({save:h,reset:S,get hasChanges(){return p},get saving(){return g}}),[p,g,o,l]),c?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($s,{className:"w-4 h-4 text-blue-500 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{children:"自定义模型 ID 来覆盖 AgentHub 和 Claude Code 使用的默认模型。留空表示使用默认模型。"}),e.jsx("p",{className:"mt-1 text-blue-600 dark:text-blue-400",children:"非 Claude 模型将按 Sonnet 定价计费,但统计中会记录实际模型 ID。"})]})]}),N&&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:N}),f==="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:"模型配置已保存"}),cl.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:v=>n(j=>({...j,[m.key]:v.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 ml({onClose:t,onInstalled:r,onOpenRepoManager:a}){const{showAlert:o}=tt(),[n,l]=s.useState([]),[i,c]=s.useState([]),[u,g]=s.useState(!0),[x,f]=s.useState(null),[b,N]=s.useState(""),[y,p]=s.useState("all"),[w,h]=s.useState(null);s.useEffect(()=>{S()},[]);const S=async(j=!1)=>{try{g(!0),f(null),j&&await K("/api/skills/repos/refresh",{method:"POST"});const[W,I]=await Promise.all([K("/api/skills/available"),K("/api/skills/repos")]);if(W.ok){const O=await W.json();l(O.skills||[])}if(I.ok){const O=await I.json();c(O.repos||[])}}catch(W){f(W.message)}finally{g(!1)}},m=async j=>{try{h(j.name);const W=await K(`/api/skills/install/${j.name}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillPath:j.path})});if(W.ok)S(),r?.();else{const I=await W.json();o(I.error||"安装技能失败",{variant:"error"})}}catch(W){o(W.message,{variant:"error"})}finally{h(null)}},v=n.filter(j=>{if(b){const W=b.toLowerCase();if(!j.name.toLowerCase().includes(W)&&!j.title?.toLowerCase().includes(W)&&!j.description?.toLowerCase().includes(W))return!1}return!(y!=="all"&&j.repository!==y)});return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-background rounded-xl shadow-xl w-full max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Skills 管理"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(U,{variant:"ghost",size:"sm",onClick:()=>S(!0),disabled:u,children:[e.jsx(nt,{className:`w-4 h-4 ${u?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(U,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Pt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(U,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Ke,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2",children:e.jsx("h3",{className:"text-amber-500 font-medium",children:"发现技能"})}),e.jsxs("div",{className:"px-4 pb-4 flex flex-wrap gap-3",children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative",children:[e.jsx(dt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ze,{type:"text",placeholder:"搜索技能名称或描述...",value:b,onChange:j=>N(j.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:y,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:"全部"}),i.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:[x&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm mb-4",children:x}),u?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):v.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:n.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的技能"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加技能仓库"}),e.jsxs(U,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Pt,{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:v.map(j=>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:j.title||j.name}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["skills/",j.name]}),e.jsx(Qe,{variant:"outline",className:"text-xs ml-2",children:j.repository})]})]}),j.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:j.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-auto pt-2",children:[e.jsxs(U,{variant:"ghost",size:"sm",onClick:()=>window.open(`https://github.com/${j.repository}`,"_blank"),children:[e.jsx(wa,{className:"w-4 h-4 mr-1"}),"查看"]}),j.installed?e.jsx(U,{size:"sm",disabled:!0,variant:"outline",className:"ml-auto",children:"已安装"}):e.jsxs(U,{size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white ml-auto",onClick:()=>m(j),disabled:w===j.name,children:[e.jsx(Ct,{className:"w-4 h-4 mr-1"}),w===j.name?"安装中...":"安装"]})]})]})},`${j.repository}-${j.name}`))})]})]})})}function ul({onClose:t,onChanged:r}){const{showAlert:a,showConfirm:o}=tt(),[n,l]=s.useState([]),[i,c]=s.useState(!0),[u,g]=s.useState(null),[x,f]=s.useState(""),[b,N]=s.useState("main"),[y,p]=s.useState(!1),[w,h]=s.useState(null);s.useEffect(()=>{S()},[]);const S=async()=>{try{c(!0),g(null);const j=await K("/api/skills/repos");if(j.ok){const W=await j.json();l(W.repos||[])}else{const W=await j.json();g(W.error||"Failed to fetch repos")}}catch(j){g(j.message)}finally{c(!1)}},m=async j=>{if(j.preventDefault(),!x.trim()){g("请输入仓库 URL");return}try{p(!0),g(null);const W=await K("/api/skills/repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:x.trim(),branch:b.trim()||"main"})});if(W.ok)f(""),N("main"),S(),r?.();else{const I=await W.json();g(I.error||"Failed to add repo")}}catch(W){g(W.message)}finally{p(!1)}},v=async(j,W)=>{if(await o(`确定要移除仓库 "${j}/${W}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{h(`${j}/${W}`);const I=await K(`/api/skills/repos/${j}/${W}`,{method:"DELETE"});if(I.ok)S(),r?.();else{const O=await I.json();a(O.error||"移除仓库失败",{variant:"error"})}}catch(I){a(I.message,{variant:"error"})}finally{h(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(U,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(rs,{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(Ze,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:x,onChange:j=>f(j.target.value),disabled:y})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-muted-foreground mb-1",children:"分支"}),e.jsx(Ze,{type:"text",placeholder:"main",value:b,onChange:j=>N(j.target.value),disabled:y})]}),e.jsxs(U,{type:"submit",disabled:y||!x.trim(),className:"bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(Rt,{className:"w-4 h-4 mr-2"}),y?"添加中...":"添加仓库"]})]})]}),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(ka,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有添加任何仓库"})]}):n.map(j=>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:[j.owner,"/",j.repo]}),j.isSystem&&e.jsx(Qe,{variant:"outline",className:"text-xs bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300",children:"内置"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Nr,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Qe,{variant:"outline",className:"text-xs",children:["识别到 ",j.skillCount," 个技能"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[!j.isSystem&&j.url&&e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>window.open(j.url,"_blank"),children:e.jsx(wa,{className:"w-4 h-4"})}),!j.isSystem&&e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>v(j.owner,j.repo),disabled:w===`${j.owner}/${j.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(lt,{className:"w-4 h-4"})})]})]})},`${j.owner}/${j.repo}`))]})]})]})})}function xl(){const{showAlert:t,showConfirm:r}=tt(),[a,o]=s.useState([]),[n,l]=s.useState(!0),[i,c]=s.useState(null),[u,g]=s.useState(!1),[x,f]=s.useState(!1),[b,N]=s.useState(!1),y=s.useRef(null);s.useEffect(()=>{p()},[]);const p=async()=>{try{l(!0),c(null);const v=await K("/api/skills");if(v.ok){const j=await v.json();o(j.skills||[])}else{const j=await v.json();c(j.error||"Failed to fetch skills")}}catch(v){c(v.message)}finally{l(!1)}},w=async v=>{if(await r(`确定要删除技能 "${v}" 吗?`,{title:"删除技能",variant:"danger",confirmText:"确认删除"}))try{const j=await K(`/api/skills/${v}`,{method:"DELETE"});if(j.ok)p();else{const W=await j.json();t(W.error||"删除技能失败",{variant:"error"})}}catch(j){t(j.message,{variant:"error"})}},h=()=>{y.current?.click()},S=async v=>{const j=v.target.files?.[0];if(j)try{N(!0);const W=new FormData;W.append("skillZip",j);const I=await K("/api/skills/import",{method:"POST",body:W});if(I.ok)p();else{const O=await I.json();t(O.error||"导入技能失败",{variant:"error"})}}catch(W){t(W.message,{variant:"error"})}finally{N(!1),y.current&&(y.current.value="")}},m=(v,j)=>{switch(v){case"repo":return e.jsx(Qe,{variant:"outline",className:"text-xs bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300",children:j||"仓库"});case"imported":return e.jsx(Qe,{variant:"outline",className:"text-xs bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",children:"导入"});default:return e.jsx(Qe,{variant:"outline",className:"text-xs",children:"本地"})}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(cr,{className:"w-5 h-5 text-amber-500"}),e.jsx("h3",{className:"text-lg font-medium text-foreground",children:"Skills 管理"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Skills 是 AgentHub 的扩展能力,可以通过 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:a.length})," 个技能"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{ref:y,type:"file",accept:".zip",className:"hidden",onChange:S}),e.jsxs(U,{onClick:h,variant:"outline",size:"sm",disabled:b,children:[e.jsx(Ct,{className:"w-4 h-4 mr-2"}),b?"导入中...":"导入已有"]}),e.jsxs(U,{onClick:()=>g(!0),className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:[e.jsx(dt,{className:"w-4 h-4 mr-2"}),"发现技能"]})]})]}),i&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-red-800 dark:text-red-200 text-sm",children:i}),e.jsx("div",{className:"space-y-2",children:n?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):a.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(cr,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"还没有安装任何技能"}),e.jsx("p",{className:"text-xs mt-2",children:'点击"发现技能"从仓库安装,或"导入已有"上传本地技能'})]}):a.map(v=>e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"font-medium text-foreground",children:v.title||v.name}),m(v.source,v.repository)]}),v.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:v.description})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4 shrink-0",children:e.jsx(U,{variant:"ghost",size:"sm",onClick:()=>w(v.name),className:"text-red-500 hover:text-red-600",title:"删除技能",children:e.jsx(lt,{className:"w-4 h-4"})})})]})},v.name))}),u&&e.jsx(ml,{onClose:()=>g(!1),onInstalled:p,onOpenRepoManager:()=>{g(!1),f(!0)}}),x&&e.jsx(ul,{onClose:()=>f(!1),onChanged:()=>{}})]})}function pl({projects:t=[],onClose:r,onSubmitted:a}){const{showAlert:o}=tt(),[n,l]=s.useState(""),[i,c]=s.useState(""),[u,g]=s.useState(""),[x,f]=s.useState(""),[b,N]=s.useState(!1),[y,p]=s.useState({hasClaudeMd:!1,skills:[],mcps:[],refFiles:[]}),[w,h]=s.useState(new Set),[S,m]=s.useState(new Set),[v,j]=s.useState(new Set),[W,I]=s.useState(!1),[O,A]=s.useState(""),[T,M]=s.useState({files:[],truncated:!1}),[B,_]=s.useState(!1),[ce,V]=s.useState(new Set),[ee,ne]=s.useState(""),[ve,ye]=s.useState(!1),[xe,ke]=s.useState(null),[Ee,Me]=s.useState(null),[_e,Be]=s.useState(""),[Q,Se]=s.useState(!1),Fe=s.useRef(null),Ne=t.filter(q=>q.fullPath);s.useEffect(()=>{if(n){Le(n),Te(n);const q=Ne.find(oe=>oe.name===n);if(q){const oe=(q.displayName||q.name).toLowerCase().replace(/[^a-z0-9_-]/g,"-").replace(/-+/g,"-").slice(0,50);c(oe),g(q.displayName||q.name)}}else M({files:[],truncated:!1}),V(new Set),ne(""),ye(!1)},[n]),s.useEffect(()=>{if(Fe.current&&clearTimeout(Fe.current),!i||!/^[a-zA-Z0-9_-]{1,100}$/.test(i)){ke(null),Me(null),Se(!1);return}return Se(!0),Fe.current=setTimeout(async()=>{try{const q=await K(`/api/agents/check-name/${encodeURIComponent(i)}`);if(q.ok){const oe=await q.json();ke(oe.existing),Me(oe.pendingConflict),oe.existing&&!x&&f(oe.existing.description||"")}}catch{ke(null),Me(null)}finally{Se(!1)}},400),()=>{Fe.current&&clearTimeout(Fe.current)}},[i]);const Le=async q=>{if(Ne.find(te=>te.name===q))try{const te=await K(`/api/agents/preview?projectKey=${encodeURIComponent(q)}`);if(te.ok){const Ie=await te.json();p(Ie),h(new Set((Ie.skills||[]).map(G=>G.name))),m(new Set((Ie.mcps||[]).map(G=>G.name))),j(new Set((Ie.refFiles||[]).filter(G=>G.exists).map(G=>G.path)))}}catch{p({hasClaudeMd:!1,skills:[],mcps:[],refFiles:[]}),h(new Set),m(new Set),j(new Set)}},Te=async q=>{_(!0),V(new Set),ne(""),ye(!1);try{const oe=await K(`/api/agents/project-files?projectKey=${encodeURIComponent(q)}`);if(oe.ok){const te=await oe.json();M(te)}else M({files:[],truncated:!1})}catch{M({files:[],truncated:!1})}finally{_(!1)}},ze=q=>q<1024?`${q} B`:q<1024*1024?`${(q/1024).toFixed(1)} KB`:`${(q/(1024*1024)).toFixed(1)} MB`,Ce=s.useMemo(()=>{const q=new Set((y.refFiles||[]).map(te=>te.path));let oe=(T.files||[]).filter(te=>!q.has(te.path));if(ee.trim()){const te=ee.toLowerCase();oe=oe.filter(Ie=>Ie.path.toLowerCase().includes(te))}return oe},[T.files,y.refFiles,ee]),He=async()=>{if(n){N(!0);try{const q=await K("/api/agents/generate-description",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectKey:n,skills:[...w],mcps:[...S]})}),oe=await q.json();q.ok?f(oe.description||""):o(oe.error||"生成失败",{variant:"error"})}catch(q){o(q.message,{variant:"error"})}finally{N(!1)}}},Ve=q=>/^[a-zA-Z0-9_-]{1,100}$/.test(q)?(A(""),!0):(A("只能包含字母、数字、连字符和下划线,1-100 字符"),!1),je=async()=>{if(!n){o("请选择一个项目",{variant:"warning"});return}if(!Ve(i))return;if(!u.trim()){o("请填写显示名称",{variant:"warning"});return}if(Ne.find(oe=>oe.name===n)){I(!0);try{const oe=new Date().toISOString(),te=(y.skills||[]).filter(ae=>w.has(ae.name)),Ie=(y.mcps||[]).filter(ae=>S.has(ae.name)),G=te.map(ae=>` - name: "${ae.name}"
137
- repo: "${ae.repo||""}"`).join(`
138
- `),re=Ie.map(ae=>` - name: "${ae.name}"
139
- repo: "${ae.repo||""}"`).join(`
140
- `),C=[...new Set([...v,...ce])],F=[" - CLAUDE.md",...C.map(ae=>` - ${ae}`)].join(`
141
- `),de=[`name: "${i}"`,`display_name: "${u}"`,"description: |",x.split(`
142
- `).map(ae=>` ${ae}`).join(`
143
- `)||" (no description)",'version: "1.0.0"',`created_at: "${oe}"`,`updated_at: "${oe}"`,te.length>0?`skills:
144
- ${G}`:"skills: []",Ie.length>0?`mcps:
145
- ${re}`:"mcps: []",`files:
146
- ${F}`].join(`
147
- `),pe=await K("/api/agents/submit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentName:i,displayName:u,description:x,projectKey:n,agentYaml:de,refFiles:C,...xe?{updateNotes:_e||void 0}:{}})}),P=await pe.json();pe.ok?a?.():o(P.error||"提交失败",{variant:"error"})}catch(oe){o(oe.message,{variant:"error"})}finally{I(!1)}}},Ae=!!xe;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(St,{className:"w-5 h-5 text-blue-500"}),e.jsx("h2",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:Ae?"更新 Agent":"提交 Agent"})]}),e.jsx("button",{onClick:r,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx(Ke,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-4 space-y-4 overflow-y-auto flex-1",children:[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:n,onChange:q=>l(q.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:"-- 选择项目 --"}),Ne.map(q=>e.jsx("option",{value:q.name,children:q.displayName||q.name},q.name))]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:["Agent 标识名 ",e.jsx("span",{className:"text-gray-400 text-xs",children:"(英文,用于目录名)"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ze,{value:i,onChange:q=>{c(q.target.value),Ve(q.target.value)},placeholder:"e.g. my-agent",className:"text-sm"}),Q&&e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2",children:e.jsx(Tt,{className:"w-4 h-4 text-gray-400 animate-spin"})})]}),O&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:O})]}),Q&&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(Tt,{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:"正在检查 Agent 信息..."})]}),!Q&&Ae&&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($s,{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:"更新模式"}),":仓库中已存在 Agent「",xe.display_name,"」,当前版本 v",xe.version,"。提交将作为版本更新处理。"]})]}),!Q&&Ee&&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(At,{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:["用户 ",Ee.username," 已在 ",new Date(Ee.submitted_at).toLocaleString("zh-CN",{dateStyle:"short",timeStyle:"short"})," 提交了同名 Agent 的审核,建议更换标识名以避免冲突。"]})]}),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(Ze,{value:u,onChange:q=>g(q.target.value),placeholder:"My Agent",className:"text-sm",disabled:Q})]}),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:He,disabled:!n||b||Q,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(cr,{className:"w-3 h-3"}),b?"AI 生成中...":"AI 生成"]})]}),e.jsx("textarea",{value:x,onChange:q=>f(q.target.value),placeholder:"描述这个 Agent 的用途和功能...",rows:3,disabled:Q,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"})]}),Ae&&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:_e,onChange:q=>Be(q.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"})]}),n&&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(es,{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 ${y.hasClaudeMd?"text-gray-700 dark:text-gray-300":"text-gray-400 dark:text-gray-600"}`,children:[e.jsx(es,{className:`w-3.5 h-3.5 flex-shrink-0 ${y.hasClaudeMd?"text-green-500":"text-gray-300"}`}),e.jsxs("span",{children:["CLAUDE.md ",!y.hasClaudeMd&&e.jsx("span",{className:"text-amber-500",children:"(未找到)"})]})]}),y.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:"(勾选需要包含的)"})]}),y.skills.map(q=>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:w.has(q.name),onChange:oe=>{const te=new Set(w);oe.target.checked?te.add(q.name):te.delete(q.name),h(te)},className:"rounded text-purple-500 focus:ring-purple-400 focus:ring-offset-0"}),e.jsx(Sr,{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0"}),e.jsx("span",{children:q.name})]},q.name))]}),y.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:"(勾选需要包含的)"})]}),y.mcps.map(q=>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:S.has(q.name),onChange:oe=>{const te=new Set(S);oe.target.checked?te.add(q.name):te.delete(q.name),m(te)},className:"rounded text-orange-500 focus:ring-orange-400 focus:ring-offset-0"}),e.jsx(zs,{className:"w-3.5 h-3.5 text-orange-500 flex-shrink-0"}),e.jsx("span",{children:q.name})]},q.name))]}),y.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:"(勾选需要包含的)"})]}),y.refFiles.map(q=>e.jsxs("label",{className:`flex items-center gap-2 text-xs cursor-pointer py-0.5 ${q.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:v.has(q.path),disabled:!q.exists,onChange:oe=>{const te=new Set(v);oe.target.checked?te.add(q.path):te.delete(q.path),j(te)},className:"rounded text-blue-500 focus:ring-blue-400 focus:ring-offset-0 disabled:opacity-40"}),e.jsx(es,{className:`w-3.5 h-3.5 flex-shrink-0 ${q.exists?"text-blue-400":"text-gray-300"}`}),e.jsx("span",{className:"truncate",children:q.path}),!q.exists&&e.jsx("span",{className:"text-amber-500 flex-shrink-0",children:"(未找到)"})]},q.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:()=>ye(!ve),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:[ve?e.jsx(ts,{className:"w-3 h-3"}):e.jsx(Ls,{className:"w-3 h-3"}),"项目文件 ",e.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"(手动选择需要包含的)"})]}),ce.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:["已选 ",ce.size]})]}),ve&&e.jsxs("div",{className:"mt-1.5 space-y-1.5",children:[e.jsxs("div",{className:"relative",children:[e.jsx(dt,{className:"w-3 h-3 text-gray-400 absolute left-2 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"text",value:ee,onChange:q=>ne(q.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"})]}),B?e.jsx("div",{className:"flex items-center justify-center py-3",children:e.jsx(Tt,{className:"w-3.5 h-3.5 text-gray-400 animate-spin"})}):Ce.length===0?e.jsx("p",{className:"text-[11px] text-gray-400 text-center py-2",children:"无匹配文件"}):e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-0.5",children:Ce.map(q=>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:ce.has(q.path),onChange:oe=>{const te=new Set(ce);oe.target.checked?te.add(q.path):te.delete(q.path),V(te)},className:"rounded text-teal-500 focus:ring-teal-400 focus:ring-offset-0"}),e.jsx(es,{className:"w-3.5 h-3.5 text-teal-400 flex-shrink-0"}),e.jsx("span",{className:"truncate flex-1 min-w-0",children:q.path}),e.jsx("span",{className:"text-[10px] text-gray-400 flex-shrink-0",children:ze(q.size)})]},q.path))}),T.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(U,{variant:"outline",size:"sm",onClick:r,disabled:W,children:"取消"}),e.jsx(U,{size:"sm",onClick:je,disabled:W||!n||Q,className:"flex items-center gap-1.5",children:W?e.jsx("span",{children:"提交中..."}):e.jsxs(e.Fragment,{children:[e.jsx(hs,{className:"w-3.5 h-3.5"}),Ae?"提交更新":"提交审核"]})})]})]})})}function hl({projects:t=[]}){const{showAlert:r,showConfirm:a}=tt(),{hasPermission:o}=mt(),[n,l]=s.useState([]),[i,c]=s.useState(!0),[u,g]=s.useState(!1),[x,f]=s.useState(null),[b,N]=s.useState(!1),[y,p]=s.useState(null),[w,h]=s.useState([]),[S,m]=s.useState(!1),v={};for(const M of t)if(M.agentInfo?.isAgent){const B=M.agentInfo.agentName;v[B]=M.agentInfo.installedVersion}const j=i?[]:t.filter(M=>M.agentInfo?.isAgent&&!n.some(B=>(B.dirName||B.name)===M.agentInfo.agentName));s.useEffect(()=>{W(),I()},[]);const W=async()=>{try{c(!0);const M=await K("/api/agents");if(M.ok){const B=await M.json();l(B.agents||[])}else{const B=await M.json();r(B.error||"获取 Agent 列表失败",{variant:"error"})}}catch(M){r(M.message,{variant:"error"})}finally{c(!1)}},I=async()=>{try{m(!0);const M=await K("/api/agents/submissions/my");if(M.ok){const B=await M.json();h(B.submissions||[])}}catch{}finally{m(!1)}},O=async()=>{try{g(!0);const M=await K("/api/agents/refresh",{method:"POST"});if(M.ok)await W();else{const B=await M.json();r(B.error||"刷新失败",{variant:"error"})}}catch(M){r(M.message,{variant:"error"})}finally{g(!1)}},A=async(M,B=!1)=>{const _=M.dirName||M.name;f(_);try{const ce=await K("/api/agents/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentName:_,force:B})}),V=await ce.json();if(ce.status===409&&V.conflict){f(null),await a("检测到本地 CLAUDE.md 已被修改,更新将覆盖本地改动,是否继续?",{title:"本地文件冲突",confirmText:"强制更新",variant:"warning"})&&await A(M,!0);return}ce.ok?(r(`Agent "${M.display_name||M.name}" ${B?"更新":"安装"}成功!项目已创建,Skills 和 MCP 服务已安装。`,{title:B?"更新成功":"安装成功"}),window.refreshProjects?.(),window.refreshMcpServers?.(),W()):r(V.error||"安装失败",{variant:"error"})}catch(ce){r(ce.message,{variant:"error"})}finally{f(null)}},T=M=>{const B=M.dirName||M.name,_=v[B];return _?_===M.version?{state:"up_to_date",installedVersion:_}:{state:"update_available",installedVersion:_,latestVersion:M.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(nt,{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:"从 Agent 仓库安装预配置的项目模板,包含所需的 Skills 和 MCP 服务。"}),e.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[e.jsxs(U,{variant:"outline",size:"sm",onClick:O,disabled:u,className:"flex items-center gap-1.5",children:[e.jsx(nt,{className:`w-3.5 h-3.5 ${u?"animate-spin":""}`}),"刷新仓库"]}),o("submit_agent")&&e.jsxs(U,{variant:"outline",size:"sm",onClick:()=>N(!0),className:"flex items-center gap-1.5",children:[e.jsx(hs,{className:"w-3.5 h-3.5"}),"提交 Agent"]})]})]}),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(St,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"暂无可用 Agent"}),e.jsx("p",{className:"text-xs mt-1",children:'点击"刷新仓库"从服务器获取最新 Agent 列表'})]}):e.jsx("div",{className:"space-y-2",children:n.map(M=>{const B=M.dirName||M.name,_=T(M),ce=y===B,V=x===B;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(St,{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:M.display_name||M.name}),e.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:["v",M.version]}),_.state==="update_available"&&e.jsxs(Qe,{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",_.latestVersion]}),_.state==="up_to_date"&&e.jsx(Qe,{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:"已安装"})]}),M.description&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 truncate",children:M.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[M.skills?.length>0&&e.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:[M.skills.length," 个 Skill"]}),M.mcps?.length>0&&e.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:[M.mcps.length," 个 MCP"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(U,{size:"sm",variant:_.state==="not_installed"?"default":"outline",onClick:()=>A(M),disabled:V||_.state==="up_to_date",className:"text-xs h-7 px-2.5",children:V?e.jsx(nt,{className:"w-3 h-3 animate-spin"}):_.state==="up_to_date"?"已是最新":_.state==="update_available"?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"w-3 h-3 mr-1"}),"更新"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ct,{className:"w-3 h-3 mr-1"}),"安装"]})}),(M.skills?.length>0||M.mcps?.length>0)&&e.jsx("button",{onClick:()=>p(ce?null:B),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:ce?e.jsx(Na,{className:"w-4 h-4"}):e.jsx(ts,{className:"w-4 h-4"})})]})]}),ce&&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:[M.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:M.skills.map(ee=>e.jsx(Qe,{variant:"outline",className:"text-xs",children:ee.name},ee.name))})]}),M.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:M.mcps.map(ee=>e.jsx(Qe,{variant:"outline",className:"text-xs",children:ee.name},ee.name))})]})]})]},B)})}),j.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(At,{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:j.map(M=>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:M.displayName}),e.jsx("span",{className:"text-xs text-gray-400 font-mono ml-2",children:M.agentInfo.agentName}),e.jsxs("span",{className:"text-xs text-amber-600 dark:text-amber-400 ml-2",children:["v",M.agentInfo.installedVersion]})]}),e.jsx("span",{className:"text-xs text-amber-500 dark:text-amber-400",children:"已下线,本地仍可继续使用"})]},M.agentInfo.agentName))})]}),(w.length>0||S)&&e.jsxs("div",{className:"mt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"我的提交记录"}),e.jsxs("button",{onClick:I,disabled:S,className:"text-xs text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex items-center gap-1",children:[e.jsx(nt,{className:`w-3 h-3 ${S?"animate-spin":""}`}),"刷新"]})]}),e.jsx("div",{className:"space-y-2",children:w.map(M=>{const B={pending:{label:"审核中",icon:bs,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:Ca,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:Sa,color:"text-red-600 dark:text-red-400",bg:"bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800"}},_=B[M.status]||B.pending,ce=_.icon;return e.jsx("div",{className:`border rounded-lg px-3 py-2.5 ${_.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:M.display_name}),e.jsxs("span",{className:"text-xs text-gray-400",children:["(",M.agent_name,")"]}),M.version&&e.jsxs("span",{className:"text-xs text-gray-400",children:["v",M.version]})]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:["提交于 ",new Date(M.submitted_at).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"})]}),M.status==="rejected"&&M.reject_reason&&e.jsxs("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1",children:["拒绝原因:",M.reject_reason]}),M.status==="approved"&&M.reviewed_at&&e.jsxs("p",{className:"text-xs text-green-600 dark:text-green-400 mt-0.5",children:["审核通过,已发布为 v",M.version]})]}),e.jsxs("div",{className:`flex items-center gap-1 flex-shrink-0 text-xs font-medium ${_.color}`,children:[e.jsx(ce,{className:"w-3.5 h-3.5"}),_.label]})]})},M.id)})})]}),b&&e.jsx(pl,{projects:t,onClose:()=>N(!1),onSubmitted:()=>{N(!1),I()}})]})}function fl({onClose:t,onChanged:r}){const{showAlert:a,showConfirm:o}=tt(),[n,l]=s.useState([]),[i,c]=s.useState(!0),[u,g]=s.useState(null),[x,f]=s.useState(""),[b,N]=s.useState(!1),[y,p]=s.useState(null);s.useEffect(()=>{w()},[]);const w=async()=>{try{c(!0),g(null);const m=await K("/api/mcp-repos");if(m.ok){const v=await m.json();l(v.repos||[])}else{const v=await m.json();g(v.error||"Failed to fetch repos")}}catch(m){g(m.message)}finally{c(!1)}},h=async m=>{if(m.preventDefault(),!x.trim()){g("请输入仓库 URL");return}try{N(!0),g(null);const v=await K("/api/mcp-repos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:x.trim()})});if(v.ok)f(""),w(),r?.();else{const j=await v.json();g(j.error||"Failed to add repo")}}catch(v){g(v.message)}finally{N(!1)}},S=async(m,v)=>{if(await o(`确定要移除仓库 "${m}/${v}" 吗?`,{title:"移除仓库",variant:"danger",confirmText:"确认移除"}))try{p(`${m}/${v}`);const j=await K(`/api/mcp-repos/${m}/${v}`,{method:"DELETE"});if(j.ok)w(),r?.();else{const W=await j.json();a(W.error||"移除仓库失败",{variant:"error"})}}catch(j){a(j.message,{variant:"error"})}finally{p(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(U,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(rs,{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:h,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(Ze,{type:"text",placeholder:"owner/name 或 https://github.com/owner/name",value:x,onChange:m=>f(m.target.value),disabled:b})]}),e.jsxs(U,{type:"submit",disabled:b||!x.trim(),className:"bg-purple-600 hover:bg-purple-700 text-white",children:[e.jsx(Rt,{className:"w-4 h-4 mr-2"}),b?"添加中...":"添加仓库"]})]})]}),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(ka,{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(Qe,{variant:"outline",className:"text-xs bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",children:"内置"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Nr,{className:"w-3 h-3"}),"分支: main"]}),e.jsxs(Qe,{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(U,{variant:"ghost",size:"sm",onClick:()=>S(m.owner,m.repo),disabled:y===`${m.owner}/${m.repo}`,className:"text-red-500 hover:text-red-600",children:e.jsx(lt,{className:"w-4 h-4"})})})]})},`${m.owner}/${m.repo}`))]})]})]})})}const gl=t=>{switch(t){case"stdio":return e.jsx(kr,{className:"w-3 h-3"});case"sse":return e.jsx(Sr,{className:"w-3 h-3"});case"http":return e.jsx(Is,{className:"w-3 h-3"});default:return e.jsx(zs,{className:"w-3 h-3"})}};function bl({onClose:t,onInstalled:r,onOpenRepoManager:a}){const{showAlert:o,showConfirm:n}=tt(),[l,i]=s.useState([]),[c,u]=s.useState([]),[g,x]=s.useState(!0),[f,b]=s.useState(null),[N,y]=s.useState(""),[p,w]=s.useState("all"),[h,S]=s.useState(null),[m,v]=s.useState(null);s.useEffect(()=>{j()},[]);const j=async(A=!1)=>{try{x(!0),b(null),A&&await K("/api/mcp-repos/refresh",{method:"POST"});const[T,M]=await Promise.all([K("/api/mcp-repos/available"),K("/api/mcp-repos")]);if(T.ok){const B=await T.json();i(B.services||[])}if(M.ok){const B=await M.json();u(B.repos||[])}}catch(T){b(T.message)}finally{x(!1)}},W=async A=>{try{S(A.dirName+A.repository);const T=await K("/api/mcp-repos/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({servicePath:A.path})});if(T.ok)j(),r?.();else{const M=await T.json();o(M.error||"安装 MCP 服务失败",{variant:"error"})}}catch(T){o(T.message,{variant:"error"})}finally{S(null)}},I=async A=>{if(!(!A.serverNames||A.serverNames.length===0)&&await n(`确定要卸载 "${A.name}" 吗?这将移除 ${A.serverNames.join(", ")} 的配置。`,{title:"卸载 MCP 服务",variant:"danger",confirmText:"确认卸载"}))try{v(A.dirName+A.repository);for(const T of A.serverNames)await K(`/api/mcp-repos/uninstall/${encodeURIComponent(T)}`,{method:"DELETE"});j(),r?.()}catch(T){o(T.message,{variant:"error"})}finally{v(null)}},O=l.filter(A=>{if(N){const T=N.toLowerCase();if(!A.dirName?.toLowerCase().includes(T)&&!A.name?.toLowerCase().includes(T)&&!A.description?.toLowerCase().includes(T))return!1}return!(p!=="all"&&A.repository!==p)});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(U,{variant:"ghost",size:"sm",onClick:()=>j(!0),disabled:g,children:[e.jsx(nt,{className:`w-4 h-4 ${g?"animate-spin":""}`}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"刷新"})]}),e.jsxs(U,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(Pt,{className:"w-4 h-4"}),e.jsx("span",{className:"ml-1 hidden sm:inline",children:"仓库管理"})]}),e.jsx(U,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(Ke,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2",children:e.jsx("h3",{className:"text-purple-500 font-medium",children:"发现 MCP 服务"})}),e.jsxs("div",{className:"px-4 pb-4 flex flex-wrap gap-3",children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative",children:[e.jsx(dt,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Ze,{type:"text",placeholder:"搜索 MCP 服务名称或描述...",value:N,onChange:A=>y(A.target.value),className:"pl-10"})]})}),e.jsxs("select",{value:p,onChange:A=>w(A.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:"全部仓库"}),c.map(A=>e.jsxs("option",{value:`${A.owner}/${A.repo}`,children:[A.owner,"/",A.repo]},`${A.owner}/${A.repo}`))]})]}),e.jsxs("div",{className:"flex-1 overflow-auto px-4 pb-4",children:[f&&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:f}),g?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):O.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:l.length===0?e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"没有可用的 MCP 服务"}),e.jsx("p",{className:"text-xs mt-2",children:"请先添加 MCP 仓库"}),e.jsxs(U,{variant:"outline",size:"sm",className:"mt-4",onClick:a,children:[e.jsx(Pt,{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:O.map(A=>{const T=`${A.repository}-${A.dirName}`,M=h===A.dirName+A.repository,B=m===A.dirName+A.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:A.name||A.dirName}),e.jsxs(Qe,{variant:"outline",className:"text-xs flex items-center gap-1",children:[gl(A.type),A.type]})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:A.repository}),A.serverNames?.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:["· ",A.serverNames.join(", ")]})]})]}),A.description&&e.jsx("p",{className:"text-sm text-muted-foreground flex-1 line-clamp-3 mb-3",children:A.description}),e.jsx("div",{className:"flex items-center gap-2 mt-auto pt-2",children:A.installed?e.jsxs(U,{size:"sm",variant:"outline",className:"ml-auto text-red-600 hover:text-red-700 border-red-200 hover:border-red-300",onClick:()=>I(A),disabled:B,children:[e.jsx(lt,{className:"w-4 h-4 mr-1"}),B?"卸载中...":"卸载"]}):e.jsxs(U,{size:"sm",className:"bg-purple-600 hover:bg-purple-700 text-white ml-auto",onClick:()=>W(A),disabled:M,children:[e.jsx(Ct,{className:"w-4 h-4 mr-1"}),M?"安装中...":"安装"]})})]})},T)})})]})]})})}function vl({isOpen:t,onClose:r,projects:a=[],initialTab:o="agents",autoScrollToBottom:n,onAutoScrollChange:l,sendByCtrlEnter:i,onSendByCtrlEnterChange:c}){const u=va(),{isDarkMode:g,toggleDarkMode:x}=el(),{user:f,logout:b,hasPermission:N}=mt(),{showAlert:y,showConfirm:p}=tt(),[w,h]=s.useState([]),[S,m]=s.useState([]),[v,j]=s.useState(""),[W,I]=s.useState(""),[O,A]=s.useState(!1),[T,M]=s.useState(!1),[B,_]=s.useState(null),[ce,V]=s.useState("name"),[ee,ne]=s.useState([]),[ve,ye]=s.useState(!1),[xe,ke]=s.useState(null),[Ee,Me]=s.useState(!1),[_e,Be]=s.useState(!1),[Q,Se]=s.useState({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),[Fe,Ne]=s.useState(!1),[Le,Te]=s.useState({}),[ze,Ce]=s.useState({}),[He,Ve]=s.useState({}),[je,Ae]=s.useState(o),[q,oe]=s.useState(""),[te,Ie]=s.useState("permissions");s.useEffect(()=>{const R={permissions:"tab_permissions",mcp:"tab_mcp",skills:"tab_skills",models:"tab_models",agents:null},Y=R[te];if(Y&&!N(Y)){const $e=["permissions","mcp","skills","models","agents"].find(rt=>{const it=R[rt];return!it||N(it)});$e&&Ie($e)}},[N,te]);const G=s.useRef(null),[re,C]=s.useState({saving:!1,hasChanges:!1}),F=s.useCallback(R=>C(R),[]),[de,pe]=s.useState(""),[P,ae]=s.useState(""),[ue,le]=s.useState(""),[k,X]=s.useState(""),[se,fe]=s.useState(""),[J,Re]=s.useState(!1),[$,we]=s.useState(""),[We,Oe]=s.useState(!1),[Ge,Pe]=s.useState(""),[$r,_t]=s.useState(!1),[gt,Et]=s.useState(null),[bt,Os]=s.useState(()=>localStorage.getItem("codeEditorTheme")||"dark"),[ot,Fs]=s.useState(()=>localStorage.getItem("codeEditorWordWrap")==="true"),[vt,as]=s.useState(()=>localStorage.getItem("codeEditorShowMinimap")!=="false"),[Mt,Bt]=s.useState(()=>localStorage.getItem("codeEditorLineNumbers")!=="false"),[Ht,Jt]=s.useState(()=>localStorage.getItem("codeEditorFontSize")||"14"),yt=async()=>{try{const R=await K("/api/mcp/config/read");if(R.ok){const $e=await R.json();if($e.success&&$e.servers){ne($e.servers);return}}const Y=await K("/api/mcp/cli/list");if(Y.ok){const $e=await Y.json();if($e.success&&$e.servers){const rt=$e.servers.map(it=>({id:it.name,name:it.name,type:it.type,scope:"user",config:{command:it.command||"",args:it.args||[],env:it.env||{},url:it.url||"",headers:it.headers||{},timeout:3e4},created:new Date().toISOString(),updated:new Date().toISOString()}));ne(rt);return}}const ie=await K("/api/mcp/servers?scope=user");if(ie.ok){const $e=await ie.json();ne($e.servers||[])}else console.error("Failed to fetch MCP servers")}catch(R){console.error("Error fetching MCP servers:",R)}},ct=async R=>{try{xe&&await qt(xe.id,"user");const Y=await K("/api/mcp/cli/add",{method:"POST",body:JSON.stringify({name:R.name,type:R.type,scope:R.scope,projectPath:R.projectPath,command:R.config?.command,args:R.config?.args||[],url:R.config?.url,headers:R.config?.headers||{},env:R.config?.env||{}})});if(Y.ok){const ie=await Y.json();if(ie.success)return await yt(),!0;throw new Error(ie.error||"Failed to save server via Claude CLI")}else{const ie=await Y.json();throw new Error(ie.error||"Failed to save server")}}catch(Y){throw console.error("Error saving MCP server:",Y),Y}},qt=async(R,Y="user")=>{try{const ie=await K(`/api/mcp/cli/remove/${R}?scope=${Y}`,{method:"DELETE"});if(ie.ok){const $e=await ie.json();if($e.success)return await yt(),!0;throw new Error($e.error||"Failed to delete server via Claude CLI")}else{const $e=await ie.json();throw new Error($e.error||"Failed to delete server")}}catch(ie){throw console.error("Error deleting MCP server:",ie),ie}},Kt=async(R,Y="user")=>{try{const ie=await K(`/api/mcp/servers/${R}/test?scope=${Y}`,{method:"POST"});if(ie.ok)return(await ie.json()).testResult;{const $e=await ie.json();throw new Error($e.error||"Failed to test server")}}catch(ie){throw console.error("Error testing MCP server:",ie),ie}},ns=async(R,Y="user")=>{try{const ie=await K(`/api/mcp/servers/${R}/tools?scope=${Y}`,{method:"POST"});if(ie.ok)return(await ie.json()).toolsResult;{const $e=await ie.json();throw new Error($e.error||"Failed to discover tools")}}catch(ie){throw console.error("Error discovering MCP tools:",ie),ie}};s.useEffect(()=>{t&&(os(),Ae(o),he.auth.feishuStatus().then(R=>R.json()).then(R=>{Et(R.bound?R:!1)}).catch(()=>Et(!1)))},[t,o]),s.useEffect(()=>(window.refreshMcpServers=yt,()=>{delete window.refreshMcpServers}),[yt]),s.useEffect(()=>{localStorage.setItem("codeEditorTheme",bt),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[bt]),s.useEffect(()=>{localStorage.setItem("codeEditorWordWrap",ot.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[ot]),s.useEffect(()=>{localStorage.setItem("codeEditorShowMinimap",vt.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[vt]),s.useEffect(()=>{localStorage.setItem("codeEditorLineNumbers",Mt.toString()),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Mt]),s.useEffect(()=>{localStorage.setItem("codeEditorFontSize",Ht),window.dispatchEvent(new Event("codeEditorSettingsChanged"))},[Ht]);const os=async()=>{try{let R=null;try{const Y=await he.settings.getAgentPermissions();Y.ok&&(R=(await Y.json()).agentPermissions)}catch{}if(R)h(R.allowedTools||[]),m(R.disallowedTools||[]),A(R.skipPermissions||!1),V(R.projectSortOrder||"name"),localStorage.setItem("claude-settings",JSON.stringify(R));else{const Y=localStorage.getItem("claude-settings");if(Y){const ie=JSON.parse(Y);h(ie.allowedTools||[]),m(ie.disallowedTools||[]),A(ie.skipPermissions||!1),V(ie.projectSortOrder||"name")}else h([]),m([]),A(!1),V("name")}await yt()}catch(R){console.error("Error loading tool settings:",R),h([]),m([]),A(!1),V("name")}},ut=async()=>{M(!0),_(null);try{const R={allowedTools:w,disallowedTools:S,skipPermissions:O,projectSortOrder:ce,lastUpdated:new Date().toISOString()};localStorage.setItem("claude-settings",JSON.stringify(R));try{await he.settings.saveAgentPermissions(R)}catch(Y){console.warn("Failed to sync agent permissions to server:",Y)}_("success"),setTimeout(()=>{r()},1e3)}catch(R){console.error("Error saving tool settings:",R),_("error")}finally{M(!1)}},Vt=async R=>{if(R.preventDefault(),X(""),fe(""),!de){X("请输入当前密码");return}if(!P){X("请输入新密码");return}if(P.length<6){X("新密码至少需要6个字符");return}if(P!==ue){X("两次输入的新密码不一致");return}Re(!0);try{const Y=await he.auth.changePassword(de,P),ie=await Y.json();Y.ok?(fe("密码修改成功"),pe(""),ae(""),le("")):X(ie.error||"修改密码失败")}catch(Y){console.error("Error changing password:",Y),X("网络错误,请稍后再试")}finally{Re(!1)}},is=f?.username&&!f.username.includes("@"),Gt=async()=>{Oe(!0),Pe(""),we(""),_t(!1);try{const R=await he.auth.feishuBindToken(),Y=await R.json();R.ok&&Y.token?we(Y.token):Pe(Y.error||"生成失败,请重试")}catch{Pe("网络错误,请稍后再试")}finally{Oe(!1)}},jt=()=>{if(!$)return;const R=`/auth ${$}`;if(navigator.clipboard&&window.isSecureContext)navigator.clipboard.writeText(R).then(()=>{_t(!0),setTimeout(()=>_t(!1),2e3)});else{const Y=document.createElement("textarea");Y.value=R,Y.style.position="fixed",Y.style.opacity="0",document.body.appendChild(Y),Y.focus(),Y.select();try{document.execCommand("copy"),_t(!0),setTimeout(()=>_t(!1),2e3)}finally{document.body.removeChild(Y)}}},st=()=>{Se({name:"",type:"stdio",scope:"user",projectPath:"",config:{command:"",args:[],env:{},url:"",headers:{},timeout:3e4},jsonInput:"",importMode:"form"}),ke(null),ye(!1),oe("")},Yt=(R=null)=>{R?(ke(R),Se({name:R.name,type:R.type,scope:R.scope,projectPath:R.projectPath||"",config:{...R.config},raw:R.raw,importMode:"form",jsonInput:""})):st(),ye(!0)},wt=async R=>{R.preventDefault(),Ne(!0);try{if(Q.importMode==="json"){const Y=await K("/api/mcp/cli/add-json",{method:"POST",body:JSON.stringify({name:Q.name,jsonConfig:Q.jsonInput,scope:Q.scope,projectPath:Q.projectPath})});if(Y.ok){const ie=await Y.json();if(ie.success)await yt(),st(),_("success");else throw new Error(ie.error||"Failed to add server via JSON")}else{const ie=await Y.json();throw new Error(ie.error||"Failed to add server")}}else await ct(Q),st(),_("success")}catch(Y){y(`错误: ${Y.message}`,{variant:"error"}),_("error")}finally{Ne(!1)}},ls=async(R,Y)=>{if(await p("确定要删除此 MCP 服务器吗?",{title:"删除 MCP 服务器",variant:"danger",confirmText:"确认删除"}))try{await qt(R,Y),_("success")}catch(ie){y(`错误: ${ie.message}`,{variant:"error"}),_("error")}},Qt=async(R,Y)=>{try{Te({...Le,[R]:{loading:!0}});const ie=await Kt(R,Y);Te({...Le,[R]:ie})}catch(ie){Te({...Le,[R]:{success:!1,message:ie.message,details:[]}})}},xt=async(R,Y)=>{try{Ve({...He,[R]:!0});const ie=await ns(R,Y);Ce({...ze,[R]:ie})}catch{Ce({...ze,[R]:{success:!1,tools:[],resources:[],prompts:[]}})}finally{Ve({...He,[R]:!1})}},zt=(R,Y)=>{Se(ie=>({...ie,config:{...ie.config,[R]:Y}}))};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(Pt,{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(U,{variant:"ghost",size:"sm",onClick:r,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(Ke,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx("div",{className:"border-b border-border",children:e.jsxs("div",{className:"flex px-4 md:px-6",children:[e.jsx("button",{onClick:()=>Ae("agents"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="agents"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"Agent"}),e.jsx("button",{onClick:()=>Ae("appearance"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="appearance"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"外观"}),e.jsx("button",{onClick:()=>Ae("account"),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${je==="account"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"账户"})]})}),e.jsxs("div",{className:"p-4 md:p-6 space-y-6 md:space-y-8 pb-safe-area-inset-bottom",children:[je==="appearance"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:je==="appearance"&&e.jsxs("div",{className:"space-y-6 md:space-y-8",children:[e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"深色模式"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"切换浅色和深色主题"})]}),e.jsxs("button",{onClick: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":g,"aria-label":"Toggle dark mode",children:[e.jsx("span",{className:"sr-only",children:"Toggle dark mode"}),e.jsx("span",{className:`${g?"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:g?e.jsx(Kr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Vr,{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(Hn,{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(Jn,{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:()=>c&&c(!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:ce,onChange:R=>V(R.target.value),className:"text-sm bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2 w-32",children:[e.jsx("option",{value:"name",children:"按字母顺序"}),e.jsx("option",{value:"date",children:"按最近活动"})]})]})})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"文件编辑器"}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"编辑器主题"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"文件编辑器的默认主题"})]}),e.jsxs("button",{onClick:()=>Os(bt==="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":bt==="dark","aria-label":"Toggle editor theme",children:[e.jsx("span",{className:"sr-only",children:"Toggle editor theme"}),e.jsx("span",{className:`${bt==="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:bt==="dark"?e.jsx(Kr,{className:"w-3.5 h-3.5 text-gray-700"}):e.jsx(Vr,{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:()=>Fs(!ot),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":ot,"aria-label":"Toggle word wrap",children:[e.jsx("span",{className:"sr-only",children:"Toggle word wrap"}),e.jsx("span",{className:`${ot?"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:()=>as(!vt),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":vt,"aria-label":"Toggle minimap",children:[e.jsx("span",{className:"sr-only",children:"Toggle minimap"}),e.jsx("span",{className:`${vt?"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:()=>Bt(!Mt),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":Mt,"aria-label":"Toggle line numbers",children:[e.jsx("span",{className:"sr-only",children:"Toggle line numbers"}),e.jsx("span",{className:`${Mt?"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:Ht,onChange:R=>Jt(R.target.value),className:"text-sm bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2 w-24",children:[e.jsx("option",{value:"10",children:"10px"}),e.jsx("option",{value:"11",children:"11px"}),e.jsx("option",{value:"12",children:"12px"}),e.jsx("option",{value:"13",children:"13px"}),e.jsx("option",{value:"14",children:"14px"}),e.jsx("option",{value:"15",children:"15px"}),e.jsx("option",{value:"16",children:"16px"}),e.jsx("option",{value:"18",children:"18px"}),e.jsx("option",{value:"20",children:"20px"})]})]})})]})]})}),je==="agents"&&e.jsx("div",{className:"flex flex-col h-full min-h-[400px] md:min-h-[500px]",children:e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:e.jsxs("div",{className:"flex px-2 md:px-4 overflow-x-auto",children:[N("tab_permissions")&&e.jsx("button",{onClick:()=>Ie("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 ${te==="permissions"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"权限"}),N("tab_mcp")&&e.jsx("button",{onClick:()=>Ie("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 ${te==="mcp"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"MCP 服务器"}),N("tab_skills")&&e.jsx("button",{onClick:()=>Ie("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 ${te==="skills"?"border-amber-600 text-amber-600 dark:text-amber-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"技能"}),N("tab_models")&&e.jsx("button",{onClick:()=>Ie("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 ${te==="models"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"模型"}),e.jsx("button",{onClick:()=>Ie("agents"),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 ${te==="agents"?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:"Agents"})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 md:p-4",children:[te==="permissions"&&e.jsx(nl,{agent:"claude",skipPermissions:O,setSkipPermissions:A,allowedTools:w,setAllowedTools:h,disallowedTools:S,setDisallowedTools:m,newAllowedTool:v,setNewAllowedTool:j,newDisallowedTool:W,setNewDisallowedTool:I}),te==="mcp"&&e.jsx(ll,{agent:"claude",servers:ee,onAdd:()=>Yt(),onEdit:R=>Yt(R),onDelete:(R,Y)=>ls(R,Y),onTest:(R,Y)=>Qt(R,Y),onDiscoverTools:(R,Y)=>xt(R,Y),testResults:Le,serverTools:ze,toolsLoading:He,onDiscoverRepo:()=>Me(!0)}),te==="skills"&&e.jsx(xl,{}),te==="models"&&e.jsx(dl,{ref:G,onStatusChange:F}),te==="agents"&&e.jsx(hl,{projects:a})]})]})}),je==="account"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"账户"}),e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/10 rounded-full flex items-center justify-center",children:e.jsx("span",{className:"text-lg font-semibold text-primary",children:f?.username?.charAt(0).toUpperCase()})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:f?.username}),e.jsx("div",{className:"text-sm text-muted-foreground",children:f?.role==="super_admin"?"超级管理员":f?.role==="admin"?"管理员":"用户"})]})]})}),is&&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(dr,{className:"w-5 h-5 text-blue-600"}),e.jsx("div",{className:"font-medium text-foreground",children:"修改密码"})]}),e.jsxs("form",{onSubmit:Vt,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:de,onChange:R=>pe(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入当前密码",disabled:J})]}),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:R=>ae(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入新密码(至少6个字符)",disabled:J})]}),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:ue,onChange:R=>le(R.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请再次输入新密码",disabled:J})]}),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})}),se&&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:se})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(U,{type:"submit",disabled:J,className:"bg-blue-600 hover:bg-blue-700",children:J?"修改中...":"修改密码"})})]})]}),N("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:"飞书账号绑定"})]}),gt?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:gt.feishuOpenId}),gt.createdAt&&e.jsxs("span",{className:"ml-2 text-xs text-green-600/70 dark:text-green-500/70",children:["· ",new Date(gt.createdAt).toLocaleDateString("zh-CN")]})]})]}):gt===!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 小时。"]}),$?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 ",$]}),e.jsx("button",{onClick:jt,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:$r?e.jsx(Ms,{className:"w-4 h-4 text-green-500"}):e.jsx(qn,{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:Gt,disabled:We,className:"flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 hover:underline disabled:opacity-50",children:[e.jsx(nt,{className:"w-3 h-3"}),"重新生成"]})]})]}):e.jsxs("div",{className:"space-y-2",children:[Ge&&e.jsx("p",{className:"text-sm text-red-500",children:Ge}),e.jsxs(U,{onClick:Gt,disabled:We,variant:"outline",className:"gap-2",children:[We?e.jsx(nt,{className:"w-4 h-4 animate-spin"}):e.jsx(dr,{className:"w-4 h-4"}),We?"生成中...":"生成绑定 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(U,{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 p("确定要退出登录吗?",{title:"退出登录",variant:"warning",confirmText:"退出"})&&(r(),u("/"),b())},children:[e.jsx(Kn,{className:"w-4 h-4"}),"退出"]})]})})]})}),ve&&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:xe?"编辑 MCP 服务器":"添加 MCP 服务器"}),e.jsx(U,{variant:"ghost",size:"sm",onClick:st,children:e.jsx(Ke,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:wt,className:"p-4 space-y-4",children:[!xe&&e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>Se(R=>({...R,importMode:"form"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${Q.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(R=>({...R,importMode:"json"})),className:`px-4 py-2 rounded-lg font-medium transition-colors ${Q.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 导入"})]}),Q.importMode==="form"&&xe&&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:[Q.scope==="user"?e.jsx(Is,{className:"w-4 h-4"}):e.jsx(gs,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:Q.scope==="user"?"用户(全局)":"项目(本地)"}),Q.scope==="local"&&Q.projectPath&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",qe(Q.projectPath)]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"编辑现有服务器时无法更改作用域"})]}),Q.importMode==="form"&&!xe&&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(R=>({...R,scope:"user",projectPath:""})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${Q.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(Is,{className:"w-4 h-4"}),e.jsx("span",{children:"用户(全局)"})]})}),e.jsx("button",{type:"button",onClick:()=>Se(R=>({...R,scope:"local"})),className:`flex-1 px-4 py-2 rounded-lg font-medium transition-colors ${Q.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(gs,{className:"w-4 h-4"}),e.jsx("span",{children:"项目(本地)"})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:Q.scope==="user"?"用户作用域:在您机器上的所有项目中可用":"本地作用域:仅在选定的项目中可用"})]}),Q.scope==="local"&&!xe&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"项目 *"}),e.jsxs("select",{value:Q.projectPath,onChange:R=>Se(Y=>({...Y,projectPath:R.target.value})),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500",required:Q.scope==="local",children:[e.jsx("option",{value:"",children:"选择项目..."}),a.map(R=>e.jsx("option",{value:R.path||R.fullPath,children:R.displayName||R.name},R.name))]}),Q.projectPath&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Path: ",qe(Q.projectPath)]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:Q.importMode==="json"?"md:col-span-2":"",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"服务器名称 *"}),e.jsx(Ze,{value:Q.name,onChange:R=>{Se(Y=>({...Y,name:R.target.value}))},placeholder:"my-server",required:!0})]}),Q.importMode==="form"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"传输类型 *"}),e.jsxs("select",{value:Q.type,onChange:R=>{Se(Y=>({...Y,type:R.target.value}))},className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 rounded-lg focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:"stdio",children:"stdio"}),e.jsx("option",{value:"sse",children:"SSE"}),e.jsx("option",{value:"http",children:"HTTP"})]})]})]}),xe&&Q.raw&&Q.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 ",xe.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(Q.raw,null,2)})]}),Q.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:Q.jsonInput,onChange:R=>{Se(Y=>({...Y,jsonInput:R.target.value}));try{if(R.target.value.trim()){const Y=JSON.parse(R.target.value);Y.type?Y.type==="stdio"&&!Y.command?oe("stdio 类型需要 command 字段"):(Y.type==="http"||Y.type==="sse")&&!Y.url?oe(`${Y.type} 类型需要 url 字段`):oe(""):oe("缺少必填字段:type")}}catch{R.target.value.trim()?oe("无效的 JSON 格式"):oe("")}},className:`w-full px-3 py-2 border ${q?"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:`{
148
- "type": "stdio",
149
- "command": "/path/to/server",
150
- "args": ["--api-key", "abc123"],
151
- "env": {
152
- "CACHE_DIR": "/tmp"
153
- }
154
- }`,required:!0}),q&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:q}),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"}']})]})}),Q.importMode==="form"&&Q.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(Ze,{value:Q.config.command,onChange:R=>zt("command",R.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(Q.config.args)?Q.config.args.join(`
155
- `):"",onChange:R=>zt("args",R.target.value.split(`
156
- `).filter(Y=>Y.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
157
- abc123`})]})]}),Q.importMode==="form"&&(Q.type==="sse"||Q.type==="http")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-2",children:"URL *"}),e.jsx(Ze,{value:Q.config.url,onChange:R=>zt("url",R.target.value),placeholder:"https://api.example.com/mcp",type:"url",required:!0})]}),Q.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(Q.config.env||{}).map(([R,Y])=>`${R}=${Y}`).join(`
158
- `),onChange:R=>{const Y={};R.target.value.split(`
159
- `).forEach(ie=>{const[$e,...rt]=ie.split("=");$e&&$e.trim()&&(Y[$e.trim()]=rt.join("=").trim())}),zt("env",Y)},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
160
- DEBUG=true`})]}),Q.importMode==="form"&&(Q.type==="sse"||Q.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(Q.config.headers||{}).map(([R,Y])=>`${R}=${Y}`).join(`
161
- `),onChange:R=>{const Y={};R.target.value.split(`
162
- `).forEach(ie=>{const[$e,...rt]=ie.split("=");$e&&$e.trim()&&(Y[$e.trim()]=rt.join("=").trim())}),zt("headers",Y)},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
163
- X-API-Key=your-key`})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(U,{type:"button",variant:"outline",onClick:st,children:"取消"}),e.jsx(U,{type:"submit",disabled:Fe,className:"bg-purple-600 hover:bg-purple-700 disabled:opacity-50",children:Fe?"保存中...":xe?"更新服务器":"添加服务器"})]})]})]})})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between p-4 md:p-6 border-t border-border flex-shrink-0 gap-3 pb-safe-area-inset-bottom",children:[e.jsx("div",{className:"flex items-center justify-center sm:justify-start gap-2 order-2 sm:order-1",children:je==="agents"&&te==="models"?re.saving?e.jsx("span",{className:"text-sm text-muted-foreground",children:"保存中..."}):null:e.jsxs(e.Fragment,{children:[B==="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"})}),"设置保存成功!"]}),B==="error"&&e.jsxs("div",{className:"text-red-600 dark:text-red-400 text-sm flex items-center gap-1",children:[e.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),"保存设置失败"]})]})}),e.jsxs("div",{className:"flex items-center gap-3 order-1 sm:order-2",children:[je==="agents"&&te==="models"&&re.hasChanges&&e.jsx(U,{variant:"outline",onClick:()=>G.current?.reset(),disabled:re.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"重置"}),e.jsx(U,{variant:"outline",onClick:r,disabled:T||re.saving,className:"flex-1 sm:flex-none h-10 touch-manipulation",children:"取消"}),e.jsx(U,{onClick:je==="agents"&&te==="models"?()=>G.current?.save():ut,disabled:je==="agents"&&te==="models"?re.saving||!re.hasChanges:T,className:"flex-1 sm:flex-none h-10 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 touch-manipulation",children:T||re.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"}),"保存中..."]}):"保存设置"})]})]})]})}),Ee&&e.jsx(bl,{onClose:()=>Me(!1),onInstalled:()=>yt(),onOpenRepoManager:()=>{Me(!1),Be(!0)}}),_e&&e.jsx(fl,{onClose:()=>Be(!1),onChanged:()=>{}})]}):null}const yl=[{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 jl({user:t,onClose:r,onSaved:a}){const[o,n]=s.useState({}),[l,i]=s.useState(!0),[c,u]=s.useState(!1),[g,x]=s.useState(""),[f,b]=s.useState(!1);s.useEffect(()=>{N()},[t.id]);const N=async()=>{i(!0);try{const S=await(await he.admin.getUserPermissions(t.id)).json();if(S.permissions)n(S.permissions),b(!0);else{const v=await(await he.admin.getDefaultPermissions()).json();n(v.permissions||{}),b(!1)}}catch(h){console.error("Error fetching permissions:",h),x("加载权限失败")}finally{i(!1)}},y=h=>{n(S=>({...S,[h]:!S[h]})),b(!0)},p=async h=>{h.preventDefault(),x(""),u(!0);try{const S=await he.admin.updateUserPermissions(t.id,o),m=await S.json();S.ok?(a?.(),r()):x(m.error||"保存失败")}catch(S){console.error("Error saving permissions:",S),x("网络错误,请稍后再试")}finally{u(!1)}},w=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||{}),b(!1)}}catch(h){console.error("Error resetting permissions:",h),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]}),f?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(Ke,{className:"w-5 h-5"})})]}),l?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"加载中..."}):e.jsxs("form",{onSubmit:p,className:"space-y-3",children:[e.jsx("div",{className:"space-y-1 max-h-[400px] overflow-y-auto",children:yl.map(h=>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:h.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:h.desc})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":o[h.key]!==!1,onClick:()=>y(h.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[h.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[h.key]!==!1?"translate-x-4":"translate-x-0"}`})})]},h.key))}),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 items-center justify-between pt-2",children:[e.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:w,disabled:c||!f,className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(Ea,{className:"w-3.5 h-3.5"}),"重置为默认"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{type:"button",variant:"outline",onClick:r,disabled:c,children:"取消"}),e.jsx(U,{type:"submit",disabled:c,children:c?"保存中...":"保存"})]})]})]})]})})}function wl({user:t,onClose:r,onSaved:a}){const[o,n]=s.useState(new Set),[l,i]=s.useState([]),[c,u]=s.useState(""),[g,x]=s.useState(!0),[f,b]=s.useState(!1),[N,y]=s.useState(""),[p,w]=s.useState(!1);s.useEffect(()=>{h()},[t.id]);const h=async()=>{x(!0);try{const[O,A]=await Promise.all([K("/api/agents"),he.admin.getUserVisibleAgents(t.id)]),T=await O.json(),M=await A.json();i(T.agents||[]),M.agents&&Array.isArray(M.agents)?(n(new Set(M.agents)),w(!0)):(n(new Set),w(!1))}catch(O){console.error("Error fetching agent visibility data:",O),y("加载数据失败")}finally{x(!1)}},S=s.useMemo(()=>{if(!c.trim())return l;const O=c.toLowerCase();return l.filter(A=>(A.display_name||A.name||"").toLowerCase().includes(O)||(A.description||"").toLowerCase().includes(O)||(A.dirName||"").toLowerCase().includes(O))},[l,c]),m=S.length>0&&S.every(O=>o.has(O.dirName||O.name)),v=O=>{n(A=>{const T=new Set(A);return T.has(O)?T.delete(O):T.add(O),T}),w(!0)},j=()=>{n(O=>{const A=new Set(O);return m?S.forEach(T=>A.delete(T.dirName||T.name)):S.forEach(T=>A.add(T.dirName||T.name)),A}),w(!0)},W=async O=>{O.preventDefault(),y(""),b(!0);try{const A=[...o],T=await he.admin.updateUserVisibleAgents(t.id,A),M=await T.json();T.ok?(a?.(),r()):y(M.error||"保存失败")}catch(A){console.error("Error saving agent visibility:",A),y("网络错误,请稍后再试")}finally{b(!1)}},I=async()=>{y(""),b(!0);try{(await he.admin.updateUserVisibleAgents(t.id,null)).ok&&(n(new Set),w(!1))}catch(O){console.error("Error resetting agent visibility:",O),y("重置失败")}finally{b(!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:["Agent 可见性 - ",t.username||t.email]}),p?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(Ke,{className:"w-5 h-5"})})]}),g?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(Vn,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"仓库中暂无 Agent"})]}):e.jsxs("form",{onSubmit:W,className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(dt,{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:c,onChange:O=>u(O.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:j,className:"w-3.5 h-3.5 rounded border-gray-300 dark:border-gray-600 text-blue-600 focus:ring-blue-500"}),c?`全选搜索结果(${S.length})`:`全选(${l.length})`]}),e.jsx("div",{className:"space-y-0.5 max-h-[400px] overflow-y-auto border border-border rounded-md",children:S.length===0?e.jsx("div",{className:"text-center py-6 text-muted-foreground text-sm",children:"未找到匹配的 Agent"}):S.map(O=>{const A=O.dirName||O.name,T=o.has(A);return e.jsxs("label",{className:`flex items-start gap-2.5 px-3 py-2 cursor-pointer transition-colors hover:bg-accent/50 ${T?"bg-blue-50/50 dark:bg-blue-900/10":""}`,children:[e.jsx("input",{type:"checkbox",checked:T,onChange:()=>v(A),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:O.display_name||O.name}),O.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",O.version]})]}),O.description&&e.jsx("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:O.description})]})]},A)})}),e.jsxs("div",{className:"text-xs text-muted-foreground px-1",children:["已选 ",o.size," / 共 ",l.length," 个 Agent"]}),N&&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:N})}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:I,disabled:f||!p,className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(Ea,{className:"w-3.5 h-3.5"}),"重置为默认"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(U,{type:"button",variant:"outline",onClick:r,disabled:f,children:"取消"}),e.jsx(U,{type:"submit",disabled:f,children:f?"保存中...":"保存"})]})]})]})]})})}function kl({isSuperAdmin:t,onNavigateToUsage:r,onViewUser:a}){const{user:o}=mt(),{showConfirm:n}=tt(),[l,i]=s.useState([]),[c,u]=s.useState({}),[g,x]=s.useState(!0),[f,b]=s.useState(null),[N,y]=s.useState(!1),[p,w]=s.useState(""),[h,S]=s.useState(""),[m,v]=s.useState(""),[j,W]=s.useState(!1),[I,O]=s.useState(null),[A,T]=s.useState({total_limit_usd:"",daily_limit_usd:""}),[M,B]=s.useState(""),[_,ce]=s.useState(!1),[V,ee]=s.useState(null),[ne,ve]=s.useState(""),[ye,xe]=s.useState(""),[ke,Ee]=s.useState(""),[Me,_e]=s.useState(!1),[Be,Q]=s.useState(null),[Se,Fe]=s.useState(""),[Ne,Le]=s.useState(""),[Te,ze]=s.useState(!1),[Ce,He]=s.useState(null),[Ve,je]=s.useState(null),Ae=async()=>{try{const $=await K("/api/admin/users");if($.ok){const we=await $.json();i(we.users)}}catch($){console.error("Error fetching users:",$)}finally{x(!1)}},q=async()=>{try{const $=await K("/api/admin/usage/summary");if($.ok){const we=await $.json(),We={};for(const Oe of we.users)We[Oe.user_uuid]={total_cost:Oe.total_cost||0,total_requests:Oe.total_requests||0,last_active:Oe.last_active};u(We)}}catch($){console.error("Error fetching usage data:",$)}};s.useEffect(()=>{Ae(),q()},[]);const oe=$=>!$||$===0?"$0.00":$<.01?`$${$.toFixed(4)}`:`$${$.toFixed(2)}`,te=$=>$.role==="super_admin"?!1:t||$.id===o?.id?!0:$.role==="user",Ie=$=>$.id===o?.id?!1:t?$.role!=="super_admin":!["admin","super_admin"].includes($.role),G=async($,we)=>{const We=we==="active"?"disabled":"active";b($);try{(await K(`/api/admin/users/${$}`,{method:"PATCH",body:JSON.stringify({status:We})})).ok&&i(l.map(Ge=>Ge.id===$?{...Ge,status:We}:Ge))}catch(Oe){console.error("Error updating user status:",Oe)}finally{b(null)}},re=async($,we)=>{if(await n(`确定要删除用户 "${we}"?这将删除其所有数据。`,{title:"删除用户",variant:"danger",confirmText:"确认删除"})){b($);try{(await K(`/api/admin/users/${$}`,{method:"DELETE"})).ok&&i(l.filter(Oe=>Oe.id!==$))}catch(We){console.error("Error deleting user:",We)}finally{b(null)}}},C=async $=>{if($.preventDefault(),v(""),!p||!h){v("用户名和密码不能为空");return}if(p.length<3){v("用户名至少3个字符");return}if(h.length<6){v("密码至少6个字符");return}W(!0);try{const we=await he.admin.createUser(p,h),We=await we.json();we.ok?(await Ae(),y(!1),w(""),S("")):v(We.error||"创建用户失败")}catch(we){console.error("Error creating user:",we),v("网络错误,请稍后再试")}finally{W(!1)}},F=()=>{y(!1),w(""),S(""),v("")},de=$=>{O($),T({total_limit_usd:$.total_limit_usd!==null&&$.total_limit_usd!==void 0?String($.total_limit_usd):"",daily_limit_usd:$.daily_limit_usd!==null&&$.daily_limit_usd!==void 0?String($.daily_limit_usd):""}),B("")},pe=()=>{O(null),T({total_limit_usd:"",daily_limit_usd:""}),B("")},P=async $=>{$.preventDefault(),B("");const we=A.total_limit_usd.trim()===""?null:parseFloat(A.total_limit_usd),We=A.daily_limit_usd.trim()===""?null:parseFloat(A.daily_limit_usd);if(we!==null&&(isNaN(we)||we<0)){B("总额度限制必须是正数或留空");return}if(We!==null&&(isNaN(We)||We<0)){B("每日额度限制必须是正数或留空");return}ce(!0);try{const Oe=await he.admin.updateUserLimits(I.id,{total_limit_usd:we,daily_limit_usd:We}),Ge=await Oe.json();Oe.ok?(i(l.map(Pe=>Pe.id===I.id?{...Pe,total_limit_usd:we,daily_limit_usd:We}:Pe)),pe()):B(Ge.error||"更新限制失败")}catch(Oe){console.error("Error updating limits:",Oe),B("网络错误,请稍后再试")}finally{ce(!1)}},ae=$=>$==null?"无限制":`$${$.toFixed(2)}`,ue=$=>{ee($),ve(""),xe(""),Ee("")},le=()=>{ee(null),ve(""),xe(""),Ee("")},k=async $=>{if($.preventDefault(),Ee(""),!ne){Ee("请输入新密码");return}if(ne.length<6){Ee("密码至少需要6个字符");return}if(ne!==ye){Ee("两次输入的密码不一致");return}_e(!0);try{const we=await he.admin.resetUserPassword(V.id,ne),We=await we.json();we.ok?le():Ee(We.error||"重置密码失败")}catch(we){console.error("Error resetting password:",we),Ee("网络错误,请稍后再试")}finally{_e(!1)}},X=$=>{Q($),Fe($.role==="admin"?"admin":"user"),Le("")},se=()=>{Q(null),Fe(""),Le("")},fe=async $=>{$.preventDefault(),Le(""),ze(!0);try{const we=await he.admin.updateUserRole(Be.id,Se),We=await we.json();we.ok?(i(l.map(Oe=>Oe.id===Be.id?{...Oe,role:Se}:Oe)),se()):Le(We.error||"更新角色失败")}catch(we){console.error("Error updating role:",we),Le("网络错误,请稍后再试")}finally{ze(!1)}},J=$=>$==="super_admin"?e.jsx(ro,{className:"w-4 h-4 text-amber-500 flex-shrink-0"}):$==="admin"?e.jsx($t,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(mr,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),Re=$=>$==="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:"超级管理员"}):$==="admin"?e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-blue-500/20 text-blue-400",children:"管理员"}):e.jsx("span",{className:"inline-block px-1.5 py-0.5 text-xs rounded whitespace-nowrap bg-gray-500/20 text-gray-400",children:"用户"});return g?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(U,{variant:"default",size:"sm",onClick:()=>y(!0),className:"flex items-center gap-2",children:[e.jsx(Gn,{className:"w-4 h-4"}),"创建用户"]}),r&&e.jsxs(U,{variant:"outline",size:"sm",onClick:r,className:"flex items-center gap-2",children:[e.jsx(Yn,{className:"w-4 h-4"}),"使用量统计"]})]})]}),e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[700px]",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-900/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-muted-foreground",children:"用户"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-24",children:"角色"}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium text-muted-foreground w-16",children:"状态"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-20",children:"费用"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-28",children:"额度限制"}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-muted-foreground w-24",children:"创建时间"}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium text-muted-foreground w-28",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:l.map($=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-900/30",children:[e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[J($.role),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground text-sm truncate",children:$.username||$.email}),$.email&&$.username&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:$.email})]})]})}),e.jsx("td",{className:"px-3 py-2 text-center",children:Re($.role)}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${$.status==="active"?"bg-green-500":"bg-red-500"}`,title:$.status==="active"?"活跃":"已禁用"})}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("span",{className:"font-mono text-xs text-foreground whitespace-nowrap",children:oe(c[$.uuid]?.total_cost)})}),e.jsx("td",{className:"px-3 py-2 text-right",children:te($)?e.jsx("button",{onClick:()=>de($),className:"text-xs text-blue-600 dark:text-blue-400 hover:underline font-mono whitespace-nowrap",title:"点击编辑额度限制",children:$.total_limit_usd!==null||$.daily_limit_usd!==null?e.jsxs("span",{className:"flex flex-col items-end text-[11px] leading-tight",children:[e.jsxs("span",{children:["总:",ae($.total_limit_usd)]}),e.jsxs("span",{children:["日:",ae($.daily_limit_usd)]})]}):e.jsxs("span",{className:"flex items-center gap-1 justify-end",children:[e.jsx(Cr,{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($.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[a&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>a($.uuid,$.username||$.email),title:"查看使用详情",children:e.jsx(Qn,{className:"w-4 h-4 text-indigo-500"})}),t&&$.role!=="super_admin"&&$.id!==o?.id&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>X($),title:"修改角色",children:e.jsx(Xn,{className:"w-4 h-4 text-purple-500"})}),$.role==="user"&&Ie($)&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>He($),title:"功能权限",children:e.jsx(Zn,{className:"w-4 h-4 text-green-500"})}),$.role==="user"&&Ie($)&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>je($),title:"Agent 可见性",children:e.jsx(eo,{className:"w-4 h-4 text-cyan-500"})}),Ie($)&&e.jsxs(e.Fragment,{children:[$.username&&e.jsx(U,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>ue($),disabled:f===$.id,title:"重置密码",children:e.jsx(dr,{className:"w-4 h-4 text-blue-500"})}),e.jsx(U,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>G($.id,$.status),disabled:f===$.id,title:$.status==="active"?"禁用用户":"启用用户",children:$.status==="active"?e.jsx(to,{className:"w-4 h-4 text-orange-500"}):e.jsx(so,{className:"w-4 h-4 text-green-500"})}),e.jsx(U,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>re($.id,$.username||$.email),disabled:f===$.id,title:"删除用户",children:e.jsx(lt,{className:"w-4 h-4 text-red-500"})})]})]})})]},$.id))})]})}),N&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card 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:F,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ke,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:C,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:p,onChange:$=>w($.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:j})]}),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:h,onChange:$=>S($.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:j})]}),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(U,{type:"button",variant:"outline",onClick:F,disabled:j,children:"取消"}),e.jsx(U,{type:"submit",disabled:j,children:j?"创建中...":"创建"})]})]})]})}),I&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-card border border-border rounded-lg shadow-lg w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-lg font-semibold text-foreground",children:["设置额度限制 - ",I.username||I.email]}),e.jsx("button",{onClick:pe,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ke,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:P,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:A.total_limit_usd,onChange:$=>T(we=>({...we,total_limit_usd:$.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:_}),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:A.daily_limit_usd,onChange:$=>T(we=>({...we,daily_limit_usd:$.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:_}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"用户每日使用金额达到此限制后,需等待次日重置"})]}),c[I.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:oe(c[I.uuid]?.total_cost)})]})}),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(U,{type:"button",variant:"outline",onClick:pe,disabled:_,children:"取消"}),e.jsx(U,{type:"submit",disabled:_,children:_?"保存中...":"保存"})]})]})]})}),V&&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:["重置密码 - ",V.username]}),e.jsx("button",{onClick:le,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ke,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"resetNewPassword",className:"block text-sm font-medium text-foreground mb-1",children:"新密码"}),e.jsx("input",{type:"password",id:"resetNewPassword",value:ne,onChange:$=>ve($.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:Me})]}),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:ye,onChange:$=>xe($.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:Me})]}),ke&&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:ke})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(U,{type:"button",variant:"outline",onClick:le,disabled:Me,children:"取消"}),e.jsx(U,{type:"submit",disabled:Me,children:Me?"重置中...":"重置密码"})]})]})]})}),Be&&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:["修改角色 - ",Be.username||Be.email]}),e.jsx("button",{onClick:se,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ke,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:fe,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:$=>Fe($.target.value),className:"text-blue-600",disabled:Te}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($t,{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:$=>Fe($.target.value),className:"text-blue-600",disabled:Te}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mr,{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:"受额度限制,无管理权限"})]})]})]}),Ne&&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:Ne})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(U,{type:"button",variant:"outline",onClick:se,disabled:Te,children:"取消"}),e.jsx(U,{type:"submit",disabled:Te,children:Te?"保存中...":"保存"})]})]})]})}),Ce&&e.jsx(jl,{user:Ce,onClose:()=>He(null),onSaved:()=>Ae()}),Ve&&e.jsx(wl,{user:Ve,onClose:()=>je(null),onSaved:()=>Ae()})]})}function Nl(){const[t,r]=s.useState(""),[a,o]=s.useState(!0),[n,l]=s.useState(!1),[i,c]=s.useState(null);s.useEffect(()=>{u()},[]);const u=async()=>{try{const x=await he.admin.getDefaultLimits();if(x.ok){const f=await x.json();r(f.default_total_limit_usd!==null?String(f.default_total_limit_usd):"")}}catch(x){console.error("Error fetching default limits:",x)}finally{o(!1)}},g=async x=>{x.preventDefault(),l(!0),c(null);const f=t.trim()===""?null:parseFloat(t);if(f!==null&&(isNaN(f)||f<0)){c("error"),l(!1);return}try{(await he.admin.updateDefaultLimits({default_total_limit_usd:f})).ok?(c("success"),setTimeout(()=>c(null),2e3)):c("error")}catch(b){console.error("Error updating default limits:",b),c("error")}finally{l(!1)}};return a?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"正在加载..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"新用户默认额度"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"新注册用户将自动应用此总额度限制,留空表示不限制。管理员账户不受此限制。"})]}),e.jsxs("form",{onSubmit:g,className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1 max-w-xs",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-1",children:"默认总额度上限 (USD)"}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:t,onChange:x=>r(x.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"留空表示不限制",disabled:n})]}),e.jsxs(U,{type:"submit",variant:"default",size:"sm",disabled:n,className:"flex items-center gap-2",children:[e.jsx(wr,{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:"此设置仅影响新注册的用户,不会修改已有用户的额度。"})]})}const Sl=[{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 Cl(){const[t,r]=s.useState({}),[a,o]=s.useState(!0),[n,l]=s.useState(!1),[i,c]=s.useState(null);s.useEffect(()=>{u()},[]);const u=async()=>{try{const f=await he.admin.getDefaultPermissions();if(f.ok){const b=await f.json();r(b.permissions||{})}}catch(f){console.error("Error fetching default permissions:",f)}finally{o(!1)}},g=f=>{r(b=>({...b,[f]:!b[f]}))},x=async f=>{f.preventDefault(),l(!0),c(null);try{(await he.admin.updateDefaultPermissions(t)).ok?(c("success"),setTimeout(()=>c(null),2e3)):c("error")}catch(b){console.error("Error updating default permissions:",b),c("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:Sl.map(f=>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:f.label}),e.jsx("button",{type:"button",role:"switch","aria-checked":t[f.key]!==!1,onClick:()=>g(f.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[f.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[f.key]!==!1?"translate-x-4":"translate-x-0"}`})})]},f.key))}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsxs(U,{type:"submit",variant:"default",size:"sm",disabled:n,className:"flex items-center gap-2",children:[e.jsx(wr,{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 El(){const{showConfirm:t}=tt(),[r,a]=s.useState([]),[o,n]=s.useState(!0),[l,i]=s.useState(null),[c,u]=s.useState(!1),[g,x]=s.useState(""),[f,b]=s.useState(""),[N,y]=s.useState(!1),p=async()=>{try{const m=await he.admin.getEmailDomains();if(m.ok){const v=await m.json();a(v.domains)}}catch(m){console.error("Error fetching email domains:",m)}finally{n(!1)}};s.useEffect(()=>{p()},[]);const w=async m=>{if(m.preventDefault(),b(""),!g){b("域名不能为空");return}if(!/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(g)){b("域名格式无效,例如: example.com");return}y(!0);try{const j=await he.admin.addEmailDomain(g.toLowerCase()),W=await j.json();j.ok?(await p(),u(!1),x("")):b(W.error||"添加域名失败")}catch(j){console.error("Error adding domain:",j),b("网络错误,请稍后再试")}finally{y(!1)}},h=async(m,v)=>{if(await t(`确定要删除域名 "${v}"?删除后该域名的邮箱将无法注册。`,{title:"删除域名",variant:"danger",confirmText:"确认删除"})){i(m);try{(await he.admin.removeEmailDomain(m)).ok&&a(r.filter(W=>W.id!==m))}catch(j){console.error("Error removing domain:",j)}finally{i(null)}}},S=()=>{u(!1),x(""),b("")};return o?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"正在加载..."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"邮箱域名白名单"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:r.length===0?"未设置白名单,所有邮箱域名均可注册":"只有白名单内的域名邮箱可以注册"})]}),e.jsxs(U,{variant:"default",size:"sm",onClick:()=>u(!0),className:"flex items-center gap-2",children:[e.jsx(Rt,{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(Ds,{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(U,{variant:"ghost",size:"sm",onClick:()=>h(m.id,m.domain),disabled:l===m.id,title:"删除域名",children:e.jsx(lt,{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(Ds,{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:"添加域名后,只有白名单内的域名邮箱可以注册"})]}),c&&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:S,className:"text-muted-foreground hover:text-foreground",children:e.jsx(Ke,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:w,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:g,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:N}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"输入域名后,该域名下的所有邮箱(如 user@example.com)都可以注册"})]}),f&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:f})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(U,{type:"button",variant:"outline",onClick:S,disabled:N,children:"取消"}),e.jsx(U,{type:"submit",disabled:N,children:N?"添加中...":"添加"})]})]})]})})]})}const Es={pending:{label:"待审核",className:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",icon:bs},approved:{label:"已通过",className:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",icon:Ca},rejected:{label:"已拒绝",className:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",icon:Sa}};function ha(t){return t?new Date(t).toLocaleString("zh-CN",{dateStyle:"short",timeStyle:"short"}):"-"}function Ml({submissionId:t}){const[r,a]=s.useState(null),[o,n]=s.useState(!0),[l,i]=s.useState(0);if(s.useEffect(()=>{K(`/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(nt,{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 c=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,g)=>e.jsxs("button",{onClick:()=>i(g),className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded border transition-colors ${g===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(es,{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:c?.content||""})]})}function Ll(){const{showAlert:t,showConfirm:r}=tt(),[a,o]=s.useState([]),[n,l]=s.useState(!0),[i,c]=s.useState("pending"),[u,g]=s.useState(null),[x,f]=s.useState(null),[b,N]=s.useState(""),[y,p]=s.useState(null);s.useEffect(()=>{w()},[i]);const w=async()=>{try{l(!0);const v=i?`/api/agents/submissions?status=${i}`:"/api/agents/submissions",j=await K(v);if(j.ok){const W=await j.json();o(W.submissions||[])}else t("加载提交列表失败",{variant:"error"})}catch(v){t(v.message,{variant:"error"})}finally{l(!1)}},h=async v=>{if(await r(`确认通过 "${v.display_name}" 的审核?
164
- 系统将自动递增版本号并发布到 Agent 仓库。`,{title:"确认审核通过",confirmText:"确认通过",variant:"info"})){f(v.id);try{const W=await K(`/api/agents/submissions/${v.id}/approve`,{method:"POST"}),I=await W.json();W.ok?(t(`已通过审核,版本 v${I.version} 已发布到仓库。`,{title:"审核通过"}),w()):t(I.error||"操作失败",{variant:"error"})}catch(W){t(W.message,{variant:"error"})}finally{f(null)}}},S=v=>{p(v.id),N("")},m=async v=>{f(v.id);try{const j=await K(`/api/agents/submissions/${v.id}/reject`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:b})});if(j.ok)t("已拒绝该提交。",{title:"审核拒绝"}),p(null),w();else{const W=await j.json();t(W.error||"操作失败",{variant:"error"})}}catch(j){t(j.message,{variant:"error"})}finally{f(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:()=>c(v),className:`px-3 py-1 text-xs rounded-full border transition-colors ${i===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===""?"全部":Es[v]?.label},v||"all"))}),e.jsxs(U,{variant:"outline",size:"sm",onClick:w,className:"flex items-center gap-1.5",children:[e.jsx(nt,{className:`w-3.5 h-3.5 ${n?"animate-spin":""}`}),"刷新"]})]}),n?e.jsx("div",{className:"text-center py-8 text-gray-400 text-sm",children:"加载中..."}):a.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:["暂无",i?Es[i]?.label:"","提交记录"]}):e.jsx("div",{className:"space-y-2",children:a.map(v=>{const j=Es[v.status]||Es.pending,W=j.icon,I=u===v.id,O=x===v.id,A=y===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(Qe,{className:`text-xs ${j.className} flex items-center gap-1`,children:[e.jsx(W,{className:"w-3 h-3"}),j.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:["提交时间: ",ha(v.submitted_at)]}),v.reviewed_at&&e.jsxs("span",{children:["审核时间: ",ha(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(U,{size:"sm",className:"text-xs h-7 px-2.5 bg-green-600 hover:bg-green-700 text-white",onClick:()=>h(v),disabled:O,children:O?"处理中...":"通过"}),e.jsx(U,{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:()=>S(v),disabled:O,children:"拒绝"})]}),e.jsx("button",{onClick:()=>g(I?null:v.id),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:I?e.jsx(Na,{className:"w-4 h-4"}):e.jsx(ts,{className:"w-4 h-4"})})]})]}),I&&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(Ml,{submissionId:v.id})]}),A&&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:b,onChange:T=>N(T.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(U,{size:"sm",className:"text-xs h-7 px-2.5 bg-red-600 hover:bg-red-700 text-white",onClick:()=>m(v),disabled:O,children:O?"处理中...":"确认拒绝"}),e.jsx(U,{size:"sm",variant:"outline",className:"text-xs h-7 px-2.5",onClick:()=>p(null),disabled:O,children:"取消"})]})]})]},v.id)})})]})}function Il({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 c=(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(c,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 Dl({onBack:t}){const[r,a]=s.useState("week"),[o,n]=s.useState(null),[l,i]=s.useState(!0),[c,u]=s.useState(!1),g=async()=>{try{const h=await K(`/api/admin/usage/dashboard?period=${r}`);if(h.ok){const S=await h.json();n(S)}}catch(h){console.error("Error fetching dashboard data:",h)}finally{i(!1),u(!1)}};s.useEffect(()=>{i(!0),g()},[r]);const x=async()=>{try{u(!0),await K("/api/admin/usage/scan",{method:"POST"}),await g()}catch(h){console.error("Error triggering scan:",h),u(!1)}},f=h=>!h||h===0?"$0.00":h<.01?`$${h.toFixed(4)}`:`$${h.toFixed(2)}`,b=h=>h?h>=1e6?`${(h/1e6).toFixed(1)}M`:h>=1e3?`${(h/1e3).toFixed(1)}K`:h.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:N,dailyTrend:y,modelDistribution:p,topUsers:w}=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(U,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(rs,{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(h=>e.jsx("button",{onClick:()=>a(h),className:`px-4 py-2 text-sm font-medium transition-colors ${r===h?"bg-primary text-primary-foreground":"bg-background text-foreground hover:bg-muted"}`,children:h==="week"?"周":"月"},h))}),e.jsx(U,{variant:"outline",size:"sm",onClick:x,disabled:c,title:"扫描新的使用数据",children:e.jsx(nt,{className:`w-4 h-4 ${c?"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(Cr,{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:f(N?.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(Ma,{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:[N?.activeUsers||0," / ",N?.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(_s,{className:"w-5 h-5 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"总请求数"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:b(N?.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(La,{className:"w-5 h-5 text-orange-600 dark:text-orange-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"会话数"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:b(N?.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:"每日成本趋势"}),y&&y.length>0?e.jsx(Il,{days:y,formatCost:f,formatNumber:b}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]}),e.jsxs("div",{className:"bg-card border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-4",children:"模型成本"}),p&&p.length>0?e.jsx("div",{className:"space-y-3",children:p.map(h=>{const S=p.reduce((I,O)=>I+(O.cost||0),0)||1,m=(h.cost||0)/S*100,v=(h.normalized_model||h.model||"").toLowerCase(),W=(I=>I.includes("codex")?"bg-orange-500":I.includes("opus")?"bg-purple-500":I.includes("sonnet")?"bg-blue-500":I.includes("haiku")?"bg-green-500":"bg-gray-500")(v);return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Qe,{variant:"secondary",className:"truncate max-w-[200px]",title:h.model,children:h.model}),e.jsxs("span",{className:"text-sm text-muted-foreground whitespace-nowrap",children:[b(h.requests)," 请求"]})]}),e.jsx("span",{className:"text-sm font-mono text-foreground whitespace-nowrap ml-2",children:f(h.cost)})]}),e.jsx("div",{className:"h-2 bg-gray-100 dark:bg-gray-800 rounded overflow-hidden",children:e.jsx("div",{className:`h-full ${W} rounded`,style:{width:`${m}%`}})})]},h.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:"用户成本"}),w&&w.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:w.map((h,S)=>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:["#",S+1]}),e.jsx("td",{className:"py-2 text-sm font-medium text-foreground",children:h.username}),e.jsx("td",{className:"py-2 text-sm text-right text-muted-foreground",children:b(h.total_requests)}),e.jsx("td",{className:"py-2 text-sm text-right font-mono text-foreground",children:f(h.total_cost)})]},h.user_uuid))})]})}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"无可用的使用数据"})]})]})}const fa={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 ga(t=""){const r=t.toLowerCase();return r.includes("codex")?"codex":r.includes("opus")?"opus":r.includes("sonnet")?"sonnet":r.includes("haiku")?"haiku":"default"}function Pr(t){return!t||t===0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function yr(t){return t?t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString():"0"}function Tl(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 Al({data:t}){const[r,a]=s.useState(null),o=140,n=o/2,l=o/2,i=56,c=t.reduce((x,f)=>x+(f.cost||0),0)||1;let u=-Math.PI/2;const g=t.map(x=>{const f=(x.cost||0)/c,b=f*2*Math.PI,N=u+b,y=n+i*Math.cos(u),p=l+i*Math.sin(u),w=n+i*Math.cos(N),h=l+i*Math.sin(N),S=b>Math.PI?1:0,m=f<.001?"":`M ${n} ${l} L ${y} ${p} A ${i} ${i} 0 ${S} 1 ${w} ${h} Z`,v=u+b/2,j={...x,pathD:m,ratio:f,midAngle:v,key:x.model};return u=N,j});return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("svg",{width:o,height:o,className:"flex-shrink-0",children:[g.map(x=>e.jsx("path",{d:x.pathD,fill:fa.hex[ga(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:g.map(x=>{const f=(x.ratio*100).toFixed(1),b=ga(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 ${fa.tailwind[b]}`}),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:[f,"%"]}),e.jsx("span",{className:"text-xs font-mono text-foreground flex-shrink-0 w-14 text-right",children:Pr(x.cost)})]},x.key)})})]})}function Rl({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:["费用:",Pr(r.cost)]}),e.jsxs("div",{className:"text-muted-foreground",children:["请求:",yr(r.requests)]})]})]})}function Pl({userUuid:t,username:r,onBack:a}){const[o,n]=s.useState(null),[l,i]=s.useState(!0);s.useEffect(()=>{(async()=>{try{const f=await K(`/api/admin/usage/users/${t}?period=week`);f.ok&&n(await f.json())}catch(f){console.error("Error fetching user usage:",f)}finally{i(!1)}})()},[t]);const c=Tl(7),u={};(o?.dailyTrend||[]).forEach(x=>{u[x.date]=x});const g=c.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(U,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(rs,{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(Cr,{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:Pr(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(_s,{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:yr(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(La,{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:yr(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(Rl,{days:g})]}),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(Al,{data:o.modelDistribution}):e.jsx("div",{className:"flex items-center justify-center h-36 text-muted-foreground text-sm",children:"暂无使用数据"})]})]})]})}function $l({isOpen:t,onClose:r}){const{isAdmin:a,isSuperAdmin:o}=mt(),[n,l]=s.useState("users"),[i,c]=s.useState(!1),[u,g]=s.useState(null);if(!t||!a)return null;const x=[{id:"users",label:"用户管理",icon:Ma},{id:"system",label:"系统设置",icon:ao},{id:"agents",label:"Agent 审核",icon:St}],f=b=>{l(b),c(!1),g(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($t,{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(U,{variant:"ghost",size:"sm",onClick:r,className:"text-muted-foreground hover:text-foreground touch-manipulation",children:e.jsx(Ke,{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(b=>e.jsx("button",{onClick:()=>f(b.id),className:`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${n===b.id?"border-blue-600 text-blue-600 dark:text-blue-400":"border-transparent text-muted-foreground hover:text-foreground"}`,children:b.label},b.id))})}),e.jsx("div",{className:"hidden md:flex flex-col w-48 border-r border-border p-3 gap-1 flex-shrink-0",children:x.map(b=>{const N=b.icon;return e.jsxs("button",{onClick:()=>f(b.id),className:`flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${n===b.id?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground hover:bg-accent/50"}`,children:[e.jsx(N,{className:"w-4 h-4"}),b.label]},b.id)})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 md:p-6",children:[n==="users"&&e.jsx("div",{className:"space-y-6 md:space-y-8",children:i?e.jsx(Dl,{onBack:()=>c(!1)}):u?e.jsx(Pl,{userUuid:u.uuid,username:u.username,onBack:()=>g(null)}):e.jsx(kl,{isSuperAdmin:o,onNavigateToUsage:()=>c(!0),onViewUser:(b,N)=>g({uuid:b,username:N})})}),n==="system"&&e.jsxs("div",{className:"space-y-6 md:space-y-8",children:[e.jsx(Nl,{}),e.jsx("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 md:pt-8",children:e.jsx(Cl,{})}),e.jsx(El,{})]}),n==="agents"&&e.jsx(Ll,{})]})]})]})})}function _l({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(At,{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(Ke,{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(U,{variant:"default",onClick:a,children:"我知道了"})})]})})}function zl(){const[t,r]=s.useState(null),[a,o]=s.useState([]),[n,l]=s.useState(!1),i=s.useRef(null),c=s.useRef(null),{token:u}=mt();s.useEffect(()=>(i.current&&(clearTimeout(i.current),i.current=null),c.current&&(c.current.close(),c.current=null),u?g():(l(!1),r(null)),()=>{i.current&&clearTimeout(i.current),c.current&&c.current.close()}),[u]);const g=()=>{try{const f=u||localStorage.getItem("auth-token");if(!f){console.warn("No authentication token found for WebSocket connection");return}const N=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws?token=${encodeURIComponent(f)}`,y=new WebSocket(N);c.current=y,y.onopen=()=>{l(!0),r(y)},y.onmessage=p=>{try{const w=JSON.parse(p.data);o(h=>[...h,w])}catch(w){console.error("Error parsing WebSocket message:",w)}},y.onclose=()=>{l(!1),r(null),c.current=null,(localStorage.getItem("auth-token")||isPlatform)&&(i.current=setTimeout(()=>{g()},3e3))},y.onerror=p=>{console.error("WebSocket error:",p)}}catch(f){console.error("Error creating WebSocket connection:",f)}};return{ws:t,sendMessage:f=>{t&&n?t.send(JSON.stringify(f)):console.warn("WebSocket not connected")},messages:a,isConnected:n}}const Va=s.createContext({ws:null,sendMessage:()=>{},messages:[],isConnected:!1}),Ol=()=>{const t=s.useContext(Va);if(!t)throw new Error("useWebSocketContext must be used within a WebSocketProvider");return t},Fl=({children:t})=>{const r=zl();return e.jsx(Va.Provider,{value:r,children:t})},Wl=()=>{const[t,r]=s.useState("email"),[a,o]=s.useState(""),[n,l]=s.useState(""),[i,c]=s.useState(!1),[u,g]=s.useState(""),[x,f]=s.useState(0),{sendCode:b,verifyCode:N,smtpConfigured:y}=mt();s.useEffect(()=>{if(x>0){const m=setTimeout(()=>f(x-1),1e3);return()=>clearTimeout(m)}},[x]);const p=async m=>{if(m.preventDefault(),g(""),!a||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)){g("请输入有效的邮箱地址");return}c(!0);const j=await b(a);j.success?(r("code"),f(60)):(g(j.error),j.waitSeconds&&f(j.waitSeconds)),c(!1)},w=async m=>{if(m.preventDefault(),g(""),!n||n.length!==6){g("请输入6位验证码");return}c(!0);const v=await N(a,n);v.success||g(v.error),c(!1)},h=async()=>{if(x>0)return;g(""),c(!0);const m=await b(a);m.success?f(60):g(m.error),c(!1)},S=()=>{r("email"),l(""),g("")};return y?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(Ps,{size:64})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:t==="email"?"欢迎使用 AgentHub":"创建管理员账户"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?"输入邮箱创建管理员账户":`验证码已发送至 ${a}`})]}),t==="email"&&e.jsxs("form",{onSubmit:p,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-foreground mb-1",children:"邮箱地址"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ds,{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:w,className:"space-y-4",children:[e.jsxs("button",{type:"button",onClick:S,className:"flex items-center text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(rs,{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:h,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(Ps,{size:64})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"欢迎使用 AgentHub"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"系统初始化"})]}),e.jsxs("div",{className:"p-4 bg-yellow-100 dark:bg-yellow-900/20 border border-yellow-300 dark:border-yellow-800 rounded-md",children:[e.jsx("p",{className:"text-sm text-yellow-700 dark:text-yellow-400",children:"SMTP 邮件服务未配置。请联系管理员配置以下环境变量后重启服务:"}),e.jsxs("ul",{className:"mt-2 text-sm text-yellow-700 dark:text-yellow-400 list-disc list-inside",children:[e.jsx("li",{children:"SMTP_SERVER"}),e.jsx("li",{children:"SMTP_PORT"}),e.jsx("li",{children:"SMTP_USERNAME"}),e.jsx("li",{children:"SMTP_PASSWORD"})]})]})]})})})},Ul=()=>{const[t,r]=s.useState("email"),[a,o]=s.useState("email"),[n,l]=s.useState(""),[i,c]=s.useState(""),[u,g]=s.useState(""),[x,f]=s.useState(""),[b,N]=s.useState(!1),[y,p]=s.useState(""),[w,h]=s.useState(0),[S,m]=s.useState(!1),{login:v,sendCode:j,verifyCode:W,smtpConfigured:I}=mt();s.useEffect(()=>{if(w>0){const V=setTimeout(()=>h(w-1),1e3);return()=>clearTimeout(V)}},[w]),s.useEffect(()=>{I||r("password")},[I]);const O=async V=>{if(V.preventDefault(),p(""),!n||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)){p("请输入有效的邮箱地址");return}N(!0);const ne=await j(n);ne.success?(o("code"),h(60),m(ne.type==="register")):(p(ne.error),ne.waitSeconds&&h(ne.waitSeconds)),N(!1)},A=async V=>{if(V.preventDefault(),p(""),!i||i.length!==6){p("请输入6位验证码");return}N(!0);const ee=await W(n,i);ee.success||p(ee.error),N(!1)},T=async()=>{if(w>0)return;p(""),N(!0);const V=await j(n);V.success?h(60):p(V.error),N(!1)},M=async V=>{if(V.preventDefault(),p(""),!u||!x){p("请输入用户名和密码");return}N(!0);const ee=await v(u,x);ee.success||p(ee.error),N(!1)},B=()=>{o("email"),c(""),p("")},_=()=>{r("email"),o("email"),p("")},ce=()=>{r("password"),p("")};return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx("div",{className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-lg border border-border p-8 space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("img",{src:"/logo.svg",className:"w-16 h-16",alt:"AgentHub"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:t==="email"?a==="email"?"欢迎使用 AgentHub":S?"创建您的账户":"验证您的身份":"欢迎回来"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:t==="email"?a==="email"?"输入邮箱以接收验证码":`验证码已发送至 ${n}`:"使用账号密码登录"})]}),t==="email"&&a==="email"&&e.jsxs("form",{onSubmit:O,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(Ds,{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:V=>l(V.target.value),className:"w-full pl-10 pr-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入邮箱地址",required:!0,disabled:b,autoComplete:"email"})]})]}),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.jsx("button",{type:"submit",disabled:b||w>0,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:b?"发送中...":w>0?`${w}秒后可重新发送`:"获取验证码"})]}),t==="email"&&a==="code"&&e.jsxs("form",{onSubmit:A,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(rs,{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:V=>c(V.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground text-center text-2xl tracking-widest focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"000000",required:!0,disabled:b,maxLength:6,autoComplete:"one-time-code"})]}),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.jsx("button",{type:"submit",disabled:b||i.length!==6,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:b?"验证中...":S?"创建账户并登录":"登录"}),e.jsx("div",{className:"text-center",children:e.jsx("button",{type:"button",onClick:T,disabled:w>0||b,className:"text-sm text-blue-500 hover:text-blue-600 disabled:text-muted-foreground",children:w>0?`${w}秒后可重新发送`:"重新发送验证码"})})]}),t==="password"&&e.jsxs("form",{onSubmit:M,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(mr,{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:V=>g(V.target.value),className:"w-full pl-10 pr-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入用户名",required:!0,disabled:b})]})]}),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(no,{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:V=>f(V.target.value),className:"w-full pl-10 pr-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"请输入密码",required:!0,disabled:b})]})]}),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.jsx("button",{type:"submit",disabled:b,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:b?"登录中...":"登录"})]}),e.jsx("div",{className:"text-center pt-4 border-t border-border",children:t==="email"&&I?e.jsx("button",{type:"button",onClick:ce,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用账号密码登录"}):t==="password"&&I?e.jsx("button",{type:"button",onClick:_,className:"text-sm text-muted-foreground hover:text-foreground",children:"使用邮箱验证码登录"}):null})]})})})},Bl=()=>e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("div",{className:"w-16 h-16 bg-primary rounded-lg flex items-center justify-center shadow-sm",children:e.jsx(_s,{className:"w-8 h-8 text-primary-foreground"})})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground mb-2",children:"AgentHub"}),e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce"}),e.jsx("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),e.jsx("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"加载中..."})]})}),Hl=({children:t})=>{const{user:r,isLoading:a,needsSetup:o}=mt();return a?e.jsx(Bl,{}):o?e.jsx(Wl,{}):r?t:e.jsx(Ul,{})};function or(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 ba(){const t=va(),{sessionId:r}=An(),{limitStatus:a,setLimitStatus:o,checkLimitStatus:n,user:l,isAdmin:i}=mt(),[c,u]=s.useState([]),[g,x]=s.useState(null),[f,b]=s.useState(null),[N,y]=s.useState("chat"),[p,w]=s.useState(!1),[h,S]=s.useState(!1),[m,v]=s.useState(!0),[j,W]=s.useState(!1),[I,O]=s.useState(!1),[A,T]=s.useState(!1),[M,B]=s.useState("agents"),[_,ce]=or("autoScrollToBottom",!0),[V,ee]=or("sendByCtrlEnter",!1),[ne,ve]=or("sidebarVisible",!0),[ye,xe]=s.useState(!1),[ke,Ee]=s.useState(null),[Me,_e]=s.useState(new Set),[Be,Q]=s.useState(new Set),[Se,Fe]=s.useState(0),{ws:Ne,sendMessage:Le,messages:Te}=Ol(),ze=s.useCallback(P=>{Ee(P),xe(!0)},[]),[Ce,He]=s.useState(!1);s.useEffect(()=>{const P=()=>{const ae=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone||document.referrer.includes("android-app://");He(ae),document.addEventListener("touchstart",{}),ae?(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 P(),window.matchMedia("(display-mode: standalone)").addEventListener("change",P),()=>{window.matchMedia("(display-mode: standalone)").removeEventListener("change",P)}},[]),s.useEffect(()=>{const P=()=>{w(window.innerWidth<768)};return P(),window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[]),s.useEffect(()=>{je()},[]);const Ve=(P,ae,ue,le)=>{if(!ue||!le)return!0;const k=P?.find(Re=>Re.name===ue.name),X=ae?.find(Re=>Re.name===ue.name);if(!k||!X)return!1;const se=k.sessions?.find(Re=>Re.id===le.id),fe=X.sessions?.find(Re=>Re.id===le.id);return!se||!fe?!1:se.id===fe.id&&se.title===fe.title&&se.created_at===fe.created_at&&se.updated_at===fe.updated_at};s.useEffect(()=>{if(Te.length>0){const P=Te[Te.length-1];if(P.type==="projects_updated"){if(P.changedFile&&f&&g){const k=P.changedFile.replace(/\\/g,"/").split("/");k.length>=2&&k[k.length-1].replace(".jsonl","")===f.id&&(Me.has(f.id)||Fe(J=>J+1))}if(f&&Me.has(f.id)||Me.size>0&&Array.from(Me).some(le=>le.startsWith("new-session-"))){const le=P.projects;if(!Ve(c,le,g,f))return}const ue=P.projects;if(u(ue),g){const le=ue.find(k=>k.name===g.name);le&&(JSON.stringify(le)!==JSON.stringify(g)&&x(le),f&&([...le.sessions||[]].find(se=>se.id===f.id)||b(null)))}}}},[Te,g,f,Me]);const je=async()=>{try{v(!0);const ae=await(await he.projects()).json();u(ue=>ue.length===0||ae.some((k,X)=>{const se=ue[X];return se?k.name!==se.name||k.displayName!==se.displayName||k.fullPath!==se.fullPath||JSON.stringify(k.sessionMeta)!==JSON.stringify(se.sessionMeta)||JSON.stringify(k.sessions)!==JSON.stringify(se.sessions)||JSON.stringify(k.agentInfo)!==JSON.stringify(se.agentInfo):!0})||ae.length!==ue.length?ae:ue)}catch(P){console.error("Error fetching projects:",P)}finally{v(!1)}};window.refreshProjects=je,window.openSettings=s.useCallback((P="tools")=>{B(P),O(!0)},[]),window.openAdminPanel=s.useCallback(()=>{T(!0)},[]),s.useEffect(()=>{if(r&&c.length>0){const P=!f||f.id!==r;for(const ae of c){let ue=ae.sessions?.find(le=>le.id===r);if(ue){x(ae),b({...ue,__provider:"claude"}),P&&y("chat");return}}}},[r,c,t]);const Ae=P=>{x(P),b(null),t("/"),p&&S(!1)},q=P=>{if(b(P),N!=="git"&&N!=="preview"&&y("chat"),p){const ae=P.__projectName,ue=g?.name;ae!==ue&&S(!1)}t(`/session/${P.id}`)},oe=P=>{x(P),b(null),y("chat"),t("/"),p&&S(!1)},te=P=>{f?.id===P&&(b(null),t("/")),u(ae=>ae.map(ue=>({...ue,sessions:ue.sessions?.filter(le=>le.id!==P)||[],sessionMeta:{...ue.sessionMeta,total:Math.max(0,(ue.sessionMeta?.total||0)-1)}})))},Ie=async()=>{try{const ae=await(await he.projects()).json();if(u(ue=>ae.some((k,X)=>{const se=ue[X];return se?k.name!==se.name||k.displayName!==se.displayName||k.fullPath!==se.fullPath||JSON.stringify(k.sessionMeta)!==JSON.stringify(se.sessionMeta)||JSON.stringify(k.sessions)!==JSON.stringify(se.sessions):!0})||ae.length!==ue.length?ae:ue),g){const ue=ae.find(le=>le.name===g.name);if(ue&&(JSON.stringify(ue)!==JSON.stringify(g)&&x(ue),f)){const le=ue.sessions?.find(k=>k.id===f.id);le&&JSON.stringify(le)!==JSON.stringify(f)&&b(le)}}}catch(P){console.error("Error refreshing sidebar:",P)}},G=P=>{g?.name===P&&(x(null),b(null),t("/")),u(ae=>ae.filter(ue=>ue.name!==P))},re=s.useCallback(P=>{P&&_e(ae=>new Set([...ae,P]))},[]),C=s.useCallback(P=>{P&&_e(ae=>{const ue=new Set(ae);return ue.delete(P),ue})},[]),F=s.useCallback(P=>{P&&Q(ae=>new Set([...ae,P]))},[]),de=s.useCallback(P=>{P&&Q(ae=>{const ue=new Set(ae);return ue.delete(P),ue})},[]),pe=s.useCallback(P=>{P&&_e(ae=>{const ue=new Set;for(const le of ae)le.startsWith("new-session-")||ue.add(le);return ue.add(P),ue})},[]);return e.jsxs("div",{className:"fixed inset-0 flex bg-background",children:[!p&&e.jsx("div",{className:`h-full flex-shrink-0 border-r border-border bg-card transition-all duration-300 ${ne?"w-80":"w-14"}`,children:e.jsx("div",{className:"h-full overflow-hidden",children:ne?e.jsx(Qr,{projects:c,selectedProject:g,selectedSession:f,onProjectSelect:Ae,onSessionSelect:q,onNewSession:oe,onSessionDelete:te,onProjectDelete:G,isLoading:m,onRefresh:Ie,onShowSettings:()=>O(!0),onShowAdmin:()=>T(!0),isPWA:Ce,isMobile:p,onToggleSidebar:()=>ve(!1)}):e.jsxs("div",{className:"h-full flex flex-col items-center py-4 gap-4",children:[e.jsx("button",{onClick:()=>ve(!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:()=>O(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Settings",title:"Settings",children:e.jsx(Pt,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})}),i&&e.jsx("button",{onClick:()=>T(!0),className:"p-2 hover:bg-accent rounded-md transition-colors duration-200","aria-label":"Admin",title:"管理",children:e.jsx($t,{className:"w-5 h-5 text-muted-foreground hover:text-foreground transition-colors"})})]})})}),p&&e.jsxs("div",{className:`fixed inset-0 z-50 flex transition-all duration-150 ease-out ${h?"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:P=>{P.stopPropagation(),S(!1)},onTouchStart:P=>{P.preventDefault(),P.stopPropagation(),S(!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 ${h?"translate-x-0":"-translate-x-full"}`,onClick:P=>P.stopPropagation(),onTouchStart:P=>P.stopPropagation(),children:e.jsx(Qr,{projects:c,selectedProject:g,selectedSession:f,onProjectSelect:Ae,onSessionSelect:q,onNewSession:oe,onSessionDelete:te,onProjectDelete:G,isLoading:m,onRefresh:Ie,onShowSettings:()=>O(!0),onShowAdmin:()=>T(!0),isPWA:Ce,isMobile:p,onToggleSidebar:()=>ve(!1)})})]}),e.jsx("div",{className:`flex-1 flex flex-col min-w-0 ${p&&!j?"pb-mobile-nav":""}`,children:e.jsx(Xi,{selectedProject:g,selectedSession:f,activeTab:N,setActiveTab:y,ws:Ne,sendMessage:Le,messages:Te,isMobile:p,isPWA:Ce,onMenuClick:()=>S(!0),isLoading:m,onInputFocusChange:W,onSessionActive:re,onSessionInactive:C,onSessionProcessing:F,onSessionNotProcessing:de,processingSessions:Be,onReplaceTemporarySession:pe,onNavigateToSession:P=>t(`/session/${P}`),onShowSettings:()=>O(!0),autoScrollToBottom:_,sendByCtrlEnter:V,externalMessageUpdate:Se,limitStatus:a,onLimitBlocked:ze,checkLimitStatus:n})}),p&&e.jsx(Zi,{activeTab:N,setActiveTab:y,isInputFocused:j}),e.jsx(vl,{isOpen:I,onClose:()=>O(!1),projects:c,initialTab:M,autoScrollToBottom:_,onAutoScrollChange:ce,sendByCtrlEnter:V,onSendByCtrlEnterChange:ee}),e.jsx($l,{isOpen:A,onClose:()=>T(!1)}),e.jsx(_l,{isOpen:ye,limitType:ke,onClose:()=>xe(!1)})]})}function Jl(){return e.jsx(tl,{children:e.jsx(Co,{children:e.jsx(Fl,{children:e.jsx(No,{children:e.jsx(Hl,{children:e.jsx(Dn,{children:e.jsxs(Tn,{children:[e.jsx(Hr,{path:"/",element:e.jsx(ba,{})}),e.jsx(Hr,{path:"/session/:sessionId",element:e.jsx(ba,{})})]})})})})})})})}bo.createRoot(document.getElementById("root")).render(e.jsx(ft.StrictMode,{children:e.jsx(Jl,{})}));