@seqyuan/annovibe 0.8.107 → 0.8.108
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/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +10 -10
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/agent/runtime/route.js +1 -1
- package/.next/server/app/api/internal/runtime/route.js +1 -1
- package/.next/server/app/api/models/route.js +1 -1
- package/.next/server/app/api/version/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +1 -1
- package/.next/server/app/login.segments/_full.segment.rsc +1 -1
- package/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/.next/server/app/login.segments/_index.segment.rsc +1 -1
- package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/login.segments/login.segment.rsc +1 -1
- package/.next/server/app/page.js +2 -2
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke.html +1 -1
- package/.next/server/app/smoke.rsc +1 -1
- package/.next/server/app/smoke.segments/_full.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_index.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
- package/.next/server/app-paths-manifest.json +10 -10
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/{page-832d77469963de9f.js → page-5d2752f33d23c5b3.js} +2 -2
- package/package.json +1 -1
- /package/.next/static/{Ts3ilnUPDU_qhJrRMvknS → oYIrsu-ftPq4TOPT8tYRu}/_buildManifest.js +0 -0
- /package/.next/static/{Ts3ilnUPDU_qhJrRMvknS → oYIrsu-ftPq4TOPT8tYRu}/_ssgManifest.js +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,65145))},65145:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>n0});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function a(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function s({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:a(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:a(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${b?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,a]=(0,o.useState)(""),[s,c]=(0,o.useState)(null),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),j=(0,o.useCallback)(async e=>{m(!0),b(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);a(n.current??""),c(n.parent??null),p(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){b(e instanceof Error?e.message:String(e))}finally{m(!1)}},[]);return((0,o.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&i(t)},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=g.trim();e&&j(e)},disabled:!g.trim()||v,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:g.trim()&&!v?"var(--text-muted)":"var(--text-dim)",cursor:g.trim()&&!v?"pointer":"default",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:g.trim()?"var(--accent)":"var(--bg-hover)",color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>s&&void j(s),disabled:!s,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:s?"var(--bg)":"transparent",color:s?"var(--text-muted)":"var(--text-dim)",cursor:s?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),h.length>0&&(0,n.jsxs)("select",{value:h.find(e=>l.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&j(e.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),h.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:l,children:l})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:v?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):y?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:y}):0===u.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):u.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void j(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let c="AnnoVibe",u="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function h(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function x(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function g(e){return new DOMException(e,"TimeoutError")}function f(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}function v(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function m(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"…/"+o.slice(-2).join(n)}function y(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||m(e,t)}let b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function j(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),a=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:b[Math.floor(Math.random()*b.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.107":c,r),s=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;s(t),t&&(l.current=setTimeout(()=>s(!1),3e3))},[e,s]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:a})}function k({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:i,initialSessionId:l,onInitialRestoreDone:a,refreshKey:c,onSessionDeleted:v,selectedCwd:b,onCwdChange:I}){let[R,M]=(0,o.useState)([]),[W,L]=(0,o.useState)({}),[$,E]=(0,o.useState)(()=>new Set),P=(0,o.useRef)(!1),[A,D]=(0,o.useState)(!0),[B,N]=(0,o.useState)(!1),[O,H]=(0,o.useState)(null),[F,_]=(0,o.useState)(null),[U,K]=(0,o.useState)(""),[J,V]=(0,o.useState)(null),[q,Y]=(0,o.useState)(!1),[G,Z]=(0,o.useState)("project"),[X,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(!1),[er,en]=(0,o.useState)(!1),[eo,ei]=(0,o.useState)(()=>new Set),[el,ea]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(u)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[es,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(null),[ep,eh]=(0,o.useState)(null),[ex,eg]=(0,o.useState)(!1),ef=(0,o.useRef)(null),ev=(0,o.useRef)(!1),em=(0,o.useRef)(!1),ey=(0,o.useRef)(!1),eb=(0,o.useRef)(new Map),ej=(0,o.useCallback)(async(e=!1)=>{try{let t;e&&(H(null),D(!0));let r=new AbortController;try{t=setTimeout(()=>r.abort(g("Project loading timed out")),3e4);let e=await fetch("/api/projects?sessions=false",{signal:r.signal});if(!e.ok)throw Error(await x("projects",e));let n=await e.json();M(n.projects),H(null)}finally{clearTimeout(t)}}catch(e){H(f(e,"Loading projects timed out. Codex may still be starting; click Refresh to retry."))}finally{e&&D(!1)}},[]),ek=(0,o.useCallback)(async(e,t=!1)=>{if(!e)return;let r=eb.current.get(e);if(r)return r;let n=(async()=>{L(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let r;t&&D(!0);let n=new AbortController;try{r=setTimeout(()=>n.abort(g("Chat loading timed out")),3e4);let t=await fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:n.signal});if(!t.ok)throw Error(await x("sessions",t));let o=await t.json();o.runningSessionIds&&!P.current&&E(new Set(o.runningSessionIds)),L(t=>({...t,[e]:{sessions:o.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(r)}}catch(r){let t=f(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");L(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}}))}finally{t&&D(!1),eb.current.delete(e)}})();return eb.current.set(e,n),n},[]),ew=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!ew.current;ew.current=!0,ej(e)},[ej,c]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&K(e.home)}).catch(()=>{})},[]);let eS=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(ev.current){ev.current=!1;return}if(em.current){em.current=!1;return}I?.(F)},[F,I]);let eC=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return V(n.error??`HTTP ${r.status}`),!1;return ej(!1),!0}catch(e){return V(e instanceof Error?e.message:String(e)),!1}},[ej]),eT=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ez=(0,o.useCallback)(e=>{em.current=!0,_(e),V(null),ea(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),h(r),r}),I?.(e),eT(e),ek(e,!1)},[ek,I,eT]);(0,o.useEffect)(()=>{if(0!==R.length&&null===F){if(l&&!eS.current){eS.current=!0;let e=Object.values(W).flatMap(e=>e.sessions).find(e=>e.id===l);if(e){_(e.cwd),eT(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(l)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(_(e.info.cwd),eT(e.info.cwd),t(e.info,!0)):a?.()}).catch(()=>a?.());return}let e=R[0]?.cwd;e&&(_(e),eT(e))}},[R,F,l,t,a,W,eT]);let eI=b??F;(0,o.useEffect)(()=>{let e=new EventSource("/api/agent/running/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data);"running"===t.type&&(P.current=!0,E(new Set(t.runningSessionIds??[])))}catch{}},()=>e.close()},[]),(0,o.useEffect)(()=>{if(!eI)return;let e=window.setInterval(()=>{ek(eI,!1)},3e4);return()=>window.clearInterval(e)},[eI,ek]),(0,o.useEffect)(()=>{let e=()=>{eI&&ek(eI,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eI,ek]);let eR=(0,o.useCallback)(e=>{if(!e){Z("agent"),Y(!0);return}let t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(t,e)},[r]),eM=(0,o.useCallback)(e=>{if(!e){Z("workbench"),Y(!0);return}i?.(e)},[i]),eW=(0,o.useCallback)(async e=>{await eC(e,!0)&&(ez(e),Y(!1),V(null),"agent"===G&&eR(e),"workbench"===G&&eM(e))},[ez,eR,eM,G,eC]),eL=(0,o.useCallback)(e=>{Q(e),et(!0)},[]),e$=(0,o.useCallback)(()=>{et(!1),Q(null)},[]),eE=(0,o.useCallback)(e=>{let t=X??eI;e$(),"agent"===e?eR(t):eM(t)},[e$,eR,eM,eI,X]),eP=(0,o.useCallback)(()=>{eL(eI)},[eI,eL]),eA=(0,o.useCallback)(()=>{Z("project"),V(null),Y(!0)},[]),eD=(0,o.useMemo)(()=>[...eI&&!R.some(e=>e.cwd===eI)?[{cwd:eI,displayName:y(eI,U),chatCount:W[eI]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...R].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,o="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==o?n-o:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[eI,U,R,W]),eB=(0,o.useMemo)(()=>{let e=e=>{let t=W[e.cwd],r=[...t?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:e,cwd:e.cwd,displayName:e.displayName||y(e.cwd,U),sessions:r,sessionsState:t,lastAccessed:(e.lastAccessed??e.created??"")||r[0]?.modified||""}},t=eD.filter(e=>!0===e.pinned).map(e);if(eI){let r=eD.find(e=>e.cwd===eI);r&&!0!==r.pinned&&t.push(e(r))}return t},[eI,U,W,eD]);(0,o.useEffect)(()=>{if(0===eB.length||ey.current||(ey.current=!0,!eB[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eB.slice(1).map(e=>e.cwd));ea(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(h(e),e):t),window.localStorage.setItem(p,"1")},[eB]);let eN=(0,o.useCallback)((e,r=!1)=>{e.cwd!==eI&&(ev.current=!0,_(e.cwd)),ea(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),h(r),r}),eT(e.cwd),t(e,r)},[t,eI,eT]),eO=(0,o.useCallback)(e=>{ea(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),h(r),r})},[]);(0,o.useEffect)(()=>{for(let e of eB){let t=W[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eI,r=el.has(e.cwd);if(!t&&r)continue;ek(e.cwd,!1)}}},[el,eI,ek,eB,W]);let eH=(0,o.useCallback)(e=>{ei(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eF=(0,o.useCallback)(async e=>{eh("reorder");try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);M(r.projects??[]),H(null)}catch(e){H(e instanceof Error?e.message:String(e)),ej(!1)}finally{eh(null)}},[ej]),e_=(0,o.useCallback)(async(e,t)=>{eh(`pin:${e}`);try{let r=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,pinned:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);M(n.projects??[]),H(null)}catch(e){H(e instanceof Error?e.message:String(e)),ej(!1)}finally{eh(null)}},[ej]),eU=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eD.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),o=r.indexOf(t);if(-1===n||-1===o)return;let i=[...r];i.splice(n,1);let l=i.indexOf(t);i.splice(l,0,e),eF(i)},[eF,eD]),eK=(0,o.useCallback)(async()=>{N(!0);try{await ej(!1);let e=new Set([...Object.entries(W).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eI?[eI]:[]]);await Promise.all([...e].map(e=>ek(e,!1)))}finally{N(!1)}},[eI,ej,ek,W]);return(0,o.useEffect)(()=>{if(!ex)return;let e=e=>{ef.current&&!ef.current.contains(e.target)&&eg(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[ex]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)(j,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eP,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:eI?`New chat in ${eI}`:"New chat in a project path",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,n.jsx)("button",{onClick:()=>en(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(s,{open:er,cwd:eI,homeDir:U,onClose:()=>en(!1),onSelectSession:e=>{eN(e)}}),(0,n.jsxs)("div",{ref:ef,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>eg(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eI?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eI?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eI??"Select project",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:eI?"var(--text)":"var(--text-dim)"},children:eI?eD.find(e=>e.cwd===eI)?.displayName??m(eI,U):"Select project…"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:ex?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eI&&(0,n.jsx)(S,{pinned:eD.find(e=>e.cwd===eI)?.pinned===!0,onToggle:()=>void e_(eI,eD.find(e=>e.cwd===eI)?.pinned!==!0)}),ex&&(0,n.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===eD.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eD.map(e=>{let t=e.cwd===eI;return(0,n.jsx)(C,{project:e,homeDir:U,isCurrent:t,onSelect:()=>{ez(e.cwd),eg(!1)},onTogglePinned:()=>void e_(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{eg(!1),eA()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eD.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"Add project…"]})]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:eK,disabled:B,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:B?"var(--accent)":"var(--text-dim)",cursor:B?"default":"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:B?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:eA,title:"New project","aria-label":"New project",style:{height:26,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s, color 0.12s, border-color 0.12s",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v4.5A1.5 1.5 0 0 1 13 12H3a1.5 1.5 0 0 1-1.5-1.5v-6Z"}),(0,n.jsx)("path",{d:"M11 7v3M9.5 8.5h3"})]}),"New Project"]})]})]}),J&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:J})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[A&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),O&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:O}),!A&&!O&&0===eB.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!A&&!O&&eB.map(t=>{let r,o=el.has(t.cwd),i=t.cwd===eI,l=eo.has(t.cwd),a=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),s=a.length,d=a;if(s>10&&!l){d=a.slice(0,10);let t=a.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let c=s-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:ec===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ec===t.cwd),opacity:es===t.cwd?.55:1},onDragOver:e=>{es&&es!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eu(t.cwd))},onDragLeave:()=>{ec===t.cwd&&eu(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||es;eu(null),ed(null),r&&eU(r,t.cwd)},children:[(0,n.jsx)(T,{group:t,isCurrent:i,isCollapsed:o,isDragging:es===t.cwd,pinBusy:ep===`pin:${t.cwd}`,onToggle:()=>eO(t.cwd),onSelect:()=>ez(t.cwd),onTogglePinned:()=>void e_(t.cwd,!0!==t.project.pinned),onDragStart:e=>{ed(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{ed(null),eu(null)}}),!o&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(z,{node:r,selectedSessionId:e,onSelectSession:eN,onRenamed:()=>void ek(t.cwd,!1),onSessionDeleted:e=>{v?.(e),ek(t.cwd,!1)},depth:0,runningSessionIds:$},r.session.id))]})),(l||c>0)&&s>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eH(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:l?"Show less":`Show ${Math.max(0,c)} more`})]})]},t.cwd||"__no_project")})]}),ee&&(0,n.jsx)(w,{cwd:X,onChoose:eE,onClose:e$}),(0,n.jsx)(d,{open:q,initialPath:eI,onClose:()=>Y(!1),onSelect:e=>eW(e)})]})}function w({cwd:e,onChoose:t,onClose:r}){let o=e?y(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function S({pinned:e,onToggle:t}){return(0,n.jsx)("button",{type:"button",onClick:t,title:e?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:e?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:e?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function C({project:e,homeDir:t,isCurrent:r,onSelect:i,onTogglePinned:l}){let[a,s]=(0,o.useState)(!1),d=e.displayName||y(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":a?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:i,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:a?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!a,pointerEvents:a?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function T({group:e,isCurrent:t,isCollapsed:r,isDragging:i,pinBusy:l,onToggle:a,onSelect:s,onTogglePinned:d,onDragStart:c,onDragEnd:u}){let[p,h]=(0,o.useState)(!1),x=e.lastAccessed,g=Math.max(0,e.project.chatCount??e.sessions.length??0),f=!0===e.project.pinned,m=(0,o.useCallback)(()=>{t?a():s()},[t,s,a]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:c,onDragEnd:u,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),m())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:i?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:i?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!p&&g>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[g," ",1===g?"chat":"chats"]}),!p&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:v(x)}),f?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:p?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!p,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:p?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function z({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:a,runningSessionIds:s}){let[d,c]=(0,o.useState)(!1),u=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[a>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*a+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(I,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:a,hasChildren:u,collapsed:d,onToggleCollapse:()=>c(e=>!e),isRunning:s.has(e.session.id)})]}),u&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(z,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:a+1,runningSessionIds:s},e.session.id))})]})}function I({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:a=0,hasChildren:s=!1,collapsed:d=!1,onToggleCollapse:c,isRunning:u=!1}){let[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(""),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(!1),w=(0,o.useRef)(null),S=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),C=(0,o.useCallback)(t=>{t.stopPropagation(),m(e.name??""),g(!0),setTimeout(()=>w.current?.select(),0)},[e.name]),T=(0,o.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[f,e.id,e.name,i]),z=(0,o.useCallback)(e=>{e.stopPropagation(),b(!0)},[]),R=(0,o.useCallback)(async t=>{t.stopPropagation(),b(!1),k(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{k(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),b(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:y||x?void 0:r,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:a>0?12*a+14:14,paddingRight:8,cursor:y||x?"default":"pointer",background:y?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:y?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:j?.5:1,gap:6,overflow:"hidden"},children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",S.slice(0,22),S.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:R,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:M,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):x?(0,n.jsx)("input",{ref:w,value:f,onChange:e=>m(e.target.value),onBlur:T,onKeyDown:e=>{"Enter"===e.key&&T(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[a>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===a&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:u?7:5,height:u?7:5,borderRadius:"50%",background:u?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...u?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),W&&(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:W?"var(--accent)":"var(--text)"},title:S,children:S}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:v(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),s&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),p&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:C,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:z,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var R=r(94456);let M="subagent",W=["retain","recall","reflect"],L=[],$=["read","bash","edit","write"],E=["bash","read","edit","write","grep","find","ls"],P=[...E,"kernel_plot_run","kernel_plot_render","kernel_plot_inspect","kernel_plot_stop","kernel_plot_artifacts"],A=[...E,M];function D(e){return[...e].sort().join(",")}function B(e){switch(e){case"none":return L;case"default":return $;case"workbench":return P;case"agent":return A;default:return E}}function N(e,t){return[...new Set([...B(e),...t])]}let O=new Map,H=["off","default","full","agent"],F={off:"none",default:"default",full:"full",agent:"agent"},_={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},U={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},K=["auto","off","minimal","low","medium","high","xhigh"],J={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},V=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function q({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function Y(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function G(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,o=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&o.push(`Page ${e}
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{43322:(e,t,r)=>{Promise.resolve().then(r.bind(r,65145))},65145:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>n0});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function a(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function s({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:a(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:a(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${b?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,a]=(0,o.useState)(""),[s,c]=(0,o.useState)(null),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),j=(0,o.useCallback)(async e=>{m(!0),b(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);a(n.current??""),c(n.parent??null),p(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){b(e instanceof Error?e.message:String(e))}finally{m(!1)}},[]);return((0,o.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&i(t)},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=g.trim();e&&j(e)},disabled:!g.trim()||v,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:g.trim()&&!v?"var(--text-muted)":"var(--text-dim)",cursor:g.trim()&&!v?"pointer":"default",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:g.trim()?"var(--accent)":"var(--bg-hover)",color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>s&&void j(s),disabled:!s,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:s?"var(--bg)":"transparent",color:s?"var(--text-muted)":"var(--text-dim)",cursor:s?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),h.length>0&&(0,n.jsxs)("select",{value:h.find(e=>l.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&j(e.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),h.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:l,children:l})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:v?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):y?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:y}):0===u.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):u.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void j(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let c="AnnoVibe",u="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function h(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function x(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function g(e){return new DOMException(e,"TimeoutError")}function f(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}function v(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function m(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"…/"+o.slice(-2).join(n)}function y(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||m(e,t)}let b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function j(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),a=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:b[Math.floor(Math.random()*b.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.108":c,r),s=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;s(t),t&&(l.current=setTimeout(()=>s(!1),3e3))},[e,s]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:a})}function k({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:i,initialSessionId:l,onInitialRestoreDone:a,refreshKey:c,onSessionDeleted:v,selectedCwd:b,onCwdChange:I}){let[R,M]=(0,o.useState)([]),[W,L]=(0,o.useState)({}),[$,E]=(0,o.useState)(()=>new Set),P=(0,o.useRef)(!1),[A,D]=(0,o.useState)(!0),[B,N]=(0,o.useState)(!1),[O,H]=(0,o.useState)(null),[F,_]=(0,o.useState)(null),[U,K]=(0,o.useState)(""),[J,V]=(0,o.useState)(null),[q,Y]=(0,o.useState)(!1),[G,Z]=(0,o.useState)("project"),[X,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(!1),[er,en]=(0,o.useState)(!1),[eo,ei]=(0,o.useState)(()=>new Set),[el,ea]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(u)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[es,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(null),[ep,eh]=(0,o.useState)(null),[ex,eg]=(0,o.useState)(!1),ef=(0,o.useRef)(null),ev=(0,o.useRef)(!1),em=(0,o.useRef)(!1),ey=(0,o.useRef)(!1),eb=(0,o.useRef)(new Map),ej=(0,o.useCallback)(async(e=!1)=>{try{let t;e&&(H(null),D(!0));let r=new AbortController;try{t=setTimeout(()=>r.abort(g("Project loading timed out")),3e4);let e=await fetch("/api/projects?sessions=false",{signal:r.signal});if(!e.ok)throw Error(await x("projects",e));let n=await e.json();M(n.projects),H(null)}finally{clearTimeout(t)}}catch(e){H(f(e,"Loading projects timed out. Codex may still be starting; click Refresh to retry."))}finally{e&&D(!1)}},[]),ek=(0,o.useCallback)(async(e,t=!1)=>{if(!e)return;let r=eb.current.get(e);if(r)return r;let n=(async()=>{L(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let r;t&&D(!0);let n=new AbortController;try{r=setTimeout(()=>n.abort(g("Chat loading timed out")),3e4);let t=await fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:n.signal});if(!t.ok)throw Error(await x("sessions",t));let o=await t.json();o.runningSessionIds&&!P.current&&E(new Set(o.runningSessionIds)),L(t=>({...t,[e]:{sessions:o.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(r)}}catch(r){let t=f(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");L(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}}))}finally{t&&D(!1),eb.current.delete(e)}})();return eb.current.set(e,n),n},[]),ew=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!ew.current;ew.current=!0,ej(e)},[ej,c]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&K(e.home)}).catch(()=>{})},[]);let eS=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(ev.current){ev.current=!1;return}if(em.current){em.current=!1;return}I?.(F)},[F,I]);let eC=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return V(n.error??`HTTP ${r.status}`),!1;return ej(!1),!0}catch(e){return V(e instanceof Error?e.message:String(e)),!1}},[ej]),eT=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ez=(0,o.useCallback)(e=>{em.current=!0,_(e),V(null),ea(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),h(r),r}),I?.(e),eT(e),ek(e,!1)},[ek,I,eT]);(0,o.useEffect)(()=>{if(0!==R.length&&null===F){if(l&&!eS.current){eS.current=!0;let e=Object.values(W).flatMap(e=>e.sessions).find(e=>e.id===l);if(e){_(e.cwd),eT(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(l)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(_(e.info.cwd),eT(e.info.cwd),t(e.info,!0)):a?.()}).catch(()=>a?.());return}let e=R[0]?.cwd;e&&(_(e),eT(e))}},[R,F,l,t,a,W,eT]);let eI=b??F;(0,o.useEffect)(()=>{let e=new EventSource("/api/agent/running/events");return e.onmessage=e=>{try{let t=JSON.parse(e.data);"running"===t.type&&(P.current=!0,E(new Set(t.runningSessionIds??[])))}catch{}},()=>e.close()},[]),(0,o.useEffect)(()=>{if(!eI)return;let e=window.setInterval(()=>{ek(eI,!1)},3e4);return()=>window.clearInterval(e)},[eI,ek]),(0,o.useEffect)(()=>{let e=()=>{eI&&ek(eI,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eI,ek]);let eR=(0,o.useCallback)(e=>{if(!e){Z("agent"),Y(!0);return}let t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(t,e)},[r]),eM=(0,o.useCallback)(e=>{if(!e){Z("workbench"),Y(!0);return}i?.(e)},[i]),eW=(0,o.useCallback)(async e=>{await eC(e,!0)&&(ez(e),Y(!1),V(null),"agent"===G&&eR(e),"workbench"===G&&eM(e))},[ez,eR,eM,G,eC]),eL=(0,o.useCallback)(e=>{Q(e),et(!0)},[]),e$=(0,o.useCallback)(()=>{et(!1),Q(null)},[]),eE=(0,o.useCallback)(e=>{let t=X??eI;e$(),"agent"===e?eR(t):eM(t)},[e$,eR,eM,eI,X]),eP=(0,o.useCallback)(()=>{eL(eI)},[eI,eL]),eA=(0,o.useCallback)(()=>{Z("project"),V(null),Y(!0)},[]),eD=(0,o.useMemo)(()=>[...eI&&!R.some(e=>e.cwd===eI)?[{cwd:eI,displayName:y(eI,U),chatCount:W[eI]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...R].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,o="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==o?n-o:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[eI,U,R,W]),eB=(0,o.useMemo)(()=>{let e=e=>{let t=W[e.cwd],r=[...t?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:e,cwd:e.cwd,displayName:e.displayName||y(e.cwd,U),sessions:r,sessionsState:t,lastAccessed:(e.lastAccessed??e.created??"")||r[0]?.modified||""}},t=eD.filter(e=>!0===e.pinned).map(e);if(eI){let r=eD.find(e=>e.cwd===eI);r&&!0!==r.pinned&&t.push(e(r))}return t},[eI,U,W,eD]);(0,o.useEffect)(()=>{if(0===eB.length||ey.current||(ey.current=!0,!eB[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eB.slice(1).map(e=>e.cwd));ea(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(h(e),e):t),window.localStorage.setItem(p,"1")},[eB]);let eN=(0,o.useCallback)((e,r=!1)=>{e.cwd!==eI&&(ev.current=!0,_(e.cwd)),ea(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),h(r),r}),eT(e.cwd),t(e,r)},[t,eI,eT]),eO=(0,o.useCallback)(e=>{ea(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),h(r),r})},[]);(0,o.useEffect)(()=>{for(let e of eB){let t=W[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eI,r=el.has(e.cwd);if(!t&&r)continue;ek(e.cwd,!1)}}},[el,eI,ek,eB,W]);let eH=(0,o.useCallback)(e=>{ei(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eF=(0,o.useCallback)(async e=>{eh("reorder");try{let t=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);M(r.projects??[]),H(null)}catch(e){H(e instanceof Error?e.message:String(e)),ej(!1)}finally{eh(null)}},[ej]),e_=(0,o.useCallback)(async(e,t)=>{eh(`pin:${e}`);try{let r=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,pinned:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);M(n.projects??[]),H(null)}catch(e){H(e instanceof Error?e.message:String(e)),ej(!1)}finally{eh(null)}},[ej]),eU=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eD.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),o=r.indexOf(t);if(-1===n||-1===o)return;let i=[...r];i.splice(n,1);let l=i.indexOf(t);i.splice(l,0,e),eF(i)},[eF,eD]),eK=(0,o.useCallback)(async()=>{N(!0);try{await ej(!1);let e=new Set([...Object.entries(W).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eI?[eI]:[]]);await Promise.all([...e].map(e=>ek(e,!1)))}finally{N(!1)}},[eI,ej,ek,W]);return(0,o.useEffect)(()=>{if(!ex)return;let e=e=>{ef.current&&!ef.current.contains(e.target)&&eg(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[ex]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)(j,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eP,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:eI?`New chat in ${eI}`:"New chat in a project path",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,n.jsx)("button",{onClick:()=>en(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,n.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,n.jsx)(s,{open:er,cwd:eI,homeDir:U,onClose:()=>en(!1),onSelectSession:e=>{eN(e)}}),(0,n.jsxs)("div",{ref:ef,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>eg(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eI?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eI?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eI??"Select project",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:eI?"var(--text)":"var(--text-dim)"},children:eI?eD.find(e=>e.cwd===eI)?.displayName??m(eI,U):"Select project…"}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:ex?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eI&&(0,n.jsx)(S,{pinned:eD.find(e=>e.cwd===eI)?.pinned===!0,onToggle:()=>void e_(eI,eD.find(e=>e.cwd===eI)?.pinned!==!0)}),ex&&(0,n.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===eD.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eD.map(e=>{let t=e.cwd===eI;return(0,n.jsx)(C,{project:e,homeDir:U,isCurrent:t,onSelect:()=>{ez(e.cwd),eg(!1)},onTogglePinned:()=>void e_(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{eg(!1),eA()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eD.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"Add project…"]})]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:eK,disabled:B,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:B?"var(--accent)":"var(--text-dim)",cursor:B?"default":"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:B?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:eA,title:"New project","aria-label":"New project",style:{height:26,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s, color 0.12s, border-color 0.12s",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v4.5A1.5 1.5 0 0 1 13 12H3a1.5 1.5 0 0 1-1.5-1.5v-6Z"}),(0,n.jsx)("path",{d:"M11 7v3M9.5 8.5h3"})]}),"New Project"]})]})]}),J&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:J})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[A&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),O&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:O}),!A&&!O&&0===eB.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!A&&!O&&eB.map(t=>{let r,o=el.has(t.cwd),i=t.cwd===eI,l=eo.has(t.cwd),a=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),s=a.length,d=a;if(s>10&&!l){d=a.slice(0,10);let t=a.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let c=s-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:ec===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ec===t.cwd),opacity:es===t.cwd?.55:1},onDragOver:e=>{es&&es!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eu(t.cwd))},onDragLeave:()=>{ec===t.cwd&&eu(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||es;eu(null),ed(null),r&&eU(r,t.cwd)},children:[(0,n.jsx)(T,{group:t,isCurrent:i,isCollapsed:o,isDragging:es===t.cwd,pinBusy:ep===`pin:${t.cwd}`,onToggle:()=>eO(t.cwd),onSelect:()=>ez(t.cwd),onTogglePinned:()=>void e_(t.cwd,!0!==t.project.pinned),onDragStart:e=>{ed(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{ed(null),eu(null)}}),!o&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(z,{node:r,selectedSessionId:e,onSelectSession:eN,onRenamed:()=>void ek(t.cwd,!1),onSessionDeleted:e=>{v?.(e),ek(t.cwd,!1)},depth:0,runningSessionIds:$},r.session.id))]})),(l||c>0)&&s>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eH(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:l?"Show less":`Show ${Math.max(0,c)} more`})]})]},t.cwd||"__no_project")})]}),ee&&(0,n.jsx)(w,{cwd:X,onChoose:eE,onClose:e$}),(0,n.jsx)(d,{open:q,initialPath:eI,onClose:()=>Y(!1),onSelect:e=>eW(e)})]})}function w({cwd:e,onChoose:t,onClose:r}){let o=e?y(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function S({pinned:e,onToggle:t}){return(0,n.jsx)("button",{type:"button",onClick:t,title:e?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:e?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:e?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:e?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function C({project:e,homeDir:t,isCurrent:r,onSelect:i,onTogglePinned:l}){let[a,s]=(0,o.useState)(!1),d=e.displayName||y(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":a?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:i,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:a?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!a,pointerEvents:a?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function T({group:e,isCurrent:t,isCollapsed:r,isDragging:i,pinBusy:l,onToggle:a,onSelect:s,onTogglePinned:d,onDragStart:c,onDragEnd:u}){let[p,h]=(0,o.useState)(!1),x=e.lastAccessed,g=Math.max(0,e.project.chatCount??e.sessions.length??0),f=!0===e.project.pinned,m=(0,o.useCallback)(()=>{t?a():s()},[t,s,a]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:c,onDragEnd:u,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),m())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:i?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:i?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!p&&g>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[g," ",1===g?"chat":"chats"]}),!p&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:v(x)}),f?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:p?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!p,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:p?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function z({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:a,runningSessionIds:s}){let[d,c]=(0,o.useState)(!1),u=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[a>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*a+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(I,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:a,hasChildren:u,collapsed:d,onToggleCollapse:()=>c(e=>!e),isRunning:s.has(e.session.id)})]}),u&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(z,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:a+1,runningSessionIds:s},e.session.id))})]})}function I({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:a=0,hasChildren:s=!1,collapsed:d=!1,onToggleCollapse:c,isRunning:u=!1}){let[p,h]=(0,o.useState)(!1),[x,g]=(0,o.useState)(!1),[f,m]=(0,o.useState)(""),[y,b]=(0,o.useState)(!1),[j,k]=(0,o.useState)(!1),w=(0,o.useRef)(null),S=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),C=(0,o.useCallback)(t=>{t.stopPropagation(),m(e.name??""),g(!0),setTimeout(()=>w.current?.select(),0)},[e.name]),T=(0,o.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[f,e.id,e.name,i]),z=(0,o.useCallback)(e=>{e.stopPropagation(),b(!0)},[]),R=(0,o.useCallback)(async t=>{t.stopPropagation(),b(!1),k(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{k(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),b(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:y||x?void 0:r,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:a>0?12*a+14:14,paddingRight:8,cursor:y||x?"default":"pointer",background:y?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:y?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:j?.5:1,gap:6,overflow:"hidden"},children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",S.slice(0,22),S.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:R,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,n.jsx)("button",{onClick:M,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):x?(0,n.jsx)("input",{ref:w,value:f,onChange:e=>m(e.target.value),onBlur:T,onKeyDown:e=>{"Enter"===e.key&&T(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[a>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===a&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:u?7:5,height:u?7:5,borderRadius:"50%",background:u?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...u?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),W&&(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:W?"var(--accent)":"var(--text)"},title:S,children:S}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:v(e.modified)}),(0,n.jsxs)("span",{children:[e.messageCount," msgs"]}),!1===e.cwdExists&&(0,n.jsx)("span",{title:`Project path missing: ${e.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),s&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c?.()},title:d?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:d?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),p&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:C,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:z,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var R=r(94456);let M="subagent",W=["retain","recall","reflect"],L=[],$=["read","bash","edit","write"],E=["bash","read","edit","write","grep","find","ls"],P=[...E,"kernel_plot_run","kernel_plot_render","kernel_plot_inspect","kernel_plot_stop","kernel_plot_artifacts"],A=[...E,M];function D(e){return[...e].sort().join(",")}function B(e){switch(e){case"none":return L;case"default":return $;case"workbench":return P;case"agent":return A;default:return E}}function N(e,t){return[...new Set([...B(e),...t])]}let O=new Map,H=["off","default","full","agent"],F={off:"none",default:"default",full:"full",agent:"agent"},_={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},U={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},K=["auto","off","minimal","low","medium","high","xhigh"],J={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},V=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function q({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function Y(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function G(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,o=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&o.push(`Page ${e}
|
|
2
2
|
${r}`)}return o.join("\n\n")}async function Z(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],i=[];for(let e of o){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];i.push(...r.map(e=>Y(e[1])))}return i.join("").replace(/[ \t]+\n/g,"\n")}async function X(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],o=t.utils.sheet_to_csv(r);return`Sheet: ${e}
|
|
3
3
|
${o}`}).join("\n\n")}async function Q(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),i=[];for(let{name:e,match:t}of o){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>Y(e[1]).trim()).filter(Boolean);r.length&&i.push(`Slide ${t[1]}
|
|
4
4
|
${r.join("\n")}`)}return i.join("\n\n")}async function ee(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,o="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))o=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)o=await G(t);else if("docx"===r)o=await Z(t);else if("xlsx"===r)o=await X(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};o=await Q(t)}let{text:i,truncated:l}=(n=o.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
|
|
5
5
|
|
|
6
|
-
[truncated after 60000 characters]`,truncated:!0};if(!i)return{extractionError:"No extractable text found"};return{extractedText:i,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let et=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:a,modelNames:s,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,sessionKind:f,onToolPresetChange:v,memoryTools:m,onMemoryToolsChange:y,thinkingLevel:b,onThinkingLevelChange:j,availableThinkingLevels:k,thinkingLevelMap:w,retryInfo:S,soundEnabled:C,onSoundToggle:T,planMode:z,onPlanModeChange:I,cornerBadge:R,promptHistory:M,sessionHistoryKey:L,activeFilePath:$,onDismissFileContext:E},P){let A,D,B,[N,Y]=(0,o.useState)(""),[G,Z]=(0,o.useState)(!1),[X,Q]=(0,o.useState)(null),[et,er]=(0,o.useState)(!1),[en,eo]=(0,o.useState)(!1),[ei,el]=(0,o.useState)(!1),[ea,es]=(0,o.useState)(!1),[ed,ec]=(0,o.useState)(!1),[eu,ep]=(0,o.useState)(null),[eh,ex]=(0,o.useState)([]),[eg,ef]=(0,o.useState)([]),ev=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),em=ev?{display:"none"}:void 0,ey=ev?28:32,eb=ev?"6px 8px":"8px 12px",ej=ev?160:180,ek=ev&&!l,ew=ed?"var(--text)":"var(--text-muted)",eS={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},eC=ev?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[eT,ez]=(0,o.useState)(null),eI=(0,o.useRef)(null),eR=(0,o.useRef)(null),eM=(0,o.useRef)(null),eW=(0,o.useRef)(null),eL=(0,o.useRef)(null),e$=(0,o.useRef)(null),eE=(0,o.useRef)(null),eP=(0,o.useRef)(null),eA=(0,o.useRef)(null),eD=(0,o.useRef)(null),eB=(0,o.useCallback)(e=>{let t=eI.current;if(!t)return void Y(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=!(o.length>0)||o.endsWith(" ")||o.endsWith("\n")?"":" ";Y(o+l+e+i),requestAnimationFrame(()=>{let t=eI.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,o.useImperativeHandle)(P,()=>({insertIfEmpty(e){let t=eI.current;(t?t.value:N).trim()||(Y(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eB(e)},addImages(e){eN(e)},addFiles(e){eO(e)}}));let eN=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ex(e=>[...e,...r])},[]),eO=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eN(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,o=await ee(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));ef(t=>[...t,...e])}},[eN]),eH=(0,o.useCallback)(e=>{ex(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eF=(0,o.useCallback)(e=>{ef(t=>{let r=[...t];return r.splice(e,1),r})},[]),e_=(0,o.useCallback)(()=>{ex(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ef([])},[]),eU=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(s??{}).map(([e,t])=>({provider:a?.provider??"unknown",modelId:e,name:t})),eK=[];for(let e of eU){let t=eK.find(t=>t.provider===e.provider);t?t.options.push(e):eK.push({provider:e.provider,options:[e]})}let eJ=a?eU.find(e=>e.modelId===a.modelId&&e.provider===a.provider)?.name??a.modelId:eU.length>0?eU[0].name:null,eV=a?eU.find(e=>e.modelId===a.modelId&&e.provider===a.provider):eU[0],eq=eV?.input?.includes("image")??!0,eY=eh.length>0&&eV?.input!==void 0&&!eq,eG=(!!N.trim()||eh.length>0||eg.length>0)&&!eY,eZ=u?V:V.filter(e=>"/compact"!==e.command),eX=eZ.filter(e=>"native"===e.kind),eQ=eZ.filter(e=>"shortcut"===e.kind),e0=m??[],e1=e0.length>0?`${e0.length} enabled`:"off",e2=eU.length>0&&!!eJ&&!!c,e5=!!j,e4=!!v&&"workbench"!==f,e3=!!y,e8=eJ??"Default",e6=(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e7=(g??"full")==="workbench"?"workbench":Object.entries(F).find(([,e])=>e===(g??"full"))?.[0]??"full",e9=ev?26:32,te=ev?7:9,tt=ev?3:6,tr={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},tn=ev&&(G||et||en||ei||ea||ed);(0,o.useEffect)(()=>{eY||ez(null)},[eY]);let to=(0,o.useCallback)(e=>{if(!N.trim()){Y(e),requestAnimationFrame(()=>{let t=eI.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eB(e)},[eB,N]),ti=(0,o.useCallback)(()=>{let t=N.trim();if(t||eh.length||eg.length){if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!eh.length&&!eg.length&&u){h?p?.():u(),Y(""),eI.current&&(eI.current.style.height="auto");return}e(t,eh.length?eh:void 0,eg.length?eg:void 0),Y(""),e_(),eI.current&&(eI.current.style.height="auto")}}},[N,eh,eg,eq,l,e,e_,u,p,h]),tl=(0,o.useCallback)(e=>{let t=N.trim();if(!t&&!eh.length&&!eg.length)return;if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eh.length?eh:void 0,o=eg.length?eg:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),Y(""),e_(),eI.current&&(eI.current.style.height="auto")},[N,eh,eg,eq,r,i,e_]),ta=M??[],ts=L??null,td=(0,o.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&ta.length>0){let t=eI.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let o=((n=O.get(e))||(n={cursor:-1,draftSnapshot:""},O.set(e,n)),n);if(-1===o.cursor)o.draftSnapshot=t,o.cursor=0;else{if(!(o.cursor<r.length-1))return null;o.cursor+=1}return r[o.cursor]??null}(ts,t.value,ta);null!==n&&(Y(n),requestAnimationFrame(()=>{t.setSelectionRange(n.length,n.length)}));return}if("ArrowDown"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&function(e){if(!e)return!1;let t=O.get(e);return(t?.cursor??-1)>=0}(ts)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=O.get(e);if(!r||-1===r.cursor)return null;if(r.cursor>0)return r.cursor-=1,{text:t[r.cursor]??"",returnedToPresent:!1};let n=r.draftSnapshot;return r.cursor=-1,r.draftSnapshot="",{text:n,returnedToPresent:!0}}(ts,ta);t&&(Y(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eI.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ts&&O.set(ts,{cursor:-1,draftSnapshot:""}),l&&(r||i)?tl(r?"steer":"followup"):ti())},[l,r,i,tl,ti,ta,ts]),tc=(0,o.useCallback)(()=>{let e=eI.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tu=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eO(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eO]);return(0,o.useEffect)(()=>{if(!G&&!et&&!en&&!ei&&!ea&&!ed)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eR.current?.contains(t),n=!!eM.current?.contains(t);r||n||Z(!1),eW.current?.contains(t)||er(!1),eL.current?.contains(t)||eo(!1),e$.current?.contains(t)||el(!1),eE.current?.contains(t)||es(!1),eP.current?.contains(t)||ec(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[G,et,en,ei,ea,ed]),(0,o.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||ep(!!t?.ready)}).catch(()=>{e||ep(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:eC,children:[tn&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{Z(!1),er(!1),eo(!1),el(!1),es(!1),ec(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eA,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eN(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eD,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{eO(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:ev?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ev?"0 8px":void 0,boxSizing:"border-box"},children:[R&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:R}),S&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ev?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",S.attempt,"/",S.maxAttempts,")…",S.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",S.errorMessage]})]}),$&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:ev?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$.replace(/^.*[\\/]/,"")}),E&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),E()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(eh.length>0||eg.length>0)&&(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[eh.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${eY?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eH(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),eg.map((e,t)=>(0,n.jsx)(q,{doc:e,onRemove:()=>eF(t)},`doc-${t}`))]}),(eY||eT)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ev?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M10.29 3.86 1.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"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,n.jsx)("span",{children:eT??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:ev?4:8,alignItems:ev?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ev?13:14,padding:ev?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:eI,value:N,onChange:e=>Y(e.target.value),onKeyDown:td,onInput:tc,onPaste:tu,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ev?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!ev,paddingBottom:+!!ev}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ev?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tl("steer"),disabled:!eG,title:eY?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eG?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!ev&&"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>tl("followup"),disabled:!eG,title:eY?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eG?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!ev&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:ti,disabled:!eG,title:eY?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ev?3:6,padding:ev?"5px 9px":"7px 14px",marginBottom:+!!ev,background:eG?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eG?"#fff":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:ev?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eG?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:ev?13:14,height:ev?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:ev?5:8,display:"flex",alignItems:ev?"flex-start":"center",gap:tt,flexWrap:ev?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ev?"1 1 100%":"0 0 auto",width:ev?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ev,flexWrap:ev?"wrap":"nowrap",rowGap:4*!!ev},children:[(0,n.jsx)("button",{onClick:()=>eA.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:"none",border:"none",borderRadius:te,color:eh.length||eg.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eD.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(er(e=>!e),eo(!1),Z(!1),el(!1),es(!1),ec(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:te,color:x?"#ef4444":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=x?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=et?"var(--bg-hover)":"none",e.currentTarget.style.color=x?"#ef4444":"var(--text-muted)"},children:["/",x&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),et&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:x?"1px solid var(--border)":"none"},children:"Commands"}),x&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:x}),eX.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),eX.map(e=>(0,n.jsxs)("button",{onClick:()=>{(er(!1),"/compact"===e.command&&h)?p?.():to(e.command)},style:{display:"flex",alignItems:"center",gap:ev?6:8,width:"100%",padding:eb,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&h?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&h?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&h?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&h?"中止当前压缩任务":e.description})]})]},e.command))]}),eQ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eX.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eX.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eQ.map(e=>(0,n.jsxs)("button",{onClick:()=>{er(!1),to(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eb,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),y&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(eo(e=>!e),er(!1),Z(!1),el(!1),es(!1),ec(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ey,padding:0,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:e0.length>0?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=en?"var(--bg-hover)":"none",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),e0.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),en&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),W.map(e=>{let t=e0.includes(e),r=U[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?e0.filter(t=>t!==e):[...e0,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eb,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:r.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:r.description})]})]},e)})]})]}),e2&&(0,n.jsxs)("div",{ref:eR,style:{position:"relative",flex:ev?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!ev){let t=e.currentTarget.getBoundingClientRect();Q({top:t.top,left:t.left,width:t.width})}er(!1),eo(!1),el(!1),es(!1),ec(!1),Z(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:eb,height:ey,width:ev?"100%":void 0,maxWidth:ev?"100%":220,overflow:"hidden",background:G?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=G?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eJ})]}),G&&(ev?(0,n.jsxs)("div",{ref:eM,style:{...tr,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:eJ})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===a?.modelId&&e.provider===a?.provider;return(0,n.jsxs)("button",{onClick:()=>{Z(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"10px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"normal",lineHeight:1.35},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:8},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})]}):X&&(D=(A=window.visualViewport?.height??window.innerHeight)-X.top+6,B=Math.max(120,Math.min(X.top-8,.6*A)),(0,n.jsx)("div",{ref:eM,style:{position:"fixed",bottom:D,left:X.left,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",width:"max-content",minWidth:X.width,maxHeight:B,overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===a?.modelId&&e.provider===a?.provider;return(0,n.jsxs)("button",{onClick:()=>{Z(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]}),ev&&!l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:eP,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),eo(!1),Z(!1),el(!1),es(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),es(!1),el(!1),eo(!1),Z(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),el(!1),eo(!1),es(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),eo(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),el(!1),eo(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]}),void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),I(!z)},style:{...eS,border:z?"1px solid rgba(59,130,246,0.24)":"none",background:z?"rgba(59,130,246,0.06)":"none"},children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Mode"}),(0,n.jsx)("div",{style:{fontSize:12,color:z?"#3b82f6":"var(--text)",marginTop:2},children:z?"Plan(只读规划)":"Code(可执行)"})]})]})]})]}),(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",borderRadius:8,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ek?"none":void 0,flex:ev?"0 0 auto":1,width:ev?0:void 0,height:ev?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:ev?"auto":void 0,display:"flex",alignItems:"center",gap:ev?4:2,marginLeft:ev?0:"auto",marginTop:0},children:[ek&&!ev&&(0,n.jsxs)("div",{ref:eP,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),eo(!1),Z(!1),el(!1),es(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),es(!1),el(!1),eo(!1),Z(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),el(!1),eo(!1),es(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),eo(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),el(!1),eo(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]})]})]})]}),(!ek&&!l||ev&&ea)&&j&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),eo(!1),Z(!1),el(!1),ec(!1),es(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:eb,height:ey,background:ea?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ea?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,n.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(0,n.jsx)("span",{style:em,children:(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),ea&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:ej},overflow:"hidden"},children:K.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(b??"auto")===e,r=J[e],o="auto"!==e&&w?w[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{es(!1),t||j(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ek&&!l||ev&&ei)&&e4&&(0,n.jsxs)("div",{ref:e$,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),eo(!1),Z(!1),es(!1),ec(!1),el(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:eb,height:ey,background:ei?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ei?"var(--bg-hover)":"none",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,n.jsx)("span",{style:em,children:e7})]}),ei&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:H.map(e=>{let t=F[e],r=(g??"full")===t,o="agent"===e&&!1===eu,i=o?"需安装 pi-subagents":_[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(el(!1),r||v(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ey,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ev?8:9,color:"#ef4444",cursor:"pointer",fontSize:ev?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),!ek&&void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{l||I(!z)},disabled:l,title:z?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:eb,height:ey,background:z?"rgba(59,130,246,0.08)":"none",border:z?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:ev?8:9,color:z?"#3b82f6":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background=z?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color=z?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=z?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color=z?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:em,children:z?"Plan":"Code"})]}),!ev&&void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ev?28:32,height:ev?28:32,padding:0,background:"none",border:"none",borderRadius:ev?8:9,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function er(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function en({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,a]=(0,o.useState)(0),[s,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(a(0),d(1)):(a(e.scrollTop/o),d(n/t));let l=i.current,s=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,a=r.height;s.push({topRatio:l/t,heightRatio:a/t,msg:n,index:s.length})}}h(s)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-s,e))/(1-s)*n)},[r,s]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-s),o=n>=0&&n<=s?n:s/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},a=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",a)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",a)},[c,s,l,S]),T=y.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-s)*100,R=100*s,M=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${R}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=er(e.msg),r=x&&M===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=er(e.msg),i=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function eo(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ei(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function el(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ea(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function es(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:ei(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!eo(t))return{...e,summary:ei(r)};let o=Array.isArray(t.results)?t.results.filter(eo):[],i=o[0],l=i?.progressSummary,a=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],s=el(i?.finalOutput,i?.output,r);return{...e,mode:el(t.mode),runId:el(t.runId),agent:el(i?.agent,e.agent)??e.agent,task:el(i?.task,e.task),summary:ei(s),model:el(i?.model),durationMs:ea(l?.durationMs),toolCount:ea(l?.toolCount),tokens:ea(l?.tokens),outputPath:el(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:el(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:a,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return eo(t)&&Array.isArray(t.results)&&t.results.some(e=>eo(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function ed({messages:e,runs:t}){let r=(0,o.useMemo)(()=>es(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),a=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(ec,{title:`Active (${l.length})`,runs:l}),a.length>0&&(0,n.jsx)(ec,{title:`Completed (${a.length})`,runs:a,compact:l.length>0})]})}function ec({title:e,runs:t,compact:r}){return(0,n.jsxs)("div",{style:{marginBottom:r?10:16},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t.map(e=>(0,n.jsx)(eu,{run:e},e.id))]})}function eu({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",a="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",s="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${a}`,background:s,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(ep,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:ei(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${a}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(eh,{run:e})]})]})}function ep({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function eh({run:e}){let t=[e.model?["model",e.model]:void 0,e.runId?["run",e.runId]:void 0,e.outputPath?["output",e.outputPath]:void 0,e.sessionFile?["session",e.sessionFile]:void 0,...(e.artifacts??[]).slice(0,4).map((e,t)=>[`artifact ${t+1}`,e])].filter(Boolean);return 0===t.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:t.map(([e,t])=>(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:e}),(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t,children:t})]},`${e}:${t}`))})}function ex({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:o,isNew:i,isStreaming:l=!1,onResume:a,onDismiss:s}){if(i||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),o&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",o.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:s,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,n.jsx)("button",{type:"button",onClick:a,disabled:l,title:l?"Wait until the agent finishes before updating Workbench":c?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:l?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:l?.55:1,whiteSpace:"nowrap"},children:c?"Reload Initial Data":"Resume Workbench"})]})}function eg(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:r}}async function ef(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}var ev=r(28999);async function em(e,t){if(!t.length)return[];let r=await fetch("/api/images/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,images:t.map(e=>({data:e.data,mimeType:e.mimeType,name:e.name}))})}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`Upload failed (HTTP ${r.status})`);return(n.uploaded??[]).map((e,r)=>({...e,previewUrl:t[r]?.previewUrl}))}async function ey(e,t,r){let n=new TextDecoder,o="",i=new Promise(e=>{r?.aborted?e():r?.addEventListener("abort",()=>e(),{once:!0})});for(;;){let r=await Promise.race([e.read(),i.then(()=>({done:!0,value:void 0}))]);if(r.done)break;let l=(o+=n.decode(r.value,{stream:!0})).split("\n");for(let e of(o=l.pop()||"",l)){if(!e.startsWith("data: "))continue;let r=e.slice(6);if("[DONE]"!==r)try{t(r)}catch{}}}if(o.trim())for(let e of o.split("\n")){if(!e.startsWith("data: "))continue;let r=e.slice(6);if("[DONE]"!==r)try{t(r)}catch{}}}let eb="__annovibeStreamSessions__",ej="__annovibeStreamListeners__",ek="__annovibeStreamErrorCallbacks__";function ew(){let e=globalThis;return e[eb]||(e[eb]=new Map),e[eb]}function eS(){let e=globalThis;return e[ek]||(e[ek]=new Map),e[ek]}function eC(e){return{sessionId:e,phase:"idle",startedAt:null,lastEventAt:null,lastHeartbeatAt:null,reconnectCount:0,lastSyncReason:null,accumulatedText:"",toolCalls:[],toolResults:[],statusText:null,streamingMessage:null,isStreaming:!1,error:null}}function eT(e,t){let r;for(let n of(!(r=globalThis)[ej]&&(r[ej]=new Map),r[ej]).get(e)??[])try{n(t)}catch{}}function ez(e){e.textThrottleTimer&&(clearTimeout(e.textThrottleTimer),e.textThrottleTimer=null),e.textDirty&&(e.textDirty=!1,eR(e))}function eI(e,t=!1){let r=Date.now();if(e.snapshot.lastEventAt=r,!t){e.textDirty=!0,e.textThrottleTimer||(e.textThrottleTimer=setTimeout(()=>{e.textThrottleTimer=null,e.textDirty&&(e.textDirty=!1,eR(e))},100));return}ez(e),eR(e)}function eR(e,t){let r=Date.now(),n=function(e){let t=[];for(let r of e.toolCalls.values())t.push({type:"toolCall",toolCallId:r.toolCallId,toolName:r.toolName,input:r.input??{}});let r=e.accumulatedText.trim();return r&&t.push({type:"text",text:r}),t}(e),o=(t??e.snapshot.phase)==="active";e.snapshot={...e.snapshot,phase:t??e.snapshot.phase,lastEventAt:r,accumulatedText:e.accumulatedText,toolCalls:[...e.toolCalls.values()],toolResults:[...e.toolResults.values()],statusText:o?function(e){if(e.activeToolId){let t=e.toolCalls.get(e.activeToolId);if(t){let e=Math.max(0,Math.floor((Date.now()-t.startedAt)/1e3));return`Running ${t.toolName||"tool"}… (${e}s)`}}return e.accumulatedText.trim()?"Generating response…":e.toolCalls.size>0?"Finishing tool results…":null}(e):e.snapshot.statusText,streamingMessage:o&&n.length>0?{role:"assistant",content:n}:null,isStreaming:o},eT(e.snapshot.sessionId,{type:"snapshot-updated",snapshot:e.snapshot})}function eM(e){eW(e),e.idleCheckTimer=setInterval(()=>{if("connected"!==e.connectionState)return;let t=Math.max(e.snapshot.lastEventAt??0,e.snapshot.lastHeartbeatAt??0);if(Date.now()-t>=18e4){eL(e),ez(e);let t="Stream idle timeout — no activity for 180s.";e.snapshot={...e.snapshot,phase:"error",isStreaming:!1,streamingMessage:null,statusText:null,error:t},eW(e),eT(e.snapshot.sessionId,{type:"error",snapshot:e.snapshot});let r=eS().get(e.snapshot.sessionId);if(r)try{r(e.snapshot.sessionId,t)}catch{}}},1e4)}function eW(e){e.idleCheckTimer&&(clearInterval(e.idleCheckTimer),e.idleCheckTimer=null)}function eL(e){e.toolProgressTimer&&(clearInterval(e.toolProgressTimer),e.toolProgressTimer=null)}function e$(e){let t=ew(),r=t.get(e);return r||(r={snapshot:eC(e),accumulatedText:"",toolCalls:new Map,toolResults:new Map,toolProgressTimer:null,activeToolId:null,textThrottleTimer:null,textDirty:!1,connectionState:"idle",idleCheckTimer:null},t.set(e,r)),r}function eE(e,t){let r=eS();return r.set(e,t),()=>{r.get(e)===t&&r.delete(e)}}function eP(e){let t=ew(),r=t.get(e);r&&(eL(r),eW(r),ez(r)),t.delete(e)}function eA(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function eD(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}-${Math.random().toString(36).slice(2,11)}`}let eB=["read","bash","grep","find","ls"];function eN(e,t){return e.trim()||0!==t?`text:${e}|images:${t}`:null}function eO(e){return"string"==typeof e?eN(e,0):Array.isArray(e)?eN(e.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"),e.filter(e=>!!e&&"object"==typeof e&&"image"===e.type).length):null}function eH(e){let t=new Map;for(let r of e){let e="user"!==r.role?null:eO(r.content);e&&t.set(e,(t.get(e)??0)+1)}return t}function eF(e,t,r){return e.sessionId===t&&(!e.leafId||r.includes(e.leafId))}let e_=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function eU(e){return e_.some(t=>e.type.startsWith(t))}function eK({agentPhase:e,startedAt:t}){let[r,i]=(0,o.useState)(0);return(0,o.useEffect)(()=>{if(!t)return void i(0);let e=()=>i(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);return 0===t.length?"Running tool…":1===t.length?`Running ${t[0]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(r)]})})}function eJ(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function eV({goal:e,planTasks:t,isRunning:r,onExecutePlan:i,onContinuePlanning:l,onEditPlan:a}){let[s,d]=(0,o.useState)(!1),c=(0,o.useCallback)(()=>d(e=>!e),[]),u=e&&"dropped"!==e.status,p=t&&t.length>0;if(!u&&!p)return null;let h=(0,o.useMemo)(()=>!e?.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e?.tokenBudget,e?.tokensUsed]),x=t?.filter(e=>"completed"===e.status).length??0,g=!!t&&x===t.length;return(0,n.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[u&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:p?"1px solid var(--border)":"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[eJ(e.tokensUsed),e.tokenBudget?` / ${eJ(e.tokenBudget)} tokens`:" tokens"]}),null!=h&&(0,n.jsxs)("span",{children:[h,"%"]})]}),null!=h&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:h>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(h,100)}%`,transition:"width 0.3s"}})})]}),p&&(0,n.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,n.jsxs)("div",{onClick:c,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&c()},"aria-expanded":!s,style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,cursor:"pointer",padding:"6px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"#3b82f6"},children:["Plan \xb7 ",t.length," 步"]}),g&&(0,n.jsxs)("span",{style:{borderRadius:4,padding:"0 6px",fontSize:10,fontWeight:600,background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",x,"/",t.length]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(a||l||i)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),a()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"修改计划"}),l&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"继续规划"}),i&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),i()},disabled:r,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:r?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:r?"not-allowed":"pointer"},children:"执行计划"})]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:s?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!s&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,borderRadius:4,padding:"3px 8px",background:"inProgress"===e.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,n.jsx)("div",{style:{marginTop:1},children:function(e){switch(e){case"completed":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,n.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,n.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round",children:(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"1.5s",repeatCount:"indefinite"})})]});default:return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"var(--border)",strokeWidth:"1.5"})})}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:12,lineHeight:1.5,...function(e){switch(e){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(e.status)},children:e.step})]},e.id))})]})]})}function eq(e){let t=e.findIndex(e=>"completed"!==e.status);return t<0?e:e.map((e,r)=>r===t?{...e,status:"completed"}:r===t+1&&"pending"===e.status?{...e,status:"inProgress"}:e)}let eY=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function eG({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[a,s]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(a||i!==o)if(a&&""===i)s(!1),r(t=>(t+1)%e.length);else{let e=a?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),a?28:55)}else n=setTimeout(()=>s(!0),1800);return()=>clearTimeout(n)},[i,a,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eZ({status:e}){let t=e?.current??"0.8.107"??"0.0.0";if(e?.updateAvailable){let r=e.latest?`v${e.latest}`:"latest";return(0,n.jsxs)("span",{title:`Current v${t}; latest ${r}; run ${e.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:e.updateCommand})]})}return(0,n.jsxs)("span",{title:`AnnoVibe v${t}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",t]})}function eX({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:a,chatInputRef:s,onBranchDataChange:d,onSessionStatsChange:u,onContextUsageChange:p,onToolPresetActive:h,generativeUI:x,activeFilePath:g,onOpenFileAtLine:f}){var v;let m,[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)([]),[C,T]=(0,o.useState)(""),[z,I]=(0,o.useState)(!1),L=(0,o.useRef)(!1),[B,O]=(0,o.useState)(!1),H=g&&!B?g:null;(0,o.useEffect)(()=>{O(!1)},[g]);let{data:F,loading:_,error:U,messages:K,entryIds:J,streamState:V,agentRunning:q,modelNames:Y,modelList:G,modelThinkingLevels:Z,modelThinkingLevelMaps:X,toolPreset:Q,memoryTools:ee,thinkingLevel:er,retryInfo:eo,contextUsage:ei,forkingEntryId:el,isCompacting:ea,compactError:ec,displayModel:eu,sessionStats:ep,agentPhase:eh,agentError:eb,isNew:ej,loadMoreMessages:ek,hasMoreMessages:eS,totalMessages:eR,loadedMessagesCount:e_,messagesEndRef:eJ,scrollContainerRef:eQ,lastUserMsgRef:e0,handleSend:e1,handleAbort:e2,handleFork:e5,handleNavigate:e4,handleModelChange:e3,handleCompact:e8,handleSteer:e6,handleFollowUp:e7,handleAbortCompaction:e9,handleToolPresetChange:te,handleMemoryToolsChange:tt,handleThinkingLevelChange:tr,handleAgentEventRef:tn}=function(e){let{session:t,newSessionCwd:r,planMode:n=!1,onAgentEnd:i,onSessionCreated:l,onSessionForked:a,modelsRefreshKey:s,onBranchDataChange:d,onPlanModeState:c}=e,u=null===t&&null!==r,[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!u),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useState)(0),[T,z]=(0,o.useState)(!1),[I,R]=(0,o.useState)(0),[L,B]=(0,o.useReducer)(eA,{isStreaming:!1,streamingMessage:null}),[O,H]=(0,o.useState)(!1),[F,_]=(0,o.useState)({}),[U,K]=(0,o.useState)([]),[J,V]=(0,o.useState)({}),[q,Y]=(0,o.useState)({}),[G,Z]=(0,o.useState)(null),[X,Q]=(0,o.useState)("full"),[ee,et]=(0,o.useState)([...W]),[er,en]=(0,o.useState)("auto"),[eo,ei]=(0,o.useState)(null),[el,ea]=(0,o.useState)(null),[es,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(null),[ep,eh]=(0,o.useState)(null),[ex,eb]=(0,o.useState)(null),[ej,ek]=(0,o.useState)(!1),[eS,eR]=(0,o.useState)(null),[e_,eU]=(0,o.useState)(null),[eK,eJ]=(0,o.useState)(null),eV=(0,o.useRef)(null),eq=(0,o.useRef)(t?.id??null),eY=(0,o.useRef)(!1),eG=(0,o.useRef)(null),eZ=(0,o.useRef)(null),eX=(0,o.useRef)(null),eQ=(0,o.useRef)(!1),e0=(0,o.useRef)(null),e1=(0,o.useRef)(!1),e2=(0,o.useRef)(null),e5=(0,o.useRef)(null),e4=(0,o.useRef)(new Map),e3=(0,o.useRef)(new Map),e8=(0,o.useRef)(null),e6=(0,o.useRef)(null),e7=(0,o.useRef)(0);(0,o.useEffect)(()=>{e8.current=m},[m]);let e9=e.setNewSessionModel??Z,te=e.setToolPreset??Q,tt=e.setMemoryTools??et,tr=ep??p?.context.model??ex??null,tn=u?G:tr,to=(0,o.useCallback)(()=>n?eB:N(X,ee),[ee,n,X]),ti=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
|
|
6
|
+
[truncated after 60000 characters]`,truncated:!0};if(!i)return{extractionError:"No extractable text found"};return{extractedText:i,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let et=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:a,modelNames:s,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,sessionKind:f,onToolPresetChange:v,memoryTools:m,onMemoryToolsChange:y,thinkingLevel:b,onThinkingLevelChange:j,availableThinkingLevels:k,thinkingLevelMap:w,retryInfo:S,soundEnabled:C,onSoundToggle:T,planMode:z,onPlanModeChange:I,cornerBadge:R,promptHistory:M,sessionHistoryKey:L,activeFilePath:$,onDismissFileContext:E},P){let A,D,B,[N,Y]=(0,o.useState)(""),[G,Z]=(0,o.useState)(!1),[X,Q]=(0,o.useState)(null),[et,er]=(0,o.useState)(!1),[en,eo]=(0,o.useState)(!1),[ei,el]=(0,o.useState)(!1),[ea,es]=(0,o.useState)(!1),[ed,ec]=(0,o.useState)(!1),[eu,ep]=(0,o.useState)(null),[eh,ex]=(0,o.useState)([]),[eg,ef]=(0,o.useState)([]),ev=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),em=ev?{display:"none"}:void 0,ey=ev?28:32,eb=ev?"6px 8px":"8px 12px",ej=ev?160:180,ek=ev&&!l,ew=ed?"var(--text)":"var(--text-muted)",eS={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},eC=ev?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[eT,ez]=(0,o.useState)(null),eI=(0,o.useRef)(null),eR=(0,o.useRef)(null),eM=(0,o.useRef)(null),eW=(0,o.useRef)(null),eL=(0,o.useRef)(null),e$=(0,o.useRef)(null),eE=(0,o.useRef)(null),eP=(0,o.useRef)(null),eA=(0,o.useRef)(null),eD=(0,o.useRef)(null),eB=(0,o.useCallback)(e=>{let t=eI.current;if(!t)return void Y(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=!(o.length>0)||o.endsWith(" ")||o.endsWith("\n")?"":" ";Y(o+l+e+i),requestAnimationFrame(()=>{let t=eI.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,o.useImperativeHandle)(P,()=>({insertIfEmpty(e){let t=eI.current;(t?t.value:N).trim()||(Y(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eB(e)},addImages(e){eN(e)},addFiles(e){eO(e)}}));let eN=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ex(e=>[...e,...r])},[]),eO=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eN(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,o=await ee(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));ef(t=>[...t,...e])}},[eN]),eH=(0,o.useCallback)(e=>{ex(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eF=(0,o.useCallback)(e=>{ef(t=>{let r=[...t];return r.splice(e,1),r})},[]),e_=(0,o.useCallback)(()=>{ex(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ef([])},[]),eU=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(s??{}).map(([e,t])=>({provider:a?.provider??"unknown",modelId:e,name:t})),eK=[];for(let e of eU){let t=eK.find(t=>t.provider===e.provider);t?t.options.push(e):eK.push({provider:e.provider,options:[e]})}let eJ=a?eU.find(e=>e.modelId===a.modelId&&e.provider===a.provider)?.name??a.modelId:eU.length>0?eU[0].name:null,eV=a?eU.find(e=>e.modelId===a.modelId&&e.provider===a.provider):eU[0],eq=eV?.input?.includes("image")??!0,eY=eh.length>0&&eV?.input!==void 0&&!eq,eG=(!!N.trim()||eh.length>0||eg.length>0)&&!eY,eZ=u?V:V.filter(e=>"/compact"!==e.command),eX=eZ.filter(e=>"native"===e.kind),eQ=eZ.filter(e=>"shortcut"===e.kind),e0=m??[],e1=e0.length>0?`${e0.length} enabled`:"off",e2=eU.length>0&&!!eJ&&!!c,e5=!!j,e4=!!v&&"workbench"!==f,e3=!!y,e8=eJ??"Default",e6=(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e7=(g??"full")==="workbench"?"workbench":Object.entries(F).find(([,e])=>e===(g??"full"))?.[0]??"full",e9=ev?26:32,te=ev?7:9,tt=ev?3:6,tr={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},tn=ev&&(G||et||en||ei||ea||ed);(0,o.useEffect)(()=>{eY||ez(null)},[eY]);let to=(0,o.useCallback)(e=>{if(!N.trim()){Y(e),requestAnimationFrame(()=>{let t=eI.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eB(e)},[eB,N]),ti=(0,o.useCallback)(()=>{let t=N.trim();if(t||eh.length||eg.length){if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!eh.length&&!eg.length&&u){h?p?.():u(),Y(""),eI.current&&(eI.current.style.height="auto");return}e(t,eh.length?eh:void 0,eg.length?eg:void 0),Y(""),e_(),eI.current&&(eI.current.style.height="auto")}}},[N,eh,eg,eq,l,e,e_,u,p,h]),tl=(0,o.useCallback)(e=>{let t=N.trim();if(!t&&!eh.length&&!eg.length)return;if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eh.length?eh:void 0,o=eg.length?eg:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),Y(""),e_(),eI.current&&(eI.current.style.height="auto")},[N,eh,eg,eq,r,i,e_]),ta=M??[],ts=L??null,td=(0,o.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&ta.length>0){let t=eI.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let o=((n=O.get(e))||(n={cursor:-1,draftSnapshot:""},O.set(e,n)),n);if(-1===o.cursor)o.draftSnapshot=t,o.cursor=0;else{if(!(o.cursor<r.length-1))return null;o.cursor+=1}return r[o.cursor]??null}(ts,t.value,ta);null!==n&&(Y(n),requestAnimationFrame(()=>{t.setSelectionRange(n.length,n.length)}));return}if("ArrowDown"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&function(e){if(!e)return!1;let t=O.get(e);return(t?.cursor??-1)>=0}(ts)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=O.get(e);if(!r||-1===r.cursor)return null;if(r.cursor>0)return r.cursor-=1,{text:t[r.cursor]??"",returnedToPresent:!1};let n=r.draftSnapshot;return r.cursor=-1,r.draftSnapshot="",{text:n,returnedToPresent:!0}}(ts,ta);t&&(Y(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eI.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ts&&O.set(ts,{cursor:-1,draftSnapshot:""}),l&&(r||i)?tl(r?"steer":"followup"):ti())},[l,r,i,tl,ti,ta,ts]),tc=(0,o.useCallback)(()=>{let e=eI.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tu=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eO(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eO]);return(0,o.useEffect)(()=>{if(!G&&!et&&!en&&!ei&&!ea&&!ed)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eR.current?.contains(t),n=!!eM.current?.contains(t);r||n||Z(!1),eW.current?.contains(t)||er(!1),eL.current?.contains(t)||eo(!1),e$.current?.contains(t)||el(!1),eE.current?.contains(t)||es(!1),eP.current?.contains(t)||ec(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[G,et,en,ei,ea,ed]),(0,o.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||ep(!!t?.ready)}).catch(()=>{e||ep(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:eC,children:[tn&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{Z(!1),er(!1),eo(!1),el(!1),es(!1),ec(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eA,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eN(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eD,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{eO(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:ev?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ev?"0 8px":void 0,boxSizing:"border-box"},children:[R&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:R}),S&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ev?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",S.attempt,"/",S.maxAttempts,")…",S.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",S.errorMessage]})]}),$&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:ev?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$.replace(/^.*[\\/]/,"")}),E&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),E()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(eh.length>0||eg.length>0)&&(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[eh.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${eY?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eH(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),eg.map((e,t)=>(0,n.jsx)(q,{doc:e,onRemove:()=>eF(t)},`doc-${t}`))]}),(eY||eT)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ev?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M10.29 3.86 1.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"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,n.jsx)("span",{children:eT??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:ev?4:8,alignItems:ev?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ev?13:14,padding:ev?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:eI,value:N,onChange:e=>Y(e.target.value),onKeyDown:td,onInput:tc,onPaste:tu,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ev?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!ev,paddingBottom:+!!ev}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ev?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tl("steer"),disabled:!eG,title:eY?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eG?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!ev&&"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>tl("followup"),disabled:!eG,title:eY?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eG?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!ev&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:ti,disabled:!eG,title:eY?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ev?3:6,padding:ev?"5px 9px":"7px 14px",marginBottom:+!!ev,background:eG?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eG?"#fff":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:ev?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eG?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:ev?13:14,height:ev?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:ev?5:8,display:"flex",alignItems:ev?"flex-start":"center",gap:tt,flexWrap:ev?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ev?"1 1 100%":"0 0 auto",width:ev?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ev,flexWrap:ev?"wrap":"nowrap",rowGap:4*!!ev},children:[(0,n.jsx)("button",{onClick:()=>eA.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:"none",border:"none",borderRadius:te,color:eh.length||eg.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eD.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(er(e=>!e),eo(!1),Z(!1),el(!1),es(!1),ec(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:te,color:x?"#ef4444":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=x?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=et?"var(--bg-hover)":"none",e.currentTarget.style.color=x?"#ef4444":"var(--text-muted)"},children:["/",x&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),et&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:x?"1px solid var(--border)":"none"},children:"Commands"}),x&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:x}),eX.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),eX.map(e=>(0,n.jsxs)("button",{onClick:()=>{(er(!1),"/compact"===e.command&&h)?p?.():to(e.command)},style:{display:"flex",alignItems:"center",gap:ev?6:8,width:"100%",padding:eb,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&h?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&h?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&h?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&h?"中止当前压缩任务":e.description})]})]},e.command))]}),eQ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eX.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eX.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eQ.map(e=>(0,n.jsxs)("button",{onClick:()=>{er(!1),to(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eb,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),y&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(eo(e=>!e),er(!1),Z(!1),el(!1),es(!1),ec(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ey,padding:0,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:e0.length>0?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=en?"var(--bg-hover)":"none",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),e0.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),en&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),W.map(e=>{let t=e0.includes(e),r=U[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?e0.filter(t=>t!==e):[...e0,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:eb,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:r.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:r.description})]})]},e)})]})]}),e2&&(0,n.jsxs)("div",{ref:eR,style:{position:"relative",flex:ev?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!ev){let t=e.currentTarget.getBoundingClientRect();Q({top:t.top,left:t.left,width:t.width})}er(!1),eo(!1),el(!1),es(!1),ec(!1),Z(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:eb,height:ey,width:ev?"100%":void 0,maxWidth:ev?"100%":220,overflow:"hidden",background:G?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=G?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eJ})]}),G&&(ev?(0,n.jsxs)("div",{ref:eM,style:{...tr,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:eJ})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===a?.modelId&&e.provider===a?.provider;return(0,n.jsxs)("button",{onClick:()=>{Z(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"10px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"normal",lineHeight:1.35},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:8},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})]}):X&&(D=(A=window.visualViewport?.height??window.innerHeight)-X.top+6,B=Math.max(120,Math.min(X.top-8,.6*A)),(0,n.jsx)("div",{ref:eM,style:{position:"fixed",bottom:D,left:X.left,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",width:"max-content",minWidth:X.width,maxHeight:B,overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===a?.modelId&&e.provider===a?.provider;return(0,n.jsxs)("button",{onClick:()=>{Z(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]}),ev&&!l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:eP,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),eo(!1),Z(!1),el(!1),es(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),es(!1),el(!1),eo(!1),Z(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),el(!1),eo(!1),es(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),eo(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),el(!1),eo(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]}),void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),I(!z)},style:{...eS,border:z?"1px solid rgba(59,130,246,0.24)":"none",background:z?"rgba(59,130,246,0.06)":"none"},children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Mode"}),(0,n.jsx)("div",{style:{fontSize:12,color:z?"#3b82f6":"var(--text)",marginTop:2},children:z?"Plan(只读规划)":"Code(可执行)"})]})]})]})]}),(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",borderRadius:8,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ek?"none":void 0,flex:ev?"0 0 auto":1,width:ev?0:void 0,height:ev?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:ev?"auto":void 0,display:"flex",alignItems:"center",gap:ev?4:2,marginLeft:ev?0:"auto",marginTop:0},children:[ek&&!ev&&(0,n.jsxs)("div",{ref:eP,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),eo(!1),Z(!1),el(!1),es(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),es(!1),el(!1),eo(!1),Z(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),el(!1),eo(!1),es(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),eo(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),Z(!1),es(!1),el(!1),eo(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]})]})]})]}),(!ek&&!l||ev&&ea)&&j&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),eo(!1),Z(!1),el(!1),ec(!1),es(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:eb,height:ey,background:ea?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ea?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,n.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(0,n.jsx)("span",{style:em,children:(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),ea&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:ej},overflow:"hidden"},children:K.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(b??"auto")===e,r=J[e],o="auto"!==e&&w?w[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{es(!1),t||j(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ek&&!l||ev&&ei)&&e4&&(0,n.jsxs)("div",{ref:e$,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),eo(!1),Z(!1),es(!1),ec(!1),el(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:eb,height:ey,background:ei?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ei?"var(--bg-hover)":"none",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,n.jsx)("span",{style:em,children:e7})]}),ei&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:H.map(e=>{let t=F[e],r=(g??"full")===t,o="agent"===e&&!1===eu,i=o?"需安装 pi-subagents":_[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(el(!1),r||v(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ey,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ev?8:9,color:"#ef4444",cursor:"pointer",fontSize:ev?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),!ek&&void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{l||I(!z)},disabled:l,title:z?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:eb,height:ey,background:z?"rgba(59,130,246,0.08)":"none",border:z?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:ev?8:9,color:z?"#3b82f6":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background=z?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color=z?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=z?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color=z?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:em,children:z?"Plan":"Code"})]}),!ev&&void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ev?28:32,height:ev?28:32,padding:0,background:"none",border:"none",borderRadius:ev?8:9,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function er(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function en({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,a]=(0,o.useState)(0),[s,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(a(0),d(1)):(a(e.scrollTop/o),d(n/t));let l=i.current,s=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,a=r.height;s.push({topRatio:l/t,heightRatio:a/t,msg:n,index:s.length})}}h(s)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-s,e))/(1-s)*n)},[r,s]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-s),o=n>=0&&n<=s?n:s/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},a=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",a)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",a)},[c,s,l,S]),T=y.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-s)*100,R=100*s,M=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${R}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=er(e.msg),r=x&&M===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=er(e.msg),i=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function eo(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function ei(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function el(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ea(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function es(e){let t=new Map;for(let r of e){if("custom"===r.role&&"subagent-notify"===r.customType&&"string"==typeof r.content){let e=r.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(e){let n=`bg-${e[2]}-${r.timestamp??""}`;t.set(n,{id:n,agent:e[2],status:e[1],task:e[3],summary:ei(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!eo(t))return{...e,summary:ei(r)};let o=Array.isArray(t.results)?t.results.filter(eo):[],i=o[0],l=i?.progressSummary,a=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],s=el(i?.finalOutput,i?.output,r);return{...e,mode:el(t.mode),runId:el(t.runId),agent:el(i?.agent,e.agent)??e.agent,task:el(i?.task,e.task),summary:ei(s),model:el(i?.model),durationMs:ea(l?.durationMs),toolCount:ea(l?.toolCount),tokens:ea(l?.tokens),outputPath:el(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:el(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:a,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return eo(t)&&Array.isArray(t.results)&&t.results.some(e=>eo(e)&&"number"==typeof e.exitCode&&0!==e.exitCode)?"failed":"completed"}(r)},r.details,n))}}return Array.from(t.values()).sort((e,t)=>(t.timestamp??0)-(e.timestamp??0))}function ed({messages:e,runs:t}){let r=(0,o.useMemo)(()=>es(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),a=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(ec,{title:`Active (${l.length})`,runs:l}),a.length>0&&(0,n.jsx)(ec,{title:`Completed (${a.length})`,runs:a,compact:l.length>0})]})}function ec({title:e,runs:t,compact:r}){return(0,n.jsxs)("div",{style:{marginBottom:r?10:16},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:e}),t.map(e=>(0,n.jsx)(eu,{run:e},e.id))]})}function eu({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",a="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",s="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${a}`,background:s,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(ep,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:ei(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${a}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[e.summary&&(0,n.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:e.summary}),(0,n.jsx)(eh,{run:e})]})]})}function ep({running:e,color:t}){return(0,n.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:t,display:"inline-block",animation:e?"pulse 1.5s infinite":void 0,flexShrink:0}})}function eh({run:e}){let t=[e.model?["model",e.model]:void 0,e.runId?["run",e.runId]:void 0,e.outputPath?["output",e.outputPath]:void 0,e.sessionFile?["session",e.sessionFile]:void 0,...(e.artifacts??[]).slice(0,4).map((e,t)=>[`artifact ${t+1}`,e])].filter(Boolean);return 0===t.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:t.map(([e,t])=>(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:e}),(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:t,children:t})]},`${e}:${t}`))})}function ex({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:o,isNew:i,isStreaming:l=!1,onResume:a,onDismiss:s}){if(i||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),o&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",o.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:s,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,n.jsx)("button",{type:"button",onClick:a,disabled:l,title:l?"Wait until the agent finishes before updating Workbench":c?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:l?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:l?.55:1,whiteSpace:"nowrap"},children:c?"Reload Initial Data":"Resume Workbench"})]})}function eg(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:r}}async function ef(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}var ev=r(28999);async function em(e,t){if(!t.length)return[];let r=await fetch("/api/images/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,images:t.map(e=>({data:e.data,mimeType:e.mimeType,name:e.name}))})}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`Upload failed (HTTP ${r.status})`);return(n.uploaded??[]).map((e,r)=>({...e,previewUrl:t[r]?.previewUrl}))}async function ey(e,t,r){let n=new TextDecoder,o="",i=new Promise(e=>{r?.aborted?e():r?.addEventListener("abort",()=>e(),{once:!0})});for(;;){let r=await Promise.race([e.read(),i.then(()=>({done:!0,value:void 0}))]);if(r.done)break;let l=(o+=n.decode(r.value,{stream:!0})).split("\n");for(let e of(o=l.pop()||"",l)){if(!e.startsWith("data: "))continue;let r=e.slice(6);if("[DONE]"!==r)try{t(r)}catch{}}}if(o.trim())for(let e of o.split("\n")){if(!e.startsWith("data: "))continue;let r=e.slice(6);if("[DONE]"!==r)try{t(r)}catch{}}}let eb="__annovibeStreamSessions__",ej="__annovibeStreamListeners__",ek="__annovibeStreamErrorCallbacks__";function ew(){let e=globalThis;return e[eb]||(e[eb]=new Map),e[eb]}function eS(){let e=globalThis;return e[ek]||(e[ek]=new Map),e[ek]}function eC(e){return{sessionId:e,phase:"idle",startedAt:null,lastEventAt:null,lastHeartbeatAt:null,reconnectCount:0,lastSyncReason:null,accumulatedText:"",toolCalls:[],toolResults:[],statusText:null,streamingMessage:null,isStreaming:!1,error:null}}function eT(e,t){let r;for(let n of(!(r=globalThis)[ej]&&(r[ej]=new Map),r[ej]).get(e)??[])try{n(t)}catch{}}function ez(e){e.textThrottleTimer&&(clearTimeout(e.textThrottleTimer),e.textThrottleTimer=null),e.textDirty&&(e.textDirty=!1,eR(e))}function eI(e,t=!1){let r=Date.now();if(e.snapshot.lastEventAt=r,!t){e.textDirty=!0,e.textThrottleTimer||(e.textThrottleTimer=setTimeout(()=>{e.textThrottleTimer=null,e.textDirty&&(e.textDirty=!1,eR(e))},100));return}ez(e),eR(e)}function eR(e,t){let r=Date.now(),n=function(e){let t=[];for(let r of e.toolCalls.values())t.push({type:"toolCall",toolCallId:r.toolCallId,toolName:r.toolName,input:r.input??{}});let r=e.accumulatedText.trim();return r&&t.push({type:"text",text:r}),t}(e),o=(t??e.snapshot.phase)==="active";e.snapshot={...e.snapshot,phase:t??e.snapshot.phase,lastEventAt:r,accumulatedText:e.accumulatedText,toolCalls:[...e.toolCalls.values()],toolResults:[...e.toolResults.values()],statusText:o?function(e){if(e.activeToolId){let t=e.toolCalls.get(e.activeToolId);if(t){let e=Math.max(0,Math.floor((Date.now()-t.startedAt)/1e3));return`Running ${t.toolName||"tool"}… (${e}s)`}}return e.accumulatedText.trim()?"Generating response…":e.toolCalls.size>0?"Finishing tool results…":null}(e):e.snapshot.statusText,streamingMessage:o&&n.length>0?{role:"assistant",content:n}:null,isStreaming:o},eT(e.snapshot.sessionId,{type:"snapshot-updated",snapshot:e.snapshot})}function eM(e){eW(e),e.idleCheckTimer=setInterval(()=>{if("connected"!==e.connectionState)return;let t=Math.max(e.snapshot.lastEventAt??0,e.snapshot.lastHeartbeatAt??0);if(Date.now()-t>=18e4){eL(e),ez(e);let t="Stream idle timeout — no activity for 180s.";e.snapshot={...e.snapshot,phase:"error",isStreaming:!1,streamingMessage:null,statusText:null,error:t},eW(e),eT(e.snapshot.sessionId,{type:"error",snapshot:e.snapshot});let r=eS().get(e.snapshot.sessionId);if(r)try{r(e.snapshot.sessionId,t)}catch{}}},1e4)}function eW(e){e.idleCheckTimer&&(clearInterval(e.idleCheckTimer),e.idleCheckTimer=null)}function eL(e){e.toolProgressTimer&&(clearInterval(e.toolProgressTimer),e.toolProgressTimer=null)}function e$(e){let t=ew(),r=t.get(e);return r||(r={snapshot:eC(e),accumulatedText:"",toolCalls:new Map,toolResults:new Map,toolProgressTimer:null,activeToolId:null,textThrottleTimer:null,textDirty:!1,connectionState:"idle",idleCheckTimer:null},t.set(e,r)),r}function eE(e,t){let r=eS();return r.set(e,t),()=>{r.get(e)===t&&r.delete(e)}}function eP(e){let t=ew(),r=t.get(e);r&&(eL(r),eW(r),ez(r)),t.delete(e)}function eA(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function eD(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}-${Math.random().toString(36).slice(2,11)}`}let eB=["read","bash","grep","find","ls"];function eN(e,t){return e.trim()||0!==t?`text:${e}|images:${t}`:null}function eO(e){return"string"==typeof e?eN(e,0):Array.isArray(e)?eN(e.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"),e.filter(e=>!!e&&"object"==typeof e&&"image"===e.type).length):null}function eH(e){let t=new Map;for(let r of e){let e="user"!==r.role?null:eO(r.content);e&&t.set(e,(t.get(e)??0)+1)}return t}function eF(e,t,r){return e.sessionId===t&&(!e.leafId||r.includes(e.leafId))}let e_=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function eU(e){return e_.some(t=>e.type.startsWith(t))}function eK({agentPhase:e,startedAt:t}){let[r,i]=(0,o.useState)(0);return(0,o.useEffect)(()=>{if(!t)return void i(0);let e=()=>i(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);return 0===t.length?"Running tool…":1===t.length?`Running ${t[0]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(r)]})})}function eJ(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function eV({goal:e,planTasks:t,isRunning:r,onExecutePlan:i,onContinuePlanning:l,onEditPlan:a}){let[s,d]=(0,o.useState)(!1),c=(0,o.useCallback)(()=>d(e=>!e),[]),u=e&&"dropped"!==e.status,p=t&&t.length>0;if(!u&&!p)return null;let h=(0,o.useMemo)(()=>!e?.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e?.tokenBudget,e?.tokensUsed]),x=t?.filter(e=>"completed"===e.status).length??0,g=!!t&&x===t.length;return(0,n.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[u&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:p?"1px solid var(--border)":"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[eJ(e.tokensUsed),e.tokenBudget?` / ${eJ(e.tokenBudget)} tokens`:" tokens"]}),null!=h&&(0,n.jsxs)("span",{children:[h,"%"]})]}),null!=h&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:h>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(h,100)}%`,transition:"width 0.3s"}})})]}),p&&(0,n.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,n.jsxs)("div",{onClick:c,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&c()},"aria-expanded":!s,style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,cursor:"pointer",padding:"6px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"#3b82f6"},children:["Plan \xb7 ",t.length," 步"]}),g&&(0,n.jsxs)("span",{style:{borderRadius:4,padding:"0 6px",fontSize:10,fontWeight:600,background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",x,"/",t.length]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(a||l||i)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[a&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),a()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"修改计划"}),l&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"继续规划"}),i&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),i()},disabled:r,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:r?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:r?"not-allowed":"pointer"},children:"执行计划"})]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:s?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!s&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,borderRadius:4,padding:"3px 8px",background:"inProgress"===e.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,n.jsx)("div",{style:{marginTop:1},children:function(e){switch(e){case"completed":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,n.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,n.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round",children:(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"1.5s",repeatCount:"indefinite"})})]});default:return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"var(--border)",strokeWidth:"1.5"})})}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:12,lineHeight:1.5,...function(e){switch(e){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(e.status)},children:e.step})]},e.id))})]})]})}function eq(e){let t=e.findIndex(e=>"completed"!==e.status);return t<0?e:e.map((e,r)=>r===t?{...e,status:"completed"}:r===t+1&&"pending"===e.status?{...e,status:"inProgress"}:e)}let eY=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function eG({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[a,s]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(a||i!==o)if(a&&""===i)s(!1),r(t=>(t+1)%e.length);else{let e=a?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),a?28:55)}else n=setTimeout(()=>s(!0),1800);return()=>clearTimeout(n)},[i,a,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eZ({status:e}){let t=e?.current??"0.8.108"??"0.0.0";if(e?.updateAvailable){let r=e.latest?`v${e.latest}`:"latest";return(0,n.jsxs)("span",{title:`Current v${t}; latest ${r}; run ${e.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:e.updateCommand})]})}return(0,n.jsxs)("span",{title:`AnnoVibe v${t}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",t]})}function eX({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:a,chatInputRef:s,onBranchDataChange:d,onSessionStatsChange:u,onContextUsageChange:p,onToolPresetActive:h,generativeUI:x,activeFilePath:g,onOpenFileAtLine:f}){var v;let m,[y,b]=(0,o.useState)(null),[j,k]=(0,o.useState)(!1),[w,S]=(0,o.useState)([]),[C,T]=(0,o.useState)(""),[z,I]=(0,o.useState)(!1),L=(0,o.useRef)(!1),[B,O]=(0,o.useState)(!1),H=g&&!B?g:null;(0,o.useEffect)(()=>{O(!1)},[g]);let{data:F,loading:_,error:U,messages:K,entryIds:J,streamState:V,agentRunning:q,modelNames:Y,modelList:G,modelThinkingLevels:Z,modelThinkingLevelMaps:X,toolPreset:Q,memoryTools:ee,thinkingLevel:er,retryInfo:eo,contextUsage:ei,forkingEntryId:el,isCompacting:ea,compactError:ec,displayModel:eu,sessionStats:ep,agentPhase:eh,agentError:eb,isNew:ej,loadMoreMessages:ek,hasMoreMessages:eS,totalMessages:eR,loadedMessagesCount:e_,messagesEndRef:eJ,scrollContainerRef:eQ,lastUserMsgRef:e0,handleSend:e1,handleAbort:e2,handleFork:e5,handleNavigate:e4,handleModelChange:e3,handleCompact:e8,handleSteer:e6,handleFollowUp:e7,handleAbortCompaction:e9,handleToolPresetChange:te,handleMemoryToolsChange:tt,handleThinkingLevelChange:tr,handleAgentEventRef:tn}=function(e){let{session:t,newSessionCwd:r,planMode:n=!1,onAgentEnd:i,onSessionCreated:l,onSessionForked:a,modelsRefreshKey:s,onBranchDataChange:d,onPlanModeState:c}=e,u=null===t&&null!==r,[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!u),[f,v]=(0,o.useState)(null),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)([]),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useState)(0),[T,z]=(0,o.useState)(!1),[I,R]=(0,o.useState)(0),[L,B]=(0,o.useReducer)(eA,{isStreaming:!1,streamingMessage:null}),[O,H]=(0,o.useState)(!1),[F,_]=(0,o.useState)({}),[U,K]=(0,o.useState)([]),[J,V]=(0,o.useState)({}),[q,Y]=(0,o.useState)({}),[G,Z]=(0,o.useState)(null),[X,Q]=(0,o.useState)("full"),[ee,et]=(0,o.useState)([...W]),[er,en]=(0,o.useState)("auto"),[eo,ei]=(0,o.useState)(null),[el,ea]=(0,o.useState)(null),[es,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(null),[ep,eh]=(0,o.useState)(null),[ex,eb]=(0,o.useState)(null),[ej,ek]=(0,o.useState)(!1),[eS,eR]=(0,o.useState)(null),[e_,eU]=(0,o.useState)(null),[eK,eJ]=(0,o.useState)(null),eV=(0,o.useRef)(null),eq=(0,o.useRef)(t?.id??null),eY=(0,o.useRef)(!1),eG=(0,o.useRef)(null),eZ=(0,o.useRef)(null),eX=(0,o.useRef)(null),eQ=(0,o.useRef)(!1),e0=(0,o.useRef)(null),e1=(0,o.useRef)(!1),e2=(0,o.useRef)(null),e5=(0,o.useRef)(null),e4=(0,o.useRef)(new Map),e3=(0,o.useRef)(new Map),e8=(0,o.useRef)(null),e6=(0,o.useRef)(null),e7=(0,o.useRef)(0);(0,o.useEffect)(()=>{e8.current=m},[m]);let e9=e.setNewSessionModel??Z,te=e.setToolPreset??Q,tt=e.setMemoryTools??et,tr=ep??p?.context.model??ex??null,tn=u?G:tr,to=(0,o.useCallback)(()=>n?eB:N(X,ee),[ee,n,X]),ti=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
|
|
7
7
|
${t}
|
|
8
8
|
${e.extractedText}`.trim()}return`${r}
|
|
9
9
|
[Text extraction unavailable: ${e.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),tl=(0,o.useCallback)(async e=>{let t=await fetch(`/api/agent/${encodeURIComponent(e)}/prepare`,{method:"POST"});if(!t.ok)throw Error((await t.json().catch(()=>({}))).error??`Failed to prepare session (HTTP ${t.status})`)},[]),ta=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let r of b){if("assistant"!==r.role)continue;let n=r.usage;n&&(e.input+=n.input??0,e.output+=n.output??0,e.cacheRead+=n.cacheRead??0,e.cacheWrite+=n.cacheWrite??0,t+=n.cost?.total??0)}return e.input+e.output+e.cacheRead+e.cacheWrite>0?{tokens:e,cost:t}:null})(),ts=(0,o.useCallback)(async(e,t=!1,r=!1)=>{try{t&&g(!0);let n=r?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}?limit=50&offset=0`,o=await fetch(n);if(eq.current&&eq.current!==e)return null;if(404===o.status)return t&&(h(null),y(null),j([]),v(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();r||(C(i.totalMessages??i.context.messages.length),z(i.hasMore??!1),R(i.context.messages.length)),h(i),y(i.leafId);let l=i.context.messages,a=eH(l),s=new Map,d=Date.now();for(let[t,r]of e4.current)if(r.sessionId===e){if(d-r.createdAt>12e4){e4.current.delete(t);continue}if(r.confirmKey){let e=a.get(r.confirmKey)??0,n=s.get(r.confirmKey)??0;e-n>r.confirmCountAtCreate&&(e4.current.delete(t),s.set(r.confirmKey,n+1))}}e3.current=a;let u=i.context.entryIds??[],p=[...e4.current.values()].filter(t=>eF(t,e,u)).map(e=>e.message);return j(p.length>0?[...l,...p]:l),w(i.context.entryIds??[]),eh(null),v(null),!i.agentState?.state?.thinkingLevel&&i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&en(i.context.thinkingLevel),i.agentState?.state?.planMode&&c?.(i.agentState.state.planMode),i.agentState??null}catch(e){return v(String(e)),null}finally{t&&g(!1)}},[c]),td=(0,o.useRef)(!1),tc=(0,o.useCallback)(async()=>{if(td.current)return;td.current=!0;let e=eq.current;if(!e){td.current=!1;return}try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}?limit=50&offset=${I}`);if(!t.ok)return;let r=await t.json();j(e=>[...r.context.messages,...e]),w(e=>[...r.context.entryIds??[],...e]),R(e=>e+r.context.messages.length),z(r.hasMore??!1)}catch{}finally{td.current=!1}},[I]),tu=(0,o.useCallback)(async(e,t)=>{try{let r=t?`/api/sessions/${encodeURIComponent(e)}/context?leafId=${encodeURIComponent(t)}`:`/api/sessions/${encodeURIComponent(e)}/context`,n=await fetch(r);if(!n.ok)throw Error(`HTTP ${n.status}`);let o=await n.json(),i=o.context.messages,l=o.context.entryIds??[],a=eH(i),s=new Map,d=Date.now();for(let[t,r]of e4.current)if(r.sessionId===e){if(d-r.createdAt>12e4){e4.current.delete(t);continue}if(r.confirmKey){let e=a.get(r.confirmKey)??0,n=s.get(r.confirmKey)??0;e-n>r.confirmCountAtCreate&&(e4.current.delete(t),s.set(r.confirmKey,n+1))}}e3.current=a;let c=[...e4.current.values()].filter(t=>eF(t,e,l)).map(e=>e.message);j(c.length>0?[...i,...c]:i),w(l)}catch(e){console.error("Failed to load context:",e)}},[]),tp=(0,o.useCallback)(async e=>{try{let t=await ef(e,{type:"get_tools"});if(t){let e,r,n,o;te((r=(e=t.filter(e=>e.active).map(e=>e.name)).filter(e=>!W.includes(e)),n=D(e),o=D(r),""===n?"none":n===D($)?"default":n===D(E)?"full":n===D(P)?"workbench":n===D(A)?"agent":""===o?"none":o===D($)?"default":o===D(E)?"full":o===D(P)?"workbench":o===D(A)||e.includes(M)?"agent":"default")),tt(W.filter(e=>t.some(t=>t.active&&t.name===e)))}}catch(e){console.error("Failed to load tools:",e)}},[tt,te]),th=(0,o.useCallback)((e,t={})=>{eV.current?.close(),eV.current=null;let r=`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`;return!function(e){let t=e$(e);if("active"===t.snapshot.phase)return eI(t,!0),eM(t),t.snapshot;let r=Date.now();t.snapshot={...eC(e),phase:"active",startedAt:r,lastEventAt:r,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},eM(t),eI(t,!0),t.snapshot}(e),new Promise((n,o)=>{let i=!1,l=null,a=e=>{if(!i){if(i=!0,clearTimeout(s),e){l?.close(),eV.current===l&&(eV.current=null),o(e);return}n()}},s=setTimeout(()=>{t.requireConnected?a(Error("Timed out waiting for event stream connection")):a()},t.timeoutMs??3e4);eV.current=l=function(e){let{url:t,onEvent:r,onStateChange:n,onFatalError:o,maxReconnectAttempts:i=1/0,reconnectBaseMs:l=1e3,reconnectMaxMs:a=3e4,autoReconnect:s=!0}=e,d="idle",c=new AbortController,u=0,p=null,h=!1,x=e=>{d!==e&&(d=e,n?.(e))},g=()=>{null!==p&&(clearTimeout(p),p=null)},f=()=>{if(h)return;if(!s)return void x("error");if(u>=i){x("error"),o?.(Error(`Max reconnect attempts (${i}) reached`));return}let e=Math.min(a,l*2**u);u+=1,x("connecting"),p=setTimeout(()=>{p=null,v()},e)},v=async()=>{if(!h){g(),c=new AbortController,x("connecting");try{let e=await fetch(t,{signal:c.signal,headers:{Accept:"text/event-stream","Cache-Control":"no-cache"}});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`);let n=e.body;if(!n)throw Error("Response has no readable body");let o=n.getReader();x("connected"),u=0,await ey(o,r,c.signal),o.releaseLock(),x("closed"),!h&&s&&f()}catch(e){if(h||e instanceof DOMException&&"AbortError"===e.name)return void x("closed");x("error"),s&&f()}}};return{get state(){return d},connect:()=>{h=!1,u=0,g(),v()},close:()=>{h=!0,g(),c.abort(),x("closed")},get abortController(){return c}}}({url:r,onEvent:e=>{try{let t=JSON.parse(e);"connected"===t.type&&a(),eG.current?.(t)}catch{}},onStateChange:r=>{!function(e,t){let r=ew().get(e);if(!r)return;let n=r.connectionState;r.connectionState=t,"connected"===t&&"connected"!==n&&(r.snapshot={...r.snapshot,lastEventAt:Date.now(),lastHeartbeatAt:Date.now()},eM(r)),"connected"!==t&&"connected"===n&&eW(r)}(e,r),t.requireConnected&&"error"===r&&a(Error("Failed to connect event stream"))},reconnectBaseMs:1e3,reconnectMaxMs:3e4}),l.connect()})},[]),tx=(0,o.useCallback)(async(e,t="manual")=>{if(!e||eq.current!==e)return;let r=e7.current;try{let t=await fetch(`/api/agent/${encodeURIComponent(e)}`),n=await t.json().catch(()=>({}));if(eq.current!==e||e7.current!==r)return;if(n.running){if(eY.current=!0,H(!0),eU(e=>e??{kind:"waiting_model"}),!eV.current||"closed"===eV.current.state||"error"===eV.current.state){let t;(t=ew().get(e))&&(t.snapshot={...t.snapshot,reconnectCount:t.snapshot.reconnectCount+1,lastSyncReason:"sse-reconnect",lastEventAt:Date.now()},eI(t,!0)),th(e,{replay:!0})}}else eY.current=!1,eV.current?.close(),eV.current=null,eP(e),H(!1),eU(null),ei(null),B({type:"end"}),await ts(e);n.state?.contextUsage!==void 0&&ea(n.state.contextUsage??null),n.state?.systemPrompt!==void 0&&ed(n.state.systemPrompt??null),n.state?.isCompacting!==void 0&&ek(n.state.isCompacting),n.state?.thinkingLevel!==void 0&&en(n.state.thinkingLevel??"auto"),n.state?.planMode!==void 0&&c?.(n.state.planMode)}catch{}},[th,ts,c]);(0,o.useEffect)(()=>{eZ.current=tx},[tx]),(0,o.useEffect)(()=>{eY.current=O},[O]),eG.current=(0,o.useCallback)(e=>{let t=eq.current;switch(t&&function(e,t){let r=e$(e),n=Date.now();switch(t.type){case"agent_start":if("active"===r.snapshot.phase)return eI(r,!0),r.snapshot;return eL(r),r.accumulatedText="",r.toolCalls.clear(),r.toolResults.clear(),r.activeToolId=null,r.snapshot={...eC(e),phase:"active",startedAt:n,lastEventAt:n,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},eM(r),eI(r,!0),r.snapshot;case"message_update":{let e=t.message;if(!e||"assistant"!==e.role)return r.snapshot;let o=e.content;for(let e of Array.isArray(o)?o:[])"object"==typeof e&&null!==e&&"type"in e&&("text"===e.type?r.accumulatedText=e.text??"":"toolCall"===e.type&&e.toolCallId&&!r.toolCalls.has(e.toolCallId)&&r.toolCalls.set(e.toolCallId,{...e,startedAt:n}));return eI(r,!1),r.snapshot}case"tool_execution_start":{let e="string"==typeof t.toolCallId?t.toolCallId:"",o="string"==typeof t.toolName?t.toolName:"tool",i=t.input??{};if(!e)return r.snapshot;let l=r.toolCalls.get(e);return r.toolCalls.set(e,{type:"toolCall",toolCallId:e,toolName:o,input:l?.input??i,startedAt:l?.startedAt??n}),r.activeToolId=e,eL(r),r.activeToolId&&(r.toolProgressTimer=setInterval(()=>eI(r,!0),1e3)),eI(r,!0),r.snapshot}case"tool_execution_end":{let e="string"==typeof t.toolCallId?t.toolCallId:"",o="string"==typeof t.toolName?t.toolName:"tool",i="string"==typeof t.result?t.result:JSON.stringify(t.result??"");if(e){let l=r.toolCalls.get(e);l&&r.toolCalls.set(e,{...l,endedAt:n}),r.toolResults.set(e,{role:"toolResult",toolCallId:e,toolName:o,content:[{type:"text",text:i}],isError:!!t.isError,timestamp:n}),r.activeToolId===e&&(r.activeToolId=null,eL(r))}return eI(r,!0),r.snapshot}case"message_end":return ez(r),eI(r,!0),r.snapshot;case"agent_end":{ez(r),eL(r),eW(r);let n="string"==typeof t.error?t.error:null;return r.activeToolId=null,r.snapshot={...r.snapshot,phase:n?"error":"completed",isStreaming:!1,streamingMessage:null,statusText:null,error:n},eT(e,n?{type:"error",snapshot:r.snapshot}:{type:"completed",snapshot:r.snapshot}),r.snapshot}case"heartbeat":return r.snapshot={...r.snapshot,lastHeartbeatAt:n},r.snapshot;default:return r.snapshot}}(t,e),e.type){case"agent_start":eJ(null),eY.current=!0,H(!0),eU({kind:"waiting_model"}),B({type:"start"});break;case"agent_end":eY.current=!1,eV.current?.close(),eV.current=null,H(!1),eU(null),ei(null),B({type:"end"}),eq.current&&(ts(eq.current),fetch(`/api/agent/${encodeURIComponent(eq.current)}`).then(e=>e.json()).then(e=>{!1===e.running&&(H(!1),eU(null),B({type:"end"})),e.state?.contextUsage!==void 0&&ea(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&ed(e.state.systemPrompt??null),e.state?.isCompacting!==void 0&&ek(e.state.isCompacting)}).catch(()=>{})),i?.();break;case"message_start":case"message_update":{if(!eY.current)break;let t=e.message;if(t?.role==="user")break;t&&B({type:"update",message:eg(t)}),eU(null);break}case"message_end":{if(!eY.current)break;let t=e.message;t&&"user"!==t.role&&j(e=>[...e,eg(t)]),B({type:"reset"}),eU({kind:"waiting_model"});break}case"prompt_done":if(!eY.current)break;tx(eq.current??"","prompt_done");break;case"tool_execution_start":{let t=e.toolCallId,r=e.toolName,n=e.args,o="bash"===r&&"string"==typeof n?.command?n.command:void 0;eU(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r,args:o}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;eU(e=>{if(e?.kind!=="running_tools")return e;let r=e.tools.filter(e=>e.id!==t);return 0===r.length?{kind:"waiting_model"}:{kind:"running_tools",tools:r}});break}case"auto_retry_start":ei({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":ei(null);break;case"auto_compaction_start":case"compaction_start":ek(!0),eR(null);break;case"auto_compaction_end":case"compaction_end":ek(!1),e.errorMessage?eR(e.errorMessage):!e.aborted&&eq.current&&ts(eq.current)}},[ts,i]);let tg=(0,o.useCallback)(async(e,o,i,a)=>{if(!e.trim()&&!o?.length&&!i?.length||O)return;e7.current+=1;let s=ti(i),d=e.trim()?s?`${e}
|