@seqyuan/annovibe 0.8.38 → 0.8.39

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 (65) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +2 -2
  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.html +1 -1
  48. package/.next/server/app/smoke.rsc +1 -1
  49. package/.next/server/app/smoke.segments/_full.segment.rsc +1 -1
  50. package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
  51. package/.next/server/app/smoke.segments/_index.segment.rsc +1 -1
  52. package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
  53. package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
  54. package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
  55. package/.next/server/app-paths-manifest.json +2 -2
  56. package/.next/server/middleware-build-manifest.js +1 -1
  57. package/.next/server/next-font-manifest.js +1 -1
  58. package/.next/server/next-font-manifest.json +1 -1
  59. package/.next/server/pages/404.html +1 -1
  60. package/.next/server/pages/500.html +1 -1
  61. package/.next/server/server-reference-manifest.json +1 -1
  62. package/.next/static/chunks/app/{page-b661cdb3bfe2fa39.js → page-443865609e7e67a7.js} +2 -2
  63. package/package.json +1 -1
  64. /package/.next/static/{mCpHlVFXHtaZWXtpC4gki → tzG34HSOTS30YvTSTz81W}/_buildManifest.js +0 -0
  65. /package/.next/static/{mCpHlVFXHtaZWXtpC4gki → tzG34HSOTS30YvTSTz81W}/_ssgManifest.js +0 -0
@@ -1,9 +1,9 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{16945:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>rO});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${b?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,s]=(0,o.useState)(""),[a,c]=(0,o.useState)(null),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),j=(0,o.useCallback)(async e=>{m(!0),b(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(n.current??""),c(n.parent??null),p(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){b(e instanceof Error?e.message:String(e))}finally{m(!1)}},[]);return((0,o.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&i(t)},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=g.trim();e&&j(e)},disabled:!g.trim()||v,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:g.trim()&&!v?"var(--text-muted)":"var(--text-dim)",cursor:g.trim()&&!v?"pointer":"default",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:g.trim()?"var(--accent)":"var(--bg-hover)",color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>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===u.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):u.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void j(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let c="AnnoVibe",u="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function h(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function x(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function g(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function f(e,t){let r,n,o;if(!e)return"No Project";let i=e.replace(/[\\/]+$/,""),l=i.includes("/")?"/":"\\";return i.split(l).filter(Boolean).pop()||(n=(r=t&&e.startsWith(t)?"~"+e.slice(t.length):e).includes("/")?"/":"\\",(o=r.split(n).filter(Boolean)).length<=2?r:"…/"+o.slice(-2).join(n))}let v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function m(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:v[Math.floor(Math.random()*v.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.38":c,r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function y({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:c,selectedCwd:g,onCwdChange:v}){let[k,w]=(0,o.useState)([]),[S,C]=(0,o.useState)([]),[T,z]=(0,o.useState)(!0),[I,M]=(0,o.useState)(null),[L,R]=(0,o.useState)(null),[W,E]=(0,o.useState)(""),[$,P]=(0,o.useState)(null),[B,D]=(0,o.useState)(!1),[N,O]=(0,o.useState)("project"),[A,H]=(0,o.useState)(!1),[F,U]=(0,o.useState)(()=>new Set),[_,J]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(u)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[V,K]=(0,o.useState)(null),[Y,q]=(0,o.useState)(null),[X,Z]=(0,o.useState)(null),G=(0,o.useRef)(!1),Q=(0,o.useRef)(!1),ee=(0,o.useRef)(!1),et=(0,o.useCallback)(async(e=!1)=>{try{e&&(M(null),z(!0));let[t,r]=await Promise.all([fetch("/api/sessions"),fetch("/api/projects")]);if(!t.ok)throw Error(await x("sessions",t));if(!r.ok)throw Error(await x("projects",r));let n=await t.json(),o=await r.json();w(n.sessions),C(o.projects),M(null)}catch(e){M(String(e))}finally{e&&z(!1)}},[]),er=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!er.current;er.current=!0,et(e)},[et,s]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&E(e.home)}).catch(()=>{})},[]);let en=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(G.current){G.current=!1;return}if(Q.current){Q.current=!1;return}v?.(L)},[L,v]);let eo=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return P(n.error??`HTTP ${r.status}`),!1;return et(!1),!0}catch(e){return P(e instanceof Error?e.message:String(e)),!1}},[et]),ei=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),el=(0,o.useCallback)(e=>{Q.current=!0,R(e),P(null),J(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),h(r),r}),v?.(e),ei(e)},[v,ei]);(0,o.useEffect)(()=>{if((0!==k.length||0!==S.length)&&null===L){if(i&&!en.current){en.current=!0;let e=k.find(e=>e.id===i);if(e){R(e.cwd),ei(e.cwd),t(e,!0);return}l?.()}let e=S[0]?.cwd;e&&(R(e),ei(e))}},[k,S,L,i,t,l,ei]);let es=g??L,ea=(0,o.useCallback)(e=>{if(!e){O("chat"),D(!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]),ed=(0,o.useCallback)(async e=>{await eo(e,!0)&&(el(e),D(!1),P(null),"chat"===N&&ea(e))},[el,ea,N,eo]),ec=(0,o.useCallback)(()=>{ea(es)},[ea,es]),eu=(0,o.useCallback)(()=>{O("project"),P(null),D(!0)},[]),ep=(0,o.useMemo)(()=>[...es&&!S.some(e=>e.cwd===es)?[{cwd:es,displayName:f(es,W),chatCount:k.filter(e=>e.cwd===es).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...S].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,o="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==o?n-o:e.displayName.localeCompare(t.displayName,void 0,{numeric:!0,sensitivity:"base"})}),[k,es,W,S]),eh=(0,o.useMemo)(()=>{let e=new Map;for(let t of k){let r=t.cwd||"";e.has(r)||e.set(r,[]),e.get(r).push(t)}return ep.map(t=>{let r=[...e.get(t.cwd)??[]].sort((e,t)=>t.modified.localeCompare(e.modified));return{project:t,cwd:t.cwd,displayName:t.displayName||f(t.cwd,W),sessions:r,lastAccessed:(t.lastAccessed??t.created??"")||r[0]?.modified||""}})},[k,W,ep]);(0,o.useEffect)(()=>{if(0===eh.length||ee.current||(ee.current=!0,!eh[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eh.slice(1).map(e=>e.cwd));J(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(h(e),e):t),window.localStorage.setItem(p,"1")},[eh]);let ex=(0,o.useCallback)((e,r=!1)=>{e.cwd!==es&&(G.current=!0,R(e.cwd)),J(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),h(r),r}),ei(e.cwd),t(e,r)},[t,es,ei]),eg=(0,o.useCallback)(e=>{J(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),h(r),r})},[]),ef=(0,o.useCallback)(e=>{U(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ev=(0,o.useCallback)(async e=>{Z("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}`);C(r.projects??[]),M(null)}catch(e){M(e instanceof Error?e.message:String(e)),et(!1)}finally{Z(null)}},[et]),em=(0,o.useCallback)(async(e,t)=>{Z(`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}`);C(n.projects??[]),M(null)}catch(e){M(e instanceof Error?e.message:String(e)),et(!1)}finally{Z(null)}},[et]),ey=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=ep.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),o=r.indexOf(t);if(-1===n||-1===o)return;let i=[...r];i.splice(n,1);let l=i.indexOf(t);i.splice(l,0,e),ev(i)},[ev,ep]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)(m,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:ec,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:es?`New chat in ${es}`:"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:()=>H(!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:A,cwd:es,homeDir:W,onClose:()=>H(!1),onSelectSession:e=>{ex(e)}}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"8px 10px 6px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontSize:12,fontWeight:700},children:"Projects"}),(0,n.jsxs)("button",{type:"button",onClick:eu,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"},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"]})]}),$&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:$})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[T&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),I&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:I}),!T&&!I&&0===eh.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!T&&!I&&eh.map(t=>{let r=_.has(t.cwd),o=t.cwd===es,i=F.has(t.cwd),l=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),s=l.length,a=l;if(s>10&&!i){a=l.slice(0,10);let t=l.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!a.includes(t)&&(a=[...a,t])}let d=s-a.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:Y===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(Y===t.cwd),opacity:V===t.cwd?.55:1},onDragOver:e=>{V&&V!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",q(t.cwd))},onDragLeave:()=>{Y===t.cwd&&q(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||V;q(null),K(null),r&&ey(r,t.cwd)},children:[(0,n.jsx)(b,{group:t,isCurrent:o,isCollapsed:r,isDragging:V===t.cwd,pinBusy:X===`pin:${t.cwd}`,onToggle:()=>eg(t.cwd),onSelect:()=>el(t.cwd),onTogglePinned:()=>void em(t.cwd,!0!==t.project.pinned),onNewSession:e=>{e.stopPropagation(),el(t.cwd),ea(t.cwd)},onDragStart:e=>{K(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{K(null),q(null)}}),!r&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[0===t.sessions.length?(0,n.jsx)("button",{type:"button",onClick:()=>{el(t.cwd),ea(t.cwd)},style:{width:"100%",padding:"10px 12px",background:"transparent",border:"none",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)"},children:"Start a new session in this project"}):a.map(t=>(0,n.jsx)(j,{node:t,selectedSessionId:e,onSelectSession:ex,onRenamed:et,onSessionDeleted:e=>{c?.(e),et()},depth:0},t.session.id)),(i||d>0)&&s>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:i?"Show less":`Show ${Math.max(0,d)} more`})]})]},t.cwd||"__no_project")})]}),(0,n.jsx)(d,{open:B,initialPath:es||W||null,onClose:()=>D(!1),onSelect:e=>void ed(e)})]})}function b({group:e,isCurrent:t,isCollapsed:r,isDragging:i,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onNewSession:c,onDragStart:u,onDragEnd:p}){let[h,x]=(0,o.useState)(!1),g=(0,o.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:g,onDragStart:u,onDragEnd:p,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),g())},onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),title:e.cwd,style:{width:"100%",minHeight:30,display:"flex",alignItems:"center",gap:5,padding:"4px 7px",background:t&&!r?"var(--bg-selected)":h?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:i?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s"},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",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:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.4",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:500,color:"var(--text)"},children:e.displayName}),e.project.pinned&&(0,n.jsx)("span",{style:{flexShrink:0,fontSize:10,color:"var(--accent)"},children:"pinned"}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:e.project.pinned?"Unpin project":"Pin project",tabIndex:h?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:e.project.pinned?"var(--accent)":"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:h||e.project.pinned?1:0,pointerEvents:h||e.project.pinned?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s"},children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:e.project.pinned?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M5 2.5h6l-1.8 4v3.2l1.3 2.3H5.5l1.3-2.3V6.5L5 2.5Z"})})}),(0,n.jsx)("button",{type:"button",onClick:c,title:"New chat in this project",tabIndex:h?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:"pointer",flexShrink:0,opacity:+!!h,pointerEvents:h?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1.5",x2:"6",y2:"10.5"}),(0,n.jsx)("line",{x1:"1.5",y1:"6",x2:"10.5",y2:"6"})]})}),(0,n.jsx)("span",{title:"Drag to reorder projects",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:+!!h,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor","aria-hidden":"true",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 j({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(k,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(j,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function k({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[f,v]=(0,o.useState)(""),[m,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(!1),w=(0,o.useRef)(null),S=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),C=(0,o.useCallback)(t=>{t.stopPropagation(),v(e.name??""),x(!0),setTimeout(()=>w.current?.select(),0)},[e.name]),T=(0,o.useCallback)(async()=>{let t=f.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[f,e.id,e.name,i]),z=(0,o.useCallback)(e=>{e.stopPropagation(),y(!0)},[]),I=(0,o.useCallback)(async t=>{t.stopPropagation(),y(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),y(!1)},[]);return(0,n.jsx)("div",{onClick:m||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1)},style:{height:m?42:34,display:"flex",alignItems:"center",paddingLeft:s>0?12*s+16:18,paddingRight:6,cursor:m||h?"default":"pointer",background:m?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:"none",borderRadius:6,transition:"background 0.1s",opacity:b?.5:1,gap:5,overflow:"hidden"},children:m?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",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:28,padding:"0 9px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:11,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:28,padding:"0 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):h?(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&&x(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:5,height:5,borderRadius:"50%",background:t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0}}),(0,n.jsx)("div",{style:{flex:1,minWidth:0},children:(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",wordBreak:"break-all"},title:S,children:S})}),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"})})}),(0,n.jsx)("span",{title:`${g(e.modified)} \xb7 ${e.messageCount} msgs`,style:{width:42,flexShrink:0,color:"var(--text-dim)",fontSize:11,textAlign:"right",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",opacity:+!u,transition:"opacity 0.12s"},children:g(e.modified)}),u&&(0,n.jsxs)("div",{style:{display:"flex",gap:2,flexShrink:0,marginLeft:-42},children:[(0,n.jsx)("button",{onClick:C,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)("svg",{width:"13",height:"13",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:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,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="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:"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 w=r(94456);let S="subagent",C=["retain","recall","reflect"],T=[],z=["read","bash","edit","write"],I=["bash","read","edit","write","grep","find","ls"],M=[...I,"kernel_plot_run","kernel_plot_stop","kernel_plot_artifacts"],L=[...I,S];function R(e){return[...e].sort().join(",")}function W(e){switch(e){case"none":return T;case"default":return z;case"workbench":return M;case"agent":return L;default:return I}}function E(e,t){return[...new Set([...W(e),...t])]}let $=["off","default","full","workbench","agent"],P={off:"none",default:"default",full:"full",workbench:"workbench",agent:"agent"},B={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",workbench:"全工具 + Workbench 运行时",agent:"High + 子代理"},D={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},N=["auto","off","minimal","low","medium","high","xhigh"],O={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},A=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function H({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function F(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function U(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,o=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&o.push(`Page ${e}
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{16945:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>rO});var n=r(95155),o=r(12115),i=r(73321);function l(e,t){let r=t&&e.startsWith(t)?"~"+e.slice(t.length):e,n=r.includes("/")?"/":"\\",o=r.split(n).filter(Boolean);return o.length<=2?r:"..."+n+o.slice(-2).join(n)}function s(e){let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function a({open:e,cwd:t,homeDir:r,onClose:i,onSelectSession:d}){let[c,u]=(0,o.useState)(""),[p,h]=(0,o.useState)("current"),[x,g]=(0,o.useState)([]),[f,v]=(0,o.useState)(!1),[m,y]=(0,o.useState)(null),[b,j]=(0,o.useState)(!1),k=(0,o.useRef)(null);if((0,o.useEffect)(()=>{e&&(h(t?"current":"all"),setTimeout(()=>k.current?.focus(),0))},[e,t]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&i()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,i]),(0,o.useEffect)(()=>{if(!e)return;let r=c.trim();if(r.length<2){g([]),v(!1),y(null),j(!1);return}let n=new AbortController,o=setTimeout(async()=>{v(!0),y(null);try{let e=new URLSearchParams({q:r,scope:p});t&&e.set("cwd",t);let o=await fetch(`/api/search?${e.toString()}`,{signal:n.signal});if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();if(i.error)throw Error(i.error);g(i.results??[]),j(i.truncated??!1)}catch(e){"AbortError"!==e.name&&y(String(e))}finally{v(!1)}},180);return()=>{clearTimeout(o),n.abort()}},[e,c,p,t]),!e)return null;let w=c.trim(),S=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:e=>{e.target===e.currentTarget&&i()},children:(0,n.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,n.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,n.jsx)("input",{ref:k,value:c,onChange:e=>u(e.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,n.jsx)("button",{type:"button",onClick:i,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M4 4 12 12"}),(0,n.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,n.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!t},{value:"all",label:"All history",disabled:!1}].map(e=>(0,n.jsx)("button",{type:"button",disabled:e.disabled,onClick:()=>h(e.value),style:{height:24,padding:"0 9px",background:p===e.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:e.disabled?"var(--text-dim)":p===e.value?"var(--text)":"var(--text-muted)",cursor:e.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:e.label},e.value))}),(0,n.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===p&&t?l(t,r):"Searching every saved session"})]})]}),(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[w.length<2&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),w.length>=2&&f&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),m&&(0,n.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:m}),w.length>=2&&!f&&!m&&0===x.length&&(0,n.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),x.map(e=>(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:e.session.name||e.session.firstMessage||"(no messages)"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:s(e.session.modified)})]}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(e.session.cwd,r)})]}),e.matchCount>e.matches.length&&(0,n.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[e.matchCount," matches"]})]}),e.matches.map(t=>(0,n.jsxs)("button",{type:"button",onClick:()=>{d(e.session),i()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,n.jsx)("span",{style:{minWidth:54,color:"user"===t.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:t.role}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:s(t.timestamp)})]}),(0,n.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(e,t){let r=t.trim();if(!r)return e;let o=e.toLowerCase().indexOf(r.toLowerCase());return o<0?e:(0,n.jsxs)(n.Fragment,{children:[e.slice(0,o),(0,n.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:e.slice(o,o+r.length)}),e.slice(o+r.length)]})}(t.snippet,w)})]},t.entryId))]},e.session.id))]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsx)("span",{children:S>0?`${S}${b?"+":""} results`:"Esc to close"}),f&&x.length>0&&(0,n.jsx)("span",{children:"Updating..."})]})]})})}function d({open:e,initialPath:t,onClose:r,onSelect:i}){let[l,s]=(0,o.useState)(""),[a,c]=(0,o.useState)(null),[u,p]=(0,o.useState)([]),[h,x]=(0,o.useState)([]),[g,f]=(0,o.useState)(""),[v,m]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),j=(0,o.useCallback)(async e=>{m(!0),b(null);try{let t=e?`/api/projects/browse?dir=${encodeURIComponent(e)}`:"/api/projects/browse",r=await fetch(t),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);s(n.current??""),c(n.parent??null),p(n.directories??[]),x(n.drives??[]),f(n.current??"")}catch(e){b(e instanceof Error?e.message:String(e))}finally{m(!1)}},[]);return((0,o.useEffect)(()=>{e&&j(t||void 0)},[j,t,e]),(0,o.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&r()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[r,e]),e)?(0,n.jsx)("div",{onMouseDown:e=>{e.target===e.currentTarget&&r()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,n.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,n.jsx)("button",{type:"button",onClick:r,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,n.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&i(t)},style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=g.trim();e&&j(e)},disabled:!g.trim()||v,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:g.trim()&&!v?"var(--text-muted)":"var(--text-dim)",cursor:g.trim()&&!v?"pointer":"default",fontSize:12},children:"Browse"}),(0,n.jsx)("button",{type:"submit",disabled:!g.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:g.trim()?"var(--accent)":"var(--bg-hover)",color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>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===u.length?(0,n.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):u.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>void j(e.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},title:e.path,children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,n.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},e.path))}),(0,n.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l,children:l}),(0,n.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,n.jsx)("button",{type:"button",onClick:r,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,n.jsx)("button",{type:"button",onClick:()=>l&&i(l),disabled:!l,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:l?"var(--accent)":"var(--bg-hover)",color:l?"#fff":"var(--text-dim)",cursor:l?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let c="AnnoVibe",u="annovibe:sidebar:collapsed-projects",p="annovibe:sidebar:collapsed-projects:init-v3";function h(e){window.localStorage.setItem(u,JSON.stringify([...e]))}async function x(e,t){let r=`${e}: HTTP ${t.status}`;try{let n=await t.json();return"string"==typeof n.error&&n.error?`${e}: ${n.error}`:r}catch{return r}}function g(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),o=Math.floor(r/36e5),i=Math.floor(r/864e5);return n<1?"just now":n<60?`${n}m ago`:o<24?`${o}h ago`:i<7?`${i}d ago`:t.toLocaleDateString()}function f(e,t){let r,n,o;if(!e)return"No Project";let i=e.replace(/[\\/]+$/,""),l=i.includes("/")?"/":"\\";return i.split(l).filter(Boolean).pop()||(n=(r=t&&e.startsWith(t)?"~"+e.slice(t.length):e).includes("/")?"/":"\\",(o=r.split(n).filter(Boolean)).length<=2?r:"…/"+o.slice(-2).join(n))}let v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function m(){let[e,t]=(0,o.useState)(!1),[r,i]=(0,o.useState)(!1),l=(0,o.useRef)(null),s=function(e,t){let[r,n]=(0,o.useState)(e),i=(0,o.useRef)(null),l=(0,o.useRef)(0);return(0,o.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,o=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:v[Math.floor(Math.random()*v.length)]).join("")),l.current<r?i.current=requestAnimationFrame(o):n(e)};return i.current=requestAnimationFrame(o),()=>{i.current&&cancelAnimationFrame(i.current)}},[e,t]),r}(e?"v0.8.39":c,r),a=(0,o.useCallback)(e=>{t(e),i(!0),setTimeout(()=>i(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,o.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;a(t),t&&(l.current=setTimeout(()=>a(!1),3e3))},[e,a]);return(0,o.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:s})}function y({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:i,onInitialRestoreDone:l,refreshKey:s,onSessionDeleted:c,selectedCwd:g,onCwdChange:v}){let[k,w]=(0,o.useState)([]),[S,C]=(0,o.useState)([]),[T,z]=(0,o.useState)(!0),[I,M]=(0,o.useState)(null),[L,R]=(0,o.useState)(null),[W,E]=(0,o.useState)(""),[$,P]=(0,o.useState)(null),[B,D]=(0,o.useState)(!1),[N,O]=(0,o.useState)("project"),[A,H]=(0,o.useState)(!1),[F,U]=(0,o.useState)(()=>new Set),[_,J]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(u)??window.localStorage.getItem("pidex:sidebar:collapsed-projects");return e?new Set(JSON.parse(e)):new Set}catch{return new Set}})()),[V,K]=(0,o.useState)(null),[Y,q]=(0,o.useState)(null),[X,Z]=(0,o.useState)(null),G=(0,o.useRef)(!1),Q=(0,o.useRef)(!1),ee=(0,o.useRef)(!1),et=(0,o.useCallback)(async(e=!1)=>{try{e&&(M(null),z(!0));let[t,r]=await Promise.all([fetch("/api/sessions"),fetch("/api/projects")]);if(!t.ok)throw Error(await x("sessions",t));if(!r.ok)throw Error(await x("projects",r));let n=await t.json(),o=await r.json();w(n.sessions),C(o.projects),M(null)}catch(e){M(String(e))}finally{e&&z(!1)}},[]),er=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e=!er.current;er.current=!0,et(e)},[et,s]),(0,o.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&E(e.home)}).catch(()=>{})},[]);let en=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(G.current){G.current=!1;return}if(Q.current){Q.current=!1;return}v?.(L)},[L,v]);let eo=(0,o.useCallback)(async(e,t=!1)=>{try{let r=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,create:t})}),n=await r.json();if(!r.ok||n.error)return P(n.error??`HTTP ${r.status}`),!1;return et(!1),!0}catch(e){return P(e instanceof Error?e.message:String(e)),!1}},[et]),ei=(0,o.useCallback)(e=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,touch:!0})}).catch(()=>{})},[]),el=(0,o.useCallback)(e=>{Q.current=!0,R(e),P(null),J(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),h(r),r}),v?.(e),ei(e)},[v,ei]);(0,o.useEffect)(()=>{if((0!==k.length||0!==S.length)&&null===L){if(i&&!en.current){en.current=!0;let e=k.find(e=>e.id===i);if(e){R(e.cwd),ei(e.cwd),t(e,!0);return}l?.()}let e=S[0]?.cwd;e&&(R(e),ei(e))}},[k,S,L,i,t,l,ei]);let es=g??L,ea=(0,o.useCallback)(e=>{if(!e){O("chat"),D(!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]),ed=(0,o.useCallback)(async e=>{await eo(e,!0)&&(el(e),D(!1),P(null),"chat"===N&&ea(e))},[el,ea,N,eo]),ec=(0,o.useCallback)(()=>{ea(es)},[ea,es]),eu=(0,o.useCallback)(()=>{O("project"),P(null),D(!0)},[]),ep=(0,o.useMemo)(()=>[...es&&!S.some(e=>e.cwd===es)?[{cwd:es,displayName:f(es,W),chatCount:k.filter(e=>e.cwd===es).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...S].sort((e,t)=>{let r=!0===e.pinned;if(r!==(!0===t.pinned))return r?-1:1;let n="number"==typeof e.sortOrder?e.sortOrder:Number.MAX_SAFE_INTEGER,o="number"==typeof t.sortOrder?t.sortOrder:Number.MAX_SAFE_INTEGER;return n!==o?n-o:e.displayName.localeCompare(t.displayName,void 0,{numeric:!0,sensitivity:"base"})}),[k,es,W,S]),eh=(0,o.useMemo)(()=>{let e=new Map;for(let t of k){let r=t.cwd||"";e.has(r)||e.set(r,[]),e.get(r).push(t)}return ep.map(t=>{let r=[...e.get(t.cwd)??[]].sort((e,t)=>t.modified.localeCompare(e.modified));return{project:t,cwd:t.cwd,displayName:t.displayName||f(t.cwd,W),sessions:r,lastAccessed:(t.lastAccessed??t.created??"")||r[0]?.modified||""}})},[k,W,ep]);(0,o.useEffect)(()=>{if(0===eh.length||ee.current||(ee.current=!0,!eh[0]?.cwd||window.localStorage.getItem(p)))return;let e=new Set(eh.slice(1).map(e=>e.cwd));J(t=>!function(e,t){if(e.size!==t.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}(t,e)?(h(e),e):t),window.localStorage.setItem(p,"1")},[eh]);let ex=(0,o.useCallback)((e,r=!1)=>{e.cwd!==es&&(G.current=!0,R(e.cwd)),J(t=>{if(!t.has(e.cwd))return t;let r=new Set(t);return r.delete(e.cwd),h(r),r}),ei(e.cwd),t(e,r)},[t,es,ei]),eg=(0,o.useCallback)(e=>{J(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),h(r),r})},[]),ef=(0,o.useCallback)(e=>{U(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ev=(0,o.useCallback)(async e=>{Z("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}`);C(r.projects??[]),M(null)}catch(e){M(e instanceof Error?e.message:String(e)),et(!1)}finally{Z(null)}},[et]),em=(0,o.useCallback)(async(e,t)=>{Z(`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}`);C(n.projects??[]),M(null)}catch(e){M(e instanceof Error?e.message:String(e)),et(!1)}finally{Z(null)}},[et]),ey=(0,o.useCallback)((e,t)=>{if(!e||!t||e===t)return;let r=ep.map(e=>e.cwd).filter(Boolean),n=r.indexOf(e),o=r.indexOf(t);if(-1===n||-1===o)return;let i=[...r];i.splice(n,1);let l=i.indexOf(t);i.splice(l,0,e),ev(i)},[ev,ep]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)(m,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,n.jsxs)("button",{onClick:ec,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:es?`New chat in ${es}`:"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:()=>H(!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:A,cwd:es,homeDir:W,onClose:()=>H(!1),onSelectSession:e=>{ex(e)}}),(0,n.jsxs)("div",{style:{flexShrink:0,padding:"8px 10px 6px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontSize:12,fontWeight:700},children:"Projects"}),(0,n.jsxs)("button",{type:"button",onClick:eu,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"},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"]})]}),$&&(0,n.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:$})]}),(0,n.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[T&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),I&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:I}),!T&&!I&&0===eh.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!T&&!I&&eh.map(t=>{let r=_.has(t.cwd),o=t.cwd===es,i=F.has(t.cwd),l=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let o=function(e){let n=r.get(e),o=new Set;for(;n&&!o.has(n);){if(o.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);o?t.get(o).children.push(e):n.push(e)}let o=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>o(e.children))};return o(n),n}(t.sessions),s=l.length,a=l;if(s>10&&!i){a=l.slice(0,10);let t=l.find(t=>(function e(t,r){return!!r&&(t.session.id===r||t.children.some(t=>e(t,r)))})(t,e));t&&!a.includes(t)&&(a=[...a,t])}let d=s-a.length;return(0,n.jsxs)("div",{style:{marginBottom:6,borderTop:Y===t.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(Y===t.cwd),opacity:V===t.cwd?.55:1},onDragOver:e=>{V&&V!==t.cwd&&(e.preventDefault(),e.dataTransfer.dropEffect="move",q(t.cwd))},onDragLeave:()=>{Y===t.cwd&&q(null)},onDrop:e=>{e.preventDefault();let r=e.dataTransfer.getData("text/project-cwd")||V;q(null),K(null),r&&ey(r,t.cwd)},children:[(0,n.jsx)(b,{group:t,isCurrent:o,isCollapsed:r,isDragging:V===t.cwd,pinBusy:X===`pin:${t.cwd}`,onToggle:()=>eg(t.cwd),onSelect:()=>el(t.cwd),onTogglePinned:()=>void em(t.cwd,!0!==t.project.pinned),onNewSession:e=>{e.stopPropagation(),el(t.cwd),ea(t.cwd)},onDragStart:e=>{K(t.cwd),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/project-cwd",t.cwd)},onDragEnd:()=>{K(null),q(null)}}),!r&&(0,n.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[0===t.sessions.length?(0,n.jsx)("button",{type:"button",onClick:()=>{el(t.cwd),ea(t.cwd)},style:{width:"100%",padding:"10px 12px",background:"transparent",border:"none",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)"},children:"Start a new session in this project"}):a.map(t=>(0,n.jsx)(j,{node:t,selectedSessionId:e,onSelectSession:ex,onRenamed:et,onSessionDeleted:e=>{c?.(e),et()},depth:0},t.session.id)),(i||d>0)&&s>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:i?"Show less":`Show ${Math.max(0,d)} more`})]})]},t.cwd||"__no_project")})]}),(0,n.jsx)(d,{open:B,initialPath:es||W||null,onClose:()=>D(!1),onSelect:e=>void ed(e)})]})}function b({group:e,isCurrent:t,isCollapsed:r,isDragging:i,pinBusy:l,onToggle:s,onSelect:a,onTogglePinned:d,onNewSession:c,onDragStart:u,onDragEnd:p}){let[h,x]=(0,o.useState)(!1),g=(0,o.useCallback)(()=>{t?s():a()},[t,a,s]);return(0,n.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:g,onDragStart:u,onDragEnd:p,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),g())},onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),title:e.cwd,style:{width:"100%",minHeight:30,display:"flex",alignItems:"center",gap:5,padding:"4px 7px",background:t&&!r?"var(--bg-selected)":h?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:i?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s"},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",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:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.4",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:500,color:"var(--text)"},children:e.displayName}),e.project.pinned&&(0,n.jsx)("span",{style:{flexShrink:0,fontSize:10,color:"var(--accent)"},children:"pinned"}),!e.project.exists&&(0,n.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},disabled:l,title:e.project.pinned?"Unpin project":"Pin project",tabIndex:h?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:e.project.pinned?"var(--accent)":"var(--text-muted)",cursor:l?"wait":"pointer",flexShrink:0,opacity:h||e.project.pinned?1:0,pointerEvents:h||e.project.pinned?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s"},children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:e.project.pinned?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M5 2.5h6l-1.8 4v3.2l1.3 2.3H5.5l1.3-2.3V6.5L5 2.5Z"})})}),(0,n.jsx)("button",{type:"button",onClick:c,title:"New chat in this project",tabIndex:h?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:"pointer",flexShrink:0,opacity:+!!h,pointerEvents:h?"auto":"none",transition:"opacity 0.12s, background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1.5",x2:"6",y2:"10.5"}),(0,n.jsx)("line",{x1:"1.5",y1:"6",x2:"10.5",y2:"6"})]})}),(0,n.jsx)("span",{title:"Drag to reorder projects",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:+!!h,transition:"opacity 0.12s",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor","aria-hidden":"true",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 j({node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s}){let[a,d]=(0,o.useState)(!1),c=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[s>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*s+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(k,{session:e.session,isSelected:e.session.id===t,onClick:()=>r(e.session),onRenamed:i,onDeleted:e=>l?.(e),depth:s,hasChildren:c,collapsed:a,onToggleCollapse:()=>d(e=>!e)})]}),c&&!a&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(j,{node:e,selectedSessionId:t,onSelectSession:r,onRenamed:i,onSessionDeleted:l,depth:s+1},e.session.id))})]})}function k({session:e,isSelected:t,onClick:r,onRenamed:i,onDeleted:l,depth:s=0,hasChildren:a=!1,collapsed:d=!1,onToggleCollapse:c}){let[u,p]=(0,o.useState)(!1),[h,x]=(0,o.useState)(!1),[f,v]=(0,o.useState)(""),[m,y]=(0,o.useState)(!1),[b,j]=(0,o.useState)(!1),w=(0,o.useRef)(null),S=e.name||e.firstMessage.slice(0,50)||e.id.slice(0,12),C=(0,o.useCallback)(t=>{t.stopPropagation(),v(e.name??""),x(!0),setTimeout(()=>w.current?.select(),0)},[e.name]),T=(0,o.useCallback)(async()=>{let t=f.trim();if(x(!1),t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),i?.()}catch{}},[f,e.id,e.name,i]),z=(0,o.useCallback)(e=>{e.stopPropagation(),y(!0)},[]),I=(0,o.useCallback)(async t=>{t.stopPropagation(),y(!1),j(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),l?.(e.id)}catch{j(!1)}},[e.id,l]),M=(0,o.useCallback)(e=>{e.stopPropagation(),y(!1)},[]);return(0,n.jsx)("div",{onClick:m||h?void 0:r,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1)},style:{height:m?42:34,display:"flex",alignItems:"center",paddingLeft:s>0?12*s+16:18,paddingRight:6,cursor:m||h?"default":"pointer",background:m?"rgba(239,68,68,0.06)":t?"var(--bg-selected)":u?"var(--bg-hover)":"transparent",borderLeft:"none",borderRadius:6,transition:"background 0.1s",opacity:b?.5:1,gap:5,overflow:"hidden"},children:m?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,n.jsxs)("span",{style:{fontWeight:600},children:["“",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:28,padding:"0 9px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:11,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:28,padding:"0 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):h?(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&&x(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,n.jsxs)(n.Fragment,{children:[s>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===s&&(0,n.jsx)("span",{"aria-hidden":"true",style:{width:5,height:5,borderRadius:"50%",background:t?"var(--accent)":"var(--text-dim)",opacity:t?1:.35,flexShrink:0}}),(0,n.jsx)("div",{style:{flex:1,minWidth:0},children:(0,n.jsx)("div",{style:{fontSize:13,fontWeight:t?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",wordBreak:"break-all"},title:S,children:S})}),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"})})}),(0,n.jsx)("span",{title:`${g(e.modified)} \xb7 ${e.messageCount} msgs`,style:{width:42,flexShrink:0,color:"var(--text-dim)",fontSize:11,textAlign:"right",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",opacity:+!u,transition:"opacity 0.12s"},children:g(e.modified)}),u&&(0,n.jsxs)("div",{style:{display:"flex",gap:2,flexShrink:0,marginLeft:-42},children:[(0,n.jsx)("button",{onClick:C,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)("svg",{width:"13",height:"13",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:22,height:22,padding:0,background:"transparent",border:"none",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,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="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:"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 w=r(94456);let S="subagent",C=["retain","recall","reflect"],T=[],z=["read","bash","edit","write"],I=["bash","read","edit","write","grep","find","ls"],M=[...I,"kernel_plot_run","kernel_plot_stop","kernel_plot_artifacts"],L=[...I,S];function R(e){return[...e].sort().join(",")}function W(e){switch(e){case"none":return T;case"default":return z;case"workbench":return M;case"agent":return L;default:return I}}function E(e,t){return[...new Set([...W(e),...t])]}let $=["off","default","full","workbench","agent"],P={off:"none",default:"default",full:"full",workbench:"workbench",agent:"agent"},B={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",workbench:"全工具 + Workbench 运行时",agent:"High + 子代理"},D={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},N=["auto","off","minimal","low","medium","high","xhigh"],O={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},A=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function H({doc:e,onRemove:t}){var r;let o=e.fileName.split(".").pop()?.toLowerCase()??"",i=function(e){switch(e){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(o),l=(r=e.size)<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`;return(0,n.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:e.fileName,children:[(0,n.jsx)("span",{style:{color:i.color,fontSize:14,flexShrink:0},children:i.emoji}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:e.fileName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[o.toUpperCase()," \xb7 ",l,e.extractionError?" \xb7 no text":e.truncated?" \xb7 truncated":e.extractedText?" \xb7 text":""]})]}),(0,n.jsx)("button",{onClick:t,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function F(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function U(e){let t=await Promise.all([r.e(2213),r.e(2619)]).then(r.bind(r,12810));t.GlobalWorkerOptions.workerSrc=new r.U(r(53228)).toString();let n=await t.getDocument({data:e.slice(0)}).promise,o=[];for(let e=1;e<=n.numPages;e+=1){let t=await n.getPage(e),r=(await t.getTextContent()).items.map(e=>"str"in e?e.str:"").filter(Boolean).join(" ");r.trim()&&o.push(`Page ${e}
2
2
  ${r}`)}return o.join("\n\n")}async function _(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=["word/document.xml",...Object.keys(n.files).filter(e=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(e)).sort()],i=[];for(let e of o){let t=n.file(e);if(!t)continue;let r=[...(await t.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];i.push(...r.map(e=>F(e[1])))}return i.join("").replace(/[ \t]+\n/g,"\n")}async function J(e){let t=await Promise.all([r.e(3524),r.e(8436)]).then(r.bind(r,15967)),n=t.read(e,{type:"array"});return n.SheetNames.map(e=>{let r=n.Sheets[e],o=t.utils.sheet_to_csv(r);return`Sheet: ${e}
3
3
  ${o}`}).join("\n\n")}async function V(e){let t=(await Promise.all([r.e(2619),r.e(4453)]).then(r.t.bind(r,54453,23))).default,n=await t.loadAsync(e),o=Object.keys(n.files).map(e=>({name:e,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(e)})).filter(e=>null!==e.match).sort((e,t)=>Number(e.match[1])-Number(t.match[1])),i=[];for(let{name:e,match:t}of o){let r=[...(await n.file(e).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(e=>F(e[1]).trim()).filter(Boolean);r.length&&i.push(`Slide ${t[1]}
4
4
  ${r.join("\n")}`)}return i.join("\n\n")}async function K(e,t){let r=e.name.split(".").pop()?.toLowerCase()??"";try{let n,o="";if(e.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(r))o=new TextDecoder("utf-8").decode(t);else if("pdf"===r||"application/pdf"===e.type)o=await U(t);else if("docx"===r)o=await _(t);else if("xlsx"===r)o=await J(t);else{if("pptx"!==r)return{extractionError:"Text extraction is not supported for this file type"};o=await V(t)}let{text:i,truncated:l}=(n=o.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:n,truncated:!1}:{text:`${n.slice(0,6e4)}
5
5
 
6
- [truncated after 60000 characters]`,truncated:!0};if(!i)return{extractionError:"No extractable text found"};return{extractedText:i,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let Y=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,onToolPresetChange:f,memoryTools:v,onMemoryToolsChange:m,thinkingLevel:y,onThinkingLevelChange:b,availableThinkingLevels:j,thinkingLevelMap:k,retryInfo:w,soundEnabled:S,onSoundToggle:T,cornerBadge:z},I){let M,L,R,[W,E]=(0,o.useState)(""),[F,U]=(0,o.useState)(!1),[_,J]=(0,o.useState)(null),[V,Y]=(0,o.useState)(!1),[q,X]=(0,o.useState)(!1),[Z,G]=(0,o.useState)(!1),[Q,ee]=(0,o.useState)(!1),[et,er]=(0,o.useState)(!1),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)([]),[es,ea]=(0,o.useState)([]),ed=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),ec=ed?{display:"none"}:void 0,eu=ed?28:32,ep=ed?"6px 8px":"8px 12px",eh=ed?160:180,ex=ed&&!l,eg=et?"var(--text)":"var(--text-muted)",ef={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},ev=ed?{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},[em,ey]=(0,o.useState)(null),eb=(0,o.useRef)(null),ej=(0,o.useRef)(null),ek=(0,o.useRef)(null),ew=(0,o.useRef)(null),eS=(0,o.useRef)(null),eC=(0,o.useRef)(null),eT=(0,o.useRef)(null),ez=(0,o.useRef)(null),eI=(0,o.useRef)(null),eM=(0,o.useRef)(null),eL=(0,o.useCallback)(e=>{let t=eb.current;if(!t)return void E(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=!(o.length>0)||o.endsWith(" ")||o.endsWith("\n")?"":" ";E(o+l+e+i),requestAnimationFrame(()=>{let t=eb.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,o.useImperativeHandle)(I,()=>({insertIfEmpty(e){let t=eb.current;(t?t.value:W).trim()||(E(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eL(e)},addImages(e){eR(e)},addFiles(e){eW(e)}}));let eR=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));el(e=>[...e,...r])},[]),eW=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eR(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,o=await K(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));ea(t=>[...t,...e])}},[eR]),eE=(0,o.useCallback)(e=>{el(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),e$=(0,o.useCallback)(e=>{ea(t=>{let r=[...t];return r.splice(e,1),r})},[]),eP=(0,o.useCallback)(()=>{el(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ea([])},[]),eB=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})),eD=[];for(let e of eB){let t=eD.find(t=>t.provider===e.provider);t?t.options.push(e):eD.push({provider:e.provider,options:[e]})}let eN=s?eB.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eB.length>0?eB[0].name:null,eO=s?eB.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eB[0],eA=eO?.input?.includes("image")??!0,eH=ei.length>0&&eO?.input!==void 0&&!eA,eF=(!!W.trim()||ei.length>0||es.length>0)&&!eH,eU=u?A:A.filter(e=>"/compact"!==e.command),e_=eU.filter(e=>"native"===e.kind),eJ=eU.filter(e=>"shortcut"===e.kind),eV=v??[],eK=eV.length>0?`${eV.length} enabled`:"off",eY=eB.length>0&&!!eN&&!!c,eq=!!b,eX=!!f,eZ=eN??"Default",eG=(()=>{let e=y??"auto";if("auto"===e||!k)return e;let t=k[e];return null!=t?t:e})(),eQ=Object.entries(P).find(([,e])=>e===(g??"full"))?.[0]??"full",e0=ed?26:32,e1=ed?7:9,e2=ed?3:6,e5={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)"},e4=ed&&(F||V||q||Z||Q||et);(0,o.useEffect)(()=>{eH||ey(null)},[eH]);let e3=(0,o.useCallback)(e=>{if(!W.trim()){E(e),requestAnimationFrame(()=>{let t=eb.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eL(e)},[eL,W]),e8=(0,o.useCallback)(()=>{let t=W.trim();if(t||ei.length||es.length){if(ei.length&&!eA)return void ey("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!ei.length&&!es.length&&u){h?p?.():u(),E(""),eb.current&&(eb.current.style.height="auto");return}e(t,ei.length?ei:void 0,es.length?es:void 0),E(""),eP(),eb.current&&(eb.current.style.height="auto")}}},[W,ei,es,eA,l,e,eP,u,p,h]),e6=(0,o.useCallback)(e=>{let t=W.trim();if(!t&&!ei.length&&!es.length)return;if(ei.length&&!eA)return void ey("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=ei.length?ei:void 0,o=es.length?es:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),E(""),eP(),eb.current&&(eb.current.style.height="auto")},[W,ei,es,eA,r,i,eP]),e7=(0,o.useCallback)(e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),l&&(r||i)?e6(r?"steer":"followup"):e8())},[l,r,i,e6,e8]),e9=(0,o.useCallback)(()=>{let e=eb.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),te=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eW(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eW]);return(0,o.useEffect)(()=>{if(!F&&!V&&!q&&!Z&&!Q&&!et)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!ej.current?.contains(t),n=!!ek.current?.contains(t);r||n||U(!1),ew.current?.contains(t)||Y(!1),eS.current?.contains(t)||X(!1),eC.current?.contains(t)||G(!1),eT.current?.contains(t)||ee(!1),ez.current?.contains(t)||er(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[F,V,q,Z,Q,et]),(0,o.useEffect)(()=>{if(!f)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||eo(!!t?.ready)}).catch(()=>{e||eo(!1)}),()=>{e=!0}},[f]),(0,n.jsxs)("div",{style:ev,children:[e4&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{U(!1),Y(!1),X(!1),G(!1),ee(!1),er(!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:eI,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eR(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eM,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=>{eW(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:ed?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ed?"0 8px":void 0,boxSizing:"border-box"},children:[z&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:z}),w&&(0,n.jsxs)("div",{style:{marginBottom:ed?6:8,padding:ed?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ed?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 (",w.attempt,"/",w.maxAttempts,")…",w.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",w.errorMessage]})]}),(ei.length>0||es.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:[ei.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 ${eH?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eE(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}`)),es.map((e,t)=>(0,n.jsx)(H,{doc:e,onRemove:()=>e$(t)},`doc-${t}`))]}),(eH||em)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ed?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:em??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:ed?4:8,alignItems:ed?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ed?13:14,padding:ed?"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:eb,value:W,onChange:e=>E(e.target.value),onKeyDown:e7,onInput:e9,onPaste:te,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ed?"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:+!!ed,paddingBottom:+!!ed}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[!ed&&r&&(0,n.jsxs)("button",{onClick:()=>e6("steer"),disabled:!eF,title:eH?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:"7px 12px",background:eF?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eF?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eF?"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"})]}),"Steer"]}),!ed&&i&&(0,n.jsxs)("button",{onClick:()=>e6("followup"),disabled:!eF,title:eH?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:"7px 12px",background:eF?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eF?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eF?"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"})]}),"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:e8,disabled:!eF,title:eH?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ed?3:6,padding:ed?"5px 9px":"7px 14px",marginBottom:+!!ed,background:eF?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eF?"#fff":"var(--text-dim)",cursor:eF?"pointer":"not-allowed",fontSize:ed?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eF?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:ed?13:14,height:ed?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:ed?5:8,display:"flex",alignItems:ed?"flex-start":"center",gap:e2,flexWrap:ed?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ed?"1 1 100%":"0 0 auto",width:ed?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ed,flexWrap:ed?"wrap":"nowrap",rowGap:4*!!ed},children:[(0,n.jsx)("button",{onClick:()=>eI.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e0,height:e0,padding:0,background:"none",border:"none",borderRadius:e1,color:ei.length||es.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=ei.length||es.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ei.length||es.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eM.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||(Y(e=>!e),X(!1),U(!1),G(!1),ee(!1),er(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e0,height:e0,padding:0,background:V?"var(--bg-hover)":"none",border:"none",borderRadius:e1,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=V?"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"}})]}),V&&(0,n.jsxs)("div",{style:{...ed?e5:{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}),e_.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"}),e_.map(e=>(0,n.jsxs)("button",{onClick:()=>{(Y(!1),"/compact"===e.command&&h)?p?.():e3(e.command)},style:{display:"flex",alignItems:"center",gap:ed?6:8,width:"100%",padding:ep,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ed?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))]}),eJ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(e_.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:e_.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eJ.map(e=>(0,n.jsxs)("button",{onClick:()=>{Y(!1),e3(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ep,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ed?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))]})]})]}),m&&(0,n.jsxs)("div",{ref:eS,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(X(e=>!e),Y(!1),U(!1),G(!1),ee(!1),er(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:eu,padding:0,background:q?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:eV.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=eV.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=q?"var(--bg-hover)":"none",e.currentTarget.style.color=eV.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eV.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),q&&(0,n.jsxs)("div",{style:{...ed?e5:{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"}),C.map(e=>{let t=eV.includes(e),r=D[e];return(0,n.jsxs)("button",{onClick:()=>{m(t?eV.filter(t=>t!==e):[...eV,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ep,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ed?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)})]})]}),eY&&(0,n.jsxs)("div",{ref:ej,style:{position:"relative",flex:ed?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!ed){let t=e.currentTarget.getBoundingClientRect();J({top:t.top,left:t.left,width:t.width})}Y(!1),X(!1),G(!1),ee(!1),er(!1),U(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:ep,height:eu,width:ed?"100%":void 0,maxWidth:ed?"100%":220,overflow:"hidden",background:F?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ed?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=F?"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:eN})]}),F&&(ed?(0,n.jsxs)("div",{ref:ek,style:{...e5,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:eN})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eD.map((e,t)=>(0,n.jsxs)("div",{children:[eD.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:()=>{U(!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))})]}):_&&(L=(M=window.visualViewport?.height??window.innerHeight)-_.top+6,R=Math.max(120,Math.min(_.top-8,.6*M)),(0,n.jsx)("div",{ref:ek,style:{position:"fixed",bottom:L,left:_.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:_.width,maxHeight:R,overflowY:"auto"},children:eD.map((e,t)=>(0,n.jsxs)("div",{children:[eD.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:()=>{U(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ex?"none":void 0,flex:ed?"0 0 auto":1,width:ed?0:void 0,height:ed?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:ed?"1 1 100%":"0 0 auto",width:ed?"100%":void 0,display:"flex",alignItems:"center",justifyContent:ed?"space-between":void 0,gap:ed?4:2,marginLeft:ed?0:"auto",marginTop:2*!!ed},children:[ex&&(0,n.jsxs)("div",{ref:ez,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{Y(!1),X(!1),U(!1),G(!1),ee(!1),er(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:eg,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=et?"var(--bg-hover)":"none",e.currentTarget.style.color=et?"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"})]})}),et&&(0,n.jsxs)("div",{style:{...e5,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:[eY&&(0,n.jsxs)("button",{onClick:()=>{er(!1),ee(!1),G(!1),X(!1),U(!0)},style:ef,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:eZ})]}),(eq||eX)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[eq&&(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),G(!1),X(!1),ee(!0)},style:ef,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:eG})]}),eX&&(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),ee(!1),X(!1),G(!0)},style:ef,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:eQ})]})]}),!!m&&(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),ee(!1),G(!1),X(!0)},style:ef,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:eV.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eK})]})]})]})]}),(!ex&&!l||ed&&Q)&&b&&(0,n.jsxs)("div",{ref:eT,style:{position:"relative"},children:[!ex&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(Y(!1),X(!1),U(!1),G(!1),er(!1),ee(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:ep,height:eu,background:Q?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ed?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=Q?"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:ec,children:(()=>{let e=y??"auto";if("auto"===e||!k)return e;let t=k[e];return null!=t?t:e})()})]}),Q&&(0,n.jsx)("div",{style:{...ed?e5:{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:eh},overflow:"hidden"},children:N.filter(e=>!j||"auto"===e||j.includes(e)).map(e=>{let t=(y??"auto")===e,r=O[e],o="auto"!==e&&k?k[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{ee(!1),t||b(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:ed?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ex&&!l||ed&&Z)&&f&&(0,n.jsxs)("div",{ref:eC,style:{position:"relative"},children:[!ex&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(Y(!1),X(!1),U(!1),ee(!1),er(!1),G(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:ep,height:eu,background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ed?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.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:ec,children:Object.entries(P).find(([,e])=>e===(g??"full"))?.[0]??"full"})]}),Z&&(0,n.jsx)("div",{style:{...ed?e5:{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:$.map(e=>{let t=P[e],r=(g??"full")===t,o="agent"===e&&!1===en,i=o?"需安装 pi-subagents":B[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(G(!1),r||f(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:ed?11:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:eu,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ed?8:9,color:"#ef4444",cursor:"pointer",fontSize:ed?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),void 0!==T&&(0,n.jsx)("button",{onClick:T,title:S?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ed?28:32,height:ed?28:32,padding:0,background:"none",border:"none",borderRadius:ed?8:9,color:S?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:S?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=S?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=S?"1":"0.55"},children:S?(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 X({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,L=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${M}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=q(e.msg),r=x&&L===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=q(e.msg),i=L===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function Z(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function G(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function Q(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ee(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function et(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:G(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!Z(t))return{...e,summary:G(r)};let o=Array.isArray(t.results)?t.results.filter(Z):[],i=o[0],l=i?.progressSummary,s=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=Q(i?.finalOutput,i?.output,r);return{...e,mode:Q(t.mode),runId:Q(t.runId),agent:Q(i?.agent,e.agent)??e.agent,task:Q(i?.task,e.task),summary:G(a),model:Q(i?.model),durationMs:ee(l?.durationMs),toolCount:ee(l?.toolCount),tokens:ee(l?.tokens),outputPath:Q(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:Q(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:s,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return Z(t)&&Array.isArray(t.results)&&t.results.some(e=>Z(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 er({messages:e,runs:t}){let r=(0,o.useMemo)(()=>et(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),s=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(en,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(en,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function en({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)(eo,{run:e},e.id))]})}function eo({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(ei,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:G(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)(el,{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 el({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 es(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:r}}async function ea(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}function ed(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function ec(e){if("user"!==e.role)return null;var t=e.content;if("string"==typeof t)return`text:${t}`;if(!Array.isArray(t))try{return`other:${JSON.stringify(t)}`}catch{return"other:"}let r=t.map(e=>{if(!e||"object"!=typeof e)return e;if("text"===e.type)return{type:"text",text:e.text};if("image"===e.type){let t=e.source&&"object"==typeof e.source?e.source:{};return{type:"image",mimeType:t.media_type??e.mimeType,data:t.data??e.data,url:t.url}}return e});try{return`blocks:${JSON.stringify(r)}`}catch{return"blocks:"}}function eu(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let ep=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function eh(e){return ep.some(t=>e.type.startsWith(t))}var ex=r(51256);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."],ef=/\b(seurat|scanpy|single[- ]cell|scrna|sc[- ]rna|rna[- ]seq|transcriptom|gene|genes|marker|cell type|cluster|clustering|umap|tsne|pca|qc|mitochondrial|percent\.mt|nfeature|ncount|deg|differential expression|go enrichment|kegg|reactome|pathway|gsea|volcano|heatmap|h5ad|rds|loom|mtx|fastq|bam|vcf|counts?|expression|annotation|doublet|batch|integration|harmony|scvi)\b|生信|单细胞|转录组|基因|表达矩阵|差异表达|富集|通路|聚类|细胞类型|细胞注释|质控|线粒体|标记基因|火山图|热图/i,ev=/(?:^|[\s(["'`])(?:\.{1,2}\/|\/|~\/)?[A-Za-z0-9_.@+\-/\\]+\/\s*(?:[::-]|[0-9]+|含|共|files?|个文件|PDFs?|PNGs?|输出|output|results?)/im,em=/\.(?:csv|tsv|xlsx|xls|pdf|png|jpg|jpeg|svg|html|r|R|py|rds|h5ad|loom|mtx|tsv\.gz|csv\.gz)\b/i;function ey({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(s||i!==o)if(s&&""===i)a(!1),r(t=>(t+1)%e.length);else{let e=s?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[i,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eb({status:e}){let t=e?.current??"0.8.38"??"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 ej(e){let t=e.content;return"string"==typeof t?t:Array.isArray(t)?t.map(e=>"text"===e.type?e.text:"toolCall"===e.type?`${e.toolName} ${JSON.stringify(e.input)}`:"").join("\n"):""}function ek({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSystemPromptChange:u,onSessionStatsChange:p,onContextUsageChange:h,onReportUpdated:x,generativeUI:g}){var f;let v,{data:m,loading:y,error:b,messages:j,entryIds:k,streamState:T,activeLeafId:W,agentRunning:$,modelNames:P,modelList:B,modelThinkingLevels:D,modelThinkingLevelMaps:N,toolPreset:O,memoryTools:A,thinkingLevel:H,retryInfo:F,contextUsage:U,forkingEntryId:_,isCompacting:J,compactError:V,displayModel:K,sessionStats:q,agentPhase:Z,agentError:G,isNew:Q,messagesEndRef:ee,scrollContainerRef:en,lastUserMsgRef:eo,handleSend:ei,handleAbort:el,handleFork:ep,handleNavigate:ew,handleModelChange:eS,handleCompact:eC,handleSteer:eT,handleFollowUp:ez,handleAbortCompaction:eI,handleToolPresetChange:eM,handleMemoryToolsChange:eL,handleThinkingLevelChange:eR,handleAgentEventRef:eW}=function(e){let{session:t,newSessionCwd:r,onAgentEnd:n,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:a,onSystemPromptChange:d}=e,c=null===t&&null!==r,[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(!c),[g,f]=(0,o.useState)(null),[v,m]=(0,o.useState)(null),[y,b]=(0,o.useState)([]),[j,k]=(0,o.useState)([]),[w,T]=(0,o.useReducer)(ed,{isStreaming:!1,streamingMessage:null}),[W,$]=(0,o.useState)(!1),[P,B]=(0,o.useState)({}),[D,N]=(0,o.useState)([]),[O,A]=(0,o.useState)({}),[H,F]=(0,o.useState)({}),[U,_]=(0,o.useState)(null),[J,V]=(0,o.useState)("full"),[K,Y]=(0,o.useState)([]),[q,X]=(0,o.useState)("auto"),[Z,G]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(null),[et,er]=(0,o.useState)(null),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)(null),[ep,eh]=(0,o.useState)(null),[ex,eg]=(0,o.useState)(!1),[ef,ev]=(0,o.useState)(null),[em,ey]=(0,o.useState)(null),[eb,ej]=(0,o.useState)(null),ek=(0,o.useRef)(null),ew=(0,o.useRef)(t?.id??null),eS=(0,o.useRef)(!1),eC=(0,o.useRef)(null),eT=(0,o.useRef)(!1),ez=(0,o.useRef)(null),eI=(0,o.useRef)(!1),eM=(0,o.useRef)(null),eL=(0,o.useRef)(null),eR=(0,o.useRef)(new Map),eW=(0,o.useRef)(new Set),eE=e.setNewSessionModel??_,e$=e.setToolPreset??V,eP=e.setMemoryTools??Y,eB=ei??u?.context.model??ep??null,eD=c?U:eB,eN=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
6
+ [truncated after 60000 characters]`,truncated:!0};if(!i)return{extractionError:"No extractable text found"};return{extractedText:i,truncated:l}}catch(e){return{extractionError:e instanceof Error?e.message:String(e)}}}let Y=(0,o.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:i,isStreaming:l,model:s,modelNames:a,modelList:d,onModelChange:c,onCompact:u,onAbortCompaction:p,isCompacting:h,compactError:x,toolPreset:g,onToolPresetChange:f,memoryTools:v,onMemoryToolsChange:m,thinkingLevel:y,onThinkingLevelChange:b,availableThinkingLevels:j,thinkingLevelMap:k,retryInfo:w,soundEnabled:S,onSoundToggle:T,cornerBadge:z},I){let M,L,R,[W,E]=(0,o.useState)(""),[F,U]=(0,o.useState)(!1),[_,J]=(0,o.useState)(null),[V,Y]=(0,o.useState)(!1),[q,X]=(0,o.useState)(!1),[Z,G]=(0,o.useState)(!1),[Q,ee]=(0,o.useState)(!1),[et,er]=(0,o.useState)(!1),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)([]),[es,ea]=(0,o.useState)([]),ed=function(e=768){let[t,r]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(`(max-width: ${e}px)`),n=()=>r(t.matches);return n(),t.addEventListener?.("change",n),()=>t.removeEventListener?.("change",n)},[e]),t}(),ec=ed?{display:"none"}:void 0,eu=ed?28:32,ep=ed?"6px 8px":"8px 12px",eh=ed?160:180,ex=ed&&!l,eg=et?"var(--text)":"var(--text-muted)",ef={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},ev=ed?{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},[em,ey]=(0,o.useState)(null),eb=(0,o.useRef)(null),ej=(0,o.useRef)(null),ek=(0,o.useRef)(null),ew=(0,o.useRef)(null),eS=(0,o.useRef)(null),eC=(0,o.useRef)(null),eT=(0,o.useRef)(null),ez=(0,o.useRef)(null),eI=(0,o.useRef)(null),eM=(0,o.useRef)(null),eL=(0,o.useCallback)(e=>{let t=eb.current;if(!t)return void E(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,o=t.value.slice(0,r),i=t.value.slice(n),l=!(o.length>0)||o.endsWith(" ")||o.endsWith("\n")?"":" ";E(o+l+e+i),requestAnimationFrame(()=>{let t=eb.current;if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},[]);(0,o.useImperativeHandle)(I,()=>({insertIfEmpty(e){let t=eb.current;(t?t.value:W).trim()||(E(e),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},insertText(e){eL(e)},addImages(e){eR(e)},addFiles(e){eW(e)}}));let eR=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/"));if(!t.length)return;let r=await Promise.all(t.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=()=>{t({data:n.result.split(",")[1],mimeType:e.type,previewUrl:URL.createObjectURL(e)})},n.onerror=r,n.readAsDataURL(e)})));el(e=>[...e,...r])},[]),eW=(0,o.useCallback)(async e=>{let t=e.filter(e=>e.type.startsWith("image/")),r=e.filter(e=>!e.type.startsWith("image/"));if(t.length&&eR(t),r.length){let e=await Promise.all(r.map(e=>new Promise((t,r)=>{let n=new FileReader;n.onload=async()=>{let r=n.result,o=await K(e,r);t({data:r,fileName:e.name,mimeType:e.type||"application/octet-stream",size:e.size,...o})},n.onerror=r,n.readAsArrayBuffer(e)})));ea(t=>[...t,...e])}},[eR]),eE=(0,o.useCallback)(e=>{el(t=>{let r=[...t];return URL.revokeObjectURL(r[e].previewUrl),r.splice(e,1),r})},[]),e$=(0,o.useCallback)(e=>{ea(t=>{let r=[...t];return r.splice(e,1),r})},[]),eP=(0,o.useCallback)(()=>{el(e=>(e.forEach(e=>URL.revokeObjectURL(e.previewUrl)),[])),ea([])},[]),eB=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})),eD=[];for(let e of eB){let t=eD.find(t=>t.provider===e.provider);t?t.options.push(e):eD.push({provider:e.provider,options:[e]})}let eN=s?eB.find(e=>e.modelId===s.modelId&&e.provider===s.provider)?.name??s.modelId:eB.length>0?eB[0].name:null,eO=s?eB.find(e=>e.modelId===s.modelId&&e.provider===s.provider):eB[0],eA=eO?.input?.includes("image")??!0,eH=ei.length>0&&eO?.input!==void 0&&!eA,eF=(!!W.trim()||ei.length>0||es.length>0)&&!eH,eU=u?A:A.filter(e=>"/compact"!==e.command),e_=eU.filter(e=>"native"===e.kind),eJ=eU.filter(e=>"shortcut"===e.kind),eV=v??[],eK=eV.length>0?`${eV.length} enabled`:"off",eY=eB.length>0&&!!eN&&!!c,eq=!!b,eX=!!f,eZ=eN??"Default",eG=(()=>{let e=y??"auto";if("auto"===e||!k)return e;let t=k[e];return null!=t?t:e})(),eQ=Object.entries(P).find(([,e])=>e===(g??"full"))?.[0]??"full",e0=ed?26:32,e1=ed?7:9,e2=ed?3:6,e5={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)"},e4=ed&&(F||V||q||Z||Q||et);(0,o.useEffect)(()=>{eH||ey(null)},[eH]);let e3=(0,o.useCallback)(e=>{if(!W.trim()){E(e),requestAnimationFrame(()=>{let t=eb.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)});return}eL(e)},[eL,W]),e8=(0,o.useCallback)(()=>{let t=W.trim();if(t||ei.length||es.length){if(ei.length&&!eA)return void ey("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!l){if("/compact"===t&&!ei.length&&!es.length&&u){h?p?.():u(),E(""),eb.current&&(eb.current.style.height="auto");return}e(t,ei.length?ei:void 0,es.length?es:void 0),E(""),eP(),eb.current&&(eb.current.style.height="auto")}}},[W,ei,es,eA,l,e,eP,u,p,h]),e6=(0,o.useCallback)(e=>{let t=W.trim();if(!t&&!ei.length&&!es.length)return;if(ei.length&&!eA)return void ey("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let n=ei.length?ei:void 0,o=es.length?es:void 0;"steer"===e&&r?r(t,n,o):"followup"===e&&i&&i(t,n,o),E(""),eP(),eb.current&&(eb.current.style.height="auto")},[W,ei,es,eA,r,i,eP]),e7=(0,o.useCallback)(e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),l&&(r||i)?e6(r?"steer":"followup"):e8())},[l,r,i,e6,e8]),e9=(0,o.useCallback)(()=>{let e=eb.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),te=(0,o.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&(e.type.startsWith("image/")||e.type.includes("pdf")||e.type.includes("officedocument")||e.type.includes("msword")||e.type.includes("ms-")));t.length&&(e.preventDefault(),eW(t.map(e=>e.getAsFile()).filter(e=>null!==e)))},[eW]);return(0,o.useEffect)(()=>{if(!F&&!V&&!q&&!Z&&!Q&&!et)return;let e=e=>{let t=e.target;if(!(t instanceof Node))return;let r=!!ej.current?.contains(t),n=!!ek.current?.contains(t);r||n||U(!1),ew.current?.contains(t)||Y(!1),eS.current?.contains(t)||X(!1),eC.current?.contains(t)||G(!1),eT.current?.contains(t)||ee(!1),ez.current?.contains(t)||er(!1)};return document.addEventListener("pointerdown",e,!0),()=>{document.removeEventListener("pointerdown",e,!0)}},[F,V,q,Z,Q,et]),(0,o.useEffect)(()=>{if(!f)return;let e=!1;return fetch("/api/subagents/status").then(e=>e.ok?e.json():null).then(t=>{e||eo(!!t?.ready)}).catch(()=>{e||eo(!1)}),()=>{e=!0}},[f]),(0,n.jsxs)("div",{style:ev,children:[e4&&(0,n.jsx)("div",{"aria-hidden":!0,onClick:()=>{U(!1),Y(!1),X(!1),G(!1),ee(!1),er(!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:eI,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{eR(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsx)("input",{ref:eM,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=>{eW(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:ed?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ed?"0 8px":void 0,boxSizing:"border-box"},children:[z&&(0,n.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:z}),w&&(0,n.jsxs)("div",{style:{marginBottom:ed?6:8,padding:ed?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ed?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 (",w.attempt,"/",w.maxAttempts,")…",w.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",w.errorMessage]})]}),(ei.length>0||es.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:[ei.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 ${eH?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,n.jsx)("button",{onClick:()=>eE(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}`)),es.map((e,t)=>(0,n.jsx)(H,{doc:e,onRemove:()=>e$(t)},`doc-${t}`))]}),(eH||em)&&(0,n.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ed?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:em??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:ed?4:8,alignItems:ed?"flex-end":"center",background:"var(--bg)",border:`1px solid ${l&&(r||i)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ed?13:14,padding:ed?"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:eb,value:W,onChange:e=>E(e.target.value),onKeyDown:e7,onInput:e9,onPaste:te,placeholder:l&&(r||i)?"Steer 立即注入 / Follow-up 排队…":l?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ed?"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:+!!ed,paddingBottom:+!!ed}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[!ed&&r&&(0,n.jsxs)("button",{onClick:()=>e6("steer"),disabled:!eF,title:eH?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:"7px 12px",background:eF?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:eF?"rgba(180,130,0,1)":"var(--text-dim)",cursor:eF?"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"})]}),"Steer"]}),!ed&&i&&(0,n.jsxs)("button",{onClick:()=>e6("followup"),disabled:!eF,title:eH?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:"7px 12px",background:eF?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:eF?"rgba(99,102,241,1)":"var(--text-dim)",cursor:eF?"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"})]}),"Follow-up"]})]}):(0,n.jsxs)("button",{onClick:e8,disabled:!eF,title:eH?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ed?3:6,padding:ed?"5px 9px":"7px 14px",marginBottom:+!!ed,background:eF?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:eF?"#fff":"var(--text-dim)",cursor:eF?"pointer":"not-allowed",fontSize:ed?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:eF?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,n.jsxs)("svg",{width:ed?13:14,height:ed?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:ed?5:8,display:"flex",alignItems:ed?"flex-start":"center",gap:e2,flexWrap:ed?"wrap":"nowrap"},children:[(0,n.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ed?"1 1 100%":"0 0 auto",width:ed?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ed,flexWrap:ed?"wrap":"nowrap",rowGap:4*!!ed},children:[(0,n.jsx)("button",{onClick:()=>eI.current?.click(),disabled:l,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e0,height:e0,padding:0,background:"none",border:"none",borderRadius:e1,color:ei.length||es.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=ei.length||es.length?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ei.length||es.length?"var(--accent)":"var(--text-muted)"},onContextMenu:e=>{e.preventDefault(),eM.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||(Y(e=>!e),X(!1),U(!1),G(!1),ee(!1),er(!1))},disabled:l,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:e0,height:e0,padding:0,background:V?"var(--bg-hover)":"none",border:"none",borderRadius:e1,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=V?"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"}})]}),V&&(0,n.jsxs)("div",{style:{...ed?e5:{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}),e_.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"}),e_.map(e=>(0,n.jsxs)("button",{onClick:()=>{(Y(!1),"/compact"===e.command&&h)?p?.():e3(e.command)},style:{display:"flex",alignItems:"center",gap:ed?6:8,width:"100%",padding:ep,background:"none",border:"none",color:"/compact"===e.command&&h?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ed?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))]}),eJ.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{marginTop:2*(e_.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:e_.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),eJ.map(e=>(0,n.jsxs)("button",{onClick:()=>{Y(!1),e3(e.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ep,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ed?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))]})]})]}),m&&(0,n.jsxs)("div",{ref:eS,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>{l||(X(e=>!e),Y(!1),U(!1),G(!1),ee(!1),er(!1))},disabled:l,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:eu,padding:0,background:q?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:eV.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=eV.length>0?"var(--accent)":"var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=q?"var(--bg-hover)":"none",e.currentTarget.style.color=eV.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),eV.length>0&&(0,n.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),q&&(0,n.jsxs)("div",{style:{...ed?e5:{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"}),C.map(e=>{let t=eV.includes(e),r=D[e];return(0,n.jsxs)("button",{onClick:()=>{m(t?eV.filter(t=>t!==e):[...eV,e])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:ep,background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ed?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)})]})]}),eY&&(0,n.jsxs)("div",{ref:ej,style:{position:"relative",flex:ed?"1 1 160px":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{if(!ed){let t=e.currentTarget.getBoundingClientRect();J({top:t.top,left:t.left,width:t.width})}Y(!1),X(!1),G(!1),ee(!1),er(!1),U(e=>!e)},disabled:l,style:{display:"flex",alignItems:"center",gap:6,padding:ep,height:eu,width:ed?"100%":void 0,maxWidth:ed?"100%":220,overflow:"hidden",background:F?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ed?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=F?"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:eN})]}),F&&(ed?(0,n.jsxs)("div",{ref:ek,style:{...e5,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:eN})]}),(0,n.jsx)("div",{style:{overflowY:"auto"},children:eD.map((e,t)=>(0,n.jsxs)("div",{children:[eD.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:()=>{U(!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))})]}):_&&(L=(M=window.visualViewport?.height??window.innerHeight)-_.top+6,R=Math.max(120,Math.min(_.top-8,.6*M)),(0,n.jsx)("div",{ref:ek,style:{position:"fixed",bottom:L,left:_.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:_.width,maxHeight:R,overflowY:"auto"},children:eD.map((e,t)=>(0,n.jsxs)("div",{children:[eD.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:()=>{U(!1),t||c(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0},children:e.name}),e.input?.includes("image")&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${e.provider}:${e.modelId}`)})]},e.provider))})))]})]}),(0,n.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:ex?"none":void 0,flex:ed?"0 0 auto":1,width:ed?0:void 0,height:ed?0:void 0}}),(0,n.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:ed?"1 1 100%":"0 0 auto",width:ed?"100%":void 0,display:"flex",alignItems:"center",justifyContent:ed?"space-between":void 0,gap:ed?4:2,marginLeft:ed?0:"auto",marginTop:2*!!ed},children:[ex&&(0,n.jsxs)("div",{ref:ez,style:{position:"relative"},children:[(0,n.jsx)("button",{onClick:()=>{Y(!1),X(!1),U(!1),G(!1),ee(!1),er(e=>!e)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:et?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:eg,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=et?"var(--bg-hover)":"none",e.currentTarget.style.color=et?"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"})]})}),et&&(0,n.jsxs)("div",{style:{...e5,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:[eY&&(0,n.jsxs)("button",{onClick:()=>{er(!1),ee(!1),G(!1),X(!1),U(!0)},style:ef,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:eZ})]}),(eq||eX)&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[eq&&(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),G(!1),X(!1),ee(!0)},style:ef,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:eG})]}),eX&&(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),ee(!1),X(!1),G(!0)},style:ef,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:eQ})]})]}),!!m&&(0,n.jsxs)("button",{onClick:()=>{er(!1),U(!1),ee(!1),G(!1),X(!0)},style:ef,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:eV.length>0?"var(--accent)":"var(--text)",marginTop:2},children:eK})]})]})]})]}),(!ex&&!l||ed&&Q)&&b&&(0,n.jsxs)("div",{ref:eT,style:{position:"relative"},children:[!ex&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(Y(!1),X(!1),U(!1),G(!1),er(!1),ee(e=>!e))},disabled:l,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:ep,height:eu,background:Q?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ed?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=Q?"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:ec,children:(()=>{let e=y??"auto";if("auto"===e||!k)return e;let t=k[e];return null!=t?t:e})()})]}),Q&&(0,n.jsx)("div",{style:{...ed?e5:{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:eh},overflow:"hidden"},children:N.filter(e=>!j||"auto"===e||j.includes(e)).map(e=>{let t=(y??"auto")===e,r=O[e],o="auto"!==e&&k?k[e]:void 0,i=null!=o&&o!==e?o:e,l=null!=o&&o!==e;return(0,n.jsxs)("button",{onClick:()=>{ee(!1),t||b(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:ed?11:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[i,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),(!ex&&!l||ed&&Z)&&f&&(0,n.jsxs)("div",{ref:eC,style:{position:"relative"},children:[!ex&&!l&&(0,n.jsxs)("button",{onClick:()=>{l||(Y(!1),X(!1),U(!1),ee(!1),er(!1),G(e=>!e))},disabled:l,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ed?3:5,padding:ep,height:eu,background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:ed?8:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:ed?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.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:ec,children:Object.entries(P).find(([,e])=>e===(g??"full"))?.[0]??"full"})]}),Z&&(0,n.jsx)("div",{style:{...ed?e5:{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:$.map(e=>{let t=P[e],r=(g??"full")===t,o="agent"===e&&!1===en,i=o?"需安装 pi-subagents":B[e];return(0,n.jsxs)("button",{onClick:()=>{!o&&(G(!1),r||f(t))},disabled:o,title:o?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:r?"var(--bg-selected)":"none",border:"none",color:r?"var(--text)":"var(--text-muted)",cursor:o?"not-allowed":"pointer",fontSize:ed?11:12,textAlign:"left",fontWeight:r?600:400,opacity:o?.5:1,whiteSpace:"nowrap"},onMouseEnter:e=>{r||o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[r?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:i})]},e)})})]}),l&&(0,n.jsxs)("button",{onClick:t,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:eu,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ed?8:9,color:"#ef4444",cursor:"pointer",fontSize:ed?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),void 0!==T&&(0,n.jsx)("button",{onClick:T,title:S?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ed?28:32,height:ed?28:32,padding:0,background:"none",border:"none",borderRadius:ed?8:9,color:S?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:S?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=S?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=S?"1":"0.55"},children:S?(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 X({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:i}){let[l,s]=(0,o.useState)(0),[a,d]=(0,o.useState)(1),[c,u]=(0,o.useState)(!1),[p,h]=(0,o.useState)([]),[x,g]=(0,o.useState)(!1),[f,v]=(0,o.useState)(null),m=(0,o.useRef)(!1),y=(0,o.useRef)(null),b=(0,o.useMemo)(()=>t?[...e,t]:e,[e,t]),j=(0,o.useRef)(b);j.current=b;let k=(0,o.useRef)(null);k.current=()=>{let e=r.current;if(!e)return;let t=e.scrollHeight,n=e.clientHeight,o=t-n;u(o>20),o<=0?(s(0),d(1)):(s(e.scrollTop/o),d(n/t));let l=i.current,a=[],c=0,p=j.current;for(let r=0;r<p.length;r++){let n=p[r];if("user"!==n.role&&"assistant"!==n.role)continue;let o=l?.[c];if(c++,("user"===n.role||"assistant"===n.role&&(n.content??[]).some(e=>"text"===e.type))&&o&&t>0){let r=o.getBoundingClientRect(),i=e.getBoundingClientRect(),l=r.top-i.top+e.scrollTop,s=r.height;a.push({topRatio:l/t,heightRatio:s/t,msg:n,index:a.length})}}h(a)};let w=(0,o.useCallback)(()=>k.current(),[]);(0,o.useEffect)(()=>{let e=r.current;if(!e)return;e.addEventListener("scroll",w,{passive:!0});let t=new ResizeObserver(w);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),w(),()=>{e.removeEventListener("scroll",w),t.disconnect()}},[r,w]),(0,o.useEffect)(()=>{let e=setTimeout(w,50);return()=>clearTimeout(e)},[e.length,w]);let S=(0,o.useCallback)(e=>{let t=r.current;if(!t)return;let n=t.scrollHeight-t.clientHeight;n<=0||(t.scrollTop=Math.max(0,Math.min(1-a,e))/(1-a)*n)},[r,a]),C=(0,o.useCallback)(e=>{if(!c)return;m.current=!0;let t=e.currentTarget.getBoundingClientRect(),r=(e.clientY-t.top)/t.height,n=r-l*(1-a),o=n>=0&&n<=a?n:a/2;S(r-o);let i=e=>{m.current&&S((e.clientY-t.top)/t.height-o)},s=()=>{m.current=!1,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},[c,a,l,S]),T=y.current?.clientHeight??600,z=(0,o.useMemo)(()=>{if(!x||0===p.length)return[];let e=p.map(e=>Math.round(e.topRatio*T-11));for(let t=0;t<10;t++){for(let t=1;t<e.length;t++){let r=e[t-1]+22+2;e[t]<r&&(e[t]=r)}for(let t=e.length-2;t>=0;t--){let r=e[t+1]-22-2;e[t]>r&&(e[t]=r)}}for(let t=0;t<e.length;t++)e[t]=Math.max(0,Math.min(T-22,e[t]));return e},[x,p,T]);if(!c)return null;let I=l*(1-a)*100,M=100*a,L=null!==f&&p.length>0?p.reduce((e,t)=>Math.abs(t.topRatio-f)<Math.abs(p[e].topRatio-f)?t.index:e,0):null;return(0,n.jsxs)("div",{ref:y,onMouseDown:C,onMouseEnter:()=>g(!0),onMouseLeave:()=>{g(!1),v(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${I}%`,height:`${M}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),p.map(e=>{let t=q(e.msg),r=x&&L===e.index,o="user"===e.msg.role,i=100*e.topRatio;return(0,n.jsx)("div",{style:{position:"absolute",top:`${i}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,n.jsx)("div",{style:{width:o?8:6,height:o?8:6,borderRadius:o?2:"50%",background:t.bg,border:`1.5px solid ${t.border}`,flexShrink:0,transition:"transform 0.1s",transform:r?"scale(1.6)":"scale(1)"}})},e.index)}),(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),x&&p.map((e,t)=>{let r=function(e){if("user"===e.role){let t=e.content;return"string"==typeof t?t.slice(0,200):Array.isArray(t)?t.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("\n").slice(0,200):""}if("assistant"===e.role){let t=e.content??[],r=t.filter(e=>"text"===e.type).map(e=>e.text).join(" ");if(r)return r.slice(0,200);let n=t.filter(e=>"toolCall"===e.type).map(e=>e.toolName);if(n.length)return n.join(", ")}return""}(e.msg),o=q(e.msg),i=L===e.index;return r&&0!==z.length?(0,n.jsx)("div",{style:{position:"absolute",top:z[t],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${i?o.border:"var(--border)"}`,borderRight:`1px solid ${i?o.border:"var(--border)"}`,borderBottom:`1px solid ${i?o.border:"var(--border)"}`,borderLeft:`2px solid ${o.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:i?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,n.jsx)("div",{style:{fontSize:11,color:i?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r})},e.index):null})]})}function Z(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function G(e,t=220){if(!e)return;let r=e.trim();if(r)return r.length>t?`${r.slice(0,t)}...`:r}function Q(...e){for(let t of e)if("string"==typeof t&&t.trim())return t}function ee(...e){for(let t of e)if("number"==typeof t&&Number.isFinite(t))return t}function et(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:G(r.content.split("\n").slice(3).join("\n")),timestamp:r.timestamp})}}if("assistant"===r.role){let e=r.content;if(!e)continue;for(let n of e)if("toolCall"===n.type&&"subagent"===n.toolName&&n.input){let e=n.input,o=e.agent??(e.chain?"chain":e.tasks?"parallel":e.action??"subagent"),i="string"==typeof e.task?e.task:void 0,l=n.toolCallId??`sub-${o}-${r.timestamp??Date.now()}`;t.set(l,{id:l,agent:o,status:"running",task:i,timestamp:r.timestamp})}}if("toolResult"===r.role){if(r.toolName&&"subagent"!==r.toolName||!r.toolCallId||!t.has(r.toolCallId))continue;let e=t.get(r.toolCallId),n=r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n");t.set(r.toolCallId,function(e,t,r){let n;if(!Z(t))return{...e,summary:G(r)};let o=Array.isArray(t.results)?t.results.filter(Z):[],i=o[0],l=i?.progressSummary,s=i&&(n=i.artifactPaths)?Object.values(n).filter(e=>"string"==typeof e&&e.trim().length>0):[],a=Q(i?.finalOutput,i?.output,r);return{...e,mode:Q(t.mode),runId:Q(t.runId),agent:Q(i?.agent,e.agent)??e.agent,task:Q(i?.task,e.task),summary:G(a),model:Q(i?.model),durationMs:ee(l?.durationMs),toolCount:ee(l?.toolCount),tokens:ee(l?.tokens),outputPath:Q(i?.savedOutputPath,i?.artifactPaths?.outputPath),sessionFile:Q(i?.sessionFile,i?.artifactPaths?.jsonlPath),artifacts:s,resultCount:o.length||void 0}}({...e,status:function(e){if(e.isError)return"failed";let t=e.details;return Z(t)&&Array.isArray(t.results)&&t.results.some(e=>Z(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 er({messages:e,runs:t}){let r=(0,o.useMemo)(()=>et(e??[]),[e]),i=t??r,l=i.filter(e=>"running"===e.status),s=i.filter(e=>"running"!==e.status);return 0===i.length?null:(0,n.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[l.length>0&&(0,n.jsx)(en,{title:`Active (${l.length})`,runs:l}),s.length>0&&(0,n.jsx)(en,{title:`Completed (${s.length})`,runs:s,compact:l.length>0})]})}function en({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)(eo,{run:e},e.id))]})}function eo({run:e}){let[t,r]=(0,o.useState)(!1),i="running"===e.status,l="completed"===e.status?"#22c55e":"failed"===e.status?"#ef4444":i?"var(--accent)":"var(--text-dim)",s="failed"===e.status?"rgba(248,113,113,0.35)":i?"rgba(99,102,241,0.25)":"var(--border)",a="failed"===e.status?"rgba(248,113,113,0.05)":i?"rgba(99,102,241,0.05)":"var(--bg-panel)",d=[e.mode,e.resultCount&&e.resultCount>1?`${e.resultCount} results`:void 0,void 0!==e.toolCount?`${e.toolCount} tools`:void 0,void 0!==e.tokens?`${e.tokens.toLocaleString()} tok`:void 0,void 0!==e.durationMs?`${Math.round(e.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),c=!!(e.summary||e.outputPath||e.sessionFile||e.artifacts?.length||e.model||e.runId);return(0,n.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${s}`,background:a,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,n.jsxs)("button",{onClick:()=>c&&r(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:c?"pointer":"default"},children:[(0,n.jsx)(ei,{running:i,color:l}),(0,n.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.agent}),(0,n.jsx)("span",{style:{color:l,fontSize:10,fontWeight:700,flexShrink:0},children:e.status}),d&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:d}),c&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:t?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),e.task&&(0,n.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:G(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)(el,{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 el({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 es(e){if("assistant"!==e.role)return e;let t=e.content;if(!Array.isArray(t))return e;let r=t.map(e=>("object"!=typeof e||null===e||Array.isArray(e)||"toolCall"!==e.type?null:{type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input})??e);return{...e,content:r}}async function ea(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.data}function ed(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:t.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return e}}function ec(e){if("user"!==e.role)return null;var t=e.content;if("string"==typeof t)return`text:${t}`;if(!Array.isArray(t))try{return`other:${JSON.stringify(t)}`}catch{return"other:"}let r=t.map(e=>{if(!e||"object"!=typeof e)return e;if("text"===e.type)return{type:"text",text:e.text};if("image"===e.type){let t=e.source&&"object"==typeof e.source?e.source:{};return{type:"image",mimeType:t.media_type??e.mimeType,data:t.data??e.data,url:t.url}}return e});try{return`blocks:${JSON.stringify(r)}`}catch{return"blocks:"}}function eu(e){if(!e.role)return null;try{return`${e.role}:${JSON.stringify(e)}`}catch{return null}}let ep=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function eh(e){return ep.some(t=>e.type.startsWith(t))}var ex=r(51256);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."],ef=/\b(seurat|scanpy|single[- ]cell|scrna|sc[- ]rna|rna[- ]seq|transcriptom|gene|genes|marker|cell type|cluster|clustering|umap|tsne|pca|qc|mitochondrial|percent\.mt|nfeature|ncount|deg|differential expression|go enrichment|kegg|reactome|pathway|gsea|volcano|heatmap|h5ad|rds|loom|mtx|fastq|bam|vcf|counts?|expression|annotation|doublet|batch|integration|harmony|scvi)\b|生信|单细胞|转录组|基因|表达矩阵|差异表达|富集|通路|聚类|细胞类型|细胞注释|质控|线粒体|标记基因|火山图|热图/i,ev=/(?:^|[\s(["'`])(?:\.{1,2}\/|\/|~\/)?[A-Za-z0-9_.@+\-/\\]+\/\s*(?:[::-]|[0-9]+|含|共|files?|个文件|PDFs?|PNGs?|输出|output|results?)/im,em=/\.(?:csv|tsv|xlsx|xls|pdf|png|jpg|jpeg|svg|html|r|R|py|rds|h5ad|loom|mtx|tsv\.gz|csv\.gz)\b/i;function ey({phrases:e}){let[t,r]=(0,o.useState)(()=>Math.floor(Math.random()*e.length)),[i,l]=(0,o.useState)(""),[s,a]=(0,o.useState)(!1),[d,c]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{let e=setInterval(()=>c(e=>!e),530);return()=>clearInterval(e)},[]),(0,o.useEffect)(()=>{let n,o=e[t];if(s||i!==o)if(s&&""===i)a(!1),r(t=>(t+1)%e.length);else{let e=s?o.slice(0,i.length-1):o.slice(0,i.length+1);n=setTimeout(()=>l(e),s?28:55)}else n=setTimeout(()=>a(!0),1800);return()=>clearTimeout(n)},[i,s,t,e]),(0,n.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[i,(0,n.jsx)("span",{style:{opacity:+!!d,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function eb({status:e}){let t=e?.current??"0.8.39"??"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 ej(e){let t=e.content;return"string"==typeof t?t:Array.isArray(t)?t.map(e=>"text"===e.type?e.text:"toolCall"===e.type?`${e.toolName} ${JSON.stringify(e.input)}`:"").join("\n"):""}function ek({session:e,newSessionCwd:t,onAgentEnd:r,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,chatInputRef:a,onBranchDataChange:d,onSystemPromptChange:u,onSessionStatsChange:p,onContextUsageChange:h,onReportUpdated:x,generativeUI:g}){var f;let v,{data:m,loading:y,error:b,messages:j,entryIds:k,streamState:T,activeLeafId:W,agentRunning:$,modelNames:P,modelList:B,modelThinkingLevels:D,modelThinkingLevelMaps:N,toolPreset:O,memoryTools:A,thinkingLevel:H,retryInfo:F,contextUsage:U,forkingEntryId:_,isCompacting:J,compactError:V,displayModel:K,sessionStats:q,agentPhase:Z,agentError:G,isNew:Q,messagesEndRef:ee,scrollContainerRef:en,lastUserMsgRef:eo,handleSend:ei,handleAbort:el,handleFork:ep,handleNavigate:ew,handleModelChange:eS,handleCompact:eC,handleSteer:eT,handleFollowUp:ez,handleAbortCompaction:eI,handleToolPresetChange:eM,handleMemoryToolsChange:eL,handleThinkingLevelChange:eR,handleAgentEventRef:eW}=function(e){let{session:t,newSessionCwd:r,onAgentEnd:n,onSessionCreated:i,onSessionForked:l,modelsRefreshKey:s,onBranchDataChange:a,onSystemPromptChange:d}=e,c=null===t&&null!==r,[u,p]=(0,o.useState)(null),[h,x]=(0,o.useState)(!c),[g,f]=(0,o.useState)(null),[v,m]=(0,o.useState)(null),[y,b]=(0,o.useState)([]),[j,k]=(0,o.useState)([]),[w,T]=(0,o.useReducer)(ed,{isStreaming:!1,streamingMessage:null}),[W,$]=(0,o.useState)(!1),[P,B]=(0,o.useState)({}),[D,N]=(0,o.useState)([]),[O,A]=(0,o.useState)({}),[H,F]=(0,o.useState)({}),[U,_]=(0,o.useState)(null),[J,V]=(0,o.useState)("full"),[K,Y]=(0,o.useState)([...C]),[q,X]=(0,o.useState)("auto"),[Z,G]=(0,o.useState)(null),[Q,ee]=(0,o.useState)(null),[et,er]=(0,o.useState)(null),[en,eo]=(0,o.useState)(null),[ei,el]=(0,o.useState)(null),[ep,eh]=(0,o.useState)(null),[ex,eg]=(0,o.useState)(!1),[ef,ev]=(0,o.useState)(null),[em,ey]=(0,o.useState)(null),[eb,ej]=(0,o.useState)(null),ek=(0,o.useRef)(null),ew=(0,o.useRef)(t?.id??null),eS=(0,o.useRef)(!1),eC=(0,o.useRef)(null),eT=(0,o.useRef)(!1),ez=(0,o.useRef)(null),eI=(0,o.useRef)(!1),eM=(0,o.useRef)(null),eL=(0,o.useRef)(null),eR=(0,o.useRef)(new Map),eW=(0,o.useRef)(new Set),eE=e.setNewSessionModel??_,e$=e.setToolPreset??V,eP=e.setMemoryTools??Y,eB=ei??u?.context.model??ep??null,eD=c?U:eB,eN=(0,o.useCallback)(e=>e?.length?e.map((e,t)=>{let r=`Attachment ${t+1}: ${e.fileName} (${e.mimeType||"application/octet-stream"}, ${e.size} bytes)`;if(e.extractedText){let t=e.truncated?"\n[The extracted text was truncated before sending.]":"";return`${r}
7
7
  ${t}
8
8
  ${e.extractedText}`.trim()}return`${r}
9
9
  [Text extraction unavailable: ${e.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),eO=(0,o.useCallback)(e=>{let t=ec(e);if(!t)return;let r=eR.current;r.set(t,(r.get(t)??0)+1)},[]),eA=(0,o.useCallback)(e=>{let t=ec(e);if(!t)return!1;let r=eR.current,n=r.get(t)??0;return!(n<=0)&&(1===n?r.delete(t):r.set(t,n-1),!0)},[]),eH=(()=>{let e={input:0,output:0,cacheRead:0,cacheWrite:0},t=0;for(let r of y){if("assistant"!==r.role)continue;let n=r.usage;n&&(e.input+=n.input??0,e.output+=n.output??0,e.cacheRead+=n.cacheRead??0,e.cacheWrite+=n.cacheWrite??0,t+=n.cost?.total??0)}return e.input+e.output+e.cacheRead+e.cacheWrite>0?{tokens:e,cost:t}:null})(),eF=(0,o.useCallback)(async(e,t=!1,r=!1)=>{try{t&&x(!0);let n=r?`/api/sessions/${encodeURIComponent(e)}?includeState`:`/api/sessions/${encodeURIComponent(e)}`,o=await fetch(n);if(ew.current&&ew.current!==e)return null;if(404===o.status)return t&&(p(null),m(null),b([]),f(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let i=await o.json();return p(i),m(i.leafId),b(i.context.messages),k(i.context.entryIds??[]),eR.current.clear(),eW.current=new Set(i.context.messages.map(eu).filter(e=>!!e)),el(null),f(null),!i.agentState?.state?.thinkingLevel&&i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&X(i.context.thinkingLevel),i.agentState??null}catch(e){return f(String(e)),null}finally{t&&x(!1)}},[]),eU=(0,o.useCallback)(async(e,t)=>{try{let r=t?`/api/sessions/${encodeURIComponent(e)}/context?leafId=${encodeURIComponent(t)}`:`/api/sessions/${encodeURIComponent(e)}/context`,n=await fetch(r);if(!n.ok)throw Error(`HTTP ${n.status}`);let o=await n.json();b(o.context.messages),k(o.context.entryIds??[]),eR.current.clear()}catch(e){console.error("Failed to load context:",e)}},[]),e_=(0,o.useCallback)(async e=>{try{let t=await ea(e,{type:"get_tools"});if(t){let e,r,n,o;e$((r=(e=t.filter(e=>e.active).map(e=>e.name)).filter(e=>!C.includes(e)),n=R(e),o=R(r),""===n?"none":n===R(z)?"default":n===R(I)?"full":n===R(M)?"workbench":n===R(L)?"agent":""===o?"none":o===R(z)?"default":o===R(I)?"full":o===R(M)?"workbench":o===R(L)||e.includes(S)?"agent":"default")),eP(C.filter(e=>t.some(t=>t.active&&t.name===e)))}}catch(e){console.error("Failed to load tools:",e)}},[eP,e$]),eJ=(0,o.useCallback)((e,t={})=>{ek.current&&(ek.current.close(),ek.current=null);let r=new EventSource(`/api/agent/${encodeURIComponent(e)}/events${t.replay?"?replay=1":""}`);ek.current=r,r.onmessage=e=>{try{let t=JSON.parse(e.data);eC.current?.(t)}catch{}},r.onerror=()=>{ek.current===r&&eS.current&&(r.close(),ek.current=null,setTimeout(()=>{eS.current&&eJ(e)},1e3))}},[]);(0,o.useEffect)(()=>{eS.current=W},[W]),eC.current=(0,o.useCallback)(e=>{switch(e.type){case"agent_start":ej(null),$(!0),ey({kind:"waiting_model"}),T({type:"start"});break;case"agent_end":eS.current=!1,ek.current?.close(),ek.current=null,$(!1),ey(null),G(null),T({type:"end"}),ew.current&&(eF(ew.current),fetch(`/api/agent/${encodeURIComponent(ew.current)}`).then(e=>e.json()).then(e=>{!1===e.running&&($(!1),ey(null),T({type:"end"})),e.state?.contextUsage!==void 0&&ee(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&er(e.state.systemPrompt??null),e.state?.isCompacting!==void 0&&eg(e.state.isCompacting)}).catch(()=>{})),n?.();break;case"message_start":case"message_update":{let t=e.message;if(t){let e=es(t);eW.current.has(eu(e)??"")||T({type:"update",message:e})}ey(null);break}case"message_end":{let t=e.message;if(t){let e=es(t),r=eu(e),n=!!r&&eW.current.has(r);r&&eW.current.add(r),n||"user"===e.role&&eA(e)||b(t=>[...t,e])}T({type:"reset"}),ey({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName;ey(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r}),{kind:"running_tools",tools:n}});break}case"tool_execution_end":{let t=e.toolCallId;ey(e=>{if(e?.kind!=="running_tools")return e;let r=e.tools.filter(e=>e.id!==t);return 0===r.length?{kind:"waiting_model"}:{kind:"running_tools",tools:r}});break}case"auto_retry_start":G({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":G(null);break;case"auto_compaction_start":case"compaction_start":eg(!0),ev(null);break;case"auto_compaction_end":case"compaction_end":eg(!1),e.errorMessage?ev(e.errorMessage):!e.aborted&&ew.current&&eF(ew.current)}},[eA,eF,n]);let eV=(0,o.useCallback)(async(e,n,o)=>{if(!e.trim()&&!n?.length&&!o?.length||W)return;let l=eN(o),s=e.trim()?l?`${e}