@seqyuan/annovibe 0.8.66 → 0.8.67
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 +3 -3
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/agent/runtime/route.js +1 -1
- package/.next/server/app/api/internal/runtime/route.js +1 -1
- package/.next/server/app/api/models-config/test/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 +3 -3
- package/.next/server/chunks/4741.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/{page-85499519228afae8.js → page-b520597ccd6ee848.js} +2 -2
- package/package.json +3 -3
- /package/.next/static/{kSOfQw2tkIvT6TUDYFA26 → loesu0nFGu4lXnhvPK1si}/_buildManifest.js +0 -0
- /package/.next/static/{kSOfQw2tkIvT6TUDYFA26 → loesu0nFGu4lXnhvPK1si}/_ssgManifest.js +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{15845:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>r9});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function 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:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),b(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{v(!0),b(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&b(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children: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),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children: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 o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${y?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,s]=(0,o.useState)(""),[a,c]=(0,o.useState)(null),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[b,y]=(0,o.useState)(null),j=(0,o.useCallback)(async e=>{m(!0),y(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(n.current??""),c(n.parent??null),p(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){y(e instanceof Error?e.message:String(e))}finally{m(!1)}},[]);return((0,o.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&i(t)},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=g.trim();e&&j(e)},disabled:!g.trim()||v,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:g.trim()&&!v?"var(--text-muted)":"var(--text-dim)",cursor:g.trim()&&!v?"pointer":"default",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:g.trim()?"var(--accent)":"var(--bg-hover)",color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>a&&void j(a),disabled:!a,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:a?"var(--bg)":"transparent",color:a?"var(--text-muted)":"var(--text-dim)",cursor:a?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),h.length>0&&(0,n.jsxs)("select",{value:h.find(e=>l.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&j(e.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),h.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:l,children:l})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:v?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):b?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:b}):0===u.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):u.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void j(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let c="AnnoVibe",u="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function h(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function x(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function g(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function f(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"…/"+o.slice(-2).join(n)}function v(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||f(e,t)}let m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function b(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:m[Math.floor(Math.random()*m.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.66":c,r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function y({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:i,initialSessionId:l,onInitialRestoreDone:s,refreshKey:c,onSessionDeleted:g,selectedCwd:m,onCwdChange:T}){let[z,I]=(0,o.useState)([]),[M,W]=(0,o.useState)([]),[L,R]=(0,o.useState)(!0),[E,P]=(0,o.useState)(null),[$,D]=(0,o.useState)(null),[B,N]=(0,o.useState)(""),[A,H]=(0,o.useState)(null),[O,F]=(0,o.useState)(!1),[U,_]=(0,o.useState)("project"),[K,V]=(0,o.useState)(null),[J,Y]=(0,o.useState)(!1),[q,G]=(0,o.useState)(!1),[Z,X]=(0,o.useState)(()=>new Set),[Q,ee]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(u)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[et,er]=(0,o.useState)(null),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)(null),[es,ea]=(0,o.useState)(!1),ed=(0,o.useRef)(null),[ec,eu]=(0,o.useState)(!1),ep=(0,o.useRef)(!1),eh=(0,o.useRef)(!1),ex=(0,o.useRef)(!1),eg=(0,o.useCallback)(async(e=!1)=>{try{e&&(P(null),R(!0));let t=new AbortController,r=setTimeout(()=>t.abort(new DOMException("Loading timed out","TimeoutError")),3e4),[n,o]=await Promise.all([fetch("/api/sessions",{signal:t.signal}),fetch("/api/projects",{signal:t.signal})]);if(clearTimeout(r),!n.ok)throw Error(await x("sessions",n));if(!o.ok)throw Error(await x("projects",o));let i=await n.json(),l=await o.json();I(i.sessions),W(l.projects),P(null)}catch(e){P(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&&R(!1)}},[]),ef=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!ef.current;ef.current=!0,eg(e)},[eg,c]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{eg(!1)},15e3);return()=>window.clearInterval(e)},[eg]),(0,o.useEffect)(()=>{let e=()=>{eg(!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eg]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&N(e.home)}).catch(()=>{})},[]);let ev=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(ep.current){ep.current=!1;return}if(eh.current){eh.current=!1;return}T?.($)},[$,T]);let em=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return H(n.error??`HTTP ${r.status}`),!1;return eg(!1),!0}catch(e){return H(e instanceof Error?e.message:String(e)),!1}},[eg]),eb=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ey=(0,o.useCallback)(e=>{eh.current=!0,D(e),H(null),ee(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),h(r),r}),T?.(e),eb(e)},[T,eb]);(0,o.useEffect)(()=>{if((0!==z.length||0!==M.length)&&null===$){if(l&&!ev.current){ev.current=!0;let e=z.find(e=>e.id===l);if(e){D(e.cwd),eb(e.cwd),t(e,!0);return}s?.()}let e=M[0]?.cwd;e&&(D(e),eb(e))}},[z,M,$,l,t,s,eb]);let ej=m??$,ek=(0,o.useCallback)(e=>{if(!e){_("agent"),F(!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]),ew=(0,o.useCallback)(e=>{if(!e){_("workbench"),F(!0);return}i?.(e)},[i]),eS=(0,o.useCallback)(async e=>{await em(e,!0)&&(ey(e),F(!1),H(null),"agent"===U&&ek(e),"workbench"===U&&ew(e))},[ey,ek,ew,U,em]),eC=(0,o.useCallback)(e=>{V(e),Y(!0)},[]),eT=(0,o.useCallback)(()=>{Y(!1),V(null)},[]),ez=(0,o.useCallback)(e=>{let t=K??ej;eT(),"agent"===e?ek(t):ew(t)},[eT,ek,ew,ej,K]),eI=(0,o.useCallback)(()=>{eC(ej)},[ej,eC]),eM=(0,o.useCallback)(()=>{_("project"),H(null),F(!0)},[]),eW=(0,o.useMemo)(()=>[...ej&&!M.some(e=>e.cwd===ej)?[{cwd:ej,displayName:v(ej,B),chatCount:z.filter(e=>e.cwd===ej).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...M].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,o="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==o?n-o:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[z,ej,B,M]),eL=(0,o.useMemo)(()=>{let e=new Map;for(let t of z){let r=t.cwd||"";e.has(r)||e.set(r,[]),e.get(r).push(t)}let t=t=>{let r=[...e.get(t.cwd)??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:t,cwd:t.cwd,displayName:t.displayName||v(t.cwd,B),sessions:r,lastAccessed:(t.lastAccessed??t.created??"")||r[0]?.modified||""}},r=eW.filter(e=>!0===e.pinned).map(t);if(ej){let e=eW.find(e=>e.cwd===ej);e&&!0!==e.pinned&&r.push(t(e))}return r},[z,ej,B,eW]);(0,o.useEffect)(()=>{if(0===eL.length||ex.current||(ex.current=!0,!eL[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eL.slice(1).map(e=>e.cwd));ee(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(h(e),e):t),window.localStorage.setItem(p,"1")},[eL]);let eR=(0,o.useCallback)((e,r=!1)=>{e.cwd!==ej&&(ep.current=!0,D(e.cwd)),ee(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),h(r),r}),eb(e.cwd),t(e,r)},[t,ej,eb]),eE=(0,o.useCallback)(e=>{ee(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),h(r),r})},[]),eP=(0,o.useCallback)(e=>{X(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),e$=(0,o.useCallback)(async e=>{el("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}`);W(r.projects??[]),P(null)}catch(e){P(e instanceof Error?e.message:String(e)),eg(!1)}finally{el(null)}},[eg]),eD=(0,o.useCallback)(async(e,t)=>{el(`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}`);W(n.projects??[]),P(null)}catch(e){P(e instanceof Error?e.message:String(e)),eg(!1)}finally{el(null)}},[eg]),eB=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eW.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),o=r.indexOf(t);if(-1===n||-1===o)return;let i=[...r];i.splice(n,1);let l=i.indexOf(t);i.splice(l,0,e),e$(i)},[e$,eW]),eN=(0,o.useCallback)(async()=>{eu(!0);try{let e=eW.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=>{I(r=>[...r.filter(t=>t.cwd!==e),...t.sessions??[]])}).catch(()=>{}))):await eg(!1)}finally{eu(!1)}},[eg,eW]);return(0,o.useEffect)(()=>{if(!es)return;let e=e=>{ed.current&&!ed.current.contains(e.target)&&ea(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[es]),(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)(b,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eI,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:ej?`New chat in ${ej}`:"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:()=>G(!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:q,cwd:ej,homeDir:B,onClose:()=>G(!1),onSelectSession:e=>{eR(e)}}),(0,n.jsxs)("div",{ref:ed,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>ea(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:ej?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ej?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:ej??"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:ej?"var(--text)":"var(--text-dim)"},children:ej?eW.find(e=>e.cwd===ej)?.displayName??f(ej,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:es?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),ej&&(0,n.jsx)(k,{pinned:eW.find(e=>e.cwd===ej)?.pinned===!0,onToggle:()=>void eD(ej,eW.find(e=>e.cwd===ej)?.pinned!==!0)}),es&&(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===eW.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eW.map(e=>{let t=e.cwd===ej;return(0,n.jsx)(w,{project:e,homeDir:B,isCurrent:t,onSelect:()=>{ey(e.cwd),ea(!1)},onTogglePinned:()=>void eD(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{ea(!1),eM()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eW.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"Add project…"]})]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:eN,disabled:ec,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:ec?"var(--accent)":"var(--text-dim)",cursor:ec?"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:ec?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:eM,title:"New project","aria-label":"New project",style:{height:26,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s, color 0.12s, border-color 0.12s",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v4.5A1.5 1.5 0 0 1 13 12H3a1.5 1.5 0 0 1-1.5-1.5v-6Z"}),(0,n.jsx)("path",{d:"M11 7v3M9.5 8.5h3"})]}),"New Project"]})]})]}),A&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:A})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[L&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),E&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:E}),!L&&!E&&0===eL.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!L&&!E&&eL.map(t=>{let r=Q.has(t.cwd),o=t.cwd===ej,i=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 o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),s=l.length,a=l;if(s>10&&!i){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:en===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(en===t.cwd),opacity:et===t.cwd?.55:1},onDragOver:e=>{et&&et!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eo(t.cwd))},onDragLeave:()=>{en===t.cwd&&eo(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||et;eo(null),er(null),r&&eB(r,t.cwd)},children:[(0,n.jsx)(S,{group:t,isCurrent:o,isCollapsed:r,isDragging:et===t.cwd,pinBusy:ei===`pin:${t.cwd}`,onToggle:()=>eE(t.cwd),onSelect:()=>ey(t.cwd),onTogglePinned:()=>void eD(t.cwd,!0!==t.project.pinned),onDragStart:e=>{er(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{er(null),eo(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)(C,{node:t,selectedSessionId:e,onSelectSession:eR,onRenamed:eg,onSessionDeleted:e=>{g?.(e),eg()},depth:0},t.session.id)),(i||d>0)&&s>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eP(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:i?"Show less":`Show ${Math.max(0,d)} more`})]})]},t.cwd||"__no_project")})]}),J&&(0,n.jsx)(j,{cwd:K,onChoose:ez,onClose:eT}),(0,n.jsx)(d,{open:O,initialPath:ej,onClose:()=>F(!1),onSelect:e=>eS(e)})]})}function j({cwd:e,onChoose:t,onClose:r}){let o=e?v(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function k({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 w({project:e,homeDir:t,isCurrent:r,onSelect:i,onTogglePinned:l}){let[s,a]=(0,o.useState)(!1),d=e.displayName||v(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:i,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex: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 S({group:e,isCurrent:t,isCollapsed:r,isDragging:i,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:u}){let[p,h]=(0,o.useState)(!1),x=e.lastAccessed,f=Math.max(0,e.project.chatCount??e.sessions.length??0),v=!0===e.project.pinned,m=(0,o.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:c,onDragEnd:u,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),m())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:i?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:i?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!p&&f>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[f," ",1===f?"chat":"chats"]}),!p&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:g(x)}),v?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:p?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!p,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:p?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function C({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.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)(T,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,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)(C,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function T({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[f,v]=(0,o.useState)(""),[m,b]=(0,o.useState)(!1),[y,j]=(0,o.useState)(!1),k=(0,o.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,o.useCallback)(t=>{t.stopPropagation(),v(e.name??""),x(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,o.useCallback)(async()=>{let t=f.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[f,e.id,e.name,i]),z=(0,o.useCallback)(e=>{e.stopPropagation(),b(!0)},[]),I=(0,o.useCallback)(async t=>{t.stopPropagation(),b(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),b(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:m||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!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)":u?"var(--bg-hover)":"transparent",borderLeft:m?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:y?.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:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&x(!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:g(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"})})}),u&&(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 z=r(94456);let I="subagent",M=["retain","recall","reflect"],W=[],L=["read","bash","edit","write"],R=["bash","read","edit","write","grep","find","ls"],E=[...R,"kernel_plot_run","kernel_plot_render","kernel_plot_stop","kernel_plot_artifacts"],P=[...R,I];function $(e){return[...e].sort().join(",")}function D(e){switch(e){case"none":return W;case"default":return L;case"workbench":return E;case"agent":return P;default:return R}}function B(e,t){return[...new Set([...D(e),...t])]}let N=new Map,A=["off","default","full","agent"],H={off:"none",default:"default",full:"full",agent:"agent"},O={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},F={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},U=["auto","off","minimal","low","medium","high","xhigh"],_={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},K=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function V({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function J(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function Y(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,o=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&o.push(`Page ${e}
|
|
1
|
+
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{15845:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>r9});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function 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:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),b(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{v(!0),b(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&b(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children: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),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children: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 o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${y?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,s]=(0,o.useState)(""),[a,c]=(0,o.useState)(null),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[b,y]=(0,o.useState)(null),j=(0,o.useCallback)(async e=>{m(!0),y(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(n.current??""),c(n.parent??null),p(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){y(e instanceof Error?e.message:String(e))}finally{m(!1)}},[]);return((0,o.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&i(t)},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=g.trim();e&&j(e)},disabled:!g.trim()||v,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:g.trim()&&!v?"var(--text-muted)":"var(--text-dim)",cursor:g.trim()&&!v?"pointer":"default",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:g.trim()?"var(--accent)":"var(--bg-hover)",color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>a&&void j(a),disabled:!a,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:a?"var(--bg)":"transparent",color:a?"var(--text-muted)":"var(--text-dim)",cursor:a?"pointer":"default",padding:0},title:"Up",children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),h.length>0&&(0,n.jsxs)("select",{value:h.find(e=>l.toLowerCase().startsWith(e.toLowerCase()))??"",onChange:e=>{e.target.value&&j(e.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("option",{value:"",children:"Drive"}),h.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:l,children:l})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:v?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):b?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:b}):0===u.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):u.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void j(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let c="AnnoVibe",u="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function h(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function x(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function g(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function f(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"…/"+o.slice(-2).join(n)}function v(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||f(e,t)}let m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function b(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:m[Math.floor(Math.random()*m.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.67":c,r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function y({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:i,initialSessionId:l,onInitialRestoreDone:s,refreshKey:c,onSessionDeleted:g,selectedCwd:m,onCwdChange:T}){let[z,I]=(0,o.useState)([]),[M,W]=(0,o.useState)([]),[L,R]=(0,o.useState)(!0),[E,P]=(0,o.useState)(null),[$,D]=(0,o.useState)(null),[B,N]=(0,o.useState)(""),[A,H]=(0,o.useState)(null),[O,F]=(0,o.useState)(!1),[U,_]=(0,o.useState)("project"),[K,V]=(0,o.useState)(null),[J,Y]=(0,o.useState)(!1),[q,G]=(0,o.useState)(!1),[Z,X]=(0,o.useState)(()=>new Set),[Q,ee]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(u)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[et,er]=(0,o.useState)(null),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)(null),[es,ea]=(0,o.useState)(!1),ed=(0,o.useRef)(null),[ec,eu]=(0,o.useState)(!1),ep=(0,o.useRef)(!1),eh=(0,o.useRef)(!1),ex=(0,o.useRef)(!1),eg=(0,o.useCallback)(async(e=!1)=>{try{e&&(P(null),R(!0));let t=new AbortController,r=setTimeout(()=>t.abort(new DOMException("Loading timed out","TimeoutError")),3e4),[n,o]=await Promise.all([fetch("/api/sessions",{signal:t.signal}),fetch("/api/projects",{signal:t.signal})]);if(clearTimeout(r),!n.ok)throw Error(await x("sessions",n));if(!o.ok)throw Error(await x("projects",o));let i=await n.json(),l=await o.json();I(i.sessions),W(l.projects),P(null)}catch(e){P(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&&R(!1)}},[]),ef=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!ef.current;ef.current=!0,eg(e)},[eg,c]),(0,o.useEffect)(()=>{let e=window.setInterval(()=>{eg(!1)},15e3);return()=>window.clearInterval(e)},[eg]),(0,o.useEffect)(()=>{let e=()=>{eg(!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eg]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&N(e.home)}).catch(()=>{})},[]);let ev=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(ep.current){ep.current=!1;return}if(eh.current){eh.current=!1;return}T?.($)},[$,T]);let em=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return H(n.error??`HTTP ${r.status}`),!1;return eg(!1),!0}catch(e){return H(e instanceof Error?e.message:String(e)),!1}},[eg]),eb=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),ey=(0,o.useCallback)(e=>{eh.current=!0,D(e),H(null),ee(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),h(r),r}),T?.(e),eb(e)},[T,eb]);(0,o.useEffect)(()=>{if((0!==z.length||0!==M.length)&&null===$){if(l&&!ev.current){ev.current=!0;let e=z.find(e=>e.id===l);if(e){D(e.cwd),eb(e.cwd),t(e,!0);return}s?.()}let e=M[0]?.cwd;e&&(D(e),eb(e))}},[z,M,$,l,t,s,eb]);let ej=m??$,ek=(0,o.useCallback)(e=>{if(!e){_("agent"),F(!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]),ew=(0,o.useCallback)(e=>{if(!e){_("workbench"),F(!0);return}i?.(e)},[i]),eS=(0,o.useCallback)(async e=>{await em(e,!0)&&(ey(e),F(!1),H(null),"agent"===U&&ek(e),"workbench"===U&&ew(e))},[ey,ek,ew,U,em]),eC=(0,o.useCallback)(e=>{V(e),Y(!0)},[]),eT=(0,o.useCallback)(()=>{Y(!1),V(null)},[]),ez=(0,o.useCallback)(e=>{let t=K??ej;eT(),"agent"===e?ek(t):ew(t)},[eT,ek,ew,ej,K]),eI=(0,o.useCallback)(()=>{eC(ej)},[ej,eC]),eM=(0,o.useCallback)(()=>{_("project"),H(null),F(!0)},[]),eW=(0,o.useMemo)(()=>[...ej&&!M.some(e=>e.cwd===ej)?[{cwd:ej,displayName:v(ej,B),chatCount:z.filter(e=>e.cwd===ej).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...M].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,o="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==o?n-o:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[z,ej,B,M]),eL=(0,o.useMemo)(()=>{let e=new Map;for(let t of z){let r=t.cwd||"";e.has(r)||e.set(r,[]),e.get(r).push(t)}let t=t=>{let r=[...e.get(t.cwd)??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:t,cwd:t.cwd,displayName:t.displayName||v(t.cwd,B),sessions:r,lastAccessed:(t.lastAccessed??t.created??"")||r[0]?.modified||""}},r=eW.filter(e=>!0===e.pinned).map(t);if(ej){let e=eW.find(e=>e.cwd===ej);e&&!0!==e.pinned&&r.push(t(e))}return r},[z,ej,B,eW]);(0,o.useEffect)(()=>{if(0===eL.length||ex.current||(ex.current=!0,!eL[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eL.slice(1).map(e=>e.cwd));ee(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(h(e),e):t),window.localStorage.setItem(p,"1")},[eL]);let eR=(0,o.useCallback)((e,r=!1)=>{e.cwd!==ej&&(ep.current=!0,D(e.cwd)),ee(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),h(r),r}),eb(e.cwd),t(e,r)},[t,ej,eb]),eE=(0,o.useCallback)(e=>{ee(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),h(r),r})},[]),eP=(0,o.useCallback)(e=>{X(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),e$=(0,o.useCallback)(async e=>{el("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}`);W(r.projects??[]),P(null)}catch(e){P(e instanceof Error?e.message:String(e)),eg(!1)}finally{el(null)}},[eg]),eD=(0,o.useCallback)(async(e,t)=>{el(`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}`);W(n.projects??[]),P(null)}catch(e){P(e instanceof Error?e.message:String(e)),eg(!1)}finally{el(null)}},[eg]),eB=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eW.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),o=r.indexOf(t);if(-1===n||-1===o)return;let i=[...r];i.splice(n,1);let l=i.indexOf(t);i.splice(l,0,e),e$(i)},[e$,eW]),eN=(0,o.useCallback)(async()=>{eu(!0);try{let e=eW.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=>{I(r=>[...r.filter(t=>t.cwd!==e),...t.sessions??[]])}).catch(()=>{}))):await eg(!1)}finally{eu(!1)}},[eg,eW]);return(0,o.useEffect)(()=>{if(!es)return;let e=e=>{ed.current&&!ed.current.contains(e.target)&&ea(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[es]),(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)(b,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eI,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:ej?`New chat in ${ej}`:"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:()=>G(!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:q,cwd:ej,homeDir:B,onClose:()=>G(!1),onSelectSession:e=>{eR(e)}}),(0,n.jsxs)("div",{ref:ed,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>ea(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:ej?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ej?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:ej??"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:ej?"var(--text)":"var(--text-dim)"},children:ej?eW.find(e=>e.cwd===ej)?.displayName??f(ej,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:es?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),ej&&(0,n.jsx)(k,{pinned:eW.find(e=>e.cwd===ej)?.pinned===!0,onToggle:()=>void eD(ej,eW.find(e=>e.cwd===ej)?.pinned!==!0)}),es&&(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===eW.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eW.map(e=>{let t=e.cwd===ej;return(0,n.jsx)(w,{project:e,homeDir:B,isCurrent:t,onSelect:()=>{ey(e.cwd),ea(!1)},onTogglePinned:()=>void eD(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{ea(!1),eM()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eW.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"Add project…"]})]})]}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,n.jsx)("button",{type:"button",onClick:eN,disabled:ec,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:ec?"var(--accent)":"var(--text-dim)",cursor:ec?"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:ec?"spin 0.9s linear infinite":void 0},children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,n.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,n.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,n.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,n.jsxs)("button",{type:"button",onClick:eM,title:"New project","aria-label":"New project",style:{height:26,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s, color 0.12s, border-color 0.12s",flexShrink:0},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v4.5A1.5 1.5 0 0 1 13 12H3a1.5 1.5 0 0 1-1.5-1.5v-6Z"}),(0,n.jsx)("path",{d:"M11 7v3M9.5 8.5h3"})]}),"New Project"]})]})]}),A&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:A})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[L&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),E&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:E}),!L&&!E&&0===eL.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!L&&!E&&eL.map(t=>{let r=Q.has(t.cwd),o=t.cwd===ej,i=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 o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),s=l.length,a=l;if(s>10&&!i){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:en===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(en===t.cwd),opacity:et===t.cwd?.55:1},onDragOver:e=>{et&&et!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eo(t.cwd))},onDragLeave:()=>{en===t.cwd&&eo(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||et;eo(null),er(null),r&&eB(r,t.cwd)},children:[(0,n.jsx)(S,{group:t,isCurrent:o,isCollapsed:r,isDragging:et===t.cwd,pinBusy:ei===`pin:${t.cwd}`,onToggle:()=>eE(t.cwd),onSelect:()=>ey(t.cwd),onTogglePinned:()=>void eD(t.cwd,!0!==t.project.pinned),onDragStart:e=>{er(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{er(null),eo(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)(C,{node:t,selectedSessionId:e,onSelectSession:eR,onRenamed:eg,onSessionDeleted:e=>{g?.(e),eg()},depth:0},t.session.id)),(i||d>0)&&s>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eP(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:i?"Show less":`Show ${Math.max(0,d)} more`})]})]},t.cwd||"__no_project")})]}),J&&(0,n.jsx)(j,{cwd:K,onChoose:ez,onClose:eT}),(0,n.jsx)(d,{open:O,initialPath:ej,onClose:()=>F(!1),onSelect:e=>eS(e)})]})}function j({cwd:e,onChoose:t,onClose:r}){let o=e?v(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function k({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 w({project:e,homeDir:t,isCurrent:r,onSelect:i,onTogglePinned:l}){let[s,a]=(0,o.useState)(!1),d=e.displayName||v(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:i,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex: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 S({group:e,isCurrent:t,isCollapsed:r,isDragging:i,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:u}){let[p,h]=(0,o.useState)(!1),x=e.lastAccessed,f=Math.max(0,e.project.chatCount??e.sessions.length??0),v=!0===e.project.pinned,m=(0,o.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:m,onDragStart:c,onDragEnd:u,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),m())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":p?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:i?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:i?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!p&&f>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[f," ",1===f?"chat":"chats"]}),!p&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:g(x)}),v?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:p?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:p?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!p,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:p?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function C({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.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)(T,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,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)(C,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function T({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[f,v]=(0,o.useState)(""),[m,b]=(0,o.useState)(!1),[y,j]=(0,o.useState)(!1),k=(0,o.useRef)(null),w=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),S=(0,o.useCallback)(t=>{t.stopPropagation(),v(e.name??""),x(!0),setTimeout(()=>k.current?.select(),0)},[e.name]),C=(0,o.useCallback)(async()=>{let t=f.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[f,e.id,e.name,i]),z=(0,o.useCallback)(e=>{e.stopPropagation(),b(!0)},[]),I=(0,o.useCallback)(async t=>{t.stopPropagation(),b(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),b(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:m||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!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)":u?"var(--bg-hover)":"transparent",borderLeft:m?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:y?.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:C,onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&x(!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:g(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"})})}),u&&(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 z=r(94456);let I="subagent",M=["retain","recall","reflect"],W=[],L=["read","bash","edit","write"],R=["bash","read","edit","write","grep","find","ls"],E=[...R,"kernel_plot_run","kernel_plot_render","kernel_plot_stop","kernel_plot_artifacts"],P=[...R,I];function $(e){return[...e].sort().join(",")}function D(e){switch(e){case"none":return W;case"default":return L;case"workbench":return E;case"agent":return P;default:return R}}function B(e,t){return[...new Set([...D(e),...t])]}let N=new Map,A=["off","default","full","agent"],H={off:"none",default:"default",full:"full",agent:"agent"},O={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},F={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},U=["auto","off","minimal","low","medium","high","xhigh"],_={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},K=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function V({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function J(e){return e.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function Y(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,o=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&o.push(`Page ${e}
|
|
2
2
|
${r}`)}return o.join("\n\n")}async function q(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],i=[];for(let e of o){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];i.push(...r.map(e=>J(e[1])))}return i.join("").replace(/[ \t]+\n/g,"\n")}async function G(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],o=t.utils.sheet_to_csv(r);return`Sheet: ${e}
|
|
3
3
|
${o}`}).join("\n\n")}async function Z(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),i=[];for(let{name:e,match:t}of o){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>J(e[1]).trim()).filter(Boolean);r.length&&i.push(`Slide ${t[1]}
|
|
4
4
|
${r.join("\n")}`)}return i.join("\n\n")}async function X(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,o="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))o=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)o=await Y(t);else if("docx"===r)o=await q(t);else if("xlsx"===r)o=await G(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};o=await Z(t)}let{text:i,truncated:l}=(n=o.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
|
|
5
5
|
|
|
6
|
-
[truncated after 60000 characters]`,truncated:!0};if(!i)return{extractionError:"No extractable text found"};return{extractedText:i,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let Q=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,sessionKind:f,onToolPresetChange:v,memoryTools:m,onMemoryToolsChange:b,thinkingLevel:y,onThinkingLevelChange:j,availableThinkingLevels:k,thinkingLevelMap:w,retryInfo:S,soundEnabled:C,onSoundToggle:T,planMode:z,onPlanModeChange:I,cornerBadge:W,promptHistory:L,sessionHistoryKey:R},E){let P,$,D,[B,J]=(0,o.useState)(""),[Y,q]=(0,o.useState)(!1),[G,Z]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(!1),[et,er]=(0,o.useState)(!1),[en,eo]=(0,o.useState)(!1),[ei,el]=(0,o.useState)(!1),[es,ea]=(0,o.useState)(!1),[ed,ec]=(0,o.useState)(null),[eu,ep]=(0,o.useState)([]),[eh,ex]=(0,o.useState)([]),eg=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),ef=eg?{display:"none"}:void 0,ev=eg?28:32,em=eg?"6px 8px":"8px 12px",eb=eg?160:180,ey=eg&&!l,ej=es?"var(--text)":"var(--text-muted)",ek={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},ew=eg?{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},[eS,eC]=(0,o.useState)(null),eT=(0,o.useRef)(null),ez=(0,o.useRef)(null),eI=(0,o.useRef)(null),eM=(0,o.useRef)(null),eW=(0,o.useRef)(null),eL=(0,o.useRef)(null),eR=(0,o.useRef)(null),eE=(0,o.useRef)(null),eP=(0,o.useRef)(null),e$=(0,o.useRef)(null),eD=(0,o.useCallback)(e=>{let t=eT.current;if(!t)return void J(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=!(o.length>0)||o.endsWith(" ")||o.endsWith("\n")?"":" ";J(o+l+e+i),requestAnimationFrame(()=>{let t=eT.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,o.useImperativeHandle)(E,()=>({insertIfEmpty(e){let t=eT.current;(t?t.value:B).trim()||(J(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eD(e)},addImages(e){eB(e)},addFiles(e){eN(e)}}));let eB=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ep(e=>[...e,...r])},[]),eN=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eB(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,o=await X(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));ex(t=>[...t,...e])}},[eB]),eA=(0,o.useCallback)(e=>{ep(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eH=(0,o.useCallback)(e=>{ex(t=>{let r=[...t];return r.splice(e,1),r})},[]),eO=(0,o.useCallback)(()=>{ep(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ex([])},[]),eF=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})),eU=[];for(let e of eF){let t=eU.find(t=>t.provider===e.provider);t?t.options.push(e):eU.push({provider:e.provider,options:[e]})}let e_=s?eF.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eF.length>0?eF[0].name:null,eK=s?eF.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eF[0],eV=eK?.input?.includes("image")??!0,eJ=eu.length>0&&eK?.input!==void 0&&!eV,eY=(!!B.trim()||eu.length>0||eh.length>0)&&!eJ,eq=u?K:K.filter(e=>"/compact"!==e.command),eG=eq.filter(e=>"native"===e.kind),eZ=eq.filter(e=>"shortcut"===e.kind),eX=m??[],eQ=eX.length>0?`${eX.length} enabled`:"off",e0=eF.length>0&&!!e_&&!!c,e1=!!j,e2=!!v&&"workbench"!==f,e5=e_??"Default",e4=(()=>{let e=y??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e3=(g??"full")==="workbench"?"workbench":Object.entries(H).find(([,e])=>e===(g??"full"))?.[0]??"full",e8=eg?26:32,e6=eg?7:9,e7=eg?3:6,e9={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)"},te=eg&&(Y||Q||et||en||ei||es);(0,o.useEffect)(()=>{eJ||eC(null)},[eJ]);let tt=(0,o.useCallback)(e=>{if(!B.trim()){J(e),requestAnimationFrame(()=>{let t=eT.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eD(e)},[eD,B]),tr=(0,o.useCallback)(()=>{let t=B.trim();if(t||eu.length||eh.length){if(eu.length&&!eV)return void eC("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!eu.length&&!eh.length&&u){h?p?.():u(),J(""),eT.current&&(eT.current.style.height="auto");return}e(t,eu.length?eu:void 0,eh.length?eh:void 0),J(""),eO(),eT.current&&(eT.current.style.height="auto")}}},[B,eu,eh,eV,l,e,eO,u,p,h]),tn=(0,o.useCallback)(e=>{let t=B.trim();if(!t&&!eu.length&&!eh.length)return;if(eu.length&&!eV)return void eC("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eu.length?eu:void 0,o=eh.length?eh:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),J(""),eO(),eT.current&&(eT.current.style.height="auto")},[B,eu,eh,eV,r,i,eO]),to=L??[],ti=R??null,tl=(0,o.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&to.length>0){let t=eT.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let o=((n=N.get(e))||(n={cursor:-1,draftSnapshot:""},N.set(e,n)),n);if(-1===o.cursor)o.draftSnapshot=t,o.cursor=0;else{if(!(o.cursor<r.length-1))return null;o.cursor+=1}return r[o.cursor]??null}(ti,t.value,to);null!==n&&(J(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=N.get(e);return(t?.cursor??-1)>=0}(ti)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=N.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}}(ti,to);t&&(J(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eT.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ti&&N.set(ti,{cursor:-1,draftSnapshot:""}),l&&(r||i)?tn(r?"steer":"followup"):tr())},[l,r,i,tn,tr,to,ti]),ts=(0,o.useCallback)(()=>{let e=eT.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),ta=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eN(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eN]);return(0,o.useEffect)(()=>{if(!Y&&!Q&&!et&&!en&&!ei&&!es)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!ez.current?.contains(t),n=!!eI.current?.contains(t);r||n||q(!1),eM.current?.contains(t)||ee(!1),eW.current?.contains(t)||er(!1),eL.current?.contains(t)||eo(!1),eR.current?.contains(t)||el(!1),eE.current?.contains(t)||ea(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[Y,Q,et,en,ei,es]),(0,o.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||ec(!!t?.ready)}).catch(()=>{e||ec(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:ew,children:[te&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{q(!1),ee(!1),er(!1),eo(!1),el(!1),ea(!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:eP,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eB(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:e$,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=>{eN(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eg?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eg?"0 8px":void 0,boxSizing:"border-box"},children:[W&&(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:W}),S&&(0,n.jsxs)("div",{style:{marginBottom:eg?6:8,padding:eg?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eg?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]})]}),(eu.length>0||eh.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:[eu.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 ${eJ?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eA(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}`)),eh.map((e,t)=>(0,n.jsx)(V,{doc:e,onRemove:()=>eH(t)},`doc-${t}`))]}),(eJ||eS)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:eg?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:eS??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:eg?4:8,alignItems:eg?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:eg?13:14,padding:eg?"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:eT,value:B,onChange:e=>J(e.target.value),onKeyDown:tl,onInput:ts,onPaste:ta,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:eg?"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:+!!eg,paddingBottom:+!!eg}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:eg?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tn("steer"),disabled:!eY,title:eJ?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eg,padding:eg?"6px 8px":"7px 12px",background:eY?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eY?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eY?"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"})]}),!eg&&"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>tn("followup"),disabled:!eY,title:eJ?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eg,padding:eg?"6px 8px":"7px 12px",background:eY?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eY?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eY?"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"})]}),!eg&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:tr,disabled:!eY,title:eJ?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eg?3:6,padding:eg?"5px 9px":"7px 14px",marginBottom:+!!eg,background:eY?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eY?"#fff":"var(--text-dim)",cursor:eY?"pointer":"not-allowed",fontSize:eg?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eY?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:eg?13:14,height:eg?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:eg?5:8,display:"flex",alignItems:eg?"flex-start":"center",gap:e7,flexWrap:eg?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eg?"1 1 100%":"0 0 auto",width:eg?"100%":void 0,display:"flex",alignItems:"center",gap:2*!eg,flexWrap:eg?"wrap":"nowrap",rowGap:4*!!eg},children:[(0,n.jsx)("button",{onClick:()=>eP.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e8,height:e8,padding:0,background:"none",border:"none",borderRadius:e6,color:eu.length||eh.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=eu.length||eh.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eu.length||eh.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),e$.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:eM,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ee(e=>!e),er(!1),q(!1),eo(!1),el(!1),ea(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e8,height:e8,padding:0,background:Q?"var(--bg-hover)":"none",border:"none",borderRadius:e6,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=Q?"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"}})]}),Q&&(0,n.jsxs)("div",{style:{...eg?e9:{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}),eG.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"}),eG.map(e=>(0,n.jsxs)("button",{onClick:()=>{(ee(!1),"/compact"===e.command&&h)?p?.():tt(e.command)},style:{display:"flex",alignItems:"center",gap:eg?6:8,width:"100%",padding:em,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eg?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))]}),eZ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eG.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eG.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eZ.map(e=>(0,n.jsxs)("button",{onClick:()=>{ee(!1),tt(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eg?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))]})]})]}),b&&(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(er(e=>!e),ee(!1),q(!1),eo(!1),el(!1),ea(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ev,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:eX.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=eX.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=et?"var(--bg-hover)":"none",e.currentTarget.style.color=eX.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eX.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),et&&(0,n.jsxs)("div",{style:{...eg?e9:{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"}),M.map(e=>{let t=eX.includes(e),r=F[e];return(0,n.jsxs)("button",{onClick:()=>{b(t?eX.filter(t=>t!==e):[...eX,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eg?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)})]})]}),e0&&(0,n.jsxs)("div",{ref:ez,style:{position:"relative",flex:eg?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eg){let t=e.currentTarget.getBoundingClientRect();Z({top:t.top,left:t.left,width:t.width})}ee(!1),er(!1),eo(!1),el(!1),ea(!1),q(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ev,width:eg?"100%":void 0,maxWidth:eg?"100%":220,overflow:"hidden",background:Y?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?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=Y?"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:e_})]}),Y&&(eg?(0,n.jsxs)("div",{ref:eI,style:{...e9,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:e_})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eU.map((e,t)=>(0,n.jsxs)("div",{children:[eU.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:()=>{q(!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))})]}):G&&($=(P=window.visualViewport?.height??window.innerHeight)-G.top+6,D=Math.max(120,Math.min(G.top-8,.6*P)),(0,n.jsx)("div",{ref:eI,style:{position:"fixed",bottom:$,left:G.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:G.width,maxHeight:D,overflowY:"auto"},children:eU.map((e,t)=>(0,n.jsxs)("div",{children:[eU.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:()=>{q(!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:ey?"none":void 0,flex:eg?"0 0 auto":1,width:eg?0:void 0,height:eg?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:eg?"1 1 100%":"0 0 auto",width:eg?"100%":void 0,display:"flex",alignItems:"center",justifyContent:eg?"space-between":void 0,gap:eg?4:2,marginLeft:eg?0:"auto",marginTop:2*!!eg},children:[ey&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{ee(!1),er(!1),q(!1),eo(!1),el(!1),ea(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:es?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ej,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=es?"var(--bg-hover)":"none",e.currentTarget.style.color=es?"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"})]})}),es&&(0,n.jsxs)("div",{style:{...e9,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:[e0&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),el(!1),eo(!1),er(!1),q(!0)},style:ek,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:e5})]}),(e1||e2)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e1&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),q(!1),eo(!1),er(!1),el(!0)},style:ek,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:e4})]}),e2&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),q(!1),el(!1),er(!1),eo(!0)},style:ek,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:e3})]})]}),!!b&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),q(!1),el(!1),eo(!1),er(!0)},style:ek,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:eX.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eQ})]})]})]})]}),(!ey&&!l||eg&&ei)&&j&&(0,n.jsxs)("div",{ref:eR,style:{position:"relative"},children:[!ey&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(ee(!1),er(!1),q(!1),eo(!1),ea(!1),el(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:eg?3:5,padding:em,height:ev,background:ei?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?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=ei?"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:ef,children:(()=>{let e=y??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),ei&&(0,n.jsx)("div",{style:{...eg?e9:{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:eb},overflow:"hidden"},children:U.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(y??"auto")===e,r=_[e],o="auto"!==e&&w?w[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{el(!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:eg?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ey&&!l||eg&&en)&&e2&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[!ey&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(ee(!1),er(!1),q(!1),el(!1),ea(!1),eo(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eg?3:5,padding:em,height:ev,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?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=en?"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:ef,children:e3})]}),en&&(0,n.jsx)("div",{style:{...eg?e9:{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:A.map(e=>{let t=H[e],r=(g??"full")===t,o="agent"===e&&!1===ed,i=o?"需安装 pi-subagents":O[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(eo(!1),r||v(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:eg?11:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ev,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eg?8:9,color:"#ef4444",cursor:"pointer",fontSize:eg?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"]}),!ey&&void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{l||I(!z)},disabled:l,title:z?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ev,background:z?"rgba(59,130,246,0.08)":"none",border:z?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:eg?8:9,color:z?"#3b82f6":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background=z?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color=z?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=z?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color=z?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:ef,children:z?"Plan":"Code"})]}),void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:eg?28:32,height:eg?28:32,padding:0,background:"none",border:"none",borderRadius:eg?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 ee(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 et({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),b=(0,o.useRef)(null),y=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(y);j.current=y;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=b.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,W=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:b,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}}),p.map(e=>{let t=ee(e.msg),r=x&&W===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=ee(e.msg),i=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 ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function er(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function en(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function eo(...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 el(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:en(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!er(t))return{...e,summary:en(r)};let o=Array.isArray(t.results)?t.results.filter(er):[],i=o[0],l=i?.progressSummary,s=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=eo(i?.finalOutput,i?.output,r);return{...e,mode:eo(t.mode),runId:eo(t.runId),agent:eo(i?.agent,e.agent)??e.agent,task:eo(i?.task,e.task),summary:en(a),model:eo(i?.model),durationMs:ei(l?.durationMs),toolCount:ei(l?.toolCount),tokens:ei(l?.tokens),outputPath:eo(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:eo(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:s,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return er(t)&&Array.isArray(t.results)&&t.results.some(e=>er(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 es({messages:e,runs:t}){let r=(0,o.useMemo)(()=>el(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),s=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(ea,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(ea,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function ea({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)(ed,{run:e},e.id))]})}function ed({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${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)(ec,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:en(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)(eu,{run:e})]})]})}function ec({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 eu({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:o,isNew:i,isStreaming:l=!1,onResume:s,onDismiss:a}){if(i||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),o&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",o.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick: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 eh(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 ex(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 eg(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 ef(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 ev(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let em=["read","bash","grep","find","ls"],eb=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ey(e){return eb.some(t=>e.type.startsWith(t))}function ej({agentPhase:e,startedAt:t}){let[r,i]=(0,o.useState)(0);return(0,o.useEffect)(()=>{if(!t)return void i(0);let e=()=>i(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);return 0===t.length?"Running tool…":1===t.length?`Running ${t[0]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(r)]})})}function ek(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ew({goal:e,planTasks:t,isRunning:r,onExecutePlan:i,onContinuePlanning:l,onEditPlan:s}){let[a,d]=(0,o.useState)(!1),c=(0,o.useCallback)(()=>d(e=>!e),[]),u=e&&"dropped"!==e.status,p=t&&t.length>0;if(!u&&!p)return null;let h=(0,o.useMemo)(()=>!e?.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e?.tokenBudget,e?.tokensUsed]),x=t?.filter(e=>"completed"===e.status).length??0,g=!!t&&x===t.length;return(0,n.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[u&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:p?"1px solid var(--border)":"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[ek(e.tokensUsed),e.tokenBudget?` / ${ek(e.tokenBudget)} tokens`:" tokens"]}),null!=h&&(0,n.jsxs)("span",{children:[h,"%"]})]}),null!=h&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:h>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(h,100)}%`,transition:"width 0.3s"}})})]}),p&&(0,n.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,n.jsxs)("div",{onClick:c,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&c()},"aria-expanded":!a,style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,cursor:"pointer",padding:"6px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"#3b82f6"},children:["Plan \xb7 ",t.length," 步"]}),g&&(0,n.jsxs)("span",{style:{borderRadius:4,padding:"0 6px",fontSize:10,fontWeight:600,background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",x,"/",t.length]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(s||l||i)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[s&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),s()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"修改计划"}),l&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"继续规划"}),i&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),i()},disabled:r,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:r?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:r?"not-allowed":"pointer"},children:"执行计划"})]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:a?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!a&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,borderRadius:4,padding:"3px 8px",background:"inProgress"===e.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,n.jsx)("div",{style:{marginTop:1},children:function(e){switch(e){case"completed":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,n.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,n.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round",children:(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"1.5s",repeatCount:"indefinite"})})]});default:return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"var(--border)",strokeWidth:"1.5"})})}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:12,lineHeight:1.5,...function(e){switch(e){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(e.status)},children:e.step})]},e.id))})]})]})}function eS(e){let t=e.findIndex(e=>"completed"!==e.status);return t<0?e:e.map((e,r)=>r===t?{...e,status:"completed"}:r===t+1&&"pending"===e.status?{...e,status:"inProgress"}:e)}let eC=["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 eT({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(s||i!==o)if(s&&""===i)a(!1),r(t=>(t+1)%e.length);else{let e=s?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[i,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function ez({status:e}){let t=e?.current??"0.8.66"??"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 eI({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSystemPromptChange:u,onSessionStatsChange:p,onContextUsageChange:h,onToolPresetActive:x,generativeUI:g}){var f;let v,[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useState)(""),[T,W]=(0,o.useState)(!1),D=(0,o.useRef)(!1),{data:N,loading:A,error:H,messages:O,entryIds:F,streamState:U,agentRunning:_,modelNames:K,modelList:V,modelThinkingLevels:J,modelThinkingLevelMaps:Y,toolPreset:q,memoryTools:G,thinkingLevel:Z,retryInfo:X,contextUsage:ee,forkingEntryId:er,isCompacting:en,compactError:eo,displayModel:ei,sessionStats:ea,agentPhase:ed,agentError:ec,isNew:eu,messagesEndRef:eb,scrollContainerRef:ek,lastUserMsgRef:eM,handleSend:eW,handleAbort:eL,handleFork:eR,handleNavigate:eE,handleModelChange:eP,handleCompact:e$,handleSteer:eD,handleFollowUp:eB,handleAbortCompaction:eN,handleToolPresetChange:eA,handleMemoryToolsChange:eH,handleThinkingLevelChange:eO,handleAgentEventRef:eF}=function(e){let{session:t,newSessionCwd:r,planMode:n=!1,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:d,onSystemPromptChange:c}=e,u=null===t&&null!==r,[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!u),[f,v]=(0,o.useState)(null),[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)([]),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useReducer)(eg,{isStreaming:!1,streamingMessage:null}),[T,z]=(0,o.useState)(!1),[W,D]=(0,o.useState)({}),[N,A]=(0,o.useState)([]),[H,O]=(0,o.useState)({}),[F,U]=(0,o.useState)({}),[_,K]=(0,o.useState)(null),[V,J]=(0,o.useState)("full"),[Y,q]=(0,o.useState)([...M]),[G,Z]=(0,o.useState)("auto"),[X,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(null),[er,en]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(null),[el,es]=(0,o.useState)(null),[ea,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(!1),[ep,eb]=(0,o.useState)(null),[ey,ej]=(0,o.useState)(null),[ek,ew]=(0,o.useState)(null),eS=(0,o.useRef)(null),eC=(0,o.useRef)(t?.id??null),eT=(0,o.useRef)(!1),ez=(0,o.useRef)(null),eI=(0,o.useRef)(!1),eM=(0,o.useRef)(null),eW=(0,o.useRef)(!1),eL=(0,o.useRef)(null),eR=(0,o.useRef)(null),eE=(0,o.useRef)(new Map),eP=(0,o.useRef)(new Set),e$=e.setNewSessionModel??K,eD=e.setToolPreset??J,eB=e.setMemoryTools??q,eN=el??p?.context.model??ea??null,eA=u?_:eN,eH=(0,o.useCallback)(()=>n?em:B(V,Y),[Y,n,V]),eO=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
|
|
6
|
+
[truncated after 60000 characters]`,truncated:!0};if(!i)return{extractionError:"No extractable text found"};return{extractedText:i,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let Q=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,sessionKind:f,onToolPresetChange:v,memoryTools:m,onMemoryToolsChange:b,thinkingLevel:y,onThinkingLevelChange:j,availableThinkingLevels:k,thinkingLevelMap:w,retryInfo:S,soundEnabled:C,onSoundToggle:T,planMode:z,onPlanModeChange:I,cornerBadge:W,promptHistory:L,sessionHistoryKey:R},E){let P,$,D,[B,J]=(0,o.useState)(""),[Y,q]=(0,o.useState)(!1),[G,Z]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(!1),[et,er]=(0,o.useState)(!1),[en,eo]=(0,o.useState)(!1),[ei,el]=(0,o.useState)(!1),[es,ea]=(0,o.useState)(!1),[ed,ec]=(0,o.useState)(null),[eu,ep]=(0,o.useState)([]),[eh,ex]=(0,o.useState)([]),eg=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),ef=eg?{display:"none"}:void 0,ev=eg?28:32,em=eg?"6px 8px":"8px 12px",eb=eg?160:180,ey=eg&&!l,ej=es?"var(--text)":"var(--text-muted)",ek={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},ew=eg?{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},[eS,eC]=(0,o.useState)(null),eT=(0,o.useRef)(null),ez=(0,o.useRef)(null),eI=(0,o.useRef)(null),eM=(0,o.useRef)(null),eW=(0,o.useRef)(null),eL=(0,o.useRef)(null),eR=(0,o.useRef)(null),eE=(0,o.useRef)(null),eP=(0,o.useRef)(null),e$=(0,o.useRef)(null),eD=(0,o.useCallback)(e=>{let t=eT.current;if(!t)return void J(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=!(o.length>0)||o.endsWith(" ")||o.endsWith("\n")?"":" ";J(o+l+e+i),requestAnimationFrame(()=>{let t=eT.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,o.useImperativeHandle)(E,()=>({insertIfEmpty(e){let t=eT.current;(t?t.value:B).trim()||(J(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eD(e)},addImages(e){eB(e)},addFiles(e){eN(e)}}));let eB=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ep(e=>[...e,...r])},[]),eN=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eB(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,o=await X(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));ex(t=>[...t,...e])}},[eB]),eA=(0,o.useCallback)(e=>{ep(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eH=(0,o.useCallback)(e=>{ex(t=>{let r=[...t];return r.splice(e,1),r})},[]),eO=(0,o.useCallback)(()=>{ep(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ex([])},[]),eF=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})),eU=[];for(let e of eF){let t=eU.find(t=>t.provider===e.provider);t?t.options.push(e):eU.push({provider:e.provider,options:[e]})}let e_=s?eF.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eF.length>0?eF[0].name:null,eK=s?eF.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eF[0],eV=eK?.input?.includes("image")??!0,eJ=eu.length>0&&eK?.input!==void 0&&!eV,eY=(!!B.trim()||eu.length>0||eh.length>0)&&!eJ,eq=u?K:K.filter(e=>"/compact"!==e.command),eG=eq.filter(e=>"native"===e.kind),eZ=eq.filter(e=>"shortcut"===e.kind),eX=m??[],eQ=eX.length>0?`${eX.length} enabled`:"off",e0=eF.length>0&&!!e_&&!!c,e1=!!j,e2=!!v&&"workbench"!==f,e5=e_??"Default",e4=(()=>{let e=y??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e3=(g??"full")==="workbench"?"workbench":Object.entries(H).find(([,e])=>e===(g??"full"))?.[0]??"full",e8=eg?26:32,e6=eg?7:9,e7=eg?3:6,e9={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)"},te=eg&&(Y||Q||et||en||ei||es);(0,o.useEffect)(()=>{eJ||eC(null)},[eJ]);let tt=(0,o.useCallback)(e=>{if(!B.trim()){J(e),requestAnimationFrame(()=>{let t=eT.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eD(e)},[eD,B]),tr=(0,o.useCallback)(()=>{let t=B.trim();if(t||eu.length||eh.length){if(eu.length&&!eV)return void eC("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!eu.length&&!eh.length&&u){h?p?.():u(),J(""),eT.current&&(eT.current.style.height="auto");return}e(t,eu.length?eu:void 0,eh.length?eh:void 0),J(""),eO(),eT.current&&(eT.current.style.height="auto")}}},[B,eu,eh,eV,l,e,eO,u,p,h]),tn=(0,o.useCallback)(e=>{let t=B.trim();if(!t&&!eu.length&&!eh.length)return;if(eu.length&&!eV)return void eC("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eu.length?eu:void 0,o=eh.length?eh:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),J(""),eO(),eT.current&&(eT.current.style.height="auto")},[B,eu,eh,eV,r,i,eO]),to=L??[],ti=R??null,tl=(0,o.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&to.length>0){let t=eT.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let o=((n=N.get(e))||(n={cursor:-1,draftSnapshot:""},N.set(e,n)),n);if(-1===o.cursor)o.draftSnapshot=t,o.cursor=0;else{if(!(o.cursor<r.length-1))return null;o.cursor+=1}return r[o.cursor]??null}(ti,t.value,to);null!==n&&(J(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=N.get(e);return(t?.cursor??-1)>=0}(ti)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=N.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}}(ti,to);t&&(J(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eT.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ti&&N.set(ti,{cursor:-1,draftSnapshot:""}),l&&(r||i)?tn(r?"steer":"followup"):tr())},[l,r,i,tn,tr,to,ti]),ts=(0,o.useCallback)(()=>{let e=eT.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),ta=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eN(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eN]);return(0,o.useEffect)(()=>{if(!Y&&!Q&&!et&&!en&&!ei&&!es)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!ez.current?.contains(t),n=!!eI.current?.contains(t);r||n||q(!1),eM.current?.contains(t)||ee(!1),eW.current?.contains(t)||er(!1),eL.current?.contains(t)||eo(!1),eR.current?.contains(t)||el(!1),eE.current?.contains(t)||ea(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[Y,Q,et,en,ei,es]),(0,o.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||ec(!!t?.ready)}).catch(()=>{e||ec(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:ew,children:[te&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{q(!1),ee(!1),er(!1),eo(!1),el(!1),ea(!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:eP,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eB(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:e$,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=>{eN(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:eg?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:eg?"0 8px":void 0,boxSizing:"border-box"},children:[W&&(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:W}),S&&(0,n.jsxs)("div",{style:{marginBottom:eg?6:8,padding:eg?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:eg?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]})]}),(eu.length>0||eh.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:[eu.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 ${eJ?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eA(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}`)),eh.map((e,t)=>(0,n.jsx)(V,{doc:e,onRemove:()=>eH(t)},`doc-${t}`))]}),(eJ||eS)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:eg?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:eS??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:eg?4:8,alignItems:eg?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:eg?13:14,padding:eg?"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:eT,value:B,onChange:e=>J(e.target.value),onKeyDown:tl,onInput:ts,onPaste:ta,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:eg?"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:+!!eg,paddingBottom:+!!eg}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:eg?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tn("steer"),disabled:!eY,title:eJ?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!eg,padding:eg?"6px 8px":"7px 12px",background:eY?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eY?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eY?"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"})]}),!eg&&"Steer"]}),i&&(0,n.jsxs)("button",{onClick:()=>tn("followup"),disabled:!eY,title:eJ?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!eg,padding:eg?"6px 8px":"7px 12px",background:eY?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eY?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eY?"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"})]}),!eg&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:tr,disabled:!eY,title:eJ?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:eg?3:6,padding:eg?"5px 9px":"7px 14px",marginBottom:+!!eg,background:eY?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eY?"#fff":"var(--text-dim)",cursor:eY?"pointer":"not-allowed",fontSize:eg?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eY?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:eg?13:14,height:eg?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:eg?5:8,display:"flex",alignItems:eg?"flex-start":"center",gap:e7,flexWrap:eg?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:eg?"1 1 100%":"0 0 auto",width:eg?"100%":void 0,display:"flex",alignItems:"center",gap:2*!eg,flexWrap:eg?"wrap":"nowrap",rowGap:4*!!eg},children:[(0,n.jsx)("button",{onClick:()=>eP.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e8,height:e8,padding:0,background:"none",border:"none",borderRadius:e6,color:eu.length||eh.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=eu.length||eh.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eu.length||eh.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),e$.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:eM,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ee(e=>!e),er(!1),q(!1),eo(!1),el(!1),ea(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e8,height:e8,padding:0,background:Q?"var(--bg-hover)":"none",border:"none",borderRadius:e6,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=Q?"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"}})]}),Q&&(0,n.jsxs)("div",{style:{...eg?e9:{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}),eG.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"}),eG.map(e=>(0,n.jsxs)("button",{onClick:()=>{(ee(!1),"/compact"===e.command&&h)?p?.():tt(e.command)},style:{display:"flex",alignItems:"center",gap:eg?6:8,width:"100%",padding:em,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:eg?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))]}),eZ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eG.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eG.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eZ.map(e=>(0,n.jsxs)("button",{onClick:()=>{ee(!1),tt(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:eg?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))]})]})]}),b&&(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(er(e=>!e),ee(!1),q(!1),eo(!1),el(!1),ea(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ev,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:eX.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=eX.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=et?"var(--bg-hover)":"none",e.currentTarget.style.color=eX.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eX.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),et&&(0,n.jsxs)("div",{style:{...eg?e9:{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"}),M.map(e=>{let t=eX.includes(e),r=F[e];return(0,n.jsxs)("button",{onClick:()=>{b(t?eX.filter(t=>t!==e):[...eX,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:eg?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)})]})]}),e0&&(0,n.jsxs)("div",{ref:ez,style:{position:"relative",flex:eg?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!eg){let t=e.currentTarget.getBoundingClientRect();Z({top:t.top,left:t.left,width:t.width})}ee(!1),er(!1),eo(!1),el(!1),ea(!1),q(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ev,width:eg?"100%":void 0,maxWidth:eg?"100%":220,overflow:"hidden",background:Y?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?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=Y?"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:e_})]}),Y&&(eg?(0,n.jsxs)("div",{ref:eI,style:{...e9,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:e_})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eU.map((e,t)=>(0,n.jsxs)("div",{children:[eU.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:()=>{q(!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))})]}):G&&($=(P=window.visualViewport?.height??window.innerHeight)-G.top+6,D=Math.max(120,Math.min(G.top-8,.6*P)),(0,n.jsx)("div",{ref:eI,style:{position:"fixed",bottom:$,left:G.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:G.width,maxHeight:D,overflowY:"auto"},children:eU.map((e,t)=>(0,n.jsxs)("div",{children:[eU.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:()=>{q(!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:ey?"none":void 0,flex:eg?"0 0 auto":1,width:eg?0:void 0,height:eg?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:eg?"1 1 100%":"0 0 auto",width:eg?"100%":void 0,display:"flex",alignItems:"center",justifyContent:eg?"space-between":void 0,gap:eg?4:2,marginLeft:eg?0:"auto",marginTop:2*!!eg},children:[ey&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{ee(!1),er(!1),q(!1),eo(!1),el(!1),ea(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:es?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ej,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=es?"var(--bg-hover)":"none",e.currentTarget.style.color=es?"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"})]})}),es&&(0,n.jsxs)("div",{style:{...e9,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:[e0&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),el(!1),eo(!1),er(!1),q(!0)},style:ek,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:e5})]}),(e1||e2)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e1&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),q(!1),eo(!1),er(!1),el(!0)},style:ek,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:e4})]}),e2&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),q(!1),el(!1),er(!1),eo(!0)},style:ek,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:e3})]})]}),!!b&&(0,n.jsxs)("button",{onClick:()=>{ea(!1),q(!1),el(!1),eo(!1),er(!0)},style:ek,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:eX.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eQ})]})]})]})]}),(!ey&&!l||eg&&ei)&&j&&(0,n.jsxs)("div",{ref:eR,style:{position:"relative"},children:[!ey&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(ee(!1),er(!1),q(!1),eo(!1),ea(!1),el(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:eg?3:5,padding:em,height:ev,background:ei?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?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=ei?"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:ef,children:(()=>{let e=y??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),ei&&(0,n.jsx)("div",{style:{...eg?e9:{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:eb},overflow:"hidden"},children:U.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(y??"auto")===e,r=_[e],o="auto"!==e&&w?w[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{el(!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:eg?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ey&&!l||eg&&en)&&e2&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[!ey&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(ee(!1),er(!1),q(!1),el(!1),ea(!1),eo(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:eg?3:5,padding:em,height:ev,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:eg?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?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=en?"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:ef,children:e3})]}),en&&(0,n.jsx)("div",{style:{...eg?e9:{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:A.map(e=>{let t=H[e],r=(g??"full")===t,o="agent"===e&&!1===ed,i=o?"需安装 pi-subagents":O[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(eo(!1),r||v(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:eg?11:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ev,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:eg?8:9,color:"#ef4444",cursor:"pointer",fontSize:eg?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"]}),!ey&&void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{l||I(!z)},disabled:l,title:z?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ev,background:z?"rgba(59,130,246,0.08)":"none",border:z?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:eg?8:9,color:z?"#3b82f6":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:eg?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background=z?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color=z?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=z?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color=z?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:ef,children:z?"Plan":"Code"})]}),void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:eg?28:32,height:eg?28:32,padding:0,background:"none",border:"none",borderRadius:eg?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 ee(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 et({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),b=(0,o.useRef)(null),y=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(y);j.current=y;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=b.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,W=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:b,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}}),p.map(e=>{let t=ee(e.msg),r=x&&W===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=ee(e.msg),i=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 ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function er(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function en(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function eo(...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 el(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:en(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!er(t))return{...e,summary:en(r)};let o=Array.isArray(t.results)?t.results.filter(er):[],i=o[0],l=i?.progressSummary,s=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=eo(i?.finalOutput,i?.output,r);return{...e,mode:eo(t.mode),runId:eo(t.runId),agent:eo(i?.agent,e.agent)??e.agent,task:eo(i?.task,e.task),summary:en(a),model:eo(i?.model),durationMs:ei(l?.durationMs),toolCount:ei(l?.toolCount),tokens:ei(l?.tokens),outputPath:eo(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:eo(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:s,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return er(t)&&Array.isArray(t.results)&&t.results.some(e=>er(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 es({messages:e,runs:t}){let r=(0,o.useMemo)(()=>el(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),s=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(ea,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(ea,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function ea({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)(ed,{run:e},e.id))]})}function ed({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${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)(ec,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:en(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)(eu,{run:e})]})]})}function ec({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 eu({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:o,isNew:i,isStreaming:l=!1,onResume:s,onDismiss:a}){if(i||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),o&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",o.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick: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 eh(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 ex(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 eg(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 ef(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 ev(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let em=["read","bash","grep","find","ls"],eb=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ey(e){return eb.some(t=>e.type.startsWith(t))}function ej({agentPhase:e,startedAt:t}){let[r,i]=(0,o.useState)(0);return(0,o.useEffect)(()=>{if(!t)return void i(0);let e=()=>i(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.args??e.name);return 0===t.length?"Running tool…":1===t.length?`Running ${t[0]}…`:`Running ${t.slice(0,2).join(", ")}${t.length>2?` (+${t.length-2})`:""}…`}return e?.kind==="waiting_model"?"Waiting for model…":"Working…"}(e),"\xa0\xa0",function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);return`${t}m ${String(e%60).padStart(2,"0")}s`}(r)]})})}function ek(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ew({goal:e,planTasks:t,isRunning:r,onExecutePlan:i,onContinuePlanning:l,onEditPlan:s}){let[a,d]=(0,o.useState)(!1),c=(0,o.useCallback)(()=>d(e=>!e),[]),u=e&&"dropped"!==e.status,p=t&&t.length>0;if(!u&&!p)return null;let h=(0,o.useMemo)(()=>!e?.tokenBudget||e.tokenBudget<=0?null:Math.min(100,Math.round(e.tokensUsed/e.tokenBudget*100)),[e?.tokenBudget,e?.tokensUsed]),x=t?.filter(e=>"completed"===e.status).length??0,g=!!t&&x===t.length;return(0,n.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[u&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:p?"1px solid var(--border)":"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(e){switch(e){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(e.status)},children:function(e){switch(e){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,n.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:e.objective}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)("span",{children:function(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m ${String(e%60).padStart(2,"0")}s`;let r=Math.floor(t/60);return`${r}h ${t%60}m`}(e.timeUsedSeconds)}),(0,n.jsxs)("span",{children:[ek(e.tokensUsed),e.tokenBudget?` / ${ek(e.tokenBudget)} tokens`:" tokens"]}),null!=h&&(0,n.jsxs)("span",{children:[h,"%"]})]}),null!=h&&(0,n.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,n.jsx)("div",{style:{height:"100%",borderRadius:999,background:h>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(h,100)}%`,transition:"width 0.3s"}})})]}),p&&(0,n.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,n.jsxs)("div",{onClick:c,role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&c()},"aria-expanded":!a,style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,cursor:"pointer",padding:"6px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"#3b82f6"},children:["Plan \xb7 ",t.length," 步"]}),g&&(0,n.jsxs)("span",{style:{borderRadius:4,padding:"0 6px",fontSize:10,fontWeight:600,background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",x,"/",t.length]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(s||l||i)&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[s&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),s()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"修改计划"}),l&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},disabled:r,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:r?"not-allowed":"pointer",opacity:r?.55:1},children:"继续规划"}),i&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),i()},disabled:r,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:r?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:r?"not-allowed":"pointer"},children:"执行计划"})]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:a?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!a&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,borderRadius:4,padding:"3px 8px",background:"inProgress"===e.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,n.jsx)("div",{style:{marginTop:1},children:function(e){switch(e){case"completed":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,n.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,n.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round",children:(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"1.5s",repeatCount:"indefinite"})})]});default:return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"var(--border)",strokeWidth:"1.5"})})}}(e.status)}),(0,n.jsx)("span",{style:{fontSize:12,lineHeight:1.5,...function(e){switch(e){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(e.status)},children:e.step})]},e.id))})]})]})}function eS(e){let t=e.findIndex(e=>"completed"!==e.status);return t<0?e:e.map((e,r)=>r===t?{...e,status:"completed"}:r===t+1&&"pending"===e.status?{...e,status:"inProgress"}:e)}let eC=["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 eT({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(s||i!==o)if(s&&""===i)a(!1),r(t=>(t+1)%e.length);else{let e=s?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[i,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function ez({status:e}){let t=e?.current??"0.8.67"??"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 eI({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSystemPromptChange:u,onSessionStatsChange:p,onContextUsageChange:h,onToolPresetActive:x,generativeUI:g}){var f;let v,[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)(!1),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useState)(""),[T,W]=(0,o.useState)(!1),D=(0,o.useRef)(!1),{data:N,loading:A,error:H,messages:O,entryIds:F,streamState:U,agentRunning:_,modelNames:K,modelList:V,modelThinkingLevels:J,modelThinkingLevelMaps:Y,toolPreset:q,memoryTools:G,thinkingLevel:Z,retryInfo:X,contextUsage:ee,forkingEntryId:er,isCompacting:en,compactError:eo,displayModel:ei,sessionStats:ea,agentPhase:ed,agentError:ec,isNew:eu,messagesEndRef:eb,scrollContainerRef:ek,lastUserMsgRef:eM,handleSend:eW,handleAbort:eL,handleFork:eR,handleNavigate:eE,handleModelChange:eP,handleCompact:e$,handleSteer:eD,handleFollowUp:eB,handleAbortCompaction:eN,handleToolPresetChange:eA,handleMemoryToolsChange:eH,handleThinkingLevelChange:eO,handleAgentEventRef:eF}=function(e){let{session:t,newSessionCwd:r,planMode:n=!1,onAgentEnd:i,onSessionCreated:l,onSessionForked:s,modelsRefreshKey:a,onBranchDataChange:d,onSystemPromptChange:c}=e,u=null===t&&null!==r,[p,h]=(0,o.useState)(null),[x,g]=(0,o.useState)(!u),[f,v]=(0,o.useState)(null),[m,b]=(0,o.useState)(null),[y,j]=(0,o.useState)([]),[k,w]=(0,o.useState)([]),[S,C]=(0,o.useReducer)(eg,{isStreaming:!1,streamingMessage:null}),[T,z]=(0,o.useState)(!1),[W,D]=(0,o.useState)({}),[N,A]=(0,o.useState)([]),[H,O]=(0,o.useState)({}),[F,U]=(0,o.useState)({}),[_,K]=(0,o.useState)(null),[V,J]=(0,o.useState)("full"),[Y,q]=(0,o.useState)([...M]),[G,Z]=(0,o.useState)("auto"),[X,Q]=(0,o.useState)(null),[ee,et]=(0,o.useState)(null),[er,en]=(0,o.useState)(null),[eo,ei]=(0,o.useState)(null),[el,es]=(0,o.useState)(null),[ea,ed]=(0,o.useState)(null),[ec,eu]=(0,o.useState)(!1),[ep,eb]=(0,o.useState)(null),[ey,ej]=(0,o.useState)(null),[ek,ew]=(0,o.useState)(null),eS=(0,o.useRef)(null),eC=(0,o.useRef)(t?.id??null),eT=(0,o.useRef)(!1),ez=(0,o.useRef)(null),eI=(0,o.useRef)(!1),eM=(0,o.useRef)(null),eW=(0,o.useRef)(!1),eL=(0,o.useRef)(null),eR=(0,o.useRef)(null),eE=(0,o.useRef)(new Map),eP=(0,o.useRef)(new Set),e$=e.setNewSessionModel??K,eD=e.setToolPreset??J,eB=e.setMemoryTools??q,eN=el??p?.context.model??ea??null,eA=u?_:eN,eH=(0,o.useCallback)(()=>n?em:B(V,Y),[Y,n,V]),eO=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
|
|
7
7
|
${t}
|
|
8
8
|
${e.extractedText}`.trim()}return`${r}
|
|
9
9
|
[Text extraction unavailable: ${e.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),eF=(0,o.useCallback)(e=>{let t=ef(e);if(!t)return;let r=eE.current;r.set(t,(r.get(t)??0)+1)},[]),eU=(0,o.useCallback)(e=>{let t=ef(e);if(!t)return!1;let r=eE.current,n=r.get(t)??0;return!(n<=0)&&(1===n?r.delete(t):r.set(t,n-1),!0)},[]),e_=(()=>{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})(),eK=(0,o.useCallback)(async(e,t=!1,r=!1)=>{try{t&&g(!0);let n=r?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}`,o=await fetch(n);if(eC.current&&eC.current!==e)return null;if(404===o.status)return t&&(h(null),b(null),j([]),v(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();h(i),b(i.leafId),j(i.context.messages),w(i.context.entryIds??[]);let l=new Set(i.context.messages.map(ev).filter(e=>!!e));for(let e of new Set(eE.current.keys()))l.has(e)&&eE.current.delete(e);return eP.current=l,es(null),v(null),!i.agentState?.state?.thinkingLevel&&i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&Z(i.context.thinkingLevel),i.agentState??null}catch(e){return v(String(e)),null}finally{t&&g(!1)}},[]),eV=(0,o.useCallback)(async(e,t)=>{try{let r=t?`/api/sessions/${encodeURIComponent(e)}/context?leafId=${encodeURIComponent(t)}`:`/api/sessions/${encodeURIComponent(e)}/context`,n=await fetch(r);if(!n.ok)throw Error(`HTTP ${n.status}`);let o=await n.json();j(o.context.messages),w(o.context.entryIds??[]),eE.current.clear()}catch(e){console.error("Failed to load context:",e)}},[]),eJ=(0,o.useCallback)(async e=>{try{let t=await ex(e,{type:"get_tools"});if(t){let e,r,n,o;eD((r=(e=t.filter(e=>e.active).map(e=>e.name)).filter(e=>!M.includes(e)),n=$(e),o=$(r),""===n?"none":n===$(L)?"default":n===$(R)?"full":n===$(E)?"workbench":n===$(P)?"agent":""===o?"none":o===$(L)?"default":o===$(R)?"full":o===$(E)?"workbench":o===$(P)||e.includes(I)?"agent":"default")),eB(M.filter(e=>t.some(t=>t.active&&t.name===e)))}}catch(e){console.error("Failed to load tools:",e)}},[eB,eD]),eY=(0,o.useCallback)((e,t={})=>{eS.current&&(eS.current.close(),eS.current=null);let r=new EventSource(`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`);eS.current=r,r.onmessage=e=>{try{let t=JSON.parse(e.data);ez.current?.(t)}catch{}},r.onerror=()=>{eS.current===r&&eT.current&&(r.close(),eS.current=null,setTimeout(()=>{eT.current&&eY(e)},1e3))}},[]);(0,o.useEffect)(()=>{eT.current=T},[T]),ez.current=(0,o.useCallback)(e=>{switch(e.type){case"agent_start":ew(null),z(!0),ej({kind:"waiting_model"}),C({type:"start"});break;case"agent_end":eT.current=!1,eS.current?.close(),eS.current=null,z(!1),ej(null),Q(null),C({type:"end"}),eC.current&&(eK(eC.current),fetch(`/api/agent/${encodeURIComponent(eC.current)}`).then(e=>e.json()).then(e=>{!1===e.running&&(z(!1),ej(null),C({type:"end"})),e.state?.contextUsage!==void 0&&et(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&en(e.state.systemPrompt??null),e.state?.isCompacting!==void 0&&eu(e.state.isCompacting)}).catch(()=>{})),i?.();break;case"message_start":case"message_update":{let t=e.message;if(t){let e=eh(t);eP.current.has(ev(e)??"")||C({type:"update",message:e})}ej(null);break}case"message_end":{let t=e.message;if(t){let e=eh(t),r=ev(e),n=!!r&&eP.current.has(r);r&&eP.current.add(r),n||"user"===e.role&&eU(e)||j(t=>[...t,e])}C({type:"reset"}),ej({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName,n=e.args,o="bash"===r&&"string"==typeof n?.command?n.command:void 0;ej(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r,args:o}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;ej(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":Q({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":Q(null);break;case"auto_compaction_start":case"compaction_start":eu(!0),eb(null);break;case"auto_compaction_end":case"compaction_end":eu(!1),e.errorMessage?eb(e.errorMessage):!e.aborted&&eC.current&&eK(eC.current)}},[eU,eK,i]);let eq=(0,o.useCallback)(async(e,n,o,i)=>{if(!e.trim()&&!n?.length&&!o?.length||T)return;let s=eO(o),a=e.trim()?s?`${e}
|