@versot/vaguspi 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +0,0 @@
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 ze=(n,o,t)=>so(n,typeof o!="symbol"?o+"":o,t);import{j as e,a as U,r as a,t as T,u as et,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(y=>({status:"fulfilled",value:y}),y=>({status:"rejected",reason:y}))))};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"),y=h?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${y}`))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)})},fe="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 wt(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 jt({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=U(),[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:fe},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"})})]}),wt(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:fe},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"})})]}),wt(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:fe},children:[e.jsx(jt,{}),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",Xe="#8b5cf6",Ut="0 0 0 2px rgba(99,102,241,0.4)";function xt({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:y,onDeleteArchivedSession:x,onTogglePin:g,pinnedSessions:v=new Set,archivedProjects:S=[],onArchiveProject:$,onUnarchiveProject:p,onDeleteProject:j,busyPaths:C=new Set,pendingDialogPaths:z=new Set}){const I=U(),{theme:H}=et(),q="vagus.sidebar.collapsedProjects",[Y,_]=a.useState(()=>{try{return new Set(JSON.parse(localStorage.getItem(q)??"[]"))}catch{return new Set}}),[w,W]=a.useState(null),[G,Z]=a.useState(),[X,ie]=a.useState(""),K=a.useMemo(()=>{const m=new Map;for(const O of n){const A=m.get(O.cwd)??[];A.push(O),m.set(O.cwd,A)}return[...m.entries()].toSorted((O,A)=>A[1][0].modified.localeCompare(O[1][0].modified)).map(([O,A])=>[O,A.toSorted((N,J)=>Number(v.has(J.path))-Number(v.has(N.path))||J.modified.localeCompare(N.modified))])},[n,v]),b=m=>{_(O=>{const A=new Set(O);A.has(m)?A.delete(m):A.add(m);try{localStorage.setItem(q,JSON.stringify([...A]))}catch{}return A})},R=(m,O,A=!1)=>{m.preventDefault(),W({x:m.clientX,y:m.clientY,kind:"session",session:O,archived:A})},P=(m,O)=>{m.preventDefault(),W({x:m.clientX,y:m.clientY,kind:"project",cwd:O})},D=()=>W(null);a.useEffect(()=>{if(!w)return;const m=A=>{A.target.closest("[data-context-menu]")||D()},O=A=>{A.key==="Escape"&&D()};return document.addEventListener("mousedown",m),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",O)}},[w]);const le=m=>{Z(m.path),ie(m.name??m.firstMessage.slice(0,40)),W(null)},Q={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"},ye=m=>{const O=X.trim();Z(void 0),O&&l&&l(m,O)},Se=n.find(m=>m.path===o),De=Se==null?void 0:Se.cwd,Fe=280,Ie=48,ue="vagus.sidebar.collapsed",[Ce,Ae]=a.useState(()=>{try{return localStorage.getItem(ue)==="1"}catch{return!1}}),Me=m=>{Ae(m),h==null||h(m);try{localStorage.setItem(ue,m?"1":"0")}catch{}},Te=H==="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}, ${Xe})`,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:Fe,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:()=>Me(!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:fe,outline:"none"},onMouseEnter:m=>{m.currentTarget.style.background=I.color.sidebarHover,m.currentTarget.style.color=I.color.fg},onMouseLeave:m=>{m.currentTarget.style.background="transparent",m.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}, ${Xe})`,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:fe,outline:"none"},onMouseEnter:m=>{m.currentTarget.style.background=I.color.sidebarHover,m.currentTarget.style.color=I.color.fg},onMouseLeave:m=>{m.currentTarget.style.background="transparent",m.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:fe,outline:"none"},onMouseEnter:m=>{m.currentTarget.style.background=I.color.sidebarHover,m.currentTarget.style.color=I.color.fg},onMouseLeave:m=>{m.currentTarget.style.background="transparent",m.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},${Xe})`,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:()=>Me(!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:fe,outline:"none",flexShrink:0},onMouseEnter:m=>{m.currentTarget.style.background=I.color.sidebarHover,m.currentTarget.style.color=I.color.fg},onMouseLeave:m=>{m.currentTarget.style.background="transparent",m.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:m=>{m.currentTarget.style.filter="brightness(1.08)",m.currentTarget.style.boxShadow="0 4px 16px rgba(99,102,241,0.45)"},onMouseLeave:m=>{m.currentTarget.style.filter="none",m.currentTarget.style.boxShadow="0 2px 10px rgba(99,102,241,0.35)"},onMouseDown:m=>{m.currentTarget.style.transform="scale(0.98)"},onMouseUp:m=>{m.currentTarget.style.transform="scale(1)"},onFocus:m=>{m.currentTarget.style.boxShadow=`${Ut}, 0 2px 10px rgba(99,102,241,0.35)`},onBlur:m=>{m.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:m=>{m.currentTarget.style.background=I.color.sidebarHover,m.currentTarget.style.color=I.color.fg},onMouseLeave:m=>{m.currentTarget.style.background="transparent",m.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:fe,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("项目")}),K.length===0&&e.jsx("div",{style:{fontSize:"0.85em",color:I.color.muted,padding:"8px 10px",lineHeight:1.5},children:T("暂无会话 — 点击“新对话”开始。")}),K.map(([m,O])=>{const A=!Y.has(m),N=De===m;return e.jsxs("div",{style:{marginBottom:2},children:[e.jsxs("div",{onClick:()=>b(m),onContextMenu:J=>P(J,m),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:fe},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},${Xe})`}}),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(xt,{text:an(m),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"})})]}),wt(A,e.jsx("div",{style:{paddingLeft:30},children:O.map(J=>{const he=J.path===o,Ee=G===J.path;return e.jsxs("div",{className:"vagus-session-row",onClick:()=>r(J.path),onContextMenu:ee=>R(ee,J),onMouseEnter:ee=>{he||(ee.currentTarget.style.background=I.color.sidebarHover)},onMouseLeave:ee=>{he||(ee.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:he?I.color.fg:I.color.muted,fontWeight:he?500:400,background:he?Te:"transparent",overflow:"hidden",whiteSpace:"nowrap",transition:fe},children:[he&&e.jsx("span",{style:{position:"absolute",left:0,top:8,bottom:8,width:3,borderRadius:3,background:`linear-gradient(180deg,${We},${Xe})`}}),e.jsx(jt,{color:he?We:void 0}),Ee?e.jsx("input",{autoFocus:!0,value:X,onChange:ee=>ie(ee.target.value),onBlur:ee=>{ee.currentTarget.style.boxShadow="none",ye(J.path)},onKeyDown:ee=>{ee.key==="Enter"&&ye(J.path),ee.key==="Escape"&&Z(void 0)},onClick:ee=>ee.stopPropagation(),onFocus:ee=>{ee.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(xt,{text:(J.name??J.firstMessage.slice(0,40))||"(空会话)"}),e.jsx("span",{style:{width:12,display:"inline-flex",justifyContent:"center",alignItems:"center",flexShrink:0},children:(C.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)})}))]},m)}),K.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(m=>e.jsxs("div",{onClick:()=>r(m.path),onContextMenu:O=>R(O,m),onMouseEnter:O=>O.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:O=>O.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:fe},children:[e.jsx(jt,{}),e.jsx(xt,{text:m.name??m.firstMessage.slice(0,40)})]},m.id))})]}),e.jsx(vo,{archivedProjects:S,busyPaths:C,collapsed:Y,onToggleProject:b,onOpenSession:r,onSessionContextMenu:(m,O,A)=>R(m,O,A),onProjectContextMenu:(m,O,A)=>{m.preventDefault(),W({x:m.clientX,y:m.clientY,kind:"archived",cwd:O,dirKey:A})},onSectionContextMenu:m=>W({x:m.clientX,y:m.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:m=>{m.currentTarget.style.background=I.color.sidebarHover,m.currentTarget.style.color=I.color.fg},onMouseLeave:m=>{m.currentTarget.style.background="transparent",m.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:fe},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("设置")})]})}),w&&e.jsxs("div",{"data-context-menu":!0,style:{position:"fixed",left:w.x,top:w.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:[w.kind==="session"&&!w.archived&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>le(w.session),style:Q,onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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(w.session.path)},style:Q,onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.currentTarget.style.background="transparent",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:v.has(w.session.path)?"#6366f1":"none",stroke:v.has(w.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(w.session.path)},style:Q,onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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("归档")]})]}),w.kind==="session"&&w.archived&&e.jsxs(e.Fragment,{children:[y&&e.jsxs("div",{onClick:()=>{W(null),y(w.session.path)},style:Q,onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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(w.session.path)},style:{...Q,color:"#E5484D"},onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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("删除")]})]}),w.kind==="project"&&$&&e.jsxs("div",{onClick:()=>{W(null),$(w.cwd)},style:Q,onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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("归档项目")]}),w.kind==="archivedAll"&&e.jsxs("div",{onClick:()=>{W(null),u==null||u()},style:{...Q,color:"#E5484D"},onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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("清空全部归档")]}),w.kind==="archived"&&e.jsxs(e.Fragment,{children:[p&&e.jsxs("div",{onClick:()=>{W(null),p(w.dirKey)},style:Q,onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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("恢复项目")]}),j&&e.jsxs("div",{onClick:()=>{W(null),j(w.dirKey)},style:{...Q,color:"#E5484D"},onMouseEnter:m=>m.currentTarget.style.background=I.color.sidebarHover,onMouseLeave:m=>m.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 St(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=U(),[r,s]=a.useState(""),i=r.toLowerCase().replace(/^\//,""),l=n.filter(y=>y.name.toLowerCase().includes(i)||y.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:y=>{y.target===y.currentTarget&&o(null)},children:e.jsxs("div",{style:u,onMouseDown:y=>y.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:y=>s(y.target.value),onKeyDown:y=>{y.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(y=>{const x=l.filter(g=>g.type===y);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:St(y,t),flexShrink:0}}),wo[y]]},y),...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:St(y,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})]},`${y}:${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:y=[],onAttach:x,onRemoveAttachment:g,onCommand:v,commands:S=[],onPickCommand:$,onRefreshCommands:p,focusSignal:j,busy:C=!1,hasPendingDialog:z=!1,onRestoreDialog:I,onStop:H,selectedModel:q,queuedMessages:Y=[],dock:_}){var He,tt,Ve;const w=U(),[W,G]=a.useState(!1),[Z,X]=a.useState(!1),[ie,K]=a.useState(0),[b,R]=a.useState(!1);a.useEffect(()=>{if(Y.length===0){R(!1);return}const M=window.setTimeout(()=>R(!0),300);return()=>window.clearTimeout(M)},[Y.length]),a.useEffect(()=>{const M=ye.current;M&&(M.style.height="auto",M.style.height=`${Math.min(M.scrollHeight,200)}px`)},[n]);const[P,D]=a.useState(!1),[le,Q]=a.useState(!1),ye=a.useRef(null),Se=a.useRef(null),De=a.useRef(null),Fe=a.useRef(null),Ie=a.useRef(null);a.useEffect(()=>{var M;j&&j>0&&((M=ye.current)==null||M.focus())},[j]),a.useEffect(()=>{if(!W)return;const M=te=>{var de,$e;const oe=te.target;(de=Fe.current)!=null&&de.contains(oe)||($e=De.current)!=null&&$e.contains(oe)||G(!1)},F=te=>{te.key==="Escape"&&G(!1)};return document.addEventListener("mousedown",M),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",F)}},[W]),a.useEffect(()=>{if(!P)return;const M=te=>{var de;const oe=te.target;(de=Ie.current)!=null&&de.contains(oe)||D(!1)},F=te=>{te.key==="Escape"&&D(!1)};return document.addEventListener("mousedown",M),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",F)}},[P]);const ue=a.useMemo(()=>{for(const M of s){const F=M.models.find(te=>(r==null?void 0:r.activeProvider)===M.id&&te.id===(r==null?void 0:r.model));if(F)return{provider:M,model:F}}},[s,r==null?void 0:r.activeProvider,r==null?void 0:r.model]),Ce=(ue==null?void 0:ue.model.contextWindow)??1e6,Ae=((He=ue==null?void 0:ue.model.input)==null?void 0:He.includes("image"))??!0,Me=((tt=r==null?void 0:r.contextUsage)==null?void 0:tt.tokens)??null,Te=Me!==null,be=Me??0,m=Math.min(1,be/Ce),O=r==null?void 0:r.latestCacheHitRate,A=7,N=2*Math.PI*A,J=N*(1-m),he={width:34,height:34,borderRadius:10,border:"none",background:"transparent",color:w.color.muted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},Ee={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"},ee={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},qe=()=>{t()},ge=Z&&n.startsWith("/"),Ne=ge?n.slice(1).split(/\s+/)[0]??"":"",ae=ge?S.filter(M=>M.name.toLowerCase().includes(Ne.toLowerCase())):[];a.useEffect(()=>{ie>=ae.length&&K(Math.max(0,ae.length-1))},[ae.length]);const Le=M=>{const F=n.slice(Ne.length+1),te=`/${M} ${F.replace(/^\s+/,"")}`;o(te),X(!1),$==null||$(M)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",position:"relative"},onMouseDown:M=>{M.target.closest("button, input, textarea, select, [contenteditable], [role='button']")||M.preventDefault()},children:[b&&Y.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}}),"排队中 · ",Y.length," 条"]}),Y.map((M,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:M.text})]},M.id))]}),(h.length>0||y.length>0)&&e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8,alignItems:"center"},children:[h.map((M,F)=>e.jsxs("div",{style:{position:"relative"},children:[e.jsx("img",{src:M.dataUrl,alt:M.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)),y.map((M,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"})]}),M.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:"✕"})]},M.name))]}),ge&&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((M,F)=>e.jsxs("button",{onClick:()=>Le(M.name),onMouseEnter:()=>K(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===ie?w.color.surface:"transparent",color:w.color.fg},children:[e.jsxs("span",{style:{color:St(M.type,w),fontWeight:600,flexShrink:0,fontSize:"0.84em"},children:["/",M.name]}),e.jsx("span",{style:{color:w.color.muted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:M.description})]},`${M.type}:${M.name}`))}),e.jsx("textarea",{ref:ye,value:n,onChange:M=>{o(M.target.value),Z&&!M.target.value.startsWith("/")&&X(!1)},onKeyDown:M=>{if(M.key==="Tab"){if(ge&&ae.length>0){M.preventDefault();const F=ae[ie];F&&Le(F.name)}return}if(M.key==="Enter"&&!M.shiftKey){if(M.nativeEvent.isComposing)return;if(ge&&ae.length>0){M.preventDefault();const F=ae[ie];F&&Le(F.name);return}M.preventDefault(),qe()}if(M.key==="Escape"){if(ge){X(!1),M.preventDefault();return}o("")}ge&&(M.key==="ArrowDown"&&(M.preventDefault(),K(F=>Math.min(F+1,ae.length-1))),M.key==="ArrowUp"&&(M.preventDefault(),K(F=>Math.max(F-1,0)))),M.key==="/"&&!M.shiftKey&&!M.ctrlKey&&!M.metaKey&&!M.altKey&&M.currentTarget.selectionStart===0&&(X(!0),p==null||p())},onPaste:M=>{var oe;const F=(oe=M.clipboardData)==null?void 0:oe.items;if(!F)return;const te=[];for(const de of Array.from(F))if(de.kind==="file"&&de.type.startsWith("image/")){const $e=de.getAsFile();$e&&te.push($e)}te.length>0&&(M.preventDefault(),x==null||x(te))},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:De,title:T("添加上下文"),style:he,onClick:()=>{G(M=>!M),D(!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"})})}),W&&e.jsx("div",{ref:Fe,style:ee,onMouseDown:M=>M.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:Ae?void 0:"当前模型不支持图片,仅可添加文本文件",action:()=>{var M;return(M=Se.current)==null?void 0:M.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(M=>e.jsxs("button",{title:M.title,onClick:()=>{G(!1),M.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:M.icon}),M.label]},M.label))}),e.jsx("input",{ref:Se,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:M=>{const F=Array.from(M.target.files??[]);F.length>0&&(x==null||x(F)),M.target.value=""}})]}),e.jsx("div",{style:{flex:1}}),r&&e.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>Q(!0),onMouseLeave:()=>Q(!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:A,fill:"none",stroke:w.color.border,strokeWidth:"2.5"}),e.jsx("circle",{cx:"9",cy:"9",r:A,fill:"none",stroke:m>.9?"#E5484D":m>.7?"#B7791F":w.color.primary,strokeWidth:"2.5",strokeLinecap:"round",strokeDasharray:`${N} ${N}`,strokeDashoffset:J,transform:"rotate(-90 9 9)"})]})}),le&&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?Te?`${Yt(be)} / ${Yt(Ce)} (${(m*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:Te?`${m*100}%`:"0%",background:m>.9?"#E5484D":m>.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:O!==void 0?`${O.toFixed(1)}%`:"—"})]})]})]}),_,e.jsxs("div",{ref:Ie,style:{position:"relative"},children:[e.jsxs("button",{style:Ee,onClick:()=>{D(M=>!M),G(!1)},title:T("切换模型"),children:[((Ve=r==null?void 0:r.model)==null?void 0:Ve.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"})})]}),P&&e.jsxs("div",{style:{...ee,left:"auto",right:0,width:250,maxHeight:320,overflowY:"auto"},onMouseDown:M=>M.stopPropagation(),children:[s.length===0&&e.jsx("div",{style:{padding:"10px 12px",fontSize:"0.86em",color:w.color.muted},children:T("暂无已配置模型")}),s.map(M=>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:M.id}),M.models.map(F=>{const te=(r==null?void 0:r.activeProvider)===M.id&&(r==null?void 0:r.model)===F.id;return e.jsxs("button",{onClick:()=>{i(M.id,F.id),D(!1)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",height:32,padding:"0 10px",border:"none",background:te?w.color.surface:"transparent",borderRadius:8,fontSize:"0.89em",color:w.color.fg,cursor:"pointer",textAlign:"left"},onMouseEnter:oe=>{te||(oe.currentTarget.style.background=w.color.surface)},onMouseLeave:oe=>{te||(oe.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}),te&&e.jsx("span",{style:{fontSize:"0.79em",color:w.color.primary},children:"✓"})]},F.id)})]},M.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"})}),c==="off"?"思考关闭":"思考中"]}),e.jsx("button",{onClick:z?I:C?H:qe,title:z?"恢复待处理的弹窗":C?"停止":"发送",style:{width:38,height:38,borderRadius:"50%",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,background:z?w.color.warning:C?"#E8833D":"linear-gradient(135deg,#6366f1,#8b5cf6)",color:"#fff",boxShadow:z||C?"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"})}):C?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=U(),[i,l]=a.useState(!1),[c,f]=a.useState(""),u=a.useRef(null),h=a.useRef(null);a.useEffect(()=>{if(!i)return;const j=z=>{var H,q;const I=z.target;(H=h.current)!=null&&H.contains(I)||(q=u.current)!=null&&q.contains(I)||l(!1)},C=z=>{z.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",C)}},[i]);const y=n.find(j=>j.id===o),x=o?o.split(/[\\/]/).filter(Boolean).pop()??o:void 0,g=(y==null?void 0:y.name)??x??"选择项目",v=n.filter(j=>j.name.toLowerCase().includes(c.toLowerCase())),S=o!==void 0,$={display:"inline-flex",alignItems:"center",gap:6,background:S?"rgba(99,102,241,0.08)":s.color.surface,color:S?"#6366f1":s.color.muted,fontSize:"0.89em",fontWeight:S?600:500,padding:"6px 10px 6px 8px",borderRadius:9,cursor:"pointer",border:`1px solid ${S?"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:j=>{j.stopPropagation(),l(C=>!C)},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:j=>j.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 14px 8px",flexShrink:0},children:[e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{color:s.color.muted},children:[e.jsx("circle",{cx:"11",cy:"11",r:"7"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{value:c,onChange:j=>f(j.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(j=>{const C=j.id===o;return e.jsxs("div",{onClick:()=>{t(j.id),l(!1)},style:{display:"flex",alignItems:"center",gap:10,height:36,padding:"0 10px",borderRadius:9,cursor:"pointer",fontSize:"0.93em",color:s.color.fg,background:C?s.color.surface:"transparent",opacity:j.available===!1?.45:1},children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{flexShrink:0,color:s.color.muted},children:e.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"})}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.name})]},j.id)})}),e.jsx("div",{style:{borderTop:`1px solid ${s.color.border}`,flexShrink:0,padding:4},children:e.jsxs("button",{onClick:()=>{r(),l(!1)},style:{display:"flex",alignItems:"center",gap:8,padding:"0 10px",height:36,width:"100%",border:"none",background:"transparent",borderRadius:8,fontSize:"0.93em",color:s.color.fg,cursor:"pointer"},children:[e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{color:s.color.muted},children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),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=U(),[s,i]=a.useState(()=>{const b=localStorage.getItem(dn);return b&&b.length>0?b:"~"}),[l,c]=a.useState([]),[f,u]=a.useState(null),[h,y]=a.useState(!0),[x,g]=a.useState(null),[v,S]=a.useState(!1),[$,p]=a.useState(""),[j,C]=a.useState({places:[],drives:[]}),[z]=a.useState(un);a.useEffect(()=>{o().then(b=>C(b)).catch(()=>{})},[]),a.useEffect(()=>{y(!0),g(null),u(null),n(s).then(b=>{i(b.path),c(b.entries)}).catch(b=>g(String(b))).finally(()=>y(!1))},[s]),a.useEffect(()=>{const b=R=>{R.key==="Enter"&&!v&&w(),R.key==="Escape"&&t(null)};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[v,s]);const I=/^[A-Za-z]:[\\/]/.test(s),H=a.useMemo(()=>s.split(/[\\/]+/).filter(Boolean),[s]);function q(b){if(I){const R=H[0];return b===0?`${R}\\`:`${R}\\${H.slice(1,b+1).join("\\")}`}return`/${H.slice(0,b+1).join("/")}`}function Y(b){if(/^[A-Za-z]:[\\/]?$/.test(b))return b;const R=b.replace(/[\\/][^\\/]+$/,"");return R.length===0?"/":I&&R.length===2&&R.endsWith(":")?`${R}\\`:R}function _(b){S(!1),i(b)}function w(){const b=f??s;b&&(Co(b),t(b))}function W(){const b=$.trim();b?_(b):S(!1)}const G=Y(s),Z=G===s,X={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"},K={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:X,onMouseDown:b=>{b.target===b.currentTarget&&t(null)},children:e.jsxs("div",{style:ie,onMouseDown:b=>b.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:K,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:{...K,opacity:Z?.35:1,cursor:Z?"default":"pointer"},disabled:Z,onClick:()=>_(G),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:b=>{b.preventDefault(),W()},children:e.jsx("input",{autoFocus:!0,value:$,onChange:b=>p(b.target.value),onBlur:()=>S(!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),S(!0)},title:s,children:[e.jsx("span",{style:{color:r.color.muted,flexShrink:0},children:I?H[0]:"/"}),H.slice(I?1:0).map((b,R)=>{const P=I?R+1:R,D=P===H.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:le=>{D||(le.stopPropagation(),_(q(P)))},children:b})]},`${b}-${R}`)})]})]}),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("位置")}),j.places.map(b=>e.jsxs("button",{onClick:()=>_(b.path),title:b.path,style:{display:"flex",alignItems:"center",gap:8,height:32,padding:"0 10px",borderRadius:8,border:"none",background:s===b.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[b.name]??"📁"}),e.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.name})]},b.path)),j.drives.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 10px 4px",fontSize:"0.75em",fontWeight:600,letterSpacing:.5,textTransform:"uppercase",color:r.color.muted},children:T("驱动器")}),j.drives.map(b=>e.jsxs("button",{onClick:()=>_(b.path),title:b.path,style:{display:"flex",alignItems:"center",gap:8,height:32,padding:"0 10px",borderRadius:8,border:"none",background:s===b.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:b.name})]},b.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(b=>e.jsxs("button",{onClick:()=>_(b),title:b,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:b.split(/[\\/]/).filter(Boolean).pop()??b})]},b))]})]}),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(b=>e.jsxs("div",{onClick:()=>b.isDirectory&&u(b.path),onDoubleClick:()=>b.isDirectory&&_(b.path),title:b.path,style:{display:"flex",flexDirection:"column",alignItems:"center",gap:6,padding:"10px 4px",borderRadius:10,cursor:b.isDirectory?"pointer":"default",background:f===b.path?r.color.surface:"transparent",userSelect:"none",overflow:"hidden"},children:[e.jsx("span",{style:{fontSize:26,lineHeight:1},children:b.isDirectory?"📁":"📄"}),e.jsx("span",{style:{fontSize:"0.82em",color:b.isDirectory?r.color.fg:r.color.muted,textAlign:"center",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.name})]},b.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:w,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+(.*)$/,lt=/^```(\w*)\s*$/,Xt=/^\s*(---+|\*\*\*+|___+)\s*$/,Ge=/^\s*>\s?(.*)$/,at=/^(\s*)([-*+]|\d+\.)\s+(.*)$/,mt=/^\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(lt);if(l){const h=l[1]??"",y=[];for(r+=1;r<o.length;){if(lt.test(o[r]??"")){r+=1;break}y.push(o[r]??""),r+=1}t.push({type:"code",lang:h,text:y.join(`
5
- `)});continue}const c=i.match(Jt);if(c){t.push({type:"heading",level:c[1].length,content:xe(c[2]??"")}),r+=1;continue}if(Xt.test(i)){t.push({type:"hr"}),r+=1;continue}if(Ge.test(i)){const h=[];for(;r<o.length&&Ge.test(o[r]??"");)h.push((o[r]??"").replace(Ge,"$1")),r+=1;t.push({type:"quote",content:fn(h.join(`
6
- `))});continue}const f=i.match(at);if(f){const h=/\d+\./.test(f[2]??""),y=[],x=(f[1]??"").length;for(;r<o.length;){const g=(s=o[r])==null?void 0:s.match(at),v=((g==null?void 0:g[1])??"").length,S=g!=null&&/\d+\./.test(g[2]??"");if(!g||v!==x||S!==h)break;const p=[(g[3]??"").trim()];for(;r+1<o.length;){const j=o[r+1]??"";if(j.length>0&&!/^\s*$/.test(j)&&!at.test(j)&&!Ge.test(j)&&!lt.test(j))p.push(j.replace(/^\s+/,"")),r+=1;else break}y.push(xe(p.join(" "))),r+=1}t.push({type:"list",ordered:h,items:y});continue}if(mt.test(i)){const h=Qt(i),y=o[r+1]??"";if(h.length>1&&Gt.test(y)&&y.includes("-")){const x=h.map(v=>xe(v)),g=[];for(r+=2;r<o.length&&mt.test(o[r]??"");)g.push(Qt(o[r]??"").map(v=>xe(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)||lt.test(h)||Xt.test(h)||Ge.test(h)||at.test(h)||mt.test(h)&&(o[r+1]??"").includes("-")&&Gt.test(o[r+1]??""))break;u.push(h.trim()),r+=1}t.push({type:"paragraph",content:xe(u.join(" "))})}return t}function Qt(n){return n.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim())}const Eo=/^(https?|mailto):/i;function xe(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,y,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:xe(c.slice(2,-2))});else if(f!==void 0)t.push({kind:"bold",children:xe(f.slice(2,-2))});else if(u!==void 0)t.push({kind:"italic",children:xe(u.slice(1,-1))});else if(h!==void 0)t.push({kind:"italic",children:xe(h.slice(1,-1))});else if(y!==void 0)t.push({kind:"strike",children:xe(y.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:xe(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)",Qe=new Map,Lo=4e3;function $o(n,o){const t=`${n.length}:${n}`,r=Qe.get(t);if(r)return r;const s=ao(n,o);if(Qe.size>=Lo){const i=Qe.keys().next().value;i!==void 0&&Qe.delete(i)}return Qe.set(t,s),s}function me({nodes:n}){const o=U();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 Ze={margin:"0 0 10px"};function zo({text:n,lang:o}){const{theme:t}=et(),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:Ze.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((y,x)=>y.color!==void 0?e.jsx("span",{style:{color:y.color},children:y.text},x):e.jsx(nn.Fragment,{children:y.text},x))})]},h))})]})}function Bo({block:n}){const{tokens:o}=et();switch(n.type){case"code":return e.jsx(zo,{text:n.text,lang:n.lang});case"paragraph":return e.jsx("p",{style:Ze,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:Ze,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:Ze.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:Ze.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,yt="#6366f1",Ao="#8b5cf6";function Ho({text:n}){const o=U(),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, ${yt}, ${Ao})`}}),e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:yt,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:yt,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?Be(o):"未知文件"}function Be(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=U();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=U();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 bt=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 y=c.get(h.file)??{file:h.file,added:0,removed:0};y.added+=h.added,y.removed+=h.removed,h.diff&&(y.diff=y.diff?`${y.diff}
9
- ${h.diff}`:h.diff),h.patch&&(y.patch=y.patch?`${y.patch}
10
- ${h.patch}`:h.patch),c.set(h.file,y)}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 y=n[h];if(y.kind==="user"||y.kind==="system")break;if(y.kind==="thinking"||y.kind==="tool"){u=!0,f=!1;break}if(y.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=U(),[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:bt,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:bt,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:bt,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 It=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=U(),i=Vo(n),[l,c]=a.useState(!1),[f,u]=a.useState(i.copyText),[h,y]=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=j=>{j.key==="Escape"&&g(null)};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[x]);const S=()=>{o==null||o(i.copyText),y(!0),window.setTimeout(()=>y(!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,j)=>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("点击查看大图")},j))}),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:S,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=U(),[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 y=n.filter(p=>p.kind==="tool").length,x=n.filter(p=>p.kind==="thinking").length,g=n.reduce((p,j)=>Math.max(p,j.kind==="thinking"||j.kind==="tool"?j.turnDurationMs??0:0),0),v=g>0||r!==void 0,$=y>0?`${y} 个工具`+(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 j=!p;return j||(h.current=!0),j})},title:c?"收起工作内容":"展开工作内容",style:{display:"flex",alignItems:"center",gap:6,width:"fit-content",textAlign:"left",border:"none",background:"transparent",padding:"2px 0",cursor:"pointer",color:l.color.muted,fontSize:"0.89em"},children:[e.jsx("span",{style:{fontSize:"0.71em",color:l.color.muted,flexShrink:0,transition:"transform 0.15s",transform:c?"rotate(90deg)":"rotate(0deg)"},children:"▶"}),e.jsx("span",{style:{color:"#6366f1",fontWeight:600},children: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,j)=>e.jsxs("div",{style:{display:"contents"},children:[e.jsx(It,{item:p,onToggleCard:()=>o(p.id)}),s&&j===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=U(),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=U(),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,y=u==="+"||u==="-"?"change":"context";y!==r&&(l(),r=y);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}=et(),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,y,x)=>{const g=h.marker==="+",v=h.marker==="-",S=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:S,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:S},children:h.content})]},`${x}-${y}`)},u=(h,y)=>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"]},y);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,y)=>{if(h.kind==="change")return e.jsx("div",{children:h.lines.map((x,g)=>f(x,g,`s${y}`))},`s${y}`);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${y}-a`),u(g,`s${y}-f`),f(x[1],1,`s${y}-b`)]},`s${y}`)}return e.jsx("div",{children:h.lines.map((x,g)=>f(x,g,`s${y}-c`))},`s${y}`)}),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=U(),[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),y={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):"",S=g>=0?x.file.slice(g+1):x.file,$=S.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:j=>{j.currentTarget.style.background=l.color.sidebarHover},onMouseLeave:j=>{j.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:S}),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:j=>{j.stopPropagation(),t(x.file,o)},title:T("在右侧面板查看本轮的 diff"),style:y,onMouseEnter:j=>{j.currentTarget.style.background=l.color.sidebarHover,j.currentTarget.style.color=l.color.fg},onMouseLeave:j=>{j.currentTarget.style.background=l.color.surface,j.currentTarget.style.color=l.color.muted},children: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 ct(){return{items:[],busy:!1,queued:[],thinkingLevel:void 0,info:void 0,historyHasMore:!1,historyTotal:0,historyStartIndex:0}}function dt(n){return n.activeId??_e}function je(n,o,t){const r=n.slots[o]??ct(),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=>({...ct(),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,dt(n),t=>({...t,items:se(t.items,{type:"system",id:o.id,text:o.text})}));case"removeMessage":return je(n,dt(n),t=>({...t,items:se(t.items,{type:"removeMessage",id:o.id})}));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,dt(n),t=>({...t,items:se(t.items,{type:"toggleCollapse",id:o.id})}));case"forceIdle":return je(n,dt(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]??ct(),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]??ct();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,y]=a.useState(0),x=a.useCallback(C=>{t.current=C,y(z=>z+1)},[]);a.useEffect(()=>{const C=t.current;if(!C)return;const z=()=>{const q=C.scrollHeight-C.scrollTop-C.clientHeight<60;r.current=q,u(!q)},I=()=>{z(),i.current||(C.scrollTop<l.current?s.current=!0:r.current&&(s.current=!1)),l.current=C.scrollTop};C.addEventListener("scroll",I,{passive:!0});const H=new ResizeObserver(z);for(const q of C.children)H.observe(q);return z(),()=>{C.removeEventListener("scroll",I),H.disconnect()}},[o,h]),a.useEffect(()=>{c.current=0,s.current=!1;let C=0,z=0;return C=requestAnimationFrame(()=>{j(!1),z=requestAnimationFrame(()=>j(!1))}),()=>{cancelAnimationFrame(C),cancelAnimationFrame(z)}},[o]),a.useEffect(()=>{const C=c.current;c.current=n,n>C&&!s.current&&r.current&&(C===0?requestAnimationFrame(()=>{j(!1),requestAnimationFrame(()=>j(!1))}):j(!1))},[n]);const g=()=>{s.current||r.current&&j(!1)},v=(C=!0)=>{s.current||j(C)},S=(C=!0,z)=>{s.current=!1;const I=t.current;if(!I)return;const H=z??(C?450:0),q=I.scrollTop;i.current=!0;const Y=performance.now();let _=-1,w=0;const W=G=>{const Z=H>0?Math.min(1,(G-Y)/H):1,X=I.scrollHeight-I.clientHeight;X===_?w++:w=0,_=X,I.scrollTop=q+(X-q)*Zt(Z),Z<1||w<2?requestAnimationFrame(W):(I.scrollTop=X,requestAnimationFrame(()=>{i.current=!1}))};requestAnimationFrame(W)},$=(C,z=500)=>{const I=t.current;if(!I||C===0)return;const H=I.scrollTop,q=Math.max(0,H+C);i.current=!0;const Y=performance.now(),_=w=>{const W=Math.min(1,(w-Y)/z);I.scrollTop=H+(q-H)*Zt(W),W<1?requestAnimationFrame(_):requestAnimationFrame(()=>{i.current=!1})};requestAnimationFrame(_)},p=()=>{c.current=0},j=C=>{const z=t.current;if(z){i.current=!0,r.current=!0;try{C?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:S,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=[],y=[];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(S=>[...S,...h]),i(S=>[...S,...y]))}),v.readAsDataURL(g)}else{x++;const v=new FileReader;v.addEventListener("load",()=>{y.push({name:g.name,content:String(v.result)}),x-=1,x===0&&(r(S=>[...S,...h]),i(S=>[...S,...y]))}),v.readAsText(g)}x===0&&(r(g=>[...g,...h]),i(g=>[...g,...y]))},removeAttachment:u=>{const h=t.length;u<h?r(y=>y.filter((x,g)=>g!==u)):i(y=>y.filter((x,g)=>g!==u-h))},submit:u=>{const h=n.trim();if(!h&&t.length===0&&s.length===0)return;o("");const y=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,y)}}}class gr{constructor({url:o,onOpen:t,onClose:r}){ze(this,"ws");ze(this,"listeners",new Set);ze(this,"onOpen");ze(this,"onClose");ze(this,"pendingFrames",[]);ze(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 S=await v.request("project.archived",{});Array.isArray(S)&&i(S)}catch{}},[]),c=a.useCallback(v=>{i(S=>S.filter($=>$.dirKey!==v))},[]),f=a.useCallback(v=>{i(S=>S.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]),y=a.useCallback(async(v,S,$)=>{n&&t(T("彻底删除项目"),T("将永久删除该归档会话文件,不可恢复。"),T("彻底删除"),()=>{(async()=>{var p;try{await n.request("project.delete",{dirKey:v}),i(C=>C.filter(z=>z.dirKey!==v));const j=s.find(C=>C.dirKey===v);$&&j&&((p=S.find(C=>C.path===$))==null?void 0:p.cwd)===j.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(S=>S.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:y,deleteArchivedSession:x,removeArchivedProject:c,removeArchivedSession:f,clearAllArchived:g}}function yr({items:n,scrollRef:o,activeId:t}){const r=U(),s=a.useMemo(()=>{const h=[];let y=0,x="";for(const g of n)g.kind==="user"?(h.push({msgIndex:y,question:g.text,answer:""}),x="",y++):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:y,answer:x},g)=>{const v=c===-1?99:Math.abs(g-c),S=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:y,answer:x,x:p.clientX,y:p.clientY})},onMouseLeave:()=>{f(-1),l(null)},onClick:p=>{var z;p.preventDefault(),p.stopPropagation();const j=document.activeElement;j instanceof HTMLElement&&j.blur();const C=(z=o.current)==null?void 0:z.querySelector(`[data-msg-index="${h}"]`);C&&C.scrollIntoView({behavior:"smooth",block:"start"})},style:{height:15,flexShrink:0,display:"flex",alignItems:"center",cursor:"pointer",pointerEvents:"auto"},children:e.jsx("div",{style:{width:S,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=U(),{theme:t}=et(),[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,dock:n.dock})})}function mn(n){const o=U(),[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((y,x)=>e.jsx("span",{style:{color:o.color.fg,whiteSpace:"pre-wrap",wordBreak:"break-word",paddingLeft:14},children:y},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=U(),{event:r}=n,[s,i]=a.useState(""),l=a.useRef(null);a.useEffect(()=>{var y;r.method==="input"&&n.status==="pending"&&((y=l.current)==null||y.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(y=>e.jsx("button",{onClick:()=>o({value:y}),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:y},y)),((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:y=>i(y.target.value),onKeyDown:y=>{y.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=U(),{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(","),[y,x]=a.useState("");a.useEffect(()=>{if(h.length>0&&h!==y){x(h);const p=l.current;if(!p)return;const j=p.querySelectorAll('[data-uicard-status="pending"]'),C=j[j.length-1];if(!C)return;const z=p.getBoundingClientRect(),I=C.getBoundingClientRect(),H=I.bottom-z.bottom;if(H<=0&&I.top>=z.top)return;const q=72,Y=H>0?H+q:I.top-z.top-q;i.animatedScrollBy(Y,750)}},[h,i]),a.useEffect(()=>{const p=l.current,j=n.onLoadMore;if(!p||!j)return;const C=()=>{p.scrollTop<200&&!n.loadingMore&&j()};return p.addEventListener("scroll",C,{passive:!0}),()=>p.removeEventListener("scroll",C)});const g=a.useRef(0),v=a.useRef(0);a.useLayoutEffect(()=>{const p=l.current;if(!p)return;const j=g.current,C=t.length>v.current;if(v.current=t.length,C&&j>0&&p.scrollTop<400){const z=p.scrollHeight-j;z>300&&(p.scrollTop+=z)}g.current=p.scrollHeight});const S=a.useMemo(()=>gn(Yo(t)),[t]),$=a.useMemo(()=>{const p=new Map,j=new Map;let C=0,z=-1,I=-1;for(let _=0;_<S.length;_++){const w=S[_];if(w.kind==="item"&&w.item.kind==="user"){C++;continue}if(w.kind==="work"){z=_,j.has(C)||j.set(C,_);for(const W of w.work)W.kind==="tool"&&W.toolCallId&&p.set(W.toolCallId,_);w.work.some(W=>W.kind==="tool")&&(I=_)}}const H=new Map,q=new Set;for(const _ of u){const w=_.event;let W=w.toolCallId?p.get(w.toolCallId):void 0;if(W===void 0&&(W=w.turn===void 0?void 0:j.get(w.turn)),W===void 0&&(W=I>=0?I:z>=0?z:void 0),W!==void 0){const G=H.get(W)??[];G.push(_),H.set(W,G),q.add(_.event.id)}}const Y=u.filter(_=>!q.has(_.event.id));return{byIdx:H,unmatched:Y}},[S,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 w=t.length-1;w>=0;w--)if(t[w].kind==="user"){p=w;break}let j;for(let w=t.length-1;w>p;w--){const W=t[w];if(W.kind==="thinking"||W.kind==="tool"){j=W;break}}const C=r&&j!==void 0?S.find(w=>w.kind==="work"&&w.work.some(W=>W.id===(j==null?void 0:j.id))):void 0,z=[];let I=0,H=0;const q={contentVisibility:"auto",containIntrinsicSize:"auto 120px"},Y=new Set;{let w;for(const W of S)W.kind==="item"?W.item.kind==="assistant"?w=W.item.id:W.item.kind==="user"&&w!==void 0&&(Y.add(w),w=void 0):(W.kind==="work"||W.kind==="turnSummary")&&(w!==void 0&&Y.add(w),w=void 0);w!==void 0&&Y.add(w)}for(const w of S){if(w.kind==="item"){const W=w.item;W.kind==="user"?z.push(e.jsx("div",{"data-msg-index":H++,style:{maxWidth:"100%",...q},children:e.jsx(It,{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(It,{item:W,onToggleCard:n.onToggleCard,onCopy:n.copyMessage,onEditSubmit:n.editSubmit,onFork:n.onFork,showCopy:W.kind==="assistant"&&Y.has(W.id)&&!r})},`g${I}`))}else if(w.kind==="turnSummary")z.push(e.jsx("div",{style:q,children:e.jsx(ar,{files:w.files,onOpenFile:n.onOpenFile,onRevertAll:()=>n.onRevertAll(w.files.map(W=>W.file)),onExpand:W=>{W&&n.autoscroll.forceScrollToBottom(!0,400)}})},`t${I}`));else{const{work:W}=w,G=((_=W[0])==null?void 0:_.id)??I,Z=w===C,X=$.byIdx.get(I)??[],ie=X.length>0?X.map((b,R)=>e.jsx("div",{"data-uicard-id":b.event.id,"data-uicard-status":b.status,children:e.jsx(en,{card:b,onRespond:P=>{var D;return(D=n.onUiCardRespond)==null?void 0:D.call(n,b,P)}})},`uicardwrap-${b.event.id??R}`)):void 0;let K=-1;if(X.length>0){for(let R=w.work.length-1;R>=0;R--)if(w.work[R].kind==="tool"){K=R;break}const b=X[0].event;if(typeof b.toolCallId=="string"&&b.toolCallId){const R=w.work.findIndex(P=>P.kind==="tool"&&P.toolCallId===b.toolCallId);R>=0&&(K=R)}}z.push(e.jsx("div",{style:q,children:e.jsx(tr,{work:W,onToggleItem:b=>n.onToggleCard(b),live:Z,startMs:s,attached:ie,attachedAnchor:K>=0?K:void 0})},`w${G}`))}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,j)=>e.jsx("div",{"data-uicard-id":p.event.id,"data-uicard-status":p.status,children:e.jsx(en,{card:p,onRespond:C=>{var z;return(z=n.onUiCardRespond)==null?void 0:z.call(n,p,C)}})},`uicardwrap-${p.event.id??j}`))}),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=U();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=U();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=U(),{tabs:t,activeId:r,collapsed:s,onActivate:i,onClose:l,onToggleCollapse:c,render:f,width:u=380,onWidthChange:h}=n,y=14,[x,g]=a.useState(!1),v=a.useRef(null),S=p=>{if(s)return;p.preventDefault(),v.current={startX:p.clientX,startW:u},g(!0);const j=z=>{if(!v.current)return;const I=v.current.startX-z.clientX,H=Math.min(900,Math.max(260,v.current.startW+I));h==null||h(H)},C=()=>{v.current=null,g(!1),document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",C)};document.addEventListener("mousemove",j),document.addEventListener("mouseup",C)},$=t.find(p=>p.id===r)??t[0]??null;return e.jsx("aside",{style:{width:s?y: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:S,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 j=$!==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:j?o.color.surface:"transparent",cursor:"pointer",userSelect:"none",flexShrink:0,maxWidth:220,transition:"background 0.15s"},onMouseEnter:C=>{j||(C.currentTarget.style.background=o.color.surface)},onMouseLeave:C=>{j||(C.currentTarget.style.background="transparent")},children:[p.icon,e.jsx("span",{style:{fontSize:"0.9em",fontWeight:j?600:500,color:j?o.color.fg:o.color.muted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:p.label}),e.jsx("button",{onClick:C=>{C.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:j?.85:.45,transition:"background 0.15s, color 0.15s, opacity 0.15s"},onMouseEnter:C=>{C.currentTarget.style.background=o.color.sidebarHover,C.currentTarget.style.color=o.color.fg,C.currentTarget.style.opacity="1"},onMouseLeave:C=>{C.currentTarget.style.background="transparent",C.currentTarget.style.color=o.color.muted,C.currentTarget.style.opacity=j?"0.8":"0.4"},children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.6",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]},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=U(),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(S=>S.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=>Be(v.file)===Be(g))&&x.add(g);else l.length>0&&x.add(l[0].file);return x}),u=x=>[...c].some(g=>Be(g)===Be(x)),h=x=>{const g=new Set(c);u(x)?g.delete([...g].find(v=>Be(v)===Be(x))):g.add(x),f(g),s==null||s(g.size>0?[...g]:void 0)},y=e.jsx("div",{style:{height:"100%"}});return l.length===0?y:e.jsx("div",{style:{display:"flex",flexDirection:"column",padding:"6px 0"},children:l.map((x,g)=>{const v=x.file.lastIndexOf("/"),S=v>=0?x.file.slice(0,v+1):"",$=v>=0?x.file.slice(v+1):x.file,p=u(x.file),j=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:C=>{C.currentTarget.style.background=i.color.sidebarHover},onMouseLeave:C=>{C.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:S}),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:["+",j.added]}),e.jsxs("span",{style:{color:i.color.error,fontSize:"0.75em",fontWeight:600,flexShrink:0},children:["-",j.removed]})]}),e.jsx("div",{style:{display:"grid",gridTemplateRows: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=U(),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 kt="cubic-bezier(0.25, 1, 0.5, 1)";function Tr({state:n}){const o=U(),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=U(),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=U(),[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,y=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 ${kt}`,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 ${kt}, transform 0.3s ${kt}`},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:y}),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),[y,x]=a.useState(new Set),[g,v]=a.useState(void 0),[S,$]=a.useState(void 0),[p,j]=a.useState(void 0),[C,z]=a.useState(!1),I="vagus.rightPanel.v1",H="vagus.rightPanel.review.v1",q=b=>{try{const R=localStorage.getItem(H),D=(R?JSON.parse(R):{})[b];return{turnId:D==null?void 0:D.turnId,selected:D==null?void 0:D.selected,open:D==null?void 0:D.open}}catch{return{}}},Y=(b,R,P,D)=>{try{const le=localStorage.getItem(H),Q=le?JSON.parse(le):{};Q[b]={turnId:R,selected:P,open:D},localStorage.setItem(H,JSON.stringify(Q))}catch{}},_=b=>{try{const R=localStorage.getItem(I),D=(R?JSON.parse(R):{})[b];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}}},w=(b,R)=>{try{const P=localStorage.getItem(I),D=P?JSON.parse(P):{};D[b]=R,localStorage.setItem(I,JSON.stringify(D))}catch{}},W="vagus.rightPanel.handled.v2",G=b=>{try{const R=localStorage.getItem(W),P=R?JSON.parse(R):{};return new Set(Array.isArray(P[b])?P[b]:[])}catch{return new Set}},Z=(b,R)=>{try{const P=localStorage.getItem(W),D=P?JSON.parse(P):{};D[b]=[...R],localStorage.setItem(W,JSON.stringify(D))}catch{}};a.useLayoutEffect(()=>{if(!o)return;const b=_(o);h(b.width),f(b.has?b.collapsed:!0),b.activeTab!==void 0&&l(b.activeTab),z(b.diffClosed===!0);const R=q(o);$(R.turnId||void 0),j(Array.isArray(R.open)?R.open:void 0),R.selected&&v(R.selected),x(G(o))},[o]),a.useEffect(()=>{o&&w(o,{collapsed:c,width:u,activeTab:i,diffClosed:C})},[c,u,i,C,o]),a.useEffect(()=>{o&&Z(o,y)},[y,o]),a.useEffect(()=>{t?C||(s(b=>b.some(R=>R.id==="diff")?b:[...b,tn]),l(b=>b??"diff")):(s(b=>b.some(R=>R.id==="diff")?b.filter(R=>R.id!=="diff"):b),l(b=>b==="diff"?void 0:b))},[t,C]);const X=a.useCallback((b,R)=>{var D;z(!1),v(b);const P=(D=R==null?void 0:R[0])==null?void 0:D.turnToolCallId;$(P),j([b]),o&&Y(o,P,b,[b]),f(!1),s(le=>le.some(Q=>Q.id==="diff")?le:[...le,tn]),l("diff")},[o]),ie=a.useCallback(b=>{b==="diff"&&z(!0),s(R=>R.filter(P=>P.id!==b)),l(R=>R===b?void 0:R)},[]),K=a.useCallback(b=>{j(b),o&&S&&Y(o,S,g??(b==null?void 0:b[0])??"",b??[])},[o,S,g]);return{rightTabs:r,rightTabId:i,rightCollapsed:c,rightPanelWidth:u,handledFiles:y,diffSelection:g,reviewTurnId:S,reviewOpen:p,setRightTabs:s,setRightTabId:l,setRightCollapsed:f,setRightPanelWidth:h,setHandledFiles:x,setDiffSelection:v,setReviewOpen:K,openFileDiff:X,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}),y=()=>{const S=h.current;if(!S.text)return;const $=S.text,p=S.sessionId;S.text="",S.raf=null,r({type:"applyEvent",sessionId:p,id:s(),event:{type:"session.message",sessionId:p,kind:"text_delta",text:$}}),u(),l.followStream()},x=(S,$)=>{const p=h.current;p.sessionId!==S&&(p.raf!==null&&cancelAnimationFrame(p.raf),p.text="",p.sessionId=S),p.text+=$,p.raf===null&&(p.raf=requestAnimationFrame(y))},g=()=>{const S=h.current;S.raf!==null&&(cancelAnimationFrame(S.raf),S.raf=null),S.text&&y()};t(S=>{var j,C,z;const $=o;if(!$)return;const p=i!==void 0&&S.sessionId===i;switch(S.type){case"session.created":f.fetchSessionInfo($,S.sessionId,{updateActivePath:!1}),f.refreshHistory($);return;case"session.turn":S.kind==="end"&&g(),r({type:"applyEvent",sessionId:S.sessionId,id:s(),event:S}),p&&S.kind==="end"&&(f.fetchSessionInfo($,S.sessionId),f.refreshHistory($),$.request("usage.stats",{}).then(I=>f.setUsageStats(I)).catch(()=>{}));return;case"session.message":if(S.kind==="user_queued"&&/<skill\s+name="/.test(S.text)){const I=(j=/<skill\s+name="([^"]+)"/.exec(S.text))==null?void 0:j[1],H=(C=f.shiftSkillText)==null?void 0:C.call(f);r({type:"userMessage",sessionId:S.sessionId,id:s(),text:H??S.text,...I?{skillTag:I}:{}})}else S.kind==="text_delta"?x(S.sessionId,S.text):S.kind==="text_done"?(g(),r({type:"applyEvent",sessionId:S.sessionId,id:s(),event:S})):r({type:"applyEvent",sessionId:S.sessionId,id:s(),event:S});p&&(S.kind==="user_queued"||S.kind==="error")&&l.scrollToBottom(!1);return;case"session.thinking":r({type:"applyEvent",sessionId:S.sessionId,id:s(),event:S}),p&&S.kind==="delta"&&(u(),l.followStream());return;case"session.tool_call":case"session.tool_result":r({type:"applyEvent",sessionId:S.sessionId,id:s(),event:S}),p&&S.type==="session.tool_call"&&f.fetchSessionInfo($,S.sessionId);return;case"session.queue_update":r({type:"applyEvent",sessionId:S.sessionId,id:s(),event:S});return;default:S.type==="ui.request"&&((z=f.onUiRequest)==null||z.call(f,S));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(()=>{})},vt=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=U(),{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,y]=a.useState(null),{rightTabs:x,rightTabId:g,rightCollapsed:v,rightPanelWidth:S,diffSelection:$,reviewTurnId:p,reviewOpen:j,setRightTabs:C,setRightTabId:z,setRightCollapsed:I,setRightPanelWidth:H,setReviewOpen:q,openFileDiff:Y,closeRightTab:_}=Wr({activeId:s.activeId,hasEdits:u}),w=a.useRef(0),W=()=>++w.current,G=a.useRef(0),Z=a.useRef(0),X=a.useRef(void 0),ie=d=>{G.current++;const k=G.current;X.current!==void 0&&clearTimeout(X.current),X.current=setTimeout(()=>{X.current=void 0,t&&$t(t,d,k)},80)},[K,b]=a.useState([]),[R,P]=a.useState(),[D,le]=a.useState(()=>sessionStorage.getItem("vagus.view.settings")==="1"),[Q,ye]=a.useState(()=>sessionStorage.getItem("vagus.view.plugins")==="1");a.useEffect(()=>{try{sessionStorage.setItem("vagus.view.settings",D?"1":"0"),sessionStorage.setItem("vagus.view.plugins",Q?"1":"0")}catch{}},[D,Q]);const[Se,De]=a.useState("appearance"),[Fe,Ie]=a.useState(null),[ue,Ce]=a.useState(new Set),[Ae,Me]=a.useState(null),[Te,be]=a.useState({}),m=Te[s.activeId??""]??Te.global??[],[O,A]=a.useState(null),N=a.useRef(null),[J,he]=a.useState({}),[Ee,ee]=a.useState({}),qe=a.useRef([]),ge=a.useMemo(()=>{const d={};for(const[k,E]of Object.entries(Ee))E.lines.length>0&&(!E.sessionId||E.sessionId===s.activeId)&&(d[k]={lines:E.lines});return d},[Ee,s.activeId]),Ne=O?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:O.type==="error"?"#E5484D":O.type==="warning"?"#B7791F":o.color.primary}}),e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:O.text})]}):null,ae=a.useMemo(()=>{const d={};for(const[k,E]of Object.entries(Ee))E.placement==="aboveEditor"&&E.lines.length>0&&(!E.sessionId||E.sessionId===s.activeId)&&(d[k]={lines:E.lines});return d},[Ee,s.activeId]);a.useEffect(()=>{Object.keys(ge).length>0?(C(k=>k.some(E=>E.id==="widget")?k:[...k,Cr]),z(k=>k??"widget")):(C(k=>k.some(E=>E.id==="widget")?k.filter(E=>E.id!=="widget"):k),z(k=>k==="widget"?void 0:k))},[ge]);const[Le,He]=a.useState(),[tt,Ve]=a.useState(!1),[M,F]=a.useState(Oe),[te,oe]=a.useState(0),de=a.useRef(!1);a.useEffect(()=>{if(D||Q){de.current=!0;return}de.current&&(de.current=!1,oe(d=>d+1))},[D,Q]);const[$e,Ct]=a.useState(!1),[kn,vn]=a.useState("ask"),[Re,ut]=a.useState(void 0),[nt,Mt]=a.useState(!1),[wn,ot]=a.useState(!1),[Tt,Et]=a.useState(null),[Rt,Wt]=a.useState(!1),Ue=a.useRef(new Map),ft="vagus.lastSession",Lt=a.useRef(!1),Ke=$r(t),ht=a.useCallback((d,k,E,L)=>{Me({title:d,message:k,confirmLabel:E,onConfirm:L})},[]),{modelsConfig:jn,enabledProviders:Ye}=Ke;a.useEffect(()=>{if(!s.activeId&&!Re&&Ye.length>0&&Ye[0].models.length>0){const d=Ye[0];ut({providerId:d.id,modelId:d.models[0].id})}},[s.activeId,Re,Ye]);const re=a.useCallback(async d=>{try{const k=await d.request("session.history",{});if(Array.isArray(k)){const E=k;b(E);for(const L of E)L.id&&L.path&&Ue.current.set(L.id,L.path)}}catch{}},[]),pe=mr(t,re,ht,d=>{R===d&&(i({type:"activate",sessionId:void 0}),P(void 0))}),{archivedProjects:Sn}=pe;a.useEffect(()=>{if(!nt){ot(!1);return}const d=window.setTimeout(()=>ot(!0),300);return()=>window.clearTimeout(d)},[nt]);const Je=(d,k,E)=>{d.request("session.info",{sessionId:k}).then(L=>{var ne;const B=L;B!=null&&B.sessionFile&&(Ue.current.set(k,B.sessionFile),(E==null?void 0:E.updateActivePath)!==!1&&P(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??++G.current,B=new Map;for(const V of K)B.set(V.path,V.id);const ne=B.get(k),ce=ne?s.slots[ne]:void 0;if(ne&&ce&&ce.items.length>0){P(k),c.resetSnap(),i({type:"activate",sessionId:ne}),Je(d,ne),re(d),oe(V=>V+1);return}Z.current++,Mt(!0),i({type:"clearActive"}),ot(!0);try{P(k);const V=await d.request("session.open",{sessionFile:k,limit:200}),ve=V.sessionId;if(L!==G.current){const Pe=s.slots[ve];(!Pe||Pe.items.length===0)&&i({type:"loadHistory",sessionId:ve,id:W(),messages:V.messages,hasMore:V.hasMore,total:V.total,startIndex:V.startIndex});return}const rt=s.slots[ve];(!rt||rt.items.length===0)&&i({type:"loadHistory",sessionId:ve,id:W(),messages:V.messages,hasMore:V.hasMore,total:V.total,startIndex:V.startIndex}),c.resetSnap(),i({type:"activate",sessionId:ve}),V.sessionFile&&P(V.sessionFile),Je(d,ve),re(d),oe(Pe=>Pe+1)}catch(V){i({type:"localSystem",id:W(),text:`无法打开会话: ${V instanceof Error?V.message:String(V)}`})}finally{Z.current--,Z.current<=0&&(Z.current=0,Mt(!1),ot(!1))}},gt=a.useRef(!1),[In,zt]=a.useState(!1),Cn=a.useCallback(async()=>{if(!t||!s.activeId||gt.current)return;const d=s.activeId,k=s.slots[d];if(!(k!=null&&k.historyHasMore)||!k.historyStartIndex||k.items.length===0)return;gt.current=!0,zt(!0);const E=Ue.current.get(d)??R;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{gt.current=!1,zt(!1)}},[t,s.activeId,s.slots,R]),Bt=a.useRef(!0);a.useEffect(()=>{if(Bt.current){Bt.current=!1;return}try{R?localStorage.setItem(ft,R):localStorage.removeItem(ft)}catch{}},[R]),a.useEffect(()=>{if(!t||Lt.current)return;Lt.current=!0;let d;try{d=localStorage.getItem(ft)??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(()=>{pt(),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:Le??void 0})).sessionId,(E=s.slots[_e])!=null&&E.items.length&&i({type:"moveWelcome",sessionId:B}),i({type:"activate",sessionId:B}),Je(t,B),Re){try{await t.request("session.model.set",{sessionId:B,providerId:Re.providerId,modelId:Re.modelId})}catch{}ut(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)=>{ht(T("派生新会话"),T(`从这条消息开始创建一条新的会话,原会话保持不变。
18
- 新会话只包含到此为止的上下文。`),T("确认派生"),()=>{Ft.current(k,E)})},[ht]),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=>vt(we.text)===vt(d));if(!ne){const we=(B??[]).slice(0,3).map(it=>JSON.stringify(it.text.slice(0,60))).join(", ");A({text:`未找到匹配的派生点 (${(B??[]).length} 个点,样本: ${we})`,type:"error"}),console.log("[fork] match failed. user text:",JSON.stringify(d),"| normText:",vt(d)),console.log("[fork] first 3 fork points:",(B??[]).slice(0,3).map(it=>({id:it.entryId,text:it.text.slice(0,80)})));return}const ce=await E.request("session.fork",{sessionId:L,entryId:ne.entryId});if(!(ce!=null&&ce.sessionId)){A({text:T("派生失败:daemon 未返回新会话"),type:"error"});return}const V=K.find(we=>we.id===L||we.path===R),ve=(V==null?void 0:V.name)||(V==null?void 0:V.firstMessage)||T("新会话"),rt=K.filter(we=>(we.name||we.firstMessage||"").startsWith(ve)).length,Pe=`${ve} (${rt+1})`;try{await E.request("session.renameFile",{sessionFile:ce.sessionFile,name:Pe})}catch{}re(E);const st=await E.request("session.open",{sessionFile:ce.sessionFile,limit:200});i({type:"loadHistory",sessionId:ce.sessionId,id:W(),messages:st.messages,hasMore:st.hasMore,total:st.total,startIndex:st.startIndex}),i({type:"activate",sessionId:ce.sessionId}),P(ce.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,P,c,K,R,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}));y({results:E})}catch(k){console.log("[frontend revertBatch catch]",String(k)),y({results:d.map(E=>({file:E,toolCallId:E,ok:!1,error:k instanceof Error?k.message:String(k)}))})}},[t,s.activeId,y]),Ln=()=>{c.resetSnap(),i({type:"activate",sessionId:void 0}),P(void 0),oe(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=K.find(E=>E.path===d);await t.request("session.delete",{sessionFile:d,sessionId:k==null?void 0:k.id}),R===d&&(i({type:"activate",sessionId:void 0}),P(void 0)),re(t)}catch{}},Bn=async d=>{if(t)try{await t.request("session.archive",{sessionFile:d}),b(k=>k.filter(E=>E.path!==d)),R===d&&(i({type:"activate",sessionId:void 0}),P(void 0)),re(t),pe.syncArchived(t)}catch{}},Dn=async d=>{if(t)try{await t.request("session.restore",{sessionFile:d}),pe.removeArchivedSession(d),re(t),pe.syncArchived(t)}catch{}},Fn=async d=>{if(t)try{const k=ue.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 K){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},[K]),Hn=a.useMemo(()=>{const d=new Set;for(const[k,E]of Object.entries(s.slots))if(E.busy){const L=Ue.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"){ee(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"){he(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:Je,refreshHistory:re,setUsageStats:Ie,onUiRequest:On,shiftSkillText:()=>qe.current.shift()}}),a.useEffect(()=>{t&&(t.request("ping").then(()=>{}).catch(()=>{}),Ke.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});ee(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 ce=ne.map(V=>({event:V.request,sessionId:V.request.sessionId,status:"answered",result:V.result}));L[B]=[...L[B]??[],...ce]}return L})}).catch(()=>{}),pe.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=>{He(d),localStorage.setItem("vagus.activeProject",d)};a.useEffect(()=>{const d=localStorage.getItem("vagus.activeProject");d&&He(d)},[]);const Nn=async d=>{if(Ve(!1),!(!d||!t)){He(d),localStorage.setItem("vagus.activeProject",d);try{const k=await t.request("session.create",{cwd:d});i({type:"activate",sessionId:k.sessionId}),re(t),oe(E=>E+1)}catch{}}},Vn=async(d,k)=>{if(ut({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} 上下文`:""}`}),Je(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(F).catch(()=>F(Oe))},[t,s.activeId]);const pt=()=>{Ht().then(F).catch(()=>F(Oe))},Qn=d=>{Ct(!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:Ye,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:m.some(d=>d.status==="pending"),selectedModel:Pn,onCommand:()=>{pt(),Ct(!0)},onRefreshCommands:pt,commands:M,onPickCommand:()=>{},focusSignal:te,queuedMessages:l.queued},[Ot,Zn]=a.useState(()=>{try{return localStorage.getItem("vagus.sidebar.collapsed")==="1"}catch{return!1}}),_t={sessions:K,activePath:R,onNewSession:Ln,onCollapsedChange:Zn,onClearAllArchived:()=>pe.clearAllArchived(),onOpenSession:ie,onOpenSettings:()=>le(!0),onOpenPlugins:()=>ye(!0),onRenameSession:$n,onDeleteSession:zn,onArchiveSession:Bn,onRestoreSession:Dn,onDeleteArchivedSession:pe.deleteArchivedSession,onTogglePin:Fn,pinnedSessions:ue,archivedProjects:Sn,onArchiveProject:async d=>{b(k=>k.filter(E=>E.cwd!==d)),await pe.archiveProject(d)},onUnarchiveProject:async d=>{pe.removeArchivedProject(d),await pe.unarchiveProject(d)},onDeleteProject:d=>pe.deleteProject(d,K,R),busyPaths:Hn,pendingDialogPaths:new Set(Object.entries(Te).filter(([,d])=>d.some(k=>k.status==="pending")).map(([d])=>Ue.current.get(d)).filter(d=>!!d))},{uiFontSize:eo}=on(),to=!s.activeId&&!D&&!nt,ke=K.find(d=>d.path===R),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:Fe,onClose:()=>le(!1),onSave:Ke.saveModels,onRefresh:Ke.refreshModels,onTest:Ke.testModel,cat:Se,onCatChange:De,projectCwd:Le,request:(d,k)=>t.request(d,k),onProbe:async d=>t?await t.request("models.probe",d):{ok:!1}})}):Q?e.jsx(a.Suspense,{fallback:null,children:e.jsx(Br,{request:(d,k)=>t.request(d,k),onClose:()=>ye(!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:Le,projects:An,onSelectProject:qn,onNewProject:()=>Ve(!0),inputCard:Pt,dockStatuses:J,dockWidgets:ae,toast:Ne})]}):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:nt,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:m,onUiCardRespond:_n,onLoadMore:Cn,loadingMore:In,dockStatuses:J,dockWidgets:ae,toast:Ne,onOpenFile:Y,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:S,onWidthChange:H,render:d=>d.id==="diff"?e.jsx(Sr,{items:l.items,selected:$,turnId:p,expandedFiles:j,onOpenChange:k=>q(k)},`${s.activeId}-${p??"none"}`):d.id==="widget"?e.jsx(Mr,{widgets:ge}):null})]}),tt&&e.jsx(To,{listDir:Gn,roots:Xn,onPick:d=>void Nn(d)}),$e&&e.jsx(jo,{commands:M,onPick:Qn}),Ae&&e.jsx(wr,{state:Ae,onClose:()=>Me(null)}),h&&e.jsx(Rr,{report:h,onClose:()=>y(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,{}));