@versot/vaguspi 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-CkJ4eBhw.js","assets/vendor-CkEpMl6t.js"])))=>i.map(i=>d[i]);
2
+ var qn=Object.defineProperty;var Nn=(n,o,t)=>o in n?qn(n,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[o]=t;var Ie=(n,o,t)=>Nn(n,typeof o!="symbol"?o+"":o,t);import{j as e,r as a,R as Vt,a as Ut,c as Vn}from"./vendor-CkEpMl6t.js";import{u as N,a as Ke,b as Kt,L as Un,D as Kn,h as Yn,J as Xn,T as Jn,A as Gn}from"./settings-CkJ4eBhw.js";(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const l of i.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function t(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=t(s);fetch(s.href,i)}})();const Qn="modulepreload",Zn=function(n){return"/"+n},Bt={},Yt=function(o,t,r){let s=Promise.resolve();if(t&&t.length>0){let l=function(g){return Promise.all(g.map(x=>Promise.resolve(x).then(f=>({status:"fulfilled",value:f}),f=>({status:"rejected",reason:f}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),p=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));s=l(t.map(g=>{if(g=Zn(g),g in Bt)return;Bt[g]=!0;const x=g.endsWith(".css"),f=x?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${g}"]${f}`))return;const h=document.createElement("link");if(h.rel=x?"stylesheet":Qn,x||(h.as="script"),h.crossOrigin="",h.href=g,p&&h.setAttribute("nonce",p),document.head.appendChild(h),x)return new Promise((u,I)=>{h.addEventListener("load",u),h.addEventListener("error",()=>I(new Error(`Unable to preload CSS for ${g}`)))})}))}function i(l){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=l,window.dispatchEvent(c),!c.defaultPrevented)throw l}return s.then(l=>{for(const c of l||[])c.status==="rejected"&&i(c.reason);return o().catch(i)})},we="background 0.15s, color 0.15s";function Xt(n){const o=new Date(n).getTime();if(Number.isNaN(o))return"";const t=Math.max(0,Math.round((Date.now()-o)/6e4));if(t<1)return"now";if(t<60)return`${t}m`;const r=Math.round(t/60);return r<24?`${r}h`:`${Math.round(r/24)}d`}function Jt(n){const o=n.replace(/\\/g,"/").split("/").filter(Boolean);return o[o.length-1]??n}function ht(n,o){return e.jsx("div",{style:{display:"grid",gridTemplateRows:n?"1fr":"0fr",transition:"grid-template-rows 0.2s ease"},children:e.jsx("div",{style:{overflow:"hidden",minHeight:0},children:o})})}function pt({size:n=14,color:o}){return e.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",style:{flexShrink:0,color:o},children:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function eo(n){const o=N(),[t,r]=a.useState(!1),s=a.useMemo(()=>n.archivedProjects.filter(i=>i.sessions.length>0).toSorted((i,l)=>l.sessions[0].modified.localeCompare(i.sessions[0].modified)),[n.archivedProjects]);return n.archivedProjects.length===0?null:e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>r(i=>!i),style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px",borderRadius:8,cursor:"pointer",userSelect:"none",fontSize:"0.88em",fontWeight:500,color:o.color.muted,marginTop:8,transition:we},onMouseEnter:i=>{i.currentTarget.style.background=o.color.sidebarHover},onMouseLeave:i=>{i.currentTarget.style.background="transparent"},children:[e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",style:{flexShrink:0},children:[e.jsx("path",{d:"M21 8l-2-4H5L3 8v2h18V8z"}),e.jsx("path",{d:"M3 10v8a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-8"}),e.jsx("path",{d:"M12 13v3"})]}),e.jsx("span",{style:{flex:1,textAlign:"left"},children:"已归档"}),e.jsx("span",{style:{fontSize:"0.75em",color:o.color.muted,background:o.color.sidebarHover,borderRadius:8,padding:"1px 7px"},children:n.archivedProjects.length}),e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0,transform:t?"rotate(0)":"rotate(-90deg)",transition:"transform 0.15s ease"},children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]}),ht(t,e.jsx("div",{style:{paddingLeft:6},children:s.map(({cwd:i,sessions:l})=>{const c=!n.collapsed.has(`arch:${i}`);return e.jsxs("div",{style:{marginBottom:1},children:[e.jsxs("div",{onClick:()=>n.onToggleProject(`arch:${i}`),onContextMenu:p=>n.onProjectContextMenu(p,i),style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:8,cursor:"pointer",userSelect:"none",fontSize:"0.9em",fontWeight:500,color:o.color.muted,opacity:.85,transition:we},onMouseEnter:p=>{p.currentTarget.style.background=o.color.sidebarHover,p.currentTarget.style.opacity="1"},onMouseLeave:p=>{p.currentTarget.style.background="transparent",p.currentTarget.style.opacity="0.85"},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",style:{flexShrink:0},children:[e.jsx("path",{d:"M21 8l-2-4H5L3 8v2h18V8z"}),e.jsx("path",{d:"M3 10v8a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-8"})]}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Jt(i)}),e.jsx("span",{style:{fontSize:"0.75em",color:o.color.muted,flexShrink:0},children:l.length}),e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0,transform:c?"rotate(0)":"rotate(-90deg)",transition:"transform 0.15s ease"},children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]}),ht(c,e.jsx("div",{style:{paddingLeft:30},children:l.map(p=>e.jsxs("div",{onClick:()=>n.onOpenSession(p.path),onContextMenu:g=>n.onSessionContextMenu(g,p,!0),onMouseEnter:g=>g.currentTarget.style.background=o.color.sidebarHover,onMouseLeave:g=>g.currentTarget.style.background="transparent",style:{display:"flex",alignItems:"center",gap:7,padding:"6px 10px",borderRadius:10,cursor:"pointer",userSelect:"none",fontSize:"0.89em",color:o.color.muted,overflow:"hidden",whiteSpace:"nowrap",transition:we},children:[e.jsx(pt,{}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(p.name??p.firstMessage.slice(0,40))||"(空会话)"}),n.busyPaths.has(p.path)&&e.jsx("span",{title:"工作中",style:{width:7,height:7,borderRadius:"50%",background:"linear-gradient(135deg,#6366f1,#8b5cf6)",animation:"vagus-pulse 1.2s ease-in-out infinite",flexShrink:0,display:"inline-block"}}),e.jsx("span",{style:{fontSize:"0.79em",color:o.color.muted,flexShrink:0},children:Xt(p.modified)})]},p.id))}))]},i)})}))]})}const Ce="#6366f1",Ze="#8b5cf6",Lt="0 0 0 2px rgba(99,102,241,0.4)";function zt({sessions:n,activePath:o,onNewSession:t,onOpenSession:r,onOpenSettings:s,onOpenPlugins:i,onRenameSession:l,onDeleteSession:c,onArchiveSession:p,onRestoreSession:g,onDeleteArchivedSession:x,onTogglePin:f,pinnedSessions:h=new Set,archivedProjects:u=[],onArchiveProject:I,onUnarchiveProject:w,onDeleteProject:b,busyPaths:m=new Set,pendingDialogPaths:j=new Set}){const k=N(),{theme:B}=Ke(),[H,P]=a.useState(new Set),[z,F]=a.useState(null),[M,O]=a.useState(),[_,Z]=a.useState(""),G=a.useMemo(()=>{const S=new Map;for(const A of n){const V=S.get(A.cwd)??[];V.push(A),S.set(A.cwd,V)}return[...S.entries()].toSorted((A,V)=>V[1][0].modified.localeCompare(A[1][0].modified)).map(([A,V])=>[A,V.toSorted((se,U)=>Number(h.has(U.path))-Number(h.has(se.path))||U.modified.localeCompare(se.modified))])},[n,h]),Q=S=>{P(A=>{const V=new Set(A);return V.has(S)?V.delete(S):V.add(S),V})},K=(S,A,V=!1)=>{S.preventDefault(),F({x:S.clientX,y:S.clientY,kind:"session",session:A,archived:V})},ee=(S,A)=>{S.preventDefault(),F({x:S.clientX,y:S.clientY,kind:"project",cwd:A})},y=()=>F(null);a.useEffect(()=>{if(!z)return;const S=V=>{V.target.closest("[data-context-menu]")||y()},A=V=>{V.key==="Escape"&&y()};return document.addEventListener("mousedown",S),document.addEventListener("keydown",A),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("keydown",A)}},[z]);const T=S=>{O(S.path),Z(S.name??S.firstMessage.slice(0,40)),F(null)},$={display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderRadius:7,cursor:"pointer",userSelect:"none",fontSize:"0.89em",color:k.color.fg,transition:"background 0.15s"},L=S=>{const A=_.trim();O(void 0),A&&l&&l(S,A)},te=n.find(S=>S.path===o),re=te==null?void 0:te.cwd,je=280,Ee=B==="light"?"rgba(99,102,241,0.10)":"rgba(99,102,241,0.16)",Te={display:"flex",alignItems:"center",gap:8,height:40,padding:"0 14px",borderRadius:12,background:`linear-gradient(135deg, ${Ce}, ${Ze})`,border:"none",color:"#fff",fontSize:"0.96em",fontWeight:600,cursor:"pointer",userSelect:"none",transition:"filter 0.15s, box-shadow 0.15s, transform 0.15s",boxShadow:"0 2px 10px rgba(99,102,241,0.35)",width:"100%",outline:"none"};return e.jsxs("aside",{style:{width:je,flexShrink:0,borderRight:`1px solid ${k.color.border}`,background:k.color.sidebarBg,display:"flex",flexDirection:"column",minHeight:0,overflow:"hidden",position:"relative"},children:[e.jsxs("div",{style:{flex:"none",height:54,display:"flex",alignItems:"center",gap:8,padding:"0 16px",borderBottom:`1px solid ${k.color.border}`},children:[e.jsx("span",{style:{width:26,height:26,borderRadius:7,background:`linear-gradient(135deg,${Ce},${Ze})`,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:"0.93em",fontWeight:700,flexShrink:0,boxShadow:"0 2px 6px rgba(99,102,241,0.4)"},children:"◈"}),e.jsx("span",{style:{fontSize:"1.05em",fontWeight:700,color:k.color.fg},children:"vagusPI"})]}),e.jsxs("div",{style:{flex:"none",padding:"14px 16px 4px",display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("button",{style:Te,onClick:t,onMouseEnter:S=>{S.currentTarget.style.filter="brightness(1.08)",S.currentTarget.style.boxShadow="0 4px 16px rgba(99,102,241,0.45)"},onMouseLeave:S=>{S.currentTarget.style.filter="none",S.currentTarget.style.boxShadow="0 2px 10px rgba(99,102,241,0.35)"},onMouseDown:S=>{S.currentTarget.style.transform="scale(0.98)"},onMouseUp:S=>{S.currentTarget.style.transform="scale(1)"},onFocus:S=>{S.currentTarget.style.boxShadow=`${Lt}, 0 2px 10px rgba(99,102,241,0.35)`},onBlur:S=>{S.currentTarget.style.boxShadow="0 2px 10px rgba(99,102,241,0.35)"},children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:e.jsx("path",{d:"M12 20h9M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4z"})}),e.jsx("span",{style:{flex:1,textAlign:"left"},children:"新对话"}),e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("circle",{cx:"12",cy:"12",r:"8"}),e.jsx("path",{d:"M12 8v8M8 12h8"})]})]}),e.jsxs("button",{onClick:i,onMouseEnter:S=>{S.currentTarget.style.background=k.color.sidebarHover,S.currentTarget.style.color=k.color.fg},onMouseLeave:S=>{S.currentTarget.style.background="transparent",S.currentTarget.style.color=k.color.muted},style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",width:"100%",border:"none",background:"transparent",borderRadius:8,cursor:"pointer",userSelect:"none",fontSize:"0.93em",color:k.color.muted,transition:we,outline:"none"},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:[e.jsx("path",{d:"M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-3 3a5 5 0 0 0-.5 7.5z"}),e.jsx("path",{d:"M14 10a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l3-3a5 5 0 0 0 .5-7.5z"})]}),e.jsx("span",{style:{flex:1,textAlign:"left"},children:"插件"})]})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflowY:"auto",padding:"4px 8px 8px"},children:[e.jsx("div",{style:{fontSize:"0.79em",fontWeight:600,color:k.color.muted,textTransform:"uppercase",letterSpacing:"0.08em",padding:"12px 10px 6px"},children:"项目"}),G.length===0&&e.jsx("div",{style:{fontSize:"0.85em",color:k.color.muted,padding:"8px 10px",lineHeight:1.5},children:'暂无会话 — 点击"新对话"开始。'}),G.map(([S,A])=>{const V=!H.has(S),se=re===S;return e.jsxs("div",{style:{marginBottom:2},children:[e.jsxs("div",{onClick:()=>Q(S),onContextMenu:U=>ee(U,S),style:{position:"relative",display:"flex",alignItems:"center",gap:8,padding:"7px 8px",borderRadius:8,cursor:"pointer",userSelect:"none",fontSize:"0.96em",fontWeight:500,color:k.color.fg,background:se?k.color.sidebarHover:"transparent",transition:we},onMouseEnter:U=>{se||(U.currentTarget.style.background=k.color.sidebarHover)},onMouseLeave:U=>{se||(U.currentTarget.style.background="transparent")},children:[se&&e.jsx("span",{style:{position:"absolute",left:0,top:8,bottom:8,width:3,borderRadius:3,background:`linear-gradient(180deg,${Ce},${Ze})`}}),e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",style:{flexShrink:0,color:se?Ce:k.color.muted},children:e.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"})}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Jt(S)}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0,color:k.color.muted,transform:V?"rotate(0)":"rotate(-90deg)",transition:"transform 0.15s ease"},children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]}),ht(V,e.jsx("div",{style:{paddingLeft:30},children:A.map(U=>{const ae=U.path===o,me=M===U.path;return e.jsxs("div",{onClick:()=>r(U.path),onContextMenu:q=>K(q,U),onMouseEnter:q=>{ae||(q.currentTarget.style.background=k.color.sidebarHover)},onMouseLeave:q=>{ae||(q.currentTarget.style.background="transparent")},style:{position:"relative",display:"flex",alignItems:"center",gap:7,padding:"6px 10px",borderRadius:10,cursor:"pointer",userSelect:"none",fontSize:"0.91em",color:ae?k.color.fg:k.color.muted,fontWeight:ae?500:400,background:ae?Ee:"transparent",overflow:"hidden",whiteSpace:"nowrap",transition:we},children:[ae&&e.jsx("span",{style:{position:"absolute",left:0,top:8,bottom:8,width:3,borderRadius:3,background:`linear-gradient(180deg,${Ce},${Ze})`}}),e.jsx(pt,{color:ae?Ce:void 0}),me?e.jsx("input",{autoFocus:!0,value:_,onChange:q=>Z(q.target.value),onBlur:q=>{q.currentTarget.style.boxShadow="none",L(U.path)},onKeyDown:q=>{q.key==="Enter"&&L(U.path),q.key==="Escape"&&O(void 0)},onClick:q=>q.stopPropagation(),onFocus:q=>{q.currentTarget.style.boxShadow=Lt},style:{flex:1,minWidth:0,fontSize:"0.89em",padding:"2px 6px",background:k.color.bg,border:`1px solid ${k.color.border}`,borderRadius:6,color:k.color.fg,outline:"none"}}):e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(U.name??U.firstMessage.slice(0,40))||"(空会话)"}),e.jsx("span",{style:{width:14,display:"inline-flex",justifyContent:"center",alignItems:"center",flexShrink:0},children:h.has(U.path)&&e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",style:{color:Ce},children:e.jsx("path",{d:"M12 17l-5.88 3.09.87-6.02L2.6 9.43l6.44-.94L12 2.5l2.96 5.99 6.44.94-4.39 4.64.87 6.02z"})})}),e.jsx("span",{style:{width:12,display:"inline-flex",justifyContent:"center",alignItems:"center",flexShrink:0},children:(m.has(U.path)||j.has(U.path))&&e.jsx("span",{title:"工作中",style:{width:7,height:7,borderRadius:"50%",background:k.color.primary,animation:"vagus-pulse 1.2s ease-in-out infinite",display:"inline-block"}})}),e.jsx("span",{style:{fontSize:"0.79em",color:k.color.muted,flexShrink:0},children:Xt(U.modified)})]},U.id)})}))]},S)}),G.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontSize:"0.79em",fontWeight:600,color:k.color.muted,textTransform:"uppercase",letterSpacing:"0.08em",padding:"16px 10px 6px"},children:"最近"}),e.jsx("div",{style:{paddingLeft:0},children:n.slice(0,5).map(S=>e.jsxs("div",{onClick:()=>r(S.path),onContextMenu:A=>K(A,S),onMouseEnter:A=>A.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:A=>A.currentTarget.style.background="transparent",style:{display:"flex",alignItems:"center",gap:7,padding:"6px 10px",borderRadius:10,cursor:"pointer",userSelect:"none",fontSize:"0.91em",color:k.color.muted,overflow:"hidden",whiteSpace:"nowrap",transition:we},children:[e.jsx(pt,{}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:S.name??S.firstMessage.slice(0,40)})]},S.id))})]}),e.jsx(eo,{archivedProjects:u,busyPaths:m,collapsed:H,onToggleProject:Q,onOpenSession:r,onSessionContextMenu:(S,A,V)=>K(S,A,V),onProjectContextMenu:(S,A)=>{S.preventDefault(),F({x:S.clientX,y:S.clientY,kind:"archived",cwd:A})}})]}),e.jsx("div",{style:{flex:"none",borderTop:`1px solid ${k.color.border}`,padding:8,background:k.color.sidebarBg},children:e.jsxs("button",{onClick:s,onMouseEnter:S=>{S.currentTarget.style.background=k.color.sidebarHover,S.currentTarget.style.color=k.color.fg},onMouseLeave:S=>{S.currentTarget.style.background="transparent",S.currentTarget.style.color=k.color.muted},style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",width:"100%",border:"none",background:"transparent",borderRadius:8,cursor:"pointer",userSelect:"none",fontSize:"0.93em",color:k.color.muted,transition:we},children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]}),e.jsx("span",{children:"设置"})]})}),z&&e.jsxs("div",{"data-context-menu":!0,style:{position:"fixed",left:z.x,top:z.y,zIndex:1e3,minWidth:140,background:k.color.surface,border:`1px solid ${k.color.border}`,borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.2)",padding:4},children:[z.kind==="session"&&!z.archived&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>T(z.session),style:$,onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:e.jsx("path",{d:"M4 20h4l10-10a2.83 2.83 0 0 0-4-4L4 16v4z"})}),"重命名"]}),f&&e.jsxs("div",{onClick:()=>{F(null),f(z.session.path)},style:$,onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:h.has(z.session.path)?"#6366f1":"none",stroke:h.has(z.session.path)?"#6366f1":"currentColor",strokeWidth:"1.6",children:e.jsx("path",{d:"M12 17l-5.88 3.09.87-6.02L2.6 9.43l6.44-.94L12 2.5l2.96 5.99 6.44.94-4.39 4.64.87 6.02z"})}),"置顶"]}),p&&e.jsxs("div",{onClick:()=>{F(null),p(z.session.path)},style:$,onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:[e.jsx("path",{d:"M21 8l-2-4H5L3 8v2h18V8z"}),e.jsx("path",{d:"M3 10v8a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-8"})]}),"归档"]})]}),z.kind==="session"&&z.archived&&e.jsxs(e.Fragment,{children:[g&&e.jsxs("div",{onClick:()=>{F(null),g(z.session.path)},style:$,onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"})]}),"恢复"]}),x&&e.jsxs("div",{onClick:()=>{F(null),x(z.session.path)},style:{...$,color:"#E5484D"},onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:e.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"})}),"删除"]})]}),z.kind==="project"&&I&&e.jsxs("div",{onClick:()=>{F(null),I(z.cwd)},style:$,onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:[e.jsx("path",{d:"M21 8l-2-4H5L3 8v2h18V8z"}),e.jsx("path",{d:"M3 10v8a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-8"})]}),"归档项目"]}),z.kind==="archived"&&e.jsxs(e.Fragment,{children:[w&&e.jsxs("div",{onClick:()=>{F(null),w(z.cwd)},style:$,onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:[e.jsx("path",{d:"M21 8l-2-4H5L3 8v2h18V8z"}),e.jsx("path",{d:"M3 10v8a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-8"}),e.jsx("path",{d:"M12 13v3"})]}),"恢复项目"]}),b&&e.jsxs("div",{onClick:()=>{F(null),b(z.cwd)},style:{...$,color:"#E5484D"},onMouseEnter:S=>S.currentTarget.style.background=k.color.sidebarHover,onMouseLeave:S=>S.currentTarget.style.background="transparent",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",children:e.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"})}),"彻底删除"]})]})]})]})}function gt(n,o){switch(n){case"extension":return o.color.success;case"skill":return o.color.warning;case"template":return o.color.accent;default:return o.color.primary}}const to={builtin:"pi 原生指令",extension:"工具指令",skill:"Skills",template:"模板"};function no({commands:n,onPick:o}){const t=N(),[r,s]=a.useState(""),i=r.toLowerCase().replace(/^\//,""),l=n.filter(f=>f.name.toLowerCase().includes(i)||f.description.toLowerCase().includes(i)),c=["builtin","extension","skill","template"],p={position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},g={width:480,maxHeight:"70vh",background:t.color.bg,border:`1px solid ${t.color.border}`,borderRadius:16,boxShadow:"0 24px 64px rgba(0,0,0,0.2)",display:"flex",flexDirection:"column",overflow:"hidden"},x={display:"flex",alignItems:"center",gap:10,height:36,padding:"0 10px",borderRadius:8,cursor:"pointer",fontSize:"0.89em",color:t.color.fg};return e.jsx("div",{style:p,onMouseDown:f=>{f.target===f.currentTarget&&o(null)},children:e.jsxs("div",{style:g,onMouseDown:f=>f.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"14px 16px 10px",borderBottom:`1px solid ${t.color.border}`,flexShrink:0},children:[e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{color:t.color.muted},children:[e.jsx("path",{d:"M4 17l6-6-6-6"}),e.jsx("path",{d:"M12 19h8"})]}),e.jsx("input",{autoFocus:!0,value:r,onChange:f=>s(f.target.value),onKeyDown:f=>{f.key==="Escape"&&o(null)},placeholder:"输入 / 命令…",style:{flex:1,border:"none",outline:"none",background:"transparent",fontSize:"0.96em",color:t.color.fg,fontFamily:"inherit"}}),e.jsxs("span",{style:{fontSize:"0.72em",color:t.color.muted,flexShrink:0},children:[l.length," 项"]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:6,minHeight:160},children:l.length===0?e.jsx("div",{style:{padding:"16px 10px",color:t.color.muted,fontSize:"0.86em"},children:"(没有匹配的命令)"}):c.flatMap(f=>{const h=l.filter(u=>u.type===f);return h.length===0?[]:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px 4px",fontSize:"0.75em",fontWeight:600,letterSpacing:.4,textTransform:"uppercase",color:t.color.muted},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:gt(f,t),flexShrink:0}}),to[f]]},f),...h.map(u=>e.jsxs("div",{onClick:()=>o(`/${u.name}`),style:x,onMouseEnter:I=>{I.currentTarget.style.background=t.color.surface},onMouseLeave:I=>{I.currentTarget.style.background="transparent"},children:[e.jsxs("span",{style:{color:gt(f,t),fontWeight:600,flexShrink:0,fontSize:"0.86em"},children:["/",u.name]}),e.jsx("span",{style:{color:t.color.muted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.description})]},`${f}:${u.name}`))]})})]})})}function $t(n){return n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(Math.round(n))}function oo({value:n,onChange:o,onSubmit:t,usage:r,providers:s,onSwitchModel:i,onSetThinking:l,thinkingLevel:c="off",permissionMode:p,onTogglePermission:g,attachments:x=[],fileAttachments:f=[],onAttach:h,onRemoveAttachment:u,onCommand:I,commands:w=[],onPickCommand:b,onRefreshCommands:m,focusSignal:j,busy:k=!1,hasPendingDialog:B=!1,onRestoreDialog:H,onStop:P,selectedModel:z,queuedMessages:F=[]}){var Xe,Ae,He;const M=N(),[O,_]=a.useState(!1),[Z,G]=a.useState(!1),[Q,K]=a.useState(0),[ee,y]=a.useState(!1);a.useEffect(()=>{if(F.length===0){y(!1);return}const C=window.setTimeout(()=>y(!0),300);return()=>window.clearTimeout(C)},[F.length]),a.useEffect(()=>{const C=re.current;C&&(C.style.height="auto",C.style.height=`${Math.min(C.scrollHeight,200)}px`)},[n]);const[T,$]=a.useState(!1),[L,te]=a.useState(!1),re=a.useRef(null),je=a.useRef(null),Ee=a.useRef(null),Te=a.useRef(null),S=a.useRef(null);a.useEffect(()=>{var C;j&&j>0&&((C=re.current)==null||C.focus())},[j]),a.useEffect(()=>{if(!O)return;const C=Y=>{var ue,be;const oe=Y.target;(ue=Te.current)!=null&&ue.contains(oe)||(be=Ee.current)!=null&&be.contains(oe)||_(!1)},W=Y=>{Y.key==="Escape"&&_(!1)};return document.addEventListener("mousedown",C),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",W)}},[O]),a.useEffect(()=>{if(!T)return;const C=Y=>{var ue;const oe=Y.target;(ue=S.current)!=null&&ue.contains(oe)||$(!1)},W=Y=>{Y.key==="Escape"&&$(!1)};return document.addEventListener("mousedown",C),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",W)}},[T]);const A=a.useMemo(()=>{for(const C of s){const W=C.models.find(Y=>(r==null?void 0:r.activeProvider)===C.id&&Y.id===(r==null?void 0:r.model));if(W)return{provider:C,model:W}}},[s,r==null?void 0:r.activeProvider,r==null?void 0:r.model]),V=(A==null?void 0:A.model.contextWindow)??1e6,se=((Xe=A==null?void 0:A.model.input)==null?void 0:Xe.includes("image"))??!0,U=((Ae=r==null?void 0:r.contextUsage)==null?void 0:Ae.tokens)??null,ae=U!==null,me=U??0,q=Math.min(1,me/V),Le=r==null?void 0:r.latestCacheHitRate,ye=7,ce=2*Math.PI*ye,ie=ce*(1-q),Ye={width:34,height:34,borderRadius:10,border:"none",background:"transparent",color:M.color.muted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},rt={display:"flex",alignItems:"center",gap:5,fontSize:"0.89em",color:M.color.muted,padding:"5px 10px",borderRadius:8,cursor:"pointer",background:"transparent",border:"none",fontFamily:"inherit"},ze={position:"absolute",bottom:42,left:0,zIndex:50,minWidth:190,background:M.color.bg,border:`1px solid ${M.color.border}`,borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.14)",padding:4},$e=()=>{t()},he=Z&&n.startsWith("/"),Re=he?n.slice(1).split(/\s+/)[0]??"":"",le=he?w.filter(C=>C.name.toLowerCase().includes(Re.toLowerCase())):[];a.useEffect(()=>{Q>=le.length&&K(Math.max(0,le.length-1))},[le.length]);const Se=C=>{const W=n.slice(Re.length+1),Y=`/${C} ${W.replace(/^\s+/,"")}`;o(Y),G(!1),b==null||b(C)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",position:"relative"},onMouseDown:C=>{C.target.closest("button, input, textarea, select, [contenteditable], [role='button']")||C.preventDefault()},children:[ee&&F.length>0&&e.jsxs("div",{style:{marginBottom:8,display:"flex",flexDirection:"column",gap:5},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:"0.78em",fontWeight:600,letterSpacing:.3,color:M.color.muted},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#8b5cf6",display:"inline-block",animation:"vagus-pulse 1.2s ease-in-out infinite",flexShrink:0}}),"排队中 · ",F.length," 条"]}),F.map((C,W)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,height:30,padding:"0 12px 0 8px",borderRadius:9,background:"rgba(99,102,241,0.07)",border:"1px solid rgba(99,102,241,0.18)",fontSize:"0.86em",color:M.color.fg},children:[e.jsx("span",{style:{fontSize:"0.7em",fontWeight:700,color:"#6366f1",background:"rgba(99,102,241,0.12)",width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:W+1}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text})]},C.id))]}),(x.length>0||f.length>0)&&e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8,alignItems:"center"},children:[x.map((C,W)=>e.jsxs("div",{style:{position:"relative"},children:[e.jsx("img",{src:C.dataUrl,alt:C.name??"",style:{width:48,height:48,objectFit:"cover",borderRadius:8,border:`1px solid ${M.color.border}`}}),e.jsx("button",{onClick:()=>u==null?void 0:u(W),title:"移除",style:{position:"absolute",top:-5,right:-5,width:16,height:16,borderRadius:"50%",border:"none",background:"#E5484D",color:"#fff",fontSize:"0.71em",lineHeight:1,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:"✕"})]},W)),f.map((C,W)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,height:26,padding:"0 8px",borderRadius:8,background:M.color.surface,border:`1px solid ${M.color.border}`,fontSize:"0.82em",color:M.color.muted},children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6z"}),e.jsx("path",{d:"M14 2v6h6"})]}),C.name,e.jsx("button",{onClick:()=>u==null?void 0:u(W+x.length),style:{width:14,height:14,borderRadius:"50%",border:"none",background:"transparent",color:M.color.muted,cursor:"pointer",fontSize:"0.79em",display:"flex",alignItems:"center",justifyContent:"center",padding:0},children:"✕"})]},C.name))]}),he&&le.length>0&&e.jsx("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",left:4,right:4,zIndex:60,background:M.color.bg,border:`1px solid ${M.color.border}`,borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.18)",maxHeight:300,overflowY:"auto",padding:4},children:le.map((C,W)=>e.jsxs("button",{onClick:()=>Se(C.name),onMouseEnter:()=>K(W),style:{display:"flex",alignItems:"center",gap:10,width:"100%",height:34,padding:"0 10px",border:"none",borderRadius:8,cursor:"pointer",textAlign:"left",fontFamily:"inherit",fontSize:"0.88em",background:W===Q?M.color.surface:"transparent",color:M.color.fg},children:[e.jsxs("span",{style:{color:gt(C.type,M),fontWeight:600,flexShrink:0,fontSize:"0.84em"},children:["/",C.name]}),e.jsx("span",{style:{color:M.color.muted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.description})]},`${C.type}:${C.name}`))}),e.jsx("textarea",{ref:re,value:n,onChange:C=>{o(C.target.value),Z&&!C.target.value.startsWith("/")&&G(!1)},onKeyDown:C=>{if(C.key==="Tab"){if(he&&le.length>0){C.preventDefault();const W=le[Q];W&&Se(W.name)}return}if(C.key==="Enter"&&!C.shiftKey){if(C.nativeEvent.isComposing)return;if(he&&le.length>0){C.preventDefault();const W=le[Q];W&&Se(W.name);return}C.preventDefault(),$e()}if(C.key==="Escape"){if(he){G(!1),C.preventDefault();return}o("")}he&&(C.key==="ArrowDown"&&(C.preventDefault(),K(W=>Math.min(W+1,le.length-1))),C.key==="ArrowUp"&&(C.preventDefault(),K(W=>Math.max(W-1,0)))),C.key==="/"&&!C.shiftKey&&!C.ctrlKey&&!C.metaKey&&!C.altKey&&C.currentTarget.selectionStart===0&&(G(!0),m==null||m())},onPaste:C=>{var oe;const W=(oe=C.clipboardData)==null?void 0:oe.items;if(!W)return;const Y=[];for(const ue of Array.from(W))if(ue.kind==="file"&&ue.type.startsWith("image/")){const be=ue.getAsFile();be&&Y.push(be)}Y.length>0&&(C.preventDefault(),h==null||h(Y))},rows:1,style:{width:"100%",minHeight:34,maxHeight:200,overflow:"auto",overflowX:"hidden",background:"transparent",border:"none",outline:"none",resize:"none",fontFamily:M.font.sans,fontSize:"1.04em",lineHeight:1.5,color:M.color.fg,padding:"2px 0 6px",scrollbarWidth:"none",msOverflowStyle:"none"}}),e.jsx("style",{children:"textarea::-webkit-scrollbar{display:none}"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,marginTop:6},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx("button",{ref:Ee,title:"添加上下文",style:Ye,onClick:()=>{_(C=>!C),$(!1)},children:e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M12 5v14M5 12h14"})})}),O&&e.jsx("div",{ref:Te,style:ze,onMouseDown:C=>C.stopPropagation(),children:[{icon:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),label:"添加附件",title:se?void 0:"当前模型不支持图片,仅可添加文本文件",action:()=>{var C;return(C=je.current)==null?void 0:C.click()}},{icon:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M4 17l6-6-6-6"}),e.jsx("path",{d:"M12 19h8"})]}),label:"使用 / 选择命令或能力",action:()=>I==null?void 0:I()}].map(C=>e.jsxs("button",{title:C.title,onClick:()=>{_(!1),C.action()},style:{display:"flex",alignItems:"center",gap:10,width:"100%",height:34,padding:"0 10px",border:"none",background:"transparent",borderRadius:8,fontSize:"0.89em",color:M.color.fg,cursor:"pointer",textAlign:"left"},onMouseEnter:W=>{W.currentTarget.style.background=M.color.surface},onMouseLeave:W=>{W.currentTarget.style.background="transparent"},children:[e.jsx("span",{style:{color:M.color.muted,display:"flex"},children:C.icon}),C.label]},C.label))}),e.jsx("input",{ref:je,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:C=>{const W=Array.from(C.target.files??[]);W.length>0&&(h==null||h(W)),C.target.value=""}})]}),e.jsx("div",{style:{flex:1}}),r&&e.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>te(!0),onMouseLeave:()=>te(!1),children:[e.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:42}}),e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"4px 4px",borderRadius:9,cursor:"default"},children:e.jsxs("svg",{width:18,height:18,viewBox:"0 0 18 18",style:{flexShrink:0},children:[e.jsx("circle",{cx:"9",cy:"9",r:ye,fill:"none",stroke:M.color.border,strokeWidth:"2.5"}),e.jsx("circle",{cx:"9",cy:"9",r:ye,fill:"none",stroke:q>.9?"#E5484D":q>.7?"#B7791F":M.color.primary,strokeWidth:"2.5",strokeLinecap:"round",strokeDasharray:`${ce} ${ce}`,strokeDashoffset:ie,transform:"rotate(-90 9 9)"})]})}),L&&e.jsxs("div",{style:{position:"absolute",bottom:34,right:0,zIndex:60,width:280,background:M.color.bg,border:`1px solid ${M.color.border}`,borderRadius:12,padding:"12px 14px",boxShadow:"0 10px 32px rgba(0,0,0,0.14)",fontSize:"0.82em",color:M.color.fg,display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{color:M.color.muted},children:"上下文容量"}),e.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:r?ae?`${$t(me)} / ${$t(V)} (${(q*100).toFixed(2)}%)`:"未知 · 待下次响应":"—"})]}),e.jsx("div",{style:{height:6,borderRadius:3,background:M.color.border,overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",width:ae?`${q*100}%`:"0%",background:q>.9?"#E5484D":q>.7?"#B7791F":M.color.primary,transition:"width 0.3s"}})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{color:M.color.muted},children:"缓存命中率"}),e.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:Le!==void 0?`${Le.toFixed(1)}%`:"—"})]})]})]}),e.jsxs("div",{ref:S,style:{position:"relative"},children:[e.jsxs("button",{style:rt,onClick:()=>{$(C=>!C),_(!1)},title:"切换模型",children:[((He=r==null?void 0:r.model)==null?void 0:He.split("/").pop())??z??"选择模型",e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),T&&e.jsxs("div",{style:{...ze,left:"auto",right:0,width:250,maxHeight:320,overflowY:"auto"},onMouseDown:C=>C.stopPropagation(),children:[s.length===0&&e.jsx("div",{style:{padding:"10px 12px",fontSize:"0.86em",color:M.color.muted},children:"暂无已配置模型"}),s.map(C=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"8px 10px 4px",fontSize:"0.75em",fontWeight:600,letterSpacing:.4,textTransform:"uppercase",color:M.color.muted},children:C.id}),C.models.map(W=>{const Y=(r==null?void 0:r.activeProvider)===C.id&&(r==null?void 0:r.model)===W.id;return e.jsxs("button",{onClick:()=>{i(C.id,W.id),$(!1)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",height:32,padding:"0 10px",border:"none",background:Y?M.color.surface:"transparent",borderRadius:8,fontSize:"0.89em",color:M.color.fg,cursor:"pointer",textAlign:"left"},onMouseEnter:oe=>{Y||(oe.currentTarget.style.background=M.color.surface)},onMouseLeave:oe=>{Y||(oe.currentTarget.style.background="transparent")},children:[e.jsx("span",{style:{fontSize:"0.79em",color:M.color.muted,flexShrink:0},children:"◆"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:W.name??W.id}),Y&&e.jsx("span",{style:{fontSize:"0.79em",color:M.color.primary},children:"✓"})]},W.id)})]},C.id))]})]}),e.jsxs("button",{onClick:()=>l(c==="off"?"high":"off"),title:c==="off"?"开启思考模式":"关闭思考模式",style:{display:"flex",alignItems:"center",gap:6,height:30,padding:"0 10px 0 8px",borderRadius:9,border:"none",cursor:"pointer",fontFamily:"inherit",fontSize:"0.88em",background:c==="off"?"transparent":"rgba(99,102,241,0.10)",color:c==="off"?M.color.muted:"#6366f1",fontWeight:c==="off"?400:600,transition:"all 0.15s"},children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0},children:e.jsx("path",{d:"M12 4.5a2.5 2.5 0 0 0-4.96-.46 2.5 2.5 0 0 0-1.98 3 2.5 2.5 0 0 0-1.32 4.24 3 3 0 0 0 .34 5.58 2.5 2.5 0 0 0 2.96 3.08A2.5 2.5 0 0 0 12 19.5a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-1.98-3A2.5 2.5 0 0 0 12 4.5z"})}),c==="off"?"思考关闭":"思考中"]}),e.jsx("button",{onClick:B?H:k?P:$e,title:B?"恢复待处理的弹窗":k?"停止":"发送",style:{width:38,height:38,borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,background:B?M.color.warning:k?"#E8833D":"linear-gradient(135deg,#6366f1,#8b5cf6)",color:"#fff",boxShadow:B||k?"none":"0 4px 14px rgba(99,102,241,0.35)",transition:"transform 0.15s, box-shadow 0.15s"},children:B?e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}):k?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}):e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",children:e.jsx("path",{d:"M12 19V5M5 12l7-7 7 7"})})})]})]})}function ro({projects:n,value:o,onChange:t,onNewProject:r}){const s=N(),[i,l]=a.useState(!1),[c,p]=a.useState(""),g=a.useRef(null),x=a.useRef(null);a.useEffect(()=>{if(!i)return;const j=B=>{var P,z;const H=B.target;(P=x.current)!=null&&P.contains(H)||(z=g.current)!=null&&z.contains(H)||l(!1)},k=B=>{B.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",k)}},[i]);const f=n.find(j=>j.id===o),h=o?o.split(/[\\/]/).filter(Boolean).pop()??o:void 0,u=(f==null?void 0:f.name)??h??"选择项目",I=n.filter(j=>j.name.toLowerCase().includes(c.toLowerCase())),w=o!==void 0,b={display:"inline-flex",alignItems:"center",gap:6,background:w?"rgba(99,102,241,0.08)":s.color.surface,color:w?"#6366f1":s.color.muted,fontSize:"0.89em",fontWeight:w?600:500,padding:"6px 10px 6px 8px",borderRadius:9,cursor:"pointer",border:`1px solid ${w?"rgba(99,102,241,0.4)":s.color.border}`,marginBottom:-1,zIndex:2,position:"relative",transition:"background 0.15s, border-color 0.15s, color 0.15s"},m={position:"absolute",bottom:36,left:0,zIndex:20,width:325,height:275,background:s.color.bg,border:`1px solid ${s.color.border}`,borderRadius:16,boxShadow:"0 16px 48px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.05)",display:i?"flex":"none",flexDirection:"column",overflow:"hidden"};return e.jsxs("div",{style:{position:"relative",alignSelf:"flex-start",zIndex:10},children:[e.jsxs("div",{ref:g,style:b,onClick:j=>{j.stopPropagation(),l(k=>!k)},children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"})}),e.jsx("span",{children:u}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{transform:i?"rotate(180deg)":"none",transition:"transform 0.15s"},children:e.jsx("path",{d:"M6 9l6 6 6-6"})})]}),e.jsxs("div",{ref:x,style:m,onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 14px 8px",flexShrink:0},children:[e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{color:s.color.muted},children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{value:c,onChange:j=>p(j.target.value),placeholder:"搜索项目",style:{flex:1,border:"none",outline:"none",background:"transparent",fontSize:"0.93em",color:s.color.fg}})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"4px 6px",minHeight:0},children:I.map(j=>{const k=j.id===o;return e.jsxs("div",{onClick:()=>{t(j.id),l(!1)},style:{display:"flex",alignItems:"center",gap:10,height:36,padding:"0 10px",borderRadius:9,cursor:"pointer",fontSize:"0.93em",color:s.color.fg,background:k?s.color.surface:"transparent",opacity:j.available===!1?.45:1},children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{flexShrink:0,color:s.color.muted},children:e.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"})}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.name})]},j.id)})}),e.jsx("div",{style:{borderTop:`1px solid ${s.color.border}`,flexShrink:0,padding:4},children:e.jsxs("button",{onClick:()=>{r(),l(!1)},style:{display:"flex",alignItems:"center",gap:8,padding:"0 10px",height:36,width:"100%",border:"none",background:"transparent",borderRadius:8,fontSize:"0.93em",color:s.color.fg,cursor:"pointer"},children:[e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{color:s.color.muted},children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),"新建项目"]})})]})]})}const Gt="vagus.picker.lastDir",Qt="vagus.picker.recent";function Zt(){try{const n=localStorage.getItem(Qt);return(n?JSON.parse(n):[]).slice(0,8)}catch{return[]}}function so(n){try{const o=Zt().filter(t=>t!==n);o.unshift(n),localStorage.setItem(Qt,JSON.stringify(o.slice(0,8))),localStorage.setItem(Gt,n)}catch{}}const io={Desktop:"🖥️",Downloads:"📥",Documents:"📄",Pictures:"🖼️",Music:"🎵",Videos:"🎬",Home:"🏠",Root:"💿"};function lo({listDir:n,roots:o,onPick:t}){const r=N(),[s,i]=a.useState(()=>{const y=localStorage.getItem(Gt);return y&&y.length>0?y:"~"}),[l,c]=a.useState([]),[p,g]=a.useState(null),[x,f]=a.useState(!0),[h,u]=a.useState(null),[I,w]=a.useState(!1),[b,m]=a.useState(""),[j,k]=a.useState({places:[],drives:[]}),[B]=a.useState(Zt);a.useEffect(()=>{o().then(y=>k(y)).catch(()=>{})},[]),a.useEffect(()=>{f(!0),u(null),g(null),n(s).then(y=>{i(y.path),c(y.entries)}).catch(y=>u(String(y))).finally(()=>f(!1))},[s]),a.useEffect(()=>{const y=T=>{T.key==="Enter"&&!I&&O(),T.key==="Escape"&&t(null)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[I,s]);const H=/^[A-Za-z]:[\\/]/.test(s),P=a.useMemo(()=>s.split(/[\\/]+/).filter(Boolean),[s]);function z(y){if(H){const T=P[0];return y===0?`${T}\\`:`${T}\\${P.slice(1,y+1).join("\\")}`}return`/${P.slice(0,y+1).join("/")}`}function F(y){if(/^[A-Za-z]:[\\/]?$/.test(y))return y;const T=y.replace(/[\\/][^\\/]+$/,"");return T.length===0?"/":H&&T.length===2&&T.endsWith(":")?`${T}\\`:T}function M(y){w(!1),i(y)}function O(){const y=p??s;y&&(so(y),t(y))}function _(){const y=b.trim();y?M(y):w(!1)}const Z=F(s),G=Z===s,Q={position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},K={width:640,maxHeight:"72vh",background:r.color.bg,border:`1px solid ${r.color.border}`,borderRadius:16,boxShadow:"0 24px 64px rgba(0,0,0,0.2)",display:"flex",flexDirection:"column",overflow:"hidden"},ee={width:30,height:30,borderRadius:8,border:"none",background:"transparent",color:r.color.muted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0};return e.jsx("div",{style:Q,onMouseDown:y=>{y.target===y.currentTarget&&t(null)},children:e.jsxs("div",{style:K,onMouseDown:y=>y.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px 8px",flexShrink:0},children:[e.jsx("span",{style:{fontSize:"0.96em",fontWeight:600,color:r.color.fg},children:"选择项目文件夹"}),e.jsx("button",{style:ee,onClick:()=>t(null),title:"关闭",children:e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"0 16px 10px",flexShrink:0},children:[e.jsx("button",{style:{...ee,opacity:G?.35:1,cursor:G?"default":"pointer"},disabled:G,onClick:()=>M(Z),title:"上一级",children:e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),I?e.jsx("form",{style:{flex:1,display:"flex"},onSubmit:y=>{y.preventDefault(),_()},children:e.jsx("input",{autoFocus:!0,value:b,onChange:y=>m(y.target.value),onBlur:()=>w(!1),placeholder:"输入路径(如 ~/projects/app)",style:{flex:1,height:30,border:`1px solid ${r.color.border}`,borderRadius:8,outline:"none",padding:"0 10px",fontSize:"0.89em",background:r.color.surface,color:r.color.fg,fontFamily:"inherit"}})}):e.jsxs("div",{style:{flex:1,height:30,display:"flex",alignItems:"center",gap:2,padding:"0 10px",borderRadius:8,background:r.color.surface,border:`1px solid ${r.color.border}`,fontSize:"0.89em",color:r.color.fg,cursor:"text",overflow:"hidden",whiteSpace:"nowrap"},onClick:()=>{m(s),w(!0)},title:s,children:[e.jsx("span",{style:{color:r.color.muted,flexShrink:0},children:H?P[0]:"/"}),P.slice(H?1:0).map((y,T)=>{const $=H?T+1:T,L=$===P.length-1;return e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[e.jsx("span",{style:{color:r.color.muted,fontSize:"0.71em"},children:"▸"}),e.jsx("span",{style:{color:L?r.color.fg:r.color.muted,fontWeight:L?500:400,cursor:L?"default":"pointer",maxWidth:120,overflow:"hidden",textOverflow:"ellipsis"},onClick:te=>{L||(te.stopPropagation(),M(z($)))},children:y})]},`${y}-${T}`)})]})]}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0,borderTop:`1px solid ${r.color.border}`},children:[e.jsxs("aside",{style:{width:150,flexShrink:0,borderRight:`1px solid ${r.color.border}`,padding:"6px 4px",overflowY:"auto",display:"flex",flexDirection:"column"},children:[e.jsx("div",{style:{padding:"6px 10px 4px",fontSize:"0.75em",fontWeight:600,letterSpacing:.5,textTransform:"uppercase",color:r.color.muted},children:"位置"}),j.places.map(y=>e.jsxs("button",{onClick:()=>M(y.path),title:y.path,style:{display:"flex",alignItems:"center",gap:8,height:32,padding:"0 10px",borderRadius:8,border:"none",background:s===y.path?r.color.surface:"transparent",cursor:"pointer",fontSize:"0.89em",color:r.color.fg,textAlign:"left",flexShrink:0},children:[e.jsx("span",{style:{fontSize:"0.93em",flexShrink:0},children:io[y.name]??"📁"}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.name})]},y.path)),j.drives.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 10px 4px",fontSize:"0.75em",fontWeight:600,letterSpacing:.5,textTransform:"uppercase",color:r.color.muted},children:"驱动器"}),j.drives.map(y=>e.jsxs("button",{onClick:()=>M(y.path),title:y.path,style:{display:"flex",alignItems:"center",gap:8,height:32,padding:"0 10px",borderRadius:8,border:"none",background:s===y.path?r.color.surface:"transparent",cursor:"pointer",fontSize:"0.89em",color:r.color.fg,textAlign:"left",flexShrink:0},children:[e.jsx("span",{style:{fontSize:"0.93em",flexShrink:0},children:"💽"}),e.jsx("span",{children:y.name})]},y.path))]}),B.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 10px 4px",fontSize:"0.75em",fontWeight:600,letterSpacing:.5,textTransform:"uppercase",color:r.color.muted},children:"最近"}),B.map(y=>e.jsxs("button",{onClick:()=>M(y),title:y,style:{display:"flex",alignItems:"center",gap:8,height:32,padding:"0 10px",borderRadius:8,border:"none",background:"transparent",cursor:"pointer",fontSize:"0.89em",color:r.color.fg,textAlign:"left",flexShrink:0},children:[e.jsx("span",{style:{fontSize:"0.93em",flexShrink:0},children:"⭐"}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.split(/[\\/]/).filter(Boolean).pop()??y})]},y))]})]}),e.jsx("div",{style:{flex:1,minWidth:0,overflowY:"auto",padding:10,display:"flex",flexDirection:"column"},children:x?e.jsx("div",{style:{padding:"32px 0",textAlign:"center",color:r.color.muted,fontSize:"0.93em"},children:"加载中…"}):h?e.jsx("div",{style:{padding:"32px 0",textAlign:"center",color:"#E5484D",fontSize:"0.93em"},children:h}):l.length===0?e.jsx("div",{style:{padding:"32px 0",textAlign:"center",color:r.color.muted,fontSize:"0.93em"},children:"(空文件夹)"}):e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(96px, 1fr))",gap:4},children:l.map(y=>e.jsxs("div",{onClick:()=>y.isDirectory&&g(y.path),onDoubleClick:()=>y.isDirectory&&M(y.path),title:y.path,style:{display:"flex",flexDirection:"column",alignItems:"center",gap:6,padding:"10px 4px",borderRadius:10,cursor:y.isDirectory?"pointer":"default",background:p===y.path?r.color.surface:"transparent",userSelect:"none",overflow:"hidden"},children:[e.jsx("span",{style:{fontSize:26,lineHeight:1},children:y.isDirectory?"📁":"📄"}),e.jsx("span",{style:{fontSize:"0.82em",color:y.isDirectory?r.color.fg:r.color.muted,textAlign:"center",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.name})]},y.path))})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"10px 16px",borderTop:`1px solid ${r.color.border}`,flexShrink:0},children:[e.jsx("span",{style:{fontSize:"0.82em",color:r.color.muted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:s,children:s}),e.jsxs("div",{style:{display:"flex",gap:8,flexShrink:0},children:[e.jsx("button",{onClick:()=>t(null),style:{height:30,padding:"0 16px",borderRadius:8,border:`1px solid ${r.color.border}`,background:"transparent",color:r.color.muted,fontSize:"0.89em",cursor:"pointer"},children:"取消"}),e.jsxs("button",{onClick:O,disabled:!s,style:{height:30,padding:"0 16px",borderRadius:8,border:"none",background:"#3A3A3A",color:"#fff",fontSize:"0.89em",cursor:"pointer",fontWeight:500},children:["选择",p?` “${p.split(/[\\/]/).filter(Boolean).pop()??p}”`:"此文件夹"]})]})]})]})})}function ne(n,o){switch(o.type){case"clear":return[];case"toolCallStarted":return[...n,{id:o.id,kind:"tool",toolCallId:o.toolCallId,name:o.name,args:o.args,status:"running",collapsed:!0}];case"toolCallFinished":{const t=[...n];for(let r=t.length-1;r>=0;r--){const s=t[r];if(!(!s||s.kind!=="tool"||s.toolCallId!==o.toolCallId)){t[r]={...s,status:o.isError?"failed":"succeeded",result:o.result,...o.diff!==void 0?{diff:o.diff}:{},...o.patch!==void 0?{patch:o.patch}:{},collapsed:!0};break}}return t}case"thinkingDelta":{const t=n[n.length-1];if(t&&t.kind==="thinking"){const r=[...n];return r[r.length-1]={...t,text:`${t.text}${o.text}`,collapsed:!1},r}return[...n,{id:o.id,kind:"thinking",text:o.text}]}case"thinkingDone":return n;case"collapseAll":return n.map(t=>t.kind==="thinking"||t.kind==="tool"?{...t,collapsed:!0}:t);case"setCollapse":{const t=new Set(o.ids);return n.map(r=>!t.has(r.id)||r.kind!=="thinking"&&r.kind!=="tool"?r:{...r,collapsed:o.collapsed})}case"toggleCollapse":return n.map(t=>t.id!==o.id||t.kind!=="thinking"&&t.kind!=="tool"?t:{...t,collapsed:!t.collapsed});case"turnEnd":{const t=[...n];for(let r=t.length-1;r>=0;r--){const s=t[r];if(!(!s||s.kind!=="thinking"&&s.kind!=="tool")){t[r]={...s,turnDurationMs:Math.max(0,o.endedAt-o.startedAt)};break}}return t}case"historyLoaded":{const t=[];let r;for(let s=0;s<o.messages.length;s++){const i=o.messages[s],l=o.id+1+s*10,c=[];if(i.role==="user"&&!i.toolCalls&&(r=void 0,c.push({id:l+100,kind:"user",text:i.text,...i.images&&i.images.length>0?{images:i.images}:{}})),i.thinking&&(c.push({id:l,kind:"thinking",text:i.thinking,collapsed:!0}),r=t.length+c.length-1),i.toolCalls)for(let p=0;p<i.toolCalls.length;p++){const g=i.toolCalls[p];c.push({id:l+1+p,kind:"tool",toolCallId:g.id||`hist-${s}-${p}`,name:g.name,args:g.args,status:g.isError===!0?"failed":"succeeded",result:g.result,...g.diff!==void 0?{diff:g.diff}:{},...g.patch!==void 0?{patch:g.patch}:{},collapsed:!0}),r=t.length+c.length-1}if(i.role==="assistant"&&c.push({id:l+100,kind:"assistant",text:i.text}),i.role==="system"&&c.push({id:l+100,kind:"system",text:i.text}),t.push(...c),i.turnDurationMs!==void 0&&r!==void 0){const p=t[r];p&&(p.kind==="thinking"||p.kind==="tool")&&(t[r]={...p,turnDurationMs:i.turnDurationMs})}}return t}case"prependHistory":{const t=[];let r;for(let s=0;s<o.messages.length;s++){const i=o.messages[s],l=-(o.id+1+s*10),c=[];if(i.role==="user"&&!i.toolCalls&&(r=void 0,c.push({id:l+100,kind:"user",text:i.text,...i.images&&i.images.length>0?{images:i.images}:{}})),i.thinking&&(c.push({id:l,kind:"thinking",text:i.thinking,collapsed:!0}),r=t.length+c.length-1),i.toolCalls)for(let p=0;p<i.toolCalls.length;p++){const g=i.toolCalls[p];c.push({id:l+1+p,kind:"tool",toolCallId:g.id||`hist-${s}-${p}`,name:g.name,args:g.args,status:g.isError===!0?"failed":"succeeded",result:g.result,...g.diff!==void 0?{diff:g.diff}:{},...g.patch!==void 0?{patch:g.patch}:{},collapsed:!0}),r=t.length+c.length-1}if(i.role==="assistant"&&c.push({id:l+100,kind:"assistant",text:i.text}),i.role==="system"&&c.push({id:l+100,kind:"system",text:i.text}),t.push(...c),i.turnDurationMs!==void 0&&r!==void 0){const p=t[r];p&&(p.kind==="thinking"||p.kind==="tool")&&(t[r]={...p,turnDurationMs:i.turnDurationMs})}}return[...t,...n]}case"userMessageEntryId":return n.map(t=>t.id!==o.id||t.kind!=="user"?t:{...t,entryId:o.entryId});case"userMessage":return[...n,{id:o.id,kind:"user",text:o.text,...o.skillTag?{skillTag:o.skillTag}:{},...o.images&&o.images.length>0?{images:o.images}:{}}];case"assistantDelta":{const t=n[n.length-1];if(t&&t.kind==="assistant"){const r=[...n];return r[r.length-1]={...t,text:`${t.text}${o.text}`},r}return[...n,{id:o.id,kind:"assistant",text:o.text}]}case"system":return[...n,{id:o.id,kind:"system",text:o.text}];case"removeMessage":return n.filter(t=>t.id!==o.id)}}const At=/^(#{1,6})\s+(.*)$/,et=/^```(\w*)\s*$/,Ht=/^\s*(---+|\*\*\*+|___+)\s*$/,Ne=/^\s*>\s?(.*)$/,tt=/^(\s*)([-*+]|\d+\.)\s+(.*)$/,dt=/^\s*\|(.+)\|\s*$/,Pt=/^[\s:|:-]+$/;function en(n){var s;const o=n.replace(/\r\n/g,`
3
+ `).split(`
4
+ `),t=[];let r=0;for(;r<o.length;){const i=o[r]??"",l=i.match(et);if(l){const x=l[1]??"",f=[];for(r+=1;r<o.length;){if(et.test(o[r]??"")){r+=1;break}f.push(o[r]??""),r+=1}t.push({type:"code",lang:x,text:f.join(`
5
+ `)});continue}const c=i.match(At);if(c){t.push({type:"heading",level:c[1].length,content:fe(c[2]??"")}),r+=1;continue}if(Ht.test(i)){t.push({type:"hr"}),r+=1;continue}if(Ne.test(i)){const x=[];for(;r<o.length&&Ne.test(o[r]??"");)x.push((o[r]??"").replace(Ne,"$1")),r+=1;t.push({type:"quote",content:en(x.join(`
6
+ `))});continue}const p=i.match(tt);if(p){const x=/\d+\./.test(p[2]??""),f=[],h=(p[1]??"").length;for(;r<o.length;){const u=(s=o[r])==null?void 0:s.match(tt),I=((u==null?void 0:u[1])??"").length,w=u!=null&&/\d+\./.test(u[2]??"");if(!u||I!==h||w!==x)break;const m=[(u[3]??"").trim()];for(;r+1<o.length;){const j=o[r+1]??"";if(j.length>0&&!/^\s*$/.test(j)&&!tt.test(j)&&!Ne.test(j)&&!et.test(j))m.push(j.replace(/^\s+/,"")),r+=1;else break}f.push(fe(m.join(" "))),r+=1}t.push({type:"list",ordered:x,items:f});continue}if(dt.test(i)){const x=Ot(i),f=o[r+1]??"";if(x.length>1&&Pt.test(f)&&f.includes("-")){const h=x.map(I=>fe(I)),u=[];for(r+=2;r<o.length&&dt.test(o[r]??"");)u.push(Ot(o[r]??"").map(I=>fe(I))),r+=1;t.push({type:"table",headers:h,rows:u});continue}}if(/^\s*$/.test(i)){r+=1;continue}const g=[i.trim()];for(r+=1;r<o.length;){const x=o[r]??"";if(/^\s*$/.test(x)||At.test(x)||et.test(x)||Ht.test(x)||Ne.test(x)||tt.test(x)||dt.test(x)&&(o[r+1]??"").includes("-")&&Pt.test(o[r+1]??""))break;g.push(x.trim()),r+=1}t.push({type:"paragraph",content:fe(g.join(" "))})}return t}function Ot(n){return n.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}const ao=/^(https?|mailto):/i;function fe(n){const o=/(`[^`\n]+`)|(\*\*(?=\S).+?\*\*(?!\*))|(__[^_\n]+__)|(\*(?=\S)[^*\n]+?\*)|(_[^_\n\s][^_\n]*_)|(~~[^~\n]+~~)|(\[[^\]\n]+\]\([^)\n\s]+\))/g,t=[];let r=0,s;for(;(s=o.exec(n))!==null;){s.index>r&&t.push({kind:"text",text:n.slice(r,s.index)}),r=o.lastIndex;const[i,l,c,p,g,x,f,h]=s;if(l!==void 0)t.push({kind:"code",text:l.slice(1,-1)});else if(c!==void 0)t.push({kind:"bold",children:fe(c.slice(2,-2))});else if(p!==void 0)t.push({kind:"bold",children:fe(p.slice(2,-2))});else if(g!==void 0)t.push({kind:"italic",children:fe(g.slice(1,-1))});else if(x!==void 0)t.push({kind:"italic",children:fe(x.slice(1,-1))});else if(f!==void 0)t.push({kind:"strike",children:fe(f.slice(2,-2))});else if(h!==void 0){const u=h.match(/^\[([^\]]+)\]\(([^)\s]+)\)$/);if(u){const I=u[2]??"";t.push(ao.test(I)?{kind:"link",href:I,children:fe(u[1]??"")}:{kind:"text",text:i})}else t.push({kind:"text",text:i})}}return r<n.length&&t.push({kind:"text",text:n.slice(r)}),t}const co="rgba(79, 140, 255, 0.08)",uo="rgba(79, 140, 255, 0.18)",Ve=new Map,fo=4e3;function ho(n,o){const t=`${n.length}:${n}`,r=Ve.get(t);if(r)return r;const s=Yn(n,o);if(Ve.size>=fo){const i=Ve.keys().next().value;i!==void 0&&Ve.delete(i)}return Ve.set(t,s),s}function pe({nodes:n}){const o=N();return e.jsx(e.Fragment,{children:n.map((t,r)=>{switch(t.kind){case"text":return e.jsx(Vt.Fragment,{children:t.text},r);case"code":return e.jsx("code",{style:{fontFamily:o.font.mono,fontSize:"0.85em",background:co,border:`1px solid ${uo}`,borderRadius:4,padding:"0.1em 0.35em",color:o.color.accent,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:t.text},r);case"bold":return e.jsx("strong",{style:{fontWeight:700},children:e.jsx(pe,{nodes:t.children})},r);case"italic":return e.jsx("em",{children:e.jsx(pe,{nodes:t.children})},r);case"strike":return e.jsx("s",{style:{opacity:.6},children:e.jsx(pe,{nodes:t.children})},r);case"link":return e.jsx("a",{href:t.href,target:"_blank",rel:"noopener noreferrer",style:{color:o.color.accent,textDecoration:"underline"},children:e.jsx(pe,{nodes:t.children})},r)}})})}const Ue={margin:"0 0 10px"};function po({text:n,lang:o}){const{theme:t}=Ke(),r=Kt(),[s,i]=a.useState(!1),l=t==="light"?Un:Kn,c=n.split(`
7
+ `),p=async()=>{try{await navigator.clipboard.writeText(n)}catch{const g=document.createElement("textarea");g.value=n,g.style.position="fixed",g.style.opacity="0",document.body.appendChild(g),g.select(),document.execCommand("copy"),document.body.removeChild(g)}i(!0),window.setTimeout(()=>i(!1),1600)};return e.jsxs("div",{style:{margin:Ue.margin,background:l.bg,border:`1px solid ${l.border}`,borderRadius:8,overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 10px 5px 14px",borderBottom:`1px solid ${l.border}`,background:"linear-gradient(90deg, rgba(99,102,241,0.08), rgba(99,102,241,0.02))"},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"linear-gradient(135deg,#6366f1,#8b5cf6)",flexShrink:0}}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.78em",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",color:l.text,opacity:.75},children:o||"code"})]}),e.jsxs("button",{onClick:()=>void p(),onMouseEnter:g=>{g.currentTarget.style.opacity="1",g.currentTarget.style.background="rgba(99,102,241,0.12)",g.currentTarget.style.borderColor="rgba(99,102,241,0.45)",g.currentTarget.style.color="#6366f1"},onMouseLeave:g=>{g.currentTarget.style.opacity="0.85",g.currentTarget.style.background="transparent",g.currentTarget.style.borderColor=l.border,g.currentTarget.style.color=s?"#16a34a":l.text},style:{display:"flex",alignItems:"center",gap:5,background:"transparent",border:`1px solid ${l.border}`,color:s?"#16a34a":l.text,borderRadius:6,padding:"3px 9px",fontSize:"0.76em",cursor:"pointer",opacity:.85,transition:"all 0.15s",flexShrink:0,fontFamily:"inherit"},children:[s?e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",children:e.jsx("path",{d:"M20 6L9 17l-5-5"})}):e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),s?"已复制":"复制"]})]}),e.jsx("pre",{style:{margin:0,padding:"10px 14px",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:r.codeFontSize,lineHeight:1.6,overflowX:r.wrapLongLines?"hidden":"auto",color:l.text,whiteSpace:r.wrapLongLines?"pre-wrap":"pre"},children:c.map((g,x)=>e.jsxs("div",{style:{display:"flex",minHeight:"1.6em"},children:[r.showLineNumbers&&e.jsx("span",{style:{width:30,flexShrink:0,textAlign:"right",marginRight:14,color:l.text,opacity:.35,userSelect:"none",fontVariantNumeric:"tabular-nums"},children:x+1}),e.jsx("span",{style:{whiteSpace:r.wrapLongLines?"pre-wrap":"pre",minWidth:0},children:ho(g,l).map((f,h)=>f.color!==void 0?e.jsx("span",{style:{color:f.color},children:f.text},h):e.jsx(Vt.Fragment,{children:f.text},h))})]},x))})]})}function go({block:n}){const{tokens:o}=Ke();switch(n.type){case"code":return e.jsx(po,{text:n.text,lang:n.lang});case"paragraph":return e.jsx("p",{style:Ue,children:e.jsx(pe,{nodes:n.content})});case"heading":return e.jsx("div",{style:{margin:"14px 0 8px",fontWeight:700,fontSize:n.level===1?20:n.level===2?17:15,color:o.color.fg},children:e.jsx(pe,{nodes:n.content})});case"list":return e.jsx("div",{style:Ue,children:n.items.map((t,r)=>n.ordered?e.jsxs("div",{style:{display:"flex",gap:8,padding:"2px 0"},children:[e.jsxs("span",{style:{color:o.color.muted,minWidth:22,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[r+1,"."]}),e.jsx("span",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:e.jsx(pe,{nodes:t})})]},r):e.jsxs("div",{style:{display:"flex",gap:8,padding:"2px 0"},children:[e.jsx("span",{style:{color:o.color.primary,minWidth:14},children:"•"}),e.jsx("span",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:e.jsx(pe,{nodes:t})})]},r))});case"quote":return e.jsx("blockquote",{style:{margin:Ue.margin,padding:"2px 0 2px 12px",borderLeft:`3px solid ${o.color.primary}`,color:o.color.muted},children:e.jsx(tn,{blocks:n.content})});case"table":return e.jsx("div",{style:{margin:Ue.margin,overflowX:"auto"},children:e.jsxs("table",{style:{borderCollapse:"collapse",fontSize:13,border:`1px solid ${o.color.border}`,borderRadius:6},children:[e.jsx("thead",{children:e.jsx("tr",{children:n.headers.map((t,r)=>e.jsx("th",{style:{border:`1px solid ${o.color.border}`,padding:"6px 10px",background:o.color.surface,fontWeight:600,textAlign:"left"},children:e.jsx(pe,{nodes:t})},r))})}),e.jsx("tbody",{children:n.rows.map((t,r)=>e.jsx("tr",{children:t.map((s,i)=>e.jsx("td",{style:{border:`1px solid ${o.color.border}`,padding:"5px 10px"},children:e.jsx(pe,{nodes:s})},i))},r))})]})});case"hr":return e.jsx("hr",{style:{border:"none",borderTop:`1px solid ${o.color.border}`,margin:"14px 0"}})}}function tn({blocks:n}){return e.jsx(e.Fragment,{children:n.map((o,t)=>e.jsx(go,{block:o},t))})}function xo({text:n}){const o=a.useMemo(()=>en(n),[n]);return e.jsx("div",{style:{overflowWrap:"anywhere",wordBreak:"break-word",minWidth:0},children:e.jsx(tn,{blocks:o})})}const mo=720,ct="#6366f1",yo="#8b5cf6";function bo({text:n}){const o=N(),t=/剩余\s*([\d.]+)\s*K/.exec(n);return e.jsx("div",{style:{display:"flex",justifyContent:"center",margin:"4px 0"},children:e.jsxs("div",{style:{maxWidth:mo,width:"100%",display:"flex",alignItems:"center",gap:8,position:"relative",overflow:"hidden",background:"linear-gradient(135deg, rgba(99,102,241,0.06), rgba(139,92,246,0.02))",border:"1px solid rgba(99,102,241,0.14)",borderRadius:10,padding:"8px 12px 8px 16px"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,bottom:0,width:3,background:`linear-gradient(180deg, ${ct}, ${yo})`}}),e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:ct,strokeWidth:"2",style:{flexShrink:0},children:e.jsx("path",{d:"M4 9h6V3M20 15h-6v6M20 9h-6V3M4 15h6v6"})}),e.jsxs("span",{style:{color:o.color.muted,fontSize:"0.85em",lineHeight:1.5},children:[e.jsx("span",{style:{color:ct,fontWeight:600},children:"前文已摘要"}),t?e.jsxs("span",{style:{opacity:.75},children:[" · 剩余 ",t[1],"K 上下文"]}):null]})]})})}function ko(n){let o;try{const t=JSON.parse(n);o=typeof t.file_path=="string"?t.file_path:typeof t.path=="string"?t.path:void 0}catch{}if(!o){const t=n.match(/"file_path"\s*:\s*"([^"]+)"|"path"\s*:\s*"([^"]+)"/);o=t?t[1]??t[2]:void 0}return o?Me(o):"未知文件"}function Me(n){return n.replace(/\\/g,"/").replace(/^\/mnt\/([a-zA-Z])\//,(o,t)=>`${t.toUpperCase()}:/`)}function vo(n){let o=0,t=0;for(const r of n.split(`
8
+ `)){const s=r[0];s==="+"?o+=1:s==="-"&&(t+=1)}return{added:o,removed:t}}function wo(n){const o=[];for(const t of n)t.kind!=="tool"||!t.diff||!t.toolCallId||o.push({file:ko(t.args),toolCallId:t.toolCallId,diff:t.diff,patch:t.patch,...vo(t.diff)});return o}const jo=/<skill\s+name="([^"]+)"[^>]*>\s*(?:References are relative to[^\n]*\n\n)?([\s\S]*?)<\/skill>/g;function So({parts:n}){const o=N();return e.jsx(e.Fragment,{children:n.map((t,r)=>t.type==="skill"?e.jsxs("span",{title:`skill: ${t.name}`,style:{display:"inline-flex",alignItems:"center",gap:5,padding:"2px 8px",borderRadius:6,fontSize:"0.85em",background:"rgba(210,153,34,0.10)",border:"1px solid rgba(210,153,34,0.30)",color:o.color.warning,fontFamily:o.font.mono},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20V5.5a.5.5 0 0 0-.5-.5H6.5A2.5 2.5 0 0 0 4 7.5v12z"}),e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 0 6.5 22H20v-5"}),e.jsx("path",{d:"M12 6.5l.8 1.9 1.9.8-1.9.8-.8 1.9-.8-1.9-1.9-.8 1.9-.8z"})]}),t.name]},r):e.jsx("span",{children:t.text},r))})}function Io(n){const o=n.text??"";if(n.skillTag){const r=o.replace(/^\/skill:[^\s]*\s*/,"");return{skillTag:n.skillTag,args:r,copyText:o.trim()}}const t=/<skill\s+name="([^"]+)"[^>]*>[\s\S]*?<\/skill>\s*([\s\S]*)$/.exec(o);if(t){const r=(t[2]??"").replace(/^\s*\n\s*/,"").trim();return{skillTag:t[1],args:r,copyText:`/skill:${t[1]}${r?" "+r:""}`}}return{args:o,copyText:o}}function Co(n){const o=[];let t=0,r;const s=new RegExp(jo.source,"g");for(;(r=s.exec(n))!==null;)r.index>t&&o.push({type:"text",text:n.slice(t,r.index)}),o.push({type:"skill",name:r[1]}),t=r.index+r[0].length;return t<n.length&&o.push({type:"text",text:n.slice(t)}),o.length>0?e.jsx(So,{parts:o}):e.jsx(e.Fragment,{children:n})}function Mo({text:n}){const o=N();return e.jsx("div",{style:{display:"flex",justifyContent:"center",margin:"4px 0"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 14px",borderRadius:999,border:"1px solid rgba(99,102,241,0.18)",background:"linear-gradient(135deg, rgba(99,102,241,0.07), rgba(139,92,246,0.03))",color:o.color.muted,fontSize:"0.85em"},children:[e.jsx("span",{style:{width:13,height:13,borderRadius:"50%",border:"2px solid rgba(99,102,241,0.25)",borderTopColor:"#6366f1",animation:"vagus-spin 0.8s linear infinite",display:"inline-block",flexShrink:0}}),n]})})}const ut=1e3;function nn(n){const o=[];let t=[],r=[],s=new Set;const i=()=>{t.length>0&&o.push({kind:"work",work:t});for(const c of r)o.push({kind:"item",item:c});const l=wo(t);if(l.length>0){const c=new Map;for(const x of l){const f=c.get(x.file)??{file:x.file,added:0,removed:0};f.added+=x.added,f.removed+=x.removed,x.diff&&(f.diff=f.diff?`${f.diff}
9
+ ${x.diff}`:x.diff),x.patch&&(f.patch=f.patch?`${f.patch}
10
+ ${x.patch}`:x.patch),c.set(x.file,f)}const p=l[l.length-1].toolCallId,g=[...c.values()].map(x=>({...x,turnToolCallId:p}));o.push({kind:"turnSummary",files:g})}t=[],r=[],s=new Set};for(let l=0;l<n.length;l++){const c=n[l];if(c.kind==="thinking"||c.kind==="tool"){if(c.kind==="thinking"){if(s.has(c.text))continue;s.add(c.text)}t.push(c)}else if(c.kind==="assistant"){let p=!0,g=t.length>0;for(let x=l+1;x<n.length;x++){const f=n[x];if(f.kind==="user"||f.kind==="system")break;if(f.kind==="thinking"||f.kind==="tool"){g=!0,p=!1;break}if(f.kind==="assistant"){p=!1;break}}p||!g?r.push(c):t.push(c)}else i(),o.push({kind:"item",item:c})}return i(),o}function Eo(n){const o=[];let t=new Set;for(const r of n)if(r.kind==="user")t=new Set,o.push(r);else if(r.kind==="thinking"){if(t.has(r.text))continue;t.add(r.text),o.push(r)}else o.push(r);return o}function To({item:n,onToggleCard:o,onCopy:t,onEditSubmit:r}){const s=N();return n.kind==="user"?e.jsx(Fo,{item:n,onCopy:t,onEditSubmit:r}):n.kind==="assistant"?e.jsx("div",{style:{display:"flex",justifyContent:"flex-start"},children:e.jsx("div",{style:{maxWidth:ut,minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",fontSize:"1em",lineHeight:1.65,color:s.color.fg},children:e.jsx(xo,{text:n.text})})}):n.kind==="thinking"?e.jsx("div",{style:{display:"flex",justifyContent:"flex-start",maxWidth:ut,width:"100%"},children:e.jsx(zo,{item:n,onToggle:()=>o==null?void 0:o(n.id)})}):n.kind==="tool"?e.jsx("div",{style:{display:"flex",justifyContent:"flex-start",maxWidth:ut,width:"100%"},children:e.jsx($o,{item:n,onToggle:()=>o==null?void 0:o(n.id)})}):n.text.startsWith("◌ 前文已摘要")||n.text.startsWith("◔ 分支摘要")?e.jsx(bo,{text:n.text}):n.text.startsWith("正在压缩")?e.jsx(Mo,{text:n.text}):e.jsx("div",{style:{display:"flex",justifyContent:"center"},children:e.jsx("span",{style:{color:s.color.muted,fontSize:"0.86em"},children:n.text})})}const xt=a.memo(To,(n,o)=>n.item===o.item),Ro={width:26,height:26,borderRadius:6,border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"inherit"};function Fo({item:n,onCopy:o,onEditSubmit:t}){const r=N(),s=Io(n),[i,l]=a.useState(!1),[c,p]=a.useState(s.copyText),[g,x]=a.useState(!1),[f,h]=a.useState(null),u=a.useRef(null);a.useEffect(()=>{var b;i&&((b=u.current)==null||b.focus())},[i]),a.useEffect(()=>{if(f===null)return;const b=m=>{m.key==="Escape"&&h(null)};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[f]);const I=()=>{o==null||o(s.copyText),x(!0),window.setTimeout(()=>x(!1),1600)},w=b=>({...Ro,color:b});return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4,maxWidth:"100%"},children:[i?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:u,value:c,onChange:b=>p(b.target.value),rows:3,style:{width:"100%",maxWidth:520,minHeight:64,background:r.color.bg,border:"1px solid #6366f1",borderRadius:12,padding:"8px 10px",fontSize:"0.95em",lineHeight:1.5,color:r.color.fg,outline:"none",resize:"vertical",fontFamily:"inherit"}}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>{l(!1),p(s.copyText)},style:{height:30,padding:"0 12px",borderRadius:8,border:`1px solid ${r.color.border}`,background:"transparent",color:r.color.muted,fontSize:"0.86em",cursor:"pointer",fontFamily:"inherit"},children:"取消"}),e.jsx("button",{onClick:()=>{c.trim()&&(t==null||t(c.trim())),l(!1)},style:{height:30,padding:"0 14px",borderRadius:8,border:"none",background:"linear-gradient(135deg,#6366f1,#8b5cf6)",color:"#fff",fontSize:"0.86em",fontWeight:600,cursor:"pointer",fontFamily:"inherit"},children:"发送"})]})]}):e.jsxs(e.Fragment,{children:[n.images&&n.images.length>0&&e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",justifyContent:"flex-end",maxWidth:"70%"},children:n.images.map((b,m)=>e.jsx("img",{src:b.dataUrl,alt:"附件",style:{width:80,height:80,borderRadius:8,border:`1px solid ${r.color.border}`,objectFit:"cover",background:r.color.bg,cursor:"zoom-in"},onClick:()=>h(b.dataUrl),title:"点击查看大图"},m))}),e.jsx("div",{style:{background:r.color.surface,border:`1px solid ${r.color.border}`,borderRadius:"14px 14px 4px 14px",padding:"10px 14px",maxWidth:"70%",color:r.color.fg,whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:"1em",lineHeight:1.55},children:s.skillTag?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,padding:"2px 8px",borderRadius:6,fontSize:"0.85em",background:"rgba(210,153,34,0.10)",border:"1px solid rgba(210,153,34,0.30)",color:r.color.warning,fontFamily:r.font.mono},children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20V5.5a.5.5 0 0 0-.5-.5H6.5A2.5 2.5 0 0 0 4 7.5v12z"}),e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 0 6.5 22H20v-5"}),e.jsx("path",{d:"M12 6.5l.8 1.9 1.9.8-1.9.8-.8 1.9-.8-1.9-1.9-.8 1.9-.8z"})]}),s.skillTag]}),e.jsx("span",{children:s.args})]}):n.text&&/<skill\s/.test(n.text)?Co(n.text):s.args}),(o||t)&&e.jsxs("div",{style:{display:"flex",gap:4,opacity:.55,transition:"opacity 0.15s"},onMouseEnter:b=>{b.currentTarget.style.opacity="1"},onMouseLeave:b=>{b.currentTarget.style.opacity="0.55"},children:[o&&e.jsx("button",{onClick:I,title:g?"已复制":"复制",style:{...w(g?"#16a34a":r.color.muted),transition:"color 0.15s"},children:g?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",children:e.jsx("path",{d:"M20 6L9 17l-5-5"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),t&&e.jsx("button",{onClick:()=>{p(s.copyText),l(!0)},title:"编辑",style:w(r.color.muted),children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:e.jsx("path",{d:"M4 20h4l10-10a2.83 2.83 0 0 0-4-4L4 16v4z"})})})]})]}),f!==null&&Ut.createPortal(e.jsx("div",{onClick:()=>h(null),style:{position:"fixed",inset:0,zIndex:300,background:"rgba(0,0,0,0.78)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},children:e.jsx("img",{src:f,alt:"查看大图",onClick:b=>b.stopPropagation(),style:{maxWidth:"90vw",maxHeight:"90vh",objectFit:"contain",borderRadius:10,boxShadow:"0 12px 48px rgba(0,0,0,0.5)"}})}),document.body)]})}function Do(n){const o=n/1e3;if(o<1)return`${Math.round(n)}ms`;if(o<60)return o<10?`${o.toFixed(1)}s`:`${Math.round(o)}s`;const t=Math.floor(o/60),r=Math.round(o%60);return r===0?`${t}m`:`${t}m ${r}s`}function Wo({stampedMs:n,startMs:o}){const[,t]=a.useState(0),r=n>0;a.useEffect(()=>{if(r)return;const i=window.setInterval(()=>t(l=>l+1),250);return()=>window.clearInterval(i)},[r]);const s=r?n:o!==void 0?Math.max(0,Date.now()-o):0;return s<=0?null:e.jsx(e.Fragment,{children:Do(s)})}function Bo({work:n,onToggleItem:o,live:t,startMs:r,attached:s,attachedAnchor:i}){const l=N(),[c,p]=a.useState(!1),g=a.useRef(!1),x=a.useRef(!1);if(a.useEffect(()=>{t?(g.current=!0,x.current||p(!0)):g.current&&(g.current=!1,p(!1),x.current=!1)},[t]),n.length===0)return null;const f=n.filter(m=>m.kind==="tool").length,h=n.filter(m=>m.kind==="thinking").length,u=n.reduce((m,j)=>Math.max(m,j.kind==="thinking"||j.kind==="tool"?j.turnDurationMs??0:0),0),I=u>0||r!==void 0,b=f>0?`${f} 个工具`+(h>0?` · ${h} 次思考`:""):h>0?`${h} 次思考`:"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("button",{onClick:()=>{p(m=>{const j=!m;return j||(x.current=!0),j})},title:c?"收起工作内容":"展开工作内容",style:{display:"flex",alignItems:"center",gap:6,width:"fit-content",textAlign:"left",border:"none",background:"transparent",padding:"2px 0",cursor:"pointer",color:l.color.muted,fontSize:"0.89em"},children:[e.jsx("span",{style:{fontSize:"0.71em",color:l.color.muted,flexShrink:0,transition:"transform 0.15s",transform:c?"rotate(90deg)":"rotate(0deg)"},children:"▶"}),e.jsx("span",{style:{color:"#6366f1",fontWeight:600},children:"工作内容"}),e.jsxs("span",{style:{color:l.color.muted},children:[b,b!==""&&I&&" · ",e.jsx(Wo,{stampedMs:u,startMs:r})]})]}),c&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,marginTop:2},children:n.map((m,j)=>e.jsxs("div",{style:{display:"contents"},children:[e.jsx(xt,{item:m,onToggleCard:()=>o(m.id)}),s&&j===i&&s]},`w${m.id}`))})]})}const Lo=a.memo(Bo,(n,o)=>n.live===o.live&&n.startMs===o.startMs&&n.attachedAnchor===o.attachedAnchor&&n.attached===o.attached&&n.work.length===o.work.length&&n.work.every((t,r)=>t===o.work[r]));function zo({item:n,onToggle:o}){const t=N(),r=n.collapsed===!0;return e.jsxs("button",{onClick:o,title:r?"展开思考":"收起思考",style:{display:"block",width:"100%",textAlign:"left",border:"1px solid rgba(99,102,241,0.2)",borderRadius:8,background:"linear-gradient(135deg, rgba(99,102,241,0.07), rgba(139,92,246,0.04))",padding:"8px 12px",cursor:"pointer",color:t.color.fg},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{color:t.color.muted,fontSize:"0.86em"},children:r?"▶":"▼"}),e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#6366f1",strokeWidth:"1.8",style:{flexShrink:0},children:e.jsx("path",{d:"M12 4.5a2.5 2.5 0 0 0-4.96-.46 2.5 2.5 0 0 0-1.98 3 2.5 2.5 0 0 0-1.32 4.24 3 3 0 0 0 .34 5.58 2.5 2.5 0 0 0 2.96 3.08A2.5 2.5 0 0 0 12 19.5a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-1.98-3A2.5 2.5 0 0 0 12 4.5z"})}),e.jsx("span",{style:{color:"#6366f1",fontSize:"0.88em",fontWeight:600,letterSpacing:"0.02em"},children:"思考"}),e.jsxs("span",{style:{marginLeft:"auto",color:t.color.muted,fontSize:"0.79em"},children:[n.text.length," chars"]})]}),!r&&e.jsx("div",{style:{marginTop:6,color:t.color.muted,fontSize:"0.86em",lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:260,overflowY:"auto"},children:n.text})]})}function $o({item:n,onToggle:o}){const t=N(),r=n.collapsed===!0,s=n.status==="succeeded"?t.color.success:n.status==="failed"?t.color.error:t.color.warning;return e.jsxs("div",{style:{border:"1px solid rgba(99,102,241,0.18)",borderRadius:8,background:"linear-gradient(135deg, rgba(99,102,241,0.06), rgba(139,92,246,0.03))",padding:"8px 12px",display:"flex",flexDirection:"column",gap:4,minWidth:"100%"},children:[e.jsxs("button",{onClick:o,title:r?"展开详情":"收起详情",style:{display:"flex",alignItems:"center",gap:8,background:"none",border:"none",padding:0,cursor:"pointer",color:"inherit",textAlign:"left"},children:[e.jsx("span",{style:{color:t.color.muted,fontSize:"0.86em"},children:r?"▶":"▼"}),e.jsx("span",{style:{color:s,fontSize:"0.86em"},children:"⚙"}),e.jsx("span",{style:{color:"#6366f1",fontSize:"0.93em",fontWeight:600,flexShrink:0},children:n.name}),n.args&&e.jsx("span",{style:{color:t.color.muted,fontSize:"0.79em",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:n.args}),e.jsx("span",{style:{marginLeft:"auto",width:72,flexShrink:0,textAlign:"right",whiteSpace:"nowrap",fontSize:"0.86em",color:s,fontWeight:600},children:n.status==="running"?"● running":n.status==="succeeded"?"✓ done":"✗ failed"})]}),!r&&e.jsx(e.Fragment,{children:n.diff?e.jsx(on,{diff:n.diff,t,full:!0,maxHeight:400}):n.result&&e.jsx("pre",{style:{background:t.color.bg,border:`1px solid ${t.color.border}`,borderRadius:6,padding:"8px 10px",margin:0,maxHeight:240,overflow:"auto",fontSize:"0.79em",lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",color:t.color.muted},children:n.result})})]})}function Ao(n){const o=n.split(`
11
+ `);return o.some(r=>r.startsWith("--- ")||r.startsWith("diff --git"))?Po(o):Ho(o)}function Ho(n){const o=[];let t=[],r=null;for(const s of n){const i=s[0]??"",l=s.indexOf(" ",1),c=l===-1?"":s.slice(1,l).trim(),p=l===-1?s.slice(1):s.slice(l+1);if(p.trim()==="...")continue;const g=i==="+"||i==="-"?"change":"context";g!==r&&(t.length>0&&r&&o.push({kind:r,lines:t}),t=[],r=g),t.push({marker:i,lineNum:c,content:p})}return t.length>0&&r&&o.push({kind:r,lines:t}),o}function Po(n){const o=[];let t=[],r=null,s=0,i=0;const l=()=>{t.length>0&&r&&o.push({kind:r,lines:t}),t=[],r=null};for(const c of n){if(c.startsWith("--- ")||c.startsWith("+++ ")||c.startsWith("diff --git")||c.startsWith("index ")||c.startsWith("\\"))continue;const p=c.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);if(p){l(),s=Number(p[1])-1,i=Number(p[2])-1;continue}const g=c[0]??"",x=g===" "||g==="+"||g==="-"?c.slice(1):c,f=g==="+"||g==="-"?"change":"context";f!==r&&(l(),r=f);let h="";g==="+"?(i++,h=String(i)):g==="-"?(s++,h=String(s)):(s++,i++,h=String(i)),t.push({marker:g,lineNum:h,content:x})}return l(),o}function on({diff:n,t:o,maxHeight:t,full:r}){const{theme:s}=Ke(),i=s==="dark",l=a.useMemo(()=>Ao(n),[n]),c=i?{addBg:"rgba(34,197,94,0.15)",addFg:"#4ade80",addEdge:"#4ade80",delBg:"rgba(239,68,68,0.15)",delFg:"#f87171",delEdge:"#f87171",foldBg:"rgba(255,255,255,0.05)",foldFg:"#9ca3af",text:o.color.fg,numFg:"#6b7280",border:o.color.border}:{addBg:"#f0fdf4",addFg:"#16a34a",addEdge:"#16a34a",delBg:"#fef2f2",delFg:"#ef4444",delEdge:"#ef4444",foldBg:"#f3f4f6",foldFg:"#6b7280",text:"#1f2937",numFg:"#9ca3af",border:"#e5e7eb"},p=(x,f,h)=>{const u=x.marker==="+",I=x.marker==="-",w=u?c.addBg:I?c.delBg:"transparent",b=u?c.addEdge:I?c.delEdge:"transparent",m=u?c.addFg:I?c.delFg:c.numFg;return e.jsxs("div",{style:{display:"flex",whiteSpace:"pre",background:w,minWidth:"100%",borderLeft:`3px solid ${b}`,lineHeight:"26px",minHeight:26,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",color:c.text},children:[e.jsx("span",{style:{flexShrink:0,width:50,textAlign:"right",paddingRight:10,userSelect:"none",color:m},children:x.lineNum}),e.jsx("span",{style:{flexShrink:0,width:18,textAlign:"center",userSelect:"none",color:m},children:x.marker===" "?" ":x.marker}),e.jsx("span",{style:{whiteSpace:"pre",background:w},children:x.content})]},`${h}-${f}`)},g=(x,f)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-start",padding:"2px 10px",background:c.foldBg,borderRadius:6,margin:"2px 0",color:c.foldFg,fontSize:"0.75em",fontFamily:"system-ui, -apple-system, sans-serif",userSelect:"none"},children:[x," unmodified lines"]},f);return e.jsx("div",{style:{background:i?o.color.bg:"#ffffff",border:`1px solid ${c.border}`,borderRadius:8,margin:0,maxHeight:t??"none",overflowX:"auto",overflowY:t!==void 0?"auto":"hidden",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",lineHeight:"26px"},children:e.jsxs("div",{style:{width:"max-content",minWidth:"100%"},children:[l.map((x,f)=>{if(x.kind==="change")return e.jsx("div",{children:x.lines.map((h,u)=>p(h,u,`s${f}`))},`s${f}`);if(r)return null;if(!r&&x.lines.length>2){const h=[x.lines[0],x.lines[x.lines.length-1]],u=x.lines.length-2;return e.jsxs("div",{children:[p(h[0],0,`s${f}-a`),g(u,`s${f}-f`),p(h[1],1,`s${f}-b`)]},`s${f}`)}return e.jsx("div",{children:x.lines.map((h,u)=>p(h,u,`s${f}-c`))},`s${f}`)}),l.length===0&&e.jsx("div",{style:{padding:"8px 10px",color:c.numFg,fontSize:"0.85em",fontFamily:"system-ui, sans-serif"},children:"(无 diff)"})]})})}function Oo({ext:n,muted:o,accent:t}){return n==="py"?e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[e.jsx("path",{d:"M14.5 3.5c3.4.4 4.7 2 4.7 4.2v3.2c0 1.7-1.3 2.8-2.8 2.8h-4.2c-2.3 0-4 1.7-4 4v3.4c0 2 1 3.4 3.9 3.4h3.3",stroke:"#3776ab",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M9.5 20.5c-3.4-.4-4.7-2-4.7-4.2v-3.2c0-1.7 1.3-2.8 2.8-2.8h4.2c2.3 0 4-1.7 4-4V3",stroke:"#ffd43b",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round"})]}):n==="md"?e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[e.jsx("path",{d:"M5 3.5h14a1.5 1.5 0 0 1 1.5 1.5v14a1.5 1.5 0 0 1-1.5 1.5H5A1.5 1.5 0 0 1 3.5 19V5A1.5 1.5 0 0 1 5 3.5z",stroke:t,strokeWidth:"1.5"}),e.jsx("path",{d:"M7.5 15.5v-6l2.5 2.5 2.5-2.5v6",stroke:t,strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M14.5 15.5V10M14.5 12h3.5M14.5 15.5h3.5",stroke:t,strokeWidth:"1.6",strokeLinecap:"round"})]}):e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[e.jsx("path",{d:"M7 3h7l5 5v13H7z",stroke:o,strokeWidth:"1.6",strokeLinejoin:"round"}),e.jsx("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.6",strokeLinejoin:"round"})]})}const _o=a.memo(function({files:o,onOpenFile:t,onRevertAll:r,reverting:s,onExpand:i}){const l=N(),[c,p]=a.useState(!1);if(o.length===0)return null;const g=o.reduce((h,u)=>h+u.added,0),x=o.reduce((h,u)=>h+u.removed,0),f={height:22,padding:"0 10px",borderRadius:5,border:`1px solid ${l.color.border}`,background:l.color.surface,color:l.color.muted,fontSize:"0.72em",fontWeight:600,cursor:"pointer",fontFamily:"inherit",flexShrink:0,transition:"background 0.15s, color 0.15s, border-color 0.15s"};return e.jsxs("div",{style:{border:`1px solid ${l.color.border}`,borderRadius:8,overflow:"hidden",background:l.color.bg,fontFamily:"inherit"},children:[e.jsxs("div",{onClick:()=>{p(h=>{const u=!h;return i==null||i(u),u})},style:{display:"flex",alignItems:"center",gap:8,padding:"7px 12px",background:l.color.surface,cursor:"pointer",borderBottom:c?`1px solid ${l.color.border}`:"none",userSelect:"none"},children:[e.jsx("span",{style:{color:l.color.muted,fontSize:"0.7em",flexShrink:0,transition:"transform 0.15s",transform:c?"rotate(90deg)":"none"},children:"▶"}),e.jsxs("span",{style:{color:l.color.fg,fontSize:"0.85em",fontWeight:600,flexShrink:0},children:[o.length," 个文件已更改"]}),e.jsxs("span",{style:{color:l.color.success,fontSize:"0.8em",fontWeight:600,flexShrink:0},children:["+",g]}),e.jsxs("span",{style:{color:l.color.error,fontSize:"0.8em",fontWeight:600,flexShrink:0},children:["-",x]}),e.jsx("span",{style:{flex:1}}),e.jsx("button",{onClick:h=>{h.stopPropagation(),r()},disabled:s,title:"撤销本轮的全部更改",style:{background:"none",border:"none",cursor:s?"wait":"pointer",color:l.color.muted,fontSize:"0.78em",fontWeight:600,fontFamily:"inherit",padding:"2px 6px",borderRadius:4,flexShrink:0,opacity:s?.55:1,transition:"color 0.15s, background 0.15s"},onMouseEnter:h=>{h.currentTarget.style.background=l.color.sidebarHover,h.currentTarget.style.color=l.color.fg},onMouseLeave:h=>{h.currentTarget.style.background="none",h.currentTarget.style.color=l.color.muted},children:s?"撤销中…":"撤销"})]}),e.jsx("div",{style:{display:"grid",gridTemplateRows:c?"1fr":"0fr",transition:"grid-template-rows 0.22s ease"},children:e.jsx("div",{style:{overflow:"hidden",minHeight:0},children:e.jsx("div",{style:{padding:"3px 0",display:"flex",flexDirection:"column"},children:o.map(h=>{const u=h.file.lastIndexOf("/"),I=u>=0?h.file.slice(0,u+1):"",w=u>=0?h.file.slice(u+1):h.file,b=w.toLowerCase(),m=b.endsWith(".py")?"py":b.endsWith(".md")?"md":"other";return e.jsxs("div",{onClick:()=>t(h.file,o),title:"在右侧面板查看本轮的 diff",style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",background:"transparent",cursor:"pointer"},onMouseEnter:j=>{j.currentTarget.style.background=l.color.sidebarHover},onMouseLeave:j=>{j.currentTarget.style.background="transparent"},children:[e.jsx(Oo,{ext:m,muted:l.color.muted,accent:l.color.accent}),e.jsxs("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8em"},children:[e.jsx("span",{style:{color:l.color.fg,fontWeight:600},children:w}),I&&e.jsxs("span",{style:{color:l.color.muted},children:[" ",I]})]}),e.jsxs("span",{style:{color:l.color.success,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["+",h.added]}),e.jsxs("span",{style:{color:l.color.error,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["-",h.removed]}),e.jsx("button",{onClick:j=>{j.stopPropagation(),t(h.file,o)},title:"在右侧面板查看本轮的 diff",style:f,onMouseEnter:j=>{j.currentTarget.style.background=l.color.sidebarHover,j.currentTarget.style.color=l.color.fg},onMouseLeave:j=>{j.currentTarget.style.background=l.color.surface,j.currentTarget.style.color=l.color.muted},children:"审查"})]},h.file)})})})})]})},(n,o)=>{if(n.files.length!==o.files.length)return!1;for(let t=0;t<n.files.length;t++){const r=n.files[t],s=o.files[t];if(r.file!==s.file||r.added!==s.added||r.removed!==s.removed||r.turnToolCallId!==s.turnToolCallId)return!1}return!0}),Be="__welcome__";function ot(){return{items:[],busy:!1,queued:[],thinkingLevel:void 0,info:void 0,historyHasMore:!1,historyTotal:0,historyStartIndex:0}}function nt(n){return n.activeId??Be}function xe(n,o,t){const r=n.slots[o]??ot(),s=t(r);return s===r?n:{...n,slots:{...n.slots,[o]:s}}}function qo(n,o){switch(o.type){case"activate":return{...n,activeId:o.sessionId};case"clearActive":return{...n,activeId:void 0};case"loadHistory":return xe(n,o.sessionId,t=>({...ot(),items:ne([],{type:"historyLoaded",id:o.id,messages:o.messages}),info:t.info,thinkingLevel:t.thinkingLevel,historyHasMore:o.hasMore??!1,historyTotal:o.total??o.messages.length,historyStartIndex:o.startIndex??Math.max(0,(o.total??o.messages.length)-o.messages.length)}));case"prependHistory":return xe(n,o.sessionId,t=>({...t,items:ne(t.items,{type:"prependHistory",id:o.id,messages:o.messages}),historyHasMore:o.hasMore,historyTotal:o.total,historyStartIndex:o.startIndex}));case"localSystem":return xe(n,nt(n),t=>({...t,items:ne(t.items,{type:"system",id:o.id,text:o.text})}));case"removeMessage":return xe(n,nt(n),t=>({...t,items:ne(t.items,{type:"removeMessage",id:o.id})}));case"userMessage":return xe(n,o.sessionId,t=>({...t,items:ne(t.items,{type:"userMessage",id:o.id,text:o.text,...o.skillTag?{skillTag:o.skillTag}:{},...o.images&&o.images.length>0?{images:o.images}:{}})}));case"setInfo":return xe(n,o.sessionId,t=>({...t,info:o.info,thinkingLevel:o.thinkingLevel??t.thinkingLevel}));case"toggleCollapse":return xe(n,nt(n),t=>({...t,items:ne(t.items,{type:"toggleCollapse",id:o.id})}));case"forceIdle":return xe(n,nt(n),t=>t.busy||t.turnStart!==void 0?{...t,busy:!1,turnStart:void 0}:t);case"moveWelcome":{const t=n.slots[Be];if(!t||t.items.length===0)return n;const r=n.slots[o.sessionId]??ot(),s={...n.slots};return s[o.sessionId]={...r,items:[...r.items,...t.items],thinkingLevel:r.thinkingLevel??t.thinkingLevel},delete s[Be],{...n,slots:s}}case"applyEvent":{const{sessionId:t,id:r,event:s}=o;return xe(n,t,i=>No(i,r,s))}}}function No(n,o,t){switch(t.type){case"session.turn":if(t.kind==="start")return{...n,busy:!0,turnStart:Date.now()};if(n.turnStart!==void 0){const r=ne(n.items,{type:"turnEnd",startedAt:n.turnStart,endedAt:Date.now()});return{...n,busy:!1,turnStart:void 0,items:r}}return{...n,busy:!1,turnStart:void 0};case"session.message":if(t.kind==="text_delta")return{...n,items:ne(n.items,{type:"assistantDelta",id:o,text:t.text})};if(t.kind==="text_done")return{...n,items:ne(n.items,{type:"collapseAll"})};if(t.kind==="user_queued"){const r=t.images;return{...n,items:ne(n.items,{type:"userMessage",id:o,text:t.text,...r&&r.length>0?{images:r}:{}})}}return t.kind==="error"?{...n,items:ne(n.items,{type:"system",id:o,text:`⚠ ${t.text}`})}:n;case"session.thinking":return t.kind==="delta"?{...n,items:ne(n.items,{type:"thinkingDelta",id:o,text:t.text})}:{...n,items:ne(n.items,{type:"thinkingDone",id:o})};case"session.tool_call":return{...n,items:ne(n.items,{type:"toolCallStarted",id:o,toolCallId:t.toolCallId,name:t.name,args:t.args})};case"session.tool_result":return{...n,items:ne(n.items,{type:"toolCallFinished",toolCallId:t.toolCallId,result:t.result,isError:t.isError,...t.diff!==void 0?{diff:t.diff}:{},...t.patch!==void 0?{patch:t.patch}:{}})};case"session.queue_update":{const r=t.steering??[],s=new Map;let i=0;for(const c of n.queued)s.set(c.text,c.id),c.id>i&&(i=c.id);let l=i+1;return{...n,queued:r.map(c=>({id:s.get(c)??l++,text:c}))}}case"session.subagent":{const r=t.kind,s=t.agentType?`[${t.agentType}] `:"";let i="";if(r==="created"||r==="started")i=`🧩 子代理 ${s}开始:${t.description??t.agentId??""}`;else if(r==="completed")i=`✅ 子代理 ${s}完成:${(t.result??"").slice(0,500)}`;else if(r==="failed")i=`❌ 子代理 ${s}失败:${t.error??t.result??""}`;else if(r==="steered")i=`📮 子代理 ${s}收到指示:${t.description??""}`;else if(r==="compacted")i=`🧹 子代理 ${s}已压缩上下文`;else return n;return{...n,items:ne(n.items,{type:"system",id:o,text:i})}}default:return n}}function Vo(){const[n,o]=a.useReducer(qo,{activeId:void 0,slots:{}}),t=n.slots[n.activeId??Be]??ot();return{state:n,dispatch:o,active:t}}const _t=n=>1-Math.pow(1-n,3);function Uo(n,o){const t=a.useRef(null),r=a.useRef(!0),s=a.useRef(!1),i=a.useRef(!1),l=a.useRef(0),c=a.useRef(0),[p,g]=a.useState(!1);a.useEffect(()=>{const b=t.current;if(!b)return;const m=()=>{const j=b.scrollHeight-b.scrollTop-b.clientHeight<60;r.current=j,g(!j),i.current||(b.scrollTop<l.current?s.current=!0:j&&(s.current=!1)),l.current=b.scrollTop};return b.addEventListener("scroll",m,{passive:!0}),m(),()=>b.removeEventListener("scroll",m)},[o]),a.useEffect(()=>{c.current=0,s.current=!1;let b=0,m=0;return b=requestAnimationFrame(()=>{w(!1),m=requestAnimationFrame(()=>w(!1))}),()=>{cancelAnimationFrame(b),cancelAnimationFrame(m)}},[o]),a.useEffect(()=>{const b=c.current;c.current=n,n>b&&!s.current&&r.current&&(b===0?requestAnimationFrame(()=>{w(!1),requestAnimationFrame(()=>w(!1))}):w(!1))},[n]);const x=()=>{s.current||r.current&&w(!1)},f=(b=!0)=>{s.current||w(b)},h=(b=!0,m)=>{if(s.current=!1,m!==void 0&&m>0){const j=t.current;if(!j)return;const k=j.scrollTop;i.current=!0;const B=performance.now(),H=P=>{const z=Math.min(1,(P-B)/m),F=j.scrollHeight-j.clientHeight;j.scrollTop=k+(F-k)*_t(z),z<1?requestAnimationFrame(H):requestAnimationFrame(()=>{i.current=!1})};requestAnimationFrame(H)}else w(b)},u=(b,m=500)=>{const j=t.current;if(!j||b===0)return;const k=j.scrollTop,B=Math.max(0,k+b);i.current=!0;const H=performance.now(),P=z=>{const F=Math.min(1,(z-H)/m);j.scrollTop=k+(B-k)*_t(F),F<1?requestAnimationFrame(P):requestAnimationFrame(()=>{i.current=!1})};requestAnimationFrame(P)},I=()=>{c.current=0},w=b=>{const m=t.current;if(m){i.current=!0,r.current=!0;try{b?m.scrollTo({top:m.scrollHeight,behavior:"smooth"}):m.scrollTop=m.scrollHeight}finally{requestAnimationFrame(()=>{i.current=!1})}}};return{scrollRef:t,nearBottomRef:r,scrollLockedRef:s,lastItemCountRef:c,showBottomBtn:p,followStream:x,scrollToBottom:f,forceScrollToBottom:h,animatedScrollBy:u,resetSnap:I}}function Ko(){const[n,o]=a.useState(""),[t,r]=a.useState([]),[s,i]=a.useState([]);return{input:n,setInput:o,attachments:t,fileAttachments:s,attachFiles:g=>{const x=[],f=[];let h=0;for(const u of g)if(u.type.startsWith("image/")){h++;const I=new FileReader;I.addEventListener("load",()=>{x.push({dataUrl:String(I.result),mimeType:u.type,name:u.name}),h-=1,h===0&&(r(w=>[...w,...x]),i(w=>[...w,...f]))}),I.readAsDataURL(u)}else{h++;const I=new FileReader;I.addEventListener("load",()=>{f.push({name:u.name,content:String(I.result)}),h-=1,h===0&&(r(w=>[...w,...x]),i(w=>[...w,...f]))}),I.readAsText(u)}h===0&&(r(u=>[...u,...x]),i(u=>[...u,...f]))},removeAttachment:g=>{const x=t.length;g<x?r(f=>f.filter((h,u)=>u!==g)):i(f=>f.filter((h,u)=>u!==g-x))},submit:g=>{const x=n.trim();if(!x&&t.length===0&&s.length===0)return;o("");const f=t;r([]);const h=s.map(I=>`<file name="${I.name}">
12
+ ${I.content}
13
+ </file>`).join(`
14
+ `),u=[x,h].filter(Boolean).join(`
15
+
16
+ `);i([]),g(u,f)}}}class Yo{constructor({url:o,onOpen:t,onClose:r}){Ie(this,"ws");Ie(this,"listeners",new Set);Ie(this,"onOpen");Ie(this,"onClose");Ie(this,"pendingFrames",[]);Ie(this,"opened",!1);this.onOpen=t,this.onClose=r,this.ws=new WebSocket(o),this.ws.addEventListener("open",()=>{var s;this.opened=!0;for(const i of this.pendingFrames)this.ws.send(JSON.stringify(i));this.pendingFrames.length=0,(s=this.onOpen)==null||s.call(this)}),this.ws.addEventListener("message",s=>{try{const i=JSON.parse(String(s.data));for(const l of this.listeners)l(i)}catch{}}),this.ws.addEventListener("close",s=>{var i;(i=this.onClose)==null||i.call(this,s.code,s.reason)})}send(o){this.opened||this.ws.readyState===WebSocket.OPEN?this.ws.send(JSON.stringify(o)):this.pendingFrames.push(o)}onFrame(o){return this.listeners.add(o),()=>this.listeners.delete(o)}close(){this.ws.close(),this.listeners.clear()}}const Xo=`ws://${location.host}`;function Jo(n){const[o,t]=a.useState(null),r=a.useRef(null),s=a.useRef(()=>{}),i=a.useCallback(l=>{s.current=l},[]);return a.useEffect(()=>{const l=n??new Yo({url:Xo,onOpen:()=>{}}),c=new Xn(l);t(c),r.current=c;const p=c.onEvent(g=>{s.current(g)});return()=>{p(),l.close()}},[n]),{client:o,registerOnEvent:i,clientRef:r}}function Go(n,o,t,r){const[s,i]=a.useState([]),l=a.useCallback(async f=>{try{const h=await f.request("project.archived",{});Array.isArray(h)&&i(h)}catch{}},[]),c=a.useCallback(async f=>{if(n)try{await n.request("project.archive",{cwd:f}),l(n),o(n)}catch{}},[n,l,o]),p=a.useCallback(async f=>{if(n)try{await n.request("project.unarchive",{cwd:f}),l(n),o(n)}catch{}},[n,l,o]),g=a.useCallback(async(f,h,u)=>{if(!n)return;const I=f.split(/[\\/]/).filter(Boolean).pop()??f;t("彻底删除项目",`将永久删除“${I}”的归档会话文件,不可恢复。`,"彻底删除",()=>{(async()=>{var w;try{await n.request("project.delete",{cwd:f}),i(b=>b.filter(m=>m.cwd!==f)),u&&((w=h.find(b=>b.path===u))==null?void 0:w.cwd)===f&&r(u),o(n)}catch{}})()})},[n,t,r,o]),x=a.useCallback(async f=>{n&&t("删除归档会话","将永久删除该归档会话,不可恢复。","删除",()=>{(async()=>{try{await n.request("session.deleteArchived",{sessionFile:f}),l(n)}catch{}})()})},[n,t,l]);return{archivedProjects:s,syncArchived:l,archiveProject:c,unarchiveProject:p,deleteProject:g,deleteArchivedSession:x}}function Qo({items:n,scrollRef:o,activeId:t}){const r=N(),s=a.useMemo(()=>{const x=[];let f=0,h="";for(const u of n)u.kind==="user"?(x.push({msgIndex:f,question:u.text,answer:""}),h="",f++):u.kind==="assistant"&&(h=u.text,x.length>0&&(x[x.length-1].answer=h));return x},[n]),[i,l]=a.useState(null),[c,p]=a.useState(-1),g=a.useRef(null);return a.useEffect(()=>{const x=g.current;x&&(x.scrollTop=x.scrollHeight)},[t]),s.length===0?null:e.jsxs("div",{ref:g,className:"vagus-nav-scroll",style:{position:"absolute",left:6,top:"50%",transform:"translateY(-50%)",width:24,maxHeight:300,overflowY:"auto",pointerEvents:"auto",zIndex:5,display:"flex",flexDirection:"column",padding:"2px 0"},children:[s.map(({msgIndex:x,question:f,answer:h},u)=>{const I=c===-1?99:Math.abs(u-c),w=I===0?26:I===1?19:13,b=I===0?"#6366f1":I===1?"rgba(99,102,241,0.55)":r.color.border;return e.jsx("div",{onMouseDown:m=>m.preventDefault(),onMouseEnter:m=>{p(u),l({index:x,question:f,answer:h,x:m.clientX,y:m.clientY})},onMouseLeave:()=>{p(-1),l(null)},onClick:m=>{var B;m.preventDefault(),m.stopPropagation();const j=document.activeElement;j instanceof HTMLElement&&j.blur();const k=(B=o.current)==null?void 0:B.querySelector(`[data-msg-index="${x}"]`);k&&k.scrollIntoView({behavior:"smooth",block:"start"})},style:{height:15,flexShrink:0,display:"flex",alignItems:"center",cursor:"pointer",pointerEvents:"auto"},children:e.jsx("div",{style:{width:w,height:3,borderRadius:2,background:b,transition:"width 0.15s, background 0.15s",flexShrink:0}})},x)}),i&&Ut.createPortal(e.jsxs("div",{style:{position:"fixed",left:i.x+18,top:Math.max(8,Math.min(i.y-12,window.innerHeight-80)),zIndex:1e3,pointerEvents:"none",background:r.color.surface,border:`1px solid ${r.color.border}`,borderRadius:8,padding:"8px 12px",fontSize:"0.78em",color:r.color.fg,maxWidth:300,lineHeight:1.5,boxShadow:"0 8px 24px rgba(0,0,0,0.15)"},children:[e.jsx("div",{style:{wordBreak:"break-word"},children:i.question.length>60?`${i.question.slice(0,60)}…`:i.question||"(空消息)"}),e.jsx("div",{style:{marginTop:6,color:r.color.muted,wordBreak:"break-word",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:i.answer.replace(/\s+/g," ")||"(暂无回答)"})]}),document.body)]})}function rn(n){const o=N(),{theme:t}=Ke(),[r,s]=a.useState(!1),i=n.variant==="welcome",l=t==="light"?"#ffffff":o.color.surface;return e.jsx("div",{className:"vagus-input-card",style:{background:l,border:`1px solid ${i&&r?"rgba(99,102,241,0.55)":o.color.border}`,borderRadius:i?22:18,boxShadow:i?r?"0 8px 40px rgba(99,102,241,0.12), 0 0 0 4px rgba(99,102,241,0.08)":"0 6px 28px rgba(0,0,0,0.05)":void 0,transition:"border-color 0.2s ease, box-shadow 0.2s ease",animation:i&&!r?"vagus-breath 3s ease-in-out infinite":void 0,display:"flex",flexDirection:"column",padding:i?"20px 24px 14px":"14px 18px 10px"},onFocus:()=>s(!0),onBlur:()=>s(!1),onMouseDown:c=>{c.target.closest("button, input, textarea, select, [contenteditable], [role='button']")||c.preventDefault()},children:e.jsx(oo,{value:n.value,onChange:n.onChange,onSubmit:n.onSubmit,usage:n.usage,providers:n.providers,onSwitchModel:n.onSwitchModel,onSetThinking:n.onSetThinking,thinkingLevel:n.thinkingLevel,permissionMode:n.permissionMode,onTogglePermission:n.onTogglePermission,attachments:n.attachments,fileAttachments:n.fileAttachments,onAttach:n.onAttach,onRemoveAttachment:n.onRemoveAttachment,busy:n.busy,onStop:n.onStop,selectedModel:n.selectedModel,onCommand:n.onCommand,commands:n.commands,onPickCommand:n.onPickCommand,onRefreshCommands:n.onRefreshCommands,focusSignal:n.focusSignal,hasPendingDialog:n.hasPendingDialog,onRestoreDialog:n.onRestoreDialog,queuedMessages:n.queuedMessages})})}const Zo={confirm:"确认",select:"请选择",input:"输入"};function qt({card:n,onRespond:o}){var x;const t=N(),{event:r}=n,[s,i]=a.useState(""),l=a.useRef(null);a.useEffect(()=>{var f;r.method==="input"&&n.status==="pending"&&((f=l.current)==null||f.focus())},[r.method,n.status]);const c=n.result?n.result.cancelled?"已取消":n.result.confirmed?"已确认":n.result.value??"":"",p=n.status==="answered",g={height:34,padding:"0 14px",borderRadius:9,fontSize:"0.9em",cursor:p?"default":"pointer",fontFamily:"inherit"};return e.jsxs("div",{style:{maxWidth:520,margin:"10px 0 6px",background:p?t.color.bg:t.color.surface,border:`1px solid ${p?t.color.border:t.color.primary}`,borderRadius:14,padding:"14px 16px",boxShadow:p?"none":"0 2px 12px rgba(0,0,0,0.12)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:p?8:10},children:[e.jsx("span",{style:{fontSize:"0.72em",fontWeight:700,letterSpacing:"0.04em",padding:"2px 8px",borderRadius:999,background:p?"transparent":t.color.primary,color:p?t.color.muted:"#fff",border:p?`1px solid ${t.color.border}`:"none"},children:r.method.toUpperCase()}),e.jsx("span",{style:{fontSize:"0.95em",fontWeight:600,color:t.color.fg},children:r.title??Zo[r.method]??r.method})]}),r.message&&e.jsx("div",{style:{fontSize:"0.92em",color:t.color.fg,lineHeight:1.6,whiteSpace:"pre-wrap",marginBottom:p?0:12},children:r.message}),p?e.jsxs("div",{style:{fontSize:"0.88em",color:t.color.muted,background:t.color.bg,border:`1px solid ${t.color.border}`,borderRadius:8,padding:"6px 10px",display:"inline-block"},children:["你的回答:",c||"—"]}):r.method==="select"?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,maxHeight:300,overflowY:"auto",marginBottom:4},children:[(r.options??[]).map(f=>e.jsx("button",{onClick:()=>o({value:f}),style:{...g,width:"100%",textAlign:"left",height:38,padding:"0 14px",border:`1px solid ${t.color.border}`,background:"transparent",color:t.color.fg},onMouseEnter:h=>{h.currentTarget.style.background=t.color.bg},onMouseLeave:h=>{h.currentTarget.style.background="transparent"},children:f},f)),((x=r.options)==null?void 0:x.length)===0&&e.jsx("div",{style:{fontSize:"0.86em",color:t.color.muted,padding:"12px 4px"},children:"(没有可用选项)"})]}):r.method==="input"?e.jsx("div",{style:{marginBottom:4},children:e.jsx("input",{ref:l,value:s,onChange:f=>i(f.target.value),onKeyDown:f=>{f.key==="Enter"&&o({value:s})},placeholder:r.placeholder??"输入…",style:{width:"100%",height:38,padding:"0 12px",borderRadius:9,border:`1px solid ${t.color.border}`,background:t.color.bg,color:t.color.fg,fontSize:"0.92em",outline:"none",fontFamily:"inherit"}})}):null,!p&&e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:6},children:[e.jsx("button",{onClick:()=>o({cancelled:!0}),style:{...g,border:`1px solid ${t.color.border}`,background:"transparent",color:t.color.fg},children:"取消"}),r.method==="confirm"&&e.jsx("button",{onClick:()=>o({confirmed:!0}),style:{...g,border:"none",background:t.color.primary,color:"#fff",fontWeight:600},children:"确认"}),r.method==="input"&&e.jsx("button",{onClick:()=>o({value:s}),disabled:s.trim().length===0,style:{...g,border:"none",background:t.color.primary,color:"#fff",fontWeight:600,opacity:s.trim().length===0?.4:1,cursor:s.trim().length===0?"not-allowed":"pointer"},children:"确定"})]})]})}function er(n){const o=N(),{items:t,busy:r,turnStartTs:s,autoscroll:i}=n,{scrollRef:l,showBottomBtn:c}=i,p=n.uiCards??[],g=p.filter(b=>b.status==="pending").map(b=>b.event.id).join(","),[x,f]=a.useState("");a.useEffect(()=>{if(g.length>0&&g!==x){f(g);const b=l.current;if(!b)return;const m=b.querySelectorAll('[data-uicard-status="pending"]'),j=m[m.length-1];if(!j)return;const k=b.getBoundingClientRect(),B=j.getBoundingClientRect(),H=B.bottom-k.bottom;if(H<=0&&B.top>=k.top)return;const P=72,z=H>0?H+P:B.top-k.top-P;i.animatedScrollBy(z,750)}},[g,i]),a.useEffect(()=>{const b=l.current,m=n.onLoadMore;if(!b||!m)return;const j=()=>{b.scrollTop<200&&!n.loadingMore&&m()};return b.addEventListener("scroll",j,{passive:!0}),()=>b.removeEventListener("scroll",j)});const h=a.useRef(0),u=a.useRef(0);a.useLayoutEffect(()=>{const b=l.current;if(!b)return;const m=h.current,j=t.length>u.current;if(u.current=t.length,j&&m>0&&b.scrollTop<400){const k=b.scrollHeight-m;k>300&&(b.scrollTop+=k)}h.current=b.scrollHeight});const I=a.useMemo(()=>nn(Eo(t)),[t]),w=a.useMemo(()=>{const b=new Map,m=new Map;let j=0,k=-1,B=-1;for(let F=0;F<I.length;F++){const M=I[F];if(M.kind==="item"&&M.item.kind==="user"){j++;continue}if(M.kind==="work"){k=F,m.has(j)||m.set(j,F);for(const O of M.work)O.kind==="tool"&&O.toolCallId&&b.set(O.toolCallId,F);M.work.some(O=>O.kind==="tool")&&(B=F)}}const H=new Map,P=new Set;for(const F of p){const M=F.event;let O=M.toolCallId?b.get(M.toolCallId):void 0;if(O===void 0&&(O=M.turn===void 0?void 0:m.get(M.turn)),O===void 0&&(O=B>=0?B:k>=0?k:void 0),O!==void 0){const _=H.get(O)??[];_.push(F),H.set(O,_),P.add(F.event.id)}}const z=p.filter(F=>!P.has(F.event.id));return{byIdx:H,unmatched:z}},[I,p]);return e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0,position:"relative"},children:[e.jsxs("header",{style:{flexShrink:0,display:"flex",alignItems:"center",gap:10,height:54,padding:"0 24px",background:o.color.bg,borderBottom:`1px solid ${o.color.border}`},children:[n.sessionName?e.jsx("span",{style:{fontSize:"0.92em",fontWeight:600,color:o.color.fg,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"38%"},children:n.sessionName}):null,n.sessionName&&n.sessionCwd?e.jsx("span",{style:{color:o.color.border,flexShrink:0,fontSize:"0.85em"},children:"|"}):null,n.sessionCwd?e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0,color:o.color.muted,fontSize:"0.85em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",style:{flexShrink:0},children:[e.jsx("path",{d:"M7 3h7l5 5v13H7z",strokeLinejoin:"round"}),e.jsx("path",{d:"M14 3v5h5",strokeLinejoin:"round"})]}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:n.sessionCwd})]}):null]}),e.jsx("main",{ref:l,style:{flex:1,overflowY:"auto",minHeight:0,padding:"28px 0"},children:e.jsxs("div",{style:{maxWidth:1050,margin:"0 auto",padding:"0 28px",display:"flex",flexDirection:"column",gap:6},children:[n.loadingMore&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,justifyContent:"center",padding:"10px 0",color:o.color.muted,fontSize:"0.82em"},children:[e.jsx("span",{style:{width:12,height:12,borderRadius:"50%",border:`2px solid ${o.color.border}`,borderTopColor:o.color.primary,animation:"vagus-spin 0.8s linear infinite",display:"inline-block"}}),"加载更早消息…"]}),t.length===0&&(n.showLoading?e.jsx("div",{style:{color:o.color.muted,fontSize:"1em",textAlign:"center",marginTop:40},children:"加载会话…"}):n.sessionLoading?null:e.jsx("div",{style:{color:o.color.muted,fontSize:"1em",textAlign:"center",marginTop:40},children:"已连接 · 输入消息开始新会话"})),(()=>{var z;let b=-1;for(let F=t.length-1;F>=0;F--)if(t[F].kind==="user"){b=F;break}let m;for(let F=t.length-1;F>b;F--){const M=t[F];if(M.kind==="thinking"||M.kind==="tool"){m=M;break}}const j=r&&m!==void 0?I.find(F=>F.kind==="work"&&F.work.some(M=>M.id===(m==null?void 0:m.id))):void 0,k=[];let B=0,H=0;const P={contentVisibility:"auto",containIntrinsicSize:"auto 120px"};for(const F of I){if(F.kind==="item"){const M=F.item;M.kind==="user"?k.push(e.jsx("div",{"data-msg-index":H++,style:{maxWidth:"100%",...P},children:e.jsx(xt,{item:M,onToggleCard:n.onToggleCard,onCopy:n.copyMessage,onEditSubmit:n.editSubmit})},`g${B}`)):k.push(e.jsx("div",{style:P,children:e.jsx(xt,{item:M,onToggleCard:n.onToggleCard,onCopy:n.copyMessage,onEditSubmit:n.editSubmit})},`g${B}`))}else if(F.kind==="turnSummary")k.push(e.jsx("div",{style:P,children:e.jsx(_o,{files:F.files,onOpenFile:n.onOpenFile,onRevertAll:()=>n.onRevertAll(F.files.map(M=>M.file)),onExpand:M=>{M&&n.autoscroll.forceScrollToBottom(!0,400)}})},`t${B}`));else{const{work:M}=F,O=((z=M[0])==null?void 0:z.id)??B,_=F===j,Z=w.byIdx.get(B)??[],G=Z.length>0?Z.map((K,ee)=>e.jsx("div",{"data-uicard-id":K.event.id,"data-uicard-status":K.status,children:e.jsx(qt,{card:K,onRespond:y=>{var T;return(T=n.onUiCardRespond)==null?void 0:T.call(n,K,y)}})},`uicardwrap-${K.event.id??ee}`)):void 0;let Q=-1;if(Z.length>0){for(let K=F.work.length-1;K>=0;K--)if(F.work[K].kind==="tool"){Q=K;break}}k.push(e.jsx("div",{style:P,children:e.jsx(Lo,{work:M,onToggleItem:K=>n.onToggleCard(K),live:_,startMs:s,attached:G,attachedAnchor:Q>=0?Q:void 0})},`w${O}`))}B++}return e.jsx(e.Fragment,{children:k})})(),w.unmatched.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:w.unmatched.map((b,m)=>e.jsx("div",{"data-uicard-id":b.event.id,"data-uicard-status":b.status,children:e.jsx(qt,{card:b,onRespond:j=>{var k;return(k=n.onUiCardRespond)==null?void 0:k.call(n,b,j)}})},`uicardwrap-${b.event.id??m}`))}),r&&t.length>0&&t[t.length-1].kind==="user"&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 0",color:o.color.muted,fontSize:"0.88em"},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:"linear-gradient(135deg,#6366f1,#8b5cf6)",animation:"vagus-pulse 1.2s ease-in-out infinite",display:"inline-block"}}),"等待响应…"]}),e.jsx("div",{})]})}),e.jsx(Qo,{items:t,scrollRef:l,activeId:n.activeId}),c&&e.jsx("button",{onClick:()=>i.forceScrollToBottom(),title:"回到底部",style:{position:"absolute",right:18,bottom:96,zIndex:6,width:36,height:36,borderRadius:"50%",background:o.color.surface,border:`1px solid ${o.color.border}`,color:o.color.muted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",transition:"background 0.15s, color 0.15s",fontFamily:"inherit"},onMouseEnter:b=>{b.currentTarget.style.background=o.color.sidebarHover,b.currentTarget.style.color=o.color.fg},onMouseLeave:b=>{b.currentTarget.style.background=o.color.surface,b.currentTarget.style.color=o.color.muted},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M12 5v14M19 12l-7 7-7-7"})})}),e.jsx("div",{style:{padding:"10px 28px 10px",background:o.color.bg,flexShrink:0},children:e.jsx("div",{style:{maxWidth:960,margin:"0 auto"},children:e.jsx(rn,{...n.inputCard,variant:"chat"})})})]})}function tr(n){const o=N();return e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0,justifyContent:"center"},children:e.jsxs("div",{style:{width:"100%",maxWidth:760,margin:"0 auto",padding:"32px 28px",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",marginBottom:22,userSelect:"none"},children:[e.jsx("div",{style:{width:46,height:46,borderRadius:14,background:"linear-gradient(135deg,#6366f1,#8b5cf6)",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:21,fontWeight:700,boxShadow:"0 6px 24px rgba(99,102,241,0.35)"},children:"◈"}),e.jsx("div",{style:{fontSize:"1.4em",fontWeight:700,color:o.color.fg,marginTop:12,letterSpacing:"-0.01em"},children:"vagusPI"}),e.jsx("div",{style:{fontSize:"0.92em",color:o.color.muted,marginTop:5},children:"你的编码智能体工作台 —— 发送第一条消息开始新的对话"})]}),e.jsx(ro,{projects:n.projects,value:n.activeProject,onChange:n.onSelectProject,onNewProject:n.onNewProject}),e.jsx("div",{style:{marginTop:10},children:e.jsx(rn,{...n.inputCard,variant:"welcome"})})]})})}function nr({state:n,onClose:o}){const t=N();return e.jsx("div",{style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center"},onMouseDown:r=>{r.target===r.currentTarget&&o()},children:e.jsxs("div",{style:{width:380,maxWidth:"calc(100vw - 48px)",background:t.color.surface,border:`1px solid ${t.color.border}`,borderRadius:16,padding:"20px 22px",boxShadow:"0 24px 80px rgba(0,0,0,0.35)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,fontSize:"1.02em",fontWeight:600,color:"#E5484D"},children:[e.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:e.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"})}),n.title]}),e.jsx("div",{style:{fontSize:"0.92em",color:t.color.muted,margin:"12px 0 22px",lineHeight:1.6},children:n.message}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[e.jsx("button",{onClick:o,style:{height:34,padding:"0 16px",borderRadius:9,border:`1px solid ${t.color.border}`,background:"transparent",color:t.color.fg,fontSize:"0.9em",cursor:"pointer",fontFamily:"inherit"},children:"取消"}),e.jsx("button",{onClick:()=>{const r=n.onConfirm;o(),r()},style:{height:34,padding:"0 16px",borderRadius:9,border:"none",background:"#E5484D",color:"#fff",fontSize:"0.9em",fontWeight:600,cursor:"pointer",fontFamily:"inherit",boxShadow:"0 2px 10px rgba(229,72,77,0.35)"},children:n.confirmLabel})]})]})})}function or(n){const o=N(),{tabs:t,activeId:r,collapsed:s,onActivate:i,onClose:l,onToggleCollapse:c,render:p,width:g=380,onWidthChange:x}=n,f=14,[h,u]=a.useState(!1),I=a.useRef(null),w=m=>{if(s)return;m.preventDefault(),I.current={startX:m.clientX,startW:g},u(!0);const j=B=>{if(!I.current)return;const H=I.current.startX-B.clientX,P=Math.min(900,Math.max(260,I.current.startW+H));x==null||x(P)},k=()=>{I.current=null,u(!1),document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",k)};document.addEventListener("mousemove",j),document.addEventListener("mouseup",k)},b=t.find(m=>m.id===r)??t[0]??null;return e.jsx("aside",{style:{width:s?f:g,flexShrink:0,minWidth:0,borderLeft:`1px solid ${o.color.border}`,background:o.color.bg,display:"flex",flexDirection:"column",minHeight:0,overflow:"hidden",transition:"width 0.3s cubic-bezier(0.25, 1, 0.5, 1)"},children:s?e.jsx("div",{onClick:c,title:"展开右侧面板",style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",userSelect:"none",background:o.color.surface,color:"#6366f1",transition:"background 0.15s"},onMouseEnter:m=>{m.currentTarget.style.background="rgba(99,102,241,0.1)"},onMouseLeave:m=>{m.currentTarget.style.background=o.color.surface},children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M15 18l-6-6 6-6"})})}):e.jsxs("div",{style:{flex:1,display:"flex",minHeight:0},children:[e.jsx("div",{onMouseDown:w,title:"拖动调整宽度",style:{width:4,flexShrink:0,cursor:"col-resize",background:h?"rgba(99,102,241,0.25)":"transparent",transition:"background 0.15s"},onMouseEnter:m=>{m.currentTarget.style.background="rgba(99,102,241,0.15)"},onMouseLeave:m=>{m.currentTarget.style.background=h?"rgba(99,102,241,0.25)":"transparent"}}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minHeight:0,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,padding:"0 6px",background:o.color.bg,borderBottom:`1px solid ${o.color.border}`,flexShrink:0,height:54,overflowX:"auto",scrollbarWidth:"none"},children:[t.map(m=>{const j=b!==null&&m.id===b.id;return e.jsxs("div",{onClick:()=>i(m.id),style:{display:"flex",alignItems:"center",gap:6,height:36,padding:"0 14px 0 20px",borderRadius:9,background:j?o.color.surface:"transparent",cursor:"pointer",userSelect:"none",flexShrink:0,maxWidth:220,transition:"background 0.15s"},onMouseEnter:k=>{j||(k.currentTarget.style.background=o.color.surface)},onMouseLeave:k=>{j||(k.currentTarget.style.background="transparent")},children:[m.icon,e.jsx("span",{style:{fontSize:"0.9em",fontWeight:j?600:500,color:j?o.color.fg:o.color.muted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:m.label}),e.jsx("button",{onClick:k=>{k.stopPropagation(),l(m.id)},title:`关闭 ${m.label}`,style:{width:17,height:17,borderRadius:5,border:"none",background:"transparent",color:o.color.muted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:0,fontFamily:"inherit",opacity:j?.85:.45,transition:"background 0.15s, color 0.15s, opacity 0.15s"},onMouseEnter:k=>{k.currentTarget.style.background=o.color.sidebarHover,k.currentTarget.style.color=o.color.fg,k.currentTarget.style.opacity="1"},onMouseLeave:k=>{k.currentTarget.style.background="transparent",k.currentTarget.style.color=o.color.muted,k.currentTarget.style.opacity=j?"0.8":"0.4"},children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.6",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]},m.id)}),e.jsx("div",{style:{flex:1}})]}),e.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden",background:o.color.bg},children:b?p(b):e.jsx("div",{style:{height:"100%"}})})]}),e.jsx("div",{onClick:c,title:"收起右侧面板",style:{width:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:o.color.surface,borderLeft:`1px solid ${o.color.border}`,cursor:"pointer",userSelect:"none",color:o.color.muted,transition:"background 0.15s, color 0.15s"},onMouseEnter:m=>{m.currentTarget.style.background="rgba(99,102,241,0.12)",m.currentTarget.style.color="#6366f1"},onMouseLeave:m=>{m.currentTarget.style.background=o.color.surface,m.currentTarget.style.color=o.color.muted},children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})})})]})})}const Nt={id:"diff",label:"审阅",icon:e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M3 12l3 3 3-6 4 9 3-5 2 2"})})};function rr({items:n,selected:o,turnId:t,expandedFiles:r,onOpenChange:s}){const i=N(),l=a.useMemo(()=>{if(!t)return[];const h=nn(n);for(let u=h.length-1;u>=0;u--){const I=h[u];if(I.kind==="turnSummary"&&I.files.some(w=>w.turnToolCallId===t))return I.files}return[]},[t,n]),[c,p]=a.useState(()=>{const h=new Set;if(r!==void 0)for(const u of r)l.some(I=>Me(I.file)===Me(u))&&h.add(u);else l.length>0&&h.add(l[0].file);return h}),g=h=>[...c].some(u=>Me(u)===Me(h)),x=h=>{const u=new Set(c);g(h)?u.delete([...u].find(I=>Me(I)===Me(h))):u.add(h),p(u),s==null||s(u.size>0?[...u]:void 0)},f=e.jsx("div",{style:{height:"100%"}});return l.length===0?f:e.jsx("div",{style:{display:"flex",flexDirection:"column",padding:"6px 0"},children:l.map((h,u)=>{const I=h.file.lastIndexOf("/"),w=I>=0?h.file.slice(0,I+1):"",b=I>=0?h.file.slice(I+1):h.file,m=g(h.file),j=sr(h.diff??"");return e.jsxs("div",{style:{borderBottom:u<l.length-1?`1px solid ${i.color.border}20`:"none"},children:[e.jsxs("div",{onClick:()=>x(h.file),style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",cursor:"pointer",userSelect:"none",background:u%2===1?i.color.surface:"transparent"},onMouseEnter:k=>{k.currentTarget.style.background=i.color.sidebarHover},onMouseLeave:k=>{k.currentTarget.style.background=u%2===1?i.color.surface:"transparent"},children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:i.color.success,strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transition:"transform 0.15s",transform:m?"rotate(90deg)":"none"},children:e.jsx("path",{d:"M9 18l6-6-6-6"})}),e.jsxs("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8em"},children:[e.jsx("span",{style:{color:i.color.muted},children:w}),e.jsx("span",{style:{color:i.color.fg,fontWeight:700},children:b})]}),e.jsxs("span",{style:{color:i.color.success,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["+",j.added]}),e.jsxs("span",{style:{color:i.color.error,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["-",j.removed]})]}),e.jsx("div",{style:{display:"grid",gridTemplateRows:m?"1fr":"0fr",transition:"grid-template-rows 0.22s ease"},children:e.jsx("div",{style:{overflow:"hidden",minHeight:0},children:e.jsx("div",{style:{padding:"2px 8px 8px",background:i.color.bg},children:h.diff?e.jsx(on,{diff:h.diff,t:i}):e.jsx("div",{style:{color:i.color.muted,fontSize:"0.78em",padding:6},children:"该轮无 diff"})})})})]},h.file)})})}function sr(n){let o=0,t=0;for(const r of n.split(`
17
+ `))r.startsWith("+")&&!r.startsWith("+++")?o+=1:r.startsWith("-")&&!r.startsWith("---")&&(t+=1);return{added:o,removed:t}}const ir={id:"widget",label:"面板",icon:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"3"}),e.jsx("path",{d:"M9 3v18M3 12h18"})]})};function lr({widgets:n}){const o=N(),t=Object.entries(n).filter(([,r])=>r.lines.length>0);return t.length===0?e.jsx("div",{style:{padding:"16px 18px",fontSize:"0.86em",color:o.color.muted},children:"(没有活动的面板)"}):e.jsx("div",{style:{padding:"10px 14px",display:"flex",flexDirection:"column",gap:10,fontFamily:o.font.mono,fontSize:"0.82em",lineHeight:1.6,color:o.color.fg},children:t.map(([r,s])=>e.jsx("div",{style:{background:o.color.bg,border:`1px solid ${o.color.border}`,borderRadius:10,padding:"8px 10px"},children:s.lines.map((i,l)=>e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:i},l))},r))})}const ft="cubic-bezier(0.25, 1, 0.5, 1)";function ar({state:n}){const o=N(),t=n==="ok"?o.color.success:n==="partial"?o.color.warning:o.color.error,r=n==="ok"?["M20 6L9 17l-5-5"]:n==="partial"?["M12 9v4","M12 17h.01","M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"]:["M18 6L6 18","M6 6l12 12"];return e.jsx("div",{style:{width:44,height:44,borderRadius:12,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",background:`${t}1f`,color:t},children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:r.map(s=>e.jsx("path",{d:s},s))})})}function dr({result:n}){const o=N(),t=n.file.lastIndexOf("/"),r=t>=0?n.file.slice(0,t+1):"",s=t>=0?n.file.slice(t+1):n.file;return e.jsxs("div",{style:{padding:"7px 10px",borderRadius:8,background:n.ok?"transparent":`${o.color.error}0d`,fontFamily:"inherit"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.82em"},children:[e.jsx("span",{style:{color:o.color.muted},children:r}),e.jsx("span",{style:{color:o.color.fg,fontWeight:500},children:s})]}),n.ok?e.jsx("span",{style:{flexShrink:0,color:o.color.success,fontSize:"0.72em",fontWeight:600,whiteSpace:"nowrap"},children:"✓ 已回退"}):e.jsx("span",{style:{flexShrink:0,color:o.color.error,fontSize:"0.72em",fontWeight:600,whiteSpace:"nowrap"},children:"✗ 回退失败"})]}),!n.ok&&n.error&&e.jsx("div",{style:{marginTop:4,color:o.color.error,fontSize:"0.7em",lineHeight:1.5,whiteSpace:"normal",wordBreak:"break-word"},children:n.error})]})}function cr({report:n,onClose:o}){const t=N(),[r,s]=a.useState(!1),i=n.results.filter(u=>u.ok).length,l=n.results.length-i,c=l===0?"ok":i===0?"fail":"partial",p=new Map;for(const u of n.results){const I=p.get(u.file);p.set(u.file,{ok:((I==null?void 0:I.ok)??!0)&&u.ok,error:u.ok?I==null?void 0:I.error:u.error??(I==null?void 0:I.error)})}const g=[...p.entries()].map(([u,I])=>({file:u,...I}));a.useEffect(()=>{const u=requestAnimationFrame(()=>s(!0));return()=>cancelAnimationFrame(u)},[]),a.useEffect(()=>{const u=I=>{I.key==="Escape"&&o()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[o]);const x=c==="ok"?t.color.success:c==="partial"?t.color.warning:t.color.error,f=c==="ok"?`已回退 ${i} 个文件`:c==="partial"?"回退部分失败":"回退失败",h=c==="ok"?"所有改动已还原到编辑前状态":c==="partial"?`成功 ${i} 个 · 失败 ${l} 个`:l===1?"1 个文件未还原":`${l} 个文件未还原`;return e.jsx("div",{onClick:o,style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0, 0, 0, 0.45)",backdropFilter:"blur(3px)",WebkitBackdropFilter:"blur(3px)",opacity:r?1:0,transition:`opacity 0.25s ${ft}`,fontFamily:t.font.sans},children:e.jsxs("div",{onClick:u=>u.stopPropagation(),style:{width:500,maxWidth:"calc(100vw - 40px)",background:t.color.surface,border:`1px solid ${t.color.border}`,borderRadius:14,boxShadow:"0 24px 60px rgba(0, 0, 0, 0.45)",padding:"20px 22px 18px",opacity:r?1:0,transform:r?"none":"translateY(10px) scale(0.97)",transition:`opacity 0.3s ${ft}, transform 0.3s ${ft}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12},children:[e.jsx(ar,{state:c}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{color:t.color.fg,fontSize:"1.02em",fontWeight:700},children:f}),e.jsx("button",{onClick:o,"aria-label":"关闭",style:{marginLeft:"auto",width:26,height:26,borderRadius:7,border:"none",background:"transparent",color:t.color.muted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"inherit",flexShrink:0,transition:"background 0.15s, color 0.15s"},onMouseEnter:u=>{u.currentTarget.style.background=t.color.bg,u.currentTarget.style.color=t.color.fg},onMouseLeave:u=>{u.currentTarget.style.background="transparent",u.currentTarget.style.color=t.color.muted},children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsx("div",{style:{color:t.color.muted,fontSize:"0.82em",marginTop:2},children:h}),e.jsx("div",{style:{height:2,background:`linear-gradient(90deg, ${x}, transparent)`,borderRadius:2,marginTop:10,opacity:.5}})]})]}),g.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,marginTop:14,maxHeight:240,overflowY:"auto"},children:g.map(u=>e.jsx(dr,{result:u},u.file))}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:18},children:e.jsx("button",{onClick:o,style:{height:32,padding:"0 18px",borderRadius:8,border:"none",background:`linear-gradient(135deg, ${t.color.primary}, #6366f1)`,color:"#fff",fontSize:"0.84em",fontWeight:600,cursor:"pointer",fontFamily:"inherit",transition:"filter 0.15s"},onMouseEnter:u=>{u.currentTarget.style.filter="brightness(1.1)"},onMouseLeave:u=>{u.currentTarget.style.filter="none"},children:"关闭"})})]})})}function ur(n){const{activeId:o,hasEdits:t}=n,[r,s]=a.useState([]),[i,l]=a.useState(void 0),[c,p]=a.useState(!1),[g,x]=a.useState(420),[f,h]=a.useState(new Set),[u,I]=a.useState(void 0),[w,b]=a.useState(void 0),[m,j]=a.useState(void 0),[k,B]=a.useState(!1),H="vagus.rightPanel.v1",P="vagus.rightPanel.review.v1",z=y=>{try{const T=localStorage.getItem(P),L=(T?JSON.parse(T):{})[y];return{turnId:L==null?void 0:L.turnId,selected:L==null?void 0:L.selected,open:L==null?void 0:L.open}}catch{return{}}},F=(y,T,$,L)=>{try{const te=localStorage.getItem(P),re=te?JSON.parse(te):{};re[y]={turnId:T,selected:$,open:L},localStorage.setItem(P,JSON.stringify(re))}catch{}},M=y=>{try{const T=localStorage.getItem(H),L=(T?JSON.parse(T):{})[y];return{collapsed:(L==null?void 0:L.collapsed)===!0,width:(L==null?void 0:L.width)??420,activeTab:L==null?void 0:L.activeTab,diffClosed:(L==null?void 0:L.diffClosed)===!0,has:L!==void 0}}catch{return{collapsed:!0,width:420,has:!1}}},O=(y,T)=>{try{const $=localStorage.getItem(H),L=$?JSON.parse($):{};L[y]=T,localStorage.setItem(H,JSON.stringify(L))}catch{}},_="vagus.rightPanel.handled.v2",Z=y=>{try{const T=localStorage.getItem(_),$=T?JSON.parse(T):{};return new Set(Array.isArray($[y])?$[y]:[])}catch{return new Set}},G=(y,T)=>{try{const $=localStorage.getItem(_),L=$?JSON.parse($):{};L[y]=[...T],localStorage.setItem(_,JSON.stringify(L))}catch{}};a.useLayoutEffect(()=>{if(!o)return;const y=M(o);x(y.width),p(y.has?y.collapsed:!0),y.activeTab!==void 0&&l(y.activeTab),B(y.diffClosed===!0);const T=z(o);b(T.turnId||void 0),j(Array.isArray(T.open)?T.open:void 0),T.selected&&I(T.selected),h(Z(o))},[o]),a.useEffect(()=>{o&&O(o,{collapsed:c,width:g,activeTab:i,diffClosed:k})},[c,g,i,k,o]),a.useEffect(()=>{o&&G(o,f)},[f,o]),a.useEffect(()=>{t?k||(s(y=>y.some(T=>T.id==="diff")?y:[...y,Nt]),l(y=>y??"diff")):(s(y=>y.some(T=>T.id==="diff")?y.filter(T=>T.id!=="diff"):y),l(y=>y==="diff"?void 0:y))},[t,k]);const Q=a.useCallback((y,T)=>{var L;B(!1),I(y);const $=(L=T==null?void 0:T[0])==null?void 0:L.turnToolCallId;b($),j([y]),o&&F(o,$,y,[y]),p(!1),s(te=>te.some(re=>re.id==="diff")?te:[...te,Nt]),l("diff")},[o]),K=a.useCallback(y=>{y==="diff"&&B(!0),s(T=>T.filter($=>$.id!==y)),l(T=>T===y?void 0:T)},[]),ee=a.useCallback(y=>{j(y),o&&w&&F(o,w,u??(y==null?void 0:y[0])??"",y??[])},[o,w,u]);return{rightTabs:r,rightTabId:i,rightCollapsed:c,rightPanelWidth:g,handledFiles:f,diffSelection:u,reviewTurnId:w,reviewOpen:m,setRightTabs:s,setRightTabId:l,setRightCollapsed:p,setRightPanelWidth:x,setHandledFiles:h,setDiffSelection:I,setReviewOpen:ee,openFileDiff:Q,closeRightTab:K}}function fr(n){const{client:o,registerOnEvent:t,dispatch:r,nextId:s,activeId:i,autoscroll:l,followAnswerRef:c,effects:p}=n,g=()=>{c!=null&&c.current&&(c.current=!1,l.scrollToBottom(!0))},x=a.useRef({sessionId:"",text:"",raf:null}),f=()=>{const w=x.current;if(!w.text)return;const b=w.text,m=w.sessionId;w.text="",w.raf=null,r({type:"applyEvent",sessionId:m,id:s(),event:{type:"session.message",sessionId:m,kind:"text_delta",text:b}}),g(),l.followStream()},h=(w,b)=>{const m=x.current;m.sessionId!==w&&(m.raf!==null&&cancelAnimationFrame(m.raf),m.text="",m.sessionId=w),m.text+=b,m.raf===null&&(m.raf=requestAnimationFrame(f))},u=()=>{const w=x.current;w.raf!==null&&(cancelAnimationFrame(w.raf),w.raf=null),w.text&&f()};t(w=>{var j,k,B;const b=o;if(!b)return;const m=i!==void 0&&w.sessionId===i;switch(w.type){case"session.created":p.fetchSessionInfo(b,w.sessionId,{updateActivePath:!1}),p.refreshHistory(b);return;case"session.turn":w.kind==="end"&&u(),r({type:"applyEvent",sessionId:w.sessionId,id:s(),event:w}),m&&w.kind==="end"&&(p.fetchSessionInfo(b,w.sessionId),p.refreshHistory(b),b.request("usage.stats",{}).then(H=>p.setUsageStats(H)).catch(()=>{}));return;case"session.message":if(w.kind==="user_queued"&&/<skill\s+name="/.test(w.text)){const H=(j=/<skill\s+name="([^"]+)"/.exec(w.text))==null?void 0:j[1],P=(k=p.shiftSkillText)==null?void 0:k.call(p);r({type:"userMessage",sessionId:w.sessionId,id:s(),text:P??w.text,...H?{skillTag:H}:{}})}else w.kind==="text_delta"?h(w.sessionId,w.text):w.kind==="text_done"?(u(),r({type:"applyEvent",sessionId:w.sessionId,id:s(),event:w})):r({type:"applyEvent",sessionId:w.sessionId,id:s(),event:w});m&&(w.kind==="user_queued"||w.kind==="error")&&l.scrollToBottom(!1);return;case"session.thinking":r({type:"applyEvent",sessionId:w.sessionId,id:s(),event:w}),m&&w.kind==="delta"&&(g(),l.followStream());return;case"session.tool_call":case"session.tool_result":r({type:"applyEvent",sessionId:w.sessionId,id:s(),event:w}),m&&w.type==="session.tool_call"&&p.fetchSessionInfo(b,w.sessionId);return;case"session.queue_update":r({type:"applyEvent",sessionId:w.sessionId,id:s(),event:w});return;default:w.type==="ui.request"&&((B=p.onUiRequest)==null||B.call(p,w));return}})}function hr(n){const[o,t]=a.useState([]),r=a.useCallback(async()=>{if(n)try{const c=await n.request("models.config");Array.isArray(c)&&t(c)}catch{}},[n]),s=a.useCallback(async c=>{if(n)try{await n.request("models.save",{providers:c}),r()}catch{}},[n,r]),i=a.useCallback(async c=>{if(!n)return{ok:!1};try{return await n.request("models.test",c)}catch{return{ok:!1}}},[n]),l=a.useMemo(()=>o.filter(c=>c.enabled!==!1),[o]);return{modelsConfig:o,enabledProviders:l,refreshModels:r,saveModels:s,testModel:i}}const pr=a.lazy(()=>Yt(()=>import("./settings-CkJ4eBhw.js").then(n=>n.i),__vite__mapDeps([0,1])).then(n=>({default:n.SettingsView}))),gr=a.lazy(()=>Yt(()=>import("./settings-CkJ4eBhw.js").then(n=>n.i),__vite__mapDeps([0,1])).then(n=>({default:n.PluginsView}))),xr=n=>{navigator.clipboard.writeText(n).catch(()=>{})},We=[{type:"builtin",name:"compact",description:"压缩上下文,摘要历史对话,腾出上下文空间"},{type:"builtin",name:"reload",description:"重新加载扩展、技能、提示词(装包后让 agent 感知新能力)"}];function mr({transport:n}){var Ft,Dt;const o=N(),{client:t,registerOnEvent:r}=Jo(n),{state:s,dispatch:i,active:l}=Vo(),c=Uo(l.items.length,s.activeId),p=Ko(),g=l.items.some(d=>d.kind==="tool"&&d.diff!==void 0),[x,f]=a.useState(null),{rightTabs:h,rightTabId:u,rightCollapsed:I,rightPanelWidth:w,diffSelection:b,reviewTurnId:m,reviewOpen:j,setRightTabs:k,setRightTabId:B,setRightCollapsed:H,setRightPanelWidth:P,setReviewOpen:z,openFileDiff:F,closeRightTab:M}=ur({activeId:s.activeId,hasEdits:g}),O=a.useRef(0),_=()=>++O.current,Z=a.useRef(0),G=a.useRef(0),Q=a.useRef(void 0),K=d=>{Z.current++;const v=Z.current;Q.current!==void 0&&clearTimeout(Q.current),Q.current=setTimeout(()=>{Q.current=void 0,t&&jt(t,d,v)},80)},[ee,y]=a.useState([]),[T,$]=a.useState(),[L,te]=a.useState(!1),[re,je]=a.useState(!1),[Ee,Te]=a.useState("appearance"),[S,A]=a.useState(null),[V,se]=a.useState(new Set),[U,ae]=a.useState(null),[me,q]=a.useState({}),Le=me[s.activeId??""]??me.global??[],[ye,ce]=a.useState(null),ie=a.useRef(null),[Ye,rt]=a.useState({}),[ze,$e]=a.useState({}),he=a.useRef([]),Re=a.useMemo(()=>{const d={};for(const[v,E]of Object.entries(ze))E.lines.length>0&&(!E.sessionId||E.sessionId===s.activeId)&&(d[v]={lines:E.lines});return d},[ze,s.activeId]);a.useEffect(()=>{Object.keys(Re).length>0?(k(v=>v.some(E=>E.id==="widget")?v:[...v,ir]),B(v=>v??"widget")):(k(v=>v.some(E=>E.id==="widget")?v.filter(E=>E.id!=="widget"):v),B(v=>v==="widget"?void 0:v))},[Re]);const[le,Se]=a.useState(),[Xe,Ae]=a.useState(!1),[He,C]=a.useState(We),[W,Y]=a.useState(0),oe=a.useRef(!1);a.useEffect(()=>{if(L||re){oe.current=!0;return}oe.current&&(oe.current=!1,Y(d=>d+1))},[L,re]);const[ue,be]=a.useState(!1),[ln,an]=a.useState("ask"),[ke,st]=a.useState(void 0),[Je,mt]=a.useState(!1),[dn,Ge]=a.useState(!1),[yt,bt]=a.useState(null),[kt,vt]=a.useState(!1),Pe=a.useRef(new Map),it="vagus.lastSession",wt=a.useRef(!1),Oe=hr(t),cn=a.useCallback((d,v,E,R)=>{ae({title:d,message:v,confirmLabel:E,onConfirm:R})},[]),{modelsConfig:un,enabledProviders:_e}=Oe;a.useEffect(()=>{if(!s.activeId&&!ke&&_e.length>0&&_e[0].models.length>0){const d=_e[0];st({providerId:d.id,modelId:d.models[0].id})}},[s.activeId,ke,_e]);const de=a.useCallback(async d=>{try{const v=await d.request("session.history",{});if(Array.isArray(v)){const E=v;y(E);for(const R of E)R.id&&R.path&&Pe.current.set(R.id,R.path)}}catch{}},[]),ve=Go(t,de,cn,d=>{T===d&&(i({type:"activate",sessionId:void 0}),$(void 0))}),{archivedProjects:fn}=ve;a.useEffect(()=>{if(!Je){Ge(!1);return}const d=window.setTimeout(()=>Ge(!0),300);return()=>window.clearTimeout(d)},[Je]);const qe=(d,v,E)=>{d.request("session.info",{sessionId:v}).then(R=>{var X;const D=R;D!=null&&D.sessionFile&&(Pe.current.set(v,D.sessionFile),(E==null?void 0:E.updateActivePath)!==!1&&$(D.sessionFile)),typeof((X=D==null?void 0:D.contextUsage)==null?void 0:X.tokens)=="number"&&bt(null),i({type:"setInfo",sessionId:v,info:D,thinkingLevel:D==null?void 0:D.thinkingLevel})}).catch(()=>{})},jt=async(d,v,E)=>{const R=E??++Z.current,D=new Map;for(const J of ee)D.set(J.path,J.id);const X=D.get(v),Fe=X?s.slots[X]:void 0;if(X&&Fe&&Fe.items.length>0){$(v),c.resetSnap(),i({type:"activate",sessionId:X}),qe(d,X),de(d),Y(J=>J+1);return}G.current++,mt(!0),i({type:"clearActive"}),Ge(!0);try{$(v);const J=await d.request("session.open",{sessionFile:v,limit:200}),De=J.sessionId;if(R!==Z.current){const Qe=s.slots[De];(!Qe||Qe.items.length===0)&&i({type:"loadHistory",sessionId:De,id:_(),messages:J.messages,hasMore:J.hasMore,total:J.total,startIndex:J.startIndex});return}const Wt=s.slots[De];(!Wt||Wt.items.length===0)&&i({type:"loadHistory",sessionId:De,id:_(),messages:J.messages,hasMore:J.hasMore,total:J.total,startIndex:J.startIndex}),c.resetSnap(),i({type:"activate",sessionId:De}),J.sessionFile&&$(J.sessionFile),qe(d,De),de(d),Y(Qe=>Qe+1)}catch(J){i({type:"localSystem",id:_(),text:`无法打开会话: ${J instanceof Error?J.message:String(J)}`})}finally{G.current--,G.current<=0&&(G.current=0,mt(!1),Ge(!1))}},lt=a.useRef(!1),[hn,St]=a.useState(!1),pn=a.useCallback(async()=>{if(!t||!s.activeId||lt.current)return;const d=s.activeId,v=s.slots[d];if(!(v!=null&&v.historyHasMore)||!v.historyStartIndex||v.items.length===0)return;lt.current=!0,St(!0);const E=Pe.current.get(d)??T;try{const R=await t.request("session.page",{sessionFile:E,limit:200,beforeIndex:v.historyStartIndex});i({type:"prependHistory",sessionId:d,id:_(),messages:R.messages,hasMore:R.hasMore,total:R.total,startIndex:R.startIndex})}catch{}finally{lt.current=!1,St(!1)}},[t,s.activeId,s.slots,T]),It=a.useRef(!0);a.useEffect(()=>{if(It.current){It.current=!1;return}try{T?localStorage.setItem(it,T):localStorage.removeItem(it)}catch{}},[T]),a.useEffect(()=>{if(!t||wt.current)return;wt.current=!0;let d;try{d=localStorage.getItem(it)??void 0}catch{d=void 0}d&&(async()=>{try{await jt(t,d)}catch{}})()},[t]);const gn=d=>{switch(d){case"compact":return Ln(),!0;case"reload":return ce({text:"正在重新加载扩展与技能…",type:"info"}),ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>ce(null),2500),t&&s.activeId&&t.request("session.reload",{sessionId:s.activeId}).then(()=>{at(),ce({text:"✅ 已重新加载扩展与技能",type:"info"}),ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>ce(null),2500)}).catch(v=>{ce({text:`reload 失败:${v instanceof Error?v.message:String(v)}`,type:"error"}),ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>ce(null),4e3)}),!0;default:return!1}},Ct=(d,v)=>{d.trim().startsWith("/skill:")&&he.current.push(d.trim()),t&&(async()=>{var E;try{const R=d.split(/\s+/)[0]??"";if(R.startsWith("/")&&gn(R.slice(1)))return;let D=s.activeId;if(!D||D===Be){if(D=(await t.request("session.create",{cwd:le??void 0})).sessionId,(E=s.slots[Be])!=null&&E.items.length&&i({type:"moveWelcome",sessionId:D}),i({type:"activate",sessionId:D}),qe(t,D),ke){try{await t.request("session.model.set",{sessionId:D,providerId:ke.providerId,modelId:ke.modelId})}catch{}st(void 0)}de(t)}await t.request("session.prompt",{sessionId:D,text:d,images:v}),de(t)}catch(R){i({type:"forceIdle"}),i({type:"localSystem",id:_(),text:`error: ${R instanceof Error?R.message:String(R)}`})}})()},xn=d=>{Ct(d,[])},mn=a.useCallback(async d=>{if(!(!t||!s.activeId||d.length===0))try{const v=await t.request("tool.revertBatch",{sessionId:s.activeId,files:d}),E=((v==null?void 0:v.results)??[]).map(R=>({file:R.file,toolCallId:R.file,ok:R.ok,error:R.error}));f({results:E})}catch(v){console.log("[frontend revertBatch catch]",String(v)),f({results:d.map(E=>({file:E,toolCallId:E,ok:!1,error:v instanceof Error?v.message:String(v)}))})}},[t,s.activeId,f]),yn=()=>{c.resetSnap(),i({type:"activate",sessionId:void 0}),$(void 0),Y(d=>d+1)},bn=async(d,v)=>{if(t)try{await t.request("session.renameFile",{sessionFile:d,name:v}),de(t)}catch{}},kn=async d=>{if(t)try{const v=ee.find(E=>E.path===d);await t.request("session.delete",{sessionFile:d,sessionId:v==null?void 0:v.id}),T===d&&(i({type:"activate",sessionId:void 0}),$(void 0)),de(t)}catch{}},vn=async d=>{if(t)try{await t.request("session.archive",{sessionFile:d}),T===d&&(i({type:"activate",sessionId:void 0}),$(void 0)),de(t),ve.syncArchived(t)}catch{}},wn=async d=>{if(t)try{await t.request("session.restore",{sessionFile:d}),de(t),ve.syncArchived(t)}catch{}},jn=async d=>{if(t)try{const v=V.has(d);await t.request("session.pin",{sessionFile:d,pinned:!v}),se(E=>{const R=new Set(E);return v?R.delete(d):R.add(d),R}),de(t)}catch{}},Sn=a.useMemo(()=>{const d=new Set,v=[];for(const E of ee){if(d.has(E.cwd))continue;d.add(E.cwd);const R=E.cwd.replace(/\\/g,"/").split("/").filter(Boolean);v.push({id:E.cwd,name:R[R.length-1]??E.cwd,available:!0})}return v},[ee]),In=a.useMemo(()=>{const d=new Set;for(const[v,E]of Object.entries(s.slots))if(E.busy){const R=Pe.current.get(v);R&&d.add(R)}return d},[s.slots]),Cn=((Ft=l.info)==null?void 0:Ft.model)??(ke==null?void 0:ke.modelId),Mn=d=>{if(d.method==="widgetLines"){$e(E=>{const R=d.widgetKey??"";if(!R)return E;const D={...E};if(!d.lines||d.lines.length===0)delete D[R];else{const X=Array.isArray(d.lines)?d.lines:String(d.lines??"").split(`
18
+ `);D[R]={lines:X,placement:d.placement??"aboveEditor",sessionId:d.sessionId}}return D});return}if(d.method==="setStatus"){rt(E=>{const R=d.statusKey??"";if(!R)return E;const D={...E};return d.statusText==null?delete D[R]:D[R]=d.statusText,D});return}if(d.method==="notify"){ce({text:d.message??d.title??"",type:d.notifyType??"info"}),ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>ce(null),3500);return}if(!t)return;const v=d.sessionId??"global";q(E=>({...E,[v]:[...E[v]??[],{event:d,sessionId:d.sessionId,status:"pending"}]}))},Mt=a.useRef(!1),En=(d,v)=>{const E=d.sessionId??"global";q(R=>({...R,[E]:(R[E]??[]).map(D=>D.event.id===d.event.id?{...D,status:"answered",result:v}:D)})),Mt.current=!0,t==null||t.request("ui.respond",{id:d.event.id,...v}).catch(()=>{})};fr({client:t,registerOnEvent:r,followAnswerRef:Mt,dispatch:i,nextId:_,activeId:s.activeId,autoscroll:c,effects:{fetchSessionInfo:qe,refreshHistory:de,setUsageStats:A,onUiRequest:Mn,shiftSkillText:()=>he.current.shift()}}),a.useEffect(()=>{t&&(t.request("ping").then(()=>{}).catch(()=>{}),Oe.refreshModels(),t.request("usage.stats",{}).then(d=>A(d)).catch(()=>{}),t.request("session.pins").then(d=>{Array.isArray(d)&&se(new Set(d))}).catch(()=>{}),t.request("ui.widgets",{}).then(d=>{const v=d;if(v){const E={};for(const[R,D]of Object.entries(v))D!=null&&D.lines&&D.lines.length>0&&(E[R]={lines:D.lines,placement:D.placement==="belowEditor"?"belowEditor":"aboveEditor",sessionId:D.sessionId});$e(E)}}).catch(()=>{}),t.request("ui.pending",{}).then(d=>{const v=d;if(v&&v.length>0){const E={};for(const R of v){const D=R.request,X=D.sessionId??"global";E[X]=[...E[X]??[],{event:D,sessionId:D.sessionId,status:"pending"}]}q(E)}}).catch(()=>{}),t.request("ui.history",{}).then(d=>{const v=d;v&&q(E=>{const R={...E};for(const[D,X]of Object.entries(v)){const Fe=X.map(J=>({event:J.request,sessionId:J.request.sessionId,status:"answered",result:J.result}));R[D]=[...R[D]??[],...Fe]}return R})}).catch(()=>{}),ve.syncArchived(t),de(t))},[t]),a.useEffect(()=>{const d=v=>{if(v.target.closest("textarea, input, button, [role='menu'], [role='menuitem'], [contenteditable]"))return;const R=document.activeElement;R instanceof HTMLElement&&R.blur()};return document.addEventListener("mousedown",d,!0),()=>document.removeEventListener("mousedown",d,!0)},[]);const Tn=d=>{Se(d),localStorage.setItem("vagus.activeProject",d)};a.useEffect(()=>{const d=localStorage.getItem("vagus.activeProject");d&&Se(d)},[]);const Rn=async d=>{if(Ae(!1),!(!d||!t)){Se(d),localStorage.setItem("vagus.activeProject",d);try{const v=await t.request("session.create",{cwd:d});i({type:"activate",sessionId:v.sessionId}),de(t),Y(E=>E+1)}catch{}}},Fn=async(d,v)=>{if(st({providerId:d,modelId:v}),s.activeId&&i({type:"setInfo",sessionId:s.activeId,info:l.info?{...l.info,model:v,activeProvider:d}:void 0}),!(!t||!s.activeId))try{await t.request("session.model.set",{sessionId:s.activeId,providerId:d,modelId:v})}catch{}},Dn=()=>{!t||!s.activeId||t.request("session.abort",{sessionId:s.activeId}).catch(()=>{})},Wn=()=>{!t||!s.activeId||t.request("session.abortCompaction",{sessionId:s.activeId}).catch(()=>{})},Bn=async d=>{if(s.activeId&&i({type:"setInfo",sessionId:s.activeId,info:l.info,thinkingLevel:d}),!(!t||!s.activeId))try{await t.request("session.thinking.set",{sessionId:s.activeId,level:d})}catch{}},Ln=async()=>{if(!t||!s.activeId)return;const d=s.activeId,v=_();vt(!0),i({type:"localSystem",id:v,text:"正在压缩上下文…"});try{const E=await t.request("session.compact",{sessionId:d});i({type:"removeMessage",id:v});const R=E==null?void 0:E.estimatedTokensAfter,D=typeof R=="number"&&R>0?`${(R/1e3).toFixed(1)}K`:"";bt(typeof R=="number"?R:null),i({type:"localSystem",id:_(),text:`◌ 前文已摘要${D?` · 剩余 ${D} 上下文`:""}`}),qe(t,d),t.request("usage.stats",{}).then(X=>A(X)).catch(()=>{})}catch(E){i({type:"removeMessage",id:v});const R=E instanceof Error?E.message:String(E),D=R.includes("Nothing to compact")||R.includes("Already compacted")?"上下文还没大到需要压缩(会话内容太少,或刚刚已经压缩过)":`压缩失败:${R}`;i({type:"localSystem",id:_(),text:D})}finally{vt(!1)}},zn=async()=>t?await t.request("project.roots",{}):{places:[],drives:[]},$n=async d=>t?await t.request("project.listDir",{dir:d}):{path:d,entries:[]},Et=async()=>{if(!t)return We;try{const d=await t.request("commands.list",{sessionId:s.activeId??void 0});return[...We,...(d.extensions??[]).map(v=>({type:"extension",name:v.name,description:v.description??""})),...(d.templates??[]).map(v=>({type:"template",name:v.name,description:v.description??""})),...(d.skills??[]).map(v=>({type:"skill",name:`skill:${v.name}`,description:v.description??""}))]}catch{return We}};a.useEffect(()=>{t&&Et().then(C).catch(()=>C(We))},[t,s.activeId]);const at=()=>{Et().then(C).catch(()=>C(We))},An=d=>{be(!1),d&&p.setInput(v=>`${v}${d} `)},Tt={value:p.input,onChange:p.setInput,onSubmit:()=>p.submit((d,v)=>{c.forceScrollToBottom(!1,750),Ct(d,v)}),usage:l.info?yt!==null?{...l.info,contextUsage:{tokens:yt,contextWindow:((Dt=l.info.contextUsage)==null?void 0:Dt.contextWindow)??1e6,percent:null}}:l.info:null,providers:_e,onSwitchModel:(d,v)=>void Fn(d,v),onSetThinking:d=>void Bn(d),thinkingLevel:l.thinkingLevel??"low",permissionMode:ln,onTogglePermission:()=>an(d=>d==="ask"?"auto":"ask"),attachments:p.attachments,fileAttachments:p.fileAttachments,onAttach:p.attachFiles,onRemoveAttachment:p.removeAttachment,busy:l.busy||kt,onStop:kt?Wn:Dn,hasPendingDialog:Le.some(d=>d.status==="pending"),selectedModel:Cn,onCommand:()=>{at(),be(!0)},onRefreshCommands:at,commands:He,onPickCommand:()=>{},focusSignal:W,queuedMessages:l.queued},Rt={sessions:ee,activePath:T,onNewSession:yn,onOpenSession:K,onOpenSettings:()=>te(!0),onOpenPlugins:()=>je(!0),onRenameSession:bn,onDeleteSession:kn,onArchiveSession:vn,onRestoreSession:wn,onDeleteArchivedSession:ve.deleteArchivedSession,onTogglePin:jn,pinnedSessions:V,archivedProjects:fn,onArchiveProject:ve.archiveProject,onUnarchiveProject:ve.unarchiveProject,onDeleteProject:d=>ve.deleteProject(d,ee,T),busyPaths:In,pendingDialogPaths:new Set(Object.entries(me).filter(([,d])=>d.some(v=>v.status==="pending")).map(([d])=>Pe.current.get(d)).filter(d=>!!d))},{uiFontSize:Hn}=Kt(),Pn=!s.activeId&&!L&&!Je,ge=ee.find(d=>d.path===T),On=(ge==null?void 0:ge.name)??(ge==null?void 0:ge.firstMessage)??"",_n=ge==null?void 0:ge.cwd;return e.jsxs("div",{style:{height:"100dvh",margin:0,display:"flex",overflow:"hidden",background:o.color.bg,color:o.color.fg,fontFamily:o.font.sans,fontSize:Hn},children:[L?e.jsx(a.Suspense,{fallback:null,children:e.jsx(pr,{providers:un,usageStats:S,onClose:()=>te(!1),onSave:Oe.saveModels,onRefresh:Oe.refreshModels,onTest:Oe.testModel,cat:Ee,onCatChange:Te,projectCwd:le,request:(d,v)=>t.request(d,v),onProbe:async d=>t?await t.request("models.probe",d):{ok:!1}})}):re?e.jsx(a.Suspense,{fallback:null,children:e.jsx(gr,{request:(d,v)=>t.request(d,v),onClose:()=>je(!1),t:o})}):Pn?e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"row",minWidth:0},children:[e.jsx(zt,{...Rt}),e.jsx(tr,{activeProject:le,projects:Sn,onSelectProject:Tn,onNewProject:()=>Ae(!0),inputCard:Tt})]}):e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"row",minWidth:0},children:[e.jsx(zt,{...Rt}),e.jsx(er,{items:l.items,busy:l.busy,turnStartTs:l.turnStart,sessionLoading:Je,showLoading:dn,autoscroll:c,sessionName:On,sessionCwd:_n,activeId:s.activeId,onToggleCard:d=>i({type:"toggleCollapse",id:d}),copyMessage:xr,editSubmit:xn,inputCard:Tt,uiCards:Le,onUiCardRespond:En,onLoadMore:pn,loadingMore:hn,onOpenFile:F,onRevertAll:d=>void mn(d)}),e.jsx(or,{tabs:h,activeId:u,collapsed:I,onActivate:d=>B(d),onClose:d=>M(d),onToggleCollapse:()=>H(d=>!d),width:w,onWidthChange:P,render:d=>d.id==="diff"?e.jsx(rr,{items:l.items,selected:b,turnId:m,expandedFiles:j,onOpenChange:v=>z(v)},`${s.activeId}-${m??"none"}`):d.id==="widget"?e.jsx(lr,{widgets:Re}):null})]}),Xe&&e.jsx(lo,{listDir:$n,roots:zn,onPick:d=>void Rn(d)}),ue&&e.jsx(no,{commands:He,onPick:An}),U&&e.jsx(nr,{state:U,onClose:()=>ae(null)}),(()=>{const d=Object.entries(Ye),v=d.length>0;let E=window.innerHeight;try{const X=document.querySelector(".vagus-input-card");X&&(E=X.getBoundingClientRect().top)}catch{}const R=Math.max(12,window.innerHeight-E+12),D=R+(Object.keys(Ye).length>0?40:0)+12;return e.jsxs(e.Fragment,{children:[v&&e.jsx("div",{style:{position:"fixed",bottom:R,left:"50%",transform:"translateX(-50%)",zIndex:1e4,display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center"},children:d.map(([X,Fe])=>e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,padding:"5px 12px",borderRadius:999,background:o.color.surface,border:`1px solid ${o.color.border}`,boxShadow:"0 6px 20px rgba(0,0,0,0.18)",fontSize:"0.82em",color:o.color.fg},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",flexShrink:0,background:o.color.primary}}),e.jsx("span",{style:{color:o.color.muted,fontWeight:600},children:X}),e.jsx("span",{children:Fe})]},X))}),ye&&e.jsxs("div",{style:{position:"fixed",bottom:D,left:"50%",transform:"translateX(-50%)",zIndex:10001,display:"flex",alignItems:"flex-start",gap:9,padding:"10px 16px",borderRadius:12,background:o.color.surface,border:`1px solid ${o.color.border}`,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",fontSize:"0.88em",color:o.color.fg,animation:"vagus-toast-in 0.2s ease",maxWidth:"min(90vw, 560px)"},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",flexShrink:0,marginTop:5,background:ye.type==="error"?"#E5484D":ye.type==="warning"?"#B7791F":o.color.primary}}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:ye.text})]})]})})(),x&&e.jsx(cr,{report:x,onClose:()=>f(null)})]})}function yr(){return e.jsx(Jn,{children:e.jsx(Gn,{children:e.jsx(mr,{})})})}const sn=document.getElementById("root");if(!sn)throw new Error("missing #root element — index.html is malformed");Vn.createRoot(sn).render(e.jsx(yr,{}));