@versot/vaguspi 0.1.5 → 0.1.7

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,19 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-B-1r6vjG.js","assets/vendor-D5Ls3_dM.js"])))=>i.map(i=>d[i]);
2
+ var ro=Object.defineProperty;var so=(n,o,t)=>o in n?ro(n,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[o]=t;var Be=(n,o,t)=>so(n,typeof o!="symbol"?o+"":o,t);import{j as e,a as K,r as a,t as T,u as tt,R as nn,d as on,L as io,D as lo,h as ao,e as rn,J as co,I as uo,b as fo,T as ho,A as go,f as po,g as xo,i as mo}from"./vendor-D5Ls3_dM.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 yo="modulepreload",bo=function(n){return"/"+n},Vt={},sn=function(o,t,r){let s=Promise.resolve();if(t&&t.length>0){let l=function(u){return Promise.all(u.map(h=>Promise.resolve(h).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),f=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));s=l(t.map(u=>{if(u=bo(u),u in Vt)return;Vt[u]=!0;const h=u.endsWith(".css"),m=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${m}`))return;const x=document.createElement("link");if(x.rel=h?"stylesheet":yo,h||(x.as="script"),x.crossOrigin="",x.href=u,f&&x.setAttribute("nonce",f),document.head.appendChild(x),h)return new Promise((g,v)=>{x.addEventListener("load",g),x.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${u}`)))})}))}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)})},ue="background 0.15s, color 0.15s";function ln(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`}const ko=34;function an(n){const o=n.replace(/\\/g,"/").split("/").filter(Boolean);return o[o.length-1]??n}function jt(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 St({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 vo(n){const o=K(),[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),onContextMenu:i=>{n.onSectionContextMenu&&(i.preventDefault(),n.onSectionContextMenu(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:ue},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:T("已归档")}),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"})})]}),jt(t,e.jsx("div",{style:{paddingLeft:6},children:s.map(({cwd:i,dirKey:l,sessions:c})=>{const f=!n.collapsed.has(`arch:${l}`);return e.jsxs("div",{style:{marginBottom:1},children:[e.jsxs("div",{onClick:()=>n.onToggleProject(`arch:${l}`),onContextMenu:u=>n.onProjectContextMenu(u,i,l),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:ue},onMouseEnter:u=>{u.currentTarget.style.background=o.color.sidebarHover,u.currentTarget.style.opacity="1"},onMouseLeave:u=>{u.currentTarget.style.background="transparent",u.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:an(i)}),e.jsx("span",{style:{fontSize:"0.75em",color:o.color.muted,flexShrink:0},children:c.length}),e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0,transform:f?"rotate(0)":"rotate(-90deg)",transition:"transform 0.15s ease"},children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]}),jt(f,e.jsx("div",{style:{paddingLeft:30},children:c.map(u=>e.jsxs("div",{onClick:()=>n.onOpenSession(u.path),onContextMenu:h=>n.onSessionContextMenu(h,u,!0),onMouseEnter:h=>h.currentTarget.style.background=o.color.sidebarHover,onMouseLeave:h=>h.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:ue},children:[e.jsx(St,{}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1},children:(u.name??u.firstMessage.slice(0,40))||"(空会话)"}),n.busyPaths.has(u.path)&&e.jsx("span",{title:T("工作中"),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:ln(u.modified)})]},u.id))}))]},l)})}))]})}const We="#6366f1",Ge="#8b5cf6",Ut="0 0 0 2px rgba(99,102,241,0.4)";function mt({text:n,style:o}){const t=a.useRef(null),[r,s]=a.useState(!1),i=a.useRef(0),l=32;return e.jsx("span",{ref:t,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0,...o},onMouseEnter:()=>{requestAnimationFrame(()=>{const f=t.current,u=f==null?void 0:f.firstChild;if(!f||!u)return;const h=u.offsetWidth;i.current=h,h-f.clientWidth>2&&s(!0)})},onMouseLeave:()=>s(!1),children:r?e.jsxs("span",{style:{display:"inline-block",whiteSpace:"nowrap",animation:`vagus-marquee ${((i.current+l)/30).toFixed(2)}s linear infinite`},children:[e.jsx("span",{style:{paddingRight:l},children:n}),e.jsx("span",{style:{paddingRight:l},children:n})]}):e.jsx("span",{style:{display:"inline-block",whiteSpace:"nowrap"},children:n})})}function Kt({sessions:n,activePath:o,onNewSession:t,onOpenSession:r,onOpenSettings:s,onOpenPlugins:i,onRenameSession:l,onDeleteSession:c,onArchiveSession:f,onClearAllArchived:u,onCollapsedChange:h,onRestoreSession:m,onDeleteArchivedSession:x,onTogglePin:g,pinnedSessions:v=new Set,archivedProjects:j=[],onArchiveProject:$,onUnarchiveProject:p,onDeleteProject:S,busyPaths:M=new Set,pendingDialogPaths:z=new Set}){const I=K(),{theme:P}=tt(),q="vagus.sidebar.collapsedProjects",[X,_]=a.useState(()=>{try{return new Set(JSON.parse(localStorage.getItem(q)??"[]"))}catch{return new Set}}),[R,w]=a.useState(null),[Z,G]=a.useState(),[Q,ie]=a.useState(""),Y=a.useMemo(()=>{const b=new Map;for(const H of n){const A=b.get(H.cwd)??[];A.push(H),b.set(H.cwd,A)}return[...b.entries()].toSorted((H,A)=>A[1][0].modified.localeCompare(H[1][0].modified)).map(([H,A])=>[H,A.toSorted((N,J)=>Number(v.has(J.path))-Number(v.has(N.path))||J.modified.localeCompare(N.modified))])},[n,v]),y=b=>{_(H=>{const A=new Set(H);A.has(b)?A.delete(b):A.add(b);try{localStorage.setItem(q,JSON.stringify([...A]))}catch{}return A})},W=(b,H,A=!1)=>{b.preventDefault(),w({x:b.clientX,y:b.clientY,kind:"session",session:H,archived:A})},O=(b,H)=>{b.preventDefault(),w({x:b.clientX,y:b.clientY,kind:"project",cwd:H})},D=()=>w(null);a.useEffect(()=>{if(!R)return;const b=A=>{A.target.closest("[data-context-menu]")||D()},H=A=>{A.key==="Escape"&&D()};return document.addEventListener("mousedown",b),document.addEventListener("keydown",H),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",H)}},[R]);const oe=b=>{G(b.path),ie(b.name??b.firstMessage.slice(0,40)),w(null)},ee={display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderRadius:7,cursor:"pointer",userSelect:"none",fontSize:"0.89em",color:I.color.fg,transition:"background 0.15s"},Se=b=>{const H=Q.trim();G(void 0),H&&l&&l(b,H)},ye=n.find(b=>b.path===o),Fe=ye==null?void 0:ye.cwd,Ae=280,Ie=48,Ce="vagus.sidebar.collapsed",[ce,Le]=a.useState(()=>{try{return localStorage.getItem(Ce)==="1"}catch{return!1}}),$e=b=>{Le(b),h==null||h(b);try{localStorage.setItem(Ce,b?"1":"0")}catch{}},Me=P==="light"?"rgba(99,102,241,0.10)":"rgba(99,102,241,0.16)",be={display:"flex",alignItems:"center",gap:8,height:40,padding:"0 14px",borderRadius:12,background:`linear-gradient(135deg, ${We}, ${Ge})`,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.jsx("aside",{style:{width:ce?Ie:Ae,flexShrink:0,borderRight:`1px solid ${I.color.border}`,background:I.color.sidebarBg,display:"flex",flexDirection:"column",minHeight:0,overflow:"hidden",position:"relative",transition:"width 0.18s ease"},children:ce?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{flex:"none",height:54,display:"flex",alignItems:"center",justifyContent:"center",borderBottom:`1px solid ${I.color.border}`},children:e.jsx("button",{title:T("展开侧栏"),onClick:()=>$e(!1),style:{display:"flex",alignItems:"center",justifyContent:"center",width:30,height:30,borderRadius:8,border:"none",background:"transparent",color:I.color.muted,cursor:"pointer",transition:ue,outline:"none"},onMouseEnter:b=>{b.currentTarget.style.background=I.color.sidebarHover,b.currentTarget.style.color=I.color.fg},onMouseLeave:b=>{b.currentTarget.style.background="transparent",b.currentTarget.style.color=I.color.muted},children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M9 18l6-6-6-6"})})})}),e.jsxs("div",{style:{flex:"none",padding:"14px 8px 4px",display:"flex",flexDirection:"column",alignItems:"center",gap:8},children:[e.jsx("button",{title:T("新对话"),onClick:t,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:9,border:"none",cursor:"pointer",outline:"none",background:`linear-gradient(135deg, ${We}, ${Ge})`,color:"#fff",boxShadow:"0 2px 10px rgba(99,102,241,0.35)"},children:e.jsx("svg",{width:"15",height:"15",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("button",{title:T("插件"),onClick:i,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:9,border:"none",background:"transparent",color:I.color.muted,cursor:"pointer",transition:ue,outline:"none"},onMouseEnter:b=>{b.currentTarget.style.background=I.color.sidebarHover,b.currentTarget.style.color=I.color.fg},onMouseLeave:b=>{b.currentTarget.style.background="transparent",b.currentTarget.style.color=I.color.muted},children:e.jsxs("svg",{width:"15",height:"15",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("div",{style:{flex:1}}),e.jsx("div",{style:{flex:"none",borderTop:`1px solid ${I.color.border}`,padding:8,display:"flex",justifyContent:"center"},children:e.jsx("button",{title:T("设置"),onClick:s,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:9,border:"none",background:"transparent",color:I.color.muted,cursor:"pointer",transition:ue,outline:"none"},onMouseEnter:b=>{b.currentTarget.style.background=I.color.sidebarHover,b.currentTarget.style.color=I.color.fg},onMouseLeave:b=>{b.currentTarget.style.background="transparent",b.currentTarget.style.color=I.color.muted},children:e.jsxs("svg",{width:"15",height:"15",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.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{flex:"none",height:54,display:"flex",alignItems:"center",gap:8,padding:"0 16px",borderBottom:`1px solid ${I.color.border}`},children:[e.jsx("span",{style:{width:26,height:26,borderRadius:7,background:`linear-gradient(135deg,${We},${Ge})`,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:I.color.fg},children:"vagusPI"}),e.jsx("span",{style:{flex:1}}),e.jsx("button",{title:T("收起侧栏"),onClick:()=>$e(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:8,border:"none",background:"transparent",color:I.color.muted,cursor:"pointer",transition:ue,outline:"none",flexShrink:0},onMouseEnter:b=>{b.currentTarget.style.background=I.color.sidebarHover,b.currentTarget.style.color=I.color.fg},onMouseLeave:b=>{b.currentTarget.style.background="transparent",b.currentTarget.style.color=I.color.muted},children:e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M15 18l-6-6 6-6"})})})]}),e.jsxs("div",{style:{flex:"none",padding:"14px 16px 4px",display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("button",{style:be,onClick:t,onMouseEnter:b=>{b.currentTarget.style.filter="brightness(1.08)",b.currentTarget.style.boxShadow="0 4px 16px rgba(99,102,241,0.45)"},onMouseLeave:b=>{b.currentTarget.style.filter="none",b.currentTarget.style.boxShadow="0 2px 10px rgba(99,102,241,0.35)"},onMouseDown:b=>{b.currentTarget.style.transform="scale(0.98)"},onMouseUp:b=>{b.currentTarget.style.transform="scale(1)"},onFocus:b=>{b.currentTarget.style.boxShadow=`${Ut}, 0 2px 10px rgba(99,102,241,0.35)`},onBlur:b=>{b.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:T("新对话")}),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:b=>{b.currentTarget.style.background=I.color.sidebarHover,b.currentTarget.style.color=I.color.fg},onMouseLeave:b=>{b.currentTarget.style.background="transparent",b.currentTarget.style.color=I.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:I.color.muted,transition:ue,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:T("插件")})]})]}),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:I.color.muted,textTransform:"uppercase",letterSpacing:"0.08em",padding:"12px 10px 6px"},children:T("项目")}),Y.length===0&&e.jsx("div",{style:{fontSize:"0.85em",color:I.color.muted,padding:"8px 10px",lineHeight:1.5},children:T("暂无会话 — 点击“新对话”开始。")}),Y.map(([b,H])=>{const A=!X.has(b),N=Fe===b;return e.jsxs("div",{style:{marginBottom:2},children:[e.jsxs("div",{onClick:()=>y(b),onContextMenu:J=>O(J,b),style:{position:"relative",display:"flex",alignItems:"center",gap:8,padding:"7px 8px",borderRadius:8,cursor:"pointer",userSelect:"none",fontSize:"0.96em",fontWeight:500,color:I.color.fg,background:N?I.color.sidebarHover:"transparent",transition:ue},onMouseEnter:J=>{N||(J.currentTarget.style.background=I.color.sidebarHover)},onMouseLeave:J=>{N||(J.currentTarget.style.background="transparent")},children:[N&&e.jsx("span",{style:{position:"absolute",left:0,top:8,bottom:8,width:3,borderRadius:3,background:`linear-gradient(180deg,${We},${Ge})`}}),e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",style:{flexShrink:0,color:N?We:I.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(mt,{text:an(b),style:{flex:1}}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{flexShrink:0,color:I.color.muted,transform:A?"rotate(0)":"rotate(-90deg)",transition:"transform 0.15s ease"},children:e.jsx("path",{d:"M9 18l6-6-6-6"})})]}),jt(A,e.jsx("div",{style:{paddingLeft:30},children:H.map(J=>{const fe=J.path===o,Te=Z===J.path;return e.jsxs("div",{className:"vagus-session-row",onClick:()=>r(J.path),onContextMenu:te=>W(te,J),onMouseEnter:te=>{fe||(te.currentTarget.style.background=I.color.sidebarHover)},onMouseLeave:te=>{fe||(te.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:fe?I.color.fg:I.color.muted,fontWeight:fe?500:400,background:fe?Me:"transparent",overflow:"hidden",whiteSpace:"nowrap",transition:ue},children:[fe&&e.jsx("span",{style:{position:"absolute",left:0,top:8,bottom:8,width:3,borderRadius:3,background:`linear-gradient(180deg,${We},${Ge})`}}),e.jsx(St,{color:fe?We:void 0}),Te?e.jsx("input",{autoFocus:!0,value:Q,onChange:te=>ie(te.target.value),onBlur:te=>{te.currentTarget.style.boxShadow="none",Se(J.path)},onKeyDown:te=>{te.key==="Enter"&&Se(J.path),te.key==="Escape"&&G(void 0)},onClick:te=>te.stopPropagation(),onFocus:te=>{te.currentTarget.style.boxShadow=Ut},style:{flex:1,minWidth:0,fontSize:"0.89em",padding:"2px 6px",background:I.color.bg,border:`1px solid ${I.color.border}`,borderRadius:6,color:I.color.fg,outline:"none"}}):e.jsx(mt,{text:(J.name??J.firstMessage.slice(0,40))||"(空会话)"}),e.jsx("span",{style:{width:12,display:"inline-flex",justifyContent:"center",alignItems:"center",flexShrink:0},children:(M.has(J.path)||z.has(J.path))&&e.jsx("span",{title:T("工作中"),style:{width:7,height:7,borderRadius:"50%",background:I.color.primary,animation:"vagus-pulse 1.2s ease-in-out infinite",display:"inline-block"}})}),e.jsx("span",{style:{width:14,display:"inline-flex",justifyContent:"center",alignItems:"center",flexShrink:0},children:v.has(J.path)&&e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",style:{color:We},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",{className:"vagus-row-time",style:{width:ko,textAlign:"right",fontVariantNumeric:"tabular-nums",fontSize:"0.79em",color:I.color.muted,flexShrink:0},children:ln(J.modified)})]},J.id)})}))]},b)}),Y.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontSize:"0.79em",fontWeight:600,color:I.color.muted,textTransform:"uppercase",letterSpacing:"0.08em",padding:"16px 10px 6px"},children:T("最近")}),e.jsx("div",{style:{paddingLeft:0},children:n.slice(0,5).map(b=>e.jsxs("div",{onClick:()=>r(b.path),onContextMenu:H=>W(H,b),onMouseEnter:H=>H.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:H=>H.currentTarget.style.background="transparent",style:{display:"flex",alignItems:"center",gap:7,padding:"6px 10px",borderRadius:10,cursor:"pointer",userSelect:"none",fontSize:"0.91em",color:I.color.muted,overflow:"hidden",whiteSpace:"nowrap",transition:ue},children:[e.jsx(St,{}),e.jsx(mt,{text:b.name??b.firstMessage.slice(0,40)})]},b.id))})]}),e.jsx(vo,{archivedProjects:j,busyPaths:M,collapsed:X,onToggleProject:y,onOpenSession:r,onSessionContextMenu:(b,H,A)=>W(b,H,A),onProjectContextMenu:(b,H,A)=>{b.preventDefault(),w({x:b.clientX,y:b.clientY,kind:"archived",cwd:H,dirKey:A})},onSectionContextMenu:b=>w({x:b.clientX,y:b.clientY,kind:"archivedAll"})})]}),e.jsx("div",{style:{flex:"none",borderTop:`1px solid ${I.color.border}`,padding:8,background:I.color.sidebarBg},children:e.jsxs("button",{onClick:s,onMouseEnter:b=>{b.currentTarget.style.background=I.color.sidebarHover,b.currentTarget.style.color=I.color.fg},onMouseLeave:b=>{b.currentTarget.style.background="transparent",b.currentTarget.style.color=I.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:I.color.muted,transition:ue},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:T("设置")})]})}),R&&e.jsxs("div",{"data-context-menu":!0,style:{position:"fixed",left:R.x,top:R.y,zIndex:1e3,minWidth:140,background:I.color.surface,border:`1px solid ${I.color.border}`,borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.2)",padding:4},children:[R.kind==="session"&&!R.archived&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>oe(R.session),style:ee,onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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"})}),T("重命名")]}),g&&e.jsxs("div",{onClick:()=>{w(null),g(R.session.path)},style:ee,onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.currentTarget.style.background="transparent",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:v.has(R.session.path)?"#6366f1":"none",stroke:v.has(R.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"})}),T("置顶")]}),f&&e.jsxs("div",{onClick:()=>{w(null),f(R.session.path)},style:ee,onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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"})]}),T("归档")]})]}),R.kind==="session"&&R.archived&&e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{onClick:()=>{w(null),m(R.session.path)},style:ee,onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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"})]}),T("恢复")]}),x&&e.jsxs("div",{onClick:()=>{w(null),x(R.session.path)},style:{...ee,color:"#E5484D"},onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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"})}),T("删除")]})]}),R.kind==="project"&&$&&e.jsxs("div",{onClick:()=>{w(null),$(R.cwd)},style:ee,onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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"})]}),T("归档项目")]}),R.kind==="archivedAll"&&e.jsxs("div",{onClick:()=>{w(null),u==null||u()},style:{...ee,color:"#E5484D"},onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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 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"}),e.jsx("path",{d:"M10 11v6M14 11v6"})]}),T("清空全部归档")]}),R.kind==="archived"&&e.jsxs(e.Fragment,{children:[p&&e.jsxs("div",{onClick:()=>{w(null),p(R.dirKey)},style:ee,onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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"})]}),T("恢复项目")]}),S&&e.jsxs("div",{onClick:()=>{w(null),S(R.dirKey)},style:{...ee,color:"#E5484D"},onMouseEnter:b=>b.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:b=>b.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"})}),T("彻底删除")]})]})]})]})})}function It(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 wo={builtin:"pi 原生指令",extension:"工具指令",skill:"Skills",template:"模板"};function jo({commands:n,onPick:o}){const t=K(),[r,s]=a.useState(""),i=r.toLowerCase().replace(/^\//,""),l=n.filter(m=>m.name.toLowerCase().includes(i)||m.description.toLowerCase().includes(i)),c=["builtin","extension","skill","template"],f={position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},u={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"},h={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:f,onMouseDown:m=>{m.target===m.currentTarget&&o(null)},children:e.jsxs("div",{style:u,onMouseDown:m=>m.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:m=>s(m.target.value),onKeyDown:m=>{m.key==="Escape"&&o(null)},placeholder:T("输入 / 命令…"),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:T("(没有匹配的命令)")}):c.flatMap(m=>{const x=l.filter(g=>g.type===m);return x.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:It(m,t),flexShrink:0}}),wo[m]]},m),...x.map(g=>e.jsxs("div",{onClick:()=>o(`/${g.name}`),style:h,onMouseEnter:v=>{v.currentTarget.style.background=t.color.surface},onMouseLeave:v=>{v.currentTarget.style.background="transparent"},children:[e.jsxs("span",{style:{color:It(m,t),fontWeight:600,flexShrink:0,fontSize:"0.86em"},children:["/",g.name]}),e.jsx("span",{style:{color:t.color.muted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.description})]},`${m}:${g.name}`))]})})]})})}function Yt(n){return n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${(n/1e3).toFixed(1)}K`:String(Math.round(n))}function So({value:n,onChange:o,onSubmit:t,usage:r,providers:s,onSwitchModel:i,onSetThinking:l,thinkingLevel:c="off",permissionMode:f,onTogglePermission:u,attachments:h=[],fileAttachments:m=[],onAttach:x,onRemoveAttachment:g,onCommand:v,commands:j=[],onPickCommand:$,onRefreshCommands:p,focusSignal:S,busy:M=!1,hasPendingDialog:z=!1,onRestoreDialog:I,onStop:P,selectedModel:q,queuedMessages:X=[],dock:_,onCancelQueued:R}){var nt,Ve,Ue;const w=K(),[Z,G]=a.useState(!1),[Q,ie]=a.useState(!1),[Y,y]=a.useState(0),[W,O]=a.useState(!1);a.useEffect(()=>{if(X.length===0){O(!1);return}const C=window.setTimeout(()=>O(!0),300);return()=>window.clearTimeout(C)},[X.length]),a.useEffect(()=>{const C=ye.current;C&&(C.style.height="auto",C.style.height=`${Math.min(C.scrollHeight,200)}px`)},[n]);const[D,oe]=a.useState(!1),[ee,Se]=a.useState(!1),ye=a.useRef(null),Fe=a.useRef(null),Ae=a.useRef(null),Ie=a.useRef(null),Ce=a.useRef(null);a.useEffect(()=>{var C;S&&S>0&&((C=ye.current)==null||C.focus())},[S]),a.useEffect(()=>{if(!Z)return;const C=V=>{var he,Ee;const le=V.target;(he=Ie.current)!=null&&he.contains(le)||(Ee=Ae.current)!=null&&Ee.contains(le)||G(!1)},F=V=>{V.key==="Escape"&&G(!1)};return document.addEventListener("mousedown",C),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",F)}},[Z]),a.useEffect(()=>{if(!D)return;const C=V=>{var he;const le=V.target;(he=Ce.current)!=null&&he.contains(le)||oe(!1)},F=V=>{V.key==="Escape"&&oe(!1)};return document.addEventListener("mousedown",C),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",F)}},[D]);const ce=a.useMemo(()=>{for(const C of s){const F=C.models.find(V=>(r==null?void 0:r.activeProvider)===C.id&&V.id===(r==null?void 0:r.model));if(F)return{provider:C,model:F}}},[s,r==null?void 0:r.activeProvider,r==null?void 0:r.model]),Le=(ce==null?void 0:ce.model.contextWindow)??1e6,$e=((nt=ce==null?void 0:ce.model.input)==null?void 0:nt.includes("image"))??!0,Me=((Ve=r==null?void 0:r.contextUsage)==null?void 0:Ve.tokens)??null,be=Me!==null,b=Me??0,H=Math.min(1,b/Le),A=r==null?void 0:r.latestCacheHitRate,N=7,J=2*Math.PI*N,fe=J*(1-H),Te={width:34,height:34,borderRadius:10,border:"none",background:"transparent",color:w.color.muted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},te={display:"flex",alignItems:"center",gap:5,fontSize:"0.89em",color:w.color.muted,padding:"5px 10px",borderRadius:8,cursor:"pointer",background:"transparent",border:"none",fontFamily:"inherit"},qe={position:"absolute",bottom:42,left:0,zIndex:50,minWidth:190,background:w.color.bg,border:`1px solid ${w.color.border}`,borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.14)",padding:4},He=()=>{t()},xe=Q&&n.startsWith("/"),Ne=xe?n.slice(1).split(/\s+/)[0]??"":"",ae=xe?j.filter(C=>C.name.toLowerCase().includes(Ne.toLowerCase())):[];a.useEffect(()=>{Y>=ae.length&&y(Math.max(0,ae.length-1))},[ae.length]);const ze=C=>{const F=n.slice(Ne.length+1),V=`/${C} ${F.replace(/^\s+/,"")}`;o(V),ie(!1),$==null||$(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:[W&&X.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:w.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}}),"排队中 · ",X.length," 条"]}),X.map((C,F)=>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:w.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:F+1}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),R&&e.jsx("button",{onClick:()=>R(C.text),title:T("取消这条消息"),style:{width:18,height:18,borderRadius:"50%",border:"none",background:"transparent",color:w.color.muted,cursor:"pointer",fontSize:"0.72em",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0,transition:"background 0.15s, color 0.15s"},onMouseEnter:V=>{V.currentTarget.style.background="rgba(229,72,77,0.15)",V.currentTarget.style.color="#E5484D"},onMouseLeave:V=>{V.currentTarget.style.background="transparent",V.currentTarget.style.color=w.color.muted},children:"✕"})]},C.id))]}),(h.length>0||m.length>0)&&e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8,alignItems:"center"},children:[h.map((C,F)=>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 ${w.color.border}`}}),e.jsx("button",{onClick:()=>g==null?void 0:g(F),title:T("移除"),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:"✕"})]},F)),m.map((C,F)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,height:26,padding:"0 8px",borderRadius:8,background:w.color.surface,border:`1px solid ${w.color.border}`,fontSize:"0.82em",color:w.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:()=>g==null?void 0:g(F+h.length),style:{width:14,height:14,borderRadius:"50%",border:"none",background:"transparent",color:w.color.muted,cursor:"pointer",fontSize:"0.79em",display:"flex",alignItems:"center",justifyContent:"center",padding:0},children:"✕"})]},C.name))]}),xe&&ae.length>0&&e.jsx("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",left:4,right:4,zIndex:60,background:w.color.bg,border:`1px solid ${w.color.border}`,borderRadius:12,boxShadow:"0 16px 48px rgba(0,0,0,0.18)",maxHeight:300,overflowY:"auto",padding:4},children:ae.map((C,F)=>e.jsxs("button",{onClick:()=>ze(C.name),onMouseEnter:()=>y(F),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:F===Y?w.color.surface:"transparent",color:w.color.fg},children:[e.jsxs("span",{style:{color:It(C.type,w),fontWeight:600,flexShrink:0,fontSize:"0.84em"},children:["/",C.name]}),e.jsx("span",{style:{color:w.color.muted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.description})]},`${C.type}:${C.name}`))}),e.jsx("textarea",{ref:ye,value:n,onChange:C=>{o(C.target.value),Q&&!C.target.value.startsWith("/")&&ie(!1)},onKeyDown:C=>{if(C.key==="Tab"){if(xe&&ae.length>0){C.preventDefault();const F=ae[Y];F&&ze(F.name)}return}if(C.key==="Enter"&&!C.shiftKey){if(C.nativeEvent.isComposing)return;if(xe&&ae.length>0){C.preventDefault();const F=ae[Y];F&&ze(F.name);return}C.preventDefault(),He()}if(C.key==="Escape"){if(xe){ie(!1),C.preventDefault();return}o("")}xe&&(C.key==="ArrowDown"&&(C.preventDefault(),y(F=>Math.min(F+1,ae.length-1))),C.key==="ArrowUp"&&(C.preventDefault(),y(F=>Math.max(F-1,0)))),C.key==="/"&&!C.shiftKey&&!C.ctrlKey&&!C.metaKey&&!C.altKey&&C.currentTarget.selectionStart===0&&(ie(!0),p==null||p())},onPaste:C=>{var le;const F=(le=C.clipboardData)==null?void 0:le.items;if(!F)return;const V=[];for(const he of Array.from(F))if(he.kind==="file"&&he.type.startsWith("image/")){const Ee=he.getAsFile();Ee&&V.push(Ee)}V.length>0&&(C.preventDefault(),x==null||x(V))},rows:1,style:{width:"100%",minHeight:34,maxHeight:200,overflow:"auto",overflowX:"hidden",background:"transparent",border:"none",outline:"none",resize:"none",fontFamily:w.font.sans,fontSize:"1.04em",lineHeight:1.5,color:w.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:Ae,title:T("添加上下文"),style:Te,onClick:()=>{G(C=>!C),oe(!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"})})}),Z&&e.jsx("div",{ref:Ie,style:qe,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:$e?void 0:"当前模型不支持图片,仅可添加文本文件",action:()=>{var C;return(C=Fe.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:()=>v==null?void 0:v()}].map(C=>e.jsxs("button",{title:C.title,onClick:()=>{G(!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:w.color.fg,cursor:"pointer",textAlign:"left"},onMouseEnter:F=>{F.currentTarget.style.background=w.color.surface},onMouseLeave:F=>{F.currentTarget.style.background="transparent"},children:[e.jsx("span",{style:{color:w.color.muted,display:"flex"},children:C.icon}),C.label]},C.label))}),e.jsx("input",{ref:Fe,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:C=>{const F=Array.from(C.target.files??[]);F.length>0&&(x==null||x(F)),C.target.value=""}})]}),e.jsx("div",{style:{flex:1}}),r&&e.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>Se(!0),onMouseLeave:()=>Se(!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:N,fill:"none",stroke:w.color.border,strokeWidth:"2.5"}),e.jsx("circle",{cx:"9",cy:"9",r:N,fill:"none",stroke:H>.9?"#E5484D":H>.7?"#B7791F":w.color.primary,strokeWidth:"2.5",strokeLinecap:"round",strokeDasharray:`${J} ${J}`,strokeDashoffset:fe,transform:"rotate(-90 9 9)"})]})}),ee&&e.jsxs("div",{style:{position:"absolute",bottom:34,right:0,zIndex:60,width:280,background:w.color.bg,border:`1px solid ${w.color.border}`,borderRadius:12,padding:"12px 14px",boxShadow:"0 10px 32px rgba(0,0,0,0.14)",fontSize:"0.82em",color:w.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:w.color.muted},children:T("上下文容量")}),e.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:r?be?`${Yt(b)} / ${Yt(Le)} (${(H*100).toFixed(2)}%)`:"未知 · 待下次响应":"—"})]}),e.jsx("div",{style:{height:6,borderRadius:3,background:w.color.border,overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",width:be?`${H*100}%`:"0%",background:H>.9?"#E5484D":H>.7?"#B7791F":w.color.primary,transition:"width 0.3s"}})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:{color:w.color.muted},children:T("缓存命中率")}),e.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:A!==void 0?`${A.toFixed(1)}%`:"—"})]})]})]}),_,e.jsxs("div",{ref:Ce,style:{position:"relative"},children:[e.jsxs("button",{style:te,onClick:()=>{oe(C=>!C),G(!1)},title:T("切换模型"),children:[((Ue=r==null?void 0:r.model)==null?void 0:Ue.split("/").pop())??q??"选择模型",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"})})]}),D&&e.jsxs("div",{style:{...qe,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:w.color.muted},children:T("暂无已配置模型")}),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:w.color.muted},children:C.id}),C.models.map(F=>{const V=(r==null?void 0:r.activeProvider)===C.id&&(r==null?void 0:r.model)===F.id;return e.jsxs("button",{onClick:()=>{i(C.id,F.id),oe(!1)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",height:32,padding:"0 10px",border:"none",background:V?w.color.surface:"transparent",borderRadius:8,fontSize:"0.89em",color:w.color.fg,cursor:"pointer",textAlign:"left"},onMouseEnter:le=>{V||(le.currentTarget.style.background=w.color.surface)},onMouseLeave:le=>{V||(le.currentTarget.style.background="transparent")},children:[e.jsx("span",{style:{fontSize:"0.79em",color:w.color.muted,flexShrink:0},children:"◆"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:F.name??F.id}),V&&e.jsx("span",{style:{fontSize:"0.79em",color:w.color.primary},children:"✓"})]},F.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"?w.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"})}),e.jsx("span",{style:{display:"inline-block",width:"4em",textAlign:"center"},children:c==="off"?"思考关闭":"思考中"})]}),e.jsx("button",{onClick:z?I:M?P:He,title:z?"恢复待处理的弹窗":M?"停止":"发送",style:{width:38,height:38,borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,background:z?w.color.warning:M?"#E8833D":"linear-gradient(135deg,#6366f1,#8b5cf6)",color:"#fff",boxShadow:z||M?"none":"0 4px 14px rgba(99,102,241,0.35)",transition:"transform 0.15s, box-shadow 0.15s"},children:z?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"})}):M?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 Io({projects:n,value:o,onChange:t,onNewProject:r}){const s=K(),[i,l]=a.useState(!1),[c,f]=a.useState(""),u=a.useRef(null),h=a.useRef(null);a.useEffect(()=>{if(!i)return;const S=z=>{var P,q;const I=z.target;(P=h.current)!=null&&P.contains(I)||(q=u.current)!=null&&q.contains(I)||l(!1)},M=z=>{z.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",S),document.addEventListener("keydown",M),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("keydown",M)}},[i]);const m=n.find(S=>S.id===o),x=o?o.split(/[\\/]/).filter(Boolean).pop()??o:void 0,g=(m==null?void 0:m.name)??x??"选择项目",v=n.filter(S=>S.name.toLowerCase().includes(c.toLowerCase())),j=o!==void 0,$={display:"inline-flex",alignItems:"center",gap:6,background:j?"rgba(99,102,241,0.08)":s.color.surface,color:j?"#6366f1":s.color.muted,fontSize:"0.89em",fontWeight:j?600:500,padding:"6px 10px 6px 8px",borderRadius:9,cursor:"pointer",border:`1px solid ${j?"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"},p={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:u,style:$,onClick:S=>{S.stopPropagation(),l(M=>!M)},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:g}),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:h,style:p,onClick:S=>S.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:S=>f(S.target.value),placeholder:T("搜索项目"),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:v.map(S=>{const M=S.id===o;return e.jsxs("div",{onClick:()=>{t(S.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:M?s.color.surface:"transparent",opacity:S.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:S.name})]},S.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"})}),T("新建项目")]})})]})]})}const dn="vagus.picker.lastDir",cn="vagus.picker.recent";function un(){try{const n=localStorage.getItem(cn);return(n?JSON.parse(n):[]).slice(0,8)}catch{return[]}}function Co(n){try{const o=un().filter(t=>t!==n);o.unshift(n),localStorage.setItem(cn,JSON.stringify(o.slice(0,8))),localStorage.setItem(dn,n)}catch{}}const Mo={Desktop:"🖥️",Downloads:"📥",Documents:"📄",Pictures:"🖼️",Music:"🎵",Videos:"🎬",Home:"🏠",Root:"💿"};function To({listDir:n,roots:o,onPick:t}){const r=K(),[s,i]=a.useState(()=>{const y=localStorage.getItem(dn);return y&&y.length>0?y:"~"}),[l,c]=a.useState([]),[f,u]=a.useState(null),[h,m]=a.useState(!0),[x,g]=a.useState(null),[v,j]=a.useState(!1),[$,p]=a.useState(""),[S,M]=a.useState({places:[],drives:[]}),[z]=a.useState(un);a.useEffect(()=>{o().then(y=>M(y)).catch(()=>{})},[]),a.useEffect(()=>{m(!0),g(null),u(null),n(s).then(y=>{i(y.path),c(y.entries)}).catch(y=>g(String(y))).finally(()=>m(!1))},[s]),a.useEffect(()=>{const y=W=>{W.key==="Enter"&&!v&&R(),W.key==="Escape"&&t(null)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[v,s]);const I=/^[A-Za-z]:[\\/]/.test(s),P=a.useMemo(()=>s.split(/[\\/]+/).filter(Boolean),[s]);function q(y){if(I){const W=P[0];return y===0?`${W}\\`:`${W}\\${P.slice(1,y+1).join("\\")}`}return`/${P.slice(0,y+1).join("/")}`}function X(y){if(/^[A-Za-z]:[\\/]?$/.test(y))return y;const W=y.replace(/[\\/][^\\/]+$/,"");return W.length===0?"/":I&&W.length===2&&W.endsWith(":")?`${W}\\`:W}function _(y){j(!1),i(y)}function R(){const y=f??s;y&&(Co(y),t(y))}function w(){const y=$.trim();y?_(y):j(!1)}const Z=X(s),G=Z===s,Q={position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},ie={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"},Y={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:ie,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:T("选择项目文件夹")}),e.jsx("button",{style:Y,onClick:()=>t(null),title:T("关闭"),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:{...Y,opacity:G?.35:1,cursor:G?"default":"pointer"},disabled:G,onClick:()=>_(Z),title:T("上一级"),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"})})}),v?e.jsx("form",{style:{flex:1,display:"flex"},onSubmit:y=>{y.preventDefault(),w()},children:e.jsx("input",{autoFocus:!0,value:$,onChange:y=>p(y.target.value),onBlur:()=>j(!1),placeholder:T("输入路径(如 ~/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:()=>{p(s),j(!0)},title:s,children:[e.jsx("span",{style:{color:r.color.muted,flexShrink:0},children:I?P[0]:"/"}),P.slice(I?1:0).map((y,W)=>{const O=I?W+1:W,D=O===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:D?r.color.fg:r.color.muted,fontWeight:D?500:400,cursor:D?"default":"pointer",maxWidth:120,overflow:"hidden",textOverflow:"ellipsis"},onClick:oe=>{D||(oe.stopPropagation(),_(q(O)))},children:y})]},`${y}-${W}`)})]})]}),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:T("位置")}),S.places.map(y=>e.jsxs("button",{onClick:()=>_(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:Mo[y.name]??"📁"}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.name})]},y.path)),S.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:T("驱动器")}),S.drives.map(y=>e.jsxs("button",{onClick:()=>_(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))]}),z.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:T("最近")}),z.map(y=>e.jsxs("button",{onClick:()=>_(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:h?e.jsx("div",{style:{padding:"32px 0",textAlign:"center",color:r.color.muted,fontSize:"0.93em"},children:T("加载中…")}):x?e.jsx("div",{style:{padding:"32px 0",textAlign:"center",color:"#E5484D",fontSize:"0.93em"},children:x}):l.length===0?e.jsx("div",{style:{padding:"32px 0",textAlign:"center",color:r.color.muted,fontSize:"0.93em"},children:T("(空文件夹)")}):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&&u(y.path),onDoubleClick:()=>y.isDirectory&&_(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:f===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:T("取消")}),e.jsxs("button",{onClick:R,disabled:!s,style:{height:30,padding:"0 16px",borderRadius:8,border:"none",background:"#3A3A3A",color:"#fff",fontSize:"0.89em",cursor:"pointer",fontWeight:500},children:["选择",f?` “${f.split(/[\\/]/).filter(Boolean).pop()??f}”`:"此文件夹"]})]})]})]})})}function se(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 f=0;f<i.toolCalls.length;f++){const u=i.toolCalls[f];c.push({id:l+1+f,kind:"tool",toolCallId:u.id||`hist-${s}-${f}`,name:u.name,args:u.args,status:u.isError===!0?"failed":"succeeded",result:u.result,...u.diff!==void 0?{diff:u.diff}:{},...u.patch!==void 0?{patch:u.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==="tool")for(let f=0;f<(i.toolCalls??[]).length;f++){const u=i.toolCalls[f];c.push({id:l+1+f,kind:"tool",toolCallId:u.id||`hist-${s}-${f}`,name:u.name,args:u.args,status:u.isError===!0?"failed":"succeeded",result:u.result,...u.diff!==void 0?{diff:u.diff}:{},...u.patch!==void 0?{patch:u.patch}:{},collapsed:!0}),r=t.length+c.length-1}if(i.role==="system"&&c.push({id:l+100,kind:"system",text:i.text}),t.push(...c),i.turnDurationMs!==void 0&&r!==void 0){const f=t[r];f&&(f.kind==="thinking"||f.kind==="tool")&&(t[r]={...f,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.role==="tool")for(let f=0;f<(i.toolCalls??[]).length;f++){const u=i.toolCalls[f];c.push({id:l+1+f,kind:"tool",toolCallId:u.id||`hist-${s}-${f}`,name:u.name,args:u.args,status:u.isError===!0?"failed":"succeeded",result:u.result,...u.diff!==void 0?{diff:u.diff}:{},...u.patch!==void 0?{patch:u.patch}:{},collapsed:!0}),r=t.length+c.length-1}if(i.toolCalls)for(let f=0;f<i.toolCalls.length;f++){const u=i.toolCalls[f];c.push({id:l+1+f,kind:"tool",toolCallId:u.id||`hist-${s}-${f}`,name:u.name,args:u.args,status:u.isError===!0?"failed":"succeeded",result:u.result,...u.diff!==void 0?{diff:u.diff}:{},...u.patch!==void 0?{patch:u.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 f=t[r];f&&(f.kind==="thinking"||f.kind==="tool")&&(t[r]={...f,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 Jt=/^(#{1,6})\s+(.*)$/,at=/^```(\w*)\s*$/,Xt=/^\s*(---+|\*\*\*+|___+)\s*$/,Qe=/^\s*>\s?(.*)$/,dt=/^(\s*)([-*+]|\d+\.)\s+(.*)$/,yt=/^\s*\|(.+)\|\s*$/,Gt=/^[\s:|:-]+$/;function fn(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(at);if(l){const h=l[1]??"",m=[];for(r+=1;r<o.length;){if(at.test(o[r]??"")){r+=1;break}m.push(o[r]??""),r+=1}t.push({type:"code",lang:h,text:m.join(`
5
+ `)});continue}const c=i.match(Jt);if(c){t.push({type:"heading",level:c[1].length,content:pe(c[2]??"")}),r+=1;continue}if(Xt.test(i)){t.push({type:"hr"}),r+=1;continue}if(Qe.test(i)){const h=[];for(;r<o.length&&Qe.test(o[r]??"");)h.push((o[r]??"").replace(Qe,"$1")),r+=1;t.push({type:"quote",content:fn(h.join(`
6
+ `))});continue}const f=i.match(dt);if(f){const h=/\d+\./.test(f[2]??""),m=[],x=(f[1]??"").length;for(;r<o.length;){const g=(s=o[r])==null?void 0:s.match(dt),v=((g==null?void 0:g[1])??"").length,j=g!=null&&/\d+\./.test(g[2]??"");if(!g||v!==x||j!==h)break;const p=[(g[3]??"").trim()];for(;r+1<o.length;){const S=o[r+1]??"";if(S.length>0&&!/^\s*$/.test(S)&&!dt.test(S)&&!Qe.test(S)&&!at.test(S))p.push(S.replace(/^\s+/,"")),r+=1;else break}m.push(pe(p.join(" "))),r+=1}t.push({type:"list",ordered:h,items:m});continue}if(yt.test(i)){const h=Qt(i),m=o[r+1]??"";if(h.length>1&&Gt.test(m)&&m.includes("-")){const x=h.map(v=>pe(v)),g=[];for(r+=2;r<o.length&&yt.test(o[r]??"");)g.push(Qt(o[r]??"").map(v=>pe(v))),r+=1;t.push({type:"table",headers:x,rows:g});continue}}if(/^\s*$/.test(i)){r+=1;continue}const u=[i.trim()];for(r+=1;r<o.length;){const h=o[r]??"";if(/^\s*$/.test(h)||Jt.test(h)||at.test(h)||Xt.test(h)||Qe.test(h)||dt.test(h)||yt.test(h)&&(o[r+1]??"").includes("-")&&Gt.test(o[r+1]??""))break;u.push(h.trim()),r+=1}t.push({type:"paragraph",content:pe(u.join(" "))})}return t}function Qt(n){return n.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}const Eo=/^(https?|mailto):/i;function pe(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,f,u,h,m,x]=s;if(l!==void 0)t.push({kind:"code",text:l.slice(1,-1)});else if(c!==void 0)t.push({kind:"bold",children:pe(c.slice(2,-2))});else if(f!==void 0)t.push({kind:"bold",children:pe(f.slice(2,-2))});else if(u!==void 0)t.push({kind:"italic",children:pe(u.slice(1,-1))});else if(h!==void 0)t.push({kind:"italic",children:pe(h.slice(1,-1))});else if(m!==void 0)t.push({kind:"strike",children:pe(m.slice(2,-2))});else if(x!==void 0){const g=x.match(/^\[([^\]]+)\]\(([^)\s]+)\)$/);if(g){const v=g[2]??"";t.push(Eo.test(v)?{kind:"link",href:v,children:pe(g[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 Ro="rgba(79, 140, 255, 0.08)",Wo="rgba(79, 140, 255, 0.18)",Ze=new Map,Lo=4e3;function $o(n,o){const t=`${n.length}:${n}`,r=Ze.get(t);if(r)return r;const s=ao(n,o);if(Ze.size>=Lo){const i=Ze.keys().next().value;i!==void 0&&Ze.delete(i)}return Ze.set(t,s),s}function me({nodes:n}){const o=K();return e.jsx(e.Fragment,{children:n.map((t,r)=>{switch(t.kind){case"text":return e.jsx(nn.Fragment,{children:t.text},r);case"code":return e.jsx("code",{style:{fontFamily:o.font.mono,fontSize:"0.85em",background:Ro,border:`1px solid ${Wo}`,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(me,{nodes:t.children})},r);case"italic":return e.jsx("em",{children:e.jsx(me,{nodes:t.children})},r);case"strike":return e.jsx("s",{style:{opacity:.6},children:e.jsx(me,{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(me,{nodes:t.children})},r)}})})}const et={margin:"0 0 10px"};function zo({text:n,lang:o}){const{theme:t}=tt(),r=on(),[s,i]=a.useState(!1),l=t==="light"?io:lo,c=n.split(`
7
+ `),f=async()=>{try{await navigator.clipboard.writeText(n)}catch{const u=document.createElement("textarea");u.value=n,u.style.position="fixed",u.style.opacity="0",document.body.appendChild(u),u.select(),document.execCommand("copy"),document.body.removeChild(u)}i(!0),window.setTimeout(()=>i(!1),1600)};return e.jsxs("div",{style:{margin:et.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 f(),onMouseEnter:u=>{u.currentTarget.style.opacity="1",u.currentTarget.style.background="rgba(99,102,241,0.12)",u.currentTarget.style.borderColor="rgba(99,102,241,0.45)",u.currentTarget.style.color="#6366f1"},onMouseLeave:u=>{u.currentTarget.style.opacity="0.85",u.currentTarget.style.background="transparent",u.currentTarget.style.borderColor=l.border,u.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((u,h)=>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:h+1}),e.jsx("span",{style:{whiteSpace:r.wrapLongLines?"pre-wrap":"pre",minWidth:0},children:$o(u,l).map((m,x)=>m.color!==void 0?e.jsx("span",{style:{color:m.color},children:m.text},x):e.jsx(nn.Fragment,{children:m.text},x))})]},h))})]})}function Bo({block:n}){const{tokens:o}=tt();switch(n.type){case"code":return e.jsx(zo,{text:n.text,lang:n.lang});case"paragraph":return e.jsx("p",{style:et,children:e.jsx(me,{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(me,{nodes:n.content})});case"list":return e.jsx("div",{style:et,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(me,{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(me,{nodes:t})})]},r))});case"quote":return e.jsx("blockquote",{style:{margin:et.margin,padding:"2px 0 2px 12px",borderLeft:`3px solid ${o.color.primary}`,color:o.color.muted},children:e.jsx(hn,{blocks:n.content})});case"table":return e.jsx("div",{style:{margin:et.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(me,{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(me,{nodes:s})},i))},r))})]})});case"hr":return e.jsx("hr",{style:{border:"none",borderTop:`1px solid ${o.color.border}`,margin:"14px 0"}})}}function hn({blocks:n}){return e.jsx(e.Fragment,{children:n.map((o,t)=>e.jsx(Bo,{block:o},t))})}function Do({text:n}){const o=a.useMemo(()=>fn(n),[n]);return e.jsx("div",{style:{overflowWrap:"anywhere",wordBreak:"break-word",minWidth:0},children:e.jsx(hn,{blocks:o})})}const Fo=720,bt="#6366f1",Ao="#8b5cf6";function Ho({text:n}){const o=K(),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:Fo,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, ${bt}, ${Ao})`}}),e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:bt,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:bt,fontWeight:600},children:T("前文已摘要")}),t?e.jsxs("span",{style:{opacity:.75},children:[" · 剩余 ",t[1],"K 上下文"]}):null]})]})})}function Po(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?De(o):"未知文件"}function De(n){return n.replace(/\\/g,"/").replace(/^\/mnt\/([a-zA-Z])\//,(o,t)=>`${t.toUpperCase()}:/`)}function Oo(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 _o(n){const o=[];for(const t of n)t.kind!=="tool"||!t.diff||!t.toolCallId||o.push({file:Po(t.args),toolCallId:t.toolCallId,diff:t.diff,patch:t.patch,...Oo(t.diff)});return o}const qo=/<skill\s+name="([^"]+)"[^>]*>\s*(?:References are relative to[^\n]*\n\n)?([\s\S]*?)<\/skill>/g;function No({parts:n}){const o=K();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 Vo(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 Uo(n){const o=[];let t=0,r;const s=new RegExp(qo.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(No,{parts:o}):e.jsx(e.Fragment,{children:n})}function Ko({text:n}){const o=K();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 kt=1e3;function gn(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=_o(t);if(l.length>0){const c=new Map;for(const h of l){const m=c.get(h.file)??{file:h.file,added:0,removed:0};m.added+=h.added,m.removed+=h.removed,h.diff&&(m.diff=m.diff?`${m.diff}
9
+ ${h.diff}`:h.diff),h.patch&&(m.patch=m.patch?`${m.patch}
10
+ ${h.patch}`:h.patch),c.set(h.file,m)}const f=l[l.length-1].toolCallId,u=[...c.values()].map(h=>({...h,turnToolCallId:f}));o.push({kind:"turnSummary",files:u})}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 f=!0,u=t.length>0;for(let h=l+1;h<n.length;h++){const m=n[h];if(m.kind==="user"||m.kind==="system")break;if(m.kind==="thinking"||m.kind==="tool"){u=!0,f=!1;break}if(m.kind==="assistant"){f=!1;break}}f||!u?r.push(c):t.push(c)}else i(),o.push({kind:"item",item:c})}return i(),o}function Yo(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 Jo({item:n,onToggleCard:o,onCopy:t,onEditSubmit:r,showCopy:s,onFork:i}){const l=K(),[c,f]=a.useState(!1);if(n.kind==="user")return e.jsx(Go,{item:n,onCopy:t,onEditSubmit:r,onFork:i});if(n.kind==="assistant"){const u=()=>{const h=n.text;t?t(h):navigator.clipboard.writeText(h),f(!0),setTimeout(()=>f(!1),1800)};return e.jsx("div",{style:{display:"flex",justifyContent:"flex-start"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,maxWidth:kt,minWidth:0},children:[e.jsx("div",{style:{overflowWrap:"anywhere",wordBreak:"break-word",fontSize:"1em",lineHeight:1.65,color:l.color.fg},children:e.jsx(Do,{text:n.text})}),s&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-start",minHeight:20},children:e.jsx("button",{onClick:u,title:c?"已复制":"复制回答",style:{width:26,height:26,borderRadius:6,border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"inherit",color:c?"#16a34a":l.color.muted,transition:"color 0.15s",opacity:.4},onMouseEnter:h=>{h.currentTarget.style.opacity="1"},onMouseLeave:h=>{h.currentTarget.style.opacity="0.4"},children:c?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"})]})})})]})})}return n.kind==="thinking"?e.jsx("div",{style:{display:"flex",justifyContent:"flex-start",maxWidth:kt,width:"100%"},children:e.jsx(nr,{item:n,onToggle:()=>o==null?void 0:o(n.id)})}):n.kind==="tool"?e.jsx("div",{style:{display:"flex",justifyContent:"flex-start",maxWidth:kt,width:"100%"},children:e.jsx(or,{item:n,onToggle:()=>o==null?void 0:o(n.id)})}):n.text.startsWith("◌ 前文已摘要")||n.text.startsWith("◔ 分支摘要")?e.jsx(Ho,{text:n.text}):n.text.startsWith("正在压缩")?e.jsx(Ko,{text:n.text}):e.jsx("div",{style:{display:"flex",justifyContent:"center"},children:e.jsx("span",{style:{color:l.color.muted,fontSize:"0.86em"},children:n.text})})}const Ct=a.memo(Jo,(n,o)=>n.item===o.item),Xo={width:26,height:26,borderRadius:6,border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"inherit"};function Go({item:n,onCopy:o,onEditSubmit:t,onFork:r}){const s=K(),i=Vo(n),[l,c]=a.useState(!1),[f,u]=a.useState(i.copyText),[h,m]=a.useState(!1),[x,g]=a.useState(null),v=a.useRef(null);a.useEffect(()=>{var p;l&&((p=v.current)==null||p.focus())},[l]),a.useEffect(()=>{if(x===null)return;const p=S=>{S.key==="Escape"&&g(null)};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[x]);const j=()=>{o==null||o(i.copyText),m(!0),window.setTimeout(()=>m(!1),1600)},$=p=>({...Xo,color:p});return e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4,maxWidth:"100%"},children:[l?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:v,value:f,onChange:p=>u(p.target.value),rows:3,style:{width:"100%",maxWidth:520,minHeight:64,background:s.color.bg,border:"1px solid #6366f1",borderRadius:12,padding:"8px 10px",fontSize:"0.95em",lineHeight:1.5,color:s.color.fg,outline:"none",resize:"vertical",fontFamily:"inherit"}}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{onClick:()=>{c(!1),u(i.copyText)},style:{height:30,padding:"0 12px",borderRadius:8,border:`1px solid ${s.color.border}`,background:"transparent",color:s.color.muted,fontSize:"0.86em",cursor:"pointer",fontFamily:"inherit"},children:T("取消")}),e.jsx("button",{onClick:()=>{f.trim()&&(t==null||t(f.trim())),c(!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:T("发送")})]})]}):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((p,S)=>e.jsx("img",{src:p.dataUrl,alt:"附件",style:{width:80,height:80,borderRadius:8,border:`1px solid ${s.color.border}`,objectFit:"cover",background:s.color.bg,cursor:"zoom-in"},onClick:()=>g(p.dataUrl),title:T("点击查看大图")},S))}),e.jsx("div",{style:{background:s.color.surface,border:`1px solid ${s.color.border}`,borderRadius:"14px 14px 4px 14px",padding:"10px 14px",maxWidth:"70%",color:s.color.fg,whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:"1em",lineHeight:1.55},children:i.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:s.color.warning,fontFamily:s.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"})]}),i.skillTag]}),e.jsx("span",{children:i.args})]}):n.text&&/<skill\s/.test(n.text)?Uo(n.text):i.args}),(o||t||r)&&e.jsxs("div",{style:{display:"flex",gap:4},children:[r&&e.jsx("button",{onClick:()=>r(n.id,n.text,i.copyText),title:T("从此处派生新对话(创建新会话保留到此为止的上下文)"),style:{...$(s.color.muted),opacity:.5,transition:"opacity 0.15s, color 0.15s"},onMouseEnter:p=>{p.currentTarget.style.opacity="1"},onMouseLeave:p=>{p.currentTarget.style.opacity="0.5"},children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[e.jsx("path",{d:"M6 3v12a4 4 0 0 0 4 4h4"}),e.jsx("path",{d:"M14 19l3-3-3-3"}),e.jsx("path",{d:"M6 3a3 3 0 1 0 0 6 3 3 0 0 0 0-6z"})]})}),o&&e.jsx("button",{onClick:j,title:h?"已复制":"复制",style:{...$(h?"#16a34a":s.color.muted),transition:"color 0.15s"},children:h?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:()=>{u(i.copyText),c(!0)},title:T("编辑"),style:$(s.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"})})})]})]}),x!==null&&rn.createPortal(e.jsx("div",{onClick:()=>g(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:x,alt:"查看大图",onClick:p=>p.stopPropagation(),style:{maxWidth:"90vw",maxHeight:"90vh",objectFit:"contain",borderRadius:10,boxShadow:"0 12px 48px rgba(0,0,0,0.5)"}})}),document.body)]})}function Qo(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 Zo({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:Qo(s)})}function er({work:n,onToggleItem:o,live:t,startMs:r,attached:s,attachedAnchor:i}){const l=K(),[c,f]=a.useState(!1),u=a.useRef(!1),h=a.useRef(!1);if(a.useEffect(()=>{t?(u.current=!0,h.current||f(!0)):u.current&&(u.current=!1,f(!1),h.current=!1)},[t]),n.length===0)return null;const m=n.filter(p=>p.kind==="tool").length,x=n.filter(p=>p.kind==="thinking").length,g=n.reduce((p,S)=>Math.max(p,S.kind==="thinking"||S.kind==="tool"?S.turnDurationMs??0:0),0),v=g>0||r!==void 0,$=m>0?`${m} 个工具`+(x>0?` · ${x} 次思考`:""):x>0?`${x} 次思考`:"";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("button",{onClick:()=>{f(p=>{const S=!p;return S||(h.current=!0),S})},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:T("工作内容")}),e.jsxs("span",{style:{color:l.color.muted},children:[$,$!==""&&v&&" · ",e.jsx(Zo,{stampedMs:g,startMs:r})]})]}),c&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,marginTop:2},children:n.map((p,S)=>e.jsxs("div",{style:{display:"contents"},children:[e.jsx(Ct,{item:p,onToggleCard:()=>o(p.id)}),s&&S===i&&s]},`w${p.id}`))})]})}const tr=a.memo(er,(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 nr({item:n,onToggle:o}){const t=K(),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:T("思考")}),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 or({item:n,onToggle:o}){const t=K(),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(pn,{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 rr(n){const o=n.split(`
11
+ `);return o.some(r=>r.startsWith("--- ")||r.startsWith("diff --git"))?ir(o):sr(o)}function sr(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(),f=l===-1?s.slice(1):s.slice(l+1);if(f.trim()==="...")continue;const u=i==="+"||i==="-"?"change":"context";u!==r&&(t.length>0&&r&&o.push({kind:r,lines:t}),t=[],r=u),t.push({marker:i,lineNum:c,content:f})}return t.length>0&&r&&o.push({kind:r,lines:t}),o}function ir(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 f=c.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);if(f){l(),s=Number(f[1])-1,i=Number(f[2])-1;continue}const u=c[0]??"",h=u===" "||u==="+"||u==="-"?c.slice(1):c,m=u==="+"||u==="-"?"change":"context";m!==r&&(l(),r=m);let x="";u==="+"?(i++,x=String(i)):u==="-"?(s++,x=String(s)):(s++,i++,x=String(i)),t.push({marker:u,lineNum:x,content:h})}return l(),o}function pn({diff:n,t:o,maxHeight:t,full:r}){const{theme:s}=tt(),i=s==="dark",l=a.useMemo(()=>rr(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"},f=(h,m,x)=>{const g=h.marker==="+",v=h.marker==="-",j=g?c.addBg:v?c.delBg:"transparent",$=g?c.addEdge:v?c.delEdge:"transparent",p=g?c.addFg:v?c.delFg:c.numFg;return e.jsxs("div",{style:{display:"flex",whiteSpace:"pre",background:j,minWidth:"100%",borderLeft:`3px solid ${$}`,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:p},children:h.lineNum}),e.jsx("span",{style:{flexShrink:0,width:18,textAlign:"center",userSelect:"none",color:p},children:h.marker===" "?" ":h.marker}),e.jsx("span",{style:{whiteSpace:"pre",background:j},children:h.content})]},`${x}-${m}`)},u=(h,m)=>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:[h," unmodified lines"]},m);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((h,m)=>{if(h.kind==="change")return e.jsx("div",{children:h.lines.map((x,g)=>f(x,g,`s${m}`))},`s${m}`);if(r)return null;if(!r&&h.lines.length>2){const x=[h.lines[0],h.lines[h.lines.length-1]],g=h.lines.length-2;return e.jsxs("div",{children:[f(x[0],0,`s${m}-a`),u(g,`s${m}-f`),f(x[1],1,`s${m}-b`)]},`s${m}`)}return e.jsx("div",{children:h.lines.map((x,g)=>f(x,g,`s${m}-c`))},`s${m}`)}),l.length===0&&e.jsx("div",{style:{padding:"8px 10px",color:c.numFg,fontSize:"0.85em",fontFamily:"system-ui, sans-serif"},children:T("(无 diff)")})]})})}function lr({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 ar=a.memo(function({files:o,onOpenFile:t,onRevertAll:r,reverting:s,onExpand:i}){const l=K(),[c,f]=a.useState(!1);if(o.length===0)return null;const u=o.reduce((x,g)=>x+g.added,0),h=o.reduce((x,g)=>x+g.removed,0),m={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:()=>{f(x=>{const g=!x;return i==null||i(g),g})},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:["+",u]}),e.jsxs("span",{style:{color:l.color.error,fontSize:"0.8em",fontWeight:600,flexShrink:0},children:["-",h]}),e.jsx("span",{style:{flex:1}}),e.jsx("button",{onClick:x=>{x.stopPropagation(),r()},disabled:s,title:T("撤销本轮的全部更改"),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:x=>{x.currentTarget.style.background=l.color.sidebarHover,x.currentTarget.style.color=l.color.fg},onMouseLeave:x=>{x.currentTarget.style.background="none",x.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(x=>{const g=x.file.lastIndexOf("/"),v=g>=0?x.file.slice(0,g+1):"",j=g>=0?x.file.slice(g+1):x.file,$=j.toLowerCase(),p=$.endsWith(".py")?"py":$.endsWith(".md")?"md":"other";return e.jsxs("div",{onClick:()=>t(x.file,o),title:T("在右侧面板查看本轮的 diff"),style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",background:"transparent",cursor:"pointer"},onMouseEnter:S=>{S.currentTarget.style.background=l.color.sidebarHover},onMouseLeave:S=>{S.currentTarget.style.background="transparent"},children:[e.jsx(lr,{ext:p,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:j}),v&&e.jsxs("span",{style:{color:l.color.muted},children:[" ",v]})]}),e.jsxs("span",{style:{color:l.color.success,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["+",x.added]}),e.jsxs("span",{style:{color:l.color.error,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["-",x.removed]}),e.jsx("button",{onClick:S=>{S.stopPropagation(),t(x.file,o)},title:T("在右侧面板查看本轮的 diff"),style:m,onMouseEnter:S=>{S.currentTarget.style.background=l.color.sidebarHover,S.currentTarget.style.color=l.color.fg},onMouseLeave:S=>{S.currentTarget.style.background=l.color.surface,S.currentTarget.style.color=l.color.muted},children:T("审查")})]},x.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}),_e="__welcome__";function ut(){return{items:[],busy:!1,queued:[],thinkingLevel:void 0,info:void 0,historyHasMore:!1,historyTotal:0,historyStartIndex:0}}function ct(n){return n.activeId??_e}function je(n,o,t){const r=n.slots[o]??ut(),s=t(r);return s===r?n:{...n,slots:{...n.slots,[o]:s}}}function dr(n,o){switch(o.type){case"activate":return{...n,activeId:o.sessionId};case"clearActive":return{...n,activeId:void 0};case"loadHistory":return je(n,o.sessionId,t=>({...ut(),items:se([],{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 je(n,o.sessionId,t=>({...t,items:se(t.items,{type:"prependHistory",id:o.id,messages:o.messages}),historyHasMore:o.hasMore,historyTotal:o.total,historyStartIndex:o.startIndex}));case"localSystem":return je(n,ct(n),t=>({...t,items:se(t.items,{type:"system",id:o.id,text:o.text})}));case"removeMessage":return je(n,ct(n),t=>({...t,items:se(t.items,{type:"removeMessage",id:o.id})}));case"queueRemove":{const t=n.slots[o.sessionId];return t?{...n,slots:{...n.slots,[o.sessionId]:{...t,queued:t.queued.filter(r=>r.text!==o.text)}}}:n}case"userMessage":return je(n,o.sessionId,t=>({...t,items:se(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 je(n,o.sessionId,t=>({...t,info:o.info,thinkingLevel:o.thinkingLevel??t.thinkingLevel}));case"toggleCollapse":return je(n,ct(n),t=>({...t,items:se(t.items,{type:"toggleCollapse",id:o.id})}));case"forceIdle":return je(n,ct(n),t=>t.busy||t.turnStart!==void 0?{...t,busy:!1,turnStart:void 0}:t);case"moveWelcome":{const t=n.slots[_e];if(!t||t.items.length===0)return n;const r=n.slots[o.sessionId]??ut(),s={...n.slots};return s[o.sessionId]={...r,items:[...r.items,...t.items],thinkingLevel:r.thinkingLevel??t.thinkingLevel},delete s[_e],{...n,slots:s}}case"applyEvent":{const{sessionId:t,id:r,event:s}=o;return je(n,t,i=>cr(i,r,s))}}}function cr(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=se(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:se(n.items,{type:"assistantDelta",id:o,text:t.text})};if(t.kind==="text_done")return{...n,items:se(n.items,{type:"collapseAll"})};if(t.kind==="user_queued"){const r=t.images;return{...n,items:se(n.items,{type:"userMessage",id:o,text:t.text,...r&&r.length>0?{images:r}:{}})}}return t.kind==="error"?{...n,items:se(n.items,{type:"system",id:o,text:`⚠ ${t.text}`})}:n;case"session.thinking":return t.kind==="delta"?{...n,items:se(n.items,{type:"thinkingDelta",id:o,text:t.text})}:{...n,items:se(n.items,{type:"thinkingDone",id:o})};case"session.tool_call":return{...n,items:se(n.items,{type:"toolCallStarted",id:o,toolCallId:t.toolCallId,name:t.name,args:t.args})};case"session.tool_result":return{...n,items:se(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:se(n.items,{type:"system",id:o,text:i})}}default:return n}}function ur(){const[n,o]=a.useReducer(dr,{activeId:void 0,slots:{}}),t=n.slots[n.activeId??_e]??ut();return{state:n,dispatch:o,active:t}}const Zt=n=>1-Math.pow(1-n,3);function fr(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),[f,u]=a.useState(!1),[h,m]=a.useState(0),x=a.useCallback(M=>{t.current=M,m(z=>z+1)},[]);a.useEffect(()=>{const M=t.current;if(!M)return;const z=()=>{const q=M.scrollHeight-M.scrollTop-M.clientHeight<60;r.current=q,u(!q)},I=()=>{z(),i.current||(M.scrollTop<l.current?s.current=!0:r.current&&(s.current=!1)),l.current=M.scrollTop};M.addEventListener("scroll",I,{passive:!0});const P=new ResizeObserver(z);for(const q of M.children)P.observe(q);return z(),()=>{M.removeEventListener("scroll",I),P.disconnect()}},[o,h]),a.useEffect(()=>{c.current=0,s.current=!1;const M=requestAnimationFrame(()=>j(!1));return()=>cancelAnimationFrame(M)},[o,h]),a.useEffect(()=>{const M=c.current;c.current=n,n>M&&!s.current&&r.current&&(M===0?requestAnimationFrame(()=>{S(!1),requestAnimationFrame(()=>S(!1))}):S(!1))},[n]);const g=()=>{s.current||r.current&&S(!1)},v=(M=!0)=>{s.current||S(M)},j=(M=!0,z)=>{s.current=!1;const I=t.current;if(!I)return;const P=z??(M?450:0),q=I.scrollTop;i.current=!0;const X=performance.now();let _=-1,R=0;const w=Z=>{const G=P>0?Math.min(1,(Z-X)/P):1,Q=I.scrollHeight-I.clientHeight;Q===_?R++:R=0,_=Q,I.scrollTop=q+(Q-q)*Zt(G),G<1||R<2?requestAnimationFrame(w):(I.scrollTop=Q,requestAnimationFrame(()=>{i.current=!1}))};requestAnimationFrame(w)},$=(M,z=500)=>{const I=t.current;if(!I||M===0)return;const P=I.scrollTop,q=Math.max(0,P+M);i.current=!0;const X=performance.now(),_=R=>{const w=Math.min(1,(R-X)/z);I.scrollTop=P+(q-P)*Zt(w),w<1?requestAnimationFrame(_):requestAnimationFrame(()=>{i.current=!1})};requestAnimationFrame(_)},p=()=>{c.current=0},S=M=>{const z=t.current;if(z){i.current=!0,r.current=!0;try{M?z.scrollTo({top:z.scrollHeight,behavior:"smooth"}):z.scrollTop=z.scrollHeight}finally{requestAnimationFrame(()=>{i.current=!1})}}};return{scrollRef:t,refCallback:x,nearBottomRef:r,scrollLockedRef:s,lastItemCountRef:c,showBottomBtn:f,followStream:g,scrollToBottom:v,forceScrollToBottom:j,animatedScrollBy:$,resetSnap:p}}function hr(){const[n,o]=a.useState(""),[t,r]=a.useState([]),[s,i]=a.useState([]);return{input:n,setInput:o,attachments:t,fileAttachments:s,attachFiles:u=>{const h=[],m=[];let x=0;for(const g of u)if(g.type.startsWith("image/")){x++;const v=new FileReader;v.addEventListener("load",()=>{h.push({dataUrl:String(v.result),mimeType:g.type,name:g.name}),x-=1,x===0&&(r(j=>[...j,...h]),i(j=>[...j,...m]))}),v.readAsDataURL(g)}else{x++;const v=new FileReader;v.addEventListener("load",()=>{m.push({name:g.name,content:String(v.result)}),x-=1,x===0&&(r(j=>[...j,...h]),i(j=>[...j,...m]))}),v.readAsText(g)}x===0&&(r(g=>[...g,...h]),i(g=>[...g,...m]))},removeAttachment:u=>{const h=t.length;u<h?r(m=>m.filter((x,g)=>g!==u)):i(m=>m.filter((x,g)=>g!==u-h))},submit:u=>{const h=n.trim();if(!h&&t.length===0&&s.length===0)return;o("");const m=t;r([]);const x=s.map(v=>`<file name="${v.name}">
12
+ ${v.content}
13
+ </file>`).join(`
14
+ `),g=[h,x].filter(Boolean).join(`
15
+
16
+ `);i([]),u(g,m)}}}class gr{constructor({url:o,onOpen:t,onClose:r}){Be(this,"ws");Be(this,"listeners",new Set);Be(this,"onOpen");Be(this,"onClose");Be(this,"pendingFrames",[]);Be(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 pr=`ws://${location.host}`;function xr(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 gr({url:pr,onOpen:()=>{}}),c=new co(l);t(c),r.current=c;const f=c.onEvent(u=>{s.current(u)});return()=>{f(),l.close()}},[n]),{client:o,registerOnEvent:i,clientRef:r}}function mr(n,o,t,r){const[s,i]=a.useState([]),l=a.useCallback(async v=>{try{const j=await v.request("project.archived",{});Array.isArray(j)&&i(j)}catch{}},[]),c=a.useCallback(v=>{i(j=>j.filter($=>$.dirKey!==v))},[]),f=a.useCallback(v=>{i(j=>j.map($=>({...$,sessions:$.sessions.filter(p=>p.path!==v)})).filter($=>$.sessions.length>0))},[]),u=a.useCallback(async v=>{if(n)try{await n.request("project.archive",{cwd:v}),l(n),o(n)}catch{}},[n,l,o]),h=a.useCallback(async v=>{if(n)try{await n.request("project.unarchive",{dirKey:v}),c(v),l(n),o(n)}catch{}},[n,l,o,c]),m=a.useCallback(async(v,j,$)=>{n&&t(T("彻底删除项目"),T("将永久删除该归档会话文件,不可恢复。"),T("彻底删除"),()=>{(async()=>{var p;try{await n.request("project.delete",{dirKey:v}),i(M=>M.filter(z=>z.dirKey!==v));const S=s.find(M=>M.dirKey===v);$&&S&&((p=j.find(M=>M.path===$))==null?void 0:p.cwd)===S.cwd&&r($),o(n)}catch{}})()})},[n,t,r,o,s]),x=a.useCallback(async v=>{n&&t(T("删除归档会话"),T("将永久删除该归档会话,不可恢复。"),"删除",()=>{(async()=>{try{await n.request("session.deleteArchived",{sessionFile:v}),i(j=>j.map($=>({...$,sessions:$.sessions.filter(p=>p.path!==v)})).filter($=>$.sessions.length>0)),l(n)}catch{}})()})},[n,t,l]),g=a.useCallback(()=>{n&&t(T("清空全部归档"),T("将永久删除全部 {n} 个归档项目的会话文件,不可恢复。",{n:s.length}),T("全部删除"),()=>{(async()=>{try{await Promise.allSettled(s.map(v=>n.request("project.delete",{dirKey:v.dirKey}))),i([]),l(n)}catch{}})()})},[n,t,s,l]);return{archivedProjects:s,syncArchived:l,archiveProject:u,unarchiveProject:h,deleteProject:m,deleteArchivedSession:x,removeArchivedProject:c,removeArchivedSession:f,clearAllArchived:g}}function yr({items:n,scrollRef:o,activeId:t}){const r=K(),s=a.useMemo(()=>{const h=[];let m=0,x="";for(const g of n)g.kind==="user"?(h.push({msgIndex:m,question:g.text,answer:""}),x="",m++):g.kind==="assistant"&&(x=g.text,h.length>0&&(h[h.length-1].answer=x));return h},[n]),[i,l]=a.useState(null),[c,f]=a.useState(-1),u=a.useRef(null);return a.useEffect(()=>{const h=u.current;h&&(h.scrollTop=h.scrollHeight)},[t]),s.length===0?null:e.jsxs("div",{ref:u,className:"vagus-nav-scroll",style:{position:"absolute",left:6,top:"calc(50dvh - 150px)",width:24,maxHeight:300,overflowY:"auto",pointerEvents:"auto",zIndex:5,display:"flex",flexDirection:"column",padding:"2px 0"},children:[s.map(({msgIndex:h,question:m,answer:x},g)=>{const v=c===-1?99:Math.abs(g-c),j=v===0?26:v===1?19:13,$=v===0?"#6366f1":v===1?"rgba(99,102,241,0.55)":r.color.border;return e.jsx("div",{onMouseDown:p=>p.preventDefault(),onMouseEnter:p=>{f(g),l({index:h,question:m,answer:x,x:p.clientX,y:p.clientY})},onMouseLeave:()=>{f(-1),l(null)},onClick:p=>{var z;p.preventDefault(),p.stopPropagation();const S=document.activeElement;S instanceof HTMLElement&&S.blur();const M=(z=o.current)==null?void 0:z.querySelector(`[data-msg-index="${h}"]`);M&&M.scrollIntoView({behavior:"smooth",block:"start"})},style:{height:15,flexShrink:0,display:"flex",alignItems:"center",cursor:"pointer",pointerEvents:"auto"},children:e.jsx("div",{style:{width:j,height:3,borderRadius:2,background:$,transition:"width 0.15s, background 0.15s",flexShrink:0}})},h)}),i&&rn.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 xn(n){const o=K(),{theme:t}=tt(),[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(So,{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,onCancelQueued:n.onCancelQueued,dock:n.dock})})}function mn(n){const o=K(),[t,r]=a.useState(!1),s=Object.entries(n.statuses).filter(([,f])=>f.length>0),i=Object.entries(n.widgets).filter(([,f])=>f.lines.length>0);if(s.length===0&&i.length===0)return null;const l=f=>({opacity:t?1:0,transform:t?"translateY(0) scale(1)":"translateY(7px) scale(0.97)",transition:`opacity 0.24s ease ${t?70+f*45:0}ms, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) ${t?70+f*45:0}ms`});let c=0;return e.jsxs("div",{style:{position:"relative",display:"flex",alignItems:"center"},onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[e.jsx("div",{style:{position:"absolute",bottom:"calc(100% + 12px)",left:0,zIndex:60,display:"flex",flexDirection:"column",alignItems:"stretch",pointerEvents:t?"auto":"none"},children:e.jsxs("div",{style:{minWidth:300,maxWidth:480,maxHeight:"52vh",overflowY:"auto",display:"flex",flexDirection:"column",gap:8,padding:11,background:o.color.surface,border:`1px solid ${o.color.border}`,borderRadius:14,boxShadow:"0 14px 44px rgba(0,0,0,0.28)",opacity:t?1:0,transform:t?"translateY(0) scale(1)":"translateY(10px) scale(0.94)",transformOrigin:"bottom left",transition:"opacity 0.2s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1)"},children:[s.map(([f,u])=>{const h=l(c++);return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 11px",borderRadius:999,background:o.color.bg,border:`1px solid ${o.color.border}`,fontSize:"0.82em",...h},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,flexShrink:0},children:f}),e.jsx("span",{style:{color:o.color.fg,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:u})]},`s-${f}`)}),i.map(([f,u])=>{const h=l(c++);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:3,padding:"7px 11px",borderRadius:10,background:o.color.bg,border:`1px solid ${o.color.border}`,fontSize:"0.82em",...h},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:6,color:o.color.muted,fontWeight:600},children:[e.jsx("span",{style:{color:o.color.primary},children:"▦"})," ",f]}),u.lines.map((m,x)=>e.jsx("span",{style:{color:o.color.fg,whiteSpace:"pre-wrap",wordBreak:"break-word",paddingLeft:14},children:m},x))]},`w-${f}`)})]})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,padding:"7px 13px",borderRadius:999,background:o.color.surface,border:`1px solid ${t?o.color.primary:o.color.border}`,color:o.color.primary,cursor:"default",fontSize:"0.8em",fontWeight:600,opacity:t?1:.72,boxShadow:t?"0 6px 20px rgba(0,0,0,0.22)":"none",animation:t?"none":"vagus-dock-pulse 2.6s ease-in-out infinite",transition:"opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease"},children:[s.length>0&&e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"currentColor"}}),s.length]}),i.length>0&&e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsx("span",{style:{fontSize:"0.9em"},children:"▦"}),i.length]})]})]})}function yn(n){return n.toast?e.jsx("div",{style:{position:"absolute",bottom:"calc(100% + 12px)",left:"50%",transform:"translateX(-50%)",zIndex:30,maxWidth:"min(90vw, 560px)",animation:"vagus-toast-in 0.2s ease"},children:n.toast}):null}const br={confirm:"确认",select:"请选择",input:"输入"};function en({card:n,onRespond:o}){var h;const t=K(),{event:r}=n,[s,i]=a.useState(""),l=a.useRef(null);a.useEffect(()=>{var m;r.method==="input"&&n.status==="pending"&&((m=l.current)==null||m.focus())},[r.method,n.status]);const c=n.result?n.result.cancelled?"已取消":n.result.confirmed?"已确认":n.result.value??"":"",f=n.status==="answered",u={height:34,padding:"0 14px",borderRadius:9,fontSize:"0.9em",cursor:f?"default":"pointer",fontFamily:"inherit"};return e.jsxs("div",{style:{maxWidth:520,margin:"10px 0 6px",background:f?t.color.bg:t.color.surface,border:`1px solid ${f?t.color.border:t.color.primary}`,borderRadius:14,padding:"14px 16px",boxShadow:f?"none":"0 2px 12px rgba(0,0,0,0.12)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:f?8:10},children:[e.jsx("span",{style:{fontSize:"0.72em",fontWeight:700,letterSpacing:"0.04em",padding:"2px 8px",borderRadius:999,background:f?"transparent":t.color.primary,color:f?t.color.muted:"#fff",border:f?`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??br[r.method]??r.method})]}),r.message&&e.jsx("div",{style:{fontSize:"0.92em",color:t.color.fg,lineHeight:1.6,whiteSpace:"pre-wrap",marginBottom:f?0:12},children:r.message}),f?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(m=>e.jsx("button",{onClick:()=>o({value:m}),style:{...u,width:"100%",textAlign:"left",height:38,padding:"0 14px",border:`1px solid ${t.color.border}`,background:"transparent",color:t.color.fg},onMouseEnter:x=>{x.currentTarget.style.background=t.color.bg},onMouseLeave:x=>{x.currentTarget.style.background="transparent"},children:m},m)),((h=r.options)==null?void 0:h.length)===0&&e.jsx("div",{style:{fontSize:"0.86em",color:t.color.muted,padding:"12px 4px"},children:T("(没有可用选项)")})]}):r.method==="input"?e.jsx("div",{style:{marginBottom:4},children:e.jsx("input",{ref:l,value:s,onChange:m=>i(m.target.value),onKeyDown:m=>{m.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,!f&&e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:6},children:[e.jsx("button",{onClick:()=>o({cancelled:!0}),style:{...u,border:`1px solid ${t.color.border}`,background:"transparent",color:t.color.fg},children:T("取消")}),r.method==="confirm"&&e.jsx("button",{onClick:()=>o({confirmed:!0}),style:{...u,border:"none",background:t.color.primary,color:"#fff",fontWeight:600},children:T("确认")}),r.method==="input"&&e.jsx("button",{onClick:()=>o({value:s}),disabled:s.trim().length===0,style:{...u,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:T("确定")})]})]})}function kr(n){const o=K(),{items:t,busy:r,turnStartTs:s,autoscroll:i}=n,{scrollRef:l,refCallback:c,showBottomBtn:f}=i,u=n.uiCards??[],h=u.filter(p=>p.status==="pending").map(p=>p.event.id).join(","),[m,x]=a.useState("");a.useEffect(()=>{if(h.length>0&&h!==m){x(h);const p=l.current;if(!p)return;const S=p.querySelectorAll('[data-uicard-status="pending"]'),M=S[S.length-1];if(!M)return;const z=p.getBoundingClientRect(),I=M.getBoundingClientRect(),P=I.bottom-z.bottom;if(P<=0&&I.top>=z.top)return;const q=72,X=P>0?P+q:I.top-z.top-q;i.animatedScrollBy(X,750)}},[h,i]),a.useEffect(()=>{const p=l.current,S=n.onLoadMore;if(!p||!S)return;const M=()=>{p.scrollTop<200&&!n.loadingMore&&S()};return p.addEventListener("scroll",M,{passive:!0}),()=>p.removeEventListener("scroll",M)});const g=a.useRef(0),v=a.useRef(0);a.useLayoutEffect(()=>{const p=l.current;if(!p)return;const S=g.current,M=t.length>v.current;if(v.current=t.length,M&&S>0&&p.scrollTop<400){const z=p.scrollHeight-S;z>300&&(p.scrollTop+=z)}g.current=p.scrollHeight});const j=a.useMemo(()=>gn(Yo(t)),[t]),$=a.useMemo(()=>{const p=new Map,S=new Map;let M=0,z=-1,I=-1;for(let _=0;_<j.length;_++){const R=j[_];if(R.kind==="item"&&R.item.kind==="user"){M++;continue}if(R.kind==="work"){z=_,S.has(M)||S.set(M,_);for(const w of R.work)w.kind==="tool"&&w.toolCallId&&p.set(w.toolCallId,_);R.work.some(w=>w.kind==="tool")&&(I=_)}}const P=new Map,q=new Set;for(const _ of u){const R=_.event;let w=R.toolCallId?p.get(R.toolCallId):void 0;if(w===void 0&&(w=R.turn===void 0?void 0:S.get(R.turn)),w===void 0&&(w=I>=0?I:z>=0?z:void 0),w!==void 0){const Z=P.get(w)??[];Z.push(_),P.set(w,Z),q.add(_.event.id)}}const X=u.filter(_=>!q.has(_.event.id));return{byIdx:P,unmatched:X}},[j,u]);return e.jsxs("div",{ref:c,style:{flex:1,display:"flex",flexDirection:"column",minWidth:0,position:"relative",overflowY:"auto",overflowX:"hidden"},children:[e.jsxs("header",{style:{position:"sticky",top:0,zIndex:20,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("div",{style:{position:"sticky",top:0,height:0,zIndex:5},children:e.jsx(yr,{items:t,scrollRef:l,activeId:n.activeId})}),e.jsx("div",{style:{flex:"1 0 auto",paddingTop:28},children:e.jsxs("div",{style:{maxWidth:n.wide?1280: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("加载更早消息…")]}),t.length===0&&(n.showLoading?e.jsx("div",{style:{color:o.color.muted,fontSize:"1em",textAlign:"center",marginTop:40},children:T("加载会话…")}):n.sessionLoading?null:e.jsx("div",{style:{color:o.color.muted,fontSize:"1em",textAlign:"center",marginTop:40},children:T("已连接 · 输入消息开始新会话")})),(()=>{var _;let p=-1;for(let R=t.length-1;R>=0;R--)if(t[R].kind==="user"){p=R;break}let S;for(let R=t.length-1;R>p;R--){const w=t[R];if(w.kind==="thinking"||w.kind==="tool"){S=w;break}}const M=r&&S!==void 0?j.find(R=>R.kind==="work"&&R.work.some(w=>w.id===(S==null?void 0:S.id))):void 0,z=[];let I=0,P=0;const q={contentVisibility:"auto",containIntrinsicSize:"auto 120px"},X=new Set;{let R;for(const w of j)w.kind==="item"?w.item.kind==="assistant"?R=w.item.id:w.item.kind==="user"&&R!==void 0&&(X.add(R),R=void 0):(w.kind==="work"||w.kind==="turnSummary")&&(R!==void 0&&X.add(R),R=void 0);R!==void 0&&X.add(R)}for(const R of j){if(R.kind==="item"){const w=R.item;w.kind==="user"?z.push(e.jsx("div",{"data-msg-index":P++,style:{maxWidth:"100%",...q},children:e.jsx(Ct,{item:w,onToggleCard:n.onToggleCard,onCopy:n.copyMessage,onEditSubmit:n.editSubmit,onFork:n.onFork})},`g${I}`)):z.push(e.jsx("div",{style:q,children:e.jsx(Ct,{item:w,onToggleCard:n.onToggleCard,onCopy:n.copyMessage,onEditSubmit:n.editSubmit,onFork:n.onFork,showCopy:w.kind==="assistant"&&X.has(w.id)&&!r})},`g${I}`))}else if(R.kind==="turnSummary")z.push(e.jsx("div",{style:q,children:e.jsx(ar,{files:R.files,onOpenFile:n.onOpenFile,onRevertAll:()=>n.onRevertAll(R.files.map(w=>w.file)),onExpand:w=>{w&&n.autoscroll.forceScrollToBottom(!0,400)}})},`t${I}`));else{const{work:w}=R,Z=((_=w[0])==null?void 0:_.id)??I,G=R===M,Q=$.byIdx.get(I)??[],ie=Q.length>0?Q.map((y,W)=>e.jsx("div",{"data-uicard-id":y.event.id,"data-uicard-status":y.status,children:e.jsx(en,{card:y,onRespond:O=>{var D;return(D=n.onUiCardRespond)==null?void 0:D.call(n,y,O)}})},`uicardwrap-${y.event.id??W}`)):void 0;let Y=-1;if(Q.length>0){for(let W=R.work.length-1;W>=0;W--)if(R.work[W].kind==="tool"){Y=W;break}const y=Q[0].event;if(typeof y.toolCallId=="string"&&y.toolCallId){const W=R.work.findIndex(O=>O.kind==="tool"&&O.toolCallId===y.toolCallId);W>=0&&(Y=W)}}z.push(e.jsx("div",{style:q,children:e.jsx(tr,{work:w,onToggleItem:y=>n.onToggleCard(y),live:G,startMs:s,attached:ie,attachedAnchor:Y>=0?Y:void 0})},`w${Z}`))}I++}return e.jsx(e.Fragment,{children:z})})(),$.unmatched.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:$.unmatched.map((p,S)=>e.jsx("div",{"data-uicard-id":p.event.id,"data-uicard-status":p.status,children:e.jsx(en,{card:p,onRespond:M=>{var z;return(z=n.onUiCardRespond)==null?void 0:z.call(n,p,M)}})},`uicardwrap-${p.event.id??S}`))}),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"}}),T("等待响应…")]}),e.jsx("div",{})]})}),e.jsxs("div",{style:{position:"sticky",bottom:0,zIndex:20,padding:"10px 28px 10px",background:o.color.bg,flexShrink:0},children:[f&&e.jsx("button",{onClick:()=>i.forceScrollToBottom(),title:T("回到底部"),style:{position:"absolute",right:18,top:-48,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:p=>{p.currentTarget.style.background=o.color.sidebarHover,p.currentTarget.style.color=o.color.fg},onMouseLeave:p=>{p.currentTarget.style.background=o.color.surface,p.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.jsxs("div",{style:{maxWidth:n.wide?1180:960,margin:"0 auto",position:"relative"},children:[e.jsx(yn,{toast:n.toast}),e.jsx(xn,{...n.inputCard,variant:"chat",dock:n.dockStatuses||n.dockWidgets?e.jsx(mn,{statuses:n.dockStatuses??{},widgets:n.dockWidgets??{}}):void 0})]})]})]})}function vr(n){const o=K();return e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column",minWidth:0,justifyContent:"center"},children:e.jsxs("div",{style:{width:"100%",maxWidth:n.wide?900: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:T("你的编码智能体工作台 —— 发送第一条消息开始新的对话")})]}),e.jsx(Io,{projects:n.projects,value:n.activeProject,onChange:n.onSelectProject,onNewProject:n.onNewProject}),e.jsxs("div",{style:{marginTop:10,position:"relative"},children:[e.jsx(yn,{toast:n.toast}),e.jsx(xn,{...n.inputCard,variant:"welcome",dock:n.dockStatuses||n.dockWidgets?e.jsx(mn,{statuses:n.dockStatuses??{},widgets:n.dockWidgets??{}}):void 0})]})]})})}function wr({state:n,onClose:o}){const t=K();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:T("取消")}),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 jr(n){const o=K(),{tabs:t,activeId:r,collapsed:s,onActivate:i,onClose:l,onToggleCollapse:c,render:f,width:u=380,onWidthChange:h}=n,m=14,[x,g]=a.useState(!1),v=a.useRef(null),j=p=>{if(s)return;p.preventDefault(),v.current={startX:p.clientX,startW:u},g(!0);const S=z=>{if(!v.current)return;const I=v.current.startX-z.clientX,P=Math.min(900,Math.max(260,v.current.startW+I));h==null||h(P)},M=()=>{v.current=null,g(!1),document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",M)};document.addEventListener("mousemove",S),document.addEventListener("mouseup",M)},$=t.find(p=>p.id===r)??t[0]??null;return e.jsx("aside",{style:{width:s?m:u,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:T("展开右侧面板"),style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",userSelect:"none",background:o.color.surface,color:"#6366f1",transition:"background 0.15s"},onMouseEnter:p=>{p.currentTarget.style.background="rgba(99,102,241,0.1)"},onMouseLeave:p=>{p.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:j,title:T("拖动调整宽度"),style:{width:4,flexShrink:0,cursor:"col-resize",background:x?"rgba(99,102,241,0.25)":"transparent",transition:"background 0.15s"},onMouseEnter:p=>{p.currentTarget.style.background="rgba(99,102,241,0.15)"},onMouseLeave:p=>{p.currentTarget.style.background=x?"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(p=>{const S=$!==null&&p.id===$.id;return e.jsxs("div",{onClick:()=>i(p.id),style:{display:"flex",alignItems:"center",gap:6,height:36,padding:"0 14px 0 20px",borderRadius:9,background:S?o.color.surface:"transparent",cursor:"pointer",userSelect:"none",flexShrink:0,maxWidth:220,transition:"background 0.15s"},onMouseEnter:M=>{S||(M.currentTarget.style.background=o.color.surface)},onMouseLeave:M=>{S||(M.currentTarget.style.background="transparent")},children:[p.icon,e.jsx("span",{style:{fontSize:"0.9em",fontWeight:S?600:500,color:S?o.color.fg:o.color.muted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:p.label}),e.jsx("button",{onClick:M=>{M.stopPropagation(),l(p.id)},title:`关闭 ${p.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:S?.85:.45,transition:"background 0.15s, color 0.15s, opacity 0.15s"},onMouseEnter:M=>{M.currentTarget.style.background=o.color.sidebarHover,M.currentTarget.style.color=o.color.fg,M.currentTarget.style.opacity="1"},onMouseLeave:M=>{M.currentTarget.style.background="transparent",M.currentTarget.style.color=o.color.muted,M.currentTarget.style.opacity=S?"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"})})})]},p.id)}),e.jsx("div",{style:{flex:1}})]}),e.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden",background:o.color.bg},children:$?f($):e.jsx("div",{style:{height:"100%"}})})]}),e.jsx("div",{onClick:c,title:T("收起右侧面板"),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:p=>{p.currentTarget.style.background="rgba(99,102,241,0.12)",p.currentTarget.style.color="#6366f1"},onMouseLeave:p=>{p.currentTarget.style.background=o.color.surface,p.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 tn={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 Sr({items:n,selected:o,turnId:t,expandedFiles:r,onOpenChange:s}){const i=K(),l=a.useMemo(()=>{if(!t)return[];const x=gn(n);for(let g=x.length-1;g>=0;g--){const v=x[g];if(v.kind==="turnSummary"&&v.files.some(j=>j.turnToolCallId===t))return v.files}return[]},[t,n]),[c,f]=a.useState(()=>{const x=new Set;if(r!==void 0)for(const g of r)l.some(v=>De(v.file)===De(g))&&x.add(g);else l.length>0&&x.add(l[0].file);return x}),u=x=>[...c].some(g=>De(g)===De(x)),h=x=>{const g=new Set(c);u(x)?g.delete([...g].find(v=>De(v)===De(x))):g.add(x),f(g),s==null||s(g.size>0?[...g]:void 0)},m=e.jsx("div",{style:{height:"100%"}});return l.length===0?m:e.jsx("div",{style:{display:"flex",flexDirection:"column",padding:"6px 0"},children:l.map((x,g)=>{const v=x.file.lastIndexOf("/"),j=v>=0?x.file.slice(0,v+1):"",$=v>=0?x.file.slice(v+1):x.file,p=u(x.file),S=Ir(x.diff??"");return e.jsxs("div",{style:{borderBottom:g<l.length-1?`1px solid ${i.color.border}20`:"none"},children:[e.jsxs("div",{onClick:()=>h(x.file),style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",cursor:"pointer",userSelect:"none",background:g%2===1?i.color.surface:"transparent"},onMouseEnter:M=>{M.currentTarget.style.background=i.color.sidebarHover},onMouseLeave:M=>{M.currentTarget.style.background=g%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:p?"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:j}),e.jsx("span",{style:{color:i.color.fg,fontWeight:700},children:$})]}),e.jsxs("span",{style:{color:i.color.success,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["+",S.added]}),e.jsxs("span",{style:{color:i.color.error,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["-",S.removed]})]}),e.jsx("div",{style:{display:"grid",gridTemplateRows:p?"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:x.diff?e.jsx(pn,{diff:x.diff,t:i}):e.jsx("div",{style:{color:i.color.muted,fontSize:"0.78em",padding:6},children:T("该轮无 diff")})})})})]},x.file)})})}function Ir(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 Cr={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 Mr({widgets:n}){const o=K(),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:T("(没有活动的面板)")}):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 vt="cubic-bezier(0.25, 1, 0.5, 1)";function Tr({state:n}){const o=K(),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 Er({result:n}){const o=K(),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:T("✓ 已回退")}):e.jsx("span",{style:{flexShrink:0,color:o.color.error,fontSize:"0.72em",fontWeight:600,whiteSpace:"nowrap"},children:T("✗ 回退失败")})]}),!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 Rr({report:n,onClose:o}){const t=K(),[r,s]=a.useState(!1),i=n.results.filter(g=>g.ok).length,l=n.results.length-i,c=l===0?"ok":i===0?"fail":"partial",f=new Map;for(const g of n.results){const v=f.get(g.file);f.set(g.file,{ok:((v==null?void 0:v.ok)??!0)&&g.ok,error:g.ok?v==null?void 0:v.error:g.error??(v==null?void 0:v.error)})}const u=[...f.entries()].map(([g,v])=>({file:g,...v}));a.useEffect(()=>{const g=requestAnimationFrame(()=>s(!0));return()=>cancelAnimationFrame(g)},[]),a.useEffect(()=>{const g=v=>{v.key==="Escape"&&o()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[o]);const h=c==="ok"?t.color.success:c==="partial"?t.color.warning:t.color.error,m=c==="ok"?`已回退 ${i} 个文件`:c==="partial"?"回退部分失败":"回退失败",x=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 ${vt}`,fontFamily:t.font.sans},children:e.jsxs("div",{onClick:g=>g.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 ${vt}, transform 0.3s ${vt}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12},children:[e.jsx(Tr,{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:m}),e.jsx("button",{onClick:o,"aria-label":T("关闭"),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:g=>{g.currentTarget.style.background=t.color.bg,g.currentTarget.style.color=t.color.fg},onMouseLeave:g=>{g.currentTarget.style.background="transparent",g.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:x}),e.jsx("div",{style:{height:2,background:`linear-gradient(90deg, ${h}, transparent)`,borderRadius:2,marginTop:10,opacity:.5}})]})]}),u.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,marginTop:14,maxHeight:240,overflowY:"auto"},children:u.map(g=>e.jsx(Er,{result:g},g.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:g=>{g.currentTarget.style.filter="brightness(1.1)"},onMouseLeave:g=>{g.currentTarget.style.filter="none"},children:T("关闭")})})]})})}function Wr(n){const{activeId:o,hasEdits:t}=n,[r,s]=a.useState([]),[i,l]=a.useState(void 0),[c,f]=a.useState(!1),[u,h]=a.useState(420),[m,x]=a.useState(new Set),[g,v]=a.useState(void 0),[j,$]=a.useState(void 0),[p,S]=a.useState(void 0),[M,z]=a.useState(!1),I="vagus.rightPanel.v1",P="vagus.rightPanel.review.v1",q=y=>{try{const W=localStorage.getItem(P),D=(W?JSON.parse(W):{})[y];return{turnId:D==null?void 0:D.turnId,selected:D==null?void 0:D.selected,open:D==null?void 0:D.open}}catch{return{}}},X=(y,W,O,D)=>{try{const oe=localStorage.getItem(P),ee=oe?JSON.parse(oe):{};ee[y]={turnId:W,selected:O,open:D},localStorage.setItem(P,JSON.stringify(ee))}catch{}},_=y=>{try{const W=localStorage.getItem(I),D=(W?JSON.parse(W):{})[y];return{collapsed:(D==null?void 0:D.collapsed)===!0,width:(D==null?void 0:D.width)??420,activeTab:D==null?void 0:D.activeTab,diffClosed:(D==null?void 0:D.diffClosed)===!0,has:D!==void 0}}catch{return{collapsed:!0,width:420,has:!1}}},R=(y,W)=>{try{const O=localStorage.getItem(I),D=O?JSON.parse(O):{};D[y]=W,localStorage.setItem(I,JSON.stringify(D))}catch{}},w="vagus.rightPanel.handled.v2",Z=y=>{try{const W=localStorage.getItem(w),O=W?JSON.parse(W):{};return new Set(Array.isArray(O[y])?O[y]:[])}catch{return new Set}},G=(y,W)=>{try{const O=localStorage.getItem(w),D=O?JSON.parse(O):{};D[y]=[...W],localStorage.setItem(w,JSON.stringify(D))}catch{}};a.useLayoutEffect(()=>{if(!o)return;const y=_(o);h(y.width),f(y.has?y.collapsed:!0),y.activeTab!==void 0&&l(y.activeTab),z(y.diffClosed===!0);const W=q(o);$(W.turnId||void 0),S(Array.isArray(W.open)?W.open:void 0),W.selected&&v(W.selected),x(Z(o))},[o]),a.useEffect(()=>{o&&R(o,{collapsed:c,width:u,activeTab:i,diffClosed:M})},[c,u,i,M,o]),a.useEffect(()=>{o&&G(o,m)},[m,o]),a.useEffect(()=>{t?M||(s(y=>y.some(W=>W.id==="diff")?y:[...y,tn]),l(y=>y??"diff")):(s(y=>y.some(W=>W.id==="diff")?y.filter(W=>W.id!=="diff"):y),l(y=>y==="diff"?void 0:y))},[t,M]);const Q=a.useCallback((y,W)=>{var D;z(!1),v(y);const O=(D=W==null?void 0:W[0])==null?void 0:D.turnToolCallId;$(O),S([y]),o&&X(o,O,y,[y]),f(!1),s(oe=>oe.some(ee=>ee.id==="diff")?oe:[...oe,tn]),l("diff")},[o]),ie=a.useCallback(y=>{y==="diff"&&z(!0),s(W=>W.filter(O=>O.id!==y)),l(W=>W===y?void 0:W)},[]),Y=a.useCallback(y=>{S(y),o&&j&&X(o,j,g??(y==null?void 0:y[0])??"",y??[])},[o,j,g]);return{rightTabs:r,rightTabId:i,rightCollapsed:c,rightPanelWidth:u,handledFiles:m,diffSelection:g,reviewTurnId:j,reviewOpen:p,setRightTabs:s,setRightTabId:l,setRightCollapsed:f,setRightPanelWidth:h,setHandledFiles:x,setDiffSelection:v,setReviewOpen:Y,openFileDiff:Q,closeRightTab:ie}}function Lr(n){const{client:o,registerOnEvent:t,dispatch:r,nextId:s,activeId:i,autoscroll:l,followAnswerRef:c,effects:f}=n,u=()=>{c!=null&&c.current&&(c.current=!1,l.scrollToBottom(!0))},h=a.useRef({sessionId:"",text:"",raf:null}),m=()=>{const j=h.current;if(!j.text)return;const $=j.text,p=j.sessionId;j.text="",j.raf=null,r({type:"applyEvent",sessionId:p,id:s(),event:{type:"session.message",sessionId:p,kind:"text_delta",text:$}}),u(),l.followStream()},x=(j,$)=>{const p=h.current;p.sessionId!==j&&(p.raf!==null&&cancelAnimationFrame(p.raf),p.text="",p.sessionId=j),p.text+=$,p.raf===null&&(p.raf=requestAnimationFrame(m))},g=()=>{const j=h.current;j.raf!==null&&(cancelAnimationFrame(j.raf),j.raf=null),j.text&&m()};t(j=>{var S,M,z;const $=o;if(!$)return;const p=i!==void 0&&j.sessionId===i;switch(j.type){case"session.created":f.fetchSessionInfo($,j.sessionId,{updateActivePath:!1}),f.refreshHistory($);return;case"session.turn":j.kind==="end"&&g(),r({type:"applyEvent",sessionId:j.sessionId,id:s(),event:j}),p&&j.kind==="end"&&(f.fetchSessionInfo($,j.sessionId),f.refreshHistory($),$.request("usage.stats",{}).then(I=>f.setUsageStats(I)).catch(()=>{}));return;case"session.message":if(j.kind==="user_queued"&&/<skill\s+name="/.test(j.text)){const I=(S=/<skill\s+name="([^"]+)"/.exec(j.text))==null?void 0:S[1],P=(M=f.shiftSkillText)==null?void 0:M.call(f);r({type:"userMessage",sessionId:j.sessionId,id:s(),text:P??j.text,...I?{skillTag:I}:{}})}else j.kind==="text_delta"?x(j.sessionId,j.text):j.kind==="text_done"?(g(),r({type:"applyEvent",sessionId:j.sessionId,id:s(),event:j})):r({type:"applyEvent",sessionId:j.sessionId,id:s(),event:j});p&&(j.kind==="user_queued"||j.kind==="error")&&l.scrollToBottom(!1);return;case"session.thinking":r({type:"applyEvent",sessionId:j.sessionId,id:s(),event:j}),p&&j.kind==="delta"&&(u(),l.followStream());return;case"session.tool_call":case"session.tool_result":r({type:"applyEvent",sessionId:j.sessionId,id:s(),event:j}),p&&j.type==="session.tool_call"&&f.fetchSessionInfo($,j.sessionId);return;case"session.queue_update":r({type:"applyEvent",sessionId:j.sessionId,id:s(),event:j});return;default:j.type==="ui.request"&&((z=f.onUiRequest)==null||z.call(f,j));return}})}function $r(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 zr=a.lazy(()=>sn(()=>import("./settings-B-1r6vjG.js"),__vite__mapDeps([0,1])).then(n=>({default:n.SettingsView}))),Br=a.lazy(()=>sn(()=>import("./settings-B-1r6vjG.js"),__vite__mapDeps([0,1])).then(n=>({default:n.PluginsView}))),Dr=n=>{navigator.clipboard.writeText(n).catch(()=>{})},wt=n=>n.trim().replace(/\s+/g," "),Oe=[{type:"builtin",name:"compact",description:T("压缩上下文,摘要历史对话,腾出上下文空间")},{type:"builtin",name:"reload",description:T("重新加载扩展、技能、提示词(装包后让 agent 感知新能力)")}];function Fr({transport:n}){var qt,Nt;const o=K(),{client:t,registerOnEvent:r}=xr(n),{state:s,dispatch:i,active:l}=ur(),c=fr(l.items.length,s.activeId),f=hr(),u=l.items.some(d=>d.kind==="tool"&&d.diff!==void 0),[h,m]=a.useState(null),{rightTabs:x,rightTabId:g,rightCollapsed:v,rightPanelWidth:j,diffSelection:$,reviewTurnId:p,reviewOpen:S,setRightTabs:M,setRightTabId:z,setRightCollapsed:I,setRightPanelWidth:P,setReviewOpen:q,openFileDiff:X,closeRightTab:_}=Wr({activeId:s.activeId,hasEdits:u}),R=a.useRef(0),w=()=>++R.current,Z=a.useRef(0),G=a.useRef(0),Q=a.useRef(void 0),ie=d=>{Z.current++;const k=Z.current;Q.current!==void 0&&clearTimeout(Q.current),Q.current=setTimeout(()=>{Q.current=void 0,t&&$t(t,d,k)},80)},[Y,y]=a.useState([]),[W,O]=a.useState(),[D,oe]=a.useState(()=>sessionStorage.getItem("vagus.view.settings")==="1"),[ee,Se]=a.useState(()=>sessionStorage.getItem("vagus.view.plugins")==="1");a.useEffect(()=>{try{sessionStorage.setItem("vagus.view.settings",D?"1":"0"),sessionStorage.setItem("vagus.view.plugins",ee?"1":"0")}catch{}},[D,ee]);const[ye,Fe]=a.useState("appearance"),[Ae,Ie]=a.useState(null),[Ce,ce]=a.useState(new Set),[Le,$e]=a.useState(null),[Me,be]=a.useState({}),b=Me[s.activeId??""]??Me.global??[],[H,A]=a.useState(null),N=a.useRef(null),[J,fe]=a.useState({}),[Te,te]=a.useState({}),qe=a.useRef([]),He=a.useMemo(()=>{const d={};for(const[k,E]of Object.entries(Te))E.lines.length>0&&(!E.sessionId||E.sessionId===s.activeId)&&(d[k]={lines:E.lines});return d},[Te,s.activeId]),xe=H?e.jsxs("div",{style:{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,maxWidth:"min(90vw, 560px)"},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",flexShrink:0,marginTop:5,background:H.type==="error"?"#E5484D":H.type==="warning"?"#B7791F":o.color.primary}}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:H.text})]}):null,Ne=a.useMemo(()=>{const d={};for(const[k,E]of Object.entries(Te))E.placement==="aboveEditor"&&E.lines.length>0&&(!E.sessionId||E.sessionId===s.activeId)&&(d[k]={lines:E.lines});return d},[Te,s.activeId]);a.useEffect(()=>{Object.keys(He).length>0?(M(k=>k.some(E=>E.id==="widget")?k:[...k,Cr]),z(k=>k??"widget")):(M(k=>k.some(E=>E.id==="widget")?k.filter(E=>E.id!=="widget"):k),z(k=>k==="widget"?void 0:k))},[He]);const[ae,ze]=a.useState(),[nt,Ve]=a.useState(!1),[Ue,C]=a.useState(Oe),[F,V]=a.useState(0),le=a.useRef(!1);a.useEffect(()=>{if(D||ee){le.current=!0;return}le.current&&(le.current=!1,V(d=>d+1))},[D,ee]);const[he,Ee]=a.useState(!1),[kn,vn]=a.useState("ask"),[Re,ft]=a.useState(void 0),[ot,Mt]=a.useState(!1),[wn,rt]=a.useState(!1),[Tt,Et]=a.useState(null),[Rt,Wt]=a.useState(!1),Ke=a.useRef(new Map),ht="vagus.lastSession",Lt=a.useRef(!1),Ye=$r(t),gt=a.useCallback((d,k,E,L)=>{$e({title:d,message:k,confirmLabel:E,onConfirm:L})},[]),{modelsConfig:jn,enabledProviders:Je}=Ye;a.useEffect(()=>{if(!s.activeId&&!Re&&Je.length>0&&Je[0].models.length>0){const d=Je[0];ft({providerId:d.id,modelId:d.models[0].id})}},[s.activeId,Re,Je]);const re=a.useCallback(async d=>{try{const k=await d.request("session.history",{});if(Array.isArray(k)){const E=k;y(E);for(const L of E)L.id&&L.path&&Ke.current.set(L.id,L.path)}}catch{}},[]),ge=mr(t,re,gt,d=>{W===d&&(i({type:"activate",sessionId:void 0}),O(void 0))}),{archivedProjects:Sn}=ge;a.useEffect(()=>{if(!ot){rt(!1);return}const d=window.setTimeout(()=>rt(!0),300);return()=>window.clearTimeout(d)},[ot]);const Xe=(d,k,E)=>{d.request("session.info",{sessionId:k}).then(L=>{var ne;const B=L;B!=null&&B.sessionFile&&(Ke.current.set(k,B.sessionFile),(E==null?void 0:E.updateActivePath)!==!1&&O(B.sessionFile)),typeof((ne=B==null?void 0:B.contextUsage)==null?void 0:ne.tokens)=="number"&&Et(null),i({type:"setInfo",sessionId:k,info:B,thinkingLevel:B==null?void 0:B.thinkingLevel})}).catch(()=>{})},$t=async(d,k,E)=>{const L=E??++Z.current,B=new Map;for(const U of Y)B.set(U.path,U.id);const ne=B.get(k),de=ne?s.slots[ne]:void 0;if(ne&&de&&de.items.length>0){O(k),c.resetSnap(),i({type:"activate",sessionId:ne}),Xe(d,ne),re(d),V(U=>U+1);return}G.current++,Mt(!0),i({type:"clearActive"}),rt(!0);try{O(k);const U=await d.request("session.open",{sessionFile:k,limit:200}),ve=U.sessionId;if(L!==Z.current){const Pe=s.slots[ve];(!Pe||Pe.items.length===0)&&i({type:"loadHistory",sessionId:ve,id:w(),messages:U.messages,hasMore:U.hasMore,total:U.total,startIndex:U.startIndex});return}const st=s.slots[ve];(!st||st.items.length===0)&&i({type:"loadHistory",sessionId:ve,id:w(),messages:U.messages,hasMore:U.hasMore,total:U.total,startIndex:U.startIndex}),c.resetSnap(),i({type:"activate",sessionId:ve}),U.sessionFile&&O(U.sessionFile),Xe(d,ve),re(d),V(Pe=>Pe+1)}catch(U){i({type:"localSystem",id:w(),text:`无法打开会话: ${U instanceof Error?U.message:String(U)}`})}finally{G.current--,G.current<=0&&(G.current=0,Mt(!1),rt(!1))}},pt=a.useRef(!1),[In,zt]=a.useState(!1),Cn=a.useCallback(async()=>{if(!t||!s.activeId||pt.current)return;const d=s.activeId,k=s.slots[d];if(!(k!=null&&k.historyHasMore)||!k.historyStartIndex||k.items.length===0)return;pt.current=!0,zt(!0);const E=Ke.current.get(d)??W;try{const L=await t.request("session.page",{sessionFile:E,limit:200,beforeIndex:k.historyStartIndex});i({type:"prependHistory",sessionId:d,id:w(),messages:L.messages,hasMore:L.hasMore,total:L.total,startIndex:L.startIndex})}catch{}finally{pt.current=!1,zt(!1)}},[t,s.activeId,s.slots,W]),Bt=a.useRef(!0);a.useEffect(()=>{if(Bt.current){Bt.current=!1;return}try{W?localStorage.setItem(ht,W):localStorage.removeItem(ht)}catch{}},[W]),a.useEffect(()=>{if(!t||Lt.current)return;Lt.current=!0;let d;try{d=localStorage.getItem(ht)??void 0}catch{d=void 0}d&&(async()=>{try{await $t(t,d)}catch{}})()},[t]);const Mn=d=>{switch(d){case"compact":return Jn(),!0;case"reload":return A({text:T("正在重新加载扩展与技能…"),type:"info"}),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>A(null),2500),t&&s.activeId&&t.request("session.reload",{sessionId:s.activeId}).then(()=>{xt(),A({text:T("✅ 已重新加载扩展与技能"),type:"info"}),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>A(null),2500)}).catch(k=>{A({text:`reload 失败:${k instanceof Error?k.message:String(k)}`,type:"error"}),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>A(null),4e3)}),!0;default:return!1}},Dt=(d,k)=>{d.trim().startsWith("/skill:")&&qe.current.push(d.trim()),t&&(async()=>{var E;try{const L=d.split(/\s+/)[0]??"";if(L.startsWith("/")&&Mn(L.slice(1)))return;let B=s.activeId;if(!B||B===_e){if(B=(await t.request("session.create",{cwd:ae??void 0})).sessionId,(E=s.slots[_e])!=null&&E.items.length&&i({type:"moveWelcome",sessionId:B}),i({type:"activate",sessionId:B}),Xe(t,B),Re){try{await t.request("session.model.set",{sessionId:B,providerId:Re.providerId,modelId:Re.modelId})}catch{}ft(void 0)}re(t)}await t.request("session.prompt",{sessionId:B,text:d,images:k}),re(t)}catch(L){i({type:"forceIdle"}),i({type:"localSystem",id:w(),text:`error: ${L instanceof Error?L.message:String(L)}`})}})()},Tn=d=>{Dt(d,[])},Ft=a.useRef(()=>{}),En=a.useCallback((d,k,E)=>{gt(T("派生新会话"),T(`从这条消息开始创建一条新的会话,原会话保持不变。
18
+ 新会话只包含到此为止的上下文。`),T("确认派生"),()=>{Ft.current(k,E)})},[gt]),Rn=a.useCallback(async(d,k)=>{const E=t,L=s.activeId;if(!(!E||!L)){A({text:T("正在派生新会话…"),type:"info"}),N.current&&clearTimeout(N.current);try{const B=await E.request("session.forkPoints",{sessionId:L}),ne=(B??[]).findLast(we=>wt(we.text)===wt(d));if(!ne){const we=(B??[]).slice(0,3).map(lt=>JSON.stringify(lt.text.slice(0,60))).join(", ");A({text:`未找到匹配的派生点 (${(B??[]).length} 个点,样本: ${we})`,type:"error"}),console.log("[fork] match failed. user text:",JSON.stringify(d),"| normText:",wt(d)),console.log("[fork] first 3 fork points:",(B??[]).slice(0,3).map(lt=>({id:lt.entryId,text:lt.text.slice(0,80)})));return}const de=await E.request("session.fork",{sessionId:L,entryId:ne.entryId});if(!(de!=null&&de.sessionId)){A({text:T("派生失败:daemon 未返回新会话"),type:"error"});return}const U=Y.find(we=>we.id===L||we.path===W),ve=(U==null?void 0:U.name)||(U==null?void 0:U.firstMessage)||T("新会话"),st=Y.filter(we=>(we.name||we.firstMessage||"").startsWith(ve)).length,Pe=`${ve} (${st+1})`;try{await E.request("session.renameFile",{sessionFile:de.sessionFile,name:Pe})}catch{}re(E);const it=await E.request("session.open",{sessionFile:de.sessionFile,limit:200});i({type:"loadHistory",sessionId:de.sessionId,id:w(),messages:it.messages,hasMore:it.hasMore,total:it.total,startIndex:it.startIndex}),i({type:"activate",sessionId:de.sessionId}),O(de.sessionFile),re(E),c.resetSnap(),f.setInput(k),A({text:T("✅ 新会话已派生,可编辑消息后发送"),type:"info"}),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>A(null),2500)}catch(B){A({text:`派生失败:${B instanceof Error?B.message:String(B)}`,type:"error"}),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>A(null),4e3)}}},[t,s.activeId,i,re,O,c,Y,W,A,N,f]);Ft.current=Rn;const Wn=a.useCallback(async d=>{if(!(!t||!s.activeId||d.length===0))try{const k=await t.request("tool.revertBatch",{sessionId:s.activeId,files:d}),E=((k==null?void 0:k.results)??[]).map(L=>({file:L.file,toolCallId:L.file,ok:L.ok,error:L.error}));m({results:E})}catch(k){console.log("[frontend revertBatch catch]",String(k)),m({results:d.map(E=>({file:E,toolCallId:E,ok:!1,error:k instanceof Error?k.message:String(k)}))})}},[t,s.activeId,m]),Ln=()=>{c.resetSnap(),i({type:"activate",sessionId:void 0}),O(void 0),V(d=>d+1)},$n=async(d,k)=>{if(t)try{await t.request("session.renameFile",{sessionFile:d,name:k}),re(t)}catch{}},zn=async d=>{if(t)try{const k=Y.find(E=>E.path===d);await t.request("session.delete",{sessionFile:d,sessionId:k==null?void 0:k.id}),W===d&&(i({type:"activate",sessionId:void 0}),O(void 0)),re(t)}catch{}},Bn=async d=>{if(t)try{await t.request("session.archive",{sessionFile:d}),y(k=>k.filter(E=>E.path!==d)),W===d&&(i({type:"activate",sessionId:void 0}),O(void 0)),re(t),ge.syncArchived(t)}catch{}},Dn=async d=>{if(t)try{await t.request("session.restore",{sessionFile:d}),ge.removeArchivedSession(d),re(t),ge.syncArchived(t)}catch{}},Fn=async d=>{if(t)try{const k=Ce.has(d);await t.request("session.pin",{sessionFile:d,pinned:!k}),ce(E=>{const L=new Set(E);return k?L.delete(d):L.add(d),L}),re(t)}catch{}},An=a.useMemo(()=>{const d=new Set,k=[];for(const E of Y){if(d.has(E.cwd))continue;d.add(E.cwd);const L=E.cwd.replace(/\\/g,"/").split("/").filter(Boolean);k.push({id:E.cwd,name:L[L.length-1]??E.cwd,available:!0})}return k},[Y]),Hn=a.useMemo(()=>{const d=new Set;for(const[k,E]of Object.entries(s.slots))if(E.busy){const L=Ke.current.get(k);L&&d.add(L)}return d},[s.slots]),Pn=((qt=l.info)==null?void 0:qt.model)??(Re==null?void 0:Re.modelId),On=d=>{if(d.method==="widgetLines"){te(E=>{const L=d.widgetKey??"";if(!L)return E;const B={...E};if(!d.lines||d.lines.length===0)delete B[L];else{const ne=Array.isArray(d.lines)?d.lines:String(d.lines??"").split(`
19
+ `);B[L]={lines:ne,placement:d.placement??"aboveEditor",sessionId:d.sessionId}}return B});return}if(d.method==="setStatus"){fe(E=>{const L=d.statusKey??"";if(!L)return E;const B={...E};return d.statusText==null?delete B[L]:B[L]=d.statusText,B});return}if(d.method==="notify"){A({text:d.message??d.title??"",type:d.notifyType??"info"}),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>A(null),3500);return}if(!t)return;const k=d.sessionId??"global";be(E=>({...E,[k]:[...E[k]??[],{event:d,sessionId:d.sessionId,status:"pending"}]}))},At=a.useRef(!1),_n=(d,k)=>{const E=d.sessionId??"global";be(L=>({...L,[E]:(L[E]??[]).map(B=>B.event.id===d.event.id?{...B,status:"answered",result:k}:B)})),At.current=!0,t==null||t.request("ui.respond",{id:d.event.id,...k}).catch(()=>{})};Lr({client:t,registerOnEvent:r,followAnswerRef:At,dispatch:i,nextId:w,activeId:s.activeId,autoscroll:c,effects:{fetchSessionInfo:Xe,refreshHistory:re,setUsageStats:Ie,onUiRequest:On,shiftSkillText:()=>qe.current.shift()}}),a.useEffect(()=>{t&&(t.request("ping").then(()=>{}).catch(()=>{}),Ye.refreshModels(),t.request("usage.stats",{}).then(d=>Ie(d)).catch(()=>{}),t.request("session.pins").then(d=>{Array.isArray(d)&&ce(new Set(d))}).catch(()=>{}),t.request("ui.widgets",{}).then(d=>{const k=d;if(k){const E={};for(const[L,B]of Object.entries(k))B!=null&&B.lines&&B.lines.length>0&&(E[L]={lines:B.lines,placement:B.placement==="belowEditor"?"belowEditor":"aboveEditor",sessionId:B.sessionId});te(E)}}).catch(()=>{}),t.request("ui.pending",{}).then(d=>{const k=d;if(k&&k.length>0){const E={};for(const L of k){const B=L.request,ne=B.sessionId??"global";E[ne]=[...E[ne]??[],{event:B,sessionId:B.sessionId,status:"pending"}]}be(E)}}).catch(()=>{}),t.request("ui.history",{}).then(d=>{const k=d;k&&be(E=>{const L={...E};for(const[B,ne]of Object.entries(k)){const de=ne.map(U=>({event:U.request,sessionId:U.request.sessionId,status:"answered",result:U.result}));L[B]=[...L[B]??[],...de]}return L})}).catch(()=>{}),ge.syncArchived(t),re(t))},[t]),a.useEffect(()=>{const d=k=>{if(k.target.closest("textarea, input, button, [role='menu'], [role='menuitem'], [contenteditable]"))return;const L=document.activeElement;L instanceof HTMLElement&&L.blur()};return document.addEventListener("mousedown",d,!0),()=>document.removeEventListener("mousedown",d,!0)},[]);const qn=d=>{ze(d),localStorage.setItem("vagus.activeProject",d)};a.useEffect(()=>{const d=localStorage.getItem("vagus.activeProject");d&&ze(d)},[]);const Nn=async d=>{if(Ve(!1),!(!d||!t)){ze(d),localStorage.setItem("vagus.activeProject",d);try{const k=await t.request("session.create",{cwd:d});i({type:"activate",sessionId:k.sessionId}),re(t),V(E=>E+1)}catch{}}},Vn=async(d,k)=>{if(ft({providerId:d,modelId:k}),s.activeId&&i({type:"setInfo",sessionId:s.activeId,info:l.info?{...l.info,model:k,activeProvider:d}:void 0}),!(!t||!s.activeId))try{await t.request("session.model.set",{sessionId:s.activeId,providerId:d,modelId:k})}catch{}},Un=()=>{!t||!s.activeId||t.request("session.abort",{sessionId:s.activeId}).catch(()=>{})},Kn=()=>{!t||!s.activeId||t.request("session.abortCompaction",{sessionId:s.activeId}).catch(()=>{})},Yn=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{}},Jn=async()=>{if(!t||!s.activeId)return;const d=s.activeId,k=w();Wt(!0),i({type:"localSystem",id:k,text:T("正在压缩上下文…")});try{const E=await t.request("session.compact",{sessionId:d});i({type:"removeMessage",id:k});const L=E==null?void 0:E.estimatedTokensAfter,B=typeof L=="number"&&L>0?`${(L/1e3).toFixed(1)}K`:"";Et(typeof L=="number"?L:null),i({type:"localSystem",id:w(),text:`◌ 前文已摘要${B?` · 剩余 ${B} 上下文`:""}`}),Xe(t,d),t.request("usage.stats",{}).then(ne=>Ie(ne)).catch(()=>{})}catch(E){i({type:"removeMessage",id:k});const L=E instanceof Error?E.message:String(E),B=L.includes("Nothing to compact")||L.includes("Already compacted")?"上下文还没大到需要压缩(会话内容太少,或刚刚已经压缩过)":`压缩失败:${L}`;i({type:"localSystem",id:w(),text:B})}finally{Wt(!1)}},Xn=async()=>t?await t.request("project.roots",{}):{places:[],drives:[]},Gn=async d=>t?await t.request("project.listDir",{dir:d}):{path:d,entries:[]},Ht=async()=>{if(!t)return Oe;try{const d=await t.request("commands.list",{sessionId:s.activeId??void 0});return[...Oe,...(d.extensions??[]).map(k=>({type:"extension",name:k.name,description:k.description??""})),...(d.templates??[]).map(k=>({type:"template",name:k.name,description:k.description??""})),...(d.skills??[]).map(k=>({type:"skill",name:`skill:${k.name}`,description:k.description??""}))]}catch{return Oe}};a.useEffect(()=>{t&&Ht().then(C).catch(()=>C(Oe))},[t,s.activeId]);const xt=()=>{Ht().then(C).catch(()=>C(Oe))},Qn=d=>{Ee(!1),d&&f.setInput(k=>`${k}${d} `)},Pt={value:f.input,onChange:f.setInput,onSubmit:()=>f.submit((d,k)=>{c.forceScrollToBottom(!1,750),Dt(d,k)}),usage:l.info?Tt!==null?{...l.info,contextUsage:{tokens:Tt,contextWindow:((Nt=l.info.contextUsage)==null?void 0:Nt.contextWindow)??1e6,percent:null}}:l.info:null,providers:Je,onSwitchModel:(d,k)=>void Vn(d,k),onSetThinking:d=>void Yn(d),thinkingLevel:l.thinkingLevel??"low",permissionMode:kn,onTogglePermission:()=>vn(d=>d==="ask"?"auto":"ask"),attachments:f.attachments,fileAttachments:f.fileAttachments,onAttach:f.attachFiles,onRemoveAttachment:f.removeAttachment,busy:l.busy||Rt,onStop:Rt?Kn:Un,hasPendingDialog:b.some(d=>d.status==="pending"),selectedModel:Pn,onCommand:()=>{xt(),Ee(!0)},onRefreshCommands:xt,commands:Ue,onPickCommand:()=>{},focusSignal:F,queuedMessages:l.queued,onCancelQueued:d=>{t==null||t.request("session.cancelQueued",{sessionId:s.activeId,text:d}),i({type:"queueRemove",sessionId:s.activeId??"",text:d})}},[Ot,Zn]=a.useState(()=>{try{return localStorage.getItem("vagus.sidebar.collapsed")==="1"}catch{return!1}}),_t={sessions:Y,activePath:W,onNewSession:Ln,onCollapsedChange:Zn,onClearAllArchived:()=>ge.clearAllArchived(),onOpenSession:ie,onOpenSettings:()=>oe(!0),onOpenPlugins:()=>Se(!0),onRenameSession:$n,onDeleteSession:zn,onArchiveSession:Bn,onRestoreSession:Dn,onDeleteArchivedSession:ge.deleteArchivedSession,onTogglePin:Fn,pinnedSessions:Ce,archivedProjects:Sn,onArchiveProject:async d=>{y(k=>k.filter(E=>E.cwd!==d)),await ge.archiveProject(d)},onUnarchiveProject:async d=>{ge.removeArchivedProject(d),await ge.unarchiveProject(d)},onDeleteProject:d=>ge.deleteProject(d,Y,W),busyPaths:Hn,pendingDialogPaths:new Set(Object.entries(Me).filter(([,d])=>d.some(k=>k.status==="pending")).map(([d])=>Ke.current.get(d)).filter(d=>!!d))},{uiFontSize:eo}=on(),to=!s.activeId&&!D&&!ot,ke=Y.find(d=>d.path===W),no=(ke==null?void 0:ke.name)??(ke==null?void 0:ke.firstMessage)??"",oo=ke==null?void 0:ke.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:eo},children:[D?e.jsx(a.Suspense,{fallback:null,children:e.jsx(zr,{providers:jn,usageStats:Ae,onClose:()=>oe(!1),onSave:Ye.saveModels,onRefresh:Ye.refreshModels,onTest:Ye.testModel,cat:ye,onCatChange:Fe,projectCwd:ae,request:(d,k)=>t.request(d,k),onProbe:async d=>t?await t.request("models.probe",d):{ok:!1}})}):ee?e.jsx(a.Suspense,{fallback:null,children:e.jsx(Br,{request:(d,k)=>t.request(d,k),onClose:()=>Se(!1),t:o})}):to?e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"row",minWidth:0},children:[e.jsx(Kt,{..._t}),e.jsx(vr,{wide:Ot,activeProject:ae,projects:An,onSelectProject:qn,onNewProject:()=>Ve(!0),inputCard:Pt,dockStatuses:J,dockWidgets:Ne,toast:xe})]}):e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"row",minWidth:0},children:[e.jsx(Kt,{..._t}),e.jsx(kr,{wide:Ot,items:l.items,busy:l.busy,turnStartTs:l.turnStart,sessionLoading:ot,showLoading:wn,autoscroll:c,sessionName:no,sessionCwd:oo,activeId:s.activeId,onToggleCard:d=>i({type:"toggleCollapse",id:d}),copyMessage:Dr,editSubmit:Tn,onFork:En,inputCard:Pt,uiCards:b,onUiCardRespond:_n,onLoadMore:Cn,loadingMore:In,dockStatuses:J,dockWidgets:Ne,toast:xe,onOpenFile:X,onRevertAll:d=>void Wn(d)}),e.jsx(jr,{tabs:x,activeId:g,collapsed:v,onActivate:d=>z(d),onClose:d=>_(d),onToggleCollapse:()=>I(d=>!d),width:j,onWidthChange:P,render:d=>d.id==="diff"?e.jsx(Sr,{items:l.items,selected:$,turnId:p,expandedFiles:S,onOpenChange:k=>q(k)},`${s.activeId}-${p??"none"}`):d.id==="widget"?e.jsx(Mr,{widgets:He}):null})]}),nt&&e.jsx(To,{listDir:Gn,roots:Xn,onPick:d=>void Nn(d)}),he&&e.jsx(jo,{commands:Ue,onPick:Qn}),Le&&e.jsx(wr,{state:Le,onClose:()=>$e(null)}),h&&e.jsx(Rr,{report:h,onClose:()=>m(null)})]})}po("en",xo);function Ar(){return e.jsx(uo,{children:e.jsx(Hr,{})})}function Hr(){const{locale:n}=fo();return e.jsx(ho,{children:e.jsx(go,{children:e.jsx(Fr,{},n)})})}const bn=document.getElementById("root");if(!bn)throw new Error("missing #root element — index.html is malformed");mo.createRoot(bn).render(e.jsx(Ar,{}));
package/gui/index.html CHANGED
@@ -23,11 +23,18 @@
23
23
  @keyframes vagus-spin { to { transform: rotate(360deg); } }
24
24
  @keyframes vagus-breath { 0%, 100% { box-shadow: 0 6px 28px rgba(99,102,241,0.08), 0 0 0 0 rgba(99,102,241,0); border-color: rgba(99,102,241,0.2); } 50% { box-shadow: 0 6px 36px rgba(99,102,241,0.18), 0 0 0 3px rgba(99,102,241,0.06); border-color: rgba(99,102,241,0.5); } }
25
25
  /* Extension-notify toast slide-up */
26
+ @keyframes vagus-dock-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(120,140,255,0); } 50% { box-shadow: 0 0 0 5px rgba(120,140,255,0.13); } }
26
27
  @keyframes vagus-toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
27
28
  /* Sidebar marquee: single-direction seamless loop; content is doubled while hovered, -50% = exactly one copy+gap */
28
29
  @keyframes vagus-marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
29
30
  /* Row hover hides the time label so the name window widens for scrolling */
30
- .vagus-session-row:hover .vagus-row-time { display: none; }
31
+ /* Hover: the time label fades to zero width WITHOUT removing its layout slot —
32
+ pin/busy icon columns stay perfectly aligned across rows (no jump).
33
+ max-width transition animates the reclaimed space smoothly. */
34
+ /* Hover: fade only — the label keeps its layout slot, so the pin/busy
35
+ icon columns never shift (zero layout change on hover). */
36
+ .vagus-row-time { transition: opacity 0.15s ease; }
37
+ .vagus-session-row:hover .vagus-row-time { opacity: 0; }
31
38
  /* Hide the history-nav rail's own scrollbar (ticks overflow internally) */
32
39
  .vagus-nav-scroll { scrollbar-width: none; -ms-overflow-style: none; }
33
40
  .vagus-nav-scroll::-webkit-scrollbar { display: none; }
@@ -35,7 +42,7 @@
35
42
  .vagus-revert-btn { pointer-events: none; }
36
43
  div:hover > .vagus-revert-btn, .vagus-revert-btn:hover { opacity: 1 !important; pointer-events: auto; }
37
44
  </style>
38
- <script type="module" crossorigin src="/assets/index-DL6d29Yn.js"></script>
45
+ <script type="module" crossorigin src="/assets/index-DRbNBgQ5.js"></script>
39
46
  <link rel="modulepreload" crossorigin href="/assets/vendor-D5Ls3_dM.js">
40
47
 
41
48
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versot/vaguspi",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "pi-web — a web frontend for the pi coding agent. Launch the full chat UI in your browser with one command.",
5
5
  "keywords": [
6
6
  "pi",