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