@seqyuan/annovibe 0.8.121 → 0.8.122

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.
Files changed (78) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +15 -15
  3. package/.next/build-manifest.json +2 -2
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/required-server-files.js +1 -1
  6. package/.next/required-server-files.json +1 -1
  7. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  8. package/.next/server/app/_global-error.html +1 -1
  9. package/.next/server/app/_global-error.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  14. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  15. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  17. package/.next/server/app/_not-found.html +1 -1
  18. package/.next/server/app/_not-found.rsc +1 -1
  19. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  20. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  21. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  22. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  23. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  24. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  25. package/.next/server/app/api/agent/runtime/route.js +1 -1
  26. package/.next/server/app/api/internal/runtime/route.js +1 -1
  27. package/.next/server/app/api/version/route.js +1 -1
  28. package/.next/server/app/index.html +1 -1
  29. package/.next/server/app/index.rsc +2 -2
  30. package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  31. package/.next/server/app/index.segments/_full.segment.rsc +2 -2
  32. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  33. package/.next/server/app/index.segments/_index.segment.rsc +1 -1
  34. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  35. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  36. package/.next/server/app/login.html +1 -1
  37. package/.next/server/app/login.rsc +1 -1
  38. package/.next/server/app/login.segments/_full.segment.rsc +1 -1
  39. package/.next/server/app/login.segments/_head.segment.rsc +1 -1
  40. package/.next/server/app/login.segments/_index.segment.rsc +1 -1
  41. package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
  42. package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
  43. package/.next/server/app/login.segments/login.segment.rsc +1 -1
  44. package/.next/server/app/page.js +2 -2
  45. package/.next/server/app/page_client-reference-manifest.js +1 -1
  46. package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
  47. package/.next/server/app/smoke/session-stream/page_client-reference-manifest.js +1 -1
  48. package/.next/server/app/smoke/session-stream.html +1 -1
  49. package/.next/server/app/smoke/session-stream.rsc +2 -2
  50. package/.next/server/app/smoke/session-stream.segments/_full.segment.rsc +2 -2
  51. package/.next/server/app/smoke/session-stream.segments/_head.segment.rsc +1 -1
  52. package/.next/server/app/smoke/session-stream.segments/_index.segment.rsc +1 -1
  53. package/.next/server/app/smoke/session-stream.segments/_tree.segment.rsc +1 -1
  54. package/.next/server/app/smoke/session-stream.segments/smoke/session-stream/__PAGE__.segment.rsc +2 -2
  55. package/.next/server/app/smoke/session-stream.segments/smoke/session-stream.segment.rsc +1 -1
  56. package/.next/server/app/smoke/session-stream.segments/smoke.segment.rsc +1 -1
  57. package/.next/server/app/smoke.html +1 -1
  58. package/.next/server/app/smoke.rsc +1 -1
  59. package/.next/server/app/smoke.segments/_full.segment.rsc +1 -1
  60. package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
  61. package/.next/server/app/smoke.segments/_index.segment.rsc +1 -1
  62. package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
  63. package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
  64. package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
  65. package/.next/server/app-paths-manifest.json +15 -15
  66. package/.next/server/chunks/3041.js +5 -5
  67. package/.next/server/chunks/4584.js +2 -2
  68. package/.next/server/middleware-build-manifest.js +1 -1
  69. package/.next/server/middleware.js +3 -3
  70. package/.next/server/pages/404.html +1 -1
  71. package/.next/server/pages/500.html +1 -1
  72. package/.next/server/server-reference-manifest.json +1 -1
  73. package/.next/static/chunks/5377-1dcfca9d5a1c5694.js +22 -0
  74. package/.next/static/chunks/app/{page-7673f9b48c531a25.js → page-55978c1ddc84af8a.js} +2 -2
  75. package/package.json +1 -1
  76. package/.next/static/chunks/5377-8f8cd2e62855e613.js +0 -22
  77. /package/.next/static/{RGo27ZXaxOnz4AWGjVXXd → ryv7dcOEsJ2E9qSarLzwD}/_buildManifest.js +0 -0
  78. /package/.next/static/{RGo27ZXaxOnz4AWGjVXXd → ryv7dcOEsJ2E9qSarLzwD}/_ssgManifest.js +0 -0
@@ -1,9 +1,9 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{30104:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nj});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,p]=(0,i.useState)(""),[u,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(null),[m,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:u});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,u,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&o()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>p(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:o,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:u===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":u===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===u&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),b&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:b}),w.length>=2&&!f&&!b&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${m?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:o}){let[l,s]=(0,i.useState)(""),[a,c]=(0,i.useState)(null),[p,u]=(0,i.useState)([]),[h,x]=(0,i.useState)([]),[g,f]=(0,i.useState)(""),[v,b]=(0,i.useState)(!1),[y,m]=(0,i.useState)(null),j=(0,i.useCallback)(async e=>{b(!0),m(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),u(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){m(e instanceof Error?e.message:String(e))}finally{b(!1)}},[]);return((0,i.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,i.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&&o(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..."}):y?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:y}):0===p.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):p.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&&o(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";var p=r(16865);let u="annovibe:sidebar:collapsed-projects",h="annovibe:sidebar:collapsed-projects:init-v3";function x(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function g(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 f(e){return new DOMException(e,"TimeoutError")}function v(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}function b(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function y(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function m(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||y(e,t)}let j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function k(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:j[Math.floor(Math.random()*j.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.121":c,r),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick: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 w({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:o,initialSessionId:l,onInitialRestoreDone:s,refreshKey:c,onSessionDeleted:b,selectedCwd:j,onCwdChange:R}){let[M,W]=(0,i.useState)([]),[L,P]=(0,i.useState)({}),[E,$]=(0,i.useState)(()=>new Set),B=(0,i.useRef)(!1),[D,A]=(0,i.useState)(!0),[O,N]=(0,i.useState)(!1),[H,F]=(0,i.useState)(null),[U,_]=(0,i.useState)(null),[K,J]=(0,i.useState)(""),[V,q]=(0,i.useState)(null),[Y,G]=(0,i.useState)(!1),[Z,X]=(0,i.useState)("project"),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(!1),[en,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(()=>new Set),[es,ea]=(0,i.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}})()),[ed,ec]=(0,i.useState)(null),[ep,eu]=(0,i.useState)(null),[eh,ex]=(0,i.useState)(null),[eg,ef]=(0,i.useState)(!1),ev=(0,i.useRef)(null),eb=(0,i.useRef)(!1),ey=(0,i.useRef)(!1),em=(0,i.useRef)(!1),ej=(0,i.useRef)(new Map),ek=(0,i.useCallback)(async(e=!1)=>{try{let t;e&&A(!0);let r=new AbortController;try{t=setTimeout(()=>r.abort(f("Project loading timed out")),6e4);let e=await fetch("/api/projects?sessions=false",{signal:r.signal});if(!e.ok)throw Error(await g("projects",e));let n=await e.json();W(n.projects),F(null)}finally{clearTimeout(t)}}catch(e){F(v(e,"Loading projects timed out. Codex may still be starting; click Refresh to retry."))}finally{e&&A(!1)}},[]),ew=(0,i.useCallback)(async(e,t=!1)=>{if(!e)return;let r=ej.current.get(e);if(r)return r;let n=(async()=>{P(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let r;t&&A(!0);let n=new AbortController;try{r=setTimeout(()=>n.abort(f("Chat loading timed out")),6e4);let t=await fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:n.signal});if(!t.ok)throw Error(await g("sessions",t));let i=await t.json();i.runningSessionIds&&!B.current&&$(new Set(i.runningSessionIds)),P(t=>({...t,[e]:{sessions:i.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(r)}}catch(r){let t=v(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");P(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}}))}finally{t&&A(!1),ej.current.delete(e)}})();return ej.current.set(e,n),n},[]),eS=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eS.current;eS.current=!0,ek(e)},[ek,c]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&J(e.home)}).catch(()=>{})},[]);let eC=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(eb.current){eb.current=!1;return}if(ey.current){ey.current=!1;return}R?.(U)},[U,R]);let eT=(0,i.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return q(n.error??`HTTP ${r.status}`),!1;return ek(!1),!0}catch(e){return q(e instanceof Error?e.message:String(e)),!1}},[ek]),ez=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eI=(0,i.useCallback)(e=>{ey.current=!0,_(e),q(null),ea(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),x(r),r}),R?.(e),ez(e),ew(e,!1)},[ew,R,ez]);(0,i.useEffect)(()=>{if(0!==M.length&&null===U){if(l&&!eC.current){eC.current=!0;let e=Object.values(L).flatMap(e=>e.sessions).find(e=>e.id===l);if(e){_(e.cwd),ez(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(l)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(_(e.info.cwd),ez(e.info.cwd),t(e.info,!0)):s?.()}).catch(()=>s?.());return}let e=M[0]?.cwd;e&&(_(e),ez(e))}},[M,U,l,t,s,L,ez]);let eR=j??U;(0,i.useEffect)(()=>(0,p.O)(e=>{B.current=!0,$(new Set(e))}),[]),(0,i.useEffect)(()=>{if(!eR)return;let e=window.setInterval(()=>{ew(eR,!1)},3e4);return()=>window.clearInterval(e)},[eR,ew]),(0,i.useEffect)(()=>{let e=()=>{eR&&ew(eR,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eR,ew]);let eM=(0,i.useCallback)(e=>{if(!e){X("agent"),G(!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,i.useCallback)(e=>{if(!e){X("workbench"),G(!0);return}o?.(e)},[o]),eL=(0,i.useCallback)(async e=>{await eT(e,!0)&&(eI(e),G(!1),q(null),"agent"===Z&&eM(e),"workbench"===Z&&eW(e))},[eI,eM,eW,Z,eT]),eP=(0,i.useCallback)(e=>{ee(e),er(!0)},[]),eE=(0,i.useCallback)(()=>{er(!1),ee(null)},[]),e$=(0,i.useCallback)(e=>{let t=Q??eR;eE(),"agent"===e?eM(t):eW(t)},[eE,eM,eW,eR,Q]),eB=(0,i.useCallback)(()=>{eP(eR)},[eR,eP]),eD=(0,i.useCallback)(()=>{X("project"),q(null),G(!0)},[]),eA=(0,i.useMemo)(()=>[...eR&&!M.some(e=>e.cwd===eR)?[{cwd:eR,displayName:m(eR,K),chatCount:L[eR]?.sessions.length??0,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,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[eR,K,M,L]),eO=(0,i.useMemo)(()=>{let e=e=>{let t=L[e.cwd],r=[...t?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:e,cwd:e.cwd,displayName:e.displayName||m(e.cwd,K),sessions:r,sessionsState:t,lastAccessed:(e.lastAccessed??e.created??"")||r[0]?.modified||""}},t=eA.filter(e=>!0===e.pinned).map(e);if(eR){let r=eA.find(e=>e.cwd===eR);r&&!0!==r.pinned&&t.push(e(r))}return t},[eR,K,L,eA]);(0,i.useEffect)(()=>{if(0===eO.length||em.current||(em.current=!0,!eO[0]?.cwd||window.localStorage.getItem(h)))return;let e=new Set(eO.slice(1).map(e=>e.cwd));ea(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(x(e),e):t),window.localStorage.setItem(h,"1")},[eO]);let eN=(0,i.useCallback)((e,r=!1)=>{e.cwd!==eR&&(eb.current=!0,_(e.cwd)),ea(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),x(r),r}),ez(e.cwd),t(e,r)},[t,eR,ez]),eH=(0,i.useCallback)(e=>{ea(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),x(r),r})},[]);(0,i.useEffect)(()=>{for(let e of eO){let t=L[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eR,r=es.has(e.cwd);if(!t&&r)continue;ew(e.cwd,!1)}}},[es,eR,ew,eO,L]);let eF=(0,i.useCallback)(e=>{el(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eU=(0,i.useCallback)(async e=>{ex("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??[]),F(null)}catch(e){F(e instanceof Error?e.message:String(e)),ek(!1)}finally{ex(null)}},[ek]),e_=(0,i.useCallback)(async(e,t)=>{ex(`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??[]),F(null)}catch(e){F(e instanceof Error?e.message:String(e)),ek(!1)}finally{ex(null)}},[ek]),eK=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eA.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),eU(o)},[eU,eA]),eJ=(0,i.useCallback)(async()=>{N(!0);try{await ek(!1);let e=new Set([...Object.entries(L).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eR?[eR]:[]]);await Promise.all([...e].map(e=>ew(e,!1)))}finally{N(!1)}},[eR,ek,ew,L]);return(0,i.useEffect)(()=>{if(!eg)return;let e=e=>{ev.current&&!ev.current.contains(e.target)&&ef(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[eg]),(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)(k,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eB,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:eR?`New chat in ${eR}`:"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:()=>ei(!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:en,cwd:eR,homeDir:K,onClose:()=>ei(!1),onSelectSession:e=>{eN(e)}}),(0,n.jsxs)("div",{ref:ev,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>ef(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eR?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eR?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eR??"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:eR?"var(--text)":"var(--text-dim)"},children:eR?eA.find(e=>e.cwd===eR)?.displayName??y(eR,K):"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:eg?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eR&&(0,n.jsx)(C,{pinned:eA.find(e=>e.cwd===eR)?.pinned===!0,onToggle:()=>void e_(eR,eA.find(e=>e.cwd===eR)?.pinned!==!0)}),eg&&(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===eA.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eA.map(e=>{let t=e.cwd===eR;return(0,n.jsx)(T,{project:e,homeDir:K,isCurrent:t,onSelect:()=>{eI(e.cwd),ef(!1)},onTogglePinned:()=>void e_(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{ef(!1),eD()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eA.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:eJ,disabled:O,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:O?"var(--accent)":"var(--text-dim)",cursor:O?"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:O?"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:eD,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"]})]})]}),V&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:V})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[D&&0===M.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),H&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:H}),!D&&!H&&0===eO.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!D&&!H&&eO.map(t=>{let r,i=es.has(t.cwd),o=t.cwd===eR,l=eo.has(t.cwd),s=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),a=s.length,d=s;if(a>10&&!l){d=s.slice(0,10);let t=s.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let c=a-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:ep===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ep===t.cwd),opacity:ed===t.cwd?.55:1},onDragOver:e=>{ed&&ed!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eu(t.cwd))},onDragLeave:()=>{ep===t.cwd&&eu(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||ed;eu(null),ec(null),r&&eK(r,t.cwd)},children:[(0,n.jsx)(z,{group:t,isCurrent:o,isCollapsed:i,isDragging:ed===t.cwd,pinBusy:eh===`pin:${t.cwd}`,onToggle:()=>eH(t.cwd),onSelect:()=>eI(t.cwd),onTogglePinned:()=>void e_(t.cwd,!0!==t.project.pinned),onDragStart:e=>{ec(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{ec(null),eu(null)}}),!i&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(I,{node:r,selectedSessionId:e,onSelectSession:eN,onRenamed:()=>void ew(t.cwd,!1),onSessionDeleted:e=>{b?.(e),ew(t.cwd,!1)},depth:0,runningSessionIds:E},r.session.id))]})),(l||c>0)&&a>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eF(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:l?"Show less":`Show ${Math.max(0,c)} more`})]})]},t.cwd||"__no_project")})]}),et&&(0,n.jsx)(S,{cwd:Q,onChoose:e$,onClose:eE}),(0,n.jsx)(d,{open:Y,initialPath:eR,onClose:()=>G(!1),onSelect:e=>eL(e)})]})}function S({cwd:e,onChoose:t,onClose:r}){let i=e?m(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function C({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 T({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[s,a]=(0,i.useState)(!1),d=e.displayName||m(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:o,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:s?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!s,pointerEvents:s?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function z({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:p}){let[u,h]=(0,i.useState)(!1),x=e.lastAccessed,g=Math.max(0,e.project.chatCount??e.sessions.length??0),f=!0===e.project.pinned,v=(0,i.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:v,onDragStart:c,onDragEnd:p,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),v())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!u&&g>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[g," ",1===g?"chat":"chats"]}),!u&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:b(x)}),f?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:u?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:u?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:u?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!u,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:u?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function I({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s,runningSessionIds:a}){let[d,c]=(0,i.useState)(!1),p=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)(R,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:s,hasChildren:p,collapsed:d,onToggleCollapse:()=>c(e=>!e),isRunning:a.has(e.session.id)})]}),p&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(I,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s+1,runningSessionIds:a},e.session.id))})]})}function R({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c,isRunning:p=!1}){let[u,h]=(0,i.useState)(!1),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[y,m]=(0,i.useState)(!1),[j,k]=(0,i.useState)(!1),w=(0,i.useRef)(null),S=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),C=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),g(!0),setTimeout(()=>w.current?.select(),0)},[e.name]),T=(0,i.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),o?.()}catch{}},[f,e.id,e.name,o]),z=(0,i.useCallback)(e=>{e.stopPropagation(),m(!0)},[]),I=(0,i.useCallback)(async t=>{t.stopPropagation(),m(!1),k(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{k(!1)}},[e.id,l]),M=(0,i.useCallback)(e=>{e.stopPropagation(),m(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:y||x?void 0:r,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:y||x?"default":"pointer",background:y?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:y?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:j?.5:1,gap:6,overflow:"hidden"},children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",S.slice(0,22),S.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick: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"})]})]}):x?(0,n.jsx)("input",{ref:w,value:f,onChange:e=>v(e.target.value),onBlur:T,onKeyDown:e=>{"Enter"===e.key&&T(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:p?7:5,height:p?7:5,borderRadius:"50%",background:p?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...p?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),W&&(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:W?"var(--accent)":"var(--text)"},title:S,children:S}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:b(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:C,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:z,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var M=r(94456),W=r(14755);let L=new Map,P=["off","default","full","agent"],E={off:"none",default:"default",full:"full",agent:"agent"},$={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},B={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},D=["auto","off","minimal","low","medium","high","xhigh"],A={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},O=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function N({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(i),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:o.color,fontSize:14,flexShrink:0},children:o.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[i.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function H(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function F(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,i=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&i.push(`Page ${e}
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{30104:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>nj});var n=r(95155),i=r(12115),o=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"..."+n+i.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:o,onSelectSession:d}){let[c,p]=(0,i.useState)(""),[u,h]=(0,i.useState)("current"),[x,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(null),[m,j]=(0,i.useState)(!1),k=(0,i.useRef)(null);if((0,i.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,i.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&o()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,o]),(0,i.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,i=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:u});t&&e.set("cwd",t);let i=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();if(o.error)throw Error(o.error);g(o.results??[]),j(o.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(i),n.abort()}},[e,c,u,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&o()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>p(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:o,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:u===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":u===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===u&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),b&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:b}),w.length>=2&&!f&&!b&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),o()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let i=e.toLowerCase().indexOf(r.toLowerCase());return i<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,i),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(i,i+r.length)}),e.slice(i+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${m?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:o}){let[l,s]=(0,i.useState)(""),[a,c]=(0,i.useState)(null),[p,u]=(0,i.useState)([]),[h,x]=(0,i.useState)([]),[g,f]=(0,i.useState)(""),[v,b]=(0,i.useState)(!1),[y,m]=(0,i.useState)(null),j=(0,i.useCallback)(async e=>{b(!0),m(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),u(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){m(e instanceof Error?e.message:String(e))}finally{b(!1)}},[]);return((0,i.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,i.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&&o(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..."}):y?(0,n.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:y}):0===p.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):p.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&&o(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";var p=r(16865);let u="annovibe:sidebar:collapsed-projects",h="annovibe:sidebar:collapsed-projects:init-v3";function x(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function g(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 f(e){return new DOMException(e,"TimeoutError")}function v(e,t){return e instanceof DOMException&&("AbortError"===e.name||"TimeoutError"===e.name)||e instanceof Error&&/aborted without reason|AbortError/i.test(e.message)?t:e instanceof Error?e.message:String(e)}function b(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),i=Math.floor(r/36e5),o=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:i<24?`${i}h ago`:o<7?`${o}d ago`:t.toLocaleDateString()}function y(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",i=r.split(n).filter(Boolean);return i.length<=2?r:"…/"+i.slice(-2).join(n)}function m(e,t){if(!e)return"No Project";let r=e.replace(/[\\/]+$/,""),n=r.includes("/")?"/":"\\";return r.split(n).filter(Boolean).pop()||y(e,t)}let j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function k(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),s=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:j[Math.floor(Math.random()*j.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"v0.8.122":c,r),a=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick: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 w({selectedSessionId:e,onSelectSession:t,onNewSession:r,onNewWorkbench:o,initialSessionId:l,onInitialRestoreDone:s,refreshKey:c,onSessionDeleted:b,selectedCwd:j,onCwdChange:R}){let[M,W]=(0,i.useState)([]),[L,P]=(0,i.useState)({}),[E,$]=(0,i.useState)(()=>new Set),B=(0,i.useRef)(!1),[D,A]=(0,i.useState)(!0),[O,N]=(0,i.useState)(!1),[H,F]=(0,i.useState)(null),[U,_]=(0,i.useState)(null),[K,J]=(0,i.useState)(""),[V,q]=(0,i.useState)(null),[Y,G]=(0,i.useState)(!1),[Z,X]=(0,i.useState)("project"),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(!1),[en,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(()=>new Set),[es,ea]=(0,i.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}})()),[ed,ec]=(0,i.useState)(null),[ep,eu]=(0,i.useState)(null),[eh,ex]=(0,i.useState)(null),[eg,ef]=(0,i.useState)(!1),ev=(0,i.useRef)(null),eb=(0,i.useRef)(!1),ey=(0,i.useRef)(!1),em=(0,i.useRef)(!1),ej=(0,i.useRef)(new Map),ek=(0,i.useCallback)(async(e=!1)=>{try{let t;e&&A(!0);let r=new AbortController;try{t=setTimeout(()=>r.abort(f("Project loading timed out")),6e4);let e=await fetch("/api/projects?sessions=false",{signal:r.signal});if(!e.ok)throw Error(await g("projects",e));let n=await e.json();W(n.projects),F(null)}finally{clearTimeout(t)}}catch(e){F(v(e,"Loading projects timed out. Codex may still be starting; click Refresh to retry."))}finally{e&&A(!1)}},[]),ew=(0,i.useCallback)(async(e,t=!1)=>{if(!e)return;let r=ej.current.get(e);if(r)return r;let n=(async()=>{P(t=>({...t,[e]:{sessions:t[e]?.sessions??[],loaded:t[e]?.loaded??!1,error:null,loading:!0,stale:t[e]?.stale??!1}}));try{let r;t&&A(!0);let n=new AbortController;try{r=setTimeout(()=>n.abort(f("Chat loading timed out")),6e4);let t=await fetch(`/api/sessions?cwd=${encodeURIComponent(e)}`,{signal:n.signal});if(!t.ok)throw Error(await g("sessions",t));let i=await t.json();i.runningSessionIds&&!B.current&&$(new Set(i.runningSessionIds)),P(t=>({...t,[e]:{sessions:i.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(r)}}catch(r){let t=v(r,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");P(r=>({...r,[e]:{sessions:r[e]?.sessions??[],loaded:r[e]?.loaded??!1,loading:!1,error:t,stale:(r[e]?.sessions?.length??0)>0}}))}finally{t&&A(!1),ej.current.delete(e)}})();return ej.current.set(e,n),n},[]),eS=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eS.current;eS.current=!0,ek(e)},[ek,c]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&J(e.home)}).catch(()=>{})},[]);let eC=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(eb.current){eb.current=!1;return}if(ey.current){ey.current=!1;return}R?.(U)},[U,R]);let eT=(0,i.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return q(n.error??`HTTP ${r.status}`),!1;return ek(!1),!0}catch(e){return q(e instanceof Error?e.message:String(e)),!1}},[ek]),ez=(0,i.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),eI=(0,i.useCallback)(e=>{ey.current=!0,_(e),q(null),ea(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),x(r),r}),R?.(e),ez(e),ew(e,!1)},[ew,R,ez]);(0,i.useEffect)(()=>{if(0!==M.length&&null===U){if(l&&!eC.current){eC.current=!0;let e=Object.values(L).flatMap(e=>e.sessions).find(e=>e.id===l);if(e){_(e.cwd),ez(e.cwd),t(e,!0);return}fetch(`/api/sessions/${encodeURIComponent(l)}?infoOnly=1`).then(e=>e.ok?e.json():null).then(e=>{e?.info?(_(e.info.cwd),ez(e.info.cwd),t(e.info,!0)):s?.()}).catch(()=>s?.());return}let e=M[0]?.cwd;e&&(_(e),ez(e))}},[M,U,l,t,s,L,ez]);let eR=j??U;(0,i.useEffect)(()=>(0,p.O)(e=>{B.current=!0,$(new Set(e))}),[]),(0,i.useEffect)(()=>{if(!eR)return;let e=window.setInterval(()=>{ew(eR,!1)},3e4);return()=>window.clearInterval(e)},[eR,ew]),(0,i.useEffect)(()=>{let e=()=>{eR&&ew(eR,!1)};return window.addEventListener("session-created",e),()=>window.removeEventListener("session-created",e)},[eR,ew]);let eM=(0,i.useCallback)(e=>{if(!e){X("agent"),G(!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,i.useCallback)(e=>{if(!e){X("workbench"),G(!0);return}o?.(e)},[o]),eL=(0,i.useCallback)(async e=>{await eT(e,!0)&&(eI(e),G(!1),q(null),"agent"===Z&&eM(e),"workbench"===Z&&eW(e))},[eI,eM,eW,Z,eT]),eP=(0,i.useCallback)(e=>{ee(e),er(!0)},[]),eE=(0,i.useCallback)(()=>{er(!1),ee(null)},[]),e$=(0,i.useCallback)(e=>{let t=Q??eR;eE(),"agent"===e?eM(t):eW(t)},[eE,eM,eW,eR,Q]),eB=(0,i.useCallback)(()=>{eP(eR)},[eR,eP]),eD=(0,i.useCallback)(()=>{X("project"),q(null),G(!0)},[]),eA=(0,i.useMemo)(()=>[...eR&&!M.some(e=>e.cwd===eR)?[{cwd:eR,displayName:m(eR,K),chatCount:L[eR]?.sessions.length??0,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,i="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==i?n-i:(e.displayName||"").localeCompare(t.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[eR,K,M,L]),eO=(0,i.useMemo)(()=>{let e=e=>{let t=L[e.cwd],r=[...t?.sessions??[]].sort((e,t)=>(t.modified||"").localeCompare(e.modified||""));return{project:e,cwd:e.cwd,displayName:e.displayName||m(e.cwd,K),sessions:r,sessionsState:t,lastAccessed:(e.lastAccessed??e.created??"")||r[0]?.modified||""}},t=eA.filter(e=>!0===e.pinned).map(e);if(eR){let r=eA.find(e=>e.cwd===eR);r&&!0!==r.pinned&&t.push(e(r))}return t},[eR,K,L,eA]);(0,i.useEffect)(()=>{if(0===eO.length||em.current||(em.current=!0,!eO[0]?.cwd||window.localStorage.getItem(h)))return;let e=new Set(eO.slice(1).map(e=>e.cwd));ea(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(x(e),e):t),window.localStorage.setItem(h,"1")},[eO]);let eN=(0,i.useCallback)((e,r=!1)=>{e.cwd!==eR&&(eb.current=!0,_(e.cwd)),ea(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),x(r),r}),ez(e.cwd),t(e,r)},[t,eR,ez]),eH=(0,i.useCallback)(e=>{ea(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),x(r),r})},[]);(0,i.useEffect)(()=>{for(let e of eO){let t=L[e.cwd];if(!t?.loaded&&!t?.loading){let t=e.cwd===eR,r=es.has(e.cwd);if(!t&&r)continue;ew(e.cwd,!1)}}},[es,eR,ew,eO,L]);let eF=(0,i.useCallback)(e=>{el(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eU=(0,i.useCallback)(async e=>{ex("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??[]),F(null)}catch(e){F(e instanceof Error?e.message:String(e)),ek(!1)}finally{ex(null)}},[ek]),e_=(0,i.useCallback)(async(e,t)=>{ex(`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??[]),F(null)}catch(e){F(e instanceof Error?e.message:String(e)),ek(!1)}finally{ex(null)}},[ek]),eK=(0,i.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=eA.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),i=r.indexOf(t);if(-1===n||-1===i)return;let o=[...r];o.splice(n,1);let l=o.indexOf(t);o.splice(l,0,e),eU(o)},[eU,eA]),eJ=(0,i.useCallback)(async()=>{N(!0);try{await ek(!1);let e=new Set([...Object.entries(L).filter(([,e])=>e.loaded||e.loading).map(([e])=>e),...eR?[eR]:[]]);await Promise.all([...e].map(e=>ew(e,!1)))}finally{N(!1)}},[eR,ek,ew,L]);return(0,i.useEffect)(()=>{if(!eg)return;let e=e=>{ev.current&&!ev.current.contains(e.target)&&ef(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[eg]),(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)(k,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:eB,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:eR?`New chat in ${eR}`:"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:()=>ei(!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:en,cwd:eR,homeDir:K,onClose:()=>ei(!1),onSelectSession:e=>{eN(e)}}),(0,n.jsxs)("div",{ref:ev,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>ef(e=>!e),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:eR?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:eR?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:eR??"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:eR?"var(--text)":"var(--text-dim)"},children:eR?eA.find(e=>e.cwd===eR)?.displayName??y(eR,K):"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:eg?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),eR&&(0,n.jsx)(C,{pinned:eA.find(e=>e.cwd===eR)?.pinned===!0,onToggle:()=>void e_(eR,eA.find(e=>e.cwd===eR)?.pinned!==!0)}),eg&&(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===eA.length&&(0,n.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),eA.map(e=>{let t=e.cwd===eR;return(0,n.jsx)(T,{project:e,homeDir:K,isCurrent:t,onSelect:()=>{eI(e.cwd),ef(!1)},onTogglePinned:()=>void e_(e.cwd,!0!==e.pinned)},e.cwd)}),(0,n.jsxs)("button",{type:"button",onClick:()=>{ef(!1),eD()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:eA.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:eJ,disabled:O,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:O?"var(--accent)":"var(--text-dim)",cursor:O?"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:O?"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:eD,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"]})]})]}),V&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:V})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[D&&0===M.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),H&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:H}),!D&&!H&&0===eO.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!D&&!H&&eO.map(t=>{let r,i=es.has(t.cwd),o=t.cwd===eR,l=eo.has(t.cwd),s=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>(t.session.modified||"").localeCompare(e.session.modified||"")),e.forEach(e=>i(e.children))};return i(n),n}(t.sessions),a=s.length,d=s;if(a>10&&!l){d=s.slice(0,10);let t=s.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!d.includes(t)&&(d=[...d,t])}let c=a-d.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:ep===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ep===t.cwd),opacity:ed===t.cwd?.55:1},onDragOver:e=>{ed&&ed!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",eu(t.cwd))},onDragLeave:()=>{ep===t.cwd&&eu(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||ed;eu(null),ec(null),r&&eK(r,t.cwd)},children:[(0,n.jsx)(z,{group:t,isCurrent:o,isCollapsed:i,isDragging:ed===t.cwd,pinBusy:eh===`pin:${t.cwd}`,onToggle:()=>eH(t.cwd),onSelect:()=>eI(t.cwd),onTogglePinned:()=>void e_(t.cwd,!0!==t.project.pinned),onDragStart:e=>{ec(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{ec(null),eu(null)}}),!i&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(r=t.sessionsState,r?.loading&&!r?.loaded?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):r?.error&&!r?.stale?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:r.error}):0===t.sessions.length?(0,n.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,n.jsxs)(n.Fragment,{children:[r?.stale&&(0,n.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),d.map(r=>(0,n.jsx)(I,{node:r,selectedSessionId:e,onSelectSession:eN,onRenamed:()=>void ew(t.cwd,!1),onSessionDeleted:e=>{b?.(e),ew(t.cwd,!1)},depth:0,runningSessionIds:E},r.session.id))]})),(l||c>0)&&a>10&&(0,n.jsx)("button",{type:"button",onClick:()=>eF(t.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:l?"Show less":`Show ${Math.max(0,c)} more`})]})]},t.cwd||"__no_project")})]}),et&&(0,n.jsx)(S,{cwd:Q,onChoose:e$,onClose:eE}),(0,n.jsx)(d,{open:Y,initialPath:eR,onClose:()=>G(!1),onSelect:e=>eL(e)})]})}function S({cwd:e,onChoose:t,onClose:r}){let i=e?m(e):"Choose a project path next";return(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,n.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,n.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,n.jsx)("div",{title:e??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),e&&(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,n.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>t("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function C({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 T({project:e,homeDir:t,isCurrent:r,onSelect:o,onTogglePinned:l}){let[s,a]=(0,i.useState)(!1),d=e.displayName||m(e.cwd,t);return(0,n.jsxs)("div",{onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{display:"flex",alignItems:"center",gap:4,background:r?"var(--bg-selected)":s?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,n.jsxs)("button",{type:"button",onClick:o,title:e.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),!e.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},title:"Pin to sidebar",tabIndex:s?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!s,pointerEvents:s?"auto":"none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function z({group:e,isCurrent:t,isCollapsed:r,isDragging:o,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onDragStart:c,onDragEnd:p}){let[u,h]=(0,i.useState)(!1),x=e.lastAccessed,g=Math.max(0,e.project.chatCount??e.sessions.length??0),f=!0===e.project.pinned,v=(0,i.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:v,onDragStart:c,onDragEnd:p,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),v())},onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),title:e.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:o?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:o?.55:1},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:t?"var(--accent)":"var(--text-dim)"},children:r?(0,n.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,n.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:t?650:560,color:"var(--text)"},children:e.displayName}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!u&&g>0&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[g," ",1===g?"chat":"chats"]}),!u&&x&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:b(x)}),f?(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},title:"Unpin project",tabIndex:u?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:u?1:.85,transition:"opacity 0.12s"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:"Pin project to sidebar",tabIndex:u?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:+!!u,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="#ca8a04"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,n.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:u?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,n.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,n.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function I({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s,runningSessionIds:a}){let[d,c]=(0,i.useState)(!1),p=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)(R,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:o,onDeleted:e=>l?.(e),depth:s,hasChildren:p,collapsed:d,onToggleCollapse:()=>c(e=>!e),isRunning:a.has(e.session.id)})]}),p&&!d&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(I,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:o,onSessionDeleted:l,depth:s+1,runningSessionIds:a},e.session.id))})]})}function R({session:e,isSelected:t,onClick:r,onRenamed:o,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c,isRunning:p=!1}){let[u,h]=(0,i.useState)(!1),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(""),[y,m]=(0,i.useState)(!1),[j,k]=(0,i.useState)(!1),w=(0,i.useRef)(null),S=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),C=(0,i.useCallback)(t=>{t.stopPropagation(),v(e.name??""),g(!0),setTimeout(()=>w.current?.select(),0)},[e.name]),T=(0,i.useCallback)(async()=>{let t=f.trim();if(g(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),o?.()}catch{}},[f,e.id,e.name,o]),z=(0,i.useCallback)(e=>{e.stopPropagation(),m(!0)},[]),I=(0,i.useCallback)(async t=>{t.stopPropagation(),m(!1),k(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{k(!1)}},[e.id,l]),M=(0,i.useCallback)(e=>{e.stopPropagation(),m(!1)},[]),W="workbench"===e.sessionKind;return(0,n.jsx)("div",{onClick:y||x?void 0:r,onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:s>0?12*s+14:14,paddingRight:8,cursor:y||x?"default":"pointer",background:y?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:y?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:j?.5:1,gap:6,overflow:"hidden"},children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",S.slice(0,22),S.length>22?"…":"","”"]}),"?"]}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick: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"})]})]}):x?(0,n.jsx)("input",{ref:w,value:f,onChange:e=>v(e.target.value),onBlur:T,onKeyDown:e=>{"Enter"===e.key&&T(),"Escape"===e.key&&g(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:p?7:5,height:p?7:5,borderRadius:"50%",background:p?"#22c55e":t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0,...p?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),W&&(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:W?"var(--accent)":"var(--text)"},title:S,children:S}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{title:e.modified,children:b(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:C,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)",e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:z,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)",e.currentTarget.style.color="#ef4444",e.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.borderColor="var(--border)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var M=r(94456),W=r(14755);let L=new Map,P=["off","default","full","agent"],E={off:"none",default:"default",full:"full",agent:"agent"},$={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},B={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},D=["auto","off","minimal","low","medium","high","xhigh"],A={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},O=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function N({doc:e,onRemove:t}){var r;let i=e.fileName.split(".").pop()?.toLowerCase()??"",o=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(i),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:o.color,fontSize:14,flexShrink:0},children:o.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[i.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function H(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function F(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,i=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&i.push(`Page ${e}
2
2
  ${r}`)}return i.join("\n\n")}async function U(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),i=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],o=[];for(let e of i){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];o.push(...r.map(e=>H(e[1])))}return o.join("").replace(/[ \t]+\n/g,"\n")}async function _(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],i=t.utils.sheet_to_csv(r);return`Sheet: ${e}
3
3
  ${i}`}).join("\n\n")}async function K(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),i=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),o=[];for(let{name:e,match:t}of i){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>H(e[1]).trim()).filter(Boolean);r.length&&o.push(`Slide ${t[1]}
4
4
  ${r.join("\n")}`)}return o.join("\n\n")}async function J(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,i="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))i=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)i=await F(t);else if("docx"===r)i=await U(t);else if("xlsx"===r)i=await _(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};i=await K(t)}let{text:o,truncated:l}=(n=i.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
5
5
 
6
- [truncated after 60000 characters]`,truncated:!0};if(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let V=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:p,onAbortCompaction:u,isCompacting:h,compactError:x,toolPreset:g,sessionKind:f,onToolPresetChange:v,memoryTools:b,onMemoryToolsChange:y,thinkingLevel:m,onThinkingLevelChange:j,availableThinkingLevels:k,thinkingLevelMap:w,retryInfo:S,soundEnabled:C,onSoundToggle:T,planMode:z,onPlanModeChange:I,cornerBadge:R,promptHistory:M,sessionHistoryKey:H,activeFilePath:F,onDismissFileContext:U},_){let K,V,q,[Y,G]=(0,i.useState)(""),[Z,X]=(0,i.useState)(!1),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(!1),[en,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(!1),[es,ea]=(0,i.useState)(!1),[ed,ec]=(0,i.useState)(!1),[ep,eu]=(0,i.useState)(null),[eh,ex]=(0,i.useState)([]),[eg,ef]=(0,i.useState)([]),ev=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),eb=ev?{display:"none"}:void 0,ey=ev?28:32,em=ev?"6px 8px":"8px 12px",ej=ev?160:180,ek=ev&&!l,ew=ed?"var(--text)":"var(--text-muted)",eS={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},eC=ev?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[eT,ez]=(0,i.useState)(null),eI=(0,i.useRef)(null),eR=(0,i.useRef)(null),eM=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(null),eP=(0,i.useRef)(null),eE=(0,i.useRef)(null),e$=(0,i.useRef)(null),eB=(0,i.useRef)(null),eD=(0,i.useRef)(null),eA=(0,i.useCallback)(e=>{let t=eI.current;if(!t)return void G(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";G(i+l+e+o),requestAnimationFrame(()=>{let t=eI.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,i.useImperativeHandle)(_,()=>({insertIfEmpty(e){let t=eI.current;(t?t.value:Y).trim()||(G(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eA(e)},addImages(e){eO(e)},addFiles(e){eN(e)}}));let eO=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ex(e=>[...e,...r])},[]),eN=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eO(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,i=await J(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));ef(t=>[...t,...e])}},[eO]),eH=(0,i.useCallback)(e=>{ex(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eF=(0,i.useCallback)(e=>{ef(t=>{let r=[...t];return r.splice(e,1),r})},[]),eU=(0,i.useCallback)(()=>{ex(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ef([])},[]),e_=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})),eK=[];for(let e of e_){let t=eK.find(t=>t.provider===e.provider);t?t.options.push(e):eK.push({provider:e.provider,options:[e]})}let eJ=s?e_.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:e_.length>0?e_[0].name:null,eV=s?e_.find(e=>e.modelId===s.modelId&&e.provider===s.provider):e_[0],eq=eV?.input?.includes("image")??!0,eY=eh.length>0&&eV?.input!==void 0&&!eq,eG=(!!Y.trim()||eh.length>0||eg.length>0)&&!eY,eZ=p?O:O.filter(e=>"/compact"!==e.command),eX=eZ.filter(e=>"native"===e.kind),eQ=eZ.filter(e=>"shortcut"===e.kind),e0=b??[],e1=e0.length>0?`${e0.length} enabled`:"off",e2=e_.length>0&&!!eJ&&!!c,e5=!!j,e4=!!v&&"workbench"!==f,e3=!!y,e8=eJ??"Default",e6=(()=>{let e=m??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e7=(g??"full")==="workbench"?"workbench":Object.entries(E).find(([,e])=>e===(g??"full"))?.[0]??"full",e9=ev?26:32,te=ev?7:9,tt=ev?3:6,tr={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},tn=ev&&(Z||et||en||eo||es||ed);(0,i.useEffect)(()=>{eY||ez(null)},[eY]);let ti=(0,i.useCallback)(e=>{if(!Y.trim()){G(e),requestAnimationFrame(()=>{let t=eI.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eA(e)},[eA,Y]),to=(0,i.useCallback)(()=>{let t=Y.trim();if(t||eh.length||eg.length){if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!eh.length&&!eg.length&&p){h?u?.():p(),G(""),eI.current&&(eI.current.style.height="auto");return}e(t,eh.length?eh:void 0,eg.length?eg:void 0),G(""),eU(),eI.current&&(eI.current.style.height="auto")}}},[Y,eh,eg,eq,l,e,eU,p,u,h]),tl=(0,i.useCallback)(e=>{let t=Y.trim();if(!t&&!eh.length&&!eg.length)return;if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eh.length?eh:void 0,i=eg.length?eg:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),G(""),eU(),eI.current&&(eI.current.style.height="auto")},[Y,eh,eg,eq,r,o,eU]),ts=M??[],ta=H??null,td=(0,i.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&ts.length>0){let t=eI.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let i=((n=L.get(e))||(n={cursor:-1,draftSnapshot:""},L.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(ta,t.value,ts);null!==n&&(G(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=L.get(e);return(t?.cursor??-1)>=0}(ta)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=L.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}}(ta,ts);t&&(G(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eI.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ta&&L.set(ta,{cursor:-1,draftSnapshot:""}),l&&(r||o)?tl(r?"steer":"followup"):to())},[l,r,o,tl,to,ts,ta]),tc=(0,i.useCallback)(()=>{let e=eI.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tp=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eN(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eN]);return(0,i.useEffect)(()=>{if(!Z&&!et&&!en&&!eo&&!es&&!ed)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eR.current?.contains(t),n=!!eM.current?.contains(t);r||n||X(!1),eW.current?.contains(t)||er(!1),eL.current?.contains(t)||ei(!1),eP.current?.contains(t)||el(!1),eE.current?.contains(t)||ea(!1),e$.current?.contains(t)||ec(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[Z,et,en,eo,es,ed]),(0,i.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||eu(!!t?.ready)}).catch(()=>{e||eu(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:eC,children:[tn&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{X(!1),er(!1),ei(!1),el(!1),ea(!1),ec(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eB,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eO(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eD,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{eN(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:ev?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ev?"0 8px":void 0,boxSizing:"border-box"},children:[R&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:R}),S&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ev?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",S.attempt,"/",S.maxAttempts,")…",S.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",S.errorMessage]})]}),F&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:ev?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:F.replace(/^.*[\\/]/,"")}),U&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),U()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(eh.length>0||eg.length>0)&&(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[eh.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${eY?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eH(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),eg.map((e,t)=>(0,n.jsx)(N,{doc:e,onRemove:()=>eF(t)},`doc-${t}`))]}),(eY||eT)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ev?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,n.jsx)("span",{children:eT??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:ev?4:8,alignItems:ev?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ev?13:14,padding:ev?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:eI,value:Y,onChange:e=>G(e.target.value),onKeyDown:td,onInput:tc,onPaste:tp,placeholder:l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ev?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!ev,paddingBottom:+!!ev}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ev?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tl("steer"),disabled:!eG,title:eY?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eG?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!ev&&"Steer"]}),o&&(0,n.jsxs)("button",{onClick:()=>tl("followup"),disabled:!eG,title:eY?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eG?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!ev&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:to,disabled:!eG,title:eY?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ev?3:6,padding:ev?"5px 9px":"7px 14px",marginBottom:+!!ev,background:eG?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eG?"#fff":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:ev?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eG?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:ev?13:14,height:ev?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:ev?5:8,display:"flex",alignItems:ev?"flex-start":"center",gap:tt,flexWrap:ev?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ev?"1 1 100%":"0 0 auto",width:ev?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ev,flexWrap:ev?"wrap":"nowrap",rowGap:4*!!ev},children:[(0,n.jsx)("button",{onClick:()=>eB.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:"none",border:"none",borderRadius:te,color:eh.length||eg.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eD.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(er(e=>!e),ei(!1),X(!1),el(!1),ea(!1),ec(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:te,color:x?"#ef4444":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=x?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=et?"var(--bg-hover)":"none",e.currentTarget.style.color=x?"#ef4444":"var(--text-muted)"},children:["/",x&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),et&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:x?"1px solid var(--border)":"none"},children:"Commands"}),x&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:x}),eX.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),eX.map(e=>(0,n.jsxs)("button",{onClick:()=>{(er(!1),"/compact"===e.command&&h)?u?.():ti(e.command)},style:{display:"flex",alignItems:"center",gap:ev?6:8,width:"100%",padding:em,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&h?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&h?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&h?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&h?"中止当前压缩任务":e.description})]})]},e.command))]}),eQ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eX.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eX.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eQ.map(e=>(0,n.jsxs)("button",{onClick:()=>{er(!1),ti(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),y&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ei(e=>!e),er(!1),X(!1),el(!1),ea(!1),ec(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ey,padding:0,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:e0.length>0?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=en?"var(--bg-hover)":"none",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),e0.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),en&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),W.SN.map(e=>{let t=e0.includes(e),r=B[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?e0.filter(t=>t!==e):[...e0,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:r.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:r.description})]})]},e)})]})]}),e2&&(0,n.jsxs)("div",{ref:eR,style:{position:"relative",flex:ev?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!ev){let t=e.currentTarget.getBoundingClientRect();ee({top:t.top,left:t.left,width:t.width})}er(!1),ei(!1),el(!1),ea(!1),ec(!1),X(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ey,width:ev?"100%":void 0,maxWidth:ev?"100%":220,overflow:"hidden",background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=Z?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eJ})]}),Z&&(ev?(0,n.jsxs)("div",{ref:eM,style:{...tr,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:eJ})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{X(!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))})]}):Q&&(V=(K=window.visualViewport?.height??window.innerHeight)-Q.top+6,q=Math.max(120,Math.min(Q.top-8,.6*K)),(0,n.jsx)("div",{ref:eM,style:{position:"fixed",bottom:V,left:Q.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:Q.width,maxHeight:q,overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{X(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]}),ev&&!l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:e$,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),ei(!1),X(!1),el(!1),ea(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),ea(!1),el(!1),ei(!1),X(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),el(!1),ei(!1),ea(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),ei(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),el(!1),ei(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]}),void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),I(!z)},style:{...eS,border:z?"1px solid rgba(59,130,246,0.24)":"none",background:z?"rgba(59,130,246,0.06)":"none"},children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Mode"}),(0,n.jsx)("div",{style:{fontSize:12,color:z?"#3b82f6":"var(--text)",marginTop:2},children:z?"Plan(只读规划)":"Code(可执行)"})]})]})]})]}),(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",borderRadius:8,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ek?"none":void 0,flex:ev?"0 0 auto":1,width:ev?0:void 0,height:ev?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:ev?"auto":void 0,display:"flex",alignItems:"center",gap:ev?4:2,marginLeft:ev?0:"auto",marginTop:0},children:[ek&&!ev&&(0,n.jsxs)("div",{ref:e$,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),ei(!1),X(!1),el(!1),ea(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),ea(!1),el(!1),ei(!1),X(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),el(!1),ei(!1),ea(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),ei(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),el(!1),ei(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]})]})]})]}),(!ek&&!l||ev&&es)&&j&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),ei(!1),X(!1),el(!1),ec(!1),ea(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:em,height:ey,background:es?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=es?"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:eb,children:(()=>{let e=m??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),es&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:ej},overflow:"hidden"},children:D.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(m??"auto")===e,r=A[e],i="auto"!==e&&w?w[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,n.jsxs)("button",{onClick:()=>{ea(!1),t||j(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[o,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ek&&!l||ev&&eo)&&e4&&(0,n.jsxs)("div",{ref:eP,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),ei(!1),X(!1),ea(!1),ec(!1),el(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:em,height:ey,background:eo?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eo?"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:eb,children:e7})]}),eo&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:P.map(e=>{let t=E[e],r=(g??"full")===t,i="agent"===e&&!1===ep,o=i?"需安装 pi-subagents":$[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(el(!1),r||v(t))},disabled:i,title:i?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:i?"not-allowed":"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ey,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ev?8:9,color:"#ef4444",cursor:"pointer",fontSize:ev?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),!ek&&void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{l||I(!z)},disabled:l,title:z?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ey,background:z?"rgba(59,130,246,0.08)":"none",border:z?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:ev?8:9,color:z?"#3b82f6":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background=z?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color=z?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=z?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color=z?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:eb,children:z?"Plan":"Code"})]}),!ev&&void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ev?28:32,height:ev?28:32,padding:0,background:"none",border:"none",borderRadius:ev?8:9,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function q(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function Y({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,s]=(0,i.useState)(0),[a,d]=(0,i.useState)(1),[c,p]=(0,i.useState)(!1),[u,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),b=(0,i.useRef)(!1),y=(0,i.useRef)(null),m=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(m);j.current=m;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;p(i>20),i<=0?(s(0),d(1)):(s(e.scrollTop/i),d(n/t));let l=o.current,a=[],c=0,u=j.current;for(let r=0;r<u.length;r++){let n=u[r];if("user"!==n.role&&"assistant"!==n.role)continue;let i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,i.useCallback)(e=>{if(!c)return;b.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),i=n>=0&&n<=a?n:a/2;S(r-i);let o=e=>{b.current&&S((e.clientY-t.top)/t.height-i)},s=()=>{b.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,i.useMemo)(()=>{if(!x||0===u.length)return[];let e=u.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,u,T]);if(!c)return null;let I=l*(1-a)*100,R=100*a,M=null!==f&&u.length>0?u.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(u[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${R}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),u.map(e=>{let t=q(e.msg),r=x&&M===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:i?8:6,height:i?8:6,borderRadius:i?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&u.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),i=q(e.msg),o=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function G(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Z(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function X(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function Q(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function ee(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:Z(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!G(t))return{...e,summary:Z(r)};let i=Array.isArray(t.results)?t.results.filter(G):[],o=i[0],l=o?.progressSummary,s=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=X(o?.finalOutput,o?.output,r);return{...e,mode:X(t.mode),runId:X(t.runId),agent:X(o?.agent,e.agent)??e.agent,task:X(o?.task,e.task),summary:Z(a),model:X(o?.model),durationMs:Q(l?.durationMs),toolCount:Q(l?.toolCount),tokens:Q(l?.tokens),outputPath:X(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:X(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:s,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return G(t)&&Array.isArray(t.results)&&t.results.some(e=>G(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 et({messages:e,runs:t}){let r=(0,i.useMemo)(()=>ee(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),s=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(er,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(er,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function er({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)(en,{run:e},e.id))]})}function en({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":o?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(ei,{running:o,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:Z(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)(eo,{run:e})]})]})}function ei({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 eo({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 el({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:i,isNew:o,isStreaming:l=!1,onResume:s,onDismiss:a}){if(o||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),i&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",i.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:a,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,n.jsx)("button",{type:"button",onClick:s,disabled:l,title:l?"Wait until the agent finishes before updating Workbench":c?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:l?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:l?.55:1,whiteSpace:"nowrap"},children:c?"Reload Initial Data":"Resume Workbench"})]})}var es=r(5377);let ea=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ed(e){return ea.some(t=>e.type.startsWith(t))}function ec({agentPhase:e,startedAt:t}){let[r,o]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void o(0);let e=()=>o(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.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 ep(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function eu({goal:e,planTasks:t,isRunning:r,onExecutePlan:o,onContinuePlanning:l,onEditPlan:s}){let[a,d]=(0,i.useState)(!1),c=(0,i.useCallback)(()=>d(e=>!e),[]),p=e&&"dropped"!==e.status,u=t&&t.length>0;if(!p&&!u)return null;let h=(0,i.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:[p&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:u?"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:[ep(e.tokensUsed),e.tokenBudget?` / ${ep(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"}})})]}),u&&(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||o)&&(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:"继续规划"}),o&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o()},disabled:r,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:r?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:r?"not-allowed":"pointer"},children:"执行计划"})]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform: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))})]})]})}var eh=r(32383);function ex(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 eg=["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 ef({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(s||o!==i)if(s&&""===o)a(!1),r(t=>(t+1)%e.length);else{let e=s?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[o,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function ev({status:e}){let t=e?.current??"0.8.121"??"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 eb({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSessionStatsChange:p,onContextUsageChange:u,onToolPresetActive:h,generativeUI:x,activeFilePath:g,onOpenFileAtLine:f}){var v;let b,[y,m]=(0,i.useState)(null),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)([]),[C,T]=(0,i.useState)(""),[z,I]=(0,i.useState)(!1),R=(0,i.useRef)(!1),[L,P]=(0,i.useState)(!1),E=g&&!L?g:null;(0,i.useEffect)(()=>{P(!1)},[g]);let $=(0,i.useCallback)(e=>{let t;k(e.enabled),I(e.executing);let r=(t=e.todos.findIndex(e=>!e.completed),e.todos.map((e,r)=>({id:`plan-${e.step||r+1}`,step:e.text,status:e.completed?"completed":r===t?"inProgress":"pending"})));e.enabled||e.executing||r.length>0?S(r):S([])},[]),{data:B,loading:D,error:A,messages:O,entryIds:N,streamState:H,agentRunning:F,modelNames:U,modelList:_,modelThinkingLevels:K,modelThinkingLevelMaps:J,toolPreset:q,memoryTools:G,thinkingLevel:Z,retryInfo:X,contextUsage:Q,forkingEntryId:er,isCompacting:en,compactError:ei,displayModel:eo,sessionStats:ea,agentPhase:ep,agentError:ey,isNew:em,loadMoreMessages:ej,hasMoreMessages:ek,totalMessages:ew,loadedMessagesCount:eS,messagesEndRef:eC,scrollContainerRef:eT,lastUserMsgRef:ez,handleSend:eI,handleAbort:eR,handleFork:eM,handleNavigate:eW,handleModelChange:eL,handleCompact:eP,handleSteer:eE,handleFollowUp:e$,handleAbortCompaction:eB,handleToolPresetChange:eD,handleMemoryToolsChange:eA,handleThinkingLevelChange:eO,handleAgentEventRef:eN}=(0,es.T)({session:e,newSessionCwd:t,planMode:j,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:d,onPlanModeState:$}),{soundEnabled:eH,onSoundToggle:eF,playDoneSound:eU}=function(){let[e,t]=(0,i.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,i.useRef)(e);return(0,i.useEffect)(()=>{r.current=e},[e]),{soundEnabled:e,onSoundToggle:(0,i.useCallback)(()=>{t(e=>{let t=!e;return localStorage.setItem("pi-sound-enabled",String(t)),t})},[]),playDoneSound:(0,i.useCallback)(()=>{if(r.current)try{let e=new AudioContext;"suspended"===e.state&&e.resume().catch(()=>{});let t=e.currentTime;[523.25,659.25].forEach((r,n)=>{let i=e.createOscillator(),o=e.createGain();i.connect(o),o.connect(e.destination),i.type="sine",i.frequency.value=r;let l=t+.18*n;o.gain.setValueAtTime(0,l),o.gain.linearRampToValueAtTime(.18,l+.02),o.gain.exponentialRampToValueAtTime(.001,l+.45),i.start(l),i.stop(l+.45)}),setTimeout(()=>e.close(),1200)}catch{}},[]),soundEnabledRef:r}}(),e_=(0,i.useRef)(eU);e_.current=eU;let eK=(0,i.useRef)(eH);eK.current=eH,(0,i.useEffect)(()=>{F&&!y&&m(Date.now()),F||m(null)},[F,y]);let eJ=eN.current;(0,i.useEffect)(()=>{eN.current=e=>{"agent_start"===e.type&&(m(Date.now()),R.current=!1),"tool_execution_end"===e.type&&z&&(R.current=!0,S(ex)),"agent_end"===e.type&&!0!==e.willRetry&&(m(null),z&&!R.current&&S(ex)),"agent_end"===e.type&&!0!==e.willRetry&&eK.current&&e_.current(),eJ?.(e)}},[eJ,eN,z]);let eV=ea?`${ea.tokens.input}|${ea.tokens.output}|${ea.tokens.cacheRead}|${ea.tokens.cacheWrite}|${ea.cost??0}`:null,eq=(0,i.useRef)(ea);eq.current=ea,(0,i.useEffect)(()=>{p?.(eq.current)},[eV,p]),(0,i.useEffect)(()=>()=>{p?.(null)},[p]),(0,i.useEffect)(()=>(h?.("workbench"===q),()=>{h?.(!1)}),[q,h]);let eY=Q?`${Q.percent??"null"}|${Q.contextWindow}|${Q.tokens??"null"}`:null,eG=(0,i.useRef)(Q);eG.current=Q,(0,i.useEffect)(()=>{u?.(eG.current)},[eY,u]),(0,i.useEffect)(()=>()=>{u?.(null)},[u]);let eZ=(0,i.useCallback)(e=>{a?.current?.addFiles(e)},[a]),eX=(0,i.useCallback)((e,t,r)=>{let n=r?.findIndex(t=>t.src===e)??-1;e6({src:e,gallery:r,index:n>=0?n:0})},[]),{isDragOver:eQ,handleDragEnter:e0,handleDragOver:e1,handleDragLeave:e2,handleDrop:e5}=function(e){let[t,r]=(0,i.useState)(!1),n=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ed)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ed)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}(eZ),[e4,e3]=(0,i.useState)(null),[e8,e6]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!em)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&e3(t)}).catch(()=>{}),()=>{e=!0}},[em]);let e7=O.filter(e=>"user"===e.role||"assistant"===e.role),e9=(v=e7.length,(b=(0,i.useRef)([])).current=Array(v).fill(null).map((e,t)=>b.current[t]??null),b),te=(0,i.useMemo)(()=>{let e=new Map;for(let t of O)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[O]),tt=em&&0===O.length&&!H.isStreaming&&!F,tr=B?.info?.cwd??e?.cwd??t??null,tn=function(e){if(!e)return null;let t=e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(tr),ti=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[to,tl]=(0,i.useState)(!1),[ts,ta]=(0,i.useState)(!1),td=ee(O),tc=td.filter(e=>"running"===e.status).length;(0,i.useEffect)(()=>{0===td.length&&to&&tl(!1)},[td.length,to]),(0,i.useEffect)(()=>{ti&&to&&tl(!1)},[ti,to]),(0,i.useEffect)(()=>{ta(!1)},[e?.id]);let tp=(0,i.useCallback)(()=>{e?.id&&!F&&(async()=>{await eD("workbench");let e=B?.sessionMeta;if(e?.initialSourcePath&&e.initialKernel){let t=`Resume this Workbench session. Reload only the initial data file \`${e.initialSourcePath}\` using the ${e.initialKernel.toUpperCase()} runtime. Do not rerun previous analyses or load extra files unless I ask. Use the chat history only as context for what to do next.`;await eI(t)}})()},[F,B?.sessionMeta,eI,eD,e?.id]),tu=eo?K[`${eo.provider}:${eo.modelId}`]??null:null,th=eo?J[`${eo.provider}:${eo.modelId}`]??null:null,tx=B?.sessionMeta?.sessionKind??null,tg=e?.id??t??"new-chat",tf=(0,i.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let i=n.text.trim();i&&t.push(i)}return t})(e7.map(e=>{let t;return{role:e.role,text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"):""}})),[e7]),tv=(0,i.useCallback)(()=>{let t=!j;k(t);let r=e?.id;if(r){let e=t?["read","bash","grep","find","ls"]:(0,W.tE)(q,G);(0,eh.$)(r,{type:"set_tools",toolNames:e,planMode:t}).catch(()=>{})}t&&I(!1)},[G,j,e?.id,q]),tb=(0,i.useCallback)(async(e,t,r)=>{if("/plan"===e.trim()||e.trim().startsWith("/plan "))return void tv();let n=e;E&&e.trim()&&(n=`${e}
6
+ [truncated after 60000 characters]`,truncated:!0};if(!o)return{extractionError:"No extractable text found"};return{extractedText:o,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let V=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:p,onAbortCompaction:u,isCompacting:h,compactError:x,toolPreset:g,sessionKind:f,onToolPresetChange:v,memoryTools:b,onMemoryToolsChange:y,thinkingLevel:m,onThinkingLevelChange:j,availableThinkingLevels:k,thinkingLevelMap:w,retryInfo:S,soundEnabled:C,onSoundToggle:T,planMode:z,onPlanModeChange:I,cornerBadge:R,promptHistory:M,sessionHistoryKey:H,activeFilePath:F,onDismissFileContext:U},_){let K,V,q,[Y,G]=(0,i.useState)(""),[Z,X]=(0,i.useState)(!1),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(!1),[en,ei]=(0,i.useState)(!1),[eo,el]=(0,i.useState)(!1),[es,ea]=(0,i.useState)(!1),[ed,ec]=(0,i.useState)(!1),[ep,eu]=(0,i.useState)(null),[eh,ex]=(0,i.useState)([]),[eg,ef]=(0,i.useState)([]),ev=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),eb=ev?{display:"none"}:void 0,ey=ev?28:32,em=ev?"6px 8px":"8px 12px",ej=ev?160:180,ek=ev&&!l,ew=ed?"var(--text)":"var(--text-muted)",eS={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},eC=ev?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[eT,ez]=(0,i.useState)(null),eI=(0,i.useRef)(null),eR=(0,i.useRef)(null),eM=(0,i.useRef)(null),eW=(0,i.useRef)(null),eL=(0,i.useRef)(null),eP=(0,i.useRef)(null),eE=(0,i.useRef)(null),e$=(0,i.useRef)(null),eB=(0,i.useRef)(null),eD=(0,i.useRef)(null),eA=(0,i.useCallback)(e=>{let t=eI.current;if(!t)return void G(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=!(i.length>0)||i.endsWith(" ")||i.endsWith("\n")?"":" ";G(i+l+e+o),requestAnimationFrame(()=>{let t=eI.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,i.useImperativeHandle)(_,()=>({insertIfEmpty(e){let t=eI.current;(t?t.value:Y).trim()||(G(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eA(e)},addImages(e){eO(e)},addFiles(e){eN(e)}}));let eO=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));ex(e=>[...e,...r])},[]),eN=(0,i.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eO(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,i=await J(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...i})},n.onerror=r,n.readAsArrayBuffer(e)})));ef(t=>[...t,...e])}},[eO]),eH=(0,i.useCallback)(e=>{ex(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),eF=(0,i.useCallback)(e=>{ef(t=>{let r=[...t];return r.splice(e,1),r})},[]),eU=(0,i.useCallback)(()=>{ex(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ef([])},[]),e_=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})),eK=[];for(let e of e_){let t=eK.find(t=>t.provider===e.provider);t?t.options.push(e):eK.push({provider:e.provider,options:[e]})}let eJ=s?e_.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:e_.length>0?e_[0].name:null,eV=s?e_.find(e=>e.modelId===s.modelId&&e.provider===s.provider):e_[0],eq=eV?.input?.includes("image")??!0,eY=eh.length>0&&eV?.input!==void 0&&!eq,eG=(!!Y.trim()||eh.length>0||eg.length>0)&&!eY,eZ=p?O:O.filter(e=>"/compact"!==e.command),eX=eZ.filter(e=>"native"===e.kind),eQ=eZ.filter(e=>"shortcut"===e.kind),e0=b??[],e1=e0.length>0?`${e0.length} enabled`:"off",e2=e_.length>0&&!!eJ&&!!c,e5=!!j,e4=!!v&&"workbench"!==f,e3=!!y,e8=eJ??"Default",e6=(()=>{let e=m??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})(),e7=(g??"full")==="workbench"?"workbench":Object.entries(E).find(([,e])=>e===(g??"full"))?.[0]??"full",e9=ev?26:32,te=ev?7:9,tt=ev?3:6,tr={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},tn=ev&&(Z||et||en||eo||es||ed);(0,i.useEffect)(()=>{eY||ez(null)},[eY]);let ti=(0,i.useCallback)(e=>{if(!Y.trim()){G(e),requestAnimationFrame(()=>{let t=eI.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eA(e)},[eA,Y]),to=(0,i.useCallback)(()=>{let t=Y.trim();if(t||eh.length||eg.length){if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!eh.length&&!eg.length&&p){h?u?.():p(),G(""),eI.current&&(eI.current.style.height="auto");return}e(t,eh.length?eh:void 0,eg.length?eg:void 0),G(""),eU(),eI.current&&(eI.current.style.height="auto")}}},[Y,eh,eg,eq,l,e,eU,p,u,h]),tl=(0,i.useCallback)(e=>{let t=Y.trim();if(!t&&!eh.length&&!eg.length)return;if(eh.length&&!eq)return void ez("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=eh.length?eh:void 0,i=eg.length?eg:void 0;"steer"===e&&r?r(t,n,i):"followup"===e&&o&&o(t,n,i),G(""),eU(),eI.current&&(eI.current.style.height="auto")},[Y,eh,eg,eq,r,o,eU]),ts=M??[],ta=H??null,td=(0,i.useCallback)(e=>{if("ArrowUp"===e.key&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&ts.length>0){let t=eI.current;if(!t)return;let r=t.selectionStart??0;if(t.value.slice(0,r).includes("\n"))return;e.preventDefault();let n=function(e,t,r){let n;if(!e||0===r.length)return null;let i=((n=L.get(e))||(n={cursor:-1,draftSnapshot:""},L.set(e,n)),n);if(-1===i.cursor)i.draftSnapshot=t,i.cursor=0;else{if(!(i.cursor<r.length-1))return null;i.cursor+=1}return r[i.cursor]??null}(ta,t.value,ts);null!==n&&(G(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=L.get(e);return(t?.cursor??-1)>=0}(ta)){e.preventDefault();let t=function(e,t){if(!e)return null;let r=L.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}}(ta,ts);t&&(G(t.text),t.returnedToPresent&&requestAnimationFrame(()=>{let e=eI.current;e&&e.setSelectionRange(t.text.length,t.text.length)}));return}"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ta&&L.set(ta,{cursor:-1,draftSnapshot:""}),l&&(r||o)?tl(r?"steer":"followup"):to())},[l,r,o,tl,to,ts,ta]),tc=(0,i.useCallback)(()=>{let e=eI.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tp=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eN(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eN]);return(0,i.useEffect)(()=>{if(!Z&&!et&&!en&&!eo&&!es&&!ed)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!eR.current?.contains(t),n=!!eM.current?.contains(t);r||n||X(!1),eW.current?.contains(t)||er(!1),eL.current?.contains(t)||ei(!1),eP.current?.contains(t)||el(!1),eE.current?.contains(t)||ea(!1),e$.current?.contains(t)||ec(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[Z,et,en,eo,es,ed]),(0,i.useEffect)(()=>{if(!v)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||eu(!!t?.ready)}).catch(()=>{e||eu(!1)}),()=>{e=!0}},[v]),(0,n.jsxs)("div",{style:eC,children:[tn&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{X(!1),er(!1),ei(!1),el(!1),ea(!1),ec(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,n.jsx)("input",{ref:eB,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eO(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eD,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:e=>{eN(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:ev?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ev?"0 8px":void 0,boxSizing:"border-box"},children:[R&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:R}),S&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ev?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",S.attempt,"/",S.maxAttempts,")…",S.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",S.errorMessage]})]}),F&&(0,n.jsxs)("div",{style:{marginBottom:ev?6:8,padding:ev?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:ev?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:F.replace(/^.*[\\/]/,"")}),U&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),U()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(eh.length>0||eg.length>0)&&(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[eh.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${eY?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eH(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${t}`)),eg.map((e,t)=>(0,n.jsx)(N,{doc:e,onRemove:()=>eF(t)},`doc-${t}`))]}),(eY||eT)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ev?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,n.jsx)("span",{children:eT??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:ev?4:8,alignItems:ev?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ev?13:14,padding:ev?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)("textarea",{ref:eI,value:Y,onChange:e=>G(e.target.value),onKeyDown:td,onInput:tc,onPaste:tp,placeholder:l&&(r||o)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ev?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!ev,paddingBottom:+!!ev}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ev?4:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>tl("steer"),disabled:!eG,title:eY?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eG?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!ev&&"Steer"]}),o&&(0,n.jsxs)("button",{onClick:()=>tl("followup"),disabled:!eG,title:eY?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!ev,padding:ev?"6px 8px":"7px 12px",background:eG?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eG?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,n.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,n.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!ev&&"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:to,disabled:!eG,title:eY?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ev?3:6,padding:ev?"5px 9px":"7px 14px",marginBottom:+!!ev,background:eG?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eG?"#fff":"var(--text-dim)",cursor:eG?"pointer":"not-allowed",fontSize:ev?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eG?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:ev?13:14,height:ev?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,n.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:ev?5:8,display:"flex",alignItems:ev?"flex-start":"center",gap:tt,flexWrap:ev?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ev?"1 1 100%":"0 0 auto",width:ev?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ev,flexWrap:ev?"wrap":"nowrap",rowGap:4*!!ev},children:[(0,n.jsx)("button",{onClick:()=>eB.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:"none",border:"none",borderRadius:te,color:eh.length||eg.length?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=eh.length||eg.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eD.current?.click()},children:(0,n.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,n.jsxs)("div",{ref:eW,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(er(e=>!e),ei(!1),X(!1),el(!1),ea(!1),ec(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e9,height:e9,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:te,color:x?"#ef4444":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=x?"#ef4444":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=et?"var(--bg-hover)":"none",e.currentTarget.style.color=x?"#ef4444":"var(--text-muted)"},children:["/",x&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),et&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:x?"1px solid var(--border)":"none"},children:"Commands"}),x&&(0,n.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:x}),eX.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),eX.map(e=>(0,n.jsxs)("button",{onClick:()=>{(er(!1),"/compact"===e.command&&h)?u?.():ti(e.command)},style:{display:"flex",alignItems:"center",gap:ev?6:8,width:"100%",padding:em,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===e.command&&h?"#ef4444":"var(--text-dim)"},children:"/compact"===e.command&&h?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===e.command&&h?"停止压缩":e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===e.command&&h?"中止当前压缩任务":e.description})]})]},e.command))]}),eQ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(eX.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:eX.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eQ.map(e=>(0,n.jsxs)("button",{onClick:()=>{er(!1),ti(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:e.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:e.description})]})]},e.command))]})]})]}),y&&(0,n.jsxs)("div",{ref:eL,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(ei(e=>!e),er(!1),X(!1),el(!1),ea(!1),ec(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ey,padding:0,background:en?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:e0.length>0?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",opacity:l?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=en?"var(--bg-hover)":"none",e.currentTarget.style.color=e0.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),e0.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),en&&(0,n.jsxs)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),W.SN.map(e=>{let t=e0.includes(e),r=B[e];return(0,n.jsxs)("button",{onClick:()=>{y(t?e0.filter(t=>t!==e):[...e0,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:em,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:r.label}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:r.description})]})]},e)})]})]}),e2&&(0,n.jsxs)("div",{ref:eR,style:{position:"relative",flex:ev?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!ev){let t=e.currentTarget.getBoundingClientRect();ee({top:t.top,left:t.left,width:t.width})}er(!1),ei(!1),el(!1),ea(!1),ec(!1),X(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ey,width:ev?"100%":void 0,maxWidth:ev?"100%":220,overflow:"hidden",background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=Z?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:eJ})]}),Z&&(ev?(0,n.jsxs)("div",{ref:eM,style:{...tr,display:"flex",flexDirection:"column"},children:[(0,n.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:eJ})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{X(!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))})]}):Q&&(V=(K=window.visualViewport?.height??window.innerHeight)-Q.top+6,q=Math.max(120,Math.min(Q.top-8,.6*K)),(0,n.jsx)("div",{ref:eM,style:{position:"fixed",bottom:V,left:Q.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:Q.width,maxHeight:q,overflowY:"auto"},children:eK.map((e,t)=>(0,n.jsxs)("div",{children:[eK.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===s?.modelId&&e.provider===s?.provider;return(0,n.jsxs)("button",{onClick:()=>{X(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]}),ev&&!l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:e$,style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),ei(!1),X(!1),el(!1),ea(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),ea(!1),el(!1),ei(!1),X(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),el(!1),ei(!1),ea(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),ei(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),el(!1),ei(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]}),void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),I(!z)},style:{...eS,border:z?"1px solid rgba(59,130,246,0.24)":"none",background:z?"rgba(59,130,246,0.06)":"none"},children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Mode"}),(0,n.jsx)("div",{style:{fontSize:12,color:z?"#3b82f6":"var(--text)",marginTop:2},children:z?"Plan(只读规划)":"Code(可执行)"})]})]})]})]}),(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",borderRadius:8,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ek?"none":void 0,flex:ev?"0 0 auto":1,width:ev?0:void 0,height:ev?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:ev?"auto":void 0,display:"flex",alignItems:"center",gap:ev?4:2,marginLeft:ev?0:"auto",marginTop:0},children:[ek&&!ev&&(0,n.jsxs)("div",{ref:e$,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{er(!1),ei(!1),X(!1),el(!1),ea(!1),ec(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:ed?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ew,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=ed?"var(--bg-hover)":"none",e.currentTarget.style.color=ed?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),ed&&(0,n.jsxs)("div",{style:{...tr,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,n.jsxs)("div",{style:{display:"grid",gap:4},children:[e2&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),ea(!1),el(!1),ei(!1),X(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:e8})]}),(e5||e4)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[e5&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),el(!1),ei(!1),ea(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e6})]}),e4&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),ei(!1),el(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:e7})]})]}),e3&&(0,n.jsxs)("button",{onClick:()=>{ec(!1),X(!1),ea(!1),el(!1),ei(!0)},style:eS,children:[(0,n.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,n.jsx)("div",{style:{fontSize:12,color:e0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:e1})]})]})]})]}),(!ek&&!l||ev&&es)&&j&&(0,n.jsxs)("div",{ref:eE,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),ei(!1),X(!1),el(!1),ec(!1),ea(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:em,height:ey,background:es?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=es?"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:eb,children:(()=>{let e=m??"auto";if("auto"===e||!w)return e;let t=w[e];return null!=t?t:e})()})]}),es&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:ej},overflow:"hidden"},children:D.filter(e=>!k||"auto"===e||k.includes(e)).map(e=>{let t=(m??"auto")===e,r=A[e],i="auto"!==e&&w?w[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,n.jsxs)("button",{onClick:()=>{ea(!1),t||j(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[o,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ek&&!l||ev&&eo)&&e4&&(0,n.jsxs)("div",{ref:eP,style:{position:"relative"},children:[!ek&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(er(!1),ei(!1),X(!1),ea(!1),ec(!1),el(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ev?3:5,padding:em,height:ey,background:eo?"var(--bg-hover)":"none",border:"none",borderRadius:ev?8:9,color:(g??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=(g??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=eo?"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:eb,children:e7})]}),eo&&(0,n.jsx)("div",{style:{...ev?tr:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:P.map(e=>{let t=E[e],r=(g??"full")===t,i="agent"===e&&!1===ep,o=i?"需安装 pi-subagents":$[e];return(0,n.jsxs)("button",{onClick:()=>{!i&&(el(!1),r||v(t))},disabled:i,title:i?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:i?"not-allowed":"pointer",fontSize:ev?11:12,textAlign:"left",fontWeight:r?600:400,opacity:i?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:o})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:ey,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ev?8:9,color:"#ef4444",cursor:"pointer",fontSize:ev?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),!ek&&void 0!==I&&(0,n.jsxs)("button",{onClick:()=>{l||I(!z)},disabled:l,title:z?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:em,height:ey,background:z?"rgba(59,130,246,0.08)":"none",border:z?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:ev?8:9,color:z?"#3b82f6":"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ev?11:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background=z?"rgba(59,130,246,0.14)":"var(--bg-hover)",e.currentTarget.style.color=z?"#3b82f6":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=z?"rgba(59,130,246,0.08)":"none",e.currentTarget.style.color=z?"#3b82f6":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,n.jsx)("span",{style:eb,children:z?"Plan":"Code"})]}),!ev&&void 0!==T&&(0,n.jsx)("button",{onClick:T,title:C?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ev?28:32,height:ev?28:32,padding:0,background:"none",border:"none",borderRadius:ev?8:9,color:C?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:C?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=C?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=C?"1":"0.55"},children:C?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function q(e){return"user"===e.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function Y({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o}){let[l,s]=(0,i.useState)(0),[a,d]=(0,i.useState)(1),[c,p]=(0,i.useState)(!1),[u,h]=(0,i.useState)([]),[x,g]=(0,i.useState)(!1),[f,v]=(0,i.useState)(null),b=(0,i.useRef)(!1),y=(0,i.useRef)(null),m=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,i.useRef)(m);j.current=m;let k=(0,i.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,i=t-n;p(i>20),i<=0?(s(0),d(1)):(s(e.scrollTop/i),d(n/t));let l=o.current,a=[],c=0,u=j.current;for(let r=0;r<u.length;r++){let n=u[r];if("user"!==n.role&&"assistant"!==n.role)continue;let i=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&i&&t>0){let r=i.getBoundingClientRect(),o=e.getBoundingClientRect(),l=r.top-o.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,i.useCallback)(()=>k.current(),[]);(0,i.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,i.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,i.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,i.useCallback)(e=>{if(!c)return;b.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),i=n>=0&&n<=a?n:a/2;S(r-i);let o=e=>{b.current&&S((e.clientY-t.top)/t.height-i)},s=()=>{b.current=!1,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,i.useMemo)(()=>{if(!x||0===u.length)return[];let e=u.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,u,T]);if(!c)return null;let I=l*(1-a)*100,R=100*a,M=null!==f&&u.length>0?u.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(u[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${R}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),u.map(e=>{let t=q(e.msg),r=x&&M===e.index,i="user"===e.msg.role,o=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${o}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:i?8:6,height:i?8:6,borderRadius:i?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&u.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),i=q(e.msg),o=M===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${o?i.border:"var(--border)"}`,borderRight:`1px solid ${o?i.border:"var(--border)"}`,borderBottom:`1px solid ${o?i.border:"var(--border)"}`,borderLeft:`2px solid ${i.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:o?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:o?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function G(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Z(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function X(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function Q(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function ee(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:Z(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,i=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),o="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${i}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:i,status:"running",task:o,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!G(t))return{...e,summary:Z(r)};let i=Array.isArray(t.results)?t.results.filter(G):[],o=i[0],l=o?.progressSummary,s=o&&(n=o.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=X(o?.finalOutput,o?.output,r);return{...e,mode:X(t.mode),runId:X(t.runId),agent:X(o?.agent,e.agent)??e.agent,task:X(o?.task,e.task),summary:Z(a),model:X(o?.model),durationMs:Q(l?.durationMs),toolCount:Q(l?.toolCount),tokens:Q(l?.tokens),outputPath:X(o?.savedOutputPath,o?.artifactPaths?.outputPath),sessionFile:X(o?.sessionFile,o?.artifactPaths?.jsonlPath),artifacts:s,resultCount:i.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return G(t)&&Array.isArray(t.results)&&t.results.some(e=>G(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 et({messages:e,runs:t}){let r=(0,i.useMemo)(()=>ee(e??[]),[e]),o=t??r,l=o.filter(e=>"running"===e.status),s=o.filter(e=>"running"!==e.status);return 0===o.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(er,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(er,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function er({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)(en,{run:e},e.id))]})}function en({run:e}){let[t,r]=(0,i.useState)(!1),o="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":o?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":o?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":o?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(ei,{running:o,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:Z(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)(eo,{run:e})]})]})}function ei({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 eo({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 el({sessionKind:e,toolPreset:t,initialSourcePath:r,initialKernel:i,isNew:o,isStreaming:l=!1,onResume:s,onDismiss:a}){if(o||"workbench"!==e)return null;let d=r?r.replace(/\\/g,"/").split("/").filter(Boolean).pop()??r:null,c="workbench"===t;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M4 19V5"}),(0,n.jsx)("path",{d:"M4 19h16"}),(0,n.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,n.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,n.jsxs)("strong",{children:[c?"active":"inactive"," Workbench"]})," session",d&&(0,n.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:d})]}),i&&(0,n.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",i.toUpperCase()]})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsx)("button",{type:"button",onClick:a,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,n.jsx)("button",{type:"button",onClick:s,disabled:l,title:l?"Wait until the agent finishes before updating Workbench":c?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:l?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:l?.55:1,whiteSpace:"nowrap"},children:c?"Reload Initial Data":"Resume Workbench"})]})}var es=r(5377);let ea=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ed(e){return ea.some(t=>e.type.startsWith(t))}function ec({agentPhase:e,startedAt:t}){let[r,o]=(0,i.useState)(0);return(0,i.useEffect)(()=>{if(!t)return void o(0);let e=()=>o(Math.max(0,Math.floor((Date.now()-t)/1e3)));e();let r=setInterval(e,1e3);return()=>clearInterval(r)},[t]),(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(e){if(e?.kind==="running_tools"){let t=e.tools.map(e=>e.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 ep(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function eu({goal:e,planTasks:t,isRunning:r,onExecutePlan:o,onContinuePlanning:l,onEditPlan:s}){let[a,d]=(0,i.useState)(!1),c=(0,i.useCallback)(()=>d(e=>!e),[]),p=e&&"dropped"!==e.status,u=t&&t.length>0;if(!p&&!u)return null;let h=(0,i.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:[p&&(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:u?"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:[ep(e.tokensUsed),e.tokenBudget?` / ${ep(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"}})})]}),u&&(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||o)&&(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:"继续规划"}),o&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),o()},disabled:r,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:r?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:r?"not-allowed":"pointer"},children:"执行计划"})]}),(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform: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))})]})]})}var eh=r(32383);function ex(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 eg=["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 ef({phrases:e}){let[t,r]=(0,i.useState)(()=>Math.floor(Math.random()*e.length)),[o,l]=(0,i.useState)(""),[s,a]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!0);return(0,i.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,i.useEffect)(()=>{let n,i=e[t];if(s||o!==i)if(s&&""===o)a(!1),r(t=>(t+1)%e.length);else{let e=s?i.slice(0,o.length-1):i.slice(0,o.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[o,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[o,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function ev({status:e}){let t=e?.current??"0.8.122"??"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 eb({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSessionStatsChange:p,onContextUsageChange:u,onToolPresetActive:h,generativeUI:x,activeFilePath:g,onOpenFileAtLine:f}){var v;let b,[y,m]=(0,i.useState)(null),[j,k]=(0,i.useState)(!1),[w,S]=(0,i.useState)([]),[C,T]=(0,i.useState)(""),[z,I]=(0,i.useState)(!1),R=(0,i.useRef)(!1),[L,P]=(0,i.useState)(!1),E=g&&!L?g:null;(0,i.useEffect)(()=>{P(!1)},[g]);let $=(0,i.useCallback)(e=>{let t;k(e.enabled),I(e.executing);let r=(t=e.todos.findIndex(e=>!e.completed),e.todos.map((e,r)=>({id:`plan-${e.step||r+1}`,step:e.text,status:e.completed?"completed":r===t?"inProgress":"pending"})));e.enabled||e.executing||r.length>0?S(r):S([])},[]),{data:B,loading:D,error:A,messages:O,entryIds:N,streamState:H,agentRunning:F,modelNames:U,modelList:_,modelThinkingLevels:K,modelThinkingLevelMaps:J,toolPreset:q,memoryTools:G,thinkingLevel:Z,retryInfo:X,contextUsage:Q,forkingEntryId:er,isCompacting:en,compactError:ei,displayModel:eo,sessionStats:ea,agentPhase:ep,agentError:ey,isNew:em,loadMoreMessages:ej,hasMoreMessages:ek,totalMessages:ew,loadedMessagesCount:eS,messagesEndRef:eC,scrollContainerRef:eT,lastUserMsgRef:ez,handleSend:eI,handleAbort:eR,handleFork:eM,handleNavigate:eW,handleModelChange:eL,handleCompact:eP,handleSteer:eE,handleFollowUp:e$,handleAbortCompaction:eB,handleToolPresetChange:eD,handleMemoryToolsChange:eA,handleThinkingLevelChange:eO,handleAgentEventRef:eN}=(0,es.T)({session:e,newSessionCwd:t,planMode:j,onAgentEnd:r,onSessionCreated:o,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:d,onPlanModeState:$}),{soundEnabled:eH,onSoundToggle:eF,playDoneSound:eU}=function(){let[e,t]=(0,i.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,i.useRef)(e);return(0,i.useEffect)(()=>{r.current=e},[e]),{soundEnabled:e,onSoundToggle:(0,i.useCallback)(()=>{t(e=>{let t=!e;return localStorage.setItem("pi-sound-enabled",String(t)),t})},[]),playDoneSound:(0,i.useCallback)(()=>{if(r.current)try{let e=new AudioContext;"suspended"===e.state&&e.resume().catch(()=>{});let t=e.currentTime;[523.25,659.25].forEach((r,n)=>{let i=e.createOscillator(),o=e.createGain();i.connect(o),o.connect(e.destination),i.type="sine",i.frequency.value=r;let l=t+.18*n;o.gain.setValueAtTime(0,l),o.gain.linearRampToValueAtTime(.18,l+.02),o.gain.exponentialRampToValueAtTime(.001,l+.45),i.start(l),i.stop(l+.45)}),setTimeout(()=>e.close(),1200)}catch{}},[]),soundEnabledRef:r}}(),e_=(0,i.useRef)(eU);e_.current=eU;let eK=(0,i.useRef)(eH);eK.current=eH,(0,i.useEffect)(()=>{F&&!y&&m(Date.now()),F||m(null)},[F,y]);let eJ=eN.current;(0,i.useEffect)(()=>{eN.current=e=>{"agent_start"===e.type&&(m(Date.now()),R.current=!1),"tool_execution_end"===e.type&&z&&(R.current=!0,S(ex)),"agent_end"===e.type&&!0!==e.willRetry&&(m(null),z&&!R.current&&S(ex)),"agent_end"===e.type&&!0!==e.willRetry&&eK.current&&e_.current(),eJ?.(e)}},[eJ,eN,z]);let eV=ea?`${ea.tokens.input}|${ea.tokens.output}|${ea.tokens.cacheRead}|${ea.tokens.cacheWrite}|${ea.cost??0}`:null,eq=(0,i.useRef)(ea);eq.current=ea,(0,i.useEffect)(()=>{p?.(eq.current)},[eV,p]),(0,i.useEffect)(()=>()=>{p?.(null)},[p]),(0,i.useEffect)(()=>(h?.("workbench"===q),()=>{h?.(!1)}),[q,h]);let eY=Q?`${Q.percent??"null"}|${Q.contextWindow}|${Q.tokens??"null"}`:null,eG=(0,i.useRef)(Q);eG.current=Q,(0,i.useEffect)(()=>{u?.(eG.current)},[eY,u]),(0,i.useEffect)(()=>()=>{u?.(null)},[u]);let eZ=(0,i.useCallback)(e=>{a?.current?.addFiles(e)},[a]),eX=(0,i.useCallback)((e,t,r)=>{let n=r?.findIndex(t=>t.src===e)??-1;e6({src:e,gallery:r,index:n>=0?n:0})},[]),{isDragOver:eQ,handleDragEnter:e0,handleDragOver:e1,handleDragLeave:e2,handleDrop:e5}=function(e){let[t,r]=(0,i.useState)(!1),n=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ed)&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(ed)&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}(eZ),[e4,e3]=(0,i.useState)(null),[e8,e6]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!em)return;let e=!1;return fetch("/api/version").then(e=>e.ok?e.json():null).then(t=>{!e&&t?.updateAvailable&&e3(t)}).catch(()=>{}),()=>{e=!0}},[em]);let e7=O.filter(e=>"user"===e.role||"assistant"===e.role),e9=(v=e7.length,(b=(0,i.useRef)([])).current=Array(v).fill(null).map((e,t)=>b.current[t]??null),b),te=(0,i.useMemo)(()=>{let e=new Map;for(let t of O)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[O]),tt=em&&0===O.length&&!H.isStreaming&&!F,tr=B?.info?.cwd??e?.cwd??t??null,tn=function(e){if(!e)return null;let t=e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return t[t.length-1]||e}(tr),ti=function(e=768){let[t,r]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e-1}px)`),n=()=>r(t.matches);return(n(),"function"==typeof t.addEventListener)?(t.addEventListener("change",n),()=>t.removeEventListener("change",n)):(t.addListener(n),()=>t.removeListener(n))},[e]),t}(),[to,tl]=(0,i.useState)(!1),[ts,ta]=(0,i.useState)(!1),td=ee(O),tc=td.filter(e=>"running"===e.status).length;(0,i.useEffect)(()=>{0===td.length&&to&&tl(!1)},[td.length,to]),(0,i.useEffect)(()=>{ti&&to&&tl(!1)},[ti,to]),(0,i.useEffect)(()=>{ta(!1)},[e?.id]);let tp=(0,i.useCallback)(()=>{e?.id&&!F&&(async()=>{await eD("workbench");let e=B?.sessionMeta;if(e?.initialSourcePath&&e.initialKernel){let t=`Resume this Workbench session. Reload only the initial data file \`${e.initialSourcePath}\` using the ${e.initialKernel.toUpperCase()} runtime. Do not rerun previous analyses or load extra files unless I ask. Use the chat history only as context for what to do next.`;await eI(t)}})()},[F,B?.sessionMeta,eI,eD,e?.id]),tu=eo?K[`${eo.provider}:${eo.modelId}`]??null:null,th=eo?J[`${eo.provider}:${eo.modelId}`]??null:null,tx=B?.sessionMeta?.sessionKind??null,tg=e?.id??t??"new-chat",tf=(0,i.useMemo)(()=>(function(e){let t=[];for(let r=e.length-1;r>=0;r-=1){let n=e[r];if("user"!==n.role)continue;let i=n.text.trim();i&&t.push(i)}return t})(e7.map(e=>{let t;return{role:e.role,text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.filter(e=>!!e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n"):""}})),[e7]),tv=(0,i.useCallback)(()=>{let t=!j;k(t);let r=e?.id;if(r){let e=t?["read","bash","grep","find","ls"]:(0,W.tE)(q,G);(0,eh.$)(r,{type:"set_tools",toolNames:e,planMode:t}).catch(()=>{})}t&&I(!1)},[G,j,e?.id,q]),tb=(0,i.useCallback)(async(e,t,r)=>{if("/plan"===e.trim()||e.trim().startsWith("/plan "))return void tv();let n=e;E&&e.trim()&&(n=`${e}
7
7
 
8
8
  [Current file: \`${E}\`]`),await eI(n,t,r)},[tv,eI,E]),ty=(0,n.jsx)(V,{ref:a,onSend:tb,onAbort:eR,onSteer:F?eE:void 0,onFollowUp:F?e$:void 0,isStreaming:F,model:eo,modelNames:U,modelList:_,onModelChange:eL,onCompact:e||em?eP:void 0,onAbortCompaction:eB,isCompacting:en,compactError:ei,toolPreset:q,sessionKind:tx,onToolPresetChange:e||em?eD:void 0,memoryTools:G,onMemoryToolsChange:e||em?eA:void 0,thinkingLevel:Z,onThinkingLevelChange:e||em?eO:void 0,availableThinkingLevels:tu,thinkingLevelMap:th,retryInfo:X,soundEnabled:eH,onSoundToggle:eF,cornerBadge:tt?(0,n.jsx)(ev,{status:e4}):void 0,promptHistory:tf,sessionHistoryKey:tg,planMode:j,onPlanModeChange:()=>tv(),activeFilePath:E,onDismissFileContext:()=>P(!0)});(0,i.useEffect)(()=>{if(!j){z||S([]);return}let e=[...O].reverse().find(e=>"assistant"===e.role);if(!e||!Array.isArray(e.content)){S([]),T("");return}let t=e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if(!t){S([]),T("");return}let r=[];for(let e of t.matchAll(/^\s*(\d+)[.)]\s+\*{0,2}([^*\n]+)/gm)){let t=e[2].trim().replace(/\*{1,2}$/,"").trim().replace(/\s+/g," ");t.length>3&&r.push({id:`task-${r.length}`,step:t.slice(0,80),status:"pending"})}T(t),S(r)},[O,z,j]);let tm=(0,i.useCallback)(()=>{F||0===w.length||eI("请继续完善这个计划,补充遗漏的风险、步骤和验证方式。保持编号列表格式。")},[F,eI,w.length]),tj=(0,i.useCallback)(()=>{if(F||0===w.length)return;let e=C||w.map((e,t)=>`${t+1}. ${e.step}`).join("\n");a?.current?.insertText(`请按以下修改后的计划继续规划:
9
9