@seqyuan/annovibe 0.8.56 → 0.8.57
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 +6 -6
- 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/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 +6 -6
- package/.next/server/chunks/1494.js +2 -2
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware.js +3 -3
- package/.next/server/next-font-manifest.js +1 -1
- package/.next/server/next-font-manifest.json +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-6a62ffee5ced3965.js → page-4ba38abb4ab7fa91.js} +2 -2
- package/package.json +1 -1
- /package/.next/static/{QZwqtNsBEqsF_QYttjcd7 → o_wdyGkUx_hf9tokRGlUb}/_buildManifest.js +0 -0
- /package/.next/static/{QZwqtNsBEqsF_QYttjcd7 → o_wdyGkUx_hf9tokRGlUb}/_ssgManifest.js +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{11631:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>rU});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function s(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 a({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,p]=(0,i.useState)(""),[u,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:u});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,u,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&&o()},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=>p(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:o,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:u===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":u===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"===u&&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),o()},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:s(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),o()},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:s(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 i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+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..."})]})]})})}let d="AnnoVibe",c="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function u(e){window.localStorage.setItem(c,JSON.stringify([...e]))}async function h(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 x(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function g(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function f(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||g(e,t)}let v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function m(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:v[Math.floor(Math.random()*v.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.56":d,r),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),c=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:c,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:s})}function y({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:o,initialSessionId:l,onInitialRestoreDone:s,refreshKey:d,onSessionDeleted:x,selectedCwd:v,onCwdChange:C}){let[T,z]=(0,i.useState)([]),[I,M]=(0,i.useState)([]),[W,L]=(0,i.useState)(!0),[R,E]=(0,i.useState)(null),[P,$]=(0,i.useState)(null),[B,D]=(0,i.useState)(""),[N,A]=(0,i.useState)(null),[O,H]=(0,i.useState)(!1),[F,U]=(0,i.useState)("project"),[_,K]=(0,i.useState)(null),[V,J]=(0,i.useState)(!1),[Y,q]=(0,i.useState)(!1),[Z,G]=(0,i.useState)(()=>new Set),[X,Q]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(c)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[ee,et]=(0,i.useState)(null),[er,en]=(0,i.useState)(null),[ei,eo]=(0,i.useState)(null),[el,es]=(0,i.useState)(!1),ea=(0,i.useRef)(null),[ed,ec]=(0,i.useState)(!1),ep=(0,i.useRef)(!1),eu=(0,i.useRef)(!1),eh=(0,i.useRef)(!1),ex=(0,i.useCallback)(async(e=!1)=>{try{e&&(E(null),L(!0));let t=new AbortController,r=setTimeout(()=>t.abort(new DOMException("Loading timed out","TimeoutError")),3e4),[n,i]=await Promise.all([fetch("/api/sessions",{signal:t.signal}),fetch("/api/projects",{signal:t.signal})]);if(clearTimeout(r),!n.ok)throw Error(await h("sessions",n));if(!i.ok)throw Error(await h("projects",i));let o=await n.json(),l=await i.json();z(o.sessions),M(l.projects),E(null)}catch(e){E(e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?"Loading timed out. Codex may still be starting; try the refresh button.":e instanceof Error?e.message:String(e))}finally{e&&L(!1)}},[]),eg=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eg.current;eg.current=!0,ex(e)},[ex,d]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{ex(!1)},15e3);return()=>window.clearInterval(e)},[ex]),(0,i.useEffect)(()=>{let e=()=>{ex(!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[ex]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&D(e.home)}).catch(()=>{})},[]);let ef=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(ep.current){ep.current=!1;return}if(eu.current){eu.current=!1;return}C?.(P)},[P,C]);let ev=(0,i.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 A(n.error??`HTTP ${r.status}`),!1;return ex(!1),!0}catch(e){return A(e instanceof Error?e.message:String(e)),!1}},[ex]),em=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ey=(0,i.useCallback)(e=>{eu.current=!0,$(e),A(null),Q(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),u(r),r}),C?.(e),em(e)},[C,em]);(0,i.useEffect)(()=>{if((0!==T.length||0!==I.length)&&null===P){if(l&&!ef.current){ef.current=!0;let e=T.find(e=>e.id===l);if(e){$(e.cwd),em(e.cwd),t(e,!0);return}s?.()}let e=I[0]?.cwd;e&&($(e),em(e))}},[T,I,P,l,t,s,em]);let eb=v??P,ej=(0,i.useCallback)(e=>{if(!e){U("agent"),H(!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]),ek=(0,i.useCallback)(e=>{if(!e){U("workbench"),H(!0);return}o?.(e)},[o]);(0,i.useCallback)(async e=>{await ev(e,!0)&&(ey(e),H(!1),A(null),"agent"===F&&ej(e),"workbench"===F&&ek(e))},[ey,ej,ek,F,ev]);let ew=(0,i.useCallback)(e=>{K(e),J(!0)},[]),eS=(0,i.useCallback)(()=>{J(!1),K(null)},[]),eC=(0,i.useCallback)(e=>{let t=_??eb;eS(),"agent"===e?ej(t):ek(t)},[eS,ej,ek,eb,_]),eT=(0,i.useCallback)(()=>{ew(eb)},[eb,ew]),ez=(0,i.useCallback)(()=>{U("project"),A(null),H(!0)},[]),eI=(0,i.useMemo)(()=>[...eb&&!I.some(e=>e.cwd===eb)?[{cwd:eb,displayName:f(eb,B),chatCount:T.filter(e=>e.cwd===eb).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...I].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,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[T,eb,B,I]),eM=(0,i.useMemo)(()=>{let e=new Map;for(let t of T){let r=t.cwd||"";e.has(r)||e.set(r,[]),e.get(r).push(t)}return eI.map(t=>{let r=[...e.get(t.cwd)??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:t,cwd:t.cwd,displayName:t.displayName||f(t.cwd,B),sessions:r,lastAccessed:(t.lastAccessed??t.created??"")||r[0]?.modified||""}})},[T,B,eI]);(0,i.useEffect)(()=>{if(0===eM.length||eh.current||(eh.current=!0,!eM[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eM.slice(1).map(e=>e.cwd));Q(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)?(u(e),e):t),window.localStorage.setItem(p,"1")},[eM]);let eW=(0,i.useCallback)((e,r=!1)=>{e.cwd!==eb&&(ep.current=!0,$(e.cwd)),Q(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),u(r),r}),em(e.cwd),t(e,r)},[t,eb,em]),eL=(0,i.useCallback)(e=>{Q(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),u(r),r})},[]),eR=(0,i.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eE=(0,i.useCallback)(async e=>{eo("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??[]),E(null)}catch(e){E(e instanceof Error?e.message:String(e)),ex(!1)}finally{eo(null)}},[ex]),eP=(0,i.useCallback)(async(e,t)=>{eo(`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??[]),E(null)}catch(e){E(e instanceof Error?e.message:String(e)),ex(!1)}finally{eo(null)}},[ex]),e$=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eI.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),eE(o)},[eE,eI]),eB=(0,i.useCallback)(async()=>{ec(!0);try{let e=eI.filter(e=>!0===e.pinned).map(e=>e.cwd);e.length>0?await Promise.all(e.map(e=>fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e4)}).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{z(r=>[...r.filter(t=>t.cwd!==e),...t.sessions??[]])}).catch(()=>{}))):await ex(!1)}finally{ec(!1)}},[ex,eI]);return(0,i.useEffect)(()=>{if(!el)return;let e=e=>{ea.current&&!ea.current.contains(e.target)&&es(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[el]),(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)(m,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eT,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:eb?`New chat in ${eb}`:"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:()=>q(!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)(a,{open:Y,cwd:eb,homeDir:B,onClose:()=>q(!1),onSelectSession:e=>{eW(e)}}),(0,n.jsxs)("div",{ref:ea,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>es(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eb?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eb?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eb??"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:eb?"var(--text)":"var(--text-dim)"},children:eb?eI.find(e=>e.cwd===eb)?.displayName??g(eb,B):"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:el?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eb&&(0,n.jsx)(j,{pinned:eI.find(e=>e.cwd===eb)?.pinned===!0,onToggle:()=>void eP(eb,eI.find(e=>e.cwd===eb)?.pinned!==!0)}),el&&(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===eI.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eI.map(e=>{let t=e.cwd===eb;return(0,n.jsx)(k,{project:e,homeDir:B,isCurrent:t,onSelect:()=>{ey(e.cwd),es(!1)},onTogglePinned:()=>void eP(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{es(!1),ez()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eI.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.jsx)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:(0,n.jsx)("button",{type:"button",onClick:eB,disabled:ed,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:ed?"var(--accent)":"var(--text-dim)",cursor:ed?"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:ed?"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"})]})})})]}),N&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:N})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[W&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),R&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:R}),!W&&!R&&0===eM.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!W&&!R&&eM.map(t=>{let r=X.has(t.cwd),i=t.cwd===eb,o=Z.has(t.cwd),l=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 i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),s=l.length,a=l;if(s>10&&!o){a=l.slice(0,10);let t=l.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!a.includes(t)&&(a=[...a,t])}let d=s-a.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:er===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(er===t.cwd),opacity:ee===t.cwd?.55:1},onDragOver:e=>{ee&&ee!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",en(t.cwd))},onDragLeave:()=>{er===t.cwd&&en(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||ee;en(null),et(null),r&&e$(r,t.cwd)},children:[(0,n.jsx)(w,{group:t,isCurrent:i,isCollapsed:r,isDragging:ee===t.cwd,pinBusy:ei===`pin:${t.cwd}`,onToggle:()=>eL(t.cwd),onSelect:()=>ey(t.cwd),onTogglePinned:()=>void eP(t.cwd,!0!==t.project.pinned),onDragStart:e=>{et(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{et(null),en(null)}}),!r&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[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."}):a.map(t=>(0,n.jsx)(S,{node:t,selectedSessionId:e,onSelectSession:eW,onRenamed:ex,onSessionDeleted:e=>{x?.(e),ex()},depth:0},t.session.id)),(o||d>0)&&s>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eR(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:o?"Show less":`Show ${Math.max(0,d)} more`})]})]},t.cwd||"__no_project")})]}),V&&(0,n.jsx)(b,{cwd:_,onChoose:eC,onClose:eS})]})}function b({cwd:e,onChoose:t,onClose:r}){let i=e?f(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:i}),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 j({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 k({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[s,a]=(0,i.useState)(!1),d=e.displayName||f(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"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:o,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:s?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:+!!s,pointerEvents:s?"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 w({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:p}){let[u,h]=(0,i.useState)(!1),g=e.lastAccessed,f=Math.max(0,e.project.chatCount??e.sessions.length??0),v=!0===e.project.pinned,m=(0,i.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:c,onDragEnd:p,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)":u?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.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"}),!u&&f>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[f," ",1===f?"chat":"chats"]}),!u&&g&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:x(g)}),v?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:u?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:u?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:u?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:+!!u,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:u?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 S({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s}){let[a,d]=(0,i.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(C,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(S,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function C({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[p,u]=(0,i.useState)(!1),[h,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[m,y]=(0,i.useState)(!1),[b,j]=(0,i.useState)(!1),k=(0,i.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),g(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),T=(0,i.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})}),o?.()}catch{}},[f,e.id,e.name,o]),z=(0,i.useCallback)(e=>{e.stopPropagation(),y(!0)},[]),I=(0,i.useCallback)(async t=>{t.stopPropagation(),y(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,i.useCallback)(e=>{e.stopPropagation(),y(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:m||h?void 0:r,onMouseEnter:()=>u(!0),onMouseLeave:()=>{u(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:m||h?"default":"pointer",background:m?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:m?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:b?.5:1,gap:6,overflow:"hidden"},children:m?(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:["“",w.slice(0,22),w.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:I,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"})]})]}):h?(0,n.jsx)("input",{ref:k,value:f,onChange:e=>v(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:[s>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===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:5,height:5,borderRadius:"50%",background:t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0}}),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:w,children:w}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:x(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"})]})]}),a&&(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:S,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 T=r(94456);let z="subagent",I=["retain","recall","reflect"],M=[],W=["read","bash","edit","write"],L=["bash","read","edit","write","grep","find","ls"],R=[...L,"kernel_plot_run","kernel_plot_render","kernel_plot_stop","kernel_plot_artifacts"],E=[...L,z];function P(e){return[...e].sort().join(",")}function $(e){switch(e){case"none":return M;case"default":return W;case"workbench":return R;case"agent":return E;default:return L}}function B(e,t){return[...new Set([...$(e),...t])]}let D=new Map,N=["off","default","full","agent"],A={off:"none",default:"default",full:"full",agent:"agent"},O={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},H={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},F=["auto","off","minimal","low","medium","high","xhigh"],U={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},_=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function K({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=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)"}}}(i),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:o.color,fontSize:14,flexShrink:0},children:o.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:[i.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 V(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function J(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,i=[];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()&&i.push(`Page ${e}
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{11631:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>rU});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function s(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 a({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,p]=(0,i.useState)(""),[u,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:u});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,u,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&&o()},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=>p(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:o,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:u===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":u===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"===u&&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),o()},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:s(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),o()},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:s(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 i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+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..."})]})]})})}let d="AnnoVibe",c="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function u(e){window.localStorage.setItem(c,JSON.stringify([...e]))}async function h(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 x(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function g(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function f(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||g(e,t)}let v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function m(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:v[Math.floor(Math.random()*v.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.57":d,r),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),c=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:c,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:s})}function y({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:o,initialSessionId:l,onInitialRestoreDone:s,refreshKey:d,onSessionDeleted:x,selectedCwd:v,onCwdChange:C}){let[T,z]=(0,i.useState)([]),[I,M]=(0,i.useState)([]),[W,L]=(0,i.useState)(!0),[R,E]=(0,i.useState)(null),[P,$]=(0,i.useState)(null),[B,D]=(0,i.useState)(""),[N,A]=(0,i.useState)(null),[O,H]=(0,i.useState)(!1),[F,U]=(0,i.useState)("project"),[_,K]=(0,i.useState)(null),[V,J]=(0,i.useState)(!1),[Y,q]=(0,i.useState)(!1),[Z,G]=(0,i.useState)(()=>new Set),[X,Q]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(c)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[ee,et]=(0,i.useState)(null),[er,en]=(0,i.useState)(null),[ei,eo]=(0,i.useState)(null),[el,es]=(0,i.useState)(!1),ea=(0,i.useRef)(null),[ed,ec]=(0,i.useState)(!1),ep=(0,i.useRef)(!1),eu=(0,i.useRef)(!1),eh=(0,i.useRef)(!1),ex=(0,i.useCallback)(async(e=!1)=>{try{e&&(E(null),L(!0));let t=new AbortController,r=setTimeout(()=>t.abort(new DOMException("Loading timed out","TimeoutError")),3e4),[n,i]=await Promise.all([fetch("/api/sessions",{signal:t.signal}),fetch("/api/projects",{signal:t.signal})]);if(clearTimeout(r),!n.ok)throw Error(await h("sessions",n));if(!i.ok)throw Error(await h("projects",i));let o=await n.json(),l=await i.json();z(o.sessions),M(l.projects),E(null)}catch(e){E(e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?"Loading timed out. Codex may still be starting; try the refresh button.":e instanceof Error?e.message:String(e))}finally{e&&L(!1)}},[]),eg=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eg.current;eg.current=!0,ex(e)},[ex,d]),(0,i.useEffect)(()=>{let e=window.setInterval(()=>{ex(!1)},15e3);return()=>window.clearInterval(e)},[ex]),(0,i.useEffect)(()=>{let e=()=>{ex(!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[ex]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&D(e.home)}).catch(()=>{})},[]);let ef=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(ep.current){ep.current=!1;return}if(eu.current){eu.current=!1;return}C?.(P)},[P,C]);let ev=(0,i.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 A(n.error??`HTTP ${r.status}`),!1;return ex(!1),!0}catch(e){return A(e instanceof Error?e.message:String(e)),!1}},[ex]),em=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ey=(0,i.useCallback)(e=>{eu.current=!0,$(e),A(null),Q(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),u(r),r}),C?.(e),em(e)},[C,em]);(0,i.useEffect)(()=>{if((0!==T.length||0!==I.length)&&null===P){if(l&&!ef.current){ef.current=!0;let e=T.find(e=>e.id===l);if(e){$(e.cwd),em(e.cwd),t(e,!0);return}s?.()}let e=I[0]?.cwd;e&&($(e),em(e))}},[T,I,P,l,t,s,em]);let eb=v??P,ej=(0,i.useCallback)(e=>{if(!e){U("agent"),H(!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]),ek=(0,i.useCallback)(e=>{if(!e){U("workbench"),H(!0);return}o?.(e)},[o]);(0,i.useCallback)(async e=>{await ev(e,!0)&&(ey(e),H(!1),A(null),"agent"===F&&ej(e),"workbench"===F&&ek(e))},[ey,ej,ek,F,ev]);let ew=(0,i.useCallback)(e=>{K(e),J(!0)},[]),eS=(0,i.useCallback)(()=>{J(!1),K(null)},[]),eC=(0,i.useCallback)(e=>{let t=_??eb;eS(),"agent"===e?ej(t):ek(t)},[eS,ej,ek,eb,_]),eT=(0,i.useCallback)(()=>{ew(eb)},[eb,ew]),ez=(0,i.useCallback)(()=>{U("project"),A(null),H(!0)},[]),eI=(0,i.useMemo)(()=>[...eb&&!I.some(e=>e.cwd===eb)?[{cwd:eb,displayName:f(eb,B),chatCount:T.filter(e=>e.cwd===eb).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...I].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,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[T,eb,B,I]),eM=(0,i.useMemo)(()=>{let e=new Map;for(let t of T){let r=t.cwd||"";e.has(r)||e.set(r,[]),e.get(r).push(t)}return eI.map(t=>{let r=[...e.get(t.cwd)??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:t,cwd:t.cwd,displayName:t.displayName||f(t.cwd,B),sessions:r,lastAccessed:(t.lastAccessed??t.created??"")||r[0]?.modified||""}})},[T,B,eI]);(0,i.useEffect)(()=>{if(0===eM.length||eh.current||(eh.current=!0,!eM[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eM.slice(1).map(e=>e.cwd));Q(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)?(u(e),e):t),window.localStorage.setItem(p,"1")},[eM]);let eW=(0,i.useCallback)((e,r=!1)=>{e.cwd!==eb&&(ep.current=!0,$(e.cwd)),Q(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),u(r),r}),em(e.cwd),t(e,r)},[t,eb,em]),eL=(0,i.useCallback)(e=>{Q(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),u(r),r})},[]),eR=(0,i.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eE=(0,i.useCallback)(async e=>{eo("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??[]),E(null)}catch(e){E(e instanceof Error?e.message:String(e)),ex(!1)}finally{eo(null)}},[ex]),eP=(0,i.useCallback)(async(e,t)=>{eo(`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??[]),E(null)}catch(e){E(e instanceof Error?e.message:String(e)),ex(!1)}finally{eo(null)}},[ex]),e$=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eI.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),eE(o)},[eE,eI]),eB=(0,i.useCallback)(async()=>{ec(!0);try{let e=eI.filter(e=>!0===e.pinned).map(e=>e.cwd);e.length>0?await Promise.all(e.map(e=>fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e4)}).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{z(r=>[...r.filter(t=>t.cwd!==e),...t.sessions??[]])}).catch(()=>{}))):await ex(!1)}finally{ec(!1)}},[ex,eI]);return(0,i.useEffect)(()=>{if(!el)return;let e=e=>{ea.current&&!ea.current.contains(e.target)&&es(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[el]),(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)(m,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eT,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:eb?`New chat in ${eb}`:"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:()=>q(!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)(a,{open:Y,cwd:eb,homeDir:B,onClose:()=>q(!1),onSelectSession:e=>{eW(e)}}),(0,n.jsxs)("div",{ref:ea,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>es(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eb?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eb?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eb??"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:eb?"var(--text)":"var(--text-dim)"},children:eb?eI.find(e=>e.cwd===eb)?.displayName??g(eb,B):"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:el?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eb&&(0,n.jsx)(j,{pinned:eI.find(e=>e.cwd===eb)?.pinned===!0,onToggle:()=>void eP(eb,eI.find(e=>e.cwd===eb)?.pinned!==!0)}),el&&(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===eI.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eI.map(e=>{let t=e.cwd===eb;return(0,n.jsx)(k,{project:e,homeDir:B,isCurrent:t,onSelect:()=>{ey(e.cwd),es(!1)},onTogglePinned:()=>void eP(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{es(!1),ez()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eI.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.jsx)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:(0,n.jsx)("button",{type:"button",onClick:eB,disabled:ed,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:ed?"var(--accent)":"var(--text-dim)",cursor:ed?"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:ed?"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"})]})})})]}),N&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:N})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[W&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),R&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:R}),!W&&!R&&0===eM.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!W&&!R&&eM.map(t=>{let r=X.has(t.cwd),i=t.cwd===eb,o=Z.has(t.cwd),l=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 i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),s=l.length,a=l;if(s>10&&!o){a=l.slice(0,10);let t=l.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!a.includes(t)&&(a=[...a,t])}let d=s-a.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:er===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(er===t.cwd),opacity:ee===t.cwd?.55:1},onDragOver:e=>{ee&&ee!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",en(t.cwd))},onDragLeave:()=>{er===t.cwd&&en(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||ee;en(null),et(null),r&&e$(r,t.cwd)},children:[(0,n.jsx)(w,{group:t,isCurrent:i,isCollapsed:r,isDragging:ee===t.cwd,pinBusy:ei===`pin:${t.cwd}`,onToggle:()=>eL(t.cwd),onSelect:()=>ey(t.cwd),onTogglePinned:()=>void eP(t.cwd,!0!==t.project.pinned),onDragStart:e=>{et(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{et(null),en(null)}}),!r&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[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."}):a.map(t=>(0,n.jsx)(S,{node:t,selectedSessionId:e,onSelectSession:eW,onRenamed:ex,onSessionDeleted:e=>{x?.(e),ex()},depth:0},t.session.id)),(o||d>0)&&s>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eR(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:o?"Show less":`Show ${Math.max(0,d)} more`})]})]},t.cwd||"__no_project")})]}),V&&(0,n.jsx)(b,{cwd:_,onChoose:eC,onClose:eS})]})}function b({cwd:e,onChoose:t,onClose:r}){let i=e?f(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:i}),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 j({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 k({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[s,a]=(0,i.useState)(!1),d=e.displayName||f(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"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:o,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:s?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:+!!s,pointerEvents:s?"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 w({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:p}){let[u,h]=(0,i.useState)(!1),g=e.lastAccessed,f=Math.max(0,e.project.chatCount??e.sessions.length??0),v=!0===e.project.pinned,m=(0,i.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:c,onDragEnd:p,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)":u?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.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"}),!u&&f>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[f," ",1===f?"chat":"chats"]}),!u&&g&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:x(g)}),v?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:u?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:u?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:u?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:+!!u,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:u?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 S({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s}){let[a,d]=(0,i.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(C,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(S,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function C({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[p,u]=(0,i.useState)(!1),[h,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[m,y]=(0,i.useState)(!1),[b,j]=(0,i.useState)(!1),k=(0,i.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),g(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),T=(0,i.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})}),o?.()}catch{}},[f,e.id,e.name,o]),z=(0,i.useCallback)(e=>{e.stopPropagation(),y(!0)},[]),I=(0,i.useCallback)(async t=>{t.stopPropagation(),y(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,i.useCallback)(e=>{e.stopPropagation(),y(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:m||h?void 0:r,onMouseEnter:()=>u(!0),onMouseLeave:()=>{u(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:m||h?"default":"pointer",background:m?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",borderLeft:m?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:b?.5:1,gap:6,overflow:"hidden"},children:m?(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:["“",w.slice(0,22),w.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:I,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"})]})]}):h?(0,n.jsx)("input",{ref:k,value:f,onChange:e=>v(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:[s>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===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:5,height:5,borderRadius:"50%",background:t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0}}),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:w,children:w}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:x(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"})]})]}),a&&(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:S,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 T=r(94456);let z="subagent",I=["retain","recall","reflect"],M=[],W=["read","bash","edit","write"],L=["bash","read","edit","write","grep","find","ls"],R=[...L,"kernel_plot_run","kernel_plot_render","kernel_plot_stop","kernel_plot_artifacts"],E=[...L,z];function P(e){return[...e].sort().join(",")}function $(e){switch(e){case"none":return M;case"default":return W;case"workbench":return R;case"agent":return E;default:return L}}function B(e,t){return[...new Set([...$(e),...t])]}let D=new Map,N=["off","default","full","agent"],A={off:"none",default:"default",full:"full",agent:"agent"},O={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},H={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},F=["auto","off","minimal","low","medium","high","xhigh"],U={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},_=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function K({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=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)"}}}(i),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:o.color,fontSize:14,flexShrink:0},children:o.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:[i.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 V(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function J(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,i=[];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()&&i.push(`Page ${e}
|
|
2
2
|
${r}`)}return i.join("\n\n")}async function Y(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),i=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],o=[];for(let e of i){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)];o.push(...r.map(e=>V(e[1])))}return o.join("").replace(/[ \t]+\n/g,"\n")}async function q(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],i=t.utils.sheet_to_csv(r);return`Sheet: ${e}
|
|
3
3
|
${i}`}).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),i=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])),o=[];for(let{name:e,match:t}of i){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>V(e[1]).trim()).filter(Boolean);r.length&&o.push(`Slide ${t[1]}
|
|
4
4
|
${r.join("\n")}`)}return o.join("\n\n")}async function G(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,i="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))i=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)i=await J(t);else if("docx"===r)i=await Y(t);else if("xlsx"===r)i=await q(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};i=await Z(t)}let{text:o,truncated:l}=(n=i.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(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let X=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:p,onAbortCompaction:u,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,cornerBadge:z,promptHistory:M,sessionHistoryKey:W},L){let R,E,P,[$,B]=(0,i.useState)(""),[V,J]=(0,i.useState)(!1),[Y,q]=(0,i.useState)(null),[Z,X]=(0,i.useState)(!1),[Q,ee]=(0,i.useState)(!1),[et,er]=(0,i.useState)(!1),[en,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(!1),[es,ea]=(0,i.useState)(null),[ed,ec]=(0,i.useState)([]),[ep,eu]=(0,i.useState)([]),eh=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.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}(),ex=eh?{display:"none"}:void 0,eg=eh?28:32,ef=eh?"6px 8px":"8px 12px",ev=eh?160:180,em=eh&&!l,ey=eo?"var(--text)":"var(--text-muted)",eb={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},ej=eh?{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},[ek,ew]=(0,i.useState)(null),eS=(0,i.useRef)(null),eC=(0,i.useRef)(null),eT=(0,i.useRef)(null),ez=(0,i.useRef)(null),eI=(0,i.useRef)(null),eM=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(null),eR=(0,i.useRef)(null),eE=(0,i.useRef)(null),eP=(0,i.useCallback)(e=>{let t=eS.current;if(!t)return void B(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";B(i+l+e+o),requestAnimationFrame(()=>{let t=eS.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,i.useImperativeHandle)(L,()=>({insertIfEmpty(e){let t=eS.current;(t?t.value:$).trim()||(B(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eP(e)},addImages(e){e$(e)},addFiles(e){eB(e)}}));let e$=(0,i.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)})));ec(e=>[...e,...r])},[]),eB=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&e$(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,i=await G(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));eu(t=>[...t,...e])}},[e$]),eD=(0,i.useCallback)(e=>{ec(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eN=(0,i.useCallback)(e=>{eu(t=>{let r=[...t];return r.splice(e,1),r})},[]),eA=(0,i.useCallback)(()=>{ec(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),eu([])},[]),eO=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),eH=[];for(let e of eO){let t=eH.find(t=>t.provider===e.provider);t?t.options.push(e):eH.push({provider:e.provider,options:[e]})}let eF=s?eO.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eO.length>0?eO[0].name:null,eU=s?eO.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eO[0],e_=eU?.input?.includes("image")??!0,eK=ed.length>0&&eU?.input!==void 0&&!e_,eV=(!!$.trim()||ed.length>0||ep.length>0)&&!eK,eJ=p?_:_.filter(e=>"/compact"!==e.command),eY=eJ.filter(e=>"native"===e.kind),eq=eJ.filter(e=>"shortcut"===e.kind),eZ=m??[],eG=eZ.length>0?`${eZ.length} enabled`:"off",eX=eO.length>0&&!!eF&&!!c,eQ=!!j,e0=!!v&&"workbench"!==f,e1=eF??"Default",e2=(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e5=(g??"full")==="workbench"?"workbench":Object.entries(A).find(([,e])=>e===(g??"full"))?.[0]??"full",e4=eh?26:32,e3=eh?7:9,e8=eh?3:6,e6={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)"},e7=eh&&(V||Z||Q||et||en||eo);(0,i.useEffect)(()=>{eK||ew(null)},[eK]);let e9=(0,i.useCallback)(e=>{if(!$.trim()){B(e),requestAnimationFrame(()=>{let t=eS.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eP(e)},[eP,$]),te=(0,i.useCallback)(()=>{let t=$.trim();if(t||ed.length||ep.length){if(ed.length&&!e_)return void ew("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!ed.length&&!ep.length&&p){h?u?.():p(),B(""),eS.current&&(eS.current.style.height="auto");return}e(t,ed.length?ed:void 0,ep.length?ep:void 0),B(""),eA(),eS.current&&(eS.current.style.height="auto")}}},[$,ed,ep,e_,l,e,eA,p,u,h]),tt=(0,i.useCallback)(e=>{let t=$.trim();if(!t&&!ed.length&&!ep.length)return;if(ed.length&&!e_)return void ew("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=ed.length?ed:void 0,i=ep.length?ep:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),B(""),eA(),eS.current&&(eS.current.style.height="auto")},[$,ed,ep,e_,r,o,eA]),tr=M??[],tn=W??null,ti=(0,i.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&tr.length>0){let t=eS.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 i=((n=D.get(e))||(n={cursor:-1,draftSnapshot:""},D.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(tn,t.value,tr);null!==n&&(B(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=D.get(e);return(t?.cursor??-1)>=0}(tn)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=D.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}}(tn,tr);t&&(B(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eS.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),tn&&D.set(tn,{cursor:-1,draftSnapshot:""}),l&&(r||o)?tt(r?"steer":"followup"):te())},[l,r,o,tt,te,tr,tn]),to=(0,i.useCallback)(()=>{let e=eS.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tl=(0,i.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(),eB(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eB]);return(0,i.useEffect)(()=>{if(!V&&!Z&&!Q&&!et&&!en&&!eo)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eC.current?.contains(t),n=!!eT.current?.contains(t);r||n||J(!1),ez.current?.contains(t)||X(!1),eI.current?.contains(t)||ee(!1),eM.current?.contains(t)||er(!1),eW.current?.contains(t)||ei(!1),eL.current?.contains(t)||el(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[V,Z,Q,et,en,eo]),(0,i.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||ea(!!t?.ready)}).catch(()=>{e||ea(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:ej,children:[e7&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{J(!1),X(!1),ee(!1),er(!1),ei(!1),el(!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:eR,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{e$(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eE,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=>{eB(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eh?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eh?"0 8px":void 0,boxSizing:"border-box"},children:[z&&(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:z}),S&&(0,n.jsxs)("div",{style:{marginBottom:eh?6:8,padding:eh?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eh?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]})]}),(ed.length>0||ep.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:[ed.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 ${eK?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eD(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}`)),ep.map((e,t)=>(0,n.jsx)(K,{doc:e,onRemove:()=>eN(t)},`doc-${t}`))]}),(eK||ek)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:eh?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:ek??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:eh?4:8,alignItems:eh?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:eh?13:14,padding:eh?"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:eS,value:$,onChange:e=>B(e.target.value),onKeyDown:ti,onInput:to,onPaste:tl,placeholder:l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:eh?"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:+!!eh,paddingBottom:+!!eh}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:eh?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tt("steer"),disabled:!eV,title:eK?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eh,padding:eh?"6px 8px":"7px 12px",background:eV?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eV?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eV?"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"})]}),!eh&&"Steer"]}),o&&(0,n.jsxs)("button",{onClick:()=>tt("followup"),disabled:!eV,title:eK?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eh,padding:eh?"6px 8px":"7px 12px",background:eV?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eV?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eV?"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"})]}),!eh&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:te,disabled:!eV,title:eK?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eh?3:6,padding:eh?"5px 9px":"7px 14px",marginBottom:+!!eh,background:eV?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eV?"#fff":"var(--text-dim)",cursor:eV?"pointer":"not-allowed",fontSize:eh?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eV?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:eh?13:14,height:eh?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:eh?5:8,display:"flex",alignItems:eh?"flex-start":"center",gap:e8,flexWrap:eh?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eh?"1 1 100%":"0 0 auto",width:eh?"100%":void 0,display:"flex",alignItems:"center",gap:2*!eh,flexWrap:eh?"wrap":"nowrap",rowGap:4*!!eh},children:[(0,n.jsx)("button",{onClick:()=>eR.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e4,height:e4,padding:0,background:"none",border:"none",borderRadius:e3,color:ed.length||ep.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=ed.length||ep.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ed.length||ep.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eE.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:ez,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(X(e=>!e),ee(!1),J(!1),er(!1),ei(!1),el(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e4,height:e4,padding:0,background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:e3,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=Z?"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"}})]}),Z&&(0,n.jsxs)("div",{style:{...eh?e6:{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}),eY.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"}),eY.map(e=>(0,n.jsxs)("button",{onClick:()=>{(X(!1),"/compact"===e.command&&h)?u?.():e9(e.command)},style:{display:"flex",alignItems:"center",gap:eh?6:8,width:"100%",padding:ef,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eh?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*(eY.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eY.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eq.map(e=>(0,n.jsxs)("button",{onClick:()=>{X(!1),e9(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ef,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eh?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:eI,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ee(e=>!e),X(!1),J(!1),er(!1),ei(!1),el(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:eg,padding:0,background:Q?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:eZ.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=eZ.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=Q?"var(--bg-hover)":"none",e.currentTarget.style.color=eZ.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eZ.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),Q&&(0,n.jsxs)("div",{style:{...eh?e6:{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"}),I.map(e=>{let t=eZ.includes(e),r=H[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?eZ.filter(t=>t!==e):[...eZ,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ef,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eh?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)})]})]}),eX&&(0,n.jsxs)("div",{ref:eC,style:{position:"relative",flex:eh?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eh){let t=e.currentTarget.getBoundingClientRect();q({top:t.top,left:t.left,width:t.width})}X(!1),ee(!1),er(!1),ei(!1),el(!1),J(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:ef,height:eg,width:eh?"100%":void 0,maxWidth:eh?"100%":220,overflow:"hidden",background:V?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?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=V?"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:eF})]}),V&&(eh?(0,n.jsxs)("div",{ref:eT,style:{...e6,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:eF})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eH.map((e,t)=>(0,n.jsxs)("div",{children:[eH.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===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{J(!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))})]}):Y&&(E=(R=window.visualViewport?.height??window.innerHeight)-Y.top+6,P=Math.max(120,Math.min(Y.top-8,.6*R)),(0,n.jsx)("div",{ref:eT,style:{position:"fixed",bottom:E,left:Y.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:Y.width,maxHeight:P,overflowY:"auto"},children:eH.map((e,t)=>(0,n.jsxs)("div",{children:[eH.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===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{J(!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))})))]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:em?"none":void 0,flex:eh?"0 0 auto":1,width:eh?0:void 0,height:eh?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:eh?"1 1 100%":"0 0 auto",width:eh?"100%":void 0,display:"flex",alignItems:"center",justifyContent:eh?"space-between":void 0,gap:eh?4:2,marginLeft:eh?0:"auto",marginTop:2*!!eh},children:[em&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{X(!1),ee(!1),J(!1),er(!1),ei(!1),el(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:eo?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ey,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=eo?"var(--bg-hover)":"none",e.currentTarget.style.color=eo?"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"})]})}),eo&&(0,n.jsxs)("div",{style:{...e6,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:[eX&&(0,n.jsxs)("button",{onClick:()=>{el(!1),ei(!1),er(!1),ee(!1),J(!0)},style:eb,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:e1})]}),(eQ||e0)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[eQ&&(0,n.jsxs)("button",{onClick:()=>{el(!1),J(!1),er(!1),ee(!1),ei(!0)},style:eb,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:e2})]}),e0&&(0,n.jsxs)("button",{onClick:()=>{el(!1),J(!1),ei(!1),ee(!1),er(!0)},style:eb,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:e5})]})]}),!!y&&(0,n.jsxs)("button",{onClick:()=>{el(!1),J(!1),ei(!1),er(!1),ee(!0)},style:eb,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:eZ.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eG})]})]})]})]}),(!em&&!l||eh&&en)&&j&&(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[!em&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(X(!1),ee(!1),J(!1),er(!1),el(!1),ei(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:eh?3:5,padding:ef,height:eg,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?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=en?"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:ex,children:(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),en&&(0,n.jsx)("div",{style:{...eh?e6:{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:ev},overflow:"hidden"},children:F.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(b??"auto")===e,r=U[e],i="auto"!==e&&w?w[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,n.jsxs)("button",{onClick:()=>{ei(!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:eh?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:[o,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)})})]}),(!em&&!l||eh&&et)&&e0&&(0,n.jsxs)("div",{ref:eM,style:{position:"relative"},children:[!em&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(X(!1),ee(!1),J(!1),ei(!1),el(!1),er(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eh?3:5,padding:ef,height:eg,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?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=et?"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:ex,children:e5})]}),et&&(0,n.jsx)("div",{style:{...eh?e6:{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:N.map(e=>{let t=A[e],r=(g??"full")===t,i="agent"===e&&!1===es,o=i?"需安装 pi-subagents":O[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(er(!1),r||v(t))},disabled:i,title:i?"运行 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:i?"not-allowed":"pointer",fontSize:eh?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(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:o})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:eg,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eh?8:9,color:"#ef4444",cursor:"pointer",fontSize:eh?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"]}),void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:eh?28:32,height:eh?28:32,padding:0,background:"none",border:"none",borderRadius:eh?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 Q(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 ee({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,s]=(0,i.useState)(0),[a,d]=(0,i.useState)(1),[c,p]=(0,i.useState)(!1),[u,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),m=(0,i.useRef)(!1),y=(0,i.useRef)(null),b=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(b);j.current=b;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;p(i>20),i<=0?(s(0),d(1)):(s(e.scrollTop/i),d(n/t));let l=o.current,a=[],c=0,u=j.current;for(let r=0;r<u.length;r++){let n=u[r];if("user"!==n.role&&"assistant"!==n.role)continue;let i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.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,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.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-a,e))/(1-a)*n)},[r,a]),C=(0,i.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),i=n>=0&&n<=a?n:a/2;S(r-i);let o=e=>{m.current&&S((e.clientY-t.top)/t.height-i)},s=()=>{m.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,i.useMemo)(()=>{if(!x||0===u.length)return[];let e=u.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,u,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,W=null!==f&&u.length>0?u.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(u[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:`${M}%`,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}}),u.map(e=>{let t=Q(e.msg),r=x&&W===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,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:i?8:6,height:i?8:6,borderRadius:i?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&&u.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),i=Q(e.msg),o=W===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 ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function et(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function er(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function en(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ei(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function eo(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:er(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,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,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(!et(t))return{...e,summary:er(r)};let i=Array.isArray(t.results)?t.results.filter(et):[],o=i[0],l=o?.progressSummary,s=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=en(o?.finalOutput,o?.output,r);return{...e,mode:en(t.mode),runId:en(t.runId),agent:en(o?.agent,e.agent)??e.agent,task:en(o?.task,e.task),summary:er(a),model:en(o?.model),durationMs:ei(l?.durationMs),toolCount:ei(l?.toolCount),tokens:ei(l?.tokens),outputPath:en(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:en(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:s,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return et(t)&&Array.isArray(t.results)&&t.results.some(e=>et(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 el({messages:e,runs:t}){let r=(0,i.useMemo)(()=>eo(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),s=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(es,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(es,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function es({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)(ea,{run:e},e.id))]})}function ea({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":o?"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 ${s}`,background:a,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)(ed,{running:o,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:er(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,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)(ec,{run:e})]})]})}function ed({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 ec({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 ep({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:i,isNew:o,isStreaming:l=!1,onResume:s,onDismiss:a}){if(o||"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})]}),i&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",i.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:a,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:s,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 eu(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 eh(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}function ex(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 eg(e){if("user"!==e.role)return null;var t=e.content;if("string"==typeof t)return`text:${t}`;if(!Array.isArray(t))try{return`other:${JSON.stringify(t)}`}catch{return"other:"}let r=t.map(e=>{if(!e||"object"!=typeof e)return e;if("text"===e.type)return{type:"text",text:e.text};if("image"===e.type){let t=e.source&&"object"==typeof e.source?e.source:{};return{type:"image",mimeType:t.media_type??e.mimeType,data:t.data??e.data,url:t.url}}return e});try{return`blocks:${JSON.stringify(r)}`}catch{return"blocks:"}}function ef(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let ev=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function em(e){return ev.some(t=>e.type.startsWith(t))}function ey({agentPhase:e,startedAt:t}){let[r,o]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void o(0);let e=()=>o(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.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 eb(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ej({goal:e,planTasks:t,isRunning:r,onExecutePlan:o}){let[l,s]=(0,i.useState)(!1),a=(0,i.useCallback)(()=>s(e=>!e),[]),d=e&&"dropped"!==e.status,c=t&&t.length>0;if(!d&&!c)return null;let p=(0,i.useMemo)(()=>!e?.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e?.tokenBudget,e?.tokensUsed]),u=t?.filter(e=>"completed"===e.status).length??0,h=!!t&&u===t.length;return(0,n.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[d&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:c?"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:[eb(e.tokensUsed),e.tokenBudget?` / ${eb(e.tokenBudget)} tokens`:" tokens"]}),null!=p&&(0,n.jsxs)("span",{children:[p,"%"]})]}),null!=p&&(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:p>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(p,100)}%`,transition:"width 0.3s"}})})]}),c&&(0,n.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,n.jsxs)("div",{onClick:a,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&a()},"aria-expanded":!l,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," 步"]}),h&&(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:["已完成 ",u,"/",t.length]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[o&&h&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o()},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:l?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!l&&(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))})]})]})}let ek=["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 ew({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(s||o!==i)if(s&&""===o)a(!1),r(t=>(t+1)%e.length);else{let e=s?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[o,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eS({status:e}){let t=e?.current??"0.8.56"??"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 eC({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:c,onSystemPromptChange:p,onSessionStatsChange:u,onContextUsageChange:h,onToolPresetActive:x,generativeUI:g}){var f;let v,[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)([]),{data:S,loading:C,error:M,messages:$,entryIds:D,streamState:N,agentRunning:A,modelNames:O,modelList:H,modelThinkingLevels:F,modelThinkingLevelMaps:U,toolPreset:_,memoryTools:K,thinkingLevel:V,retryInfo:J,contextUsage:Y,forkingEntryId:q,isCompacting:Z,compactError:G,displayModel:Q,sessionStats:et,agentPhase:er,agentError:en,isNew:ei,messagesEndRef:es,scrollContainerRef:ea,lastUserMsgRef:ed,handleSend:ec,handleAbort:ev,handleFork:eb,handleNavigate:eT,handleModelChange:ez,handleCompact:eI,handleSteer:eM,handleFollowUp:eW,handleAbortCompaction:eL,handleToolPresetChange:eR,handleMemoryToolsChange:eE,handleThinkingLevelChange:eP,handleAgentEventRef:e$}=function(e){let{session:t,newSessionCwd:r,onAgentEnd:n,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:a,onSystemPromptChange:d}=e,c=null===t&&null!==r,[p,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!c),[g,f]=(0,i.useState)(null),[v,m]=(0,i.useState)(null),[y,b]=(0,i.useState)([]),[j,k]=(0,i.useState)([]),[w,S]=(0,i.useReducer)(ex,{isStreaming:!1,streamingMessage:null}),[C,T]=(0,i.useState)(!1),[M,$]=(0,i.useState)({}),[D,N]=(0,i.useState)([]),[A,O]=(0,i.useState)({}),[H,F]=(0,i.useState)({}),[U,_]=(0,i.useState)(null),[K,V]=(0,i.useState)("full"),[J,Y]=(0,i.useState)([...I]),[q,Z]=(0,i.useState)("auto"),[G,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(null),[en,ei]=(0,i.useState)(null),[eo,el]=(0,i.useState)(null),[es,ea]=(0,i.useState)(null),[ed,ec]=(0,i.useState)(!1),[ep,ev]=(0,i.useState)(null),[em,ey]=(0,i.useState)(null),[eb,ej]=(0,i.useState)(null),ek=(0,i.useRef)(null),ew=(0,i.useRef)(t?.id??null),eS=(0,i.useRef)(!1),eC=(0,i.useRef)(null),eT=(0,i.useRef)(!1),ez=(0,i.useRef)(null),eI=(0,i.useRef)(!1),eM=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(new Map),eR=(0,i.useRef)(new Set),eE=e.setNewSessionModel??_,eP=e.setToolPreset??V,e$=e.setMemoryTools??Y,eB=eo??p?.context.model??es??null,eD=c?U:eB,eN=(0,i.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(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let X=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:p,onAbortCompaction:u,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,cornerBadge:z,promptHistory:M,sessionHistoryKey:W},L){let R,E,P,[$,B]=(0,i.useState)(""),[V,J]=(0,i.useState)(!1),[Y,q]=(0,i.useState)(null),[Z,X]=(0,i.useState)(!1),[Q,ee]=(0,i.useState)(!1),[et,er]=(0,i.useState)(!1),[en,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(!1),[es,ea]=(0,i.useState)(null),[ed,ec]=(0,i.useState)([]),[ep,eu]=(0,i.useState)([]),eh=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.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}(),ex=eh?{display:"none"}:void 0,eg=eh?28:32,ef=eh?"6px 8px":"8px 12px",ev=eh?160:180,em=eh&&!l,ey=eo?"var(--text)":"var(--text-muted)",eb={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},ej=eh?{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},[ek,ew]=(0,i.useState)(null),eS=(0,i.useRef)(null),eC=(0,i.useRef)(null),eT=(0,i.useRef)(null),ez=(0,i.useRef)(null),eI=(0,i.useRef)(null),eM=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(null),eR=(0,i.useRef)(null),eE=(0,i.useRef)(null),eP=(0,i.useCallback)(e=>{let t=eS.current;if(!t)return void B(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";B(i+l+e+o),requestAnimationFrame(()=>{let t=eS.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,i.useImperativeHandle)(L,()=>({insertIfEmpty(e){let t=eS.current;(t?t.value:$).trim()||(B(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eP(e)},addImages(e){e$(e)},addFiles(e){eB(e)}}));let e$=(0,i.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)})));ec(e=>[...e,...r])},[]),eB=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&e$(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,i=await G(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));eu(t=>[...t,...e])}},[e$]),eD=(0,i.useCallback)(e=>{ec(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eN=(0,i.useCallback)(e=>{eu(t=>{let r=[...t];return r.splice(e,1),r})},[]),eA=(0,i.useCallback)(()=>{ec(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),eu([])},[]),eO=d&&d.length>0?d.map(e=>({provider:e.provider,modelId:e.id,name:e.name,input:e.input})):Object.entries(a??{}).map(([e,t])=>({provider:s?.provider??"unknown",modelId:e,name:t})),eH=[];for(let e of eO){let t=eH.find(t=>t.provider===e.provider);t?t.options.push(e):eH.push({provider:e.provider,options:[e]})}let eF=s?eO.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eO.length>0?eO[0].name:null,eU=s?eO.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eO[0],e_=eU?.input?.includes("image")??!0,eK=ed.length>0&&eU?.input!==void 0&&!e_,eV=(!!$.trim()||ed.length>0||ep.length>0)&&!eK,eJ=p?_:_.filter(e=>"/compact"!==e.command),eY=eJ.filter(e=>"native"===e.kind),eq=eJ.filter(e=>"shortcut"===e.kind),eZ=m??[],eG=eZ.length>0?`${eZ.length} enabled`:"off",eX=eO.length>0&&!!eF&&!!c,eQ=!!j,e0=!!v&&"workbench"!==f,e1=eF??"Default",e2=(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e5=(g??"full")==="workbench"?"workbench":Object.entries(A).find(([,e])=>e===(g??"full"))?.[0]??"full",e4=eh?26:32,e3=eh?7:9,e8=eh?3:6,e6={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)"},e7=eh&&(V||Z||Q||et||en||eo);(0,i.useEffect)(()=>{eK||ew(null)},[eK]);let e9=(0,i.useCallback)(e=>{if(!$.trim()){B(e),requestAnimationFrame(()=>{let t=eS.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eP(e)},[eP,$]),te=(0,i.useCallback)(()=>{let t=$.trim();if(t||ed.length||ep.length){if(ed.length&&!e_)return void ew("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!ed.length&&!ep.length&&p){h?u?.():p(),B(""),eS.current&&(eS.current.style.height="auto");return}e(t,ed.length?ed:void 0,ep.length?ep:void 0),B(""),eA(),eS.current&&(eS.current.style.height="auto")}}},[$,ed,ep,e_,l,e,eA,p,u,h]),tt=(0,i.useCallback)(e=>{let t=$.trim();if(!t&&!ed.length&&!ep.length)return;if(ed.length&&!e_)return void ew("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=ed.length?ed:void 0,i=ep.length?ep:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),B(""),eA(),eS.current&&(eS.current.style.height="auto")},[$,ed,ep,e_,r,o,eA]),tr=M??[],tn=W??null,ti=(0,i.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&tr.length>0){let t=eS.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 i=((n=D.get(e))||(n={cursor:-1,draftSnapshot:""},D.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(tn,t.value,tr);null!==n&&(B(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=D.get(e);return(t?.cursor??-1)>=0}(tn)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=D.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}}(tn,tr);t&&(B(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eS.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),tn&&D.set(tn,{cursor:-1,draftSnapshot:""}),l&&(r||o)?tt(r?"steer":"followup"):te())},[l,r,o,tt,te,tr,tn]),to=(0,i.useCallback)(()=>{let e=eS.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tl=(0,i.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(),eB(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eB]);return(0,i.useEffect)(()=>{if(!V&&!Z&&!Q&&!et&&!en&&!eo)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eC.current?.contains(t),n=!!eT.current?.contains(t);r||n||J(!1),ez.current?.contains(t)||X(!1),eI.current?.contains(t)||ee(!1),eM.current?.contains(t)||er(!1),eW.current?.contains(t)||ei(!1),eL.current?.contains(t)||el(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[V,Z,Q,et,en,eo]),(0,i.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||ea(!!t?.ready)}).catch(()=>{e||ea(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:ej,children:[e7&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{J(!1),X(!1),ee(!1),er(!1),ei(!1),el(!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:eR,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{e$(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eE,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=>{eB(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eh?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eh?"0 8px":void 0,boxSizing:"border-box"},children:[z&&(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:z}),S&&(0,n.jsxs)("div",{style:{marginBottom:eh?6:8,padding:eh?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eh?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]})]}),(ed.length>0||ep.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:[ed.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 ${eK?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eD(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}`)),ep.map((e,t)=>(0,n.jsx)(K,{doc:e,onRemove:()=>eN(t)},`doc-${t}`))]}),(eK||ek)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:eh?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:ek??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:eh?4:8,alignItems:eh?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:eh?13:14,padding:eh?"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:eS,value:$,onChange:e=>B(e.target.value),onKeyDown:ti,onInput:to,onPaste:tl,placeholder:l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:eh?"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:+!!eh,paddingBottom:+!!eh}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:eh?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tt("steer"),disabled:!eV,title:eK?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eh,padding:eh?"6px 8px":"7px 12px",background:eV?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eV?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eV?"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"})]}),!eh&&"Steer"]}),o&&(0,n.jsxs)("button",{onClick:()=>tt("followup"),disabled:!eV,title:eK?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eh,padding:eh?"6px 8px":"7px 12px",background:eV?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eV?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eV?"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"})]}),!eh&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:te,disabled:!eV,title:eK?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eh?3:6,padding:eh?"5px 9px":"7px 14px",marginBottom:+!!eh,background:eV?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eV?"#fff":"var(--text-dim)",cursor:eV?"pointer":"not-allowed",fontSize:eh?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eV?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:eh?13:14,height:eh?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:eh?5:8,display:"flex",alignItems:eh?"flex-start":"center",gap:e8,flexWrap:eh?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eh?"1 1 100%":"0 0 auto",width:eh?"100%":void 0,display:"flex",alignItems:"center",gap:2*!eh,flexWrap:eh?"wrap":"nowrap",rowGap:4*!!eh},children:[(0,n.jsx)("button",{onClick:()=>eR.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e4,height:e4,padding:0,background:"none",border:"none",borderRadius:e3,color:ed.length||ep.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=ed.length||ep.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ed.length||ep.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eE.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:ez,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(X(e=>!e),ee(!1),J(!1),er(!1),ei(!1),el(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e4,height:e4,padding:0,background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:e3,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=Z?"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"}})]}),Z&&(0,n.jsxs)("div",{style:{...eh?e6:{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}),eY.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"}),eY.map(e=>(0,n.jsxs)("button",{onClick:()=>{(X(!1),"/compact"===e.command&&h)?u?.():e9(e.command)},style:{display:"flex",alignItems:"center",gap:eh?6:8,width:"100%",padding:ef,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eh?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*(eY.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eY.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eq.map(e=>(0,n.jsxs)("button",{onClick:()=>{X(!1),e9(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ef,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eh?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:eI,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ee(e=>!e),X(!1),J(!1),er(!1),ei(!1),el(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:eg,padding:0,background:Q?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:eZ.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=eZ.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=Q?"var(--bg-hover)":"none",e.currentTarget.style.color=eZ.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eZ.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),Q&&(0,n.jsxs)("div",{style:{...eh?e6:{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"}),I.map(e=>{let t=eZ.includes(e),r=H[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?eZ.filter(t=>t!==e):[...eZ,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ef,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eh?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)})]})]}),eX&&(0,n.jsxs)("div",{ref:eC,style:{position:"relative",flex:eh?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eh){let t=e.currentTarget.getBoundingClientRect();q({top:t.top,left:t.left,width:t.width})}X(!1),ee(!1),er(!1),ei(!1),el(!1),J(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:ef,height:eg,width:eh?"100%":void 0,maxWidth:eh?"100%":220,overflow:"hidden",background:V?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?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=V?"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:eF})]}),V&&(eh?(0,n.jsxs)("div",{ref:eT,style:{...e6,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:eF})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eH.map((e,t)=>(0,n.jsxs)("div",{children:[eH.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===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{J(!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))})]}):Y&&(E=(R=window.visualViewport?.height??window.innerHeight)-Y.top+6,P=Math.max(120,Math.min(Y.top-8,.6*R)),(0,n.jsx)("div",{ref:eT,style:{position:"fixed",bottom:E,left:Y.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:Y.width,maxHeight:P,overflowY:"auto"},children:eH.map((e,t)=>(0,n.jsxs)("div",{children:[eH.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===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{J(!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))})))]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:em?"none":void 0,flex:eh?"0 0 auto":1,width:eh?0:void 0,height:eh?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:eh?"1 1 100%":"0 0 auto",width:eh?"100%":void 0,display:"flex",alignItems:"center",justifyContent:eh?"space-between":void 0,gap:eh?4:2,marginLeft:eh?0:"auto",marginTop:2*!!eh},children:[em&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{X(!1),ee(!1),J(!1),er(!1),ei(!1),el(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:eo?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ey,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=eo?"var(--bg-hover)":"none",e.currentTarget.style.color=eo?"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"})]})}),eo&&(0,n.jsxs)("div",{style:{...e6,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:[eX&&(0,n.jsxs)("button",{onClick:()=>{el(!1),ei(!1),er(!1),ee(!1),J(!0)},style:eb,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:e1})]}),(eQ||e0)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[eQ&&(0,n.jsxs)("button",{onClick:()=>{el(!1),J(!1),er(!1),ee(!1),ei(!0)},style:eb,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:e2})]}),e0&&(0,n.jsxs)("button",{onClick:()=>{el(!1),J(!1),ei(!1),ee(!1),er(!0)},style:eb,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:e5})]})]}),!!y&&(0,n.jsxs)("button",{onClick:()=>{el(!1),J(!1),ei(!1),er(!1),ee(!0)},style:eb,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:eZ.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eG})]})]})]})]}),(!em&&!l||eh&&en)&&j&&(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[!em&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(X(!1),ee(!1),J(!1),er(!1),el(!1),ei(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:eh?3:5,padding:ef,height:eg,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?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=en?"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:ex,children:(()=>{let e=b??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),en&&(0,n.jsx)("div",{style:{...eh?e6:{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:ev},overflow:"hidden"},children:F.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(b??"auto")===e,r=U[e],i="auto"!==e&&w?w[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,n.jsxs)("button",{onClick:()=>{ei(!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:eh?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:[o,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)})})]}),(!em&&!l||eh&&et)&&e0&&(0,n.jsxs)("div",{ref:eM,style:{position:"relative"},children:[!em&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(X(!1),ee(!1),J(!1),ei(!1),el(!1),er(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eh?3:5,padding:ef,height:eg,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:eh?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eh?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=et?"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:ex,children:e5})]}),et&&(0,n.jsx)("div",{style:{...eh?e6:{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:N.map(e=>{let t=A[e],r=(g??"full")===t,i="agent"===e&&!1===es,o=i?"需安装 pi-subagents":O[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(er(!1),r||v(t))},disabled:i,title:i?"运行 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:i?"not-allowed":"pointer",fontSize:eh?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(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:o})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:eg,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eh?8:9,color:"#ef4444",cursor:"pointer",fontSize:eh?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"]}),void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:eh?28:32,height:eh?28:32,padding:0,background:"none",border:"none",borderRadius:eh?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 Q(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 ee({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,s]=(0,i.useState)(0),[a,d]=(0,i.useState)(1),[c,p]=(0,i.useState)(!1),[u,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),m=(0,i.useRef)(!1),y=(0,i.useRef)(null),b=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(b);j.current=b;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;p(i>20),i<=0?(s(0),d(1)):(s(e.scrollTop/i),d(n/t));let l=o.current,a=[],c=0,u=j.current;for(let r=0;r<u.length;r++){let n=u[r];if("user"!==n.role&&"assistant"!==n.role)continue;let i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.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,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.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-a,e))/(1-a)*n)},[r,a]),C=(0,i.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),i=n>=0&&n<=a?n:a/2;S(r-i);let o=e=>{m.current&&S((e.clientY-t.top)/t.height-i)},s=()=>{m.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,i.useMemo)(()=>{if(!x||0===u.length)return[];let e=u.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,u,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,W=null!==f&&u.length>0?u.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(u[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:`${M}%`,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}}),u.map(e=>{let t=Q(e.msg),r=x&&W===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,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:i?8:6,height:i?8:6,borderRadius:i?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&&u.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),i=Q(e.msg),o=W===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 ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function et(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function er(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function en(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ei(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function eo(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:er(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,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,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(!et(t))return{...e,summary:er(r)};let i=Array.isArray(t.results)?t.results.filter(et):[],o=i[0],l=o?.progressSummary,s=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=en(o?.finalOutput,o?.output,r);return{...e,mode:en(t.mode),runId:en(t.runId),agent:en(o?.agent,e.agent)??e.agent,task:en(o?.task,e.task),summary:er(a),model:en(o?.model),durationMs:ei(l?.durationMs),toolCount:ei(l?.toolCount),tokens:ei(l?.tokens),outputPath:en(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:en(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:s,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return et(t)&&Array.isArray(t.results)&&t.results.some(e=>et(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 el({messages:e,runs:t}){let r=(0,i.useMemo)(()=>eo(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),s=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(es,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(es,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function es({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)(ea,{run:e},e.id))]})}function ea({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":o?"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 ${s}`,background:a,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)(ed,{running:o,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:er(e.task,150)}),t&&c&&(0,n.jsxs)("div",{style:{borderTop:`1px solid ${s}`,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)(ec,{run:e})]})]})}function ed({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 ec({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 ep({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:i,isNew:o,isStreaming:l=!1,onResume:s,onDismiss:a}){if(o||"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})]}),i&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",i.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:a,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:s,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 eu(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 eh(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}function ex(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 eg(e){if("user"!==e.role)return null;var t=e.content;if("string"==typeof t)return`text:${t}`;if(!Array.isArray(t))try{return`other:${JSON.stringify(t)}`}catch{return"other:"}let r=t.map(e=>{if(!e||"object"!=typeof e)return e;if("text"===e.type)return{type:"text",text:e.text};if("image"===e.type){let t=e.source&&"object"==typeof e.source?e.source:{};return{type:"image",mimeType:t.media_type??e.mimeType,data:t.data??e.data,url:t.url}}return e});try{return`blocks:${JSON.stringify(r)}`}catch{return"blocks:"}}function ef(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let ev=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function em(e){return ev.some(t=>e.type.startsWith(t))}function ey({agentPhase:e,startedAt:t}){let[r,o]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void o(0);let e=()=>o(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.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 eb(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ej({goal:e,planTasks:t,isRunning:r,onExecutePlan:o}){let[l,s]=(0,i.useState)(!1),a=(0,i.useCallback)(()=>s(e=>!e),[]),d=e&&"dropped"!==e.status,c=t&&t.length>0;if(!d&&!c)return null;let p=(0,i.useMemo)(()=>!e?.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e?.tokenBudget,e?.tokensUsed]),u=t?.filter(e=>"completed"===e.status).length??0,h=!!t&&u===t.length;return(0,n.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[d&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:c?"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:[eb(e.tokensUsed),e.tokenBudget?` / ${eb(e.tokenBudget)} tokens`:" tokens"]}),null!=p&&(0,n.jsxs)("span",{children:[p,"%"]})]}),null!=p&&(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:p>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(p,100)}%`,transition:"width 0.3s"}})})]}),c&&(0,n.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,n.jsxs)("div",{onClick:a,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&a()},"aria-expanded":!l,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," 步"]}),h&&(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:["已完成 ",u,"/",t.length]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[o&&h&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o()},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:l?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!l&&(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))})]})]})}let ek=["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 ew({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(s||o!==i)if(s&&""===o)a(!1),r(t=>(t+1)%e.length);else{let e=s?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[o,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eS({status:e}){let t=e?.current??"0.8.57"??"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 eC({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:c,onSystemPromptChange:p,onSessionStatsChange:u,onContextUsageChange:h,onToolPresetActive:x,generativeUI:g}){var f;let v,[m,y]=(0,i.useState)(null),[b,j]=(0,i.useState)(!1),[k,w]=(0,i.useState)([]),{data:S,loading:C,error:M,messages:$,entryIds:D,streamState:N,agentRunning:A,modelNames:O,modelList:H,modelThinkingLevels:F,modelThinkingLevelMaps:U,toolPreset:_,memoryTools:K,thinkingLevel:V,retryInfo:J,contextUsage:Y,forkingEntryId:q,isCompacting:Z,compactError:G,displayModel:Q,sessionStats:et,agentPhase:er,agentError:en,isNew:ei,messagesEndRef:es,scrollContainerRef:ea,lastUserMsgRef:ed,handleSend:ec,handleAbort:ev,handleFork:eb,handleNavigate:eT,handleModelChange:ez,handleCompact:eI,handleSteer:eM,handleFollowUp:eW,handleAbortCompaction:eL,handleToolPresetChange:eR,handleMemoryToolsChange:eE,handleThinkingLevelChange:eP,handleAgentEventRef:e$}=function(e){let{session:t,newSessionCwd:r,onAgentEnd:n,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:a,onSystemPromptChange:d}=e,c=null===t&&null!==r,[p,u]=(0,i.useState)(null),[h,x]=(0,i.useState)(!c),[g,f]=(0,i.useState)(null),[v,m]=(0,i.useState)(null),[y,b]=(0,i.useState)([]),[j,k]=(0,i.useState)([]),[w,S]=(0,i.useReducer)(ex,{isStreaming:!1,streamingMessage:null}),[C,T]=(0,i.useState)(!1),[M,$]=(0,i.useState)({}),[D,N]=(0,i.useState)([]),[A,O]=(0,i.useState)({}),[H,F]=(0,i.useState)({}),[U,_]=(0,i.useState)(null),[K,V]=(0,i.useState)("full"),[J,Y]=(0,i.useState)([...I]),[q,Z]=(0,i.useState)("auto"),[G,X]=(0,i.useState)(null),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(null),[en,ei]=(0,i.useState)(null),[eo,el]=(0,i.useState)(null),[es,ea]=(0,i.useState)(null),[ed,ec]=(0,i.useState)(!1),[ep,ev]=(0,i.useState)(null),[em,ey]=(0,i.useState)(null),[eb,ej]=(0,i.useState)(null),ek=(0,i.useRef)(null),ew=(0,i.useRef)(t?.id??null),eS=(0,i.useRef)(!1),eC=(0,i.useRef)(null),eT=(0,i.useRef)(!1),ez=(0,i.useRef)(null),eI=(0,i.useRef)(!1),eM=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(new Map),eR=(0,i.useRef)(new Set),eE=e.setNewSessionModel??_,eP=e.setToolPreset??V,e$=e.setMemoryTools??Y,eB=eo??p?.context.model??es??null,eD=c?U:eB,eN=(0,i.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"):"",[]),eA=(0,i.useCallback)(e=>{let t=eg(e);if(!t)return;let r=eL.current;r.set(t,(r.get(t)??0)+1)},[]),eO=(0,i.useCallback)(e=>{let t=eg(e);if(!t)return!1;let r=eL.current,n=r.get(t)??0;return!(n<=0)&&(1===n?r.delete(t):r.set(t,n-1),!0)},[]),eH=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let r of y){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})(),eF=(0,i.useCallback)(async(e,t=!1,r=!1)=>{try{t&&x(!0);let n=r?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}`,i=await fetch(n);if(ew.current&&ew.current!==e)return null;if(404===i.status)return t&&(u(null),m(null),b([]),f(null)),null;if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();return u(o),m(o.leafId),b(o.context.messages),k(o.context.entryIds??[]),eL.current.clear(),eR.current=new Set(o.context.messages.map(ef).filter(e=>!!e)),el(null),f(null),!o.agentState?.state?.thinkingLevel&&o.context.thinkingLevel&&"off"!==o.context.thinkingLevel&&Z(o.context.thinkingLevel),o.agentState??null}catch(e){return f(String(e)),null}finally{t&&x(!1)}},[]),eU=(0,i.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 i=await n.json();b(i.context.messages),k(i.context.entryIds??[]),eL.current.clear()}catch(e){console.error("Failed to load context:",e)}},[]),e_=(0,i.useCallback)(async e=>{try{let t=await eh(e,{type:"get_tools"});if(t){let e,r,n,i;eP((r=(e=t.filter(e=>e.active).map(e=>e.name)).filter(e=>!I.includes(e)),n=P(e),i=P(r),""===n?"none":n===P(W)?"default":n===P(L)?"full":n===P(R)?"workbench":n===P(E)?"agent":""===i?"none":i===P(W)?"default":i===P(L)?"full":i===P(R)?"workbench":i===P(E)||e.includes(z)?"agent":"default")),e$(I.filter(e=>t.some(t=>t.active&&t.name===e)))}}catch(e){console.error("Failed to load tools:",e)}},[e$,eP]),eK=(0,i.useCallback)((e,t={})=>{ek.current&&(ek.current.close(),ek.current=null);let r=new EventSource(`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`);ek.current=r,r.onmessage=e=>{try{let t=JSON.parse(e.data);eC.current?.(t)}catch{}},r.onerror=()=>{ek.current===r&&eS.current&&(r.close(),ek.current=null,setTimeout(()=>{eS.current&&eK(e)},1e3))}},[]);(0,i.useEffect)(()=>{eS.current=C},[C]),eC.current=(0,i.useCallback)(e=>{switch(e.type){case"agent_start":ej(null),T(!0),ey({kind:"waiting_model"}),S({type:"start"});break;case"agent_end":eS.current=!1,ek.current?.close(),ek.current=null,T(!1),ey(null),X(null),S({type:"end"}),ew.current&&(eF(ew.current),fetch(`/api/agent/${encodeURIComponent(ew.current)}`).then(e=>e.json()).then(e=>{!1===e.running&&(T(!1),ey(null),S({type:"end"})),e.state?.contextUsage!==void 0&&ee(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&er(e.state.systemPrompt??null),e.state?.isCompacting!==void 0&&ec(e.state.isCompacting)}).catch(()=>{})),n?.();break;case"message_start":case"message_update":{let t=e.message;if(t){let e=eu(t);eR.current.has(ef(e)??"")||S({type:"update",message:e})}ey(null);break}case"message_end":{let t=e.message;if(t){let e=eu(t),r=ef(e),n=!!r&&eR.current.has(r);r&&eR.current.add(r),n||"user"===e.role&&eO(e)||b(t=>[...t,e])}S({type:"reset"}),ey({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName;ey(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;ey(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":X({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":X(null);break;case"auto_compaction_start":case"compaction_start":ec(!0),ev(null);break;case"auto_compaction_end":case"compaction_end":ec(!1),e.errorMessage?ev(e.errorMessage):!e.aborted&&ew.current&&eF(ew.current)}},[eO,eF,n]);let eV=(0,i.useCallback)(async(e,n,i)=>{if(!e.trim()&&!n?.length&&!i?.length||C)return;let l=eN(i),s=e.trim()?l?`${e}
|