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